<?php include("_config/dbconfig.php");
include("_includes/head.php");?>
<title>Agents</title>
<?php include("_includes/header.php");



if(isset($_GET['ag']) && !empty($_GET['ag']) && isset($_GET['st']) && !empty($_GET['st'])){
    $agent_id = $_GET['ag'];
    $status   = base64_decode($_GET['st']);
    $obj_agents_class->updateStatus($agent_id, $status);
    
    echo "<script>window.location='agents.php'</script>";
    die();   
 
}
    $all_agents = $obj_agents_class->getAgent();
    
    /*echo '<pre>';
    print_r($all_cats2); 
    echo '</pre>'; */
?>
    

<div class="col-sm-12 right_form">
        <div class="title">
            <div class="row">
                <div class="col-md-8 col-sm-12">
                    <h1>Agents</h1>
                </div>
                <div class="col-md-4 col-sm-12">
			        <a href="agent_controls.php" style="cursor: pointer;" class="btn btn-primary btn-o add-event"> Add New </a>
                </div>
                
            </div>  
        </div> 
        
        <ol class="breadcrumb white">
          <li><a href="dashboard.php">Dashboard</a></li>
          <li class="active">Agents</li>
        </ol>
</div>



<?php 
/*        echo "<pre>";
        print_r($_SESSION);
        echo '</pre>';
   */     
?>
  	<div class="col-sm-12 form_inner">
			<div class="col-md-12 table_inner" style="padding:0;">
                <div class="table-responsive">
                    <table id="example" class="display nowrap lisitng_table" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                            	<th>Sr. </th>
                                <th>Full Name </th>
                                <th>Email</th>
                                <th>Mobile</th>
                                <th>CNIC</th>
                                <th>Status</th>
                                <th>Modify</th>
                                <th></th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php $i=1; foreach($all_agents as $cat){ ?>    
                            <tr>
                            	<td><?php echo $i++;?></td>
                                <td><?php echo $cat['name']?> </td>
                                <td><?php echo $cat['email']?></td>
                                <td><?php echo $cat['mobile_no']?></td>
                                <td><?php echo $cat['cnic']?></td>
                                <td>    <?php echo $cat['status']; ?> </td>
                                <td>
                                    <a href="agent_controls.php?view=<?php echo base64_encode($cat['agent_id'])?>"> View Details  </a> | 
                                    <a href="agent_controls.php?edit=<?php echo base64_encode($cat['agent_id'])?>"> Edit  </a> | 
                                    
                                    <?php if($cat['status']=="Active") { ?>
                                    <a href="agents.php?ag=<?php echo $cat['agent_id']?>&st=<?php echo base64_encode('Deactive') ?>"> Deactivate</a>
                                    <?php } else {?>
                                    <a href="agents.php?ag=<?php echo $cat['agent_id']?>&st=<?php echo base64_encode('Active') ?>">  Activate </a>
                                    <?php } ?>
                                </td>
                                <td></td>
                            </tr>

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


<?php include("_includes/footer.php"); ?>
<script>
$(document).ready(function() {
    $('#example').DataTable( {
        responsive: {
            details: {
                type: 'column',
                target: -1
            }
        },
        columnDefs: [ {
            className: 'control',
            orderable: false,
            targets:   -1
        }]
    });
	
});
</script>