<?php
/*
* date last modified 28-11-2017
* Edited by PI-Digi Logical Solutions
* HTML Files - add_user.html.php
* Mysql Tables - tbl_designation, tbl_staff
*/
include('includes/imgFunctions.php');
include('includes/functions.php'); # general functions

$isEdit = FALSE;
$debug = true;
$curDate = date('Y-m-d H:i:s');

if(isset($_REQUEST['p'])){
	$p = trim($_REQUEST['p']);
} else {
	$p = 1;
}

$typeRs = mysqli_query($con, "SELECT id, name FROM tbl_task_types ORDER BY name");


if(isset($_REQUEST['id']) && $_REQUEST['id']!=''){
	
	$isEdit = TRUE;
	$editId = mysqli_real_escape_string($con, trim($_REQUEST['id']));	
	$editRs = mysqli_query($con, "SELECT * FROM tbl_project WHERE id = '".$editId."'");
	if(mysqli_num_rows($editRs)>0){
		$resEdit = mysqli_fetch_array($editRs);
	} else {
		$error = 'Project does not exist!';
	}

} 

if(isset($_POST['add'])) {
	
	if(isset($_POST['date']) && strlen($_POST['date'])>0) {
		$date = trim($_POST['date']);
	} else {
		$error = 'Please select date';
	}
		
	if(empty($error)) {
						
		/* Adding New staff Details */		
		$insertQry = "INSERT INTO tbl_holidays (date, added_by) VALUES ('".mysqli_real_escape_string($con, $date)."', '".$_SESSION['adminId']."')";
		$execInsert = mysqli_query($con,$insertQry);
		$insert_id = mysqli_insert_id($con);		
		
		if($execInsert) {
					
			$success = 'Holiday Added Successfully';
			header('Location:index.php?page=holidays&p='.$p.'&success='.$success);
			exit();			
		}				
	} 
}

if(isset($_POST['update'])) {
	
	if(isset($_POST['date']) && strlen($_POST['date'])>0) {
		$date = trim($_POST['date']);
	} else {
		$error = 'Please select date';
	}		
	
	if(empty($error)) {
				
		$updateQry = "UPDATE tbl_holidays SET date = '".$date."', updated_by = '".$_SESSION['adminId']."' WHERE id = '".$editId."'";
		
		$execUpdate = mysqli_query($con,$updateQry);			
		
		if($execUpdate) {
			$success = 'Holiday Updated Successfully';
			header('Location:index.php?page=holidays&p='.$p.'&success='.$success);
			exit();			
		}				
	} 
}

?>