D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
u193541357
/
domains
/
racysanitaryware.com
/
public_html
/
1
/
dev
/
admin
/
Filename :
add-product.php
back
Copy
<?php include('header.php'); ?> <?php // Variables for storing product details $id = ''; $category_id = ''; $product_name = ''; $product_codeno1 = ''; $product_desc1 = ''; $product_codeno2 = ''; $product_desc2 = ''; $product_codeno3 = ''; $product_desc3 = ''; $product_description = ''; $product_image = ''; $product_drawing = ''; $product_extra_description = ''; // Check if updating an existing product if (isset($_GET['id'])) { $id = $_GET['id']; $sql = "SELECT * FROM products WHERE id = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param('i', $id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $category_id = $row['category_id']; $product_name = $row['product_name']; $product_codeno1 = $row['product_codeno1']; $product_desc1 = $row['product_desc1']; $product_codeno2 = $row['product_codeno2']; $product_desc2 = $row['product_desc2']; $product_codeno3 = $row['product_codeno3']; $product_desc3 = $row['product_desc3']; $product_description = $row['product_description']; $product_image = $row['product_image']; $product_drawing = $row['product_drawing']; $product_extra_description = $row['product_extra_description']; } } // Fetch categories for dropdown $categories = []; $cat_sql = "SELECT id, category_name FROM categories"; $cat_result = $conn->query($cat_sql); while ($cat_row = $cat_result->fetch_assoc()) { $categories[] = $cat_row; } // Fetch available icons for the multi-select dropdown $icons = []; $icon_sql = "SELECT id, icon_name FROM icons"; $icon_result = $conn->query($icon_sql); while ($icon_row = $icon_result->fetch_assoc()) { $icons[] = $icon_row; } // Convert stored product_icon_ids into an array $product_icon_ids = isset($row['product_icon_ids']) ? explode(',', $row['product_icon_ids']) : []; // Fetch available color for the multi-select dropdown $colors = []; $color_sql = "SELECT id, color_name FROM colors"; $color_result = $conn->query($color_sql); while ($color_row = $color_result->fetch_assoc()) { $color[] = $color_row; } // Convert stored product_icon_ids into an array $product_color_ids = isset($row['product_color_ids']) ? explode(',', $row['product_color_ids']) : []; ?> <div class="container-fluid"> <div class="d-sm-flex align-items-center justify-content-between mb-4"> <h1 class="h3 mb-0 text-gray-800"><?php echo isset($id) ? 'Update Product' : 'Add Product'; ?></h1> </div> <div class="card shadow mb-4"> <div class="card-body"> <form class="user" id="product-form" method="post" action="submit-product.php" enctype="multipart/form-data"> <input type="hidden" name="id" value="<?php echo $id; ?>"> <!-- Hidden ID for update --> <div class="form-group row"> <!-- Category Dropdown --> <div class="col-sm-4 mb-3"> <label for="category_id">Category</label> <select class="form-control form-select" name="category_id" required> <option value="">Select Category</option> <?php foreach ($categories as $cat) : ?> <option value="<?php echo $cat['id']; ?>" <?php echo $category_id == $cat['id'] ? 'selected' : ''; ?>> <?php echo $cat['category_name']; ?> </option> <?php endforeach; ?> </select> </div> <div class="col-sm-8 mb-3"> <label for="product_name">Product Name</label> <input type="text" class="form-control form-control-user" id="product_name" placeholder="Enter Product Name" name="product_name" value="<?php echo $product_name; ?>" required> </div> <!-- <div class="col-sm-4 mb-3"> <label for="product_slug">Product Slug</label> <input type="text" class="form-control form-control-user" id="product_slug" placeholder="Enter Product Slug" name="product_slug" value="<?php echo $product_slug; ?>" required> </div> --> <div class="col-sm-4 mb-3"> <label for="product_codeno1">Product Code 1</label> <input type="text" class="form-control form-control-user" id="product_codeno1" placeholder="Enter Product Code 1" name="product_codeno1" value="<?php echo $product_codeno1; ?>" required> </div> <div class="col-sm-4 mb-3"> <label for="product_desc1">Product Description 1</label> <input type="text" class="form-control form-control-user" id="product_desc1" placeholder="Enter Product Description 1" name="product_desc1" value="<?php echo $product_desc1; ?>" required> </div> <div class="col-sm-4 mb-3"> <label for="product_codeno2">Product Code 2</label> <input type="text" class="form-control form-control-user" id="product_codeno2" placeholder="Enter Product Code 2" name="product_codeno2" value="<?php echo $product_codeno2; ?>"> </div> <div class="col-sm-4 mb-3"> <label for="product_desc2">Product Description 2</label> <input type="text" class="form-control form-control-user" id="product_desc2" placeholder="Enter Product Description 2" name="product_desc2" value="<?php echo $product_desc2; ?>"> </div> <div class="col-sm-4 mb-3"> <label for="product_codeno3">Product Code 3</label> <input type="text" class="form-control form-control-user" id="product_codeno3" placeholder="Enter Product Code 3" name="product_codeno3" value="<?php echo $product_codeno3; ?>"> </div> <div class="col-sm-4 mb-3"> <label for="product_desc3">Product Description 3</label> <input type="text" class="form-control form-control-user" id="product_desc3" placeholder="Enter Product Description 3" name="product_desc3" value="<?php echo $product_desc3; ?>"> </div> <div class="col-sm-12 mb-3"> <label for="product_description">Main Product Description</label> <textarea cols="10" rows="5" class="form-control form-control-textarea" id="product_description" name="product_description"><?php echo $product_description; ?></textarea> </div> <div class="col-sm-6 mb-3"> <label for="product_image">Product Image</label> <input type="file" class="form-control form-control-user form-control-file" id="product_image" name="product_image" accept="image/*" onchange="previewImage(event, 'productImagePreview')"> <div class="position-relative mt-2 preview" id="productImagePreview"> <?php if (!empty($product_image)) : ?> <img src="<?php echo $product_image; ?>" alt="Product Image" style="max-width: 120px; margin-top:10px;"> <?php else : ?> <img src="" alt="" style="max-width: 120px; margin-top:10px; display: none;"> <?php endif; ?> </div> </div> <div class="col-sm-6 mb-3"> <label for="product_drawing">Product Drawing</label> <input type="file" class="form-control form-control-user form-control-file" id="product_drawing" name="product_drawing" accept="image/*" onchange="previewImage(event, 'productDrawingPreview')"> <div class="position-relative mt-2 preview" id="productDrawingPreview"> <?php if (!empty($product_drawing)) : ?> <img src="<?php echo $product_drawing; ?>" alt="Product Drawing" style="max-width: 120px; margin-top:10px;"> <?php else : ?> <img src="" alt="" style="max-width: 120px; margin-top:10px; display: none;"> <?php endif; ?> </div> </div> <div class="col-sm-12 mb-3"> <label for="product_extra_description">Extra Description</label> <textarea cols="10" rows="5" class="form-control form-control-textarea" id="product_extra_description" name="product_extra_description"><?php echo $product_extra_description; ?></textarea> </div> <!-- Multi-select Dropdown for Icons --> <div class="col-sm-12 mb-3"> <label for="product_icons">Associated Icons</label> <select class="form-control" id="product_icons" name="product_icons[]" multiple style="height:600px;"> <?php foreach ($icons as $icon) : ?> <option value="<?php echo $icon['id']; ?>" <?php echo in_array($icon['id'], $product_icon_ids) ? 'selected' : ''; ?>> <?php echo $icon['icon_name']; ?> </option> <?php endforeach; ?> </select> <small class="form-text text-muted">Hold Ctrl (Cmd on Mac) to select multiple icons.</small> </div> <!-- Multi-select Dropdown for Icons --> <div class="col-sm-12 mb-3"> <label for="product_colors">Associated Product Colors</label> <select class="form-control" id="product_colors" name="product_colors[]" multiple style="height:600px;"> <?php foreach ($color as $colors) : ?> <option value="<?php echo $colors['id']; ?>" <?php echo in_array($colors['id'], $product_color_ids) ? 'selected' : ''; ?>> <?php echo $colors['color_name']; ?> </option> <?php endforeach; ?> </select> <small class="form-text text-muted">Hold Ctrl (Cmd on Mac) to select multiple icons.</small> </div> </div> <button type="submit" class="btn btn-primary btn-user btn-block"> <?php echo (!isset($id) || empty($id)) ? 'Add Product' : 'Update Product'; ?> </button> </form> </div> </div> </div> <!-- Script for image preview --> <script> // Image Preview Functionality function previewImage(event, previewId) { const reader = new FileReader(); reader.onload = function() { const previewImg = document.getElementById(previewId).querySelector('img'); previewImg.src = reader.result; previewImg.style.display = 'block'; // Make the preview image visible }; if (event.target.files && event.target.files[0]) { reader.readAsDataURL(event.target.files[0]); } } </script> <?php include('footer.php'); ?>