From a064d26c1013bf1ecbaaae1f86ac7f01ddf11e23 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 1 Jun 2024 15:24:30 -0400 Subject: [PATCH] Fix Creating Document from a template where is would not set the document_parent causing new documents to display revisions that dont exist --- client_document_add_from_template_modal.php | 2 +- post/document.php | 51 +++++++++++---------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/client_document_add_from_template_modal.php b/client_document_add_from_template_modal.php index 26ca894c..ceb7a5f9 100644 --- a/client_document_add_from_template_modal.php +++ b/client_document_add_from_template_modal.php @@ -83,7 +83,7 @@ diff --git a/post/document.php b/post/document.php index 9cdc9f6e..728b290c 100644 --- a/post/document.php +++ b/post/document.php @@ -33,30 +33,6 @@ if (isset($_POST['add_document'])) { } -if (isset($_POST['add_document_template'])) { - - validateTechRole(); - - $client_id = intval($_POST['client_id']); - $name = sanitizeInput($_POST['name']); - $description = sanitizeInput($_POST['description']); - $content = mysqli_real_escape_string($mysqli,$_POST['content']); - $content_raw = sanitizeInput($_POST['name'] . " " . str_replace("<", " <", $_POST['content'])); - // Content Raw is used for FULL INDEX searching. Adding a space before HTML tags to allow spaces between newlines, bulletpoints, etc. for searching. - - // Document add query - $add_document = mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$name', document_description = '$description', document_content = '$content', document_content_raw = '$content_raw', document_template = 1, document_folder_id = 0, document_created_by = $session_user_id, document_client_id = 0"); - $document_id = mysqli_insert_id($mysqli); - - // Logging - mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document Template', log_action = 'Create', log_description = '$session_name created document template $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $document_id"); - - $_SESSION['alert_message'] = "Document template $name created"; - - header("Location: " . $_SERVER["HTTP_REFERER"]); - -} - if (isset($_POST['add_document_from_template'])) { // ROLE Check @@ -83,6 +59,9 @@ if (isset($_POST['add_document_from_template'])) { $document_id = mysqli_insert_id($mysqli); + // Update field document_parent to be the same id as document ID as this is the only version of the document. + mysqli_query($mysqli,"UPDATE documents SET document_parent = $document_id WHERE document_id = $document_id"); + // Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document', log_action = 'Create', log_description = 'Document $document_name created from template $document_template_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $document_id"); @@ -92,6 +71,30 @@ if (isset($_POST['add_document_from_template'])) { } +if (isset($_POST['add_document_template'])) { + + validateTechRole(); + + $client_id = intval($_POST['client_id']); + $name = sanitizeInput($_POST['name']); + $description = sanitizeInput($_POST['description']); + $content = mysqli_real_escape_string($mysqli,$_POST['content']); + $content_raw = sanitizeInput($_POST['name'] . " " . str_replace("<", " <", $_POST['content'])); + // Content Raw is used for FULL INDEX searching. Adding a space before HTML tags to allow spaces between newlines, bulletpoints, etc. for searching. + + // Document add query + $add_document = mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$name', document_description = '$description', document_content = '$content', document_content_raw = '$content_raw', document_template = 1, document_folder_id = 0, document_created_by = $session_user_id, document_client_id = 0"); + $document_id = mysqli_insert_id($mysqli); + + // Logging + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document Template', log_action = 'Create', log_description = '$session_name created document template $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $document_id"); + + $_SESSION['alert_message'] = "Document template $name created"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + if (isset($_POST['edit_document'])) { validateTechRole();