<?php 
include ('includes/header.php');

//table name
$table_name = "reports";
$page = "report.php";

$data = ['username' => '121','macaddress' => '122','section' => '123','section_category' => '124','report_title' => '125','stream_name' => '126','stream_id' => '127','report_sub_title' => '127','report_cases' => '127','report_custom_message' => '127'];
//$db->insertIfEmpty($table_name, $data);

//table call
$res = $db->select($table_name, '*', '', '');

//update call
@$resU = $db->select($table_name, '*', 'id = :id', '', [':id' => $_GET['update']]);

//delete row
if(isset($_GET['delete'])){
	$db->delete($table_name, 'id = :id',[':id' => $_GET['delete']]);
	echo "<script>window.location.href='".$page."?status=2'</script>";
}

?>

<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content" style="background-color: black;">
			<div class="modal-header">
				<h2 style="color: white;">Confirm</h2>
			</div>
			<div class="modal-body" style="color: white;">
				Do you really want to delete?
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel</button>
				<a style="color: white;" class="btn btn-danger btn-ok">Delete</a>
			</div>
		</div>
	</div>
</div>

		<div class="col-md-12 mx-auto ctmain-table">
			<div class="card-body">
				<div class="card ctcard">
					<div class="card-header card-header-warning">
						<center>
							<h2><i class="icon icon-commenting"></i> Current Reports</h2>
						</center>
					</div>
					<div class="card-body" >
					    <div class="col-12">
    			    </div>
						<br>
						<div class="table-responsive">
							<table class="table table-striped table-sm">
							<thead style="color:white!important">
								<tr>
									<th>Username</th>
									<th>Macaddress</th>
									<th>Section</th>
									<th>Section Category</th>
									<th>Title</th>
									<th>Stream Name</th>
									<th>Stream ID</th>
									<th>View Report</th>
									<th>&nbspDelete</th>
								</tr>
							</thead>
							<?php foreach ($res as $row) {
							?>
							<tbody>
								<tr>
									<td><?=$row['username'] ?></a></td>
									<td><?=$row['macaddress'] ?></td>
									<td><?=$row['section'] ?></a></td>
									<td><?=$row['section_category'] ?></td>
									<td><?=$row['report_title'] ?></a></td>
									<td><?=$row['stream_name'] ?></td>
									<td><?=$row['stream_id'] ?></a></td>
									<td><button type="button" class="btn btn-warning" data-toggle="modal" data-target="#message<?=$row['id']?>">View</button>
									</td>
									<td><a class="btn btn-danger btn-ok" href="#" data-href="<?=$page ?>?delete=<?=$row['id'] ?>" data-toggle="modal" data-target="#confirm-delete"><i class="fa fa-trash-o"></i></a>
									</td>
								</tr>
							</tbody>
							<div class="modal fade" id="message<?=$row['id']?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
							<div class="modal-dialog">
								<div class="modal-content" style="background-color: black;">
									<div class="modal-header">
										Sub Title:&nbsp<?=$row['report_sub_title'] ?> <br>
										Case:&nbsp<?=$row['report_cases'] ?>
									</div>
									<div class="modal-body" style="color: white;">
										Message: <br>
										<?php echo $row['report_custom_message']; ?>
									</div>
									<div class="modal-footer">
										<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
									</div>
								</div>
							</div>
						</div>
							<?php
							}?>
							</table>
						</div>
						</div>
					</div>
				</div>


	</div>


<?php include ('includes/footer.php');?>

</body>
</html>