<?php include('lib/config.php');?>
<?php 
  //--------------- Category Info ----------
  $srno = 0;
								  
  $selQry_users = "SELECT * FROM ".TBL_USERS." WHERE group_id !='1' ORDER BY first_name";
  $usersInfo =  $con->getMultiRow($selQry_users, __FILE__,__LINE__);
  $totUsersListings = count($usersInfo);
	if($totUsersListings>0)
	{
		?>

<table id="tblUsersListings" class="table table-striped table-bordered" style="width:100%">
  <thead>
    <tr>
      <th>Sr#</th>
      <th>Photo</th>
      <th>Name</th>
      <th>Email</th>
      <th>Login ID</th>
      <th>Group</th>
      <th>Status</th>
      <!--<th>Modules Access</th>-->
      <th>Edit</th>
      <th>Delete</th>
    </tr>
  </thead>
  <tbody>
    <?php 
		for($usr=0;$usr<$totUsersListings;$usr++)
		{
			$srno++;
  		//----------------------------------------
		$selQry_user_group = "SELECT * FROM ".TBL_USERS_GROUPS." WHERE id ='".$usersInfo[$usr]['group_id']."' ";
		$usersGroupsInfo =  $con->getSingleRow($selQry_user_group, __FILE__,__LINE__);
		$userGroup = isset($usersGroupsInfo['group_name'])?$usersGroupsInfo['group_name']:'';
		//----------------------------------------
?>
    <tr>
      <td><?php echo $srno;?>.</td>
      <td style="text-align:left;"><img src="uploads/users/<?php echo $usersInfo[$usr]['user_pic'];?>" width="50" height="50"></td>
      <td style="text-align:left;"><?php echo $usersInfo[$usr]['first_name'].' '.$usersInfo[$usr]['last_name'];?></td>
      <td style="text-align:left;"><?php echo $usersInfo[$usr]['user_email'];?></td>
      <td style="text-align:left;"><?php echo $usersInfo[$usr]['user_name'];?></td>
      <td style="text-align:left;"><?php echo $userGroup;?></td>
      <td style="text-align:left;"><?php if($usersInfo[$usr]['status']=='1'){?>
        <button type="button" class="btn btn-sm btn-success">Active</button>
        <?php }else if($usersInfo[$usr]['status']=='0'){?>
        <button type="button" class="btn btn-sm btn-danger">InActive</button>
        <?php }?>
      </td>
      <!--<td><p data-placement="top" data-toggle="tooltip" title="">
      <button class="btn btn-info btn-xs openPopup" data-title="User Modules Access" data-toggle="modal" data-target="user-modules-access.php?uid=<?php echo $usersInfo[$usr]['user_id'];?>" ><span class="glyphicon glyphicon-user"></span> Modules Access</button>
  </td>-->
      <td><p data-placement="top" data-toggle="tooltip" title="">
          <button class="btn btn-primary btn-xs openPopup" data-title="Edit User" data-target="edit-user.php?uid=<?php echo $usersInfo[$usr]['user_id'];?>"><span class="glyphicon glyphicon-pencil"></span> Edit</button>
        </p></td>
      <td><p data-placement="top" data-toggle="tooltip" title="">
          <button class="btn btn-danger btn-xs openPopup" data-title="Delete User" data-toggle="modal" data-target="del-user.php?uid=<?php echo $usersInfo[$usr]['user_id'];?>" ><span class="glyphicon glyphicon-trash"></span> Delete</button>
      </td>
    </tr>
    <?php }
?>
  </tbody>
</table>
<?php 
}?>
<script>
$(document).ready(function(e){
	
	$('#tblUsersListings').DataTable();
	
	$( ".openPopup" ).click(function() {
	 
	  var dataURL = $(this).attr('data-target');
	  var dataTitle = $(this).attr('data-title');
	  
	  $('#myModal').find('.modal-title').text(dataTitle);
      //$('#myModal').modal({show:true});  
		$('.modal-body').load(dataURL,function(){
            $('#myModal').modal({show:true});
        });
	});
});
</script>
