<?php
if(basename($_SERVER['PHP_SELF']) == 'rules.php') 
  $pp=" class='current'";
include'header.php';
include'connection.php';
$dato=$datos=$Date;

if(isset($_POST['add']))
		{
			$descri=$_POST['descri'];
			$valu=$_POST['valu'];
			$value=$_POST['value'];
		$then=mysqli_query($conn, "INSERT INTO `rules` (`Date`, `User`, `Description`, `Employer`, `Employee`) VALUES ('$Date', '$loge', '$descri', '$valu', '$value')");
		$pto='10';
		}

if(isset($_POST['upda']))
		{
			$rowid=$_POST['rowid'];
			$descri=$_POST['descri'];
			$valu=$_POST['valu'];
			$value=$_POST['value'];
		$then=mysqli_query($conn, "UPDATE `rules` SET `Date`='$Date', `User`='$loge', `Description`='$descri', `Employer`='$valu', `Employee`='$value' WHERE `Number`='$rowid'");
		$pto='20';
		}

if(isset($_POST['edit_id']))
		{
			$rowid=$_POST['rowid'];
	$doi=mysqli_query($conn, "SELECT *FROM `rules` WHERE `Number`='$rowid'");
		$roi=mysqli_fetch_assoc($doi);
			$vu=$roi['Employer'];
			$vue=$roi['Employee'];
			$des=$roi['Description'];
			$btn="UPDATE";
			$vtn="upda";
		}
else{
	$rowid='0';
	$vu='';
	$vue='';
	$des='';
	$btn="ADD";
	$vtn="add";
}
$so=mysqli_query($conn, "DELETE FROM `rules` WHERE `Employee`='0' AND `Employer`='0'");

$do=mysqli_query($conn, "SELECT *FROM `rules` ORDER BY `Number` ASC LIMIT 100");
$fo=mysqli_num_rows($do);
?>
<div class="container-fluid main-content">
        <div class="page-title">
          <h1 style='margin-top:-20px; margin-bottom: 5px;'>
         Leave Approval
          </h1>
                 </div>
     
        <div class="row">
  <div class="col-lg-2">
   
   <ul class="list-group">
      
     <li class="list-group-item">
           <a href="pays.php">
           <p>
           <i class="lnr lnr-plus-circle"></i>&nbsp;Payroll
           </p></a>
           </li>
		   <li class="list-group-item">
           <a href="payc.php">
           <p>
           <i class="lnr lnr-menu-circle"></i>&nbsp;Casual
           </p></a>
           </li>
		 <li class="list-group-item active">
           <a href="rules.php">
           <p>
           <i class="lnr lnr-plus-circle"></i>&nbsp;Rules
           </p></a>
           </li>
            </ul>
  </div>
                    
           
           
       
        <div class="col-lg-10">
                  <div class="row">
           <div class="col-lg-6 "> 
           <form action="" method="POST" class="form-horizontal ">
        <input name="searchkeyword" value="" type="hidden">
        <input name="column_name" value="" type="hidden">
    
            <div class="col-lg-4 "> 
           <select name="perpagevalue" class="form-control">
                              <option selected="selected" value="10">10 per page</option>
                              <option value="50">50 per page</option>
                              <option value="100">100 per page</option>
                              <option value="200">200 per page</option>
                            
               </select>
          
         </div>    
          
                    <div class="col-lg-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-lg-6 ">
           

        <form action="" method="post" class="form-horizontal ">
                  
                       <div class="col-lg-6" style='width:90px;'> 
                     <input class="form-control" name="valu" placeholder="Employer" type="text" style='width:90px; text-align:center;' 
					  onkeypress='return isNumberKey(event)' value="<?php echo $vu ?>">
						</div>

						 <div class="col-lg-6" style='width:90px;'> 
                     <input class="form-control" name="value" placeholder="Employee" type="text" style='width:90px; text-align:center;' 
					  onkeypress='return isNumberKey(event)' value="<?php echo $vue ?>">
                        </div> 

                       <div class="col-lg-6 input-group">
                       <?php echo"<input type='hidden' value='$rowid' name='rowid'>"; ?>
                      <input class="form-control" name="descri" placeholder="Description" type="text" value="<?php echo $des ?>">
                      <span class="input-group-btn">
                        <button class="btn  btn-primary" type="submit" name="<?php echo $vtn ?>">
						<i class="lnr lnr-magnifier"></i> <?php echo $btn ?></button>
                      </span>
                      
                      
                      </div>
                  
            </form> 
            </div>
               
            </div>

			 <?php 
if($pto==10)
echo"<center><div class='alert alert-danger' style='width:48%;text-align:center;float:center;background-color: #60c560;color: #ffffff;border-radius:5px;'>
		<i class='lnr lnr-checkmark-circle'></i> &nbsp;&nbsp; <button class='close' data-dismiss='alert' type='button'>×</button>New Rule Has Been Created.
		</div></center>";
if($pto==20)
echo"<center><div class='alert alert-danger' style='width:48%;text-align:center;float:center;background-color: #60c560;color: #ffffff;border-radius:5px;'>
		<i class='lnr lnr-checkmark-circle'></i> &nbsp;&nbsp; <button class='close' data-dismiss='alert' type='button'>×</button>Existing Rule Has Been Updated.
		</div></center>";
		?>
             
             <div class="row">
            <div class="col-lg-12">
             <span>Total Records Found : <b><?php echo $fo ?></b></span>
            <div class="widget-container fluid-height clearfix">
            <div class="widget-content padded clearfix">
               
                                 <table class="table table-striped">     
                                      <thead>
                    <tr role="row">
                     <th class="hidden-xs"> S.NO</th>
                       <th class="hidden-xs"> Date </th> 
                       <th> Description </th> 
						 <th> Employer </th>
                        <th> Employee </th>
                        <th class="hidden-xs"> Status </th>
                        <th style="text-align:center;">Actions</th>
                     </tr>
                    </thead>
                                        <tbody>
					<?php
					$n=1;
						while($ro=mysqli_fetch_assoc($do)){
$code=$ro['Number'];
$dati=$ro['Date'];
$empoe=$ro['Employee'];
$empor=$ro['Employer'];
$descri=$ro['Description'];
	
	if($empoe<100)
		$per="%";
	else
		$per="";

			$lbt="<td style='width:20px;'><span class='label label-success' style='width:80px;'>ACTIVE</span></td>";
			
		print("<tr>
                        <td class=hidden-xs style='text-align:center;'>$n</td>
                        <td class='hidden-xs'> $dati </td><td> $descri </td>
						<td> $empor $per </td><td class='hidden-xs'> $empoe $per </td> $lbt 

                     <form method=post action='rules.php'><td align='right' style='width:20px;padding-right:10px;'>
                        <input type='hidden' name='rowid' value='$code'>
									
					  <button style='background-color:transparent; border:0px solid black; width:50px;' type='submit' name='edit_id'>
						  <span style=color:red;>Edit</span></button> 
                          </td></form></tr>");
						  $n++;
						}
						?>
						
                    </tbody>   
                  </table>
                    <div class="row">
                  <div class="col-lg-12">
                  <div class="pull-right">
                  <ul class="pagination">
                      <li>
                                            </li>
                      <li class="active">
                        <a href="#">
                        1                        </a>
                      </li>
                                             <li>
                        <a href="#">
                        2                        </a>
                      </li>
                                             <li>
                                              <a class="icon" href="#">
                        <i class="lnr lnr-chevron-right"></i></a>
                                           </li>
                    </ul>
              </div></div></div>                     
                
              </div>
            </div>

<?php
include'footer.php';
?>