Mini Shell
| Direktori : /home/mhcadmin/www/ |
|
|
| Current File : /home/mhcadmin/www/ManageDebtorsList.php |
<?php
session_start();
require_once 'config/config.php';
require_once 'include/auth_validate.php';
/////// Code for new access control on header menu /////////////////////////
$User = $_SESSION['id'];
$UserAccessName= $sql = "";
$result = mysqli_query( $connection,"SELECT * FROM admin_accounts WHERE id = '$User' ");
$num = mysqli_num_rows($result);
if ($num >0){
$rows = mysqli_fetch_array($result);
$UserAccessName = $rows['UserAccessName'];
}
//Only super admin is allowed to access this page
if ($_SESSION['admin_type'] !== 'super') {
// show permission denied message
header('HTTP/1.1 401 Unauthorized', true, 401);
exit("401 Unauthorized");
}
$db = getDbInstance();
//Get data from query string
$search_string = filter_input(INPUT_GET, 'search_string');
$del_id = filter_input(INPUT_GET, 'del_id');
$filter_col = filter_input(INPUT_GET, 'filter_col');
$order_by = filter_input(INPUT_GET, 'order_by');
$page = filter_input(INPUT_GET, 'page');
$pagelimit = 20;
if ($page == "") {
$page = 1;
}
// If filter types are not selected we show latest added data first
if ($filter_col == "") {
$filter_col = "DLID";
}
if ($order_by == "") {
$order_by = "desc";
}
// select the columns
//$db->where('Full_Name', 'Administrator');
$select = array('DLID', 'DebtorNo', 'Name','PropertyNo','DebtorType','Address','Phone','Status','Balance');
// If user searches
if ($search_string) {
$db->where('DebtorNo', '%' . $search_string . '%', 'like');
}
if ($order_by) {
$db->orderBy($filter_col, $order_by);
}
$db->pageLimit = $pagelimit;
$result = $db->arraybuilder()->paginate("debtorslist", $page, $select);
$total_pages = $db->totalPages;
// get columns for order filter
foreach ($result as $value) {
foreach ($value as $col_name => $col_value) {
$filter_options[$col_name] = $col_name;
}
//execute only once
break;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$DLID = $_POST['DLID'];
$DebtorNo = $_POST['DebtorNo'];
$PropertyNo = $_POST['PropertyNo'];
$DebtorType = $_POST['DebtorType'];
$Address = $_POST['Address'];
$Phone = $_POST['Phone'];
$Status = $_POST['Status'];
$Balance = $_POST['Balance'];
$Name = $_POST['Name'];
$sql = mysqli_query($connection,"UPDATE debtorslist SET DebtorNo='$DebtorNo', Name='$Name', PropertyNo ='$PropertyNo', DebtorType = '$DebtorType', Address = '$Address', Phone = '$Phone', Status = '$Status', Balance = '$Balance' WHERE DLID = '$DLID'");
if ($sql){
$_SESSION['success'] = "Record Updated successfully!";
header('location: ManageDebtorsList.php');
} else {
$_SESSION['failure'] = "Oops! Record Update Failed";
header('location: ManageDebtorsList.php');
}
exit();
}
include_once 'include/AdminHeader.php';
?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-6">
<h4 class="page-header">Manage Debtors List</h4>
</div>
<div class="col-lg-6" style="">
<div class="page-action-links text-right">
<a href="ManageDebtorsList.php?operation=Manage%20Debtors%20lists"> <button class="btn btn-success"><span class="glyphicon glyphicon-refresh"></span> Refresh</button></a>
</div>
</div>
</div>
<?php include('include/flash_messages.php') ?>
<?php
if (isset($del_stat) && $del_stat == 1) {
echo '<div class="alert alert-info">Successfully deleted</div>';
}
?>
<!-- Begin filter section-->
<div class="well text-center filter-form">
<form class="form form-inline" action="">
<label for="input_search" >Search</label>
<input type="text" class="form-control" id="input_search" placeholder = "By Debtor Number" name="search_string" value="<?php echo $search_string; ?>">
<label for ="input_order">Order By</label>
<select name="filter_col" class="form-control">
<?php
foreach ($filter_options as $option) {
($filter_col === $option) ? $selected = "selected" : $selected = "";
echo ' <option value="' . $option . '" ' . $selected . '>' . $option . '</option>';
}
?>
</select>
<select name="order_by" class="form-control" id="input_order">
<option value="Asc" <?php
if ($order_by == 'Asc') {
echo "selected";
}
?> >Asc</option>
<option value="Desc" <?php
if ($order_by == 'Desc') {
echo "selected";
}
?>>Desc</option>
</select>
<input type="submit" value="Go" class="btn btn-primary">
</form>
</div>
<!-- Filter section end-->
<hr>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr style= "background-color:#BAC4CC;">
<th>DebtorNo</th>
<th>PropertyNo</th>
<th>Name</th>
<th>DebtorType</th>
<th>Address</th>
<th>Phone</th>
<th>Status</th>
<th>Balance</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $row) : ?>
<tr>
<td><h5><?php echo htmlspecialchars($row['DebtorNo']) ?></h5></td>
<td><h5><?php echo htmlspecialchars($row['PropertyNo']) ?></h5></td>
<td><h5><?php echo htmlspecialchars($row['Name']) ?></h5></td>
<td><h5><?php echo htmlspecialchars($row['DebtorType']) ?></h5></td>
<td><h5><?php echo htmlspecialchars($row['Address']) ?></h5></td>
<td><h5><?php echo htmlspecialchars($row['Phone']) ?></h5></td>
<td><h5><?php echo htmlspecialchars($row['Status']) ?></h5></td>
<td><h5><?php echo htmlspecialchars($row['Balance']) ?></h5></td>
<td>
<ul class="nav navbar-top-links navbar-right">
<!-- /.dropdown -->
<!-- /.dropdown -->
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-folder-open"></i>
</a>
<ul class="dropdown-menu dropdown-user">
<li class="divider"></li>
<li><h6><a href="" data-toggle="modal" data-target="#Update-Account-<?php echo $row['DLID'] ?>" ><span class="btn btn-primary" > Update Record</span></a>
</h6></li>
<li class="divider"></li>
<li><h6><a href="" data-toggle="modal" data-target="#confirm-delete-<?php echo $row['DLID'] ?>" ><span class="btn btn-danger delete_btn"> Delete Record</span></a>
</h6></li>
</ul>
</div>
<!-- /.dropdown-user -->
<!-- /.dropdown -->
</ul>
</td>
</tr>
<!-- Record Updation Modal-->
<div class="modal fade" id="Update-Account-<?php echo $row['DLID'] ?>" role="dialog">
<div class="modal-dialog">
<form action="" method="POST">
<!-- Modal content-->
<?php
$DLID = $row['DLID'];
$queryv = "SELECT * FROM `debtorslist` WHERE DLID = '$DLID'";
$resultv = mysqli_query($connection, $queryv);
$numv = mysqli_num_rows($resultv);
if ($numv >0){
$rowsv = mysqli_fetch_array($resultv);
//$UserAccessName = $rowsv['UserAccessName'];
}
?>
<div class="modal-content">
<div class="modal-header" style="text-align:center; background-color:#BAC4CC;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Update Debtor Record</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label class="control-label">DebtorNo *</label>
<input type="text" name="DebtorNo" class="form-control" value="<?php echo $rowsv['DebtorNo'] ?>" required autocomplete="off">
<input type="hidden" name="DLID" class="form-control" value="<?php echo $row['DLID'] ?>" required autocomplete="off" >
</div>
<div class="form-group">
<label class="control-label">Name *</label>
<input type="text" name="Name" class="form-control" value="<?php echo $rowsv['Name'] ?>" required autocomplete="off">
</div>
<div class="form-group">
<label class="control-label">PropertyNo *</label>
<input type="text" name="PropertyNo" class="form-control" value="<?php echo $rowsv['PropertyNo'] ?>" required autocomplete="off">
</div>
<div class="form-group">
<label class="control-label">DebtorType *</label>
<input type="text" name="DebtorType" class="form-control" value="<?php echo $rowsv['DebtorType'] ?>" required autocomplete="off">
</div>
<div class="form-group">
<label class="control-label">Address *</label>
<input type="text" name="Address" class="form-control" value="<?php echo $rowsv['Address'] ?>" autocomplete="off" >
</div>
<div class="form-group">
<label class="control-label">Phone *</label>
<input type="Phone" name="Phone" class="form-control" value="<?php echo $rowsv['Phone'] ?>" autocomplete="off">
</div>
<div class="form-group">
<label class="control-label">Status *</label>
<input type="text" name="Status" class="form-control" value="<?php echo $rowsv['Status'] ?>" autocomplete="off">
</div>
<div class="form-group">
<label class="control-label">Balance *</label>
<input type="text" name="Balance" class="form-control" value="<?php echo $rowsv['Balance'] ?>" required autocomplete="off">
</div>
<div class="form-group">
</div>
</div>
<div class="modal-footer">
<button type="submit" name="submit" id="submit" class="btn btn-warning pull-left" value = "Submit" >Save <span class="glyphicon glyphicon-send"></button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel <span class="glyphicon glyphicon-remove"></button>
</div>
</div>
</form>
</div>
</div>
<!-- Delete Confirmation Modal-->
<div class="modal fade" id="confirm-delete-<?php echo $row['DLID'] ?>" role="dialog">
<div class="modal-dialog">
<form action="DeleteDebtor.php" method="POST">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" style="text-align:center; background-color:#BAC4CC;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Confirm</h4>
</div>
<div class="modal-body">
<input type="hidden" name="del_id" id = "del_id" value="<?php echo $row['DLID'] ?>">
<p>Are you sure you want to delete this debtor Record?</p>
</div>
<div class="modal-footer">
<button type="submit" name="submit" id="submit" class="btn btn-danger delete_btn pull-left" value = "Submit" > Delete <span class="glyphicon glyphicon-trash"></button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Cancel <span class="glyphicon glyphicon-remove"></button>
</div>
</div>
</form>
</div>
</div>
<?php endforeach; ?>
</tbody>
</table>
<!-- Pagination links-->
<div class="text-center">
<?php
if (!empty($_GET)) {
//we must unset $_GET[page] if built by http_build_query function
unset($_GET['page']);
$http_query = "?" . http_build_query($_GET);
} else {
$http_query = "?";
}
if ($total_pages > 1) {
echo '<ul class="pagination text-center">';
for ($i = 1; $i <= $total_pages; $i++) {
($page == $i) ? $li_class = ' class="active"' : $li_class = "";
echo '<li' . $li_class . '><a href="ManageDebtorsList.php' . $http_query . '&page=' . $i . '">' . $i . '</a></li>';
}
echo '</ul></div>';
}
?>
</div>
</div>
<?php include_once 'include/footer.php'; ?>