<?php
@session_start();
include_once("../class/class.MySQL.php");
require '../class/resizeImage.php';
$db	=new MySQL();


if($_GET['action']=='insert')
{
// add data to  employee
$data=array();

$data['brch_id']		=$_POST['branch'];
$data['report_time'] 	=substr($_POST['reportime'], 0, -2);
$data['late_time'] 		=substr($_POST['reportlatetime'], 0, -2);
$data['half_day']		=$_POST['halfday'];
$data['full_day']		=$_POST['fullday'];
$data['time_in']		=substr($_POST['reportime'], -2);

$db->Insert($data,'report_time');
$data['reptime_id'] =$db->LastInsertID();
	
echo '{"timing":'.json_encode($data).'}';
}

if($_GET['action']=='update')
{
/*echo "<pre>";
print_r($_POST);
exit;*/
// add data to  employee
$data=array();

$data['brch_id']		=$_POST['branch'];
$data['report_time'] 	=substr($_POST['reportime'], 0, -2);
$data['late_time'] 		=substr($_POST['reportlatetime'], 0, -2);
$data['half_day']		=$_POST['halfday'];
$data['full_day']		=$_POST['fullday'];
$data['time_in']		=substr($_POST['reportime'], -2);

$where['reptime_id']	= $_POST['reportid'];
$db->Update('report_time',$data,$where);

echo '{"timing":'.json_encode($data).'}';

}
elseif($_GET['action'] == "removeded"){

	$where['reptime_id']	= $_GET['did'];
	$deductions = $db->Delete('report_time',$where);

}
		
if($_GET['action']=='viewtiming')
{

	 $query = "SELECT * FROM report_time";
	


include "pagingserch.php";

$cond.=" LIMIT $start, $limit";

if(isset($_REQUEST['page'])){
$page=$_REQUEST['page'];
}else{
$page=15;
}


$pagecnt=$start;




	$timing = $db->fetchQuery("SELECT * FROM report_time join branches on report_time.brch_id = branches.branch_id");
	


	
	$count = count($timing);
	
	if($count!=0){
	$timing[$count-1]['totalrows'] = $total_pages;
	$timing[$count-1]['lastPage'] = $lastpage;
	}
	
		$sub_rights=mysql_fetch_array(mysql_query("select * from menu as m,menu_sub as s where  s.s_menu_name='ReportTime' and m.menu_id=s.menu_id "));
	
	$userid=$_SESSION['admin_id'];

	$where['user_id']	= $userid;
	$where['s_submenu_id']	= $sub_rights['s_id'];
	
	if(count($timing) !=0){
	if($userid==1)
	{
	$timing[count($timing)-1]['permissions'][0] = array("user_id"=>$userid);
	}
	else
	{
	$timing[count($timing)-1]['permissions'] =  $db->fetchAll("tbl_user_rights",$where);
	}
	}
	echo '{"timing":'.json_encode($timing).'}';
	}
	
			
if($_GET['act']=='removeded')
{
$where['reptime_id']	= $_GET['did'];
	
$deductions = $db->Delete('report_time',$where);

}
?>