<html>
<meta charset="UTF-8" />
<?php
$flag=$_REQUEST['flag'];
if($flag=='')
{
	require_once("connection/db.php");
	require_once("convert_marathi.php");
	convert_marathi();
	$id=$_REQUEST['id'];
	$username=$_REQUEST['uname'];
	
	$result222=mysql_query("SELECT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt,t.desk_approval,t.sent_to_desk_dt,  t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject, de. 	update_date, de.dispatched_dt, de.ltr_approval, di.addressed_to, de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no, di.dispatched_to, de.ltr_category, de.assign_no,de.nasti_nashta_dt
	FROM  incoming_letters_transaction  i  LEFT OUTER JOIN tapal_to_dpt_transaction t ON i.ltr_id = t.ltr_id
	LEFT OUTER JOIN desk_transaction de ON de.dpt_ltr_id = t.dpt_ltr_id LEFT OUTER JOIN dispatched_transaction di ON di.desk_ltr_id = de.desk_ltr_id
	where t.desk_id=(select desk_id from login where login_id='$username')
	AND (de.vargawari='$id' AND de.ltr_status!='')
	AND de.final_nashta_dt IS NULL ") or die("sdfdfds".mysql_error());
	
	$i=1;
	while($test = mysql_fetch_array($result222))
	{
		$t=$_POST['txt'.$i];
		$desk_ltr_id= $test['desk_ltr_id'];
		$t=date('Y-m-d',strtotime($t));
		//echo $t."aa<br>";
		if($t!='' && $t!='1970-01-01')
		{
			$qry="UPDATE desk_transaction SET final_nashta_dt='$t' where desk_ltr_id='$desk_ltr_id' ";
			if(mysql_query($qry))
			{
				//echo "<script type='text/javascript'> alert('Updated Successfully!!!!!!'); </script>";
			}
			else
			{
				echo "<script type='text/javascript'> alert('Failed to Update!!!!')</script>";
				echo "<script language='JavaScript'> window.location.href ='rec_sort_jatanprakar.php?no=2&id=".$id." '</script>";	
			}
		}
		$i++;
	}
	echo "<script type='text/javascript'> alert('Updated Successfully!!!!')</script>";
	echo "<script language='JavaScript'> window.location.href ='rec_sort_jatanprakar.php?no=2&id=".$id." '</script>";	
}
else if($flag=='n')
{
	require_once("connection/db.php");
	require_once("convert_marathi.php");
	convert_marathi();
	$id=$_REQUEST['id'];
	$username=$_REQUEST['uname'];

	convert_marathi();
	$result222=mysql_query("SELECT * FROM incoming_letters_transaction i, tapal_to_dpt_transaction t
							where t.dept_id_from=(select dept_id from login where login_id='$username') 
							AND ( t.vargawari='$id' AND t.ltr_status!='')
							AND i.ltr_id=t.ltr_id
							AND t.final_nashta_dt IS NULL ") or die("sdfdfds".mysql_error());
	$i=1;
	while($test = mysql_fetch_array($result222))
	{
		$t=$_POST['txt'.$i];
		$dptLtrId= $test['dpt_ltr_id'];
		$t=date('Y-m-d',strtotime($t));
		//echo $t."aa<br>";
		if($t!='' && $t!='1970-01-01')
		{
			$qry="UPDATE tapal_to_dpt_transaction SET final_nashta_dt='$t' where dpt_ltr_id='$dptLtrId' ";
			if(mysql_query($qry))
			{
				//echo "<script type='text/javascript'> alert('Updated Successfully!!!!!!'); </script>";
			}
			else
			{
				echo "<script type='text/javascript'> alert('Failed to Update!!!!')</script>";
				echo "<script language='JavaScript'> window.location.href ='rec_sort_jatanprakar.php?flag=n&id=".$id." '</script>";	
			}
		}
		$i++;
	}
	echo "<script type='text/javascript'> alert('Updated Successfully!!!!')</script>";
	echo "<script language='JavaScript'> window.location.href ='rec_sort_jatanprakar.php?flag=n&id=".$id." '</script>";	
}// flag==n
?>
</html>