<?php 
if(!isset($_SESSION)) { 
  session_start(); 
  include('../includes/dbcon.php');
}
if(empty($_SESSION['hrm_id'])):
header('Location:../index.php');
endif;
$cval=0;

if(isset($_REQUEST['unit_id']))

  {
 
    $rid=$_GET['unit_id'];

    $stringParts = explode("*", $rid);

    $unit_id  = $stringParts[0];

    $loc_status= $stringParts[1];

   
    if ($loc_status=="Yes"){
      $cval=0;
    }
    else {
      $cval=1;
    }
    mysqli_query($con,"update unit_master set unit_active=$cval where unit_id=$unit_id ")or die(mysqli_error());





}

?>
<!DOCTYPE html>
<html lang="en">


<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>SalesHub | Item Management </title>
  <!-- plugins:css -->
  <?php include('../includes/commonheader.php');?>



</head>
<body>
 <?php include('../includes/header.php');?>
 <?php include('../includes/leftsidebar.php');?>
           <!-- partial -->
 <div class="main-panel">        
        <div class="content-wrapper">

          <div class="page-header">
            <h3 class="page-title">
                New Item Units 
            </h3>
          
          </div>
          <div class="col-12 grid-margin">
              <div class="card">
                <div class="card-body">

              
         
                 
    <form class="needs-validation" novalidate method="post" action="admin_units_add.php" enctype="multipart/form-data" onsubmit="return validateForm()"> 
                  
                    <div class="row">                     
                      <div class="col-md-6">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Unit Name </label>
                          <div class="col-sm-9">
                            <input type="text" class="form-control" id="catname" name="catname" placeholder="">
                          </div>
                        </div>
                      </div>
                      <div class="col-md-6">
           
             
                       





          </div>                            




                    </div>                                     
                 
                     <button type="submit" class="btn btn-primary">Save</button>
                    <button class="btn btn-light">Cancel</button>
                  </form>
                </div>
              </div>
            </div>


  <div class="content-wrapper">
          <div class="col-lg-22 grid-margin stretch-card">
              <div class="card">
                <div class="card-body">
                  <h4 >Item Unit - List </h4>
                  <p class="card-description">
                    <button type="button" onclick="document.location='home.php'" class="btn btn-warning "><i class="fas fa-arrow-left"></i> Go Back
                    
                  </button>
                  </p>
                  <div class="table-responsive">
                    <table class="table table-hover">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>Unit Name</th>                         
                          <th>Active</th>
                          <th>Edit</th> 
                        </tr>
                      </thead>
                      <tbody>
<?php
$rcount=0;
$query=mysqli_query($con,"SELECT * from unit_master")or die(mysqli_error()); 
 while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
             
                $unit_des=$row['unit_des'];
                  $unit_id=$row['unit_id'];
              
                $cat_active=$row['unit_active'];

                if ($cat_active==1) {
                    $locactive="Yes";
                }
             
                if ($cat_active==0) {
                    $locactive="No";
                }

 ?>
   <tr>
                         <td><?php echo $rcount;  ?></td>
                         <td><?php echo $row['unit_des'];?></td>
                        
                         <td><?php if ($row['unit_active']>0) { ?> &#10004;<?php } else { ?> &#10006; <?php } ?><a href="admin_unit_view.php?unit_id=<?php echo $row['unit_id'];echo "*";echo $locactive;?>"> Change</a></td>


                 
</td>  

<td>
              <form method="post" action="#" enctype="multipart/form-data">
                  
                  <input type="hidden" class="form-control pull-right" id="tid" name="tid"  value=" <?php echo $unit_id; ?>">   
                   <input type="hidden" name="fname" id="fname" class="form-control todo-list-input" placeholder="Add To-do" value="<?php echo basename($_SERVER['PHP_SELF']);  ?>">
                

                  

                       <button type="button" class="btn btn-outline-info btn-rounded btn-icon"  data-toggle="modal" data-target="#addvoucher_edit<?php echo $unit_id;?>">
                          <i class="fa fa-edit"></i>
                        </button>

                  
              </form>
              </td> 

 <?php }  ?>
</tr>
                      </tbody>
                    </table>



        </div>  <!----- <div class="content-wrapper">------>
        </div>
          
          
  </div>

 </div><!-----End of main panel--~~~~~~~~~~~~~~~~~~~~~~~--------------->
 </div><!-----Dont Delete this DIV--~~~~~~~~~~~~~~~~~~~~~~~--------------->
</div>
  <!-- container-scroller -->
<?php include('../includes/footer.php');?>
<?php include('../includes/commonjs.php');?>
 
</body>


</html>

<script>
    $( document ).ready(function() {
         // alert("Please Select Order Type");

    });

function validateForm() { 

    //````````route````````````````````````````````````
    if($('#bname').val().trim().length == 0) {
           alert("Please enter the route you visited !!!");               
            return false;
    } ////``````````````````````````````````````````

    



 } ///validateForm() { 

</script>

 <!-- End custom js for this page-->
  <script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })
  })

</script>



