<?php
require "commonincludefiles.php";
$x1      = $_POST['x1'];
$y1      = $_POST['y1'];
$width   = $_POST['width'];
$height  = $_POST['height'];
$file    = $_POST['file'];
$actiontype    = $_POST['actiontype'];
//$cropedfile='wastphoto/cropped_pic.jpg';

if($file != "")
{
if($actiontype == 'in')
{
//$srcImg  = imagecreatefromjpeg($file);
//$newImg  = imagecreatetruecolor($width, $height);

//imagecopyresampled($newImg, $srcImg, 0, 0, $x1, $y1, $width, $height, $width, $height);
//imagejpeg($newImg, $cropedfile);
//copy($cropedfile,"inpic/in1.jpg");
$indate=date('d-m-Y');
$inimagedir="studentCapture/";
if (!is_dir($inimagedir)) 
{
	mkdir($inimagedir, 0755);
	chmod($inimagedir, 0755);
}
$inimagepath="studentCapture/student-".time().".jpg";
if (file_exists($inimagepath)) 
{
	unlink($inimagepath);
}
copy($file,$inimagepath);
$inarray=split("/",$file);
$temppath="wastphoto/".$inarray[5];
unlink($temppath);
$totalin=0;
//$inresult=dbQuery("select * from cms_studentmaster where DATE_FORMAT(intime,'%Y/%m/%d')=DATE_FORMAT(CURDATE(), '%Y/%m/%d') and user_id='".$_SESSION['eUserId']."'");
//$totalin=dbRows($inresult);

//if($totalin==0)/
//{
dbQuery("insert into  inout_master set user_id='".$_SESSION['eUserId']."',intime='".Escape(date('Y-m-d H:i:s'))."', inipaddress='".$_SERVER['REMOTE_ADDR']."'");
//}
//echo '{"success":"true","msg":""}';
}
/*else if($actiontype == 'out')
{
//$srcImg  = imagecreatefromjpeg($file);
//$newImg  = imagecreatetruecolor($width, $height);

//imagecopyresampled($newImg, $srcImg, 0, 0, $x1, $y1, $width, $height, $width, $height);
//imagejpeg($newImg, $cropedfile);
//copy($cropedfile,"inpic/out1.jpg");
$outdate=date('d-m-Y');
$outimagedir="outpic/".$outdate;
if (!is_dir($outimagedir)) 
{
	mkdir($outimagedir, 0755);
	chmod($outimagedir, 0755);
}
$outimagepath="outpic/".$outdate."/out_".$_SESSION['eUserId'].".jpg";

if (file_exists($outimagepath)) 
{
	unlink($outimagepath);
}
copy($file,$outimagepath);
$inarray=split("/",$file);
$temppath="wastphoto/".$inarray[5];
unlink($temppath);
dbQuery("update inout_master set outtime='".Escape(date('Y-m-d H:i:s'))."', outipaddress='".$_SERVER['REMOTE_ADDR']."' where user_id='".$_SESSION['eUserId']."'");

//echo '{"success":"true","msg":""}';
}*/
echo '{"success":"true","msg":""}';
}
else
{
echo '{"success":"false","msg":""}';		
}
?>