Feature: Document Versioning is here!
This commit is contained in:
@@ -24,6 +24,8 @@ $document_content = $purifier->purify($row['document_content']);
|
||||
$document_created_at = nullable_htmlentities($row['document_created_at']);
|
||||
$document_updated_at = nullable_htmlentities($row['document_updated_at']);
|
||||
$document_folder_id = intval($row['document_folder_id']);
|
||||
$document_parent = intval($row['document_parent']);
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -59,8 +61,7 @@ $document_folder_id = intval($row['document_folder_id']);
|
||||
</button>
|
||||
<button type="button" class="btn btn-secondary btn-block" onclick="window.print();"><i class="fas fa-fw fa-print mr-2"></i>Print</button>
|
||||
<hr>
|
||||
<h5 class="mb-0">Related</h5>
|
||||
<hr>
|
||||
<h5 class="mb-3">Related</h5>
|
||||
<h6>
|
||||
<i class="fas fa-fw fa-paperclip text-secondary mr-2"></i>Files
|
||||
<button type="button" class="btn btn-link btn-sm" data-toggle="modal" data-target="#linkFileToDocumentModal">
|
||||
@@ -230,6 +231,37 @@ $document_folder_id = intval($row['document_folder_id']);
|
||||
|
||||
<div class="card card-body bg-light">
|
||||
<h6><i class="fas fa-history mr-2"></i>Revisions</h6>
|
||||
<?php
|
||||
if($document_parent == 0){
|
||||
|
||||
$sql_document_revisions = mysqli_query($mysqli, "SELECT * FROM documents
|
||||
WHERE document_parent = $document_id
|
||||
OR document_id = $document_id
|
||||
ORDER BY document_created_at DESC"
|
||||
);
|
||||
} else {
|
||||
$sql_document_revisions = mysqli_query($mysqli, "SELECT * FROM documents
|
||||
WHERE document_parent = $document_parent
|
||||
OR document_id = $document_parent
|
||||
ORDER BY document_created_at DESC"
|
||||
);
|
||||
}
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_document_revisions)) {
|
||||
$revision_document_id = intval($row['document_id']);
|
||||
$revision_document_name = nullable_htmlentities($row['document_name']);
|
||||
$revision_document_archived_date = nullable_htmlentities($row['document_archived_at']);
|
||||
|
||||
?>
|
||||
<div class="mt-1 <?php if($document_id == $revision_document_id){ echo "text-bold"; } ?>">
|
||||
<i class="fas fa-fw fa-clock text-secondary mr-2"></i><a href="?client_id=<?php echo $client_id; ?>&document_id=<?php echo $revision_document_id; ?>"><?php echo "$revision_document_archived_date - $revision_document_name"; ?></a>
|
||||
<a href="post.php?delete_document=<?php echo $revision_document_id; ?>">
|
||||
<i class="fas fa-fw fa-times text-danger ml-2"></i>
|
||||
</a>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="document_id" value="<?php echo $document_id; ?>">
|
||||
<input type="hidden" name="document_id" value="<?php if($document_parent == 0){ echo $document_id; } else { echo $document_parent; } ?>">
|
||||
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
||||
<div class="modal-body bg-white">
|
||||
|
||||
|
||||
@@ -1331,11 +1331,19 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.2'");
|
||||
}
|
||||
|
||||
//if (CURRENT_DATABASE_VERSION == '0.8.2') {
|
||||
if (CURRENT_DATABASE_VERSION == '0.8.2') {
|
||||
//Insert queries here required to update to DB version 0.8.3
|
||||
mysqli_query($mysqli, "ALTER TABLE `documents` ADD `document_parent` INT(11) NOT NULL DEFAULT 0 AFTER `document_content_raw`");
|
||||
|
||||
// Then, update the database to the next sequential version
|
||||
//mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.3'");
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.3'");
|
||||
}
|
||||
|
||||
//if (CURRENT_DATABASE_VERSION == '0.8.3') {
|
||||
//Insert queries here required to update to DB version 0.8.4
|
||||
|
||||
// Then, update the database to the next sequential version
|
||||
//mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.4'");
|
||||
//}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
* It is used in conjunction with database_updates.php
|
||||
*/
|
||||
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.8.2");
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.8.3");
|
||||
|
||||
17
db.sql
17
db.sql
@@ -426,6 +426,20 @@ CREATE TABLE `custom_values` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `document_files`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `document_files`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `document_files` (
|
||||
`document_id` int(11) NOT NULL,
|
||||
`file_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`document_id`,`file_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `documents`
|
||||
--
|
||||
@@ -438,6 +452,7 @@ CREATE TABLE `documents` (
|
||||
`document_name` varchar(200) NOT NULL,
|
||||
`document_content` longtext NOT NULL,
|
||||
`document_content_raw` longtext NOT NULL,
|
||||
`document_parent` int(11) NOT NULL DEFAULT 0,
|
||||
`document_created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`document_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
|
||||
`document_archived_at` datetime DEFAULT NULL,
|
||||
@@ -1700,4 +1715,4 @@ CREATE TABLE `vendors` (
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2023-09-17 17:15:39
|
||||
-- Dump completed on 2023-09-23 15:54:04
|
||||
|
||||
@@ -98,17 +98,29 @@ if (isset($_POST['edit_document'])) {
|
||||
// Content Raw is used for FULL INDEX searching. Adding a space before HTML tags to allow spaces between newlines, bulletpoints, etc. for searching.
|
||||
$folder = intval($_POST['folder']);
|
||||
|
||||
// Document add query
|
||||
mysqli_query($mysqli,"INSERT INTO documents SET document_name = '$name', document_content = '$content', document_content_raw = '$content_raw', document_template = 0, document_folder_id = $folder, document_client_id = $client_id");
|
||||
|
||||
$new_document_id = mysqli_insert_id($mysqli);
|
||||
|
||||
// Document edit query
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_name = '$name', document_content = '$content', document_content_raw = '$content_raw', document_folder_id = $folder WHERE document_id = $document_id");
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_parent = $new_document_id, document_archived_at = NOW() WHERE document_id = $document_id");
|
||||
|
||||
// Update all Previous versions with the new parent document ID
|
||||
$sql_documents = mysqli_query($mysqli, "SELECT * FROM documents WHERE document_parent = $document_id");
|
||||
|
||||
while ($row = mysqli_fetch_array($sql_documents)) {
|
||||
$old_document_id = intval($row['document_id']);
|
||||
mysqli_query($mysqli,"UPDATE documents SET document_parent = $new_document_id WHERE document_id = $old_document_id");
|
||||
}
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document', log_action = 'Modify', log_description = '$session_name updated document $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");
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document', log_action = 'Edit', log_description = '$session_name Edited document $name previous version was kept', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $new_document_id");
|
||||
|
||||
|
||||
$_SESSION['alert_message'] = "Document <strong>$name</strong> updated";
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
$_SESSION['alert_message'] = "Document <strong>$name</strong> updated, previous version kept";
|
||||
|
||||
header("Location: client_document_details.php?client_id=$client_id&document_id=$new_document_id");
|
||||
}
|
||||
|
||||
if (isset($_POST['move_document'])) {
|
||||
|
||||
Reference in New Issue
Block a user