  <?php
include_once('dashboard_department.php');
  ############################ Assign Desk TO the Letters Which Are Accepted By Department ###################################
require_once('convert_marathi.php');
$username = $_SESSION['User_Name'];
?>
<!DOCTYPE html>
<html>
<head>  
</head>
    <div class="rightpanel">
        <ul class="breadcrumbs">
            <li><a href="dashboard_department.php"><i class="iconfa-home"></i></a> <span class="separator"></span></li>
            <li><a href="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>Tables</h5>
                <h1>डेस्क लावा </h1>
            </div>
        </div><!--pageheader-->
        <div class="maincontent">
            <div class="maincontentinner">
                <h4 class="widgettitle">डेस्क लावा </h4>
				<?php //sleep(500);
					convert_marathi(); // Display in Marathi
					/* $qrye=("SELECT * FROM tapal_to_dpt_transaction, incoming_letters_transaction 
					 WHERE incoming_letters_transaction.dept_id = (SELECT dept_id FROM login WHERE login_id ='$username') 
					 AND tapal_to_dpt_transaction.desk_id='0'
					 AND tapal_to_dpt_transaction.ltr_category='' 
					 AND tapal_to_dpt_transaction.desk_approval!='approve' 
					 AND (tapal_to_dpt_transaction.desk_ltr_inword_no='0' or tapal_to_dpt_transaction.desk_ltr_inword_no='')
					 AND tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id ");*/
					 $qrye=("SELECT * FROM tapal_to_dpt_transaction, incoming_letters_transaction 
					 WHERE tapal_to_dpt_transaction.dept_id_from = (SELECT dept_id FROM login WHERE login_id ='$username') 
					 AND tapal_to_dpt_transaction.desk_id='0'
					 AND tapal_to_dpt_transaction.ltr_category='' 
					 AND tapal_to_dpt_transaction.desk_approval!='approve' 
					 AND (tapal_to_dpt_transaction.desk_ltr_inword_no='0' or tapal_to_dpt_transaction.desk_ltr_inword_no='')
					 AND tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id ");
					
					 $rsult=mysql_query($qrye) or die("vghgfhg".mysql_error());
					$cnm=mysql_num_rows($rsult);
					// echo "Result".$cnm;
					 while($rw=mysql_fetch_array($rsult))
						{	$w=$rw['dpt_ltr_id'];
							if(isset($_POST['desknm' . $rw['ltr_inword_no']]))
								{
									$selectedDeskNumber = $_POST['desknm' . $rw['ltr_inword_no']];
									if($selectedDeskNumber!="")
										{
											$sql1 = ("UPDATE tapal_to_dpt_transaction SET desk_id = '$selectedDeskNumber', sent_to_desk_dt=curdate(), desk_approval='pending' WHERE (desk_ltr_inword_no='' OR desk_ltr_inword_no='0') AND dpt_ltr_id='$w' AND returned_choice='' ") or die("".mysql_error());
											if(mysql_query($sql1))
												{
													echo "<script type='text/javascript'>alert('Assigned Desk Successfully!')</script>";
													echo '<script language="JavaScript"> window.location.href ="assign_desk.php" </script>';
												}
											else
												{
												echo "<script type='text/javascript'>alert('Assigned Desk Unsuccessful!')</script>";
												echo '<script language="JavaScript"> window.location.href ="assign_desk.php" </script>';	
												}
												
										}
									
								}
									
						}
						?>
				<form action="assign_desk.php" method="post">
                <table id="dyntable" class="table table-bordered">
                    <thead>
                        <tr>
							<th class="head0 center">विभागीय <br>आवक क्र. </th>
							<th class="head1 center">पोलीस अधीक्षक <br> कार्यालय <br>आवक क्र. /<br> आवक दिं</th>
							<th class="head0 center">संदर्भ क्र./<br> संदर्भ दिं </th>		
							<th class="head1 center">विभागीय <br>आवक दि.</th>
							<th class="head0 center">विभागीय <br>स्वीकृत दि.</th>
							<th class="head1 center">कोणाकडून <br>प्राप्त झाले  </th>
                            <th class="head0 center">संदर्भचा<br> प्रकार </th>
							<th class="head1 center">थोडक्यात<br> विषय </th>                   
							<th class="head0 center">डेस्क लावा </th>
                        </tr>
					</thead>
					<tbody>
						<?php 
						convert_marathi();
						$qre=("SELECT * FROM tapal_to_dpt_transaction,incoming_letters_transaction WHERE tapal_to_dpt_transaction.desk_id='0' AND incoming_letters_transaction.status LIKE '%approve%' AND (tapal_to_dpt_transaction.desk_ltr_inword_no='' OR tapal_to_dpt_transaction.desk_ltr_inword_no='0') AND (tapal_to_dpt_transaction.dept_id_from=(select dept_id from login where login_id='$username'))AND incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND tapal_to_dpt_transaction.returned_choice='' ORDER BY tapal_to_dpt_transaction.dpt_ltr_id DESC");
						
						
						$rsut=mysql_query($qre) or die("aaaa".mysql_error());
						$cnt=mysql_num_rows($rsut);
						while($rws=mysql_fetch_array($rsut))
							{	echo $a=$rws[dept_id];
								$refdate = strtotime($rws['ref_dt']);
								$ref= date('d-m-Y', $refdate);
								//rec dt
								$recdt = strtotime($rws['receive_dt']);
								$rec= date('d-m-Y', $recdt);
								//dpt rec dt
								$dptrcdt = strtotime($rws['dpt_ltr_rec_dt']);
								$dptrecdt= date('d-m-Y', $dptrcdt);
								//dpt_ltr_aprv_dt
								$dptapdt = strtotime($rws['dpt_ltr_aprv_dt']);
								$dptappdt= date('d-m-Y', $dptapdt);
						?>
								<tr class="gradeX">
									<?php 
									echo "
									<td class=center>".$rws['dpt_inword_no']."</td><td class=center>".$rws['ltr_inword_no']."<br>".$rec." </td>
									<td class=center>". $rws['ref_no']."<br>".$ref. "</td><td class=center>".$dptrecdt."</td><td class=center>".$dptappdt."</td>
									<td class=center style=width:100px;><div id=wrapping>".$rws['sender_name']."</div></td>";
									$id=$rws['ltr_inword_no'];
									convert_marathi();// Display in Marathi
									$qry5=("Select * from sandharbh_master,incoming_letters_transaction WHERE sandharbh_master.sandhrbh_id=incoming_letters_transaction.ltr_type AND incoming_letters_transaction.ltr_inword_no='$id' order by incoming_letters_transaction.ltr_inword_no DESC");
									$rs5=mysql_query($qry5) or die ("mmmm". mysql_error());
									while($rw5=mysql_fetch_array($rs5))
									{
										$ltr=$rw5['sandharbh_nm'];
									}
									echo "<td class=center>".$ltr."</td>";
									echo"<td class=center style=width:100px;><div class='wrapping'>".$rws['subject']."</div></td><td class=center style=width:75px;>";
									convert_marathi();
									$query = "SELECT  * FROM desk_master WHERE dept_id='$rws[dept_id]'"; 
									$result = mysql_query ($query);
									echo "<select name='desknm".$rws['ltr_inword_no']."' id ='desk'>Dropdown</option><option value=>डेस्क निवडा</option>";
									while($row = mysql_fetch_array($result))
										{
											echo"	{
											('<option id='".$row['desk_id']."' value='".$row['desk_id']."'>".$row['desk_nm']."</option>')
											}";
										}
									echo" </select></td>
								</tr>";         
							}?>
                    </tbody>
                </table>
                <br /><br />
                <p class="stdformbutton">
                     <center><button class="btn btn-primary">डेस्क लावा </button>
                     <button type="reset" class="btn">रद्द करा </button></center>
                </p>
				</form>
				<?php include_once('footer.php');?>
			</div><!--maincontentinner-->
        </div><!--maincontent-->
    </div><!--rightpanel-->
</div><!--mainwrapper-->
</body>
</html>
