<?php 
    require_once('connection/db.php');
	require_once('convert_marathi.php');
	######################################### Fetch Selected Record In Form Field And Perform Action #########################
	session_start();
	$username = $_SESSION['User_Name']; 
	$flag=$_REQUEST['flag'];
if($flag=='')
{
	$id=$_GET['num'];
	//echo "id is".$id;
	$ltrtype=$_POST['ltrtype'];
	$actiontaken=$_POST['actiontake'];
	$actiontaken1=$_POST['actiontake1'];
	convert_marathi();
	if($actiontaken1=='other')
	{
		$qry=("UPDATE desk_transaction SET action_taken='$actiontaken' WHERE desk_ltr_id='$id'");
	}
	else
	{
		$qry=("UPDATE desk_transaction SET action_taken='$actiontaken1' WHERE desk_ltr_id='$id'");
	}
	/************************************************
	action performed if update button is selected
	*************************************************/
    if (isset($_POST['update']))
	{
		if($ltrtype=='ब')
		{
			//$futureDate=date('Y-m-d', strtotime('+30 year'));
			$now23 =date('Y')+30;
			$futureDate =$now23.'-'.date('m-d');
		}
		else if($ltrtype=='क')
		{
			$now23 =date('Y')+10;
			$futureDate =$now23.'-'.date('m-d');
		}
		else if($ltrtype=='क१')
		{
			$now23 =date('Y')+5;
			$futureDate =$now23.'-'.date('m-d');
		}
		else if($ltrtype=='ड')
		{
			$now23 =date('Y')+1;
			$futureDate =$now23.'-'.date('m-d');
		}
		
		$qry2=("UPDATE desk_transaction dt, tapal_to_dpt_transaction t 
		SET dt.update_date=curdate(), 
		t.desk_approval='updated', dt.ltr_status='updated' , dt.vargawari='$ltrtype', dt.nasti_nashta_dt='$futureDate'
		WHERE desk_ltr_id='$id' AND t.dpt_ltr_id=dt.dpt_ltr_id");

		if(mysql_query($qry2)) 
		{ 
			mysql_query($qry);
			echo "<script type='text/javascript'>alert('Action Performed Successfully!')</script>";
			echo '<script language="JavaScript"> window.location.href ="desk_action_perform.php" </script>';
		}
		else
		{   
			echo "<script type='text/javascript'>alert('Problem to perform action!111111111111111dfsdf')</script>";
			echo '<script language="JavaScript"> window.location.href ="desk_action_perform.php" </script>';
		}
	}
	/************************************************
		action performed if dispatch button is selected
	*************************************************/
	if (isset($_POST['dispatch']))
	{		
		require_once('dispatch.php');// Calling dispatch.php File
		
		mysql_query($qry);
	}
	/************************************************
		Rejected letter's dispatch button is selected
		
	*************************************************/
	if (isset($_POST['rejdispatch']))
	{ 
		$recdt = date('Y-m-d', strtotime($redt));
		$rejid=$_POST['rejid'];
		require_once('dispatch.php');// Calling dispatch.php File
		if(mysql_query($qry))
		{
			$qry10=mysql_query("UPDATE desk_transaction,ltr_rejection SET desk_transaction.action_taken='$actiontaken', desk_transaction.dispatched_dt=curdate(),desk_transaction.flag='',desk_transaction.vargawari='$ltrtype' WHERE desk_transaction.desk_ltr_id='$id' AND ltr_rejection.ltr_rej_id='$rejid' AND desk_transaction.desk_ltr_id=ltr_rejection.desk_ltr_id AND desk_transaction.ltr_rej_id=ltr_rejection.ltr_rej_id") or ("qqqqqqq".mysql_error());
			
		}
		else
		{
			echo "<script type='text/javascript'>alert('Problem to perform action!')</script>";
			echo '<script language="JavaScript"> window.location.href ="desk_action_perform.php" </script>';
		}
	}
} //if($flag=='')



else if($flag=='n')
{
	$id=$_GET['num'];
	//echo "id is".$id;
	$ltrtype=$_POST['ltrtype'];

	$actiontaken1=$_POST['actiontake1'];
	convert_marathi();
	if($actiontaken1!='other')
	{
		$qry=("UPDATE tapal_to_dpt_transaction SET  action_taken='$actiontaken1' WHERE dpt_ltr_id='$id'");
	}
	else
	{
		$ationtaken=$_POST['actiontake'];
		$qry=("UPDATE tapal_to_dpt_transaction SET  action_taken='$ationtaken' WHERE dpt_ltr_id='$id'");
	}
	/************************************************
	action performed if update button is selected
	*************************************************/
    if (isset($_POST['update']))
	{
		/*$qry2=("UPDATE desk_transaction, tapal_to_dpt_transaction SET update_date=curdate(), desk_approval='updated', ltr_status='updated' WHERE desk_ltr_id='$id' AND tapal_to_dpt_transaction.dpt_ltr_id=desk_transaction.dpt_ltr_id");*/
		if($ltrtype=='ब')
		{
			//$futureDate=date('Y-m-d', strtotime('+30 year'));
			$now23 =date('Y')+30;
			$futureDate =$now23.'-'.date('m-d');
		}
		else if($ltrtype=='क')
		{
			$now23 =date('Y')+10;
			$futureDate =$now23.'-'.date('m-d');
		}
		else if($ltrtype=='क१')
		{
			$now23 =date('Y')+5;
			$futureDate =$now23.'-'.date('m-d');
		}
		else if($ltrtype=='ड')
		{
			$now23 =date('Y')+1;
			$futureDate =$now23.'-'.date('m-d');
		}
		$qry2=("UPDATE tapal_to_dpt_transaction 
				SET update_date=curdate(), ltr_status='updated' ,vargawari='$ltrtype', nasti_nashta_dt='$futureDate'
				WHERE dpt_ltr_id='$id' ") or die("hhhhh".mysql_error());
		
		if(mysql_query($qry2)) 
		{ 
			mysql_query($qry);
			echo "<script type='text/javascript'>alert('Action Performed Successfully!')</script>";
			echo '<script language="JavaScript"> window.location.href ="desk_action_perform.php?flag=n" </script>';
		}
		else
		{   
			echo "<script type='text/javascript'>alert('Problem to perform action!')</script>";
			echo '<script language="JavaScript"> window.location.href ="desk_action_perform.php?flag=n" </script>';
		}
	}
	/************************************************
		action performed if dispatch button is selected
	*************************************************/
	if (isset($_POST['dispatch']))
	{		
		require_once('dispatch_dpt.php');// Calling dispatch_dpt.php File
		mysql_query($qry);
	}
	/************************************************
		Rejected letter's dispatch button is selected
		
	*************************************************/
 /*	if (isset($_POST['rejdispatch']))
	{ 
		$recdt = date('Y-m-d', strtotime($redt));
		$rejid=$_POST['rejid'];
		require_once('dispatch.php');// Calling dispatch.php File
		if(mysql_query($qry))
		{
			$qry10=mysql_query("UPDATE desk_transaction,ltr_rejection SET desk_transaction.action_taken='$actiontaken', desk_transaction.dispatched_dt=curdate(),desk_transaction.flag='',desk_transaction.vargawari='$ltrtype' WHERE desk_transaction.desk_ltr_id='$id' AND ltr_rejection.ltr_rej_id='$rejid' AND desk_transaction.desk_ltr_id=ltr_rejection.desk_ltr_id AND desk_transaction.ltr_rej_id=ltr_rejection.ltr_rej_id") or ("qqqqqqq".mysql_error());
			
		}
		else
		{
			echo "<script type='text/javascript'>alert('Problem to perform action!')</script>";
			echo '<script language="JavaScript"> window.location.href ="desk_action_perform.php" </script>';
		}
	}*/

}// else if($flag=='n')
	 ?>