227 lines
10 KiB
PHP
227 lines
10 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 = "sub_category";
|
|
|
|
if (isset($_POST['addSubCategory'])) {
|
|
|
|
$name = sanitizeData($_POST['sub_category_name']);
|
|
$category = (int)$_POST['category_id'];
|
|
$status = (int)$_POST['status'];
|
|
|
|
if (isset($connection)) {
|
|
$insertCategory = $connection->query("INSERT INTO `sub_category` (`category_id`,`name`, `status`) VALUES ($category, '$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>Sub 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">Sub Category Page</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 Sub Category</div>
|
|
<form name="addSubCategoryForm" id="addSubCategoryForm" method="post" action="">
|
|
<div class="row">
|
|
<div class="mb-3 show_error">
|
|
<label for="sub_category_name">Sub Category Name</label>
|
|
<input type="text" class="form-control" name="sub_category_name" id="sub_category_name"
|
|
placeholder="Enter Category Name">
|
|
</div>
|
|
<div class="mb-3 show_error">
|
|
<label for="category_id">Category </label>
|
|
<select class="form-select" id="category_id" name="category_id">
|
|
<option selected="selected" value="">Select Category</option>
|
|
<?PHP
|
|
|
|
if (!empty($connection)) {
|
|
$allCategories = $connection->query("SELECT * FROM `category` WHERE `status` = 1 ORDER BY `name` ");
|
|
if ($allCategories) {
|
|
while ($category = $allCategories->fetch_object()) { ?>
|
|
<option value="<?PHP echo $category->id; ?>"><?PHP echo $category->name; ?></option>
|
|
<?PHP }
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
<div class="mb-3 show_error">
|
|
<label for="status">Sub 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="addSubCategory">
|
|
Save Sub 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">Sub Category List</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-bordered" id="basic-1">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Sub Category</th>
|
|
<th>Category</th>
|
|
<th>Status</th>
|
|
<th>Created At</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?PHP
|
|
if (isset($connection)) {
|
|
$getCategories = $connection->query("SELECT `sub_category`.*, `category`.`name` AS `category_name`
|
|
FROM `sub_category`
|
|
INNER JOIN `category`
|
|
ON `sub_category`.`category_id`= `category`.`id`
|
|
ORDER BY `sub_category`.`id`;");
|
|
if ($getCategories) {
|
|
while ($category = $getCategories->fetch_object()) { ?>
|
|
<tr>
|
|
<td><?PHP echo $category->id ?></td>
|
|
<td><?PHP echo $category->name ?></td>
|
|
<td><?PHP echo $category->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 Sub 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: {
|
|
sub_category__change__status: 'sub_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>
|