<?php

include_once("../class/class.MySQL.php");
$db	=new MySQL();

$action = $_GET['act'];
$branchid = $_GET['branchid'];
if($action == "list"){
//$where['is_blocked'] = 0;

	
	$loggedUserId = $_GET['loggedUserId'];
	//echo "<br />User Id is : ".$loggedUserId;
	//if($loggedUserId == '1'){
		$holidayes = $db->fetchQuery("SELECT id as id, date as start, title as title, color, employee_id as eid FROM `payroll_holiday_calendar` WHERE  branchid='$branchid' ");
	/*}else{

		$holidayes = $db->fetchQuery("SELECT id as id, date as start, title as title, color, employee_id as eid FROM `payroll_holiday_calendar` WHERE ( `employee_id` = '1' OR `employee_id` = '$loggedUserId' ) AND `is_blocked` = '0'  ");	
		
	}*/
	echo json_encode($holidayes);
}
elseif($action == 'update'){

	$set['date']	= date("Y-m-d",strtotime($_GET['start']));
	$where['id']	=$_GET['id'];
	$db->Update('payroll_holiday_calendar',$set,$where);

}elseif($action == 'addNew'){
	$data['title']	= $_GET['title'];
	$data['color']	= $_GET['green'];
	$data['branchid']	= $branchid;
	$data['date']	= date("Y-m-d",strtotime($_GET['start']));
	$data['employee_id'] = $_GET['loggedUserId'];
	$db->Insert($data,'payroll_holiday_calendar');
	$data['id'] = $db->LastInsertID();
	echo json_encode($data);
}elseif($action == "remove"){
	
	$where['id'] = $_GET['id'];
	
	$set['is_blocked'] = 1;
	$db->Update('payroll_holiday_calendar',$set,$where);
}



?>