<?php require_once('../Connections/oprmConn.php'); 







if(!isset($_SESSION['user_id']))







{







	header("location: ../index.php");







}







if(isset($_POST['leave'])){







if($_POST['leave']=='multi') {







//f(isset($_POST['start_date']) && ($_POST['end_date'])) {







$sd = date("Y-m-d",strtotime($_POST['start_date']));







$ed = date("Y-m-d",strtotime($_POST['end_date']));





$tl_days = $_POST['leve_days'];







$leave_duration = ((strtotime($ed)- strtotime($sd))/24/3600)+1;







 







$d = date("Y-m-d");





 //$leave_reason = REPLACE("$_POST[leave_reason]", "'", "/'");
    $leave_reason = mysql_real_escape_string(trim($_POST[leave_reason]));
    

 $q = "INSERT INTO weby_leave (`user_id`, `start_date`, `end_date`, `leave_duration`, `leave_type_id`, `leave_reason`, `status`,  `created_date`, `updated_date`) VALUES ('$_SESSION[user_id]', '$sd', '$ed', '$tl_days', '$_POST[leave_type_id]', '$leave_reason', 'P',  '$d', CURRENT_TIMESTAMP)";







mysql_select_db($database_oprmConn, $oprmConn);







$query_getProj = $q;







$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());





}























if($_POST['leave']=='single') {







//if(isset($_POST['start_date']) && ($_POST['end_date'] =="")) {







$sd = date("Y-m-d",strtotime($_POST['start_date']));







//$ed = date("Y-m-d",strtotime($_POST['end_date'])); 







$d = date("Y-m-d");



 //$leave_reason = REPLACE("$_POST[leave_reason]", "'", "/'");
    $leave_reason = mysql_real_escape_string(trim($_POST[leave_reason]));



$q = "INSERT INTO weby_leave (`user_id`, `start_date`,  `leave_duration`, `leave_type_id`, `leave_reason`, `status`,  `created_date`, `updated_date`) VALUES ('$_SESSION[user_id]', '$sd', 1, '$_POST[leave_type_id]', '$leave_reason', 'P', '$d', CURRENT_TIMESTAMP)";







mysql_select_db($database_oprmConn, $oprmConn);







$query_getProj = $q;







$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());























}















































mysql_select_db($database_oprmConn, $oprmConn);







$q = "select max(leave_id) as lid FROM weby_leave where user_id = '$_SESSION[user_id]'";







mysql_select_db($database_oprmConn, $oprmConn);







$query_getProj12 = $q;







$getProj12 = mysql_query($query_getProj12, $oprmConn) or die(mysql_error());







$row_getTime12 = mysql_fetch_assoc($getProj12);







$totalRows_getProj12 = mysql_num_rows($getProj12);















$lid = $row_getTime12['lid'];















mysql_select_db($database_oprmConn, $oprmConn);







$q = "SELECT weby_profiles.full_name, weby_leave.leave_id, weby_leave.start_date, weby_leave.end_date, weby_leave.leave_duration, weby_leave.leave_reason, weby_leave.status, weby_users.email_address FROM weby_profiles, weby_users, weby_leave WHERE weby_leave.leave_id = '$lid ' AND  weby_profiles.user_id = weby_leave.user_id AND weby_leave.user_id = weby_users.user_id";







mysql_select_db($database_oprmConn, $oprmConn);







$query_getProj = $q;







$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());







$row_getTime = mysql_fetch_assoc($getProj);







$totalRows_getProj = mysql_num_rows($getProj);















mysql_select_db($database_oprmConn, $oprmConn);







$query_getProj22 = "select email_address FROM weby_users where user_role = 1";







$getProj22 = mysql_query($query_getProj22, $oprmConn) or die(mysql_error());







$row_getProj22 = mysql_fetch_assoc($getProj22);







$totalRows_getProj22 = mysql_num_rows($getProj22);















$sde = date("d-m-Y",strtotime($row_getTime[start_date]));







