<? include("si_confi.php"); ?>
<? include("ad_head.php"); ?>
  <div class="container">
  
  <? if(isset($_REQUEST['search_status']))
{
	$fromdate=$_REQUEST['fromdate'];
	$todate=$_REQUEST['todate'];
	$username=$_REQUEST['username'];
	$search_status=$_REQUEST['search_status12'];
	?><script>window.location="viwe_work.php?frdate=<? echo $fromdate ?>&&todate=<? echo $todate?>&&sttitle=<? echo $search_status ?>&&empid=<? echo $username;?>";</script><?
}


$get_fromdate=$_REQUEST['frdate'];
$get_todate=$_REQUEST['todate'];
$get_stattustitle=$_REQUEST['sttitle'];
$get_empid123=$_REQUEST['empid'];


if($get_stattustitle=='Pending'){$get_stattustitle123="NULL";}else {$get_stattustitle123=$get_stattustitle;}
?>


<? include("mn_option.php"); ?>



<?
if($_REQUEST['action']=='trsh')
{
	$get_emp_id=base64_decode($_REQUEST['isd']);
	
	mysql_query("delete from `work_allocation` where `id`='$get_emp_id'");
	?><script>window.location="viwe_work.php?del=suc";</script><?
}
 ?>

<? 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><? } ?>
  
  
<?
if($get_fromdate==NULL && $get_todate==NULL && $get_stattustitle123==NULL && $get_empid123==NULL){
$select_count_emp=mysql_query("select count(*) as num from `work_allocation`");
}
if($get_fromdate!=NULL && $get_todate!=NULL && $get_stattustitle123==NULL  && $get_empid123==NULL){
$select_count_emp=mysql_query("select count(*) as num from `work_allocation` where `date_allocation` between '$get_fromdate' and '$get_todate'");
}
if($get_fromdate==NULL && $get_todate==NULL && $get_stattustitle123!=NULL && $get_empid123==NULL){
$select_count_emp=mysql_query("select count(*) as num from `work_allocation` where `status`='$get_stattustitle123'");
}
if($get_fromdate!=NULL && $get_todate!=NULL && $get_stattustitle123==NULL && $get_empid123!=NULL){
$select_count_emp=mysql_query("select count(*) as num from `work_allocation` where `date_allocation` between '$get_fromdate' and '$get_todate' and `username`='$get_empid123'");
}
if($get_fromdate==NULL && $get_todate==NULL && $get_stattustitle123==NULL && $get_empid123!=NULL){
$select_count_emp=mysql_query("select count(*) as num from `work_allocation` where `username`='$get_empid123'");
}
if($get_fromdate!=NULL && $get_todate!=NULL && $get_stattustitle123!=NULL && $get_empid123==NULL){
$select_count_emp=mysql_query("select count(*) as num from `work_allocation` where `date_allocation` between '$get_fromdate' and '$get_todate' and `status`='$get_stattustitle123'");
}


$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 Work Allocation&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="<?php echo $_SERVER['PHP_SELF']; ?>">
   <table id="serach_astat">
   <tr>
   <td><input type="text" name="fromdate" placeholder="From Date" id="popupDatepicker"></td>
   <td><input type="text" name="todate" placeholder="To Date" id="popupDatepicker2"></td>
   <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><select name="search_status12">
   <option hidden="" value="">Select Status</option>
   <option>Pending</option>
    <option>Complete</option>
     <option>Cancel</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>Work</td>
  <td>Allocation Date</td>
  <td>Status</td>
  <td>Status Date</td>
  <td>Particulars</td>
  <td>Edit</td>
  <td>Delete</td>
  </tr>
  <?
  if($get_fromdate==NULL && $get_todate==NULL && $get_stattustitle123==NULL && $get_empid123==NULL){
$select_employee_details=mysql_query("select * from `work_allocation` order by `id` desc");
}
if($get_fromdate!=NULL && $get_todate!=NULL && $get_stattustitle123==NULL  && $get_empid123==NULL){
$select_employee_details=mysql_query("select * from `work_allocation` where `date_allocation` between '$get_fromdate' and '$get_todate' order by `id` desc");
}
if($get_fromdate==NULL && $get_todate==NULL && $get_stattustitle123!=NULL && $get_empid123==NULL){
$select_employee_details=mysql_query("select * from `work_allocation` where `status`='$get_stattustitle123' order by `id` desc");
}
if($get_fromdate!=NULL && $get_todate!=NULL && $get_stattustitle123==NULL && $get_empid123!=NULL){
$select_employee_details=mysql_query("select * from `work_allocation` where `date_allocation` between '$get_fromdate' and '$get_todate' and `username`='$get_empid123' order by `id` desc");
}
if($get_fromdate!=NULL && $get_todate!=NULL && $get_stattustitle123!=NULL && $get_empid123==NULL){
$select_employee_details=mysql_query("select * from `work_allocation` where `date_allocation` between '$get_fromdate' and '$get_todate' and `status`='$get_stattustitle123' order by `id` desc");
}
if($get_fromdate==NULL && $get_todate==NULL && $get_stattustitle123==NULL && $get_empid123!=NULL){
$select_employee_details=mysql_query("select * from `work_allocation` where `username`='$get_empid123' order by `id` desc");
}




  while($fetch_employee_details=mysql_fetch_array($select_employee_details)){
	  
	  $empid_id=$fetch_employee_details['username'];
	  
	  $select_empname=mysql_query("select * from `employee_mng` where `emp_id`='$empid_id'");
	  $fetchemployeename=mysql_fetch_array($select_empname); ?>
  <tr bgcolor="#FFFFFF">
  <td><? echo ucwords($fetch_employee_details['username']); ?></td>
  <td><? echo ucwords($fetchemployeename['name']); ?></td>
  <td><? echo ucwords($fetch_employee_details['work']); ?></td>
  <td><? echo $fetch_employee_details['date_allocation']; ?>, <? echo $fetch_employee_details['time_allocation']; ?></td>
   
    <? if($fetch_employee_details['status']=='NULL'){ ?>
   <td bgcolor="#FF9900">Pending</td>
   <? } ?>
    <? if($fetch_employee_details['status']=='Complete'){ ?>
   <td bgcolor="#009900" style="color:#FFF;">Complete</td>
   <? } ?>
    <? if($fetch_employee_details['status']=='Cancel'){ ?>
   <td bgcolor="#F00" style="color:#FFF;">Cancel</td>
   <? } ?>
   
   
    <td><? echo $fetch_employee_details['date']; ?>, <? echo $fetch_employee_details['time']; ?></td>
     <td><? echo ucwords($fetch_employee_details['particulars']); ?></td>
  <td>
  <? if($fetch_employee_details['status']=='NULL'){ ?>
  <a href="edit_work.php?isd=<? echo base64_encode($fetch_employee_details['id']); ?>"><img src="ad_img/edit-male-user-icon.png" width="40"></a>
  <? } else { ?><div style="background:#F00;color:#FFF;padding:10px;border-radius:9px;font-weight:bold;">None</div><? } ?></td>
  <td>
   <? if($fetch_employee_details['status']=='NULL'){ ?>
   <a href="viwe_work.php?isd=<? echo base64_encode($fetch_employee_details['id']); ?>&&action=trsh" onClick="return confirm('Are you sure you want to confirm delete?');"><img src="ad_img/Remove-Male-User.png" width="40"></a>
   <? } else { ?><div style="background:#F00;color:#FFF;padding:10px;border-radius:9px;font-weight:bold;">None</div><? } ?></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>