<?php
if(basename($_SERVER['PHP_SELF']) == 'employees.php') {
  $pr=" class='current'";
} else {
  $pr="";
} 
session_start();
if(!$_SESSION['Empopa'])
Header("location:home.php");

include'header.php';
$perpagevalue=500;
$cond="ORDER BY `Fname` ASC LIMIT $perpagevalue";
$conde=" AND `Status`='0'";
$condi='';

$kete=$cote='';

if(isset($_POST['perpage']))
		{
			$perpagevalue=$_POST['perpagevalue'];
			$cond="ORDER BY `Fname` ASC LIMIT $perpagevalue";
		}
if(isset($_POST['search']))
		{
			$searchkeyword=$_POST['searchkeyword'];
		if($searchkeyword)
			$conde="AND `Status`='0' AND (`Fname` LIKE '%$searchkeyword%' OR `Lname` LIKE '%$searchkeyword%' OR `Address` LIKE '%$searchkeyword%' OR `Idno` LIKE '%$searchkeyword%' OR `Contact1` LIKE '%$searchkeyword%' OR `Contact2` LIKE '%$searchkeyword%' OR `Father` LIKE '%$searchkeyword%' OR `Mother` LIKE '%$searchkeyword%' OR `Fullname` LIKE '%$searchkeyword%')";
		else
			$conde="AND `Status`='0'";
		}
if(isset($_POST['submitfilter']))
		{
			$department=$_POST['department'];
			$_SESSION['Depa']=$department;
		}

		if($_SESSION['Depa']=='1' OR $_SESSION['Depa']=='2'){
			$department=$_SESSION['Depa'];
			$condi="AND `Depart`='$department'";
		}

if(isset($_POST['delete_id']))
		{
			$rowid=$_POST['rowid'];
			$then=mysqli_query($conn, "UPDATE `employees` SET `Status`='1001' WHERE `Eid`='$rowid' LIMIT 1");
		}
		
		if(isset($_GET['kete']))
		{
			$kete=$_GET['kete'];
			$cote="AND `Currentp`='$kete'";
		}

