first commit
This commit is contained in:
		
							
								
								
									
										198
									
								
								cms_admin/products-data-cms.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										198
									
								
								cms_admin/products-data-cms.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,198 @@ | ||||
| <?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 --> | ||||
|      <script src="https://cdn.ckeditor.com/4.22.1/standard/ckeditor.js"></script> | ||||
|    </head> | ||||
|    <body> | ||||
|       <!-- side_bar start --> | ||||
|       <?php include 'container/side_bar.php' ?> | ||||
| <?php | ||||
| $success="0"; | ||||
| if (isset($_POST['submit'])) { | ||||
|     // Collect form data | ||||
|     $small_heading_EN = mysqli_real_escape_string($conn, $_POST['small_heading_EN']); | ||||
|     $small_heading_CN = mysqli_real_escape_string($conn, $_POST['small_heading_CN']); | ||||
|     $large_heading_EN = mysqli_real_escape_string($conn, $_POST['Large_heading_EN']); | ||||
|     $large_heading_CN = mysqli_real_escape_string($conn, $_POST['Large_heading_CN']); | ||||
|     $long_description_EN = mysqli_real_escape_string($conn, $_POST['editor1_EN']); | ||||
|     $long_description_CN = mysqli_real_escape_string($conn, $_POST['editor1_CN']); | ||||
|     $added_by = $_POST['addedby'];  // Ensure user_id is properly escaped/validated | ||||
|     $status = 'active'; // You can modify this if you have a different logic for status | ||||
|      | ||||
|     // Check if there's already an entry in the database | ||||
|     $check_query = "SELECT id FROM products_cms WHERE added_by = '$added_by' LIMIT 1"; | ||||
|     $check_result = mysqli_query($conn, $check_query); | ||||
|      | ||||
|     if (mysqli_num_rows($check_result) > 0) { | ||||
|         // Update existing entry | ||||
|         $row = mysqli_fetch_assoc($check_result); | ||||
|         $id = $row['id']; | ||||
|          | ||||
|         $update_query = "UPDATE products_cms SET  | ||||
|             small_heading_EN = '$small_heading_EN', | ||||
|             small_heading_CN = '$small_heading_CN', | ||||
|             large_heading_EN = '$large_heading_EN', | ||||
|             large_heading_CN = '$large_heading_CN', | ||||
|             long_description_EN = '$long_description_EN', | ||||
|             long_description_CN = '$long_description_CN', | ||||
|             status = '$status', | ||||
|             updated_at = NOW() | ||||
|             WHERE id = '$id'"; | ||||
|              | ||||
|         if (mysqli_query($conn, $update_query)) { | ||||
|             $success= "Data updated successfully!"; | ||||
|         }  | ||||
|     } else { | ||||
|         // Insert new entry | ||||
|         $insert_query = "INSERT INTO products_cms ( | ||||
|             small_heading_EN, small_heading_CN, large_heading_EN, large_heading_CN,  | ||||
|             long_description_EN, long_description_CN, added_by, status, created_at, updated_at | ||||
|         ) VALUES ( | ||||
|             '$small_heading_EN', '$small_heading_CN', '$large_heading_EN', '$large_heading_CN', | ||||
|             '$long_description_EN', '$long_description_CN', '$added_by', '$status', NOW(), NOW() | ||||
|         )"; | ||||
|          | ||||
|         if (mysqli_query($conn, $insert_query)) { | ||||
|             $success= "Data inserted successfully!"; | ||||
|         } | ||||
|     } | ||||
|   $_POST = []; | ||||
| } | ||||
|  | ||||
|  | ||||
| ?> | ||||
|  | ||||
|  | ||||
|       <!-- 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 Products Page Data</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">Update Products Page Data</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">Update Products Page Welcome Section</h5> | ||||
|                     </div> | ||||
|                      <div class="card-body"> | ||||
|                          <?php if ($success != "0"): ?> | ||||
|                     <div class="alert alert-success" role="alert"> | ||||
|                         <?php echo $success ?> | ||||
|                     </div> | ||||
|                 <?php endif; ?> | ||||
|                    <?php | ||||
| // Fetch data from database if exists | ||||
| $added_by = $_SESSION['user_id'];  // Assuming you are using session to store the user ID | ||||
| $query = "SELECT * FROM products_cms LIMIT 1"; | ||||
| $result = mysqli_query($conn, $query); | ||||
| $data = mysqli_fetch_assoc($result); | ||||
|  | ||||
| // Check if data is available | ||||
| $small_heading_EN = isset($data['small_heading_EN']) ? $data['small_heading_EN'] : ''; | ||||
| $small_heading_CN = isset($data['small_heading_CN']) ? $data['small_heading_CN'] : ''; | ||||
| $large_heading_EN = isset($data['large_heading_EN']) ? $data['large_heading_EN'] : ''; | ||||
| $large_heading_CN = isset($data['large_heading_CN']) ? $data['large_heading_CN'] : ''; | ||||
| $long_description_EN = isset($data['long_description_EN']) ? $data['long_description_EN'] : ''; | ||||
| $long_description_CN = isset($data['long_description_CN']) ? $data['long_description_CN'] : ''; | ||||
| ?> | ||||
|  | ||||
|                          | ||||
|                         <!-- HTML form populated with PHP data --> | ||||
|                           <form action="" method="POST" enctype="multipart/form-data"> | ||||
|                             <div class="row gy-3"> | ||||
|                                 <div class="col-md-6 col-sm-12"> | ||||
|                                     <label class="form-label">Small Heading EN</label> | ||||
|                                     <input type="text" name="small_heading_EN" class="form-control" required value="<?php echo $small_heading_EN; ?>" placeholder="Enter Small Heading EN"> | ||||
|                                 </div> | ||||
|                                 <div class="col-md-6 col-sm-12"> | ||||
|                                     <label class="form-label">Small Heading CN</label> | ||||
|                                     <input type="text" name="small_heading_CN" class="form-control" required value="<?php echo $small_heading_CN; ?>" placeholder="Enter Small Heading CN"> | ||||
|                                 </div> | ||||
|                                 <div class="col-md-6 col-sm-12"> | ||||
|                                     <label class="form-label">Large Heading EN</label> | ||||
|                                     <input type="text" name="Large_heading_EN" class="form-control" required value="<?php echo $large_heading_EN; ?>" placeholder="Enter Large Heading EN"> | ||||
|                                 </div> | ||||
|                                 <div class="col-md-6 col-sm-12"> | ||||
|                                     <label class="form-label">Large Heading CN</label> | ||||
|                                     <input type="text" name="Large_heading_CN" class="form-control" required value="<?php echo $large_heading_CN; ?>" placeholder="Enter Large Heading CN"> | ||||
|                                 </div> | ||||
|                                 <div class="col-12"> | ||||
|                                     <label class="form-label">Long Description EN</label> | ||||
|                                     <textarea name="editor1_EN" id="editor1" required><?php echo $long_description_EN; ?></textarea> | ||||
|                                 </div> | ||||
|                                 <div class="col-12"> | ||||
|                                     <label class="form-label">Long Description CN</label> | ||||
|                                     <textarea name="editor1_CN" id="editor2" required><?php echo $long_description_CN; ?></textarea> | ||||
|                                 </div> | ||||
|                                 <input type="hidden" value="<?php echo $_SESSION['user_id']; ?>" name="addedby"> | ||||
|                                 <div class="col-12"> | ||||
|                                     <button type="submit" name="submit" class="btn btn-primary mt-3">Submit</button> | ||||
|                                 </div> | ||||
|                             </div> | ||||
|                         </form> | ||||
|  | ||||
|  | ||||
|                      </div> | ||||
|                   </div> | ||||
|                </div> | ||||
|             </div> | ||||
|              | ||||
|              | ||||
|              | ||||
|              | ||||
|              | ||||
|            | ||||
|          </div> | ||||
|  | ||||
|         | ||||
|  | ||||
|          <?php include 'container/footer.php' ?> | ||||
|       </main> | ||||
|       <!-- Footer Links Start --> | ||||
|       <?php include 'container/footer_links.php' ?>   | ||||
|      <script> | ||||
|         // Replace textarea with CKEditor | ||||
|         CKEDITOR.replace('editor1'); | ||||
|         CKEDITOR.replace('editor2');  CKEDITOR.replace('editor3'); | ||||
|         CKEDITOR.replace('editor4'); | ||||
|     </script> | ||||
|     <script> | ||||
|         // Function to perform the delayed click | ||||
|         function clickNotificationClose() { | ||||
|             setTimeout(function() { | ||||
|                 var closeButton = document.querySelector('.cke_notification_close'); | ||||
|                 if (closeButton) { | ||||
|                     closeButton.click(); | ||||
|                 } else { | ||||
|                     console.log('Close button not found.'); | ||||
|                 } | ||||
|             }, 100); // Delay in milliseconds (e.g., 2000ms = 2 seconds) | ||||
|         } | ||||
|  | ||||
|         // Call the function after the page has loaded | ||||
|         window.addEventListener('load', clickNotificationClose); | ||||
|     </script> | ||||
|    </body> | ||||
| </html> | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|    | ||||
		Reference in New Issue
	
	Block a user
	 root
					root