<?php
	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';
		   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;
       }
    }
	$username=$_GET['username'];
     require_once('db.php');
	 require_once('../convert_marathi.php');
	 
	 ################################# Generating Inward Number #########################################
		################################ file upload#######################################
		if (!empty($_FILES["uploadedimage"]["name"])) 
		{
			$file_name=$_FILES["uploadedimage"]["name"];
			
			$temp_name=$_FILES["uploadedimage"]["tmp_name"];
			$imgtype=$_FILES["uploadedimage"]["type"];
			$ext= GetImageExtension($imgtype);
			$imagename=$file_name;
			
			$temp = explode(".", $_FILES["uploadedimage"]["name"]);
			$newfilename =$recdt.round(microtime(true)) . '.' . end($temp);
			$target_path = "../uploads/".$newfilename;
			
			if($target_path!='')
			{
				if(!move_uploaded_file($temp_name, $target_path))
				 {
						echo "<script type='text/javascript'>alert('Unable to move file!')</script>";
						echo '<script language="JavaScript"> window.location.href ="../direct_javak.php" </script>';
				}
				else
				{
					move_uploaded_file($temp_name, $target_path);
				}
			}
		}
		else
		{
			$target_path = "../uploads/file_nt_uploaded.jpg";
		}
		################################ end of file upload #######################################
		$javak=$_POST['javak'];
		$jdate=$_POST['jdate'];
        $jdate = date('Y-m-d', strtotime($jdate));
		$sp=$_POST['sp'];
		$vibhag=$_POST['vibhag'];
		$othern=$_POST['othern'];
		$sakalan=$_POST['sakalan'];
		$sub=$_POST['sub'];
		if($sp=='dpt')
		{
			$othern='';
		}
		else if($sp=='other')
		{
			$vibhag='';
		}
		
           convert_marathi();	
			$q=mysql_query("SELECT * from login where login_id='$username' ");
			$r=mysql_fetch_array($q);
			$deptid=$r['dept_id'];
			$desk_id=$r['desk_id'];
			
			$curdt=date("Y-m-d");
			$qry=("INSERT into direct_javak(javak_no, javak_dt, actoin, dpt_id, other_nm, sakalan, subject, document,desk_id) values('$javak','$jdate','$sp' ,'$vibhag','$othern','$sakalan','$sub','$target_path','$desk_id')");
			
			if(mysql_query($qry))
			{
				echo "<script type='text/javascript'>alert('Inserted successfully!')</script>";
				echo '<script language="JavaScript"> window.location.href ="../direct_javak.php" </script>';
			}
			else
			{
			
				echo "<script type='text/javascript'>alert('Inserted unsuccessfully!')</script>";
				echo '<script language="JavaScript"> window.location.href ="../direct_javak.php" </script>';
			}
				
?>