<?php
if($leev !='Admin')
{
  header("location:logout.php");
}
?>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h4 class="m-0">Manage Users</h4>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item">Dashboard</li>
              <li class="breadcrumb-item ">Extra</li>
              <li class="breadcrumb-item active">Manage Users</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    
    
    <section class="content">
      <div class="container-fluid">
        <div class="row">
            
        <div class="col-md-6 col-sm-6 col-12">
            <div class="info-box">
              <div class="info-box-content">
               <form method="post" action="" name="form1"  enctype="multipart/form-data" onsubmit="return false;">
                   <h6><strong class="text-danger">Add Users</strong></h6>
            <div class="row">       
             <div class="col-md-6">       
            <div class="form-group">
                <label for="inputStatus">Select Staff</label>
                <select id="employee" class="form-control custom-select" required>
                <option selected disabled value="">Select ---</option>
                <?php                  
                     $query=mysqli_query($con,"select * from Staffs where Status='Active' AND User ='No'");
                    while($row=mysqli_fetch_array($query))
                    {?>
                    <option value="<?php echo htmlentities($row['id']); ?>"><?php echo htmlentities($row['Name']); ?>
                    </option>
                    <?php
                    }
                    ?>
                </select>
                
                <label id="useraddlabel"></label>
            </div>
            </div>
            <div class="col-md-3">
            <div class="form-group">
                <label for="inputStatus">Level of Access</label>
                <select id="posi" class="form-control custom-select" required>
                <option selected disabled value="">---</option>
                <option   value="Admin">Admin</option>
                <option value="Accountant">Accountant</option>
                <option  value="Data Editor">Data Editor</option>
                </select>
            </div>
            </div>
            
            <div class="col-md-3">
            <div class="form-group">
                <label for="inputStatus" style="color:#FFF">...</label>
                
               <button id="adduserbtn" class="btn btn-success  form-control btn-sm" >Add <i class="fa fa-plus"></i>
               </button>
               
               </div>
            </div>
            
            
            </div>
               </form>
              </div>
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div> 
            
            
          <div class="col-md-3 col-sm-6 col-12">
            <div class="info-box">
              <span class="info-box-icon bg-info"><i class="fa fa-group"></i></span>
              
              <?php
               // include('../include/config.php');
                $result = mysqli_query($con,"SELECT * FROM users where Aces='Yes'");
                $num_rows1 = mysqli_num_rows($result);
                {
                $sts=htmlentities($num_rows1); 
                }
                ?>
                                  
              <div class="info-box-content">
                <span class="info-box-text">All System Users</span>
                <h4 class="info-box-number budge"><?php echo $sts; ?></h4>
              </div>
                
              <!-- /.info-box-content -->
            </div>
            <!-- /.info-box -->
          </div>
          
        <div class="col-md-3 col-sm-6 col-12">
        <div class="info-box">
        <span class="info-box-icon bg-success"><i class="far fa-flag"></i></span>
    <?php                  
    $query=mysqli_query($con,"select users.*, Staffs.Name as nm from users join Staffs ON Staffs.id=users.userid ORDER by id DESC limit 1");
    
    while($row=mysqli_fetch_array($query))
    {
     $nm=htmlentities($row['nm']);
    }
    ?>
        <div class="info-box-content">
        <span class="info-box-text">Latest User</span>
        <span class="info-box-number"><?php echo $nm; ?></span>
        </div>
        <!-- /.info-box-content -->
        </div>
        <!-- /.info-box -->
        </div>
        
          </div>
         </div>
    </section>
   
    <section class="content">
      <div class="row">
        <div class="col-md-12">
          <div class="card card-primary">
            <div class="card-header">
              <h3 class="card-title">Registered Users</h3>

              <div class="card-tools">
                <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                  <i class="fas fa-minus"></i>
                </button>
              </div>
            </div>
            <div class="card-body">
            <div class="tableholder datatable-dashv1-list custom-datatable-overright">
              <div class="table-responsive">
              <table class="table datatable" style="font-size:13px" id="table" data-toggle="table" data-pagination="true" data-search="true" data-show-columns="true" data-show-pagination-switch="true" data-show-refresh="true" data-key-events="true" data-show-toggle="true" data-resizable="true" data-cookie="true"
              data-cookie-id-table="saveId" data-show-export="true" data-click-to-select="true" data-toolbar="#toolbar">
                <thead>
                  <tr>
                    <th  data-field="#">#</th>
                    <th  data-field="Name">Name</th>
                    <th  data-field="Role">User Level</th>
                    <th  data-field="Access">Access to System</th>
                    <th  data-field="Staff Status">Staff Status</th>        
                    <th  data-field="Invitation">Invitation</th> 
                     <th  data-field="Privileges">More Privileges</th>
                    <th  data-field="action">Action</th>
                  </tr>
                </thead>
                <tbody>
                  <?php                  
                     $query=mysqli_query($con,"select users.*, Staffs.Name as nm,Staffs.Status as sts,Staffs.User as uss from users join Staffs ON Staffs.id=users.userid ORDER by uss ASC");
                    $cnt=1;
                    while($row=mysqli_fetch_array($query))
                    {
                    $idd=htmlentities($row['userid']);
                    if($idauto==$idd)
                    {
                    ?>
                    <tr class="alert-warning">
                    <td><?php echo $cnt;?>  </td>
                    <td><?php echo htmlentities($row['nm']); ?></td>
                    <td disabled="true"><?php echo htmlentities($row['Level']); ?>
                    </td>
                    
                     <?php $ac=htmlentities($row['Aces']);
                     if($ac=='No')
                     {
                     ?>
                    <td class="bg-warning" title="Can not login !!"><?php echo htmlentities($row['Aces']); ?></td>
                    <?php
                    }else
                     {
                      ?>
                      <td><?php echo htmlentities($row['Aces']); ?></td>
                      <?php
                       }
                        ?>
                       <?php
                      $sta=$row['sts'];

                      if($sta=='Active')
                      {
                      ?>
                    <td class="alert-success">
                        <label >Active</label>
                    </td>
                    <?php
                      }
                    else{
                      ?>
                     <td class="alert-danger" title="Can not Login">
                        <label>In-active</label>
                     </td>
                   <?php }?>
                   
                   
                   <?php
                    if($sta=='Active')
                      {
                     ?>
                   <td></td>
                   <?php
                    }else
                    {
                    ?>
                    <td></td>
                    <?php
                    }
                    ?>
                    <td>
                     <?php
                    $level=htmlentities($row['Level']);
                    if($level=='Admin')
                    {
                    ?> 
                    <ul>
                        <li><strong class="text-white">Create Users</strong></li>
                        <li><strong class="text-white">Manage Users</strong></li>
                        <li><strong class="text-white">Approve/Delete Payroll</strong></li>
                    </ul> 
                    <?php
                    }
                    ?>
                    </td>
                    <td>
                      No Action
                    </td>
                  </tr>
                    <?php
                    }else
                    
                    
                    {
                    ?>
                  <tr>
                    <td><?php echo $cnt ?></td>
                    <td><?php echo htmlentities($row['nm']); ?></td>
                    <td><?php echo htmlentities($row['Level']); ?>  <span class="btn badge changedata bg-primary" >Change <i class="fa fa-gear"></i></span>
                    </td>
                  
                     <?php $ac=htmlentities($row['Aces']);
                     if($ac=='No')
                     {
                     ?>
                    <td title="Can not login !!" > <?php echo htmlentities($row['Aces']); ?> | <span class="btn badge bg-warning changedata" >Change <i class="fa fa-gear"></i></span>
                    </td>
                    <?php
                    }else
                     {
                      ?>
                      <td> <?php echo htmlentities($row['Aces']); ?>  <span class="btn badge changedata bg-primary" >Change <i class="fa fa-gear"></i></span>
                      </td>
                      <?php
                       }
                        ?>
                       <?php
                      $sta=$row['sts'];

                      if($sta=='Active')
                      {
                      ?>
                    <td class="alert-success">
                        <label>Active</label>
                    </td>
                    <?php
                      }
                    else{
                      ?>
                     <td class="alert-danger" title="Can not Login">
                        <label >In-active</label>
                     </td>
                   <?php }?>
                  
                   <?php
                    if($sta=='Active')
                      {
                      $pas=htmlentities($row['Pass']);
                      if($pas !='')
                      {
                      ?>
                      <td></td>
                      <?php
                      }else
                      {
                     ?>
                   <td><a href="index.php?page=Invitation&GHFxvsgHM=<?php echo $row['userid']; ?>" data-toggle="tooltip" title="Demo logins will be sent via email to this user" id="btninvite" class="badge bg-primary">Send Invitation</a></td>
                   <?php
                      }
                    }else
                    {
                    ?>
                    <td></td>
                    <?php
                    }
                    ?>
                   <td class="bg-success">
                    <?php
                    $level=htmlentities($row['Level']);
                    if($level=='Admin')
                    {
                    ?> 
                    <ul>
                        <li><strong class="text-white">Create Users</strong></li>
                        <li><strong class="text-white">Manage Users</strong></li>
                        <li><strong class="text-white">Approve/Delete Payroll</strong></li>
                    </ul> 
                    <?php
                    }
                    ?>
                   </td>
                    <td>
                      <input type="hidden" class="useridholding" value="<?php echo $row['userid'];  ?>" />  
                      <a href="#"  class="badge alert-danger empremove" > Remove as user  <i class="fa fa-trash text-red"></i>
                      </a></td>
                  </tr>
                  <?php
                    }
                   $cnt=$cnt+1;
                   }
                   ?>
                </tbody>
              </table>
              </div>
            </div>
          
            </div>
            <!-- /.card-body -->
          </div>
          <!-- /.card -->
        </div>
      </div>
      
    </section>
</div>