if($row_getTime[leave_duration]>1)







{







	$ede = date("d-m-Y",strtotime($row_getTime[end_date]));







}







else







{







	$ede = $sde;







}















 $s = "InActive";







	   if($row_getTime['status']=="A")







	   $s = "Approved";







	   if($row_getTime['status']=="P")







	   $s = "Pending";







	  















	







	$user_email = $row_getTime['email_address'];







	$user_email1 = $row_getProj22['email_address'];







    $headers = 'MIME-Version: 1.0' . "\r\n";







       $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";







       $headers .= "From: $SERVER_EMAIL" . "\r\n" ;







	$subject = "SS WEB TECHNOLOGIES- Leave Application has been submitted successfully";







	$subject1 = "SS WEB TECHNOLOGIES- $row_getTime[full_name]: Leave Application has been submitted"; 







	







	$body1 = "Hi admin,<br>This is to inform you that $row_getTime[full_name] leave request has been submitted. <br";







	$body = "Hi $row_getTime[full_name],<br>This is to inform you that your below leave request has been submitted. <br";







	$t = "br>







<br>		<table width='100%' border='1' cellpadding='5' cellspacing='0'>







<th height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>Leave id







</strong>







<td height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>From Date</strong></td>







<td height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>To Date</strong></td>







<td height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>Duration</strong></td>







<td height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>Reason</strong></td>







<td height='30' align='left' valign='top' bgcolor='#FFCC99'><strong>Status</strong></td>







</th>







<tr align='left' valign='top'>







<td height='30'>$row_getTime[leave_id]</td>







<td height='30'>$sde</td>







<td height='30'>$ede</td>







<td height='30'>$row_getTime[leave_duration]</td>







<td height='30'>$row_getTime[leave_reason]</td>







<td height='30'>$s</td>







</tr>







</table>















<br>







	If you have any queries, please contact admin.







	<br>







	Thanks,<br>







	SS WEB TECHNOLOGIES";







	$body .= $t;







	$body1 .= $t;







	mail($user_email, $subject, $body, $headers);







	mail($ADMIN_EMAIL, $subject1, $body1, $headers);







header("location: manage-leave.php");

}



mysql_select_db($database_oprmConn, $oprmConn);

$query_getRes = "SELECT weby_users.user_id, weby_users.email_address, weby_users.caeated_date, weby_users.total_leaves, weby_profiles.profile_id, weby_profiles.full_name, weby_profiles.job_title, weby_profiles.skill_set, weby_profiles.profile_pic, weby_profiles.hr_rate, weby_profiles.status FROM weby_users, weby_profiles WHERE weby_profiles.user_id = weby_users.user_id and weby_users.user_id = '$_SESSION[user_id]' and weby_profiles.status='A'";

$getRes = mysql_query($query_getRes, $oprmConn) or die(mysql_error());

$row_getRes = mysql_fetch_assoc($getRes);

$totalRows_getRes = mysql_num_rows($getRes);



mysql_select_db($database_oprmConn, $oprmConn);

$query_getProj = "SELECT * FROM weby_projects WHERE weby_projects.status = 'A' AND weby_projects.projetc_id in (select distinct project_id FROM weby_users_projects where status = 'A' and user_id = '$_SESSION[user_id]')";

$getProj = mysql_query($query_getProj, $oprmConn) or die(mysql_error());

$row_getProj = mysql_fetch_assoc($getProj);

$totalRows_getProj = mysql_num_rows($getProj); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">







<head>







<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />







<title>SS WEB TECHNOLOGIES- Tool Resource Leave</title>







<link rel="stylesheet" href="../css/style.css" type="text/css">







  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">






  <script src="//code.jquery.com/jquery-1.10.2.js"></script>







  <script src="//code.jquery.com/ui/1.9.1/jquery-ui.js"></script>




<style>



