📁 File Manager
Editing:
/home/wedigitalindia/public_html/mvskpowdercoating.com/admin/service-edit.php
<?php /* |-------------------------------------------------------------------------- | BASIC SETUP |-------------------------------------------------------------------------- */ $error_message = ''; $success_message = ''; if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id'])) { header('Location: service.php'); exit; } $service_id = (int)$_REQUEST['id']; if ($service_id <= 0) { header('Location: service.php'); exit; } /* |-------------------------------------------------------------------------- | LOAD HEADER / DATABASE |-------------------------------------------------------------------------- */ if (isset($_POST['ajax_location_content'])) { require_once __DIR__ . '/inc/config.php'; header('Content-Type: application/json; charset=utf-8'); try { if (!isset($pdo) || !($pdo instanceof PDO)) { throw new Exception('PDO connection is not initialized in inc/config.php.'); } $ajax_service_id = (int)($_POST['service_id'] ?? 0); $ajax_location_id = (int)($_POST['location_id'] ?? 0); if ($ajax_service_id <= 0 || $ajax_location_id <= 0) { throw new Exception('Invalid product or location ID.'); } $stmt = $pdo->prepare("SELECT id FROM tbl_location WHERE id = ? AND status = 1 LIMIT 1"); $stmt->execute([$ajax_location_id]); if (!$stmt->fetch(PDO::FETCH_ASSOC)) { throw new Exception('Selected location was not found.'); } $stmt = $pdo->prepare("SELECT short_description, content, description FROM tbl_service_location WHERE service_id = ? AND location_id = ? LIMIT 1"); $stmt->execute([$ajax_service_id, $ajax_location_id]); $seo = $stmt->fetch(PDO::FETCH_ASSOC); echo json_encode([ 'short_description' => $seo['short_description'] ?? '', 'content' => $seo['content'] ?? '', 'description' => $seo['description'] ?? '' ], JSON_INVALID_UTF8_SUBSTITUTE); } catch (Throwable $e) { error_log('Location AJAX error: ' . $e->getMessage()); http_response_code(500); echo json_encode(['error' => $e->getMessage()]); } exit; } require_once('header.php'); /* |-------------------------------------------------------------------------- | HELPER |-------------------------------------------------------------------------- */ if (!function_exists('e')) { function e($value) { return htmlspecialchars( (string)$value, ENT_QUOTES, 'UTF-8' ); } } /* |-------------------------------------------------------------------------- | FETCH PRODUCT |-------------------------------------------------------------------------- */ $statement = $pdo->prepare(" SELECT * FROM tbl_service WHERE id = ? LIMIT 1 "); $statement->execute([ $service_id ]); $service = $statement->fetch(PDO::FETCH_ASSOC); if (!$service) { header('Location: service.php'); exit; } /* |-------------------------------------------------------------------------- | UPDATE PRODUCT |-------------------------------------------------------------------------- */ if (isset($_POST['form1'])) { $error_message = ''; $success_message = ''; $top_category_id = (int)( $_POST['top_category_id'] ?? 0 ); $product_name = trim( $_POST['product_name'] ?? '' ); $product_slug = trim( $_POST['product_slug'] ?? '' ); $short_description = trim( $_POST['short_description'] ?? '' ); $description = $_POST['description'] ?? ''; $content = $_POST['content'] ?? ''; $current_photo = trim( $_POST['current_photo'] ?? '' ); $current_brochure = trim( $_POST['current_brochure'] ?? '' ); /* * Keep existing files unless a new file * is uploaded. */ $final_photo = basename($current_photo); $final_brochure = $current_brochure; $old_photo = basename($current_photo); $old_brochure = $current_brochure; $new_photo_path = ''; $new_brochure_path = ''; /* |-------------------------------------------------------------------------- | VALIDATION |-------------------------------------------------------------------------- */ if ($top_category_id <= 0) { $error_message .= 'Please select a category.<br>'; } if ($product_name === '') { $error_message .= 'Product name is required.<br>'; } if ($product_slug === '') { $error_message .= 'Product slug is required.<br>'; } /* |-------------------------------------------------------------------------- | NORMALIZE SLUG |-------------------------------------------------------------------------- */ if ($product_slug !== '') { $product_slug = strtolower( $product_slug ); $product_slug = preg_replace( '/[^a-z0-9]+/', '-', $product_slug ); $product_slug = trim( $product_slug, '-' ); } if ($product_slug === '') { $error_message .= 'Invalid product slug.<br>'; } /* |-------------------------------------------------------------------------- | CHECK CATEGORY |-------------------------------------------------------------------------- */ if ($top_category_id > 0) { $statement = $pdo->prepare(" SELECT id FROM tbl_top_category WHERE id = ? AND status = 1 LIMIT 1 "); $statement->execute([ $top_category_id ]); if (!$statement->fetch()) { $error_message .= 'Selected category is invalid.<br>'; } } /* |-------------------------------------------------------------------------- | CHECK DUPLICATE SLUG |-------------------------------------------------------------------------- */ if ($product_slug !== '') { $statement = $pdo->prepare(" SELECT id FROM tbl_service WHERE product_slug = ? AND id != ? LIMIT 1 "); $statement->execute([ $product_slug, $service_id ]); if ($statement->fetch()) { $error_message .= 'Product slug already exists.<br>'; } } /* |-------------------------------------------------------------------------- | APPLICATIONS |-------------------------------------------------------------------------- */ $applications = []; $application_keys = $_POST['application_key'] ?? []; $application_values = $_POST['application_value'] ?? []; if ( is_array($application_keys) && is_array($application_values) ) { foreach ( $application_keys as $index => $key ) { $key = trim($key); $value = trim( $application_values[$index] ?? '' ); if ( $key !== '' && $value !== '' ) { $applications[] = [ 'name' => $key, 'value' => $value ]; } } } $application_json = json_encode( $applications, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); if ($application_json === false) { $error_message .= 'Unable to save application data.<br>'; } /* |-------------------------------------------------------------------------- | PRODUCT IMAGE UPLOAD |-------------------------------------------------------------------------- */ if ( isset($_FILES['photo']) && !empty($_FILES['photo']['name']) ) { $photo_name = $_FILES['photo']['name']; $photo_tmp = $_FILES['photo']['tmp_name']; $photo_error = $_FILES['photo']['error']; $photo_size = $_FILES['photo']['size']; if ( $photo_error !== UPLOAD_ERR_OK ) { $error_message .= 'Product image upload failed.<br>'; } elseif ( !is_uploaded_file($photo_tmp) ) { $error_message .= 'Invalid product image upload.<br>'; } elseif ( $photo_size > 5 * 1024 * 1024 ) { $error_message .= 'Product image must not exceed 5 MB.<br>'; } else { $photo_ext = strtolower( pathinfo( $photo_name, PATHINFO_EXTENSION ) ); $allowed_extensions = [ 'jpg', 'jpeg', 'png', 'gif', 'webp' ]; if ( !in_array( $photo_ext, $allowed_extensions, true ) ) { $error_message .= 'Invalid product image format. Allowed: JPG, JPEG, PNG, GIF or WEBP.<br>'; } elseif ( @getimagesize($photo_tmp) === false ) { $error_message .= 'Uploaded file is not a valid image.<br>'; } else { /* * IMPORTANT: * Product images are inside: * * admin/assets/images/products/ */ $product_dir = __DIR__ . '/assets/images/products/'; if (!is_dir($product_dir)) { if ( !mkdir( $product_dir, 0755, true ) ) { $error_message .= 'Unable to create product image directory.<br>'; } } if ($error_message === '') { $new_photo = 'product_' . time() . '_' . bin2hex( random_bytes(5) ) . '.' . $photo_ext; $new_photo_path = $product_dir . $new_photo; if ( move_uploaded_file( $photo_tmp, $new_photo_path ) ) { /* * DATABASE: * filename only */ $final_photo = $new_photo; } else { $error_message .= 'Failed to upload product image.<br>'; } } } } } /* |-------------------------------------------------------------------------- | BROCHURE UPLOAD |-------------------------------------------------------------------------- */ if ( isset($_FILES['brochure']) && !empty($_FILES['brochure']['name']) ) { $brochure_name = $_FILES['brochure']['name']; $brochure_tmp = $_FILES['brochure']['tmp_name']; $brochure_error = $_FILES['brochure']['error']; $brochure_size = $_FILES['brochure']['size']; if ( $brochure_error !== UPLOAD_ERR_OK ) { $error_message .= 'Brochure upload failed.<br>'; } elseif ( !is_uploaded_file( $brochure_tmp ) ) { $error_message .= 'Invalid brochure upload.<br>'; } elseif ( $brochure_size > 15 * 1024 * 1024 ) { $error_message .= 'Brochure must not exceed 15 MB.<br>'; } else { $brochure_ext = strtolower( pathinfo( $brochure_name, PATHINFO_EXTENSION ) ); if ($brochure_ext !== 'pdf') { $error_message .= 'Brochure must be a PDF file.<br>'; } else { /* * Brochures are inside: * * admin/pdf/ */ $brochure_dir = __DIR__ . '/pdf/'; if (!is_dir($brochure_dir)) { if ( !mkdir( $brochure_dir, 0755, true ) ) { $error_message .= 'Unable to create brochure directory.<br>'; } } if ($error_message === '') { $new_brochure = 'brochure_' . time() . '_' . bin2hex( random_bytes(5) ) . '.pdf'; $new_brochure_path = $brochure_dir . $new_brochure; if ( move_uploaded_file( $brochure_tmp, $new_brochure_path ) ) { /* * DATABASE VALUE */ $final_brochure = 'pdf/' . $new_brochure; } else { $error_message .= 'Failed to upload brochure.<br>'; } } } } } /* |-------------------------------------------------------------------------- | GALLERY |-------------------------------------------------------------------------- */ $gallery = []; if ($final_photo !== '') { /* * Store filename only. */ $gallery[] = basename($final_photo); } $gallery_json = json_encode( $gallery, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ); if ($gallery_json === false) { $error_message .= 'Unable to save gallery data.<br>'; } /* |-------------------------------------------------------------------------- | FEATURED |-------------------------------------------------------------------------- */ $featured = isset($_POST['featured']) ? 1 : 0; /* |-------------------------------------------------------------------------- | SAVE PRODUCT |-------------------------------------------------------------------------- */ if ($error_message === '') { try { $pdo->beginTransaction(); $statement = $pdo->prepare(" UPDATE tbl_service SET top_category_id = ?, product_name = ?, product_slug = ?, short_description = ?, description = ?, content = ?, main_image = ?, gallery = ?, application = ?, brochure = ?, featured = ?, updated_at = NOW() WHERE id = ? "); $statement->execute([ $top_category_id, $product_name, $product_slug, $short_description, $description, $content, $final_photo, $gallery_json, $application_json, $final_brochure !== '' ? $final_brochure : null, $featured, $service_id ]); $pdo->commit(); /* |-------------------------------------------------------------------------- | DELETE OLD PRODUCT IMAGE |-------------------------------------------------------------------------- */ if ( $old_photo !== '' && $old_photo !== $final_photo ) { $old_photo_path = __DIR__ . '/assets/images/products/' . basename($old_photo); if ( file_exists( $old_photo_path ) ) { @unlink( $old_photo_path ); } } /* |-------------------------------------------------------------------------- | DELETE OLD BROCHURE |-------------------------------------------------------------------------- */ if ( $old_brochure !== '' && $old_brochure !== $final_brochure ) { $old_brochure_clean = str_replace( '\\', '/', $old_brochure ); $old_brochure_clean = ltrim( $old_brochure_clean, '/' ); $old_brochure_path = __DIR__ . '/' . $old_brochure_clean; if ( file_exists( $old_brochure_path ) ) { @unlink( $old_brochure_path ); } } $success_message = 'Product updated successfully.'; /* |-------------------------------------------------------------------------- | REFRESH PRODUCT |-------------------------------------------------------------------------- */ $statement = $pdo->prepare(" SELECT * FROM tbl_service WHERE id = ? LIMIT 1 "); $statement->execute([ $service_id ]); $service = $statement->fetch( PDO::FETCH_ASSOC ); } catch (PDOException $e) { if ( $pdo->inTransaction() ) { $pdo->rollBack(); } /* * Remove newly uploaded image * if database update failed. */ if ( $new_photo_path !== '' && file_exists($new_photo_path) ) { @unlink( $new_photo_path ); } /* * Remove newly uploaded brochure * if database update failed. */ if ( $new_brochure_path !== '' && file_exists($new_brochure_path) ) { @unlink( $new_brochure_path ); } $error_message = 'Database Error: ' . e($e->getMessage()); } } } /* |-------------------------------------------------------------------------- | LOCATION SEO |-------------------------------------------------------------------------- */ if (isset($_POST['save_location'])) { $location_id = (int)( $_POST['location_id'] ?? 0 ); // $short_description_loc = // trim( // $_POST[ // 'short_description_loc' // ] ?? '' // ); // $content_loc = // $_POST['content_loc'] ?? ''; $description_loc = $_POST['description_loc'] ?? ''; if ($location_id <= 0) { $error_message = 'Please select a location.<br>'; } else { try { /* * Check location */ $statement = $pdo->prepare(" SELECT id FROM tbl_location WHERE id = ? AND status = 1 LIMIT 1 "); $statement->execute([ $location_id ]); if (!$statement->fetch()) { $error_message = 'Selected location is invalid.<br>'; } else { $statement = $pdo->prepare(" INSERT INTO tbl_service_location ( service_id, location_id, short_description, content, description ) VALUES (?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE short_description = VALUES(short_description), content = VALUES(content), description = VALUES(description) "); $statement->execute([ $service_id, $location_id, $short_description_loc, $content_loc, $description_loc ]); $success_message = 'Location SEO content saved successfully.'; } } catch (PDOException $e) { $error_message = 'Database Error: ' . e($e->getMessage()); } } } /* |-------------------------------------------------------------------------- | REFRESH PRODUCT |-------------------------------------------------------------------------- */ $statement = $pdo->prepare(" SELECT * FROM tbl_service WHERE id = ? LIMIT 1 "); $statement->execute([ $service_id ]); $service = $statement->fetch( PDO::FETCH_ASSOC ); if (!$service) { header( 'Location: service.php' ); exit; } /* |-------------------------------------------------------------------------- | FETCH CATEGORIES |-------------------------------------------------------------------------- */ $statement = $pdo->prepare(" SELECT id, top_category_name FROM tbl_top_category WHERE status = 1 ORDER BY top_category_name ASC "); $statement->execute(); $categories = $statement->fetchAll( PDO::FETCH_ASSOC ); /* |-------------------------------------------------------------------------- | APPLICATION DATA |-------------------------------------------------------------------------- */ $edit_applications = []; if (!empty($service['application'])) { $decoded = json_decode( $service['application'], true ); if (is_array($decoded)) { /* * NEW FORMAT * * [ * { * "name":"Application", * "value":"Industrial" * } * ] */ if ( isset($decoded[0]) && is_array($decoded[0]) && isset($decoded[0]['name']) ) { foreach ( $decoded as $item ) { $name = trim( $item['name'] ?? '' ); $value = trim( $item['value'] ?? '' ); if ( $name !== '' && $value !== '' ) { $edit_applications[] = [ 'name' => $name, 'value' => $value ]; } } } else { /* * OLD FORMAT * * { * "Application":"Industrial" * } */ foreach ( $decoded as $key => $value ) { if ( !is_array($value) && trim((string)$key) !== '' && trim((string)$value) !== '' ) { $edit_applications[] = [ 'name' => trim((string)$key), 'value' => trim((string)$value) ]; } } } } } /* |-------------------------------------------------------------------------- | FETCH LOCATIONS |-------------------------------------------------------------------------- */ $locations = []; try { $statement = $pdo->query(" SELECT id, location_name FROM tbl_location WHERE status = 1 ORDER BY location_name ASC "); $locations = $statement->fetchAll( PDO::FETCH_ASSOC ); } catch (PDOException $e) { $locations = []; } /* |-------------------------------------------------------------------------- | FETCH EXISTING LOCATION SEO |-------------------------------------------------------------------------- */ $location_seo = []; try { $statement = $pdo->prepare(" SELECT * FROM tbl_service_location WHERE service_id = ? "); $statement->execute([ $service_id ]); $location_seo_rows = $statement->fetchAll( PDO::FETCH_ASSOC ); foreach ( $location_seo_rows as $row ) { $location_seo[ (int)$row['location_id'] ] = $row; } } catch (PDOException $e) { $location_seo = []; } /* DELETE LOCATION SEO */ if (isset($_POST['delete_location_seo'])) { $delete_location_id = (int) ( $_POST['delete_location_id'] ?? 0 ); if ($delete_location_id <= 0) { $error_message = 'Invalid location selected.'; } else { try { $statement = $pdo->prepare(" DELETE FROM tbl_service_location WHERE service_id = ? AND location_id = ? "); $statement->execute([ $service_id, $delete_location_id ]); if ($statement->rowCount() > 0) { $success_message = 'Location SEO details deleted successfully.'; } else { $error_message = 'No Location SEO record was found.'; } } catch (PDOException $e) { $error_message = 'Unable to delete Location SEO details.'; } } } ?> <section class="content-header"> <div class="content-header-left"> <h1> Edit Product </h1> </div> <div class="content-header-right"> <a href="service.php" class="btn btn-primary btn-sm"> View All </a> </div> </section> <section class="content"> <?php if (!empty($error_message)): ?> <div class="callout callout-danger"> <?php echo $error_message; ?> </div> <?php endif; ?> <?php if (!empty($success_message)): ?> <div class="callout callout-success"> <?php echo e( $success_message ); ?> </div> <?php endif; ?> <div class="nav-tabs-custom"> <ul class="nav nav-tabs"> <li class="active"> <a href="#tab1" data-toggle="tab"> Product Details </a> </li> <li> <a href="#tab2" data-toggle="tab"> Location SEO </a> </li> </ul> <div class="tab-content"> <!-- ================================================== PRODUCT DETAILS =================================================== --> <div class="tab-pane active" id="tab1"> <form method="post" enctype="multipart/form-data"> <input type="hidden" name="form1" value="1"> <input type="hidden" name="current_photo" value="<?php echo e( $service[ 'main_image' ] ?? '' ); ?>"> <input type="hidden" name="current_brochure" value="<?php echo e( $service[ 'brochure' ] ?? '' ); ?>"> <!-- CATEGORY --> <div class="form-group"> <label> Category </label> <select name="top_category_id" class="form-control" required> <option value=""> Select Category </option> <?php foreach ( $categories as $category ): ?> <option value="<?php echo (int) $category['id']; ?>" <?php echo ( (int)( $service[ 'top_category_id' ] ?? 0 ) === (int)( $category['id'] ) ) ? 'selected' : ''; ?> > <?php echo e( $category[ 'top_category_name' ] ); ?> </option> <?php endforeach; ?> </select> </div> <!-- PRODUCT NAME --> <div class="form-group"> <label> Product Name </label> <input type="text" name="product_name" class="form-control" value="<?php echo e( $service[ 'product_name' ] ?? '' ); ?>" required> </div> <!-- SLUG --> <div class="form-group"> <label> Product Slug </label> <input type="text" name="product_slug" id="product_slug" class="form-control" value="<?php echo e( $service[ 'product_slug' ] ?? '' ); ?>" required> </div> <!-- CONTENT --> <div class="form-group"> <label> Content </label> <textarea name="content" id="editor1" class="form-control"><?php echo $service[ 'content' ] ?? ''; ?></textarea> </div> <!-- SHORT DESCRIPTION --> <div class="form-group"> <label> Short Description </label> <textarea name="short_description" class="form-control" rows="4"><?php echo e( $service[ 'short_description' ] ?? '' ); ?></textarea> </div> <!-- DESCRIPTION --> <div class="form-group"> <label> Description </label> <textarea name="description" id="editor2" class="form-control"><?php echo $service[ 'description' ] ?? ''; ?></textarea> </div> <!-- APPLICATIONS --> <div class="form-group"> <label> Applications </label> <div id="application-wrapper"> <?php if ( !empty( $edit_applications ) ): ?> <?php foreach ( $edit_applications as $index => $application ): ?> <div class="application-row row" style=" margin-bottom:10px; "> <div class="col-sm-5"> <input type="text" name="application_key[]" class="form-control" placeholder="Application" value="<?php echo e( $application[ 'name' ] ); ?>"> </div> <div class="col-sm-5"> <input type="text" name="application_value[]" class="form-control" placeholder="Value" value="<?php echo e( $application[ 'value' ] ); ?>"> </div> <div class="col-sm-2"> <?php if ( $index === 0 ): ?> <button type="button" class="btn btn-success add-application"> + </button> <?php else: ?> <button type="button" class="btn btn-danger remove-application"> - </button> <?php endif; ?> </div> </div> <?php endforeach; ?> <?php else: ?> <div class="application-row row" style=" margin-bottom:10px; "> <div class="col-sm-5"> <input type="text" name="application_key[]" class="form-control" placeholder="Application"> </div> <div class="col-sm-5"> <input type="text" name="application_value[]" class="form-control" placeholder="Value"> </div> <div class="col-sm-2"> <button type="button" class="btn btn-success add-application"> + </button> </div> </div> <?php endif; ?> </div> </div> <!-- ================================================== PRODUCT IMAGE =================================================== --> <div class="form-group"> <label> Product Image </label> <?php if ( !empty( $service[ 'main_image' ] ) ): ?> <div style=" margin-bottom:10px; "> <img src="assets/images/products/<?php echo e( basename( $service[ 'main_image' ] ) ); ?>" alt="<?php echo e( $service[ 'product_name' ] ?? 'Product Image' ); ?>" style=" width:180px; height:120px; object-fit:contain; border:1px solid #ddd; padding:5px; "> </div> <?php endif; ?> <input type="file" name="photo" accept=".jpg,.jpeg,.png,.gif,.webp"> <p class="help-block"> JPG, JPEG, PNG, GIF or WEBP. Maximum 5 MB. </p> </div> <!-- ================================================== BROCHURE =================================================== --> <div class="form-group"> <label> Brochure </label> <?php if ( !empty( $service[ 'brochure' ] ) ): ?> <div style=" margin-bottom:10px; "> <a href="<?php echo e( $service[ 'brochure' ] ); ?>" target="_blank" class="btn btn-default btn-sm"> View Current Brochure </a> </div> <?php endif; ?> <input type="file" name="brochure" accept=".pdf"> <p class="help-block"> PDF only. Maximum 15 MB. </p> </div> <!-- FEATURED --> <div class="form-group"> <label> Featured </label> <label> <input type="checkbox" name="featured" value="1" <?php echo ( (int)( $service[ 'featured' ] ?? 0 ) === 1 ) ? 'checked' : ''; ?> > Featured Product </label> </div> <!-- UPDATE --> <div class="form-group"> <button type="submit" name="form1" value="1" class="btn btn-success"> Update Product </button> </div> </form> </div> <!-- ================================================== LOCATION SEO =================================================== --> <div class="tab-pane" id="tab2"> <!-- ADD / UPDATE LOCATION SEO --> <form method="post"> <div class="form-group"> <label>Select Location</label> <select name="location_id" id="location_id" class="form-control" required> <option value="">Select Location</option> <?php foreach ($locations as $location): ?> <option value="<?= (int) $location['id'] ?>"> <?= e($location['location_name']) ?> </option> <?php endforeach; ?> </select> </div> <div class="form-group"> <label>Description</label> <textarea name="description_loc" id="editor4" class="form-control"></textarea> </div> <button type="submit" name="save_location" value="1" class="btn btn-primary"> Save Location Content </button> </form> <!-- EXISTING LOCATION SEO --> <div class="location-cards"> <?php foreach ($location_seo as $seo): ?> <?php $locationId = (int)($seo['location_id'] ?? 0); $locationName = 'Location'; foreach ($locations as $location) { if ((int)$location['id'] === $locationId) { $locationName = $location['location_name']; break; } } ?> <div class="location-card"> <span class="location-card-name"><?= e($locationName) ?></span> <form method="post" onsubmit="return confirm('Delete this location content?');"> <input type="hidden" name="delete_location_id" value="<?= $locationId ?>"> <button type="submit" name="delete_location_seo" value="1" class="location-card-delete" aria-label="Delete <?= e($locationName) ?>">×</button> </form> </div> <?php endforeach; ?> </div> </div> </div> </div> </section> <script> document.addEventListener( 'DOMContentLoaded', function () { const wrapper = document.getElementById( 'application-wrapper' ); if (!wrapper) { return; } wrapper.addEventListener( 'click', function (event) { /* * ADD APPLICATION */ const addButton = event.target.closest( '.add-application' ); if (addButton) { const row = document.createElement( 'div' ); row.className = 'application-row row'; row.style.marginBottom = '10px'; row.innerHTML = ` <div class="col-sm-5"> <input type="text" name="application_key[]" class="form-control" placeholder="Application"> </div> <div class="col-sm-5"> <input type="text" name="application_value[]" class="form-control" placeholder="Value"> </div> <div class="col-sm-2"> <button type="button" class="btn btn-danger remove-application"> - </button> </div> `; wrapper.appendChild( row ); return; } /* * REMOVE APPLICATION */ const removeButton = event.target.closest( '.remove-application' ); if (removeButton) { const row = removeButton.closest( '.application-row' ); if (row) { row.remove(); } } } ); } ); document.addEventListener('DOMContentLoaded', function() { const select = document.getElementById('location_id'); const field = document.getElementById('editor4'); if (!select || !field) return; function setDescription(value) { value = value || ''; if (window.jQuery && jQuery.fn.summernote && jQuery(field).next('.note-editor').length) { jQuery(field).summernote('code', value); } else if (window.CKEDITOR && CKEDITOR.instances.editor4) { CKEDITOR.instances.editor4.setData(value); } else { field.value = value; } } select.addEventListener('change', function() { const locationId = this.value; if (!locationId) { setDescription(''); return; } const body = new URLSearchParams({ ajax_location_content: '1', service_id: <?= (int)$service_id ?>, location_id: locationId }); fetch(window.location.pathname + window.location.search, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' }, body: body.toString() }) .then(async response => { const text = await response.text(); let data; try { data = JSON.parse(text); } catch (error) { console.error('Invalid server response:', text); throw new Error('Invalid server response. Check PHP errors and the AJAX handler.'); } if (!response.ok || data.error) { throw new Error(data.error || 'HTTP error ' + response.status); } return data; }) .then(data => { setDescription(data.description || ''); }) .catch(error => { console.error('Location loading error:', error); alert(error.message || 'Unable to load location content.'); }); }); }); </script> <?php require_once('footer.php'); ?> <style> .location-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 15px; margin-top: 20px; } .location-card { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 65px; padding: 15px 18px; background: #fff; border: 1px solid #e83e8c; border-radius: 10px; box-shadow: 0 3px 10px rgba(232, 62, 140, 0.08); transition: all 0.25s ease; box-sizing: border-box; } .location-card:hover { border-color: #d81b75; box-shadow: 0 5px 16px rgba(232, 62, 140, 0.18); transform: translateY(-2px); } .location-card-name { color: #d63384; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; } .location-card form { margin: 0; flex-shrink: 0; } .location-card-delete { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border: 1px solid #e83e8c; border-radius: 50%; background: #fff0f6; color: #d63384; font-size: 21px; line-height: 1; cursor: pointer; transition: all 0.2s ease; } .location-card-delete:hover { background: #d63384; color: #fff; border-color: #d63384; } @media (max-width: 576px) { .location-cards { grid-template-columns: 1fr; } } </style>
Save
Cancel