196 lines
10 KiB
PHP
196 lines
10 KiB
PHP
<?php include('container/security.php');?>
|
|
<!DOCTYPE html>
|
|
<html lang="en" data-theme="light">
|
|
<head>
|
|
<!-- head links start -->
|
|
<?php include 'container/head_links.php';?>
|
|
<!-- head links start -->
|
|
</head>
|
|
<body>
|
|
<!-- side_bar start -->
|
|
<?php include 'container/side_bar.php' ?>
|
|
<!-- side_bar end -->
|
|
<main class="dashboard-main">
|
|
<!-- Header start -->
|
|
<?php include 'container/header.php' ?>
|
|
<div class="dashboard-main-body">
|
|
<div class="d-flex flex-wrap align-items-center justify-content-between gap-3 mb-24">
|
|
<h6 class="fw-semibold mb-0">Manage AI Tool Cateogory</h6>
|
|
<ul class="d-flex align-items-center gap-2">
|
|
<li class="fw-medium">
|
|
<a href="index-2.html" class="d-flex align-items-center gap-1 hover-text-primary">
|
|
<iconify-icon icon="solar:home-smile-angle-outline" class="icon text-lg"></iconify-icon>
|
|
Dashboard
|
|
</a>
|
|
</li>
|
|
<li>-</li>
|
|
<li class="fw-medium">Manage Cateogory</li>
|
|
</ul>
|
|
</div>
|
|
<div class="row gy-4">
|
|
<div class="col-md-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="card-title mb-0">Add New Category</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<form action="" method="POST" enctype="multipart/form-data">
|
|
<div class="row gy-3">
|
|
<div class="col-4">
|
|
<label class="form-label">Category EN Name</label>
|
|
<input type="text" name="c_name" class="form-control" required placeholder="Enter Category EN Name">
|
|
</div>
|
|
<div class="col-4">
|
|
<label class="form-label">Category CN Name</label>
|
|
<input type="text" name="cn_name" class="form-control" required placeholder="Enter Category CN Name">
|
|
</div>
|
|
<div class="col-4">
|
|
<label class="form-label">Category Icon</label>
|
|
<input type="file" name="c_icon" class="form-control" required>
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="form-label">Description EN</label>
|
|
<textarea name="description" class="form-control" rows="5" placeholder="Write EN Description"></textarea>
|
|
</div>
|
|
<div class="col-12">
|
|
<label class="form-label">Description CN</label>
|
|
<textarea name="cn_description" class="form-control" rows="5" placeholder="Write CN Description"></textarea>
|
|
</div>
|
|
<div class="col-12">
|
|
<button type="submit" class="btn btn-primary mt-3">Add Category</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
$sql = "SELECT * FROM categories ORDER BY id DESC";
|
|
$result = mysqli_query($conn, $sql);
|
|
?>
|
|
|
|
<div class="dashboard-main-body">
|
|
<div class="card basic-data-table">
|
|
<div class="card-header">
|
|
<h5 class="card-title mb-0">List Of All Categories</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<table class="table bordered-table mb-0" id="dataTable" data-page-length='10'>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">#</th>
|
|
<th scope="col">Icon</th>
|
|
<th scope="col">Name</th>
|
|
<th scope="col">Description</th>
|
|
<th scope="col">Created Date</th>
|
|
<th scope="col">Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (mysqli_num_rows($result) > 0): ?>
|
|
<?php $i = 1; // Serial number ?>
|
|
<?php while($row = mysqli_fetch_assoc($result)): ?>
|
|
<tr>
|
|
<td>
|
|
<?php echo $i++; ?>
|
|
</td>
|
|
<td>
|
|
<img src="<?php echo htmlspecialchars($row['c_icon']); ?>" alt="Category Icon" class="flex-shrink-0 me-12 radius-8" width="50" height="50">
|
|
</td>
|
|
<td>
|
|
<h6 class="text-md mb-0 fw-medium flex-grow-1"><?php echo htmlspecialchars($row['c_name']); ?><br><?php echo htmlspecialchars($row['cn_name']); ?></h6>
|
|
</td>
|
|
<td><div class="row"><div class="col-6"><textarea class="form-control"><?php echo htmlspecialchars($row['description']); ?></textarea></div><div class="col-6"><textarea class="form-control"><?php echo htmlspecialchars($row['cn_description']); ?></textarea></div></div></td>
|
|
<td><?php echo date('d M Y', strtotime($row['created_at'])); ?></td>
|
|
<td>
|
|
<a href="category_edit?id=<?php echo $row['id']; ?>" class="w-32-px h-32-px bg-primary-light text-primary-600 rounded-circle d-inline-flex align-items-center justify-content-center">
|
|
<iconify-icon icon='lucide:edit'></iconify-icon>
|
|
</a>
|
|
<a href="category_delete?id=<?php echo $row['id']; ?>" class="w-32-px h-32-px bg-danger-focus text-danger-main rounded-circle d-inline-flex align-items-center justify-content-center" onclick="return confirm('Are you sure you want to delete this category?');">
|
|
<iconify-icon icon="mingcute:delete-2-line"></iconify-icon>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php endwhile; ?>
|
|
<?php else: ?>
|
|
<tr>
|
|
<td colspan="6" class="text-center">No categories found</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
?>
|
|
|
|
<?php include 'container/footer.php' ?>
|
|
</main>
|
|
<!-- Footer Links Start -->
|
|
<?php include 'container/footer_links.php' ?>
|
|
<script>
|
|
let table = new DataTable('#dataTable');
|
|
</script>
|
|
</body>
|
|
</html>
|
|
<?php
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
// Sanitize and validate inputs
|
|
$c_name = sanitize_input(mysqli_real_escape_string($conn, $_POST['c_name']));
|
|
$description = sanitize_input(mysqli_real_escape_string($conn, $_POST['description']));
|
|
$cn_name = sanitize_input(mysqli_real_escape_string($conn, $_POST['cn_name']));
|
|
$cn_description = sanitize_input(mysqli_real_escape_string($conn, $_POST['cn_description']));
|
|
|
|
// Handle file upload for the category icon
|
|
$target_dir = "assets/images/cat_icons/";
|
|
$icon_name = basename($_FILES["c_icon"]["name"]);
|
|
$icon_name = preg_replace('/\s+/', '_', $icon_name); // Replace spaces with underscores
|
|
$icon_name = uniqid() . '_' . $icon_name; // Add a unique ID to the icon name to prevent duplication
|
|
$c_icon = $target_dir . $icon_name;
|
|
$uploadOk = 1;
|
|
$imageFileType = strtolower(pathinfo($c_icon, PATHINFO_EXTENSION));
|
|
|
|
// Check if file is an actual image
|
|
$check = getimagesize($_FILES["c_icon"]["tmp_name"]);
|
|
if ($check !== false) {
|
|
$uploadOk = 1;
|
|
} else {
|
|
echo "<script>alert('File is not an image.');</script>";
|
|
$uploadOk = 0;
|
|
}
|
|
|
|
// Check file size (5MB max)
|
|
if ($_FILES["c_icon"]["size"] > 5000000) {
|
|
echo "<script>alert('Sorry, your file is too large.');</script>";
|
|
$uploadOk = 0;
|
|
}
|
|
|
|
// Allow certain file formats
|
|
if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
|
|
echo "<script>alert('Sorry, only JPG, JPEG, PNG & GIF files are allowed.');</script>";
|
|
$uploadOk = 0;
|
|
}
|
|
|
|
// Check if $uploadOk is set to 0 by an error
|
|
if ($uploadOk == 0) {
|
|
echo "<script>alert('Sorry, your file was not uploaded.');</script>";
|
|
} else {
|
|
if (move_uploaded_file($_FILES["c_icon"]["tmp_name"], $c_icon)) {
|
|
// Insert the data into the database
|
|
$sql = "INSERT INTO categories (c_name, cn_name, c_icon, description, cn_description) VALUES ('$c_name', '$cn_name', '$c_icon', '$description', '$cn_description')";
|
|
if (mysqli_query($conn, $sql)) {
|
|
echo "<script>alert('New category added successfully'); window.location.href = 'category_add';</script>"; // Redirect to dashboard after success
|
|
exit();
|
|
} else {
|
|
echo "<script>alert('Error: " . mysqli_error($conn) . "');</script>";
|
|
}
|
|
} else {
|
|
echo "<script>alert('Sorry, there was an error uploading your file.');</script>";
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|