.act_leave { background: #373938;

  color: #fff;}



</style>



   <style type="text/css">







    .box{







       







        display: none;







		







    }







    .single{  }







    .multi{  }







    







</style>







 <script type="text/javascript">







    $(document).ready(function(){







        $('input[type="radio"]').click(function(){







            if($(this).attr("value")=="single"){







                $(".box").hide();







                $(".single").show();







            }







            if($(this).attr("value")=="multi"){







                $(".box").hide();







                $(".multi").show();







            }







	    });







    });







</script>







  







  <script>







$(function() {











   $( "#leave_date" ).datepicker();







	$( "#start_date" ).datepicker({ dateFormat:'d-M-yy', changeDate: true,    changeMonth: true,  changeYear: true   });







	$( "#end_date" ).datepicker({ dateFormat:'d-M-yy',  changeDate: true,   changeMonth: true,  changeYear: true   });







  







});















</script>







 







<script>







function validateForm() {







//alert(document.getElementById("leave").value);







var message='';







	//return false;







    if(document.getElementById("single").checked)







	{







	var startdate = document.getElementById('start_date').value;







	if (startdate == "") {







        message = message+"Start Date be filled out\n";







        //return false;







    }







	



var leave_type_id = document.getElementById('leave_type_id').options[document.getElementById('leave_type_id').selectedIndex].value;

if (leave_type_id == 0) {

message = message+"Leave Type be filled out\n";

}



var reason = document.getElementById('leave_reason').value;







	if (reason == "") {







        message = message+"Reason be filled out\n";







        //return false;







    }







	var startdate = document.getElementById('start_date').value;







	var today = new Date();















var mm = today.getMonth()+1; //January is 0!







var dd = today.getDate();







var yyyy = today.getFullYear();















if(dd<10) {







    dd='0'+dd







} 







if(mm<10) {







    mm='0'+mm







} 







today = mm+'/'+dd+'/'+yyyy;







		







		







	//if (startdate < today) {



//



//        message = message+"Check Leave Date\n";



//



//        //return false;



//



//    }







	if(message != "")







	{







		alert(message);







		return false;







	}







	else{







		alert("Leave Application Submited");







	}







			







    }







	if(document.getElementById("multi").checked)







	{







	//var message='';







var startdate = document.getElementById('start_date').value;







	if (startdate == "") {







        message = message+"Start Date be filled out\n";







        //return false;







    }







var enddate = document.getElementById('end_date').value;







	if (enddate == "") {







        message = message+"To Date be filled out\n";







        //return false;







    }







		







		







var reason = document.getElementById('leave_reason').value;







	if (reason == "") {







        message = message+"Reason be filled out\n";







        //return false;







    }







var startdate = document.getElementById('start_date').value;







var enddate = document.getElementById('end_date').value;







	if(startdate == enddate){







		message = message+"Check out\n";







        //return false;







	}	







var startdate = document.getElementById('start_date').value;







var enddate = document.getElementById('end_date').value;





startdate = new Date(startdate);
enddate = new Date(enddate);

	if(startdate > enddate){







		message = message+"Wrong Date\n";







        //return false;







	}	







var startdate = document.getElementById('start_date').value;







var today = new Date();















var mm = today.getMonth()+1; //January is 0!







var dd = today.getDate();







var yyyy = today.getFullYear();















if(dd<10) {







    dd='0'+dd







} 







if(mm<10) {







    mm='0'+mm







} 







today = mm+'/'+dd+'/'+yyyy;







		
/*


if (startdate < today) {



       alert("Leave Application Past");



        return false;



    }
*/

	if(message != "")



	{



		alert(message);



		return false;



	}



	else{



		alert("Leave Application Submited");



	}



	



		//if (startdate == today) {







//        message = message+"Check Date\n";







//        //return false;







//		}







	//	if (startdate < today && startdate!='') {



//



//		//alert(startdate);



//



//        message = message+"Check From Date Date\n";



//



//        //return false;



//



//    }







	if(message != "")







	{







		alert(message);







		return false;







	}







		else{







		alert("Leave Application Submited")







	}







	







	















    }







	







}







</script>































<script>







function calculateDate()







{







	if(document.getElementById("multi").checked){







var startdate = document.getElementById('start_date').value;















var enddate = document.getElementById('end_date').value;















var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds







var firstDate = new Date(startdate);







var secondDate = new Date(enddate);















var totaldays = Math.round(Math.abs((firstDate.getTime() - secondDate.getTime())/(oneDay))+1);
var n_days = 0;

var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var start = firstDate;
var end = secondDate;
while(start <= end){
	var d = start.getDay();
	if(d == 0 || d == 6){
		// do nothing
	}
	else{
		n_days = n_days + 1;
	}
   	var newDate = start.setDate(start.getDate() + 1);
   	start = new Date(newDate);
}

totaldays = n_days;












document.getElementById('leave_days').value = totaldays;















}







if(document.getElementById("single").checked)







	{







document.getElementById('leave_days').value = 1;







}















}















</script>







































  







</head>















<body>















<!-- Wrapper Starts -->



<div class="wrapper">



    <?php  require_once('../includes/header.php'); ?>

    

<?php  require_once('../includes/tools-menu.php'); ?>



    <!-- Banner Goes here --> 



    







    <!-- Content Goes here -->







    <article class="inside_wrapper clear_fix">







    







    	<!-- Main Content Goes here -->







      <section class="main_content">







<h2 style="float: left;padding: 20px;">Apply For Leave</h2>



<p class="text_right" style="float: right;padding: 20px;">Total Leaves (<?php echo date("Y"); ?>): <strong><?php echo $row_getRes['total_leaves']; ?></strong><br>

Used Leaves: <strong><?php $year = date('Y');

$query_getusedleaves = "SELECT SUM(`leave_duration`) AS usedleaves FROM weby_leave WHERE status = 'A' AND user_id = '$_SESSION[user_id]' AND YEAR(start_date) = '$year'AND leave_type_id ='1'";

$getusedleaves = mysql_query($query_getusedleaves, $oprmConn) or die(mysql_error());

$row_getusedleaves = mysql_fetch_assoc($getusedleaves);

$usedleaves = $row_getusedleaves['usedleaves'];

if($usedleaves<=0){ $usedleaves = 0; } echo $usedleaves; ?></strong><br>

Balance Leaves: <strong><?php $Balance = $row_getRes['total_leaves']-$usedleaves; echo $Balance; ?></strong><br>
Unpaid Leaves: <strong><?php $year = date('Y');

$query_getunpaidleave = "SELECT SUM(`leave_duration`) AS unpaidleave FROM weby_leave WHERE status = 'A' AND user_id = '$row_getLeave[user_id]' AND YEAR(start_date) = '$year'AND leave_type_id ='3'";

$getunpaidleave = mysql_query($query_getunpaidleave, $oprmConn) or die(mysql_error());

$row_getunpaidleave = mysql_fetch_assoc($getunpaidleave);

$unpaidleave = $row_getunpaidleave['unpaidleave'];

if($unpaidleave<=0){ $unpaidleave = 0; } echo $unpaidleave; ?></strong><br>
Absent : <strong><?php $year = date('Y');

$query_getabsentleave = "SELECT SUM(`leave_duration`) AS absentleave FROM weby_leave WHERE status = 'A' AND user_id = '$row_getLeave[user_id]' AND YEAR(start_date) = '$year'AND leave_type_id ='4'";

$getabsentleave = mysql_query($query_getabsentleave, $oprmConn) or die(mysql_error());

$row_getabsentleave = mysql_fetch_assoc($getabsentleave);

$absentleave = $row_getabsentleave['absentleave'];

if($absentleave<=0){ $absentleave = 0; } echo $absentleave; ?></strong><br>
</p>



<article class="resource_timesheet"> 

<form method="post" action="#" id="submit_timesheet" onsubmit="return validateForm()" name="leave">

<div class="field_item"> <input type="hidden" name="hrr" id="hrr" value="<?php echo $row_getRes['hr_rate']; ?>" /></div>





                <div class="field_item">







                <div class="field_item1">







               	  <input type="radio" name="leave" value="single" id="single" checked="checked" />Single Day







                </div>







                </div>







                <div class="field_item">







               <div class="field_item1">







                	<input type="radio" name="leave" value="multi" id="multi" />







                	Multi Days







                    </div>







                </div>







                







                  <div class="field_item">







                  







                 <div class="field_item">







               	<label>From Date:</label>







                    <input name="start_date" type="text" id="start_date" readonly="readonly" onchange="calculateDate();" /></div>







                    







                   <div class="field_item">







                   <div class="multi box">







                   







                	<label>To Date:</label>







                    <input name="end_date" type="text" id="end_date" onchange="calculateDate();" readonly="readonly" /></div>







                    </div>







                    







                    <div class="field_item">







               	<label>Total Days:</label>







                    <input name="leve_days" type="text" id="leave_days" value="1"  readonly="readonly"/></div>

<div class="field_item">

<label>Leave Type:</label>

<select name="leave_type_id" id="leave_type_id">

<option value="ALL">ALL</option>

<?php mysql_select_db($database_oprmConn, $oprmConn);

$query_getleavetype = "SELECT * FROM weby_leave_types WHERE status = 'A' ORDER BY leave_type_id = 1";

$getleavetype = mysql_query($query_getleavetype, $oprmConn) or die(mysql_error());

$row_getleavetype = mysql_fetch_assoc($getleavetype);

$totalRows_getleavetype = mysql_num_rows($getleavetype);

if($totalRows_getleavetype>0){ do { ?>

<option value="<?php echo $row_getleavetype['leave_type_id']; ?>"><?php echo $row_getleavetype['leave_type_name']; ?></option>

<?php } while ($row_getleavetype = mysql_fetch_assoc($getleavetype)); } ?>

</select>

</div>





                    <div class="field_item">







                   







                   <label>Reason:</label>







                    <textarea name="leave_reason" id="leave_reason" rows="6" /></textarea>







                    </div>







                   <div class="field_item">







                   <div class="lsub">







                    <input name="submit" type="submit" class="save_btn" onclick="MM_validateForm('start_date','','R','end_date','','R','leave_reason','','R');return document.MM_returnValue" value="Apply">







                        <input type="reset" value="Cancel" class="reset_btn">







              </div>







                </div>












                







              







                







                                    </form>







     	<div class="clear-fix">&nbsp;</div> 







            </article>







      </section>







    







    	<!-- Sidebar Goes here -->







        <aside class="sidebar">







          <div class="featured clear_fix">







            <h2 class="white_txt">My Profile</h2>







            <div class="profile_box">







                    <a href="resources-view.php?resourceid=<?php echo $row_getRes['user_id']; ?>"><img src="/RM/images/<?php if(!empty($row_getRes['profile_pic'])) echo $row_getRes['profile_pic']; else echo "black-img.jpg"; ?>" width="68" /></a>







                    <p class="profile_title"><a href="index.php?resourceid=<?php echo $_SESSION[user_id]; ?>"><?php echo $row_getRes['full_name']; ?></a><span class="desig"><br />







                    <?php echo $row_getRes['job_title']; ?></span></p>







                <p class="profile_desc"><?php echo $row_getRes['skill_set']; ?></p>







                  <div class="clear-fix">&nbsp;</div>







            </div>







          </div>







    







   	







     	 </aside>







    







    	 







    







     	<div class="clear-fix">&nbsp;</div> 







        







    </article>







    







  <div class="clear-fix">&nbsp;</div>







    <!-- Footer Goes here -->







     <?php  require_once('../includes/footer.php'); ?>



</div>







</body>







</html>







<?php







mysql_free_result($getRes);















mysql_free_result($getProj);







?>







