<?php
include_once('db.php');
require_once('convert_marathi.php');

$username = $_REQUEST['login_id'];
$ltr_id = $_REQUEST['ltr_id'];

$category = $_REQUEST['category']; /////// 1=current, 2=new sandarbh

if($category==1)
{
	$s_no = $_REQUEST['ltr_inword_no']; 

}

################################ Code To Assign reference Type As New Or Current ##############################
					
					
					$qry1 =("SELECT * FROM desk_transaction, incoming_letters_transaction, tapal_to_dpt_transaction WHERE (desk_transaction.ltr_approval='Approve') AND (desk_transaction.ltr_category='')
					AND (desk_transaction.ltr_status!='closed')
					AND (desk_transaction.dpt_ltr_id=tapal_to_dpt_transaction.dpt_ltr_id) AND (tapal_to_dpt_transaction.ltr_id=incoming_letters_transaction.ltr_id) AND desk_transaction.desk_id_from=(SELECT desk_id FROM login WHERE login_id='$username')
					AND (incoming_letters_transaction.ltr_id='$ltr_id')
					order by incoming_letters_transaction.ltr_inword_no DESC");	
					
					$rs1=mysql_query($qry1);
					
					while($row1=mysql_fetch_array($rs1))
					{	
				
						$no=$row1['desk_ltr_id'];
						
							
							$ltrcate = $category;
							$assign_no = $s_no;
							
							
							if($ltrcate=='1')
							{
								if($assign_no!='')
								{
									$qry13=("UPDATE desk_transaction set ltr_category='current', assign_no='$assign_no'  WHERE desk_ltr_id='$no'");
									$result=mysql_query($qry13);
									
								}
								else
								{
									echo "300";
								}
								
							}
							else  if($ltrcate=='2')
						   {
								$qry13=("UPDATE desk_transaction set ltr_category='new' WHERE desk_ltr_id='$no'");
								$result=mysql_query($qry13);
								
								
						   }
						   
						   if($result)
							{ 
								echo "200";
							}
							else
							{   
								echo "400";
							}
						
					}
					?>
			

