  <?php

require_once('convert_marathi.php');
############################################# Display Letters To Perform Action ######################################
session_start();
$username = $_SESSION['User_Name'];
$flag=$_REQUEST['flag'];
if($flag=='')
{
	include_once('dashboard_desk.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Tapal Admin System</title>
</head>
<body>
    <div class="rightpanel">
        <ul class="breadcrumbs">
            <li><a href="dashboard_desk.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="dashboard_desk.php">Tables</a> <span class="separator"></span></li>
             <li>कार्यवाही करा</li>
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-table"></span></div>
            <div class="pagetitle">
               <h5>Forms</h5>
                <h1>कार्यवाही करा</h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
				<h4 class="widgettitle">कार्यवाही करा</h4>             					 
                <table id="dyntable" class="table table-bordered">
                    <thead>
                        <tr>
                            <th class="head0 center">डेस्कचा <br>आवक क्र </th>
							<th class="head1 center">डेस्कला <br>प्राप्त दि.</th>
                            <th class="head0 center">स्वीकृत दि. </th>
							<th class="head1 center">संदर्भ क्र. <br>संदर्भ दिं.</th>
							<th class="head0 center">पोलीस अधिक्षक <br> कार्यालय <br>आवक क्र.<br>आवक दिं.</th>
                            <th class="head1 center">विभागीय आ. क्र.<br>विभागीय आ. दि.</th>                 
							<th class="head0 center">थोडक्यात विषय</th> 
  							<th class="head1 center">कोणाकडून प्राप्त झाले </th>
  							<th class="head1 center"> कोणास दिले <br> मोबाईल नं. </th>
							<th class="head0 center">कार्यवाही करा </th>
                        </tr>
					</thead>
					<tbody>	
					<?php	
						convert_marathi();
						$qry=("SELECT i.ref_dt,de.desk_ltr_rec_dt,de.desk_apprv_dt,t.dpt_ltr_rec_dt, i.receive_dt, de.desk_ltr_inword_no, i.ref_no, i.subject, i.ltr_inword_no, t.dpt_inword_no, i.sender_name, de.send_to, de.mobno, de.flag, de.desk_ltr_id
						FROM desk_transaction de, incoming_letters_transaction i, tapal_to_dpt_transaction t
						WHERE de.ltr_category !='' AND t.desk_id=(select desk_id from login where login_id='$username') 
						AND t.ltr_id=i.ltr_id 
						AND t.dpt_ltr_id=de.dpt_ltr_id 
						AND de.ltr_approval='Approve' 
						AND ((de.flag='false' AND de.ltr_status='dispatched')
								OR (de.flag='' AND de.ltr_status='' ))
						ORDER BY de.desk_ltr_id DESC");
						$rs=mysql_query($qry) or die("".mysql_error());
						while($rws=mysql_fetch_array($rs))
							{	
								/***************************************************************
										fetching dates in dd-mm-yyyy format
									****************************************************************/
								$refdt= strtotime($rws['ref_dt']);
								$refdte = date('d-m-Y', $refdt);
								$deskrecdt= strtotime($rws['desk_ltr_rec_dt']);
								$deskrecdte = date('d-m-Y', $deskrecdt);
								$deskappdt= strtotime($rws['desk_apprv_dt']);
								$deskappdte = date('d-m-Y', $deskappdt);
								$dptrecdt= strtotime($rws['dpt_ltr_rec_dt']);
								$dptrecdte = date('d-m-Y', $dptrecdt);
								$recdt=strtotime($rws['receive_dt']);
								$recdte=date('d-m-Y', $recdt);
								?>
								<tr class="gradeX">	
								<?php 
									$vr=$rws['desk_ltr_id'];
									echo "<td class='center'>".$rws['desk_ltr_inword_no']." </td>
									<td class='center' >".$deskrecdte." </td>
									<td class='center' >".$deskappdte ." </td>
									<td class='center' >".$rws['ref_no']."<br>".$refdte."</td>
									<td class='center' >".$rws['ltr_inword_no']."<br>".$recdte."</td>
									<td class='center' >".$rws['dpt_inword_no']."<br>".$dptrecdte."</td>
									<td class='center' style='width:100px;'>".$rws['subject']."</td>
									<td class='center'>".$rws['sender_name']."</td>
									<td class='center'>".$rws['send_to']."<br> ".$rws['mobno']."</td>";
									
									
									if($rws['flag']=='')
										{
											echo "<td class='center' ><a href=desk_action_perfom_form.php?no=$vr>Edit</a></td>";
										}
									else
										{
											echo "<td class='center' ><a href=desk_action_perfom_form.php?no=$vr>Edit</br><font color='red'>(बी.डी.ओ. कडून परत)</font></a></td>";
										}
									echo "</tr>";
									?>
					<?php 	} ?>
                    </tbody>
                </table>
              <br /><br />
          
         <?php include_once('footer.php'); ?>
        </div><!--maincontentinner-->
    </div><!--maincontent-->  
</div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php
} //if($flag=='')


else if($flag=='n')
{
	include_once('new_dashboard_department.php');
?>
<!DOCTYPE html>
<html>
<head>
<title>Tapal Admin System</title>
</head>
<body>
    <div class="rightpanel">
        <ul class="breadcrumbs">
            <li><a href="new_dashboard_department.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="new_dashboard_department.php">Tables</a> <span class="separator"></span></li>
             <li>कार्यवाही करा</li>
        </ul>
        <div class="pageheader">
            <div class="pageicon"><span class="iconfa-table"></span></div>
            <div class="pagetitle">
               <h5>Forms</h5>
                <h1>कार्यवाही करा</h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
				<h4 class="widgettitle">कार्यवाही करा</h4>             					 
                <table id="dyntable" class="table table-bordered">
                    <thead>
                        <tr>
                           <!--- <th class="head0 center">डेस्कचा <br>आवक क्र </th>
							<th class="head1 center">डेस्कला <br>प्राप्त दि.</th> -->
                            <th class="head0 center">स्वीकृत दि. </th>
							<th class="head1 center">संदर्भ क्र. <br>संदर्भ दिं.</th>
							<th class="head0 center">पोलीस अधिक्षक <br> कार्यालय <br>आवक क्र.<br>आवक दिं.</th>
                            <th class="head1 center">विभागीय आ. क्र.<br>विभागीय आ. दि.</th>                 
							<th class="head0 center">थोडक्यात विषय</th> 
  							<th class="head1 center">कोणाकडून प्राप्त झाले </th>
  							<th class="head1 center"> कोणास दिले <br> मोबाईल नं. </th>
							<th class="head0 center">कार्यवाही करा </th>
                        </tr>
					</thead>
					<tbody>	
					<?php	
						convert_marathi();
						$rs=mysql_query("SELECT *
										FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
										WHERE t.ltr_category != ''
										AND t.dept_id_from = (
										SELECT dept_id
										FROM login
										WHERE login_id = '$username' )
										AND t.ltr_id = i.ltr_id
										AND t.status = 'approve'
										AND (
												(
													t.flag = 'false'
													AND t.ltr_status = 'dispatched'
												)
												OR (
													t.flag = ''
													AND t.ltr_status = ''
												)
											)
										ORDER BY t.dpt_ltr_id DESC") or die("".mysql_error());
						
						while($rws=mysql_fetch_array($rs))
							{	
								/***************************************************************
										fetching dates in dd-mm-yyyy format
									****************************************************************/
								$refdt= strtotime($rws['ref_dt']);
								$refdte = date('d-m-Y', $refdt);
							/*	$deskrecdt= strtotime($rws['desk_ltr_rec_dt']);
								$deskrecdte = date('d-m-Y', $deskrecdt); */
								$dptappdt= strtotime($rws['dpt_ltr_aprv_dt']);
								$dptappdte = date('d-m-Y', $dptappdt);
								$dptrecdt= strtotime($rws['dpt_ltr_rec_dt']);
								$dptrecdte = date('d-m-Y', $dptrecdt);
								$recdt=strtotime($rws['receive_dt']);
								$recdte=date('d-m-Y', $recdt);
								?>
								<tr class="gradeX">	
								<?php 
									$vr=$rws['dpt_ltr_id'];
									/*echo "<td class='center'>".$rws['desk_ltr_inword_no']." </td>
									<td class='center' >".$deskrecdte." </td>*/
									echo "
									<td class='center' >".$dptappdte." </td>
									<td class='center' >".$rws['ref_no']."<br>".$refdte."</td>
									<td class='center' >".$rws['ltr_inword_no']."<br>".$recdte."</td>
									<td class='center' >".$rws['dpt_inword_no']."<br>".$dptrecdte."</td>
									<td class='center' style='width:100px;'>".$rws['subject']."</td>
									<td class='center'>".$rws['sender_name']."</td>
									<td class='center'>".$rws['send_to']." <br> ".$rws['mobno']." </td>";
									
									if($rws['flag']=='')
										{
											echo "<td class='center' ><a href=desk_action_perfom_form.php?flag=n&no=$vr>Edit</a></td>";
										}
									else
										{
											//removed functionality from BDO
											echo "<td class='center' ><a href=desk_action_perfom_form.php?flag=n&no=$vr>Edit</br><font color='red'>(बी.डी.ओ. कडून परत)</font></a></td>";
										}
									echo "</tr>";
									?>
					<?php 	} ?>
                    </tbody>
                </table>
              <br /><br />
          
         <?php include_once('footer.php'); ?>
        </div><!--maincontentinner-->
    </div><!--maincontent-->  
</div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
<?php
} //else if($flag=='n')
?>