<?php
session_start();
require_once '../includes/config.php';
require_once '../includes/database.php';
require_once '../includes/check_session.php';
require_once '../includes/auth.php';

$auth = array('customer_admin');
$authRes = checkAuth($auth, $user);
if(!$authRes)
{
    header('Location: ../index.php');
    exit;
}

$page = 1;
class Add extends database{
	
  public function getAlUsers($page,$id)
  {
      
      $where['cl_user_id'] = $id;
        return $this->fetchAll("tb_users", $where, 'created_at', 'DESC', ($page - 1) * 50, 50);
  }
}

$obj = new Add();
$users = $obj->getAlUsers($page, $user['cl_id']);
$templateType = 'add';
include '../header.php';
?>

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

            <div class="container-xxl flex-grow-1 container-p-y">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card ">
                            <div class="card-header">
                                <h4 class="fw-bold py-3 mb-4">Add User</h4>
                            </div>
                            <div class="col-sm-12 card-body">
                        
					
                                <div class="col-sm-12">
                                    <div class="order-contact">
                                            <div class="row edit-user-box">
                                                <div class="col-sm-12">
                                                    <div class="row">
                                                        <form method="post" id="form1" class="form" cluster-url="ajax/add_ajax.php" cluster-redirect="add.php">
                                                            <div class="error-main"></div>		
                                                            <?php include "template/form.php"; ?>
                                                        </form>
                                                    </div>
                                                </div>
                                            </div>                            
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12  order-wraper mt-2">
                	<div class="card mb-4">
                            <div class="card-header">Current Users</div>
                            <div class="card-body">
                                <div class="col-sm-12">
                    	<div class="curent-user">
                        	<div class="row">
								
                                <div class="col-sm-12">
                                    <div class="curent-user-nav">
                                        <table class="table table-responsive"> 
                                                        <tr>
                                                                <th>Email</th>
                                                                <th>
                                                                    Role
                                                                </th>
                                                                <th>Actions</th>
                                                        </tr>
                                                        <?php

                                                         foreach($users as $u)
                                                         {
                                                               
                                                        ?>
                                                        <tr>
                                                                <td><?php echo htmlspecialchars($u['cl_email']);?></td>
                                                                <td>
                                                                    <?php echo htmlspecialchars($u['cl_type']);?>
                                                                </td>
                                                                <td><button id="remove" data-href="user-remove?id=<?php  echo htmlspecialchars($u['id']); ?>" class="track-btn btn btn-danger">REMOVE</button>
                                                                <a id="edit" href="add-users.php?id=<?php  echo htmlspecialchars($u['id']); ?>" class="track-btn btn btn-primary">RESET PASSWORD</a></td>
                                                        </tr>
                                                        <?php

                                                         }
                                                        ?>
                                </table>
                                    	
                                    </div>
                            	</div>
                                
                        	</div>                            
                        </div>
                    </div>
                            </div>
                  
                    
                </div>
                
            </div>
        </div>
	</div>
<?php include_once '../footer.php';