%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64 User : ndkhermy ( 1200) PHP Version : 8.5.12 Disable Function : NONE Directory : /home1/ndkhermy/www/website_93b53270/admin/manage_product/ |
Upload File : |
<?php
error_reporting(0);
include("../function.php");
if($_SESSION['admin_id']==""){
header('location:../login.php');
}
$login_tbl=mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM admin WHERE admin_id='".$_SESSION['admin_id']."'"));
// Sidebar strat
include('../include/sidebar.php');
$id = $_GET['id'];
?>
<?php
if(isset($_POST['update']) && $_POST['update']=='Update'){
$cat_id=$_POST['cat_id'];
$brand_ids = isset($_POST['brand_atb']) ? implode(",", $_POST['brand_atb']) : "";
$variant_ids = isset($_POST['variant_atb']) ? implode(",", $_POST['variant_atb']) : "";
// $model_ids = isset($_POST['model_atb']) ? implode(",", $_POST['model_atb']) : "";
$model_year_ids = isset($_POST['model_year_atb']) ? implode(",", $_POST['model_year_atb']) : "";
$title=$_POST['title'];
$title=str_replace("'", "\'", $title);
$short_description=$_POST['short_description'];
$short_description=str_replace("'", "\'", $short_description);
$about=$_POST['about'];
$about=str_replace("'", "\'", $about);
$price=$_POST['price'];
$status=$_POST['status'];
$slug = create_url($title).$id;
$file_name=$_FILES['image1']['name'];
$file_tmp=$_FILES['image1']['tmp_name'];
$file_ext=strtolower(end(explode('.',$_FILES['image1']['name'])));
$CheckQ=mysqli_query($conn,"UPDATE `product_tbl` SET
`cat_id`='$cat_id',
`brand_id`='$brand_ids',
`variant_id`='$variant_ids',
-- `model_id`='$model_ids',
`model_year_id`='$model_year_ids',
`title`='$title',
`short_description`='$short_description',
`about`='$about',
`price`='$price',
`status`='$status',
`slug`='$slug' WHERE id='$id'");
if(!empty($file_name)){
$random_number= rand();
$new_file_name=$random_number.'.'.$file_ext;
$file_path="../../images/Upload/product/".$new_file_name;
$fet_dlt=mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM `product_tbl` WHERE id='$id'"));
unlink("../../images/Upload/product/".$fet_dlt['image1']);
move_uploaded_file($file_tmp,$file_path);
$addQry=mysqli_query($conn,"UPDATE `product_tbl` SET `image1`='$new_file_name' WHERE id='$id'")or die(mysqli_error($conn));
}
echo "<script>window.location='show.php?page=pro';</script>";
$_SESSION['message']="Product Added Successfully";
}
?>
<!-- [ Main Content ] start -->
<section class="pcoded-main-container">
<div class="pcoded-content">
<!-- [ breadcrumb ] start -->
<div class="page-header">
<div class="page-block">
<div class="row align-items-center">
<div class="col-md-12">
<div class="page-header-title">
<div class="card-header d-flex justify-content-between">
<button class="btn btn-dark text-light fw-bold btn-sm btn-round has-ripple"><i class="feather icon-edit"></i> Add Product List</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- [ breadcrumb ] end -->
<!-- [ Main Content ] start -->
<div class="row">
<div class="col-md-12">
<div class="card">
<!-- <div class="card-header d-flex justify-content-between">
</div> -->
<div class="card-body">
<?php if(isset($_SESSION['error'])){
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">
<i class="feather icon-alert-triangle text-danger"></i> <strong class="text-dark">'.$_SESSION['error'].'</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
</button>
</div>';
}
unset($_SESSION['error']);
?>
<?php $fetch_pro=mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM `product_tbl` WHERE id='$id'")); ?>
<form method="POST" enctype="multipart/form-data" autocomplete="off" >
<div class="container">
<div class="row">
<style type="text/css">
.multiselect {
/* width: 256px;*/
margin-top: 5px;
margin-left: 9px;
margin-bottom: 18px;
}
.selectBox {
position: relative;
}
.selectBox select {
width: 100%;
padding: 10px;
/*font-weight: bold;*/
}
.overSelect {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
}
#checkboxes {
display: none;
border: 1px #dadada solid;
max-height: 150px; /* Set maximum height for the checkboxes */
overflow-y: auto;
}
#checkboxes label {
display: block;
}
#checkboxes label:hover {
background-color: #f2cbd9;
}
#brand_checkboxes {
display: none;
border: 1px #dadada solid;
max-height: 150px; /* Set maximum height for the checkboxes */
overflow-y: auto;
}
#brand_checkboxes label {
display: block;
}
#brand_checkboxes label:hover {
background-color: #f2cbd9;
}
#brand_search {
width: 100%;
box-sizing: border-box;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
}
#variant_checkboxes {
display: none;
border: 1px #dadada solid;
max-height: 150px; /* Set maximum height for the checkboxes */
overflow-y: auto;
}
#variant_checkboxes label {
display: block;
}
#variant_checkboxes label:hover {
background-color: #f2cbd9;
}
#variant_search {
width: 100%;
box-sizing: border-box;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
}
#model_checkboxes {
display: none;
border: 1px #dadada solid;
max-height: 150px; /* Set maximum height for the checkboxes */
overflow-y: auto;
}
#model_checkboxes label {
display: block;
}
#model_checkboxes label:hover {
background-color: #f2cbd9;
}
#model_search {
width: 100%;
box-sizing: border-box;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
}
#model_year_checkboxes {
display: none;
border: 1px #dadada solid;
max-height: 150px; /* Set maximum height for the checkboxes */
overflow-y: auto;
}
#model_year_checkboxes label {
display: block;
}
#model_year_checkboxes label:hover {
background-color: #f2cbd9;
}
#model_year_search {
width: 100%;
box-sizing: border-box;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
}
</style>
<!-- Brand start --->
<div class="col-md-4">
<div class="multiselect">
<label class="form-label" for="Brand_status">Brand</label>
<div class="selectBox" onclick="showbrandCheckboxes()">
<select id="brand_select">
<option>Select Brand</option>
</select>
<div class="overSelect"></div>
</div>
<div id="brand_checkboxes" style="display: none;">
<input type="text" id="brand_search" onkeyup="filterBrand()" placeholder="Search brand ...">
<!-- Select All Checkbox -->
<label for="brand_select_all" style="font-size: 15px; padding: 10px;">
<input type="checkbox" id="brand_select_all" class="mx-2" onchange="toggleSelectAllBrands(this)">Select All
</label>
<?php
$brandQuery = mysqli_query($conn, "SELECT * FROM brand_tbl WHERE status=1");
while ($row = mysqli_fetch_array($brandQuery)) {
$brand_ids = explode(',', $fetch_pro['brand_id']);
$checked = in_array($row['id'], $brand_ids) ? "checked" : "";
?>
<label for="brand<?= $row['id'] ?>" style="font-size: 15px; padding: 10px;">
<input type="checkbox" id="brand<?= $row['id'] ?>" value="<?= $row['id'] ?>" data-brand_id="<?= $row['id'] ?>" class="mx-2 brand_item" name="brand_atb[]" onchange="updatebrandSelectBox();" <?= $checked ?> /><?= $row['name'] ?>
</label>
<?php } ?>
</div>
</div>
</div>
<!-- Variant start --->
<div class="col-md-4" id="variantshow">
<div class="multiselect">
<label class="form-label" for="model_status">Variant</label>
<div class="selectBox" onclick="showvariantCheckboxes()">
<select id="variant_select">
<option>Select Variant</option>
</select>
<div class="overSelect"></div>
</div>
<?php
if (!empty($fetch_pro['brand_id'])) {
// Sanitize brand IDs
$brd_id_array = array_filter(array_map('intval', explode(',', $fetch_pro['brand_id'])));
if (!empty($brd_id_array)) {
$brd_id_str = implode(',', $brd_id_array);
$variantQuery = mysqli_query($conn, "SELECT * FROM variant_tbl WHERE status=1 AND brand_id IN ($brd_id_str)");
?>
<div id="variant_checkboxes" style="display: none;">
<input type="text" id="variant_search" onkeyup="filterVariant()" placeholder="Search variant ...">
<!-- Select All Checkbox -->
<label for="variant_select_all" style="font-size: 15px; padding: 10px;">
<input type="checkbox" id="variant_select_all" class="mx-2" onchange="toggleSelectAllVariants(this)">Select All
</label>
<?php
$variant_ids = !empty($fetch_pro['variant_id']) ? explode(',', $fetch_pro['variant_id']) : [];
while ($row = mysqli_fetch_array($variantQuery)) {
$checked = in_array($row['id'], $variant_ids) ? "checked" : "";
?>
<label for="variant<?= $row['id'] ?>" style="font-size: 15px; padding: 10px;">
<input type="checkbox" id="variant<?= $row['id'] ?>"
value="<?= $row['id'] ?>"
class="mx-2 variant_item"
name="variant_atb[]"
onchange="updatevariantSelectBox();"
<?= $checked ?> /> <?= htmlspecialchars($row['title']) ?>
</label>
<?php } ?>
</div>
<?php
} // end if brand ids exist
} // end if brand_id not empty
?>
</div>
</div>
<!-- Variant ends --->
<!-- Model Year start --->
<div class="col-md-4">
<div class="multiselect">
<label class="form-label" for="model_year_status">Model Year</label>
<div class="selectBox" onclick="showmodel_yearCheckboxes()">
<select id="model_year_select">
<option>Select Model Year</option>
</select>
<div class="overSelect"></div>
</div>
<div id="model_year_checkboxes" style="display: none;">
<input type="text" id="model_year_search" onkeyup="filterModelYears()" placeholder="Search model years...">
<!-- Select All -->
<label for="model_year_select_all" style="font-size: 15px; padding: 10px;">
<input type="checkbox" id="model_year_select_all" class="mx-2" onchange="toggleSelectAllModelYears(this)">Select All
</label>
<?php
$model_yearQuery = mysqli_query($conn, "SELECT * FROM model_date_tbl WHERE status=1");
while ($row = mysqli_fetch_array($model_yearQuery)) {
$model_year_ids = explode(',', $fetch_pro['model_year_id']);
$checked = in_array($row['id'], $model_year_ids) ? "checked" : "";
?>
<label for="model_year<?= $row['id'] ?>" style="font-size: 15px; padding: 10px;">
<input type="checkbox" id="model_year<?= $row['id'] ?>" value="<?= $row['id'] ?>" class="mx-2 model_year_item" name="model_year_atb[]" onchange="updatemodel_yearSelectBox();" <?= $checked ?> /><?= $row['title'] ?>
</label>
<?php } ?>
</div>
</div>
</div>
<!-- Model Year ends --->
<div class="col-md-4">
<div class="form-group">
<label class="form-label" for="Service">Product Category</label>
<select class="form-select" name="cat_id" required>
<option value="">Please select Category</option>
<?php
$serQry=mysqli_query($conn,"SELECT * FROM `product_product_sevice_tbl` WHERE status=1 ORDER BY id ASC");
while($row=mysqli_fetch_array($serQry)){
?>
<option value="<?=$row['id']?>" <?=($fetch_pro['cat_id']==$row['id'])?'selected':''?>><?=$row['title']?></option>
<?php } ;?>
</select>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="form-label" for="title">Product Name</label>
<input type="text" name="title" class="form-control" value="<?=$fetch_pro['title']?>" required>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="form-label" for="price">Price AED</label>
<input type="text" name="price" oninput="FillNumber(this)" class="form-control" value="<?=$fetch_pro['price']?>" required >
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="form-label" for="short_description">Short Description</label>
<textarea class="form-control" id="editor1" name="short_description"><?=$fetch_pro['short_description']?></textarea>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="form-label " for="about">Description</label>
<textarea class="form-control" id="editor2" rows="4" name="about"><?=$fetch_pro['about']?></textarea>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label">Image</label>
<input type="file" name="image1" class="form-control">
</div>
<?php
if(!empty($id)){
echo '<img src="'.$base_url.'images/Upload/product/'.$fetch_pro['image1'].'" class="pb-2 mx-3" style="width:100px; height:80px;"><br>';
}
?>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="form-label" for="status">Status</label>
<select class="form-select" name="status" id="status">
<option value="">Please select status</option>
<option value="1" <?=($fetch_pro['status']==1)?'selected':''?>>Show</option>
<option value="0" <?=($fetch_pro['status']==0)?'selected':''?>>Hide</option>
</select>
</div>
</div>
<div class="col-md-12 mt-2">
<div class="form-group">
<input type="submit" name="update" class="btn btn-success" value="Update">
<a class="text-white btn btn-dark " href="show.php?page=pro">Back</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<!-- [ form-element ] end -->
</div>
<!-- [ Main Content ] end -->
</div>
</section>
<!-- Required Js -->
<?php include('../include/footer.php'); ?>
<!-- /////////// Sub Category ///////// -->
<script>
$(document).ready(function() {
$('#cat').on('change', function() {
var cat = this.value;
$.ajax({
url: "sub-category.php",
type: "POST",
data: {
cat: cat
},
cache: false,
success: function(result){
$("#sub").html(result);
}
});
});
});
</script>
<!-- ///////// Image ///////////// -->
<script>
$(document).ready(function() {
$("#myButton").click(function() {
$.ajax({
url: "generate_input.php",
success: function(html) {
$("#input-container").append(html);
}
});
});
});
$(document).on("click", ".remove-input", function() {
$(this).closest(".input-element").remove();
});
</script>
<!-- /////////Image And Size ///////////// -->
<script>
$(document).ready(function() {
$("#myButton1").click(function() {
$.ajax({
url: "generate_input1.php",
success: function(html) {
$("#input-container1").append(html);
}
});
});
});
$(document).on("click", ".remove-input1", function() {
$(this).closest(".input-element1").remove();
});
</script>
<!-- //////////// FAQ /////////// -->
<script>
$(document).ready(function() {
$("#myButton2").click(function() {
$.ajax({
url: "generate_input2.php",
success: function(html) {
$("#input-container2").append(html);
}
});
});
});
$(document).on("click", ".remove-input2", function() {
$(this).closest(".input-element2").remove();
});
</script>
<script>
function updatebrandSelectBox() {
var checkboxes = document.querySelectorAll('input[name="brand_atb[]"]:checked');
var selectBox = document.getElementById("brand_select");
if (checkboxes.length > 0) {
selectBox.options[0].text = checkboxes.length + " selected";
} else {
selectBox.options[0].text = "Select Brand";
}
// Update "Select All" checkbox state dynamically
var allCheckboxes = document.querySelectorAll('input[name="brand_atb[]"]');
var selectAll = document.getElementById("brand_select_all");
selectAll.checked = (checkboxes.length === allCheckboxes.length);
}
document.addEventListener("DOMContentLoaded", function() {
updatebrandSelectBox();
});
var brand_expanded = false;
function showbrandCheckboxes() {
var checkboxes = document.getElementById("brand_checkboxes");
checkboxes.style.display = brand_expanded ? "none" : "block";
brand_expanded = !brand_expanded;
}
function filterBrand() {
var input = document.getElementById("brand_search");
var filter = input.value.toLowerCase();
var labels = document.getElementById("brand_checkboxes").getElementsByTagName("label");
for (var i = 0; i < labels.length; i++) {
var text = labels[i].textContent || labels[i].innerText;
labels[i].style.display = text.toLowerCase().indexOf(filter) > -1 ? "" : "none";
}
}
// ✅ FIXED FUNCTION — handles Select All toggle
function toggleSelectAllBrands(selectAllCheckbox) {
var checkboxes = document.querySelectorAll('input[name="brand_atb[]"]');
checkboxes.forEach(function(checkbox) {
checkbox.checked = selectAllCheckbox.checked;
});
updatebrandSelectBox();
// 🔥 Trigger change event so AJAX runs too
$(".brand_item").trigger("change");
}
</script>
<script>
$(document).ready(function() {
// Trigger on change (not "checked")
$(document).on("change", ".brand_item", function() {
// Collect all selected brand IDs
var selectedBrands = [];
$('input[name="brand_atb[]"]:checked').each(function() {
selectedBrands.push($(this).val());
});
// Send to server via AJAX
$.ajax({
url: "variant-ajax.php",
type: "POST",
data: { brand_ids: selectedBrands },
success: function(response) {
// Replace content instead of appending
$("#variantshow").html(response || "<p>No brand selected.</p>");
},
error: function(xhr, status, error) {
console.error("AJAX Error:", error);
}
});
});
});
</script>
<script>
function updatevariantSelectBox() {
var checkboxes = document.querySelectorAll('input[name="variant_atb[]"]:checked');
var selectBox = document.getElementById("variant_select");
if (checkboxes.length > 0) {
selectBox.options[0].text = checkboxes.length + " selected";
} else {
selectBox.options[0].text = "Select Variant";
}
// Keep the "Select All" checkbox synced
var allCheckboxes = document.querySelectorAll('input[name="variant_atb[]"]');
var selectAll = document.getElementById("variant_select_all");
selectAll.checked = (checkboxes.length === allCheckboxes.length);
}
// Run once when the page loads
document.addEventListener("DOMContentLoaded", function() {
updatevariantSelectBox();
});
var variant_expanded = false;
function showvariantCheckboxes() {
var checkboxes = document.getElementById("variant_checkboxes");
if (!variant_expanded) {
checkboxes.style.display = "block";
variant_expanded = true;
} else {
checkboxes.style.display = "none";
variant_expanded = false;
}
}
function filterVariant() {
var input = document.getElementById("variant_search");
var filter = input.value.toLowerCase();
var checkboxes = document.getElementById("variant_checkboxes");
var labels = checkboxes.getElementsByTagName("label");
for (var i = 0; i < labels.length; i++) {
var label = labels[i];
var text = label.textContent || label.innerText;
if (text.toLowerCase().indexOf(filter) > -1) {
label.style.display = "";
} else {
label.style.display = "none";
}
}
}
// ✅ Added: Working "Select All" function
function toggleSelectAllVariants(selectAllCheckbox) {
var checkboxes = document.querySelectorAll('input[name="variant_atb[]"]');
checkboxes.forEach(function(checkbox) {
checkbox.checked = selectAllCheckbox.checked;
});
updatevariantSelectBox();
}
</script>
<script>
function updatemodel_yearSelectBox() {
var checkedBoxes = document.querySelectorAll('input[name="model_year_atb[]"]:checked');
var selectBox = document.getElementById("model_year_select");
if (checkedBoxes.length > 0) {
selectBox.options[0].text = checkedBoxes.length + " selected";
} else {
selectBox.options[0].text = "Select Model Year";
}
// ✅ Keep "Select All" checkbox in sync
var allBoxes = document.querySelectorAll('input[name="model_year_atb[]"]');
var selectAll = document.getElementById("model_year_select_all");
selectAll.checked = (checkedBoxes.length === allBoxes.length);
}
// Initial setup after page load
document.addEventListener("DOMContentLoaded", function() {
updatemodel_yearSelectBox();
});
var model_year_expanded = false;
function showmodel_yearCheckboxes() {
var checkboxes = document.getElementById("model_year_checkboxes");
if (!model_year_expanded) {
checkboxes.style.display = "block";
model_year_expanded = true;
} else {
checkboxes.style.display = "none";
model_year_expanded = false;
}
}
function filterModelYears() {
var input = document.getElementById("model_year_search");
var filter = input.value.toLowerCase();
var checkboxes = document.getElementById("model_year_checkboxes");
var labels = checkboxes.getElementsByTagName("label");
for (var i = 0; i < labels.length; i++) {
var label = labels[i];
var text = label.textContent || label.innerText;
label.style.display = text.toLowerCase().indexOf(filter) > -1 ? "" : "none";
}
}
// ✅ FIXED: Working "Select All" function
function toggleSelectAllModelYears(selectAllCheckbox) {
var checkboxes = document.querySelectorAll('input[name="model_year_atb[]"]');
checkboxes.forEach(function(checkbox) {
checkbox.checked = selectAllCheckbox.checked;
});
updatemodel_yearSelectBox();
}
</script>