318 lines
15 KiB
PHP
318 lines
15 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 = "services";
|
|
|
|
if (isset($_POST['addNewService'])) {
|
|
|
|
$file_target_dir = "../uploads/";
|
|
|
|
if (!is_dir($file_target_dir)) {
|
|
mkdir($file_target_dir, 0777, true);
|
|
}
|
|
|
|
$arr = explode("|", $_POST['sub_category_id']);
|
|
$category_id = (int) $arr[0];
|
|
$sub_category_id = (int) $arr[1];
|
|
|
|
$title = sanitizeData($_POST['title']);
|
|
$content = sanitizeData($_POST['content']);
|
|
$title2 = sanitizeData($_POST['title2']);
|
|
$content2 = sanitizeData($_POST['content2']);
|
|
$status = (int)$_POST['status'];
|
|
|
|
$image1 = $_FILES['image1']['name'];
|
|
$image1_tmp = $_FILES['image1']['tmp_name'];
|
|
$image1_ext = pathinfo($image1, PATHINFO_EXTENSION);
|
|
$image1_name = round(microtime(true) * 1000) . '_1.' . $image1_ext;
|
|
$image1_target_file = $file_target_dir . $image1_name;
|
|
|
|
$image2 = $_FILES['image2']['name'];
|
|
$image2_tmp = $_FILES['image2']['tmp_name'];
|
|
$image2_ext = pathinfo($image2, PATHINFO_EXTENSION);
|
|
$image2_name = round(microtime(true) * 1000) . '_2.' . $image2_ext;
|
|
$image2_target_file = $file_target_dir . $image2_name;
|
|
|
|
$image3 = $_FILES['image3']['name'];
|
|
$image3_tmp = $_FILES['image3']['tmp_name'];
|
|
$image3_ext = pathinfo($image3, PATHINFO_EXTENSION);
|
|
$image3_name = round(microtime(true) * 1000) . '_3.' . $image3_ext;
|
|
$image3_target_file = $file_target_dir . $image3_name;
|
|
|
|
if (isset($connection)) {
|
|
|
|
$sql = "INSERT INTO `page`
|
|
(`category_id`,`sub_category_id`,`title`, `content`, `title2`, `content2`, `image1`, `image2`, `image3`, `status`)
|
|
VALUES ($category_id, $sub_category_id, '$title', '$content', '$title2', '$content2', '$image1_name', '$image2_name', '$image3_name', $status )";
|
|
|
|
$insertPageContent = $connection->query($sql);
|
|
|
|
if ($insertPageContent) {
|
|
|
|
|
|
if (move_uploaded_file($image1_tmp, $image1_target_file) && move_uploaded_file($image2_tmp, $image2_target_file) && move_uploaded_file($image3_tmp, $image3_target_file)) {
|
|
chmod($image1_target_file, 0777);
|
|
chmod($image2_target_file, 0777);
|
|
chmod($image3_target_file, 0777);
|
|
|
|
showSweetAlert('success', 'Data Saved');
|
|
} else {
|
|
|
|
@unlink($image1_target_file);
|
|
@unlink($image2_target_file);
|
|
@unlink($image3_target_file);
|
|
|
|
$deleteLastRecord = $connection->query("DELETE FROM `page` WHERE `id` = $connection->insert_id");
|
|
|
|
showSweetAlert('error', 'Unable to upload images');
|
|
|
|
}
|
|
|
|
} else {
|
|
echo $sql;
|
|
//showSweetAlert('error', sanitizeData($sql));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
<!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>Services Manager</h3>
|
|
</div>
|
|
<div class="col-6">
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item"><a href="index.php"> <i data-feather="home"></i></a></li>
|
|
<li class="breadcrumb-item">Home</li>
|
|
<li class="breadcrumb-item active">Services Manager</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 Service</div>
|
|
<form name="addNewServiceForm" id="addNewServiceForm" method="post" action="" enctype="multipart/form-data">
|
|
<div class="row">
|
|
|
|
<div class="mb-3 show_error">
|
|
<label for="category_id">Category </label>
|
|
<select class="form-select" id="sub_category_id" name="sub_category_id">
|
|
<option selected="selected" value="">Select Category and Sub Category
|
|
</option>
|
|
<?PHP
|
|
|
|
if (!empty($connection)) {
|
|
$allCategories = $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 `category`.`name`;");
|
|
if ($allCategories) {
|
|
while ($category = $allCategories->fetch_object()) { ?>
|
|
<option value="<?PHP echo $category->category_id . '|' . $category->id; ?>"><?PHP echo $category->category_name . ' -> ' . $category->name; ?></option>
|
|
<?PHP }
|
|
}
|
|
}
|
|
?>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="mb-3 show_error">
|
|
<label for="title">Title</label>
|
|
<input type="text" class="form-control" name="title" id="title"
|
|
placeholder="Enter 1st Title">
|
|
</div>
|
|
<div class="mb-3 show_error">
|
|
<label for="content">Content</label>
|
|
<textarea type="text" class="form-control" name="content" id="content"
|
|
placeholder="Enter 1st Content" cols="3"></textarea>
|
|
</div>
|
|
|
|
<div class="mb-3 show_error">
|
|
<label for="title2">Title2</label>
|
|
<input type="text" class="form-control" name="title2" id="title2"
|
|
placeholder="Enter 2nd Title">
|
|
</div>
|
|
<div class="mb-3 show_error">
|
|
<label for="content2">Content2</label>
|
|
<textarea type="text" class="form-control" name="content2" id="content2"
|
|
placeholder="Enter 2nd Content" cols="3"></textarea>
|
|
</div>
|
|
|
|
<div class="mb-3 show_error">
|
|
<label for="image1">Image1</label>
|
|
<input type="file" class="form-control" name="image1" id="image1"
|
|
placeholder="Choose 1st Image">
|
|
</div>
|
|
|
|
<div class="mb-3 show_error">
|
|
<label for="image2">Image2</label>
|
|
<input type="file" class="form-control" name="image2" id="image2"
|
|
placeholder="Choose 2nd Image">
|
|
</div>
|
|
|
|
<div class="mb-3 show_error">
|
|
<label for="image1">Image3</label>
|
|
<input type="file" class="form-control" name="image3" id="image3"
|
|
placeholder="Choose 3rd Image">
|
|
</div>
|
|
|
|
<div class="mb-3 show_error">
|
|
<label for="status">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="addNewService">
|
|
Save Service
|
|
</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">Added Services List</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-bordered" id="basic-1">
|
|
<thead>
|
|
<tr>
|
|
<th>Service Name</th>
|
|
<th>Created At</th>
|
|
<th >Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?PHP
|
|
if (isset($connection)) {
|
|
$getCategories = $connection->query("SELECT `page`.*, `sub_category`.`name` AS `sub_category_name`,`sub_category`.`category_id` as `category_id`
|
|
FROM `page`
|
|
INNER JOIN `sub_category`
|
|
ON `page`.`sub_category_id`= `sub_category`.`id`");
|
|
if ($getCategories) {
|
|
while ($category = $getCategories->fetch_object()) { ?>
|
|
<tr>
|
|
|
|
<td><?PHP echo $category->sub_category_name ?></td>
|
|
<td><?PHP echo $category->created_at ?></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>
|
|
|
|
</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 Service 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: {
|
|
services__change__status: 'services__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>
|