<html>
<meta charset="UTF-8">

<?php 

	require_once('db.php');
	 require_once('../convert_marathi.php');
	 ################################################### Dispatch DB ###############################################################
	
	 function GetImageExtension($imagetype)
    {
       if(empty($imagetype)) return false;
       switch($imagetype)
       {
           case 'image/bmp': return '.bmp';
           case 'image/gif': return '.gif';
           case 'image/jpeg': return '.jpg';
           case 'image/png': return '.png';
		    case 'image/pdf': return '.pdf';
           default: return false;
       }
    }
	
	$id=$_GET['no'];
	$num1=$_REQUEST['num'];
	$usertype=$_POST['usertype']; //same other 
	$dispa_via=$_POST['dispatchtype'];
	
	$dispato=$_POST['dispatchmethod'];// dept or permanent
	$addressed_to=$_POST['name'];
	$sameemail=$_POST['sameemailid'];
	$ltrid=$_POST['ltrid'];
	$sameaddress=$_POST['sameadd'];
	$path=$_POST['path'];
	
	//other
	$addressed_toother=$_POST['othername'];
	$email=$_POST['emailid'];
	$address=$_POST['add'];
	$deptid=$_POST['deptid'];
	$curdeptid=$_POST['curdeptid'];
	
	$vargawariii=$_POST['ltrtype'];
	
	/////// to desk
	$curdeskid=$_POST['curdeskid'];
	$deskid=$_POST['deskid'];
	################################ file upload#######################################
		if (!empty($_FILES["uploadedimage"]["name"])) 
		{
			$file_name=$_FILES["uploadedimage"]["name"];
			//echo $file_name;
			$temp_name=$_FILES["uploadedimage"]["tmp_name"];
			$imgtype=$_FILES["uploadedimage"]["type"];
			$ext= GetImageExtension($imgtype);
			$imagename=$file_name;
			$target_path = "../uploads/".$imagename;
			if(!move_uploaded_file($temp_name, $target_path))//if file moved successfully	
			{
				echo "<script type='text/javascript'>alert('Unable to move file!')</script>";
				echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';	
			}
			else
			{
				move_uploaded_file($temp_name, $target_path);
			}
		}
		else{
		$target_path = "";
		}
		################################ end of file upload #######################################
		
	
				/*********************************************
						fetching records			
				**********************************************/
				$qry1=("SELECT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_dt, t.dpt_inword_no, t.desk_id, t.dept_id_from, i.subject,de.ltr_rej_id, de.update_date, de.dispatched_dt, de.ltr_approval,de.vargawari , de.ltr_status, i.sender_name, i.ltr_id, i.ltr_inword_no, i.receive_dt, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, de.ltr_category, de.assign_no
				FROM desk_transaction de,incoming_letters_transaction i,tapal_to_dpt_transaction t 
				where de.desk_ltr_id='$id' 
				AND t.dpt_ltr_id=de.dpt_ltr_id 
				AND t.ltr_id=i.ltr_id");
				$rs1=mysql_query($qry1) or die("abababab".mysql_error());
				$rw1=mysql_fetch_array($rs1);
				$deskinward=$rw1['desk_ltr_inword_no'];
				$ltrinwordno=$rw1['ltr_inword_no'];
			
				//echo $vargawariii."xxxxxxxxxxxx";
				/**********************************************
							Insert Query for same user name 
				***********************************************/
				if($usertype=='same' && $dispato=='permanent' && $rw1['ltr_rej_id']=='0')
				{	
					if($addressed_to!='')
					{ 
						if(($dispa_via=='email' && $sameemail!='' ) || ($dispa_via=='post' && $sameaddress!='') || ($dispa_via=='emailpost' && $sameaddress!='' && $sameemail!=''))
						{
							
							convert_marathi();
							if($vargawariii=='ब')
							{
								//$futureDate=date('Y-m-d', strtotime('+30 year'));
								$now23 =date('Y')+30;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क')
							{
								$now23 =date('Y')+10;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क१')
							{
								$now23 =date('Y')+5;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='ड')
							{
								$now23 =date('Y')+1;
								$futureDate =$now23.'-'.date('m-d');
							}
							
							$qry2=("INSERT INTO dispatched_transaction (outword_no, desk_inward_no, dispatched_via, dispatched_to, dept_id_from, addressed_to, email_id, address,ltr_id, desk_ltr_id) VALUES('$ltrinwordno','$deskinward','$dispa_via','$dispato','$curdeptid','$addressed_to','$sameemail','$sameaddress','$ltrid','$id')") or die("".mysql_error());
							 
							$qry3=("UPDATE desk_transaction de,tapal_to_dpt_transaction t SET t.desk_approval='dispatched', de.dispatched_dt=curdate(),de.nasti_nashta_dt='$futureDate', de.scan_doc='$target_path', de.ltr_status='dispatched' 
							WHERE de.desk_ltr_id='$id'  
							AND t.dpt_ltr_id=de.dpt_ltr_id");
						/*	echo "UPDATE desk_transaction de,tapal_to_dpt_transaction t SET t.desk_approval='dispatched', de.dispatched_dt=curdate(),de.nasti_nashta_dt='$futureDate', de.scan_doc='$target_path', de.ltr_status='dispatched' 
							WHERE de.desk_ltr_id='$id'  
							AND t.dpt_ltr_id=de.dpt_ltr_id"; */
						
							$qry=("UPDATE desk_transaction SET vargawari='$vargawariii' WHERE desk_ltr_id='$id' ");
							mysql_query($qry) or die("axcdsw".mysql_error());
							if(mysql_query($qry2))
							{  	
								mysql_query($qry3) or die("error".mysql_error());
										
								echo "<script type='text/javascript'>alert('Action Performed Successfully!')</script>";
								//////////
								if(mysql_query($qry3))
								{
									
								$qrye =mysql_query("SELECT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to, di.email_id, de.ltr_category, de.assign_no FROM dispatched_transaction as di, desk_transaction as de, incoming_letters_transaction as i, tapal_to_dpt_transaction AS t WHERE di.dispatched_to='permanent' and i.ltr_id=t.ltr_id AND t.dpt_ltr_id=de.dpt_ltr_id AND de.desk_ltr_id=di.desk_ltr_id AND di.desk_ltr_id=de.desk_ltr_id AND di.desk_ltr_id='$id' ") or die("error".mysql_error());
								
							while($rw=mysql_fetch_array($qrye))	 
							{	
								
								$nuk=$rw['desk_ltr_id'];
								$refdt = strtotime($rw['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rw['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);
								$outdt = strtotime($rw['dispatched_dt']);
								$dispatchdt= date('d-m-Y', $outdt);
								$did=$rw['dept_id_from'];
								$dpt=mysql_query("SELECT dept_nm from department_master WHERE dept_id='$did'");
								$dptnm=mysql_fetch_array($dpt);
								
								##############################################################################
									// if taken action is approved assign flag=true
								###############################################################################
															
								$path=$rw['scan_doc'];
								//echo "sssssssssss".$rw['email_id'];
								$str2 = substr($path, 1);
								//echo "path is".$str2;
																
								$sameemail=$rw['email_id'];
							
								//////////////////////////   eMAIL SENDING ///////////////////////////////////////	
								require_once('../PHPMailer/class.phpmailer.php');
								require_once("../PHPMailer/class.smtp.php");
								require_once("../PHPMailer/class.pop3.php");
								
								//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
								// in sms sending put path from /../..
								
												if($rw['scan_doc']!='')
												{	
											
													$path=$rw['scan_doc'];// full path of file 
													$str3 = substr($path, 3);// necssary path of file 
													$filename = basename($path); 	

													$email = new PHPMailer();
													$email->From      = ' पोलीस अधिक्षक कार्यालय, <splendid@gains.nanodnscloud.com>';
													//$email->FromName  = 'Your Name';
													$email->Subject   = 'Action taken on Ref. no-'. $rw['ref_no'];

													$email->isHTML(true);
													$message = '<html><body>';
													$message .= '<table border=1px><tr>
																<th>नाव </th>
																<th>आवक क्रमांक</th>
																<th>आवक दिनांक</th>
																<th> संदर्भ क्रमांक </th>
																<th>संदर्भ दिनांक </th>
																<th>विषय</th>
																<th>विभागाचे नाव</th>
																<th>केलेली कार्यवाही</th>
																<th> जावक क्रमांक </th>
																<th> जावक दिनांक </th>
															</tr>
															<tr>
																<td>'.$rw['sender_name'].'</td>
																<td>'.$rw['ref_no'].'</td>
																<td>'.$refdt1.'</td>
																<td>'.$rw['ltr_inword_no'].'</td>
																<td>'.$recdt1.'</td>
																<td>'.$rw['subject'].'</td>
																<td>'.$dptnm['dept_nm'].'</td>
																<td>'.$rw['action_taken'].'</td>
																<td>'.$rw['outword_no'].'</td>
																<td>'.$dispatchdt.'</td>
															</tr> </table>';
													$message .= '</body></html>';
													
													$email->Body      = $message;
													$email->AddAddress($rw['email_id']);

													//$file_to_attach = '../uploads/file_nt_uploaded.jpg';

													$email->AddAttachment( $path , $filename );

													if($email->Send())
													{
														echo "<script type='text/javascript'>alert('Email send successfully!')</script>";
													}
													else
													{
														echo "<script type='text/javascript'>alert('Error in email sending!')</script>";
													}
													
													echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
												}//if scan_doc!=''
												else 
												{
													$email = new PHPMailer();
													$email->From      = ' पोलीस अधिक्षक कार्यालय, <splendid@gains.nanodnscloud.com>';
													//$email->FromName  = 'Your Name';
													$email->Subject   = 'Action taken on Ref. no-'. $rw['ref_no'];

													$email->isHTML(true);
													$message = '<html><body>';
													$message .= '<table border=1px><tr>
																<th>नाव </th>
																<th>आवक क्रमांक</th>
																<th>आवक दिनांक</th>
																<th> संदर्भ क्रमांक </th>
																<th>संदर्भ दिनांक </th>
																<th>विषय</th>
																<th>विभागाचे नाव</th>
																<th>केलेली कार्यवाही</th>
																<th> जावक क्रमांक </th>
																<th> जावक दिनांक </th>
															</tr>
															<tr>
																<td>'.$rw['sender_name'].'</td>
																<td>'.$rw['ref_no'].'</td>
																<td>'.$refdt1.'</td>
																<td>'.$rw['ltr_inword_no'].'</td>
																<td>'.$recdt1.'</td>
																<td>'.$rw['subject'].'</td>
																<td>'.$dptnm['dept_nm'].'</td>
																<td>'.$rw['action_taken'].'</td>
																<td>'.$rw['outword_no'].'</td>
																<td>'.$dispatchdt.'</td>
															</tr> </table>';
													$message .= '</body></html>';
													
													$email->Body      = $message;
													$email->AddAddress($rw['email_id']);
													
													if($email->Send())
													{
														echo "<script type='text/javascript'>alert('Email send successfully!')</script>";
													}
													else
													{
														echo "<script type='text/javascript'>alert('Error in email sending!')</script>";
													}
													
												echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
												}
											
									}  //while
								} 
								
								
							}
							else
							{   
								echo "<script type='text/javascript'>alert('Problem to perform action1!')</script>";
								echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
							}
						}/////////////
						else
						{
							echo "<script type='text/javascript'>alert('Problem to perform action2!')</script>";
							echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
						}
					}
					else
					{   
						echo "<script type='text/javascript'>alert('Problem to perform action3!')</script>";
						echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
					}
				}
				
				
				#################################################################################################
				
				
				#################################################################################################
				if($usertype=='same' && $dispato=='permanent' && $rw1['ltr_rej_id']!='0')
				{	
					if($addressed_to!='')
					{
						if(($dispa_via=='email' && $sameemail!='' ) || ($dispa_via=='post' && $sameaddress!='') || ($dispa_via=='emailpost' && $sameaddress!='' && $sameemail!=''))
						{
						convert_marathi();
						if($vargawariii=='ब')
							{
								//$futureDate=date('Y-m-d', strtotime('+30 year'));
								$now23 =date('Y')+30;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क')
							{
								$now23 =date('Y')+10;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क१')
							{
								$now23 =date('Y')+5;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='ड')
							{
								$now23 =date('Y')+1;
								$futureDate =$now23.'-'.date('m-d');
							}
							
						$qry2=mysql_query("UPDATE dispatched_transaction SET dispatched_via='$dispa_via',dispatched_to='$dispato',dept_id_from='$curdeptid',addressed_to='$addressed_to',email_id='$sameemail', address='$sameaddress' WHERE desk_ltr_id='$id'") or die("".mysql_error());
						 
					
						$qry3=("UPDATE desk_transaction de,tapal_to_dpt_transaction t SET t.desk_approval='dispatched', de.dispatched_dt=curdate(),de.nasti_nashta_dt='$futureDate', de.scan_doc='$target_path', de.ltr_status='dispatched' 
						WHERE de.desk_ltr_id='$id'  
						AND t.dpt_ltr_id=de.dpt_ltr_id");
						
						$qry=("UPDATE desk_transaction SET vargawari='$vargawariii' WHERE desk_ltr_id='$id' ");
						mysql_query($qry) or die("axcdsw".mysql_error());
						
						if(mysql_query($qry2))
							{  	
								mysql_query($qry3) or die("error".mysql_error());
								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 action1!')</script>";
								echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
							}
						}
						else
						{
							echo "<script type='text/javascript'>alert('Problem to perform action2!')</script>";
								echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
						}
					}
					else
					{   
						echo "<script type='text/javascript'>alert('Problem to perform action3!')</script>";
						echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
					}
					
				}
				
				######################################################################################################
				
				######################################################################################################
				
				else if($usertype=='other' && $dispato=='permanent' && $rw1['ltr_rej_id']!='0')
				{
					if($addressed_toother!='')
					{
						if(($dispa_via=='email' && $email!='' ) || ($dispa_via=='post' && $address!='') || ($dispa_via=='emailpost' && $address!='' && $email!=''))
						{
						convert_marathi();
						if($vargawariii=='ब')
							{
								//$futureDate=date('Y-m-d', strtotime('+30 year'));
								$now23 =date('Y')+30;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क')
							{
								$now23 =date('Y')+10;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क१')
							{
								$now23 =date('Y')+5;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='ड')
							{
								$now23 =date('Y')+1;
								$futureDate =$now23.'-'.date('m-d');
							}
							
						$qry2=("UPDATE dispatched_transaction SET dispatched_via='$dispa_via', dispatched_to='$dispato', dept_id_from='$curdeptid', addressed_to='$addressed_toother', email_id='$email', address='$address' WHERE desk_ltr_id='$id'") or die("".mysql_error());		
					
						$qry3=("UPDATE desk_transaction,tapal_to_dpt_transaction SET tapal_to_dpt_transaction.desk_approval='dispatched', desk_transaction.scan_doc='$target_path', desk_transaction.dispatched_dt=curdate(),desk_transaction.nasti_nashta_dt='$futureDate',desk_transaction.ltr_status='dispatched' WHERE desk_transaction.desk_ltr_id='$id'  AND tapal_to_dpt_transaction.dpt_ltr_id=desk_transaction.dpt_ltr_id");
						
						$qry=("UPDATE desk_transaction SET vargawari='$vargawariii' WHERE desk_ltr_id='$id' ");
						mysql_query($qry) or die("axcdsw".mysql_error());
							
						if(mysql_query($qry2))
						{
							mysql_query($qry3) or die("Error:101".mysql_error());
							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 action1!')</script>";
							echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
			
						}				
					}
					else
					{
						echo "<script type='text/javascript'>alert('Problem to perform action2!')</script>";
							echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
					}
				}
					else
					{   
						echo "<script type='text/javascript'>alert('Problem to perform action!')</script>";
						echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
					}
					
				}
				
				
				
		
					/**********************************************
							Insert Query for other user name 
				***********************************************/
				else if($usertype=='other' && $dispato=='permanent' && $rw1['ltr_rej_id']=='0')
				{
					if($addressed_toother!='')
					{
						if(($dispa_via=='email' && $email!='' ) || ($dispa_via=='post' && $address!='') || ($dispa_via=='emailpost' && $address!='' && $email!=''))
						{
							convert_marathi();	
						if($vargawariii=='ब')
							{
								//$futureDate=date('Y-m-d', strtotime('+30 year'));
								$now23 =date('Y')+30;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क')
							{
								$now23 =date('Y')+10;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क१')
							{
								$now23 =date('Y')+5;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='ड')
							{
								$now23 =date('Y')+1;
								$futureDate =$now23.'-'.date('m-d');
							}

							$qry2=("INSERT INTO dispatched_transaction(outword_no, desk_inward_no,dispatched_via ,dispatched_to, dept_id_from, addressed_to, email_id, address, ltr_id, desk_ltr_id) VALUES('$ltrinwordno','$deskinward','$dispa_via','$dispato','$curdeptid','$addressed_toother','$email','$address','$ltrid','$id')") or die("".mysql_error());
					
					
							$qry3=("UPDATE desk_transaction de,tapal_to_dpt_transaction t SET t.desk_approval='dispatched', de.dispatched_dt=curdate(), de.nasti_nashta_dt='$futureDate', de.scan_doc='$target_path', de.ltr_status='dispatched' 
							WHERE de.desk_ltr_id='$id' 
							AND t.dpt_ltr_id=de.dpt_ltr_id");
							
							$qry=("UPDATE desk_transaction SET vargawari='$vargawariii' WHERE desk_ltr_id='$id'  ");
							mysql_query($qry) or die("axcdsw".mysql_error());
							
							if(mysql_query($qry2))
							{	
								mysql_query($qry3) or die("error".mysql_error());
								echo "<script type='text/javascript'>alert('Action Performed Successfully!')</script>";
								//////////
							if(mysql_query($qry3))
							{
								$qrye =mysql_query("SELECT de.desk_ltr_id, de.desk_id_from, de.action_taken, de.desk_ltr_rec_dt, de.desk_ltr_inword_no, i.ltr_type, t.dpt_inword_no, t.dpt_ltr_id, t.dpt_ltr_rec_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, t.sent_to_desk_dt, i.ref_dt, i.ref_no, i.dept_id, i.document, de.scan_doc, di.outword_no,  di.dispatched_to, i.sent_dt, di.dispatched_to, di.email_id, de.ltr_category, de.assign_no FROM dispatched_transaction as di, desk_transaction as de, incoming_letters_transaction as i, tapal_to_dpt_transaction AS t WHERE di.dispatched_to='permanent' and i.ltr_id=t.ltr_id AND t.dpt_ltr_id=de.dpt_ltr_id AND de.desk_ltr_id=di.desk_ltr_id AND di.desk_ltr_id=de.desk_ltr_id AND di.desk_ltr_id='$id' ") or die("error".mysql_error());
								
								
							while($rw=mysql_fetch_array($qrye))	 
							{	
								
								$nuk=$rw['desk_ltr_id'];
								$refdt = strtotime($rw['ref_dt']);
								$refdt1= date('d-m-Y', $refdt);
								$recdt = strtotime($rw['receive_dt']);
								$recdt1= date('d-m-Y', $recdt);
								$outdt = strtotime($rw['dispatched_dt']);
								$dispatchdt= date('d-m-Y', $outdt);
								$did=$rw['dept_id_from'];
								$dpt=mysql_query("SELECT dept_nm from department_master WHERE dept_id='$did'");
								$dptnm=mysql_fetch_array($dpt);
								##############################################################################
									// if taken action is approved assign flag=true
								###############################################################################
															
								$path=$rw['scan_doc'];
								//echo "sssssssssss".$rw['email_id'];
								$str2 = substr($path, 1);
								//echo "path is".$str2;
																
								$sameemail=$rw['email_id'];
							
								//////////////////////////   eMAIL SENDING ///////////////////////////////////////	
								require_once('../PHPMailer/class.phpmailer.php');
								require_once("../PHPMailer/class.smtp.php");
								require_once("../PHPMailer/class.pop3.php");
								
								//$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
								// in sms sending put path from /../..
								
												if($rw['scan_doc']!='')
												{	
													$path=$rw['scan_doc'];// full path of file 
													$str3 = substr($path, 3);// necssary path of file 
													$filename = basename($path); 	

													$email = new PHPMailer();
													$email->From      = ' पोलीस अधिक्षक कार्यालय, <splendid@gains.nanodnscloud.com>';
													//$email->FromName  = 'Your Name';
													$email->Subject   = 'Action taken on Ref. no-'. $rw['ref_no'];

													$email->isHTML(true);
													$message = '<html><body>';
													$message .= '<table border=1px><tr>
																<th>नाव </th>
																<th>आवक क्रमांक</th>
																<th>आवक दिनांक</th>
																<th> संदर्भ क्रमांक </th>
																<th>संदर्भ दिनांक </th>
																<th>विषय</th>
																<th>विभागाचे नाव</th>
																<th>केलेली कार्यवाही</th>
																<th> जावक क्रमांक </th>
																<th> जावक दिनांक </th>
															</tr>
															<tr>
																<td>'.$rw['sender_name'].'</td>
																<td>'.$rw['ref_no'].'</td>
																<td>'.$refdt1.'</td>
																<td>'.$rw['ltr_inword_no'].'</td>
																<td>'.$recdt1.'</td>
																<td>'.$rw['subject'].'</td>
																<td>'.$dptnm['dept_nm'].'</td>
																<td>'.$rw['action_taken'].'</td>
																<td>'.$rw['outword_no'].'</td>
																<td>'.$dispatchdt.'</td>
															</tr> </table>';
													$message .= '</body></html>';
													
													$email->Body      = $message;
													$email->AddAddress($rw['email_id']);

													//$file_to_attach = '../uploads/file_nt_uploaded.jpg';

													$email->AddAttachment( $path , $filename );

													if($email->Send())
													{
														echo "<script type='text/javascript'>alert('Email send successfully!')</script>";
													}
													else
													{
														echo "<script type='text/javascript'>alert('Error in email sending!')</script>";
													}
													
													echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
													
												}//if scan_doc!=''
												
												else 
												{	
													$email = new PHPMailer();
													$email->From      = ' पोलीस अधिक्षक कार्यालय, <splendid@gains.nanodnscloud.com>';
													//$email->FromName  = 'Your Name';
													$email->Subject   = 'Action taken on Ref. no-'. $rw['ref_no'];

													$email->isHTML(true);
													$message = '<html><body>';
													$message .= '<table border=1px><tr>
																<th>नाव </th>
																<th>आवक क्रमांक</th>
																<th>आवक दिनांक</th>
																<th> संदर्भ क्रमांक </th>
																<th>संदर्भ दिनांक </th>
																<th>विषय</th>
																<th>विभागाचे नाव</th>
																<th>केलेली कार्यवाही</th>
																<th> जावक क्रमांक </th>
																<th> जावक दिनांक </th>
															</tr>
															<tr>
																<td>'.$rw['sender_name'].'</td>
																<td>'.$rw['ref_no'].'</td>
																<td>'.$refdt1.'</td>
																<td>'.$rw['ltr_inword_no'].'</td>
																<td>'.$recdt1.'</td>
																<td>'.$rw['subject'].'</td>
																<td>'.$dptnm['dept_nm'].'</td>
																<td>'.$rw['action_taken'].'</td>
																<td>'.$rw['outword_no'].'</td>
																<td>'.$dispatchdt.'</td>
															</tr> </table>';
													$message .= '</body></html>';
													
													$email->Body      = $message;
													$email->AddAddress($rw['email_id']);

													//$file_to_attach = '../uploads/file_nt_uploaded.jpg';

													$email->AddAttachment( $path , $filename );

													if($email->Send())
													{
														echo "<script type='text/javascript'>alert('Email send successfully!')</script>";
													}
													else
													{
														echo "<script type='text/javascript'>alert('Error in email sending!')</script>";
													}
													echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
												}
								}								
							}
							
						}
						else
						{   
								echo "<script type='text/javascript'>alert('Problem to perform action1!')</script>";
								echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
					
						}
					}/////////////
					else
					{
						echo "<script type='text/javascript'>alert('Problem to perform action2!')</script>";
						echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
					}
				}
				else
				{   
					echo "<script type='text/javascript'>alert('Problem to perform action3!')</script>";
					echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
				}
							
			}
				
				/**********************************************
							Insert Query for dept name 
				***********************************************/
				else if($dispato=='department')
				{
					convert_marathi();
							if($vargawariii=='ब')
							{
								//$futureDate=date('Y-m-d', strtotime('+30 year'));
								$now23 =date('Y')+30;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क')
							{
								$now23 =date('Y')+10;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क१')
							{
								$now23 =date('Y')+5;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='ड')
							{
								$now23 =date('Y')+1;
								$futureDate =$now23.'-'.date('m-d');
							}
							
					$qry2=("INSERT INTO dispatched_transaction(outword_no, desk_inward_no, dispatched_via, dispatched_to, dept_id_from, dept_id_to, addressed_to, email_id, address, ltr_id,desk_ltr_id) VALUES('$ltrinwordno','$deskinward','$dispa_via','$dispato','$curdeptid','$deptid','$addressed_toother','$email','$address','$ltrid','$id')") or die("".mysql_error());
					
					$qry=("UPDATE desk_transaction SET vargawari='$vargawariii' WHERE desk_ltr_id='$id' ");
					mysql_query($qry) or die("axcdsw".mysql_error());
						
					 if(mysql_query($qry2))
						{  	
							$qry3=("UPDATE desk_transaction SET dispatched_dt=curdate(),nasti_nashta_dt='$futureDate',ltr_status='dispatched' ,desk_transaction.ltr_approval='transferred' WHERE desk_ltr_id=$id");
							if(mysql_query($qry3)) 
							{
								$qry23=("UPDATE incoming_letters_transaction, desk_transaction, tapal_to_dpt_transaction SET incoming_letters_transaction.dept_id='$deptid', tapal_to_dpt_transaction.status='approve', incoming_letters_transaction.status='pending' WHERE incoming_letters_transaction.ltr_id=tapal_to_dpt_transaction.ltr_id AND tapal_to_dpt_transaction.dpt_ltr_id=desk_transaction.dpt_ltr_id AND desk_transaction.desk_ltr_id='$id'") or die("".mysql_error());
								mysql_query($qry23) or die("error".mysql_error());
							}
							else
							{
								$qry3=("UPDATE desk_transaction SET dispatched_dt='',ltr_status='approve' ,desk_transaction.ltr_approval='' WHERE desk_ltr_id=$id");
								mysql_query($qry3) or die("error".mysql_error());
							}
					
							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!')</script>";
							echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
			
						}
				}
				
				/**********************************************
							Insert Query for desk name 
				***********************************************/
				else if($dispato=='desk')
				{
					convert_marathi();
							if($vargawariii=='ब')
							{
								//$futureDate=date('Y-m-d', strtotime('+30 year'));
								$now23 =date('Y')+30;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क')
							{
								$now23 =date('Y')+10;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='क१')
							{
								$now23 =date('Y')+5;
								$futureDate =$now23.'-'.date('m-d');
							}
							else if($vargawariii=='ड')
							{
								$now23 =date('Y')+1;
								$futureDate =$now23.'-'.date('m-d');
							}
							
					$qry2=("INSERT INTO dispatched_transaction(outword_no, desk_inward_no, dispatched_via, dispatched_to, dsk_id_from, dsk_id_to, addressed_to, email_id, address, ltr_id,desk_ltr_id) VALUES('$ltrinwordno','$deskinward','$dispa_via','$dispato','$curdeskid','$deskid','$addressed_toother','$email','$address','$ltrid','$id')");
					
					$qry=("UPDATE desk_transaction SET vargawari='$vargawariii' WHERE desk_ltr_id='$id' ");
					mysql_query($qry) or die("axcdsw".mysql_error());
						
					 if(mysql_query($qry2))
						{  	
							$qry3=("UPDATE desk_transaction SET dispatched_dt=curdate(),nasti_nashta_dt='$futureDate',ltr_status='dispatched' ,desk_transaction.ltr_approval='transferred_todesk' WHERE desk_ltr_id=$id");
							if(mysql_query($qry3)) 
							{
								$qry23=("UPDATE incoming_letters_transaction i, desk_transaction d, tapal_to_dpt_transaction t 
								SET t.desk_id='$deskid', t.desk_approval='pending'
								WHERE i.ltr_id=t.ltr_id 
								AND t.dpt_ltr_id=d.dpt_ltr_id 
								AND d.desk_ltr_id='$id'") or die("".mysql_error());
								mysql_query($qry23) or die("error".mysql_error());
							}
							else
							{
								$qry3=("UPDATE desk_transaction SET dispatched_dt='',ltr_status='approve' ,desk_transaction.ltr_approval='' WHERE desk_ltr_id=$id");
								mysql_query($qry3) or die("error".mysql_error());
							}
					
							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 action000!')</script>";
							echo '<script language="JavaScript"> window.location.href ="../desk_action_perform.php" </script>';
			
						}
				}
			?>
</html>