Skip to content

Commit

Permalink
You can now link files to documents
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyq committed Sep 20, 2023
1 parent ca82a56 commit 150defe
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
33 changes: 33 additions & 0 deletions client_document_details.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,39 @@
<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>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">
<i class="fas fa-fw fa-plus"></i>
</button>
</h6>
<ul>
<?php
$sql_files = mysqli_query($mysqli, "SELECT * FROM files, document_files
WHERE document_files.file_id = files.file_id
AND document_files.document_id = $document_id
ORDER BY file_name ASC"
);

$linked_files = array();

while ($row = mysqli_fetch_array($sql_files)) {
$file_id = intval($row['file_id']);
$file_name = nullable_htmlentities($row['file_name']);

$linked_files[] = $file_id;

?>
<li>
<?php echo $file_name; ?>
<a href="post.php?unlink_file_from_document&file_id=<?php echo $file_id; ?>&document_id=<?php echo $document_id; ?>">
<i class="fas fa-fw fa-times text-secondary ml-2"></i>
</a>
</li>
<?php
}
?>
</ul>
<h6>
<i class="fas fa-fw fa-users text-secondary mr-2"></i>Contacts
<button type="button" class="btn btn-link btn-sm" data-toggle="modal" data-target="#linkContactToDocumentModal">
Expand Down
12 changes: 10 additions & 2 deletions database_updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -1323,11 +1323,19 @@
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.1'");
}

//if (CURRENT_DATABASE_VERSION == '0.8.1') {
if (CURRENT_DATABASE_VERSION == '0.8.1') {
//Insert queries here required to update to DB version 0.8.2
mysqli_query($mysqli, "CREATE TABLE `document_files` (`document_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`document_id`,`file_id`))");

// Then, update the database to the next sequential version
//mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.2'");
mysqli_query($mysqli, "UPDATE `settings` SET `config_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

// Then, update the database to the next sequential version
//mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.3'");
//}

} else {
Expand Down
2 changes: 1 addition & 1 deletion database_version.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* It is used in conjunction with database_updates.php
*/

DEFINE("LATEST_DATABASE_VERSION", "0.8.1");
DEFINE("LATEST_DATABASE_VERSION", "0.8.2");
37 changes: 37 additions & 0 deletions post/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,43 @@

}

if (isset($_POST['link_file_to_document'])) {

validateTechRole();

$client_id = intval($_POST['client_id']);
$document_id = intval($_POST['document_id']);
$file_id = intval($_POST['file_id']);

// Document add query
mysqli_query($mysqli,"INSERT INTO document_files SET file_id = $file_id, document_id = $document_id");

// Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document', log_action = 'Link', log_description = 'Created Document File link', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id");

$_SESSION['alert_message'] = "File linked with Document";

header("Location: " . $_SERVER["HTTP_REFERER"]);

}

if (isset($_GET['unlink_file_from_document'])) {

validateTechRole();
$file_id = intval($_GET['file_id']);
$document_id = intval($_GET['document_id']);

mysqli_query($mysqli,"DELETE FROM document_files WHERE file_id = $file_id AND document_id = $document_id");

//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Document', log_action = 'unLink', log_description = 'Document File link removed', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");

$_SESSION['alert_message'] = "File has been unlinked";

header("Location: " . $_SERVER["HTTP_REFERER"]);

}

if (isset($_POST['link_vendor_to_document'])) {

validateTechRole();
Expand Down

0 comments on commit 150defe

Please sign in to comment.