<?php
session_start();
require("config.php");

if(!isset($_SESSION['auser'])){
header("location:index.php");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<title>Clan Homes | Admin</title>

<link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.png">
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/font-awesome.min.css">
<link rel="stylesheet" href="assets/css/feathericon.min.css">
<link rel="stylesheet" href="assets/plugins/datatables/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="assets/css/style.css">
</head>

<body>

<?php include("header.php"); ?>

<div class="page-wrapper">
<div class="content container-fluid">

<div class="page-header">
<div class="row">
<div class="col">
<h3 class="page-title">Builder</h3>
<ul class="breadcrumb">
<li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
<li class="breadcrumb-item active">Builder</li>
</ul>
</div>
</div>
</div>

<div class="row">
<div class="col-sm-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Builder List</h4>
<?php
if(isset($_GET['msg'])){
echo htmlspecialchars($_GET['msg']);
}
?>
</div>

<div class="card-body">
<table id="basic-datatable" class="table table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Email</th>
<th>Contact</th>
<th>User Type</th>
<th>Image</th>
<th>Action</th>
</tr>
</thead>
<tbody>

<?php
$stmt = $con->prepare("SELECT uid, uname, uemail, uphone, utype, uimage FROM user WHERE utype=?");
$type = "builder";
$stmt->bind_param("s", $type);
$stmt->execute();
$result = $stmt->get_result();

$cnt = 1;
while($row = $result->fetch_assoc()){
$image = !empty($row['uimage']) ? htmlspecialchars($row['uimage']) : "default.png";
?>

<tr>
<td><?php echo $cnt++; ?></td>
<td><?php echo htmlspecialchars($row['uname']); ?></td>
<td><?php echo htmlspecialchars($row['uemail']); ?></td>
<td><?php echo htmlspecialchars($row['uphone']); ?></td>
<td><?php echo htmlspecialchars($row['utype']); ?></td>
<td>
<img src="user/<?php echo $image; ?>" width="50" height="50" onerror="this.src='user/default.png'">
</td>
<td>
<a href="userbuilderdelete.php?id=<?php echo (int)$row['uid']; ?>"
   onclick="return confirm('Are you sure you want to delete this builder?')">
<button class="btn btn-danger">Delete</button>
</a>
</td>
</tr>

<?php } ?>

</tbody>
</table>
</div>

</div>
</div>
</div>

</div>
</div>

<script src="assets/js/jquery-3.2.1.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="assets/plugins/datatables/dataTables.bootstrap4.min.js"></script>
<script src="assets/js/script.js"></script>

</body>
</html>
