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

<?php ###############################// Add Department Database File#########################################
	require_once('db.php');
	 require_once('../convert_marathi.php');								
	 ###############################	// Add Department Database Code###################################
								

	 if (isset($_POST['save']))
	 {
       $deptnm=$_POST['deptnm'];
	   $desk_flag=$_POST['deptdesk'];
	    mysql_query('SET character_set_results=utf8');
		mysql_query('SET names=utf8');
		mysql_query('SET character_set_client=utf8');
		mysql_query('SET character_set_connection=utf8');
		mysql_query('SET character_set_results=utf8');
		mysql_query('SET collation_connection=utf8_general_ci');
		
		if($desk_flag=='y' || $desk_flag=='Y')
		{
			 $qry=("insert into department_master(dept_nm,desk_flag) values('$deptnm','Y')");
		}
		else if($desk_flag=='n' || $desk_flag=='N')
		{
			 $qry=("insert into department_master(dept_nm,desk_flag) values('$deptnm','N')");
		}
		else
		{
			echo "<script type='text/javascript'>alert('डेस्क जोडणे y/n मध्ये टाका !!!')</script>";
			echo '<script language="JavaScript"> window.location.href ="../adddepartment.php?no=1" </script>';
		}
      
		if(mysql_query($qry))
		{ 
			echo "<script type='text/javascript'>alert('Inserted Successfully!')</script>";
			echo '<script language="JavaScript"> window.location.href ="../adddepartment.php?no=1" </script>';
				
		}
		else
		{   
			echo "<script type='text/javascript'>alert('Problem to insert!')</script>";
			echo '<script language="JavaScript"> window.location.href ="../adddepartment.php?no=1" </script>';
			
		}
	 }
	 	 ################################	End OF Add Department Database Code############################
		 
		 
	 #################################	Update Department Code   ######################################
									
	
	else if(isset($_POST['saveup'])) 
	 {    
		 $deptnm=$_POST['deptnm'];
		 $deptid=$_POST['deptid'];
		 $desk_flag=$_POST['deptdesk'];
		 
		$f=mysql_query("SELECT desk_flag from department_master where dept_id='$deptid' ");
		$r=mysql_fetch_array($f);
		$flag=$r['desk_flag'];
		
		if($flag=='Y' && ($desk_flag=='n' || $desk_flag=='N' ))
		{
			echo "<script type='text/javascript'>alert('डेस्क जोडणे बदलू शकत नाही !!!')</script>";
			echo '<script language="JavaScript"> window.location.href ="../adddepartment.php?no=2" </script>';
		}
		else if($flag=='Y' && ($desk_flag=='y' || $desk_flag=='Y' ))
		{
			convert_marathi();
			$qry1=("UPDATE department_master SET dept_nm = '$deptnm', desk_flag='Y' WHERE dept_id='$deptid'");
			
			if(mysql_query($qry1))
			{   
				echo "<script type='text/javascript'>alert('Updated Successfully!')</script>";
				echo '<script language="JavaScript"> window.location.href ="../adddepartment.php?no=2" </script>';
				
			}
			else
			{   	
				echo "<script type='text/javascript'>alert('Problem to Update!')</script>";
				echo '<script language="JavaScript"> window.location.href ="../adddepartment.php?no=2" </script>';
			
			}
		}
		else if($flag=='N' && ($desk_flag=='y' || $desk_flag=='Y' || $desk_flag=='n' || $desk_flag=='N'))
		{
			convert_marathi();
			if($desk_flag=='y' || $desk_flag=='Y')
			{
				 $qry1=("UPDATE department_master SET dept_nm = '$deptnm', desk_flag='Y' WHERE dept_id='$deptid'");
			}
			else if($desk_flag=='n' || $desk_flag=='N')
			{
				 $qry1=("UPDATE department_master SET dept_nm = '$deptnm', desk_flag='N' WHERE dept_id='$deptid'");
			}
			
			
			if(mysql_query($qry1))
			{   
				echo "<script type='text/javascript'>alert('Updated Successfully!')</script>";
				echo '<script language="JavaScript"> window.location.href ="../adddepartment.php?no=2" </script>';
				
			}
			else
			{   	
				echo "<script type='text/javascript'>alert('Problem to Update!')</script>";
				echo '<script language="JavaScript"> window.location.href ="../adddepartment.php?no=2" </script>';
			
			}
		}
		
		else 
		{
			echo "<script type='text/javascript'>alert('डेस्क जोडणे y/n मध्ये टाका !!!')</script>";
			echo '<script language="JavaScript"> window.location.href ="../adddepartment.php?no=2" </script>';
		}
		
		
		
     }
	  ############################### End Of Update Department Code#######################################
	
?>
</html>
