<?php
session_start();
require_once('db.php');
require_once('../convert_marathi.php');
convert_marathi();
$username = $_SESSION['User_Name'];
$m1    = mysql_query("SELECT * FROM login WHERE login_id='$username'");
$rm1   = mysql_fetch_array($m1);
$logid = $rm1['id'];

$flag=$_REQUEST['flag'];

if($flag=='')
{
	convert_marathi();
	$rs=mysql_query("SELECT * FROM wait_register WHERE kar_flag='N' AND login_id='$logid'");
	while($rws=mysql_fetch_array($rs))
	{
		$id = $rws['id'];
		$iid  = $rws['iid'];

		date_default_timezone_set('Asia/Kolkata');
		$updt = date("d-m-Y H:i:s");

		if(isset($_POST['r'.$id]))	
		{
			convert_marathi();
			$remark = $_POST['name'.$id];

			$q1 = mysql_query("UPDATE wait_register SET remark='$remark',kar_flag='A',updt='$updt' WHERE id='$id'");
			if($q1)
			{
				$q2 = mysql_query("UPDATE desk_transaction SET wait_kar_flag='A' WHERE desk_ltr_id='$iid'");
				if($q2)
				{

				}
				else
				{
					$q1 = mysql_query("UPDATE wait_register SET remark='',kar_flag='N',updt='' WHERE id='$id'");
				}
			}
		}
	}

	echo "<script type='text/javascript'>alert('Action Performed Successfully!')</script>";
	echo '<script language="JavaScript"> window.location.href ="../await_register.php" </script>';
}

// Flag N ------------------------------------------------------------------------
else if($flag=='n')
{
	convert_marathi();
	$rs=mysql_query("SELECT * FROM wait_register WHERE kar_flag='N' AND login_id='$logid'");
	while($rws=mysql_fetch_array($rs))
	{
		$id = $rws['id'];
		$iid  = $rws['iid'];

		date_default_timezone_set('Asia/Kolkata');
		$updt = date("d-m-Y H:i:s");

		if(isset($_POST['r'.$id]))	
		{
			convert_marathi();
			$remark = $_POST['name'.$id];

			$q1 = mysql_query("UPDATE wait_register SET remark='$remark',kar_flag='A',updt='$updt' WHERE id='$id'");
			if($q1)
			{
				$q2 = mysql_query("UPDATE tapal_to_dpt_transaction SET wait_kar_flag='A' WHERE dpt_ltr_id='$iid'");
				if($q2)
				{

				}
				else
				{
					$q1 = mysql_query("UPDATE wait_register SET remark='',kar_flag='N',updt='' WHERE id='$id'");
				}
			}
		}
	}

	echo "<script type='text/javascript'>alert('Action Performed Successfully!')</script>";
	echo '<script language="JavaScript"> window.location.href ="../await_register.php?flag=n" </script>';
}
?>