<?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['emply_stat']		=$_POST['stat'];


$db->Insert($data,'emp_status');
$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['emply_stat']		=$_POST['reportime'];


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

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

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

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

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

	 $query = "SELECT * FROM emp_status";
	


include "pagingserch.php";

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

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


$pagecnt=$start;




	$timing = $db->fetchQuery("SELECT * FROM emp_status ");
	


	
	$count = count($timing);
	$timing[$count-1]['totalrows'] = $total_pages;
	$timing[$count-1]['lastPage'] = $lastpage;
	
	
	echo '{"timing":'.json_encode($timing).'}';
	}
	
			
if($_GET['action']=='removeded')
{
$where['id']	= $_GET['did'];
	
$deductions = $db->Delete('emp_status',$where);

}

if($_GET['action']=='gratuty')
{

	 $query = "SELECT * FROM gratuity_setyear";
	


include "pagingserch.php";

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

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


$pagecnt=$start;




	$timing = $db->fetchQuery("SELECT * FROM gratuity_setyear ");
	


	
	$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='GratuityYear' 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['action']=='grt_insert')
{
// add data to  employee

$resultdsg = mysql_query("SELECT * FROM gratuity_setyear where year_from='$_POST[yr_frm]' and year_to='$_POST[yr_to]' and num_days='$_POST[numdays]' ");
$rowsd = mysql_num_rows($resultdsg);

if($rowsd > 0)
{

$vars['year_from']='Already Saved Data';
echo '{"timing":'.json_encode($vars).'}';
}
else
{

$data=array();



$data['year_from']		=$_POST['yr_frm'];
$data['year_to']		=$_POST['yr_to'];
$data['num_days']		=$_POST['numdays'];
$data['emp_status']		=$_POST['empname'];
$data['time_period']		=$_POST['yearp'];
$db->Insert($data,'gratuity_setyear');
$data['id'] =$db->LastInsertID();
	
echo '{"timing":'.json_encode($data).'}';
}

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

$data['year_from']		=$_POST['yr_frm'];
$data['year_to']		=$_POST['yr_to'];
$data['num_days']		=$_POST['numdays'];
$data['emp_status']		=$_POST['empname'];
$data['time_period']		=$_POST['yearp'];

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

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

}


if($_GET['action']=='removegrtyr')
{
$where['id']	= $_GET['did'];
	
$deductions = $db->Delete('gratuity_setyear',$where);

}



if($_GET['action']=='lev_track')
{


	$sub_rights=mysql_fetch_array(mysql_query("select * from menu as m,menu_sub as s where  s.s_menu_name='addNewpersonalLeaveRequest' and m.menu_id=s.menu_id "));
	
	$userid=$_SESSION['admin_id'];

	$where['user_id']	= $userid;
	$where['s_submenu_id']	= $sub_rights['s_id'];
	if($userid==1)
	{
	$timing = array("user_id"=>$userid);
	}
	else
	{
	$timing =  $db->Select("tbl_user_rights",$where);
	}
	
	
	echo '{"timing":'.json_encode($timing).'}';
	}

?>