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


if($_SESSION['user_id'] == '')



{



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



}



if (!function_exists("GetSQLValueString")) {



function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 



{



  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;







  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);







  switch ($theType) {



    case "text":



      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";



      break;    



    case "long":



    case "int":



      $theValue = ($theValue != "") ? intval($theValue) : "NULL";



      break;



    case "double":



      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";



      break;



    case "date":



      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";



      break;



    case "defined":



      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;



      break;



  }



  return $theValue;



}



}







$maxRows_getLeave = 10;



$pageNum_getLeave = 0;



if (isset($_GET['pageNum_getLeave'])) {



  $pageNum_getLeave = $_GET['pageNum_getLeave'];



}



$startRow_getLeave = $pageNum_getLeave * $maxRows_getLeave;







mysql_select_db($database_oprmConn, $oprmConn);



$query_getRes = "SELECT weby_users.user_id, weby_users.email_address, weby_users.total_leaves, weby_users.caeated_date, 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);











mysql_select_db($database_oprmConn, $oprmConn);



$query_getLeave = "SELECT weby_leave.leave_id, weby_leave.start_date, weby_leave.end_date, weby_leave.leave_duration, weby_leave.leave_reason, weby_leave.leave_type_id, weby_leave.status FROM weby_leave WHERE weby_leave.user_id  = '$_SESSION[user_id]' AND weby_leave.status!='D' order by weby_leave.start_date DESC";



$query_limit_getLeave = sprintf("%s LIMIT %d, %d", $query_getLeave, $startRow_getLeave, $maxRows_getLeave);



$getLeave = mysql_query($query_limit_getLeave, $oprmConn) or die(mysql_error());



$row_getLeave = mysql_fetch_assoc($getLeave);







if (isset($_GET['totalRows_getLeave'])) {



  $totalRows_getLeave = $_GET['totalRows_getLeave'];



} else {



  $all_getLeave = mysql_query($query_getLeave);



  $totalRows_getLeave = mysql_num_rows($all_getLeave);



}



$totalPages_getLeave = ceil($totalRows_getLeave/$maxRows_getLeave)-1;







$queryString_getLeave = "";



if (!empty($_SERVER['QUERY_STRING'])) {



  $params = explode("&", $_SERVER['QUERY_STRING']);



  $newParams = array();



  foreach ($params as $param) {



    if (stristr($param, "pageNum_getLeave") == false && 



        stristr($param, "totalRows_getLeave") == false) {



      array_push($newParams, $param);



    }



  }



}























?>



<!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>

<style>
.act_leave { background: #373938;
  color: #fff;}
</style>

<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>





<script>



$(function() {

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



  });



function MM_validateForm() { //v4.0



  if (document.getElementById){



    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;



    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);



      if (val) { nm=val.name; if ((val=val.value)!="") {



        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');



          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';



        } else if (test!='R') { num = parseFloat(val);



          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';



          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');



            min=test.substring(8,p); max=test.substring(p+1);



            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';



      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }



    } if (errors) alert('The following error(s) occurred:\n'+errors);



    document.MM_returnValue = (errors == '');



} }







function calBill(){



document.getElementById("total_cost").value = document.getElementById("total_hrs").value * <?php echo $row_getRes['hr_rate']; ?>;



}



</script>



<!-- IE Fix for HTML5 Tags -->



<!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 



	<![endif]-->



</head>







<body>

<!-- Wrapper Starts -->
<div class="wrapper">

    <?php  require_once('../includes/header.php'); ?>
    
<?php  require_once('../includes/tools-menu.php'); ?>
  <!-- Content Goes here -->



  <article class="inside_wrapper clear_fix"> 



    



    <!-- Main Content Goes here -->



    <section class="main_content">



      <h2>Manage Leaves</h2>
<p class="text_right" style="float: left;">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>

<a class="create_btn"  href="apply-leave.php"><p align="right">Apply For Leave</p></a>
<div class="clear-fix">&nbsp;</div>



      <article class="resource_timesheet clear_fix"> 



        <!--<p class="text_right"><strong>Rate £<?php echo $row_getRes['hr_rate']; ?> per hour</strong></p>-->



        <form method="post" action="#" id="submit_timesheet">



          <div class="field_item">



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



            <!--<label>Select Project:</label>



                   <select name="project" id="project">



                      <?php



do {  



?>



                      <option value="<?php echo $row_getProj['projetc_id']?>"><?php echo $row_getProj['project_name']?></option>



                      <?php



} while ($row_getProj = mysql_fetch_assoc($getProj));



  $rows = mysql_num_rows($getProj);



  if($rows > 0) {



      mysql_data_seek($getProj, 0);



	  $row_getProj = mysql_fetch_assoc($getProj);



  }



?>



                  </select>--> 



          </div>



          <div class="field_item">



            <div class="timesheet_table">



              <div class="column_title"> <span class="item_small">Leave Id #</span><span class="item_small">Start Date </span><span class="item_small"> End Date </span><span class="item_small"> No of Days</span><span class="item_small">Leave Type</span><span class="item_small">Reason</span><span class="item_small">&nbsp; &nbsp;    Status</span> </div>



              <?php if($totalRows_getLeave>0) { do { ?>



                <div class="row <?php if($n==0) { echo "yellow"; $n=1; } else $n=0; ?>"> <span class="item_small"><?php echo $row_getLeave['leave_id']; ?></span><span class="item_small"><?php echo date('d/M/Y',strtotime($row_getLeave['start_date'])); ?></span><span class="item_small">



                  <?php if($row_getLeave['end_date'] != NULL){



 echo date('d/M/Y',strtotime($row_getLeave['end_date']));} ?>



                  </span><span class="item_small"><?php echo $row_getLeave['leave_duration']; ?></span>
<span class="item_small"><?php $query_getleavetype = "SELECT * FROM weby_leave_types WHERE status = 'A' AND leave_type_id = '$row_getLeave[leave_type_id]'";
$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){ echo $row_getleavetype['leave_type_name']; } else { echo '-'; } ?></span>
				  <span class="item_small" title="<?php echo $row_getLeave['leave_reason']; ?>"><strong><?php echo $rest = substr($row_getLeave['leave_reason'], 0, 10); ?>...</strong></span><span class="item_small">



                  <?php  if($row_getLeave['status']=="P"){



	   $s = "Pending";}if($row_getLeave['status']=="R"){



	   $s = "Rejected";}if($row_getLeave['status']=="C"){



	   $s = "Cancled";}if($row_getLeave['status']=="A"){$s = "Approved";}



	    echo $s; ?>



                  </a></span><div class="clear_fix"></div></div>



                <?php } while ($row_getLeave = mysql_fetch_assoc($getLeave)); ?>



 <div class="nav-right">
              <table width="300" border="0" align="center" cellpadding="2" style="clear:both">



                <tr>



                  <td colspan="4" align="center"><?php echo ($startRow_getLeave + 1) ?> to <?php echo min($startRow_getLeave + $maxRows_getLeave, $totalRows_getLeave) ?> of <?php echo $totalRows_getLeave ?></td>



                </tr>



                <tr>



                  <td align="center"><?php if ($pageNum_getLeave > 0) { // Show if not first page ?>



                      <a href="<?php printf("%s?pageNum_getLeave=%d%s", $currentPage, 0, $queryString_getLeave); ?>">&lt;&lt; First</a>



                      <?php } // Show if not first page ?></td>



                  <td align="center"><?php if ($pageNum_getLeave > 0) { // Show if not first page ?>



                      <a href="<?php printf("%s?pageNum_getLeave=%d%s", $currentPage, max(0, $pageNum_getLeave - 1), $queryString_getLeave); ?>">&lt; Previous</a>



                      <?php } // Show if not first page ?></td>



                  <td align="center"><?php if ($pageNum_getLeave < $totalPages_getLeave) { // Show if not last page ?>



                      <a href="<?php printf("%s?pageNum_getLeave=%d%s", $currentPage, min($totalPages_getLeave, $pageNum_getLeave + 1), $queryString_getLeave); ?>">Next &gt;</a>



                      <?php } // Show if not last page ?></td>



                  <td align="center"><?php if ($pageNum_getLeave < $totalPages_getLeave) { // Show if not last page ?>



                      <a href="<?php printf("%s?pageNum_getLeave=%d%s", $currentPage, $totalPages_getLeave, $queryString_getLeave); ?>">Last &gt;&gt;</a>



                      <?php } // Show if not last page ?></td>



                </tr>



              </table>


</div>
              <?php } else echo "<div class='no-rows'>No Leaves  entries.</div>";?>



            </div>



          </div>



          



          <!-- <div class="field_item">



                	<label>Total Cost(&pound;):</label>



                    <input type="text" name="total_cost" id="total_cost" readonly="readonly" />



                </div>--> 



          <!--<div class="field_item">



                	<label>Resion:</label>



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



                </div>--> 



          <!-- <div class="action_items">



                    	<input name="submit" type="submit" class="save_btn" onclick="MM_validateForm('date','','R','total_hrs','','R','task_details','','R');return document.MM_returnValue" value="Submit">



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



                    </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>



      <!--<h3>Recent Activity</h3>-->



      <?php #include("recent-ac.php"); ?>



    </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);



?>



