200 lines
8.3 KiB
PHP
200 lines
8.3 KiB
PHP
<?PHP
|
|
require_once "./db/config.php";
|
|
require_once "./includes/functions.php";
|
|
|
|
if (!isset($_SESSION["loggedAdmin"]) || empty($_SESSION["loggedAdmin"])) {
|
|
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
|
|
header("location: login.php?redirect_to=$actual_link");
|
|
}
|
|
|
|
$page = "category";
|
|
|
|
if (isset($_POST['addCategory'])) {
|
|
|
|
$name = sanitizeData($_POST['category_name']);
|
|
$status = (int)$_POST['status'];
|
|
|
|
if (isset($connection)) {
|
|
$insertCategory = $connection->query("INSERT INTO `category` (`name`, `status`) VALUES ('$name', $status)");
|
|
if ($insertCategory) {
|
|
showSweetAlert('success', 'Data Saved');
|
|
} else {
|
|
showSweetAlert('error', sanitizeData($connection->error));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<title>Tech4Biz - Category Manage</title>
|
|
<?PHP include "./includes/links.php"; ?>
|
|
</head>
|
|
<body>
|
|
<!-- loader starts-->
|
|
<?PHP include "./includes/loader.php"; ?>
|
|
<!-- loader ends-->
|
|
<!-- tap on top starts-->
|
|
<div class="tap-top"><i data-feather="chevrons-up"></i></div>
|
|
<!-- tap on tap ends-->
|
|
<!-- page-wrapper Start-->
|
|
<div class="page-wrapper compact-wrapper" id="pageWrapper">
|
|
<!-- Page Header Start-->
|
|
<?PHP include "./includes/header.php"; ?>
|
|
<!-- Page Header Ends -->
|
|
<!-- Page Body Start-->
|
|
<div class="page-body-wrapper">
|
|
<!-- Page Sidebar Start-->
|
|
<?PHP include "./includes/sidebar.php"; ?>
|
|
<!-- Page Sidebar Ends-->
|
|
<div class="page-body">
|
|
<div class="container-fluid">
|
|
<div class="page-title">
|
|
<div class="row">
|
|
<div class="col-6">
|
|
<h3>Category Manager</h3>
|
|
</div>
|
|
<div class="col-6">
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item"><a href="index-2.html"> <i data-feather="home"></i></a></li>
|
|
<li class="breadcrumb-item">Home</li>
|
|
<li class="breadcrumb-item active">Category</li>
|
|
</ol>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-sm-12 col-xl-5 col-md-12 col-lg-5">
|
|
<div class="ribbon-wrapper card">
|
|
<div class="card-body">
|
|
|
|
<div class="ribbon ribbon-clip ribbon-primary">Add New Category</div>
|
|
<form name="addCategoryForm" id="addCategoryForm" method="post" action="">
|
|
<div class="row">
|
|
<div class="mb-3 show_error">
|
|
<label for="category_name">Category Name</label>
|
|
<input type="text" class="form-control" name="category_name" id="category_name" placeholder="Enter Category Name">
|
|
</div>
|
|
<div class="mb-3 show_error">
|
|
<label for="category_name">Category Status</label>
|
|
<select class="form-select" id="status" name="status">
|
|
<option selected="selected" value="1">Enable</option>
|
|
<option value="2">Disable</option>
|
|
</select>
|
|
</div>
|
|
|
|
</div>
|
|
<button class="btn btn-primary" type="submit" data-bs-original-title="" title="" name="addCategory">
|
|
Save Category
|
|
</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-sm-12 col-xl-7 col-md-12 col-lg-7">
|
|
<div class="ribbon-wrapper card">
|
|
<div class="card-body">
|
|
<div class="ribbon ribbon-clip ribbon-primary">Category List</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-bordered" id="basic-1">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Name</th>
|
|
<th>Status</th>
|
|
<th>Created At</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?PHP
|
|
if (isset($connection)) {
|
|
$getCategories = $connection->query("SELECT * FROM `category` ORDER BY `id` DESC;");
|
|
if ($getCategories) {
|
|
while ($category = $getCategories->fetch_object()) { ?>
|
|
<tr>
|
|
<td><?PHP echo $category->id ?></td>
|
|
<td><?PHP echo $category->name ?></td>
|
|
<td style="cursor: pointer;">
|
|
<?PHP echo $category->status == 1 ? ' <span class="badge badge-success change__status" data-category="' . $category->id . '">Active</span>' : '<span class="badge badge-danger change__status" data-category="' . $category->id . '">Inactive</span>' ?>
|
|
</td>
|
|
<td><?PHP echo $category->created_at ?></td>
|
|
<td><?PHP echo $category->id ?></td>
|
|
</tr>
|
|
<?PHP }
|
|
}
|
|
}
|
|
?>
|
|
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<!-- footer start-->
|
|
<?PHP include './includes/footer.php'; ?>
|
|
<!-- footer end-->
|
|
</div>
|
|
</div>
|
|
<?PHP include './includes/scripts.php'; ?>
|
|
<script>
|
|
$(document).ready(function () {
|
|
if ($("#basic-1").length > 0) {
|
|
$("#basic-1").dataTable();
|
|
}
|
|
|
|
|
|
$('.change__status').click(function () {
|
|
let id = parseInt($(this).attr('data-category'));
|
|
|
|
bootbox.confirm({
|
|
closeButton: false,
|
|
message: `Are You Sure Want To Change Category Status?`,
|
|
buttons: {
|
|
confirm: {
|
|
label: 'Yes',
|
|
className: 'btn-success'
|
|
},
|
|
cancel: {
|
|
label: 'No',
|
|
className: 'btn-danger'
|
|
}
|
|
},
|
|
callback: function (result) {
|
|
if (result === true) {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '../ajax.php',
|
|
data: {
|
|
category__change__status: 'category__change__status',
|
|
id: id,
|
|
},
|
|
success: function (data) {
|
|
if (data === 'TRUE') {
|
|
location.reload();
|
|
} else {
|
|
bootbox.alert({
|
|
closeButton: false,
|
|
message: "Can't handle this request now! Contact Administrator "
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|