$do=mysqli_query($conn, "SELECT *FROM `employees` WHERE `Eid`!='1001' $conde $condi $cote $cond");
$fo=mysqli_num_rows($do);
?>	  
	  
	  <div class="container-fluid main-content">
  <div class="page-title">
          <h2 style='margin-top:-20px; margin-bottom: 5px; color:#ffcc33'>
           Employees 
          </h1>
                </div>
      
        <div class="row">
        <div class="col-md-2">
		<ul class="list-group">
			 		  <li class="list-group-item active">
           <a href="employees.php">
           <p>
           <i class="lnr lnr-menu-circle"></i>&nbsp;List of Employees
           </p></a>
           </li>
                          <li class="list-group-item">
           <a href="new_employee.php">
           <p>
           <i class="lnr lnr-plus-circle"></i>&nbsp;Create Employee
           </p></a>
           </li>
           
           <li class="list-group-item">
           <a href="susprepo.php">
           <p>
           <i class="lnr lnr-menu-circle"></i>&nbsp;Suspended List
           </p></a>
           </li> 
           
                       </ul>
		
         
  
            <div class="widget-container fluid-height">
              <div class="widget-content">
               
                <div class="panel-group" id="accordion">
                  <div class="panel">
                    <div class="panel-heading">
                    </div> 
                  </div>
                  <div class="panel">
                    <div class="panel-heading">
                      <div class="panel-title">
                      </div>
                    </div>
                    <div class="panel-collapse collapse in" id="collapseTwo">
                    </div>
                  </div>
                  <div class="panel filter-categories">
                    <div class="panel-heading">
                      <div class="panel-title">
               <a class="accordion-toggle collapsed" data-parent="#accordion" data-toggle="collapse" href="#collapseThree">
                        <div class="caret pull-right"></div>  
                        Sort By</a>
                      </div>
                    </div>
                    <div class="panel-collapse collapse in" id="collapseThree">
                      <div class="panel-body">
                      <form method="POST" action="employees.php">
                      <input value="view_employees" name="user" type="hidden">
                      <select class="form-control" name="department">
                      <option selected="selected" value="">Show All</option>
 <?php
		$de=mysqli_query($conn, "SELECT *FROM `depart` ORDER BY `Number` ASC");
			  while($re=mysqli_fetch_assoc($de)){
					$ne=$re['Number'];
					$dep=$re['Depart'];
if($_SESSION['Depa']==$ne)
$sl='selected';
else
$sl='';
			echo"<option value='$ne' $sed $sl>$dep</option>";
			  }
			  ?>                      
                      </select><br>
                      <button class="btn btn-block btn-primary" type="submit" name="submitfilter">
                      <i class="lnr lnr-checkmark-circle"></i> Submit</button>
                      </form></div></div>   </div>
                </div>
              </div>
            </div>        
         </div>
         
         
         <!-- Search and show per page on top of table -->
         <div class="col-md-10">
          <div class="row">
           <div class="col-md-6 "> 
           <form action="employees.php" method="POST" class="form-horizontal ">
        <input name="searchkeyword" value="" type="hidden">
        <input name="column_name" value="" type="hidden">
    
            <div class="col-md-4 "> 
           <select name="perpagevalue" class="form-control">
                              <option value="20">20 per page</option>
                              <option value="50">50 per page</option>
                              <option value="100">100 per page</option>
                              <option value="200">200 per page</option>
                              <option value="300">300 per page</option>
                              <option value="500" selected="selected">500 per page</option>
                            
               </select>
          
         </div>    
          
                    <div class="col-md-2 "> 
      
                 <button class="btn  btn-primary  btn-block" type="submit" name="perpage"><i class="lnr lnr-chevron-right-circle"></i> Show</button>
				
          </div> 
    
        </form>
        </div>
          
          
           <div class="col-md-6 ">
           

        <form action="" method="post" class="form-horizontal">
                  
                       <div class="col-md-3"> 
                       
                        </div>
                       <div class="col-lg-9 input-group">
                       
                      <input class="form-control" name="searchkeyword" placeholder="search" type="text" id="searche">
                      <input value="" name="department" type="hidden">
                      <span class="input-group-btn">
                        <button class="btn  btn-primary" type="submit" name="search"><i class="lnr lnr-magnifier"></i> Search</button>
                      </span>
                      
                      
                      </div>
         </form>
            </div> 
               
            </div>
            
            <div class="row" style='padding-top:-30px;'>
            <div class="col-md-12">
            <span>&nbsp;&nbsp;&nbsp;</span>  
            <div class="widget-container fluid-height clearfix" style='margin-top:-40px;'>
            <div class="widget-content padded clearfix">
                
                                 <table class="table table-striped table-hover" style='margin-top:-20px;'>     
                                      <thead>
                    <tr role="row">
                     <th class="hidden-xs"> No </th>
                       <th> First&nbsp;Name </th>
                       <th> Last&nbsp;Name </th> 
                       <th class="hidden-xs"> Salary </th>
                       <th> Telephone </th>
					   <th class="hidden-xs"> ID/Driving&nbsp;No </th>
					   <th class="hidden-xs"> Passport&nbsp;No </th>
					   <th class="hidden-xs"> Address </th>
					   <th class="hidden-xs"><center> Position </th>
					   <th class="hidden-xs"><center> Salary </th>
                        <th colspan='2'><center> Actions </th>
                     </tr>
                    </thead>
                                        <tbody>
                                          
				<?php
				$n=1;
				$stn="style='padding:1px;'";
				while($ro=mysqli_fetch_assoc($do)){
$code=$ro['Eid'];
$fna=$ro['Fname'];
$lna=$ro['Lname'];
$dep=$ro['Depart'];
$cont=$ro['Contact1'];
$conts=$ro['Contact2'];
$idn=$ro['Idno'];
$poc=$ro['Currentp'];
$adde=$ro['Address'];
$sala=number_format($ro['Salary']);

$then=mysqli_query($conn, "SELECT `Depart` FROM `depart` WHERE `Number` = '$dep'");
$ren=mysqli_fetch_assoc($then);
$dep=$ren['Depart'];

$theni=mysqli_query($conn, "SELECT `Postname` FROM `position` WHERE `Postid` = '$poc'");
$reni=mysqli_fetch_assoc($theni);
$pos=$reni['Postname'];

if($_SESSION['Empopa']){
$lne="submit";
$lin="vemployee.php?id=$code";
}
else{
$lne="button";
$lin="#";
}

$name="$fna $lna";
$so=mysqli_query($conn, "UPDATE `employees` SET `Fullname` = '$name' WHERE `Eid` = '$code'");

	print("<tr><td $stn class='hidden-xs text-center'> $n </td>
	<td $stn> $fna</td><td $stn> $lna</td>
	<td $stn class='hidden-xs'> $dep</td><td $stn align='right'> $cont</td>
	<td $stn class='hidden-xs' align='right'> $idn</td>
	<td $stn class='hidden-xs' align='right'> $conts</td>
	<td $stn class='hidden-xs'> $adde</td>
	<td $stn class='hidden-xs'><a href='employees.php?kete=$poc'>$pos</a></td>
	<td $stn class='hidden-xs text-right'> $sala </td>
	
	  <td  align='right' style='width:40px;padding:0px;'><div class='action-buttons'>
                                                <a class='table-actions' href='$lin'>View</a></td>

						<form method=post action='new_employee.php'><td align='right' style='width:40px;padding:0px;'>
                        <input type='hidden' name='rowid' value='$code'>
                           <button style='background-color:transparent;border:0px solid black; width:40px; margin:0px;' type='$lne' name='edit_id'>
						   <span style=color:blue;>Edit</span></button></td></form>
                                                </div></td></tr>");
												$n++;
				}
				?>
                    </tbody>   
                  </table>
                                      <div class="row">
                  <div class="col-md-12">
                  <div class="pull-right">
                  <ul class="pagination">
                      <li>
                                            </li>
                      <li class="activei">
                        <a href="#">
                        Next                        </a>
                      </li>
                                             <li>
                                            </li>
                    </ul>
              </div></div></div>
                                
              </div>
            </div>
   <?php
   include'footer.php';
   ?>