<? include("si_confi.php"); ?>
<? include("ad_head.php");


if($_GET['action']=='trsh')
{
	$did=$_GET['id'];
	$id2=$_GET['id2'];
	
	 $ddlm=mysql_query("delete  from `leave` where `id`='$id2'");
	
	   $seleect_employee=mysql_query("select * from `employee_mng` where emp_id='$did' ");
		while($fetch_employee=mysql_fetch_array($seleect_employee))
		{ 
	     $emid=$fetch_employee['emp_id']; 
		 $emname=$fetch_employee['name'];
		 date_default_timezone_set("Asia/Kolkata");
		 $mntth=date('F');
		 $yrar=date("Y");
		 $mn = date("m", strtotime("$mntth"));
		 $mnth=date("F",mktime(0, 0, 0, $mn, 10));
		 
      $ddlmxx=mysql_query("delete  from `emp_attendance` where `empid`='$did' and  month='$mntth' and year='$yrar'");
	  
	  $ddlmxxcc=mysql_query("delete  from `emp_attendance` where `empid`='$did' and  month='$mnth' and year='$yrar' ");
	  
	  

      $ckkqu=mysql_query("select * from emp_attendance where empid='$emid' and  month='$mntth' and year='$yrar'  ");
	  $chknum=mysql_num_rows($ckkqu);
	  
	  if($chknum==0)
	  {
	   $insf=mysql_query("insert into emp_attendance(`empid`,`emp_name`,`year`,`month`) values('$emid','$emname','$yrar','$mntth')");
	  }
	}
	?>
	<script>window.location="leave_work.php?del=suc";</script>
    <?              
	
}

 ?>

  <div class="container">
  
 
<? include("mn_option.php");  include("update.php"); ?>

<? if($_REQUEST['ed']=='suc'){ ?>
  <div class="success" style="width:92%;margin:0 auto;margin-top:9px;">Changes saved successfully.</div><? } ?>
  <? if($_REQUEST['del']=='suc'){ ?>
  <div class="error" style="width:92%;margin:0 auto;margin-top:9px;">One Details Deleted successfully.</div><? } ?>
  
  <?

$select_count_emp=mysql_query("select count(*) as num from `leave`");
$fetch_count_emp=mysql_fetch_array($select_count_emp);
$total_emp_result=$fetch_count_emp['num'];

?>
   <div style="border:groove;margin-top:10px;border-width:thin;padding:20px;border-radius:4px;border-color:#cccccc;box-shadow: 10px 9px 90px #000;">
   <h2>View Leave Details&nbsp;&nbsp;&nbsp;(Total&nbsp;:&nbsp;<? echo $total_emp_result; ?>)</h2>
   
<link type="text/css" href="../calender/jquery.datepick.css" rel="stylesheet">
<script type="text/javascript" src="../calender/jquery.min.js"></script>
<script type="text/javascript" src="../calender/jquery.datepick.js"></script>
<script type="text/javascript">
$(function() {
	$('#popupDatepicker').datepick();
	$('#inlineDatepicker').datepick({onSelect: showDate});
});
function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>
<script type="text/javascript">
$(function() {
	$('#popupDatepicker2').datepick();
	$('#inlineDatepicker2').datepick({onSelect: showDate});
});
function showDate(date) {
	alert('The date chosen is ' + date);
}
</script>

   
   <form method="post" enctype="multipart/form-data" action="leave_work.php">
   <table id="serach_astat">
   <tr>
        <td>
        <select name="username" class="validate-selection" autofocus>
        <option value="" hidden="">Select Employee</option>
        <? $seleect_employee=mysql_query("select * from `employee_mng`");
		while($fetch_employee=mysql_fetch_array($seleect_employee)){ ?>
<option value="<? echo $fetch_employee['emp_id']; ?>"><? echo ucwords($fetch_employee['name']); ?> - <? echo ucwords($fetch_employee['emp_id']); ?>
</option>
		<? } ?>
        </select>
        </td>
   <td>
   <input type="submit" name="search_status" value="Search"></td>
   </tr>
   
   
   </table>
   </form>
   <br>
   <? if($get_stattustitle!=NULL || $get_fromdate!=NULL){?>
   <span style="color:#900;">Search Terms</span>&nbsp;:&nbsp;<? if($get_fromdate!=NULL){ echo $get_fromdate; ?>&nbsp;(to)&nbsp;<? echo $get_todate; } ?>
   <? if($get_stattustitle!=NULL){ echo $get_stattustitle;} ?>
    <? } ?>   
   <? if($get_empid123!=NULL){ echo "<span style='color:#900;margin-left:5%;'>Emp ID</span>&nbsp;:&nbsp;".ucwords($get_empid123)."";} ?>
    <br> <br>
  
  <table width="100%" cellpadding="9" cellspacing="0" border="1">
  <tr bgcolor="#CCCCCC">
  <td>EMP ID</td>
  <td>EMP Name</td>
  <td>Leave For</td>
  <td>Days</td>
  <td>From Date</td>
  <td>To Date</td>
  <td>Status</td>
  <!--<td>Edit</td>-->
  <td>Delete</td>
  </tr>
  
 <?
 
 if($_REQUEST['username']!='')
 {
	 $empo=$_REQUEST['username'];
	  $select_leave_details=mysql_query("select * from `leave` WHERE empid='$empo' ");
 }
 else
 {
  $select_leave_details=mysql_query("select * from `leave` order by `id` desc");
 }
  
  
  while($fetch_leave_details=mysql_fetch_array($select_leave_details))
  {
 ?>
      
  <tr bgcolor="#FFFFFF">
  <td><? echo $fetch_leave_details['empid']; ?></td>
  <td><? echo ucwords($fetch_leave_details['name']); ?></td>
  <td><? echo $fetch_leave_details['leavefor']; ?></td>
  <td><? echo $fetch_leave_details['count']; ?></td>
  <td><? echo $fetch_leave_details['fdate']; ?></td>
  <td><? echo $fetch_leave_details['tdate']; ?></td>
   
   <? if($fetch_leave_details['status']=='0'){ ?>
   <td >
   <div style="background:#09F;color:#FFF;padding:10px;border-radius:9px;font-weight:bold; text-align:center;">UnConfirm</div>
   </td>
   <? } ?>
   
   <? if($fetch_leave_details['status']=='1'){ ?>
   <td style="color:#FFF;">
    <div style="background:#6C0;color:#FFF;padding:10px;border-radius:9px;font-weight:bold; text-align:center;">Confirmed</div>
   </td>
   <? } ?>
   
   <? if($fetch_leave_details['status']=='3'){ ?>
   <td style="color:#;">
   <div style="background:#F00;color:#FFF;padding:10px;border-radius:9px;font-weight:bold; text-align:center;">Cancel</div>
   </td>
   <? } ?>
 
 <!-- <td>
  
  <a href="edit_work.php?isd=<? echo base64_encode($fetch_leave_details['id']); ?>"><img src="ad_img/edit-male-user-icon.png" width="40"></a>
  </td>-->
  <td>
  
   <a href="leave_work.php?id=<? echo $fetch_leave_details['empid']; ?>&&id2=<? echo $fetch_leave_details['id']; ?>&&m&&action=trsh" onClick="return confirm('Are you sure you want to confirm delete?');"><img src="ad_img/Remove-Male-User.png" width="40"></a>
  </td>
  </tr>
  
  <? } ?>
  <script type="text/javascript">
function newPopup(url) {
	popupWindow = window.open(
		url,'popUpWindow','height=580,width=700,left=140,top=60,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
  </table>  
  </div>
</div><!-- container -->
  </body>
</html>