<?php
include_once("class/class.MySQL.php");
$db	=new MySQL();
$action = $_GET['act'];
$branchid = $_GET['branchid'];
$loggedUserId = $_GET['loggedUserId'];
if($action == "list"){
	//echo "<br />ID IS : ".$loggedUserID;
	/*	if($loggedUserId == '1'){
		$holidayes = $db->fetchQuery("SELECT id as id, date as start, count(title) as title FROM `payroll_holiday_calendar` WHERE `is_blocked` = '0' AND employee_id = '".$loggedUserId."' GROUP BY start ");
		echo json_encode($holidayes);	
	}else{
		$holidayes = $db->fetchQuery("SELECT id as id, date as start, count(title) as title FROM `payroll_holiday_calendar` WHERE `is_blocked` = '0' AND employee_id = '".$loggedUserId."' AND employee_id = '1' GROUP BY start ");
		echo json_encode($holidayes);	
	}*/
	if($loggedUserId == '1'){
		$holidayes = $db->fetchQuery("SELECT id as id, date as start,title as titles, count(title) as title FROM `payroll_holiday_calendar` WHERE `is_blocked` = '0' AND employee_id = '1' GROUP BY start ");
	}else{
		$holidayes = $db->fetchQuery("SELECT id as id, date as start,title as titles, count(title) as title FROM `payroll_holiday_calendar` WHERE `is_blocked` = '0' GROUP BY start ");	
	}
	echo json_encode($holidayes);
}
elseif($action == 'update'){
	//$set['title']	= $_GET['title'];
	$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']));
	$db->Insert($data,'payroll_holiday_calendar');

}elseif($action == "remove"){

	$where['id'] = $_GET['id'];
	
	$set['is_blocked'] = 1;
	$db->Update('payroll_holiday_calendar',$set,$where);
}



?>