diff --git a/ajax/ajax_contact_edit.php b/ajax/ajax_contact_edit.php new file mode 100644 index 00000000..b0286cba --- /dev/null +++ b/ajax/ajax_contact_edit.php @@ -0,0 +1,384 @@ + 'Contact ID missing.']); + exit; +} + +$contact_id = intval($_GET['id']); + +$sql = mysqli_query($mysqli, "SELECT * FROM contacts + LEFT JOIN users ON user_id = contact_user_id + WHERE contact_id = $contact_id + LIMIT 1" +); + +$row = mysqli_fetch_array($sql); +$client_id = intval($row['contact_client_id']); +$contact_name = nullable_htmlentities($row['contact_name']); +$contact_title = nullable_htmlentities($row['contact_title']); +$contact_department = nullable_htmlentities($row['contact_department']); +$contact_extension = nullable_htmlentities($row['contact_extension']); +$contact_phone = formatPhoneNumber($row['contact_phone']); +$contact_mobile = formatPhoneNumber($row['contact_mobile']); +$contact_email = nullable_htmlentities($row['contact_email']); +$contact_pin = nullable_htmlentities($row['contact_pin']); +$contact_photo = nullable_htmlentities($row['contact_photo']); +$contact_initials = initials($contact_name); +$contact_notes = nullable_htmlentities($row['contact_notes']); +$contact_primary = intval($row['contact_primary']); +$contact_important = intval($row['contact_important']); +$contact_billing = intval($row['contact_billing']); +$contact_technical = intval($row['contact_technical']); +$contact_created_at = nullable_htmlentities($row['contact_created_at']); +$contact_archived_at = nullable_htmlentities($row['contact_archived_at']); +$contact_location_id = intval($row['contact_location_id']); +$auth_method = nullable_htmlentities($row['user_auth_method']); +$contact_user_id = intval($row['contact_user_id']); + +// Tags +$contact_tag_id_array = array(); +$sql_contact_tags = mysqli_query($mysqli, "SELECT contact_tags.tag_id FROM contact_tags LEFT JOIN tags ON contact_tags.tag_id = tags.tag_id WHERE contact_id = $contact_id ORDER BY tag_name ASC"); +while ($row = mysqli_fetch_array($sql_contact_tags)) { + $contact_tag_id = intval($row['tag_id']); + $contact_tag_id_array[] = $contact_tag_id; +} + +// Build the dynamic modal title +$title = "Editing Contact: $contact_name"; + +// Generate the HTML form content using output buffering. +ob_start(); +?> +
+ + + + + + + $title, 'content' => $content]); +?> + diff --git a/client_contacts.php b/client_contacts.php index 8cd0f36b..3bff2bc5 100644 --- a/client_contacts.php +++ b/client_contacts.php @@ -383,7 +383,9 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); Make Note - + Edit @@ -418,7 +420,6 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); + +*/ +$(document).on('click', '.ajax-trigger', function (e) { + e.preventDefault(); + + // Get the URL and ID from the element's data attributes + var $trigger = $(this); + var ajaxUrl = $trigger.data('ajax-url'); + var ajaxId = $trigger.data('ajax-id'); + + // Make the AJAX call to fetch modal content + $.ajax({ + url: ajaxUrl, + method: 'GET', + data: { id: ajaxId }, + dataType: 'json', + success: function (response) { + if (response.error) { + alert(response.error); + return; + } + + // Create a unique modal ID (you can enhance this as needed) + var modalId = 'dynamicAjaxModal'; + + // Build the modal HTML using the returned title and content + var modalHtml = + ''; + + // Append the modal to the body and show it + $('body').append(modalHtml); + $('#' + modalId).modal('show'); + + // Remove the modal from the DOM once it's hidden + $('#' + modalId).on('hidden.bs.modal', function () { + $(this).remove(); + }); + }, + error: function () { + alert('Error loading modal content.'); + } + }); +}); \ No newline at end of file diff --git a/includes/footer.php b/includes/footer.php index b85eb7fc..f582a82a 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -39,7 +39,9 @@ if (str_contains(basename($_SERVER["PHP_SELF"]), "admin_")) { ?> + +