OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
cream
/
CreateLeadPage_back
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
06/17/2025 10:17:24 AM
rwxrwxr-x
📄
24-02-25index.php
42.37 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
28index.php
55.04 KB
05/19/2025 10:07:19 AM
rw-r--r--
📁
NW_images
-
02/28/2025 12:23:08 PM
rwxr-xr-x
📄
aditya_index.php
39.95 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
aditya_load_template.php
2.39 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
aditya_save-template.php
2.44 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
aditya_upload.php
851 bytes
05/19/2025 10:07:19 AM
rw-r--r--
📁
assets
-
03/13/2025 08:45:46 AM
rwxr-xr-x
📄
back_index.php
28.33 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
backup_index.php
25.17 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
db_gallery.php
292 bytes
05/19/2025 10:07:19 AM
rw-r--r--
📄
edit_template.php
658 bytes
05/19/2025 10:07:19 AM
rw-r--r--
📄
fetch_data.php
773 bytes
05/19/2025 10:07:19 AM
rw-r--r--
📄
fetch_titles.php
0 bytes
05/19/2025 10:07:19 AM
rw-r--r--
📄
form.js
7.64 KB
03/13/2025 08:45:38 AM
rw-r--r--
📁
images12
-
03/01/2025 05:00:09 AM
rwxr-xr-x
📁
images13
-
03/01/2025 05:00:09 AM
rwxr-xr-x
📁
images14
-
03/01/2025 05:00:10 AM
rwxr-xr-x
📁
images15
-
03/01/2025 05:00:10 AM
rwxr-xr-x
📁
images16
-
03/01/2025 05:00:11 AM
rwxr-xr-x
📁
images17
-
03/01/2025 05:00:11 AM
rwxr-xr-x
📁
images18
-
03/01/2025 05:00:11 AM
rwxr-xr-x
📁
images19
-
03/01/2025 05:00:12 AM
rwxr-xr-x
📁
images2
-
03/01/2025 05:00:12 AM
rwxr-xr-x
📁
images20
-
03/01/2025 05:00:13 AM
rwxr-xr-x
📁
images21
-
03/01/2025 05:00:13 AM
rwxr-xr-x
📁
images3
-
03/01/2025 05:00:14 AM
rwxr-xr-x
📁
images4
-
03/01/2025 05:00:14 AM
rwxr-xr-x
📁
images5
-
03/01/2025 05:00:15 AM
rwxr-xr-x
📁
images6
-
03/01/2025 05:00:15 AM
rwxr-xr-x
📁
images7
-
03/01/2025 05:00:16 AM
rwxr-xr-x
📁
images8
-
03/01/2025 05:00:16 AM
rwxr-xr-x
📁
images9
-
03/01/2025 05:00:17 AM
rwxr-xr-x
📄
index.php
9.53 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
load_template.php
2.21 KB
05/19/2025 10:07:19 AM
rw-r--r--
📁
newsletter
-
03/13/2025 05:29:35 AM
rwxr-xr-x
📄
newsletter.png
194.94 KB
03/13/2025 08:45:38 AM
rw-r--r--
📄
nleditor_navbar.php
22.6 KB
05/19/2025 10:07:19 AM
rw-r--r--
📁
pages
-
03/13/2025 05:29:39 AM
rwxr-xr-x
📁
pages_backup
-
03/13/2025 08:45:51 AM
rwxr-xr-x
📄
process.js
27.81 KB
03/13/2025 08:45:38 AM
rw-r--r--
📄
processb.js
31.21 KB
03/13/2025 08:45:38 AM
rw-r--r--
📄
save-template.php
2.5 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
script.js
34.02 KB
03/13/2025 08:45:38 AM
rw-r--r--
📄
styles.css
2.43 KB
03/13/2025 08:45:38 AM
rw-r--r--
📄
template1.jpg
0 bytes
03/13/2025 08:45:38 AM
rw-r--r--
📄
test.html
5.84 KB
03/13/2025 08:45:38 AM
rw-r--r--
📄
test.php
1.58 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
test_index.php
48.82 KB
05/19/2025 10:07:19 AM
rw-r--r--
📄
texts.txt
1.7 KB
03/13/2025 08:45:38 AM
rw-r--r--
📄
upload.php
858 bytes
05/19/2025 10:07:19 AM
rw-r--r--
📁
uploads
-
03/13/2025 08:45:46 AM
rwxr-xr-x
Editing: aditya_index.php
Close
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Newsletter Template Editor</title> <!-- <link rel="stylesheet" href="style.css"> --> <script src="https://cdnjs.cloudflare.com/ajax/libs/interact.js/1.10.17/interact.min.js"></script> </head> <style> /* Main styles */ :root { --primary-color: #db5919; --secondary-color: #f4d03f; --text-color: #333; --background-color: #f5f5f5; } body { margin: 0; padding: 0; font-family: Arial, sans-serif; display: flex; height: 100vh; background-color: var(--background-color); } /* Sidebar styles */ .sidebar { width: 250px; background-color: white; padding: 20px; border-right: 1px solid #ddd; overflow-y: auto; } .template-list, .elements-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; } .template, .element { padding: 10px; border: 1px solid #ddd; border-radius: 4px; cursor: pointer; transition: all 0.3s ease; } .template:hover, .element:hover { background-color: #f0f0f0; border-color: var(--primary-color); } .template img { width: 100%; height: 120px; object-fit: cover; margin-bottom: 5px; } /* Main content styles */ .main-content { max-width: 800px; flex: 1; display: flex; flex-direction: column; padding: 20px; } .toolbar { background-color: white; padding: 10px; border-radius: 4px; margin-bottom: 20px; display: flex; gap: 10px; align-items: center; } .text-controls { display: flex; gap: 10px; align-items: center; } .canvas-area { flex: 1; background-color: white; border-radius: 4px; padding: 20px; overflow-y: auto; min-height: 800px; position: relative; } /* Element styles */ .draggable { position: absolute; padding: 10px; border: 1px solid transparent; cursor: move; user-select: none; } .draggable:hover { border-color: var(--primary-color); } .draggable.selected { border: 2px solid var(--primary-color); } /* Button styles */ button { padding: 8px 16px; background-color: var(--primary-color); color: white; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s ease; } button:hover { background-color: #c24c15; } /* Form controls */ select, input[type="color"] { padding: 5px; border: 1px solid #ddd; border-radius: 4px; } /* Responsive design */ @media (max-width: 768px) { body { flex-direction: column; } .sidebar { width: 100%; height: 200px; } } .template { cursor: pointer; padding: 10px; border: 1px solid #ccc; margin: 5px; display: inline-block; } #new-div-container { margin-top: 20px; height: 100vh; overflow-y: scroll; } .new-div { width: 150px; height: auto; overflow-y: scroll; padding: 0px; margin: 10px; border: 1px solid #000; background-color: #f0f0f0; } .new-div img { width: -webkit-fill-available; } </style> <!-- css for the text --> <style> /* Existing styles */ /* :root { --primary-color: #db5919; --secondary-color: #f4d03f; --text-color: #333; --background-color: #f5f5f5; } body { margin: 0; padding: 0; font-family: Arial, sans-serif; display: flex; height: 100vh; background-color: var(--background-color); } */ .sidebar { width: 250px; background-color: white; padding: 20px; border-right: 1px solid #ddd; overflow-y: auto; } .main-content { flex: 1; display: flex; flex-direction: column; padding: 20px; } .canvas-area { flex: 1; background-color: white; border-radius: 4px; padding: 20px; overflow-y: auto; min-height: 800px; position: relative; } /* New text element styles */ .text-element { position: absolute; min-width: 50px; min-height: 20px; padding: 5px; cursor: move; border: 1px solid transparent; transition: border 0.3s ease; } .text-element:hover { border: 1px dashed var(--primary-color); } .text-element.selected { border: 1px solid var(--primary-color); } .text-element[contenteditable="true"] { outline: none; border: 1px solid var(--primary-color); } /* Text controls styles */ .text-controls { display: flex; gap: 10px; align-items: center; background-color: white; padding: 10px; border-radius: 4px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); } .text-controls button { padding: 5px 10px; /* background-color: white; */ border: 1px solid #ddd; border-radius: 4px; cursor: pointer; transition: all 0.3s ease; } .text-controls button.active { background-color: var(--primary-color); color: white; } .text-controls select, .text-controls input { padding: 5px; border: 1px solid #ddd; border-radius: 4px; } /* Add text button style */ .add-text-btn { margin-bottom: 20px; width: 100%; padding: 10px; background-color: var(--primary-color); color: white; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s ease; } .add-text-btn:hover { background-color: #c24c15; } </style> <style> /* Modal styles */ .modal { display: none; position: fixed; z-index: 1; right: 0; top: 0; width: 30%; height: 100%; overflow: auto; background-color: rgba(0, 0, 0, 0.4); } .modal-content { background-color: #fefefe; /* margin: 2% auto; */ padding: 20px; border: 1px solid #888; /* width: 100%; */ } .close { color: #aaa; font-size: 28px; font-weight: bold; position: absolute; left: 25px; top: 0; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; } #modalContent a { color: black; } </style> <body> <div class="sidebar"> <h2>Templates</h2> <div class="template-list"> <div class="template" data-template="template_1" data-category="basic_newsletter"> <span>Basic Newsletter</span> </div> <div class="template" data-template="template_2" data-category="modern_layout"> <span>Modern Layout</span> </div> <div class="template" data-template="template_3" data-category="professional"> <span>Professional</span> </div> <div class="template" data-template="template_4" data-category="minimal_desing"> <span>Minimal Design</span> </div> <div class="template" data-template="template_5" data-category="creative_style"> <span>Creative Style</span> </div> </div> <!-- <button class="add-text-btn" id="addTextBtn">Add Text</button> <div class="image-upload"> <h2>Upload Image</h2> <input type="file" id="imageUpload" accept="image/*"> </div> --> </div> <div id="new-div-container"></div> <div class="main-content"> <div class="text-controls"> <button id="collectionBtn">Collection</button> <!-- <select id="fontFamily"> <option value="Arial">Arial</option> <option value="Times New Roman">Times New Roman</option> <option value="Helvetica">Helvetica</option> <option value="Georgia">Georgia</option> <option value="Verdana">Verdana</option> </select> <select id="fontSize"> <option value="12">12px</option> <option value="14">14px</option> <option value="16">16px</option> <option value="18">18px</option> <option value="24">24px</option> <option value="32">32px</option> <option value="48">48px</option> </select> <button id="boldText" title="Bold"><strong style="color: #000;">B</strong></button> <button id="italicText" title="Italic"><em style="color: #000;">I</em></button> <button id="underlineText" title="Underline" style="color: #000;"><u>U</u></button> <input type="color" id="textColor" title="Text Color"> <select id="textAlign"> <option value="left">Left</option> <option value="center">Center</option> <option value="right">Right</option> </select> --> </div> <div class="canvas-area" id="canvasArea"> <?php $getUrl = isset($_GET['template']) ? $_GET['template'] : null; $templateUrl = $_SERVER["DOCUMENT_ROOT"]."/Xpress/NLEditor/uploads/" . $getUrl; // If template URL exists, load the template or show an error if ($templateUrl) { // Check if the template file exists before including it if (file_exists($templateUrl)) { // Include the template (this will output the content of the template) include($templateUrl); } else { echo $templateUrl . "Template file not found."; } } else { echo "No template provided."; } ?> </div> </div> <div id="myModal" class="modal"> <div class="modal-content"> <span class="close">×</span> <h2>Collection Modal</h2> <div id="modalContent"> <!-- Data will be loaded here dynamically --> </div> </div> </div> <script src="script.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script> $(document).ready(function() { // Loop through all elements with class 'template' $('.template').each(function() { $(this).on('click', function() { // Get the category of the clicked template const category = $(this).data('category'); // Category from data-category attribute // Create the URL of the PHP endpoint for category-based fetching const templateUrl = `load_template.php?category=${category}`; // Create a new div element for the template content const newDiv = $('<div class="new-div"></div>'); // Show loading message while fetching newDiv.html('<p>Loading templates...</p>'); // Append the new div to the new-div-container $('#new-div-container').empty().append(newDiv); // Clear previous content before appending // Fetch the template data from the server using the PHP endpoint $.ajax({ url: templateUrl, // The PHP endpoint method: 'GET', // HTTP method to use success: function(response) { // Check if response contains templates (using data-template-path) if (response.includes('data-template-path')) { // Parse the response and display the templates const templatesContainer = $(response); // Assuming multiple templates are returned // Insert each template into the new div newDiv.html(templatesContainer); // Add click event for each template newDiv.find('.template').each(function() { $(this).on('click', function() { // Get the template's path and image details const templatePath = $(this).data('template-path'); const imagePath = $(this).find('img').attr('src'); // Handle template selection: Update canvas area const canvasArea = $('#canvasArea'); canvasArea.empty(); // Clear the current content // Fetch and display the template content in the canvas area $.ajax({ url: templatePath, method: 'GET', success: function(templateContent) { // Insert the template content into the canvas area canvasArea.html(templateContent); // Make all text elements editable makeElementsEditable(); // Set up image uploads setupImageUploads(); // Add save button functionality addSaveButton(templatePath); }, error: function(xhr, status, error) { canvasArea.html(`<p>Error loading template: ${error}</p>`); } }); }); }); } else { // Handle error if no templates are returned newDiv.html('<p>No templates found for this category.</p>'); } }, error: function(xhr, status, error) { // If there's an error (e.g., file not found), show an error message newDiv.html(`<p>Error: ${error}</p>`); } }); }); }); }); </script> <script> // Function to show the modal function showModal() { var modal = document.getElementById("myModal"); modal.style.display = "block"; // Show the modal } // Function to close the modal function closeModal() { var modal = document.getElementById("myModal"); modal.style.display = "none"; // Hide the modal } // Fetch data from the PHP script using AJAX function fetchData() { var xhr = new XMLHttpRequest(); xhr.open("GET", "fetch_data.php", true); // Fetch data from PHP script xhr.onreadystatechange = function() { if (xhr.readyState == 4 && xhr.status == 200) { var data = JSON.parse(xhr.responseText); // Parse the response // Check if there's data if (data.message) { document.getElementById("modalContent").innerHTML = data.message; // If no data, show message } else { // Initialize the content for checkboxes var content = ""; // Function to limit text to a specific number of words function limitText(text, wordLimit) { var words = text.split(' '); if (words.length > wordLimit) { return words.slice(0, wordLimit).join(' ') + '...'; // Limit words and add '...' } else { return text; // Return full text if it's within the limit } } // Loop through data to create checkboxes data.forEach(function(item) { var limitedTitle = limitText(item.title, 10); // Limit the title to 20 words var limitedDescription = limitText(item.description, 50); // Limit the description to 100 words content += ` <div> <input type="checkbox" id="checkbox_${item.id}" name="item" value="${item.id}"> <label for="checkbox_${item.id}"> <strong>${limitedTitle}</strong><br> <small>${limitedDescription}</small> </label> </div> `; }); // Insert the generated checkboxes into the modal content document.getElementById("modalContent").innerHTML = content; } } }; xhr.send(); // Send the request } // Get the button that triggers the modal var collectionBtn = document.getElementById("collectionBtn"); // Add click event listener to the "Collection" button collectionBtn.addEventListener("click", function() { fetchData(); // Fetch data when the button is clicked showModal(); // Show the modal }); // Close the modal when the <span> (close button) is clicked document.getElementsByClassName("close")[0].addEventListener("click", closeModal); // Close the modal if the user clicks outside the modal content window.addEventListener("click", function(event) { var modal = document.getElementById("myModal"); if (event.target === modal) { closeModal(); } }); </script> <!-- script for the text --> <script> document.addEventListener('DOMContentLoaded', function() { let selectedElement = null; let textCounter = 0; // Function to create a new text element function createTextElement() { const textElement = document.createElement('div'); textElement.className = 'text-element'; textElement.setAttribute('data-text-id', `text-${++textCounter}`); textElement.innerHTML = 'Click to edit text'; textElement.style.left = '50px'; textElement.style.top = '50px'; return textElement; } // Add text button click handler document.getElementById('addTextBtn').addEventListener('click', function() { const textElement = createTextElement(); document.getElementById('canvasArea').appendChild(textElement); makeElementDraggable(textElement); selectElement(textElement); }); // Make elements draggable using interact.js function makeElementDraggable(element) { interact(element) .draggable({ inertia: true, modifiers: [ interact.modifiers.restrictRect({ restriction: 'parent', endOnly: true }) ], listeners: { move: dragMoveListener, start: function(event) { selectElement(event.target); } } }) .resizable({ edges: { left: true, right: true, bottom: true, top: true }, listeners: { move: resizeMoveListener } }); } // Drag move listener function dragMoveListener(event) { const target = event.target; const x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx; const y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy; target.style.transform = `translate(${x}px, ${y}px)`; target.setAttribute('data-x', x); target.setAttribute('data-y', y); } // Resize move listener function resizeMoveListener(event) { const target = event.target; let x = (parseFloat(target.getAttribute('data-x')) || 0); let y = (parseFloat(target.getAttribute('data-y')) || 0); Object.assign(target.style, { width: `${event.rect.width}px`, height: `${event.rect.height}px`, transform: `translate(${x}px, ${y}px)` }); } // Select element function function selectElement(element) { if (selectedElement) { selectedElement.classList.remove('selected'); selectedElement.setAttribute('contenteditable', 'false'); } selectedElement = element; element.classList.add('selected'); // Update controls to match selected element's styles document.getElementById('fontFamily').value = element.style.fontFamily || 'Arial'; document.getElementById('fontSize').value = parseInt(element.style.fontSize) || '16'; document.getElementById('textColor').value = rgb2hex(element.style.color) || '#000000'; document.getElementById('textAlign').value = element.style.textAlign || 'left'; } // Double click to edit document.getElementById('canvasArea').addEventListener('dblclick', function(e) { if (e.target.classList.contains('text-element')) { e.target.setAttribute('contenteditable', 'true'); e.target.focus(); } }); // Style controls event listeners document.getElementById('fontFamily').addEventListener('change', function(e) { if (selectedElement) { selectedElement.style.fontFamily = e.target.value; } }); document.getElementById('fontSize').addEventListener('change', function(e) { if (selectedElement) { selectedElement.style.fontSize = `${e.target.value}px`; } }); document.getElementById('textColor').addEventListener('input', function(e) { if (selectedElement) { selectedElement.style.color = e.target.value; } }); document.getElementById('boldText').addEventListener('click', function() { if (selectedElement) { const isBold = selectedElement.style.fontWeight === 'bold'; selectedElement.style.fontWeight = isBold ? 'normal' : 'bold'; this.classList.toggle('active'); } }); document.getElementById('italicText').addEventListener('click', function() { if (selectedElement) { const isItalic = selectedElement.style.fontStyle === 'italic'; selectedElement.style.fontStyle = isItalic ? 'normal' : 'italic'; this.classList.toggle('active'); } }); document.getElementById('underlineText').addEventListener('click', function() { if (selectedElement) { const isUnderlined = selectedElement.style.textDecoration === 'underline'; selectedElement.style.textDecoration = isUnderlined ? 'none' : 'underline'; this.classList.toggle('active'); } }); document.getElementById('textAlign').addEventListener('change', function(e) { if (selectedElement) { selectedElement.style.textAlign = e.target.value; } }); // Utility function to convert RGB to HEX function rgb2hex(rgb) { if (!rgb) return '#000000'; if (rgb.search("rgb") == -1) return rgb; rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/); function hex(x) { return ("0" + parseInt(x).toString(16)).slice(-2); } return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } // Click outside to deselect document.addEventListener('click', function(e) { if (!e.target.classList.contains('text-element') && !e.target.closest('.text-controls')) { if (selectedElement) { selectedElement.classList.remove('selected'); selectedElement.setAttribute('contenteditable', 'false'); selectedElement = null; } } }); // Function to save the current state of all text elements function saveTemplate(templatePath) { const elements = document.querySelectorAll('.text-element'); const templateData = []; elements.forEach(element => { const styles = getComputedStyle(element); templateData.push({ id: element.getAttribute('data-text-id'), text: element.innerHTML, position: { left: styles.left, top: styles.top }, width: styles.width, height: styles.height, fontFamily: styles.fontFamily, fontSize: styles.fontSize, color: rgb2hex(styles.color), textAlign: styles.textAlign, fontWeight: styles.fontWeight, fontStyle: styles.fontStyle, textDecoration: styles.textDecoration }); }); const jsonData = JSON.stringify(templateData); // Save data logic here console.log('Saving Template:', jsonData); // You can send the jsonData to the server or save it locally } // Add save button function addSaveButton(templatePath) { const saveBtn = $('<button class="image-upload-btn" id="saveTemplate">Save Changes</button>') .prependTo('#canvasArea') .css({ 'position': 'fixed', 'top': '20px', 'right': '20px', 'background': '#28a745', 'color': 'white', 'border': 'none', 'padding': '10px 20px', 'cursor': 'pointer', 'z-index': '1000' }); saveBtn.click(function() { saveTemplate(templatePath); }); } // Example: Initialize save button with templatePath addSaveButton('/path/to/save/template'); }); </script> <script> function makeElementsEditable() { // Make various elements editable $('#canvasArea p, #canvasArea h1, #canvasArea h2, #canvasArea h3, #canvasArea h4, #canvasArea h5, #canvasArea h6, #canvasArea span, #canvasArea a, #canvasArea li, #canvasArea strong, #canvasArea em, #canvasArea b, #canvasArea i') .attr('contenteditable', 'true') // Make elements editable .addClass('editable-element') // Add a class to identify editable elements .css({ 'border': '1px dashed transparent', // Default invisible border 'padding': '5px', // Add some padding for better interaction 'outline': 'none', // Remove default outline when focused 'cursor': 'text' // Set cursor to text when hovering over the element }) .hover( function() { $(this).css('border-color', '#999'); // Show dashed border on hover }, function() { $(this).css('border-color', 'transparent'); // Hide the border when not hovering } ) .focus(function() { // Show a solid border when the element is focused $(this).css('border-color', '#007bff'); }) .blur(function() { // Remove the border when the element loses focus $(this).css('border-color', 'transparent'); }); } $(document).ready(function() { $("#canvasArea").on("click", "a", function(event) { event.preventDefault(); // Prevent default link behavior let currentHref = $(this).attr("href") || ""; // Get current href let newHref = prompt("Enter new link:", currentHref); // Prompt user for new link if (newHref !== null && newHref.trim() !== "") { $(this).attr("href", newHref); // Update the href attribute } }); }); function setupImageUploads() { $('#canvasArea img').each(function() { const img = $(this); const uploadBtn = $('<input type="file" accept="image/*" style="display: none;">').insertAfter(img); const changeBtn = $('<button class="image-upload-btn"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M7 7H6a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2-2v-1"/><path d="M20.385 6.585a2.1 2.1 0 0 0-2.97-2.97L9 12v3h3zM16 5l3 3"/></g></svg></button>').insertAfter(img).css({ 'position': 'absolute', 'background': '#007bff', 'color': 'white', 'border': 'none', 'padding': '5px 10px', 'cursor': 'pointer', 'z-index': '1000' // 'display': 'none' }); // img.parent().css('position', 'relative').hover( // function() { // changeBtn.show(); // }, // function() { // changeBtn.hide(); // } // ); changeBtn.click(function() { uploadBtn.click(); }); uploadBtn.change(function(e) { const file = e.target.files[0]; if (file) { const formData = new FormData(); formData.append('image', file); $.ajax({ url: 'upload.php', // PHP script to handle file upload type: 'POST', data: formData, contentType: false, processData: false, success: function(response) { if (response.startsWith("uploads/NW_images/")) { let tempSrc = response; // Temporary src while uploading img.attr('src', tempSrc); // After saving, update src by removing "uploads/" // let finalSrc = response.replace("uploads/", ""); // setTimeout(function() { // img.attr('src', finalSrc); // },2000); } else { alert('Error: ' + response); } }, error: function() { alert('Image upload failed.'); } }); } }); }); } function addSaveButton(templatePath) { // Add save button at the top const saveBtn = $('<button class="image-upload-btn" id="saveTemplate">Save Changes</button>') .prependTo('#canvasArea') .css({ 'position': 'fixed', 'top': '20px', 'right': '20px', 'background': '#28a745', 'color': 'white', 'border': 'none', 'padding': '10px 20px', 'cursor': 'pointer', 'z-index': '1000' }); saveBtn.click(function() { saveTemplate(templatePath); }); } // Frontend JavaScript function saveTemplate() { // Prompt for template name const templateName = prompt('Please enter a name for your template:'); // If user cancels the prompt or enters empty string, abort save if (!templateName) { return; } // Create the template path using the provided name // Assuming templates are stored in a 'templates' directory and using .html extension const templatePath = `templates/${templateName}.html`; // Create FormData to handle both text content and images const formData = new FormData(); // Get the current state of the template const template = $('#canvasArea').clone(); // Remove editing-related elements and classes template.find('.image-upload-btn, input[type="file"]').remove(); template.find('[contenteditable]').removeAttr('contenteditable'); template.find('.editable-element').removeClass('editable-element'); // Modify image src paths template.find('img').each(function() { let src = $(this).attr('src'); if (src && src.startsWith('uploads/')) { $(this).attr('src', src.replace('uploads/', 'https://knoblycream.com/Xpress/NLEditor/uploads/')); } }); // Add the template path and HTML content to FormData formData.append('templatePath', templatePath); formData.append('template', template.html()); formData.append('templateFileName', `${templateName}.html`); // Add images to FormData with proper handling template.find('img').each(function(index) { const newImage = $(this).data('newImage'); if (newImage instanceof File) { formData.append(`image_${index}`, newImage); // Store the full image element path for accurate selection const selector = $(this).prop('tagName').toLowerCase() + ($(this).attr('class') ? '.' + $(this).attr('class').replace(/\s+/g, '.') : '') + ($(this).attr('id') ? '#' + $(this).attr('id') : ''); formData.append(`image_${index}_selector`, selector); } }); // Debug logging console.log('Sending template save request:', { templatePath, templateName, formDataEntries: Array.from(formData.entries()).map(([key, value]) => value instanceof File ? `${key}: File(${value.name})` : `${key}: ${value}` ) }); // Save the template $.ajax({ url: 'save-template.php', method: 'POST', data: formData, processData: false, contentType: false, success: function(response) { console.log('Save response:', response); if (response.success) { alert('Template saved successfully!'); window.location.href = '../choose_template.php'; } else { alert('Error saving template: ' + (response.error || 'Unknown error')); } }, error: function(xhr, status, error) { console.error('Save error:', { status, error, response: xhr.responseText }); try { const response = JSON.parse(xhr.responseText); alert('Error saving template: ' + (response.error || error)); } catch (e) { alert('Error saving template: ' + error); } } }); } // Helper function to get unique selector for an element $.fn.getPath = function() { if (this.length != 1) return false; var path = this.prop('tagName').toLowerCase(); if (this.attr('id')) { path += '#' + this.attr('id'); } else if (this.attr('class')) { path += '.' + this.attr('class').replace(/\s+/g, '.'); } return path; }; </script> </body> </html>