<?php
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `admins` ")or die(mysqli_error("getUSerData A: ".$GLOBALS['con']));$stmt->execute();$a=$stmt->get_result();$stmt->close();
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `agents` WHERE `statuslive`='1' ORDER BY `agent_name` DESC  ")or die(mysqli_error("getUSerData B: ".$GLOBALS['con']));$stmt->execute();$ag=$stmt->get_result();$stmt->close();
$stmt = $GLOBALS['con']->prepare("SELECT * FROM `surveyor` WHERE `statuslive`='1'  ")or die(mysqli_error("getUSerData C: ".$GLOBALS['con']));$stmt->execute();$s=$stmt->get_result();$stmt->close();
?>

<ul class="nav nav-tabs md-tabs nav-justified bg-white  mt-n5 mt-md-0" role="tablist">
<li class="nav-item me-2"><a id="reptab" class="nav-link active btn-info" href="#adminSection" role="tab">Admin</a></li>
<li class="nav-item"><a id="wstab" class="nav-link  btn-info" href="#agentSection" role="tab"></i>Agent</a></li>
<li class="nav-item ml-2"><a id="wstab" class="nav-link  btn-info" href="#surveyorSection" role="tab"></i>Surveyor</a></li>
</ul>

<div class="spacer100"></div>

<h2 id="adminSection">Admin Users</h2>
<table id="table-admin" class="table table-striped" style="width:100%">
<thead class="thead-dark">
<tr><th>Name</th><th>Contact Number</th><th>Email address</th><th>Security Level</th><th>Options</th></tr>
</thead>
<tbody>
<?php while($i=mysqli_fetch_array($a)){?>
<tr id="adminsD<?= $i['id']?>">
<td class="align-middle"><?= $i['name']?></td>
<td class="align-middle"><?= $i['tel']?></td>
<td class="align-middle"><?= $i['email']?></td>
<td class="align-middle text-center"><a id="adminsA<?= $i['id']?>" href="javascript:void(0)" class="btn btn-warning amber darken-<?= $i['access']?>" onClick="change('<?= $i['id']?>','seclev','agents','<?= urlencode('Admin User '.$i['name'])?>')"><?= $i['access']?></a></td>
<td>
<a href="javascript:void(0)" class="btn btn-info me-2"><i class="fad fa-pencil" onClick="change('<?= $i['id']?>','edit','admins')"></i></a>
<a href="javascript:void(0)" class="btn btn-danger"><i class="fad fa-trash" onClick="change('<?= $i['id']?>','remove','admins')"></i></a>

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

</table>
<?php 
$table="table-admin";
//$length="5";
//$scroll="400";
$showFilter="false";
require_once('includes/single_table.engine');
?>

<div class="spacer50"></div>
<hr id="surveyorSection" />
<div class="spacer50"></div>

<h2>Surveyors</h2>
<table id="table-surveyors" class="table table-striped">
<thead class="thead-dark">
<tr><th>Name</th><th>Contact Number</th><th>Email address</th><th>Post Code</th><th>Security Level</th><th>Options</th></tr>
</thead>
<tbody>
<?php while($i=mysqli_fetch_array($s)){?>
<tr id="surveyorD<?= $i['id']?>">
<td class="align-middle"><?= $i['forename']?> <?= $i['surname']?></td>
<td class="align-middle"><?= $i['phone1']?></td>
<td class="align-middle"><?= $i['email']?></td>
<td class="align-middle"><?= $i['post']?></td>
<td class="align-middle"><a id="surveyorA<?= $i['id']?>" href="javascript:void(0)" class="btn btn-warning amber darken-<?= $i['access']?>" onClick="change('<?= $i['id']?>','seclev','surveyor','<?= urlencode('Surveyor User '.$i['forename'].' '.$i['surname'])?>')"><?= $i['access']?></a></td>
<td>
<a href="index.php?t=includes/master&p=surveyor.php&id=<?= $i['id']?>&view=edit" class="btn btn-info me-2"><i class="fa fa-pencil" ></i></a>
<a href="index.php?t=includes/master&p=surveyor.php&id=<?= $i['id']?>&view=load" class="btn btn-secondary me-2"><i class="fad fa-eye"></i></a>
<a href="javascript:void(0)" class="btn btn-danger"><i class="fa fa-trash" onClick="change('<?= $i['id']?>','remove','surveyor')"></i></a>
</td>
</tr>
<?php }?>
</tbody>

</table>
<?php 
$table="table-surveyors";
$length="5";
$scroll="400";
$showFilter="false";
require_once('includes/single_table.engine');
?>

<div class="spacer50"></div>
<hr id="agentSection"/>
<div class="spacer50"></div>

<h2>Agents</h2>
<table id="table-agents" class="table table-striped">
<thead class="thead-dark">
<tr><th>Name</th><th>Contact Number</th><th>Email address</th><th>Post Code</th><th>Security Level</th><th>Options</th></tr>
</thead>
<tbody>
<?php while($i=mysqli_fetch_array($ag)){
if(empty($i['access'])){$i['access']=0;}
?>
<tr id="surveyorD<?= $i['agent_number']?>">
<td class="align-middle"><?= $i['agent_name']?></td>
<td class="align-middle"><?= $i['tel']?></td>
<td class="align-middle"><?= $i['email']?></td>
<td class="align-middle"><?= $i['post']?></td>
<td class="align-middle text-center"><a id="agentsA<?= $i['agent_number']?>" href="javascript:void(0)" class="btn btn-warning amber darken-<?= $i['access']?>" onClick="change('<?= $i['agent_number']?>','seclev','agents','<?= urlencode('Agent User '.$i['agent_name'])?>')"><?= $i['access']?></a></td>
<td>
<a href="javascript:void(0)" class="btn btn-info me-2"><i class="fad fa-pencil" onClick="change('<?= $i['agent_number']?>','edit','agents')"></i></a>
<a href="index.php?t=includes/master&p=agent.php&agent_number=<?= $i['agent_number']?>&view=load" class="btn btn-secondary me-2"><i class="fad fa-eye"></i></a>
<a href="javascript:void(0)" class="btn btn-danger"><i class="fad fa-trash" onClick="change('<?= $i['agent_number']?>','remove','agents')"></i></a>

</td>
</tr>

<?php }?>
</tbody>

</table>
<?php 
$table="table-agents";
$length="5";
$scroll="400";
$showFilter="false";
require_once('includes/single_table.engine');
?>

<hr />

<div class="blockquote">
<h3>Security levels</h3>
<p>
<a href="javascript:void(0)" class="btn-sm btn btn-warning amber darken-1">1</a> Full administrative access<br>
<a href="javascript:void(0)" class="btn-sm btn btn-warning amber darken-2">2</a> Surveyor Enhanced access<br>
<a href="javascript:void(0)" class="btn-sm btn btn-warning amber darken-3">3</a> Surveyor Assigned access<br>
<a href="javascript:void(0)" class="btn-sm btn btn-warning amber darken-4">4</a> Read-Only assigned access<br>
</p>
</div>

<script>
function change(i,t,s,n){
$('#'+s+'R'+i).css('display','table-row')
$('#popupBox .modal-body').html('');
$('#popupBox').modal('show');
$('#popupBox .modal-body').load('functions/edit_user.php?op='+t+'&id='+i+'&type='+s+'&name='+n)
}




function cancel(i,s){
$('#popupBox .modal-body').html('')
$('#popupBox').modal('hide')
}

$('.dt-buttons').css('display','none')
$('#navBox').html('<li class="breadcrumb-item active">User Management</li>');
</script>