diff --git a/README.md b/README.md
index d7271c9a..9c68f846 100644
--- a/README.md
+++ b/README.md
@@ -88,7 +88,7 @@ ITFlow is self-hosted. There is a full installation guide in the [docs](https://
1. Install a LAMP stack (Linux, Apache, MariaDB, PHP)
```sh
- sudo apt install git apache2 php libapache2-mod-php php-intl php-mysqli php-curl mariadb-server
+ sudo apt install git apache2 php libapache2-mod-php php-intl php-imap php-mysqli php-curl mariadb-server
```
2. Clone the repo
```sh
diff --git a/check_login.php b/check_login.php
index 6953d002..557ca399 100644
--- a/check_login.php
+++ b/check_login.php
@@ -16,9 +16,10 @@ if (!isset($config_enable_setup) || $config_enable_setup == 1) {
exit;
}
-if (!$_SESSION['logged']) {
+// Check user is logged in with a valid session
+if (!isset($_SESSION['logged']) || !$_SESSION['logged']) {
header("Location: login.php");
- die;
+ exit;
}
// SESSION FINGERPRINT
diff --git a/client_overview.php b/client_overview.php
index 422a34be..350f62ec 100644
--- a/client_overview.php
+++ b/client_overview.php
@@ -31,9 +31,9 @@ $sql_domains_expiring = mysqli_query($mysqli,"SELECT * FROM domains
-
+
-
+
Quick Notes
diff --git a/client_software.php b/client_software.php
index 5d21b28a..c4aa8feb 100644
--- a/client_software.php
+++ b/client_software.php
@@ -13,7 +13,8 @@ $url_query_strings_sb = http_build_query(array_merge($_GET,array('sb' => $sb, 'o
$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM software
LEFT JOIN logins ON login_software_id = software_id
- WHERE software_client_id = $client_id
+ WHERE software_client_id = $client_id
+ AND software_template = 0
AND (software_name LIKE '%$q%' OR software_type LIKE '%$q%' OR software_key LIKE '%$q%')
ORDER BY $sb $o LIMIT $record_from, $record_to");
@@ -24,8 +25,20 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
+
\ No newline at end of file
diff --git a/client_software_add_from_template_modal.php b/client_software_add_from_template_modal.php
new file mode 100644
index 00000000..3b144df8
--- /dev/null
+++ b/client_software_add_from_template_modal.php
@@ -0,0 +1,49 @@
+
+
+
+
+
New License from Template
+
+
+
+
+
+
\ No newline at end of file
diff --git a/client_software_template_add_modal.php b/client_software_template_add_modal.php
new file mode 100644
index 00000000..97c27f25
--- /dev/null
+++ b/client_software_template_add_modal.php
@@ -0,0 +1,74 @@
+
+
+
+
+
New License Template
+
+
+
+
+
+
\ No newline at end of file
diff --git a/client_software_template_edit_modal.php b/client_software_template_edit_modal.php
new file mode 100644
index 00000000..b7482019
--- /dev/null
+++ b/client_software_template_edit_modal.php
@@ -0,0 +1,73 @@
+
+
+
+
+
Editing template:
+
+
+
+
+
+
\ No newline at end of file
diff --git a/client_software_templates.php b/client_software_templates.php
new file mode 100644
index 00000000..b99e6150
--- /dev/null
+++ b/client_software_templates.php
@@ -0,0 +1,119 @@
+
+
+ $sb, 'o' => $o)));
+
+$sql = mysqli_query($mysqli,"SELECT SQL_CALC_FOUND_ROWS * FROM software
+ LEFT JOIN logins ON login_software_id = software_id
+ WHERE software_template = 1
+ AND (software_name LIKE '%$q%' OR software_type LIKE '%$q%' OR software_key LIKE '%$q%')
+ ORDER BY $sb $o LIMIT $record_from, $record_to");
+
+$num_rows = mysqli_fetch_row(mysqli_query($mysqli,"SELECT FOUND_ROWS()"));
+
+?>
+
+
Ticket: $ticket_prefix$ticket_number Subject: $ticket_subject Status: Open Portal: https://$config_base_url/portal/ticket.php?id=$id
~ $company_name Support Department $config_ticket_from_email $company_phone";
+
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_ticket_from_email, $config_ticket_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
+
+ if ($mail !== true) {
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', notification_timestamp = NOW(), company_id = $company_id");
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $company_id");
+ }
+
+ }
+ }
+
+ // Set the next run date
+ if($frequency == "weekly"){
+ // Note: We seemingly have to initialize a new datetime for each loop to avoid stacking the dates
+ $now = new DateTime();
+ $next_run = date_add($now, date_interval_create_from_date_string('1 week'));
+ }
+ elseif($frequency == "monthly"){
+ $now = new DateTime();
+ $next_run = date_add($now, date_interval_create_from_date_string('1 month'));
+ }
+ elseif($frequency == "quarterly"){
+ $now = new DateTime();
+ $next_run = date_add($now, date_interval_create_from_date_string('3 months'));
+ }
+ elseif($frequency == "biannually"){
+ $now = new DateTime();
+ $next_run = date_add($now, date_interval_create_from_date_string('6 months'));
+ }
+ elseif($frequency == "annually"){
+ $now = new DateTime();
+ $next_run = date_add($now, date_interval_create_from_date_string('12 months'));
+ }
+
+ // Update the run date
+ $next_run = $next_run->format('Y-m-d');
+ $a = mysqli_query($mysqli, "UPDATE scheduled_tickets SET scheduled_ticket_next_run = '$next_run' WHERE scheduled_ticket_id = '$schedule_id'");
+
+ }
+ }
+
+ // Clean-up ticket views table used for collision detection
+ mysqli_query($mysqli, "TRUNCATE TABLE ticket_views");
+
+ // Clean-up shared items that have been used
+ mysqli_query($mysqli, "DELETE FROM shared_items WHERE item_views = item_view_limit");
+
+ // Clean-up shared items that have expired
+ mysqli_query($mysqli, "DELETE FROM shared_items WHERE item_expire_at < NOW()");
+
+ // Invalidate any password reset links
+ mysqli_query($mysqli, "UPDATE contacts SET contact_password_reset_token = NULL WHERE contact_archived_at IS NULL");
+
+ // PAST DUE INVOICE Notifications
+ //$invoiceAlertArray = [$config_invoice_overdue_reminders];
+ $invoiceAlertArray = [30,60,90,120,150,180,210,240,270,300,330,360,390,420,450,480,510,540,570,590,620];
+
+ foreach($invoiceAlertArray as $day){
+
+ $sql = mysqli_query($mysqli,"SELECT * FROM invoices
LEFT JOIN clients ON invoice_client_id = client_id
LEFT JOIN contacts ON contact_id = primary_contact
WHERE invoice_status NOT LIKE 'Draft'
@@ -212,160 +252,160 @@ while ($row = mysqli_fetch_array($sql_companies)) {
AND DATE_ADD(invoice_due, INTERVAL $day DAY) = CURDATE()
AND invoices.company_id = $company_id
ORDER BY invoice_number DESC"
- );
+ );
- while ($row = mysqli_fetch_array($sql)) {
- $invoice_id = $row['invoice_id'];
- $invoice_prefix = $row['invoice_prefix'];
- $invoice_number = $row['invoice_number'];
- $invoice_status = $row['invoice_status'];
- $invoice_date = $row['invoice_date'];
- $invoice_due = $row['invoice_due'];
- $invoice_url_key = $row['invoice_url_key'];
- $invoice_amount = $row['invoice_amount'];
- $invoice_currency_code = $row['invoice_currency_code'];
- $client_id = $row['client_id'];
- $client_name = mysqli_real_escape_string($mysqli,$row['client_name']);
- $contact_name = $row['contact_name'];
- $contact_email = $row['contact_email'];
+ while($row = mysqli_fetch_array($sql)){
+ $invoice_id = $row['invoice_id'];
+ $invoice_prefix = $row['invoice_prefix'];
+ $invoice_number = $row['invoice_number'];
+ $invoice_status = $row['invoice_status'];
+ $invoice_date = $row['invoice_date'];
+ $invoice_due = $row['invoice_due'];
+ $invoice_url_key = $row['invoice_url_key'];
+ $invoice_amount = $row['invoice_amount'];
+ $invoice_currency_code = $row['invoice_currency_code'];
+ $client_id = $row['client_id'];
+ $client_name = mysqli_real_escape_string($mysqli,$row['client_name']);
+ $contact_name = $row['contact_name'];
+ $contact_email = $row['contact_email'];
- mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Invoice Overdue', notification = 'Invoice $invoice_prefix$invoice_number for $client_name in the amount of $invoice_amount is overdue by $day days', notification_timestamp = NOW(), notification_client_id = $client_id, company_id = $company_id");
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Invoice Overdue', notification = 'Invoice $invoice_prefix$invoice_number for $client_name in the amount of $invoice_amount is overdue by $day days', notification_timestamp = NOW(), notification_client_id = $client_id, company_id = $company_id");
- $subject = "Overdue Invoice $invoice_prefix$invoice_number";
- $body = "Hello $contact_name,
According to our records, we have not received payment for invoice $invoice_prefix$invoice_number. Please submit your payment as soon as possible. If you have any questions please contact us at $company_phone.
+ $subject = "Overdue Invoice $invoice_prefix$invoice_number";
+ $body = "Hello $contact_name,
According to our records, we have not received payment for invoice $invoice_prefix$invoice_number. Please submit your payment as soon as possible. If you have any questions please contact us at $company_phone.
~ $company_name Billing Department $config_invoice_from_email $company_phone";
- $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
- $config_invoice_from_email, $config_invoice_from_name,
- $contact_email, $contact_name,
- $subject, $body);
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_invoice_from_email, $config_invoice_from_name,
+ $contact_email, $contact_name,
+ $subject, $body);
- if ($mail === true) {
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Invoice!', history_created_at = NOW(), history_invoice_id = $new_invoice_id, company_id = $company_id");
- mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', invoice_updated_at = NOW(), invoice_client_id = $client_id WHERE invoice_id = $new_invoice_id");
+ if ($mail === true) {
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Sent', history_description = 'Cron Emailed Invoice!', history_created_at = NOW(), history_invoice_id = $new_invoice_id, company_id = $company_id");
+ mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', invoice_updated_at = NOW(), invoice_client_id = $client_id WHERE invoice_id = $new_invoice_id");
- } else {
- mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Draft', history_description = 'Cron Failed to send Invoice!', history_created_at = NOW(), history_invoice_id = $new_invoice_id, company_id = $company_id");
+ } else {
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = 'Draft', history_description = 'Cron Failed to send Invoice!', history_created_at = NOW(), history_invoice_id = $new_invoice_id, company_id = $company_id");
- mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', notification_timestamp = NOW(), company_id = $company_id");
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $company_id");
- }
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', notification_timestamp = NOW(), company_id = $company_id");
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $company_id");
+ }
- } //End if Autosend is on
- } //End Recurring Invoices Loop
- //Send Alert to inform Cron was run
- mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Cron', notification = 'Cron.php successfully executed', notification_timestamp = NOW(), company_id = $company_id");
- //Logging
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Cron', log_action = 'Ended', log_description = 'Cron executed successfully for $company_name', company_id = $company_id");
- } //End Cron Check
+ } //End if Autosend is on
+ } //End Recurring Invoices Loop
+ //Send Alert to inform Cron was run
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Cron', notification = 'Cron.php successfully executed', notification_timestamp = NOW(), company_id = $company_id");
+ //Logging
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Cron', log_action = 'Ended', log_description = 'Cron executed successfully for $company_name', company_id = $company_id");
+ } //End Cron Check
} //End Company Loop through
-?>
+?>
\ No newline at end of file
diff --git a/cron_ticket_email_parser.php b/cron_ticket_email_parser.php
index bdde8a1f..d0b6121b 100644
--- a/cron_ticket_email_parser.php
+++ b/cron_ticket_email_parser.php
@@ -27,13 +27,13 @@ include_once("get_settings.php");
// Check setting enabled
if ($config_ticket_email_parse == 0) {
- exit("Feature is not enabled - see Settings > Ticketing > Email-to-ticket parsing");
+ exit("Feature is not enabled - see Settings > Ticketing > Email-to-ticket parsing");
}
// Check IMAP function exists
if (!function_exists('imap_open')) {
- echo "PHP IMAP extension is not installed, quitting..";
- exit();
+ echo "PHP IMAP extension is not installed, quitting..";
+ exit();
}
// Prepare connection string with encryption (TLS/SSL/)
@@ -44,11 +44,11 @@ $imap = imap_open("{{$imap_mailbox}}INBOX", $config_smtp_username, $config_smtp_
// Check connection
if (!$imap) {
- // Logging
- $extended_log_description = var_export(imap_errors(), true);
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to connect to IMAP: $extended_log_description', company_id = $session_company_id");
+ // Logging
+ $extended_log_description = var_export(imap_errors(), true);
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to connect to IMAP: $extended_log_description', company_id = $session_company_id");
- exit("Could not connect to IMAP");
+ exit("Could not connect to IMAP");
}
// Search for unread (UNSEEN) emails
@@ -56,149 +56,151 @@ $emails = imap_search($imap,'UNSEEN');
if ($emails) {
- // Sort
- rsort($emails);
+ // Sort
+ rsort($emails);
- // Loop through each email
- foreach($emails as $email) {
+ // Loop through each email
+ foreach($emails as $email) {
- // Get message details
- $metadata = imap_fetch_overview($imap, $email); // Date, Subject, Size
- $header = imap_headerinfo($imap, $email); // To get the From as an email, not a contact name
- $message = imap_fetchbody($imap, $email, 1); // Body
+ // Get message details
+ $metadata = imap_fetch_overview($imap, $email,0); // Date, Subject, Size
+ $header = imap_headerinfo($imap, $email); // To get the From as an email, not a contact name
+ $message = imap_fetchbody($imap, $email, 1); // Body
- $from = trim(mysqli_real_escape_string($mysqli, htmlentities(strip_tags($header->from[0]->mailbox . "@" . $header->from[0]->host))));
- $subject = trim(mysqli_real_escape_string($mysqli, htmlentities(strip_tags($metadata[0]->subject))));
- $date = trim(mysqli_real_escape_string($mysqli, htmlentities(strip_tags($metadata[0]->date))));
+ $from = trim(mysqli_real_escape_string($mysqli, htmlentities(strip_tags($header->from[0]->mailbox . "@" . $header->from[0]->host))));
+ $subject = trim(mysqli_real_escape_string($mysqli, htmlentities(strip_tags($metadata[0]->subject))));
+ $date = trim(mysqli_real_escape_string($mysqli, htmlentities(strip_tags($metadata[0]->date))));
- // Check if we can identify a ticket number (in square brackets)
- if (preg_match("/\[$config_ticket_prefix\d+\]/", $subject, $ticket_number)) {
+ // Check if we can identify a ticket number (in square brackets)
+ if (preg_match("/\[$config_ticket_prefix\d+\]/", $subject, $ticket_number)) {
- // Get the actual ticket number (without the brackets)
- preg_match('/\d+/', $ticket_number[0], $ticket_number);
- $ticket_number = intval($ticket_number[0]);
+ // Get the actual ticket number (without the brackets)
+ preg_match('/\d+/', $ticket_number[0], $ticket_number);
+ $ticket_number = intval($ticket_number[0]);
- // Split the email into just the latest reply, with some metadata
- // We base this off the string "#--itflow--#" that we prepend the outgoing emails with (similar to the old school --reply above this line--)
- $message = explode("#--itflow--#", $message);
- $message = nl2br(htmlentities(strip_tags($message[0])));
- $message = "Email from: $from at $date:-
$message";
+ // Split the email into just the latest reply, with some metadata
+ // We base this off the string "#--itflow--#" that we prepend the outgoing emails with (similar to the old school --reply above this line--)
+ $message = explode("#--itflow--#", $message);
+ $message = nl2br(htmlentities(strip_tags($message[0])));
+ $message = "Email from: $from at $date:-
$message";
- // Lookup the ticket ID to add the reply to (just to check in-case the ID is different from the number).
- $ticket_sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_number = '$ticket_number' LIMIT 1");
- $row = mysqli_fetch_array($ticket_sql);
- $ticket_id = $row['ticket_id'];
- $ticket_reply_contact = $row['ticket_contact_id'];
- $ticket_assigned_to = $row['ticket_assigned_to'];
- $client_id = $row['ticket_client_id'];
- $session_company_id = $row['company_id'];
- $ticket_reply_type = 'Client'; // Setting to client as a default value
+ // Lookup the ticket ID to add the reply to (just to check in-case the ID is different from the number).
+ $ticket_sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_number = '$ticket_number' LIMIT 1");
+ $row = mysqli_fetch_array($ticket_sql);
+ $ticket_id = $row['ticket_id'];
+ $ticket_reply_contact = $row['ticket_contact_id'];
+ $ticket_assigned_to = $row['ticket_assigned_to'];
+ $client_id = $row['ticket_client_id'];
+ $session_company_id = $row['company_id'];
+ $ticket_reply_type = 'Client'; // Setting to client as a default value
- // Check the ticket ID is valid
- if (intval($ticket_id) && $ticket_id !== '0') {
+ // Check the ticket ID is valid
+ if (intval($ticket_id) && $ticket_id !== '0') {
- // Check that ticket is open
- if ($row['ticket_status'] == "Closed") {
+ // Check that ticket is open
+ if ($row['ticket_status'] == "Closed") {
+
+ // It's closed - let's notify someone that a client tried to reply
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Ticket', notification = '$from attempted to re-open ticket ID $ticket_id ($config_ticket_prefix$ticket_number) - check inbox manually to see email', notification_timestamp = NOW(), notification_client_id = '$client_id', company_id = '$session_company_id'");
+
+ } else {
+
+ // Ticket is open, proceed.
+
+ // Check the email matches the contact's email - if it doesn't then mark the reply as internal (so the contact doesn't see it, and the tech can edit/delete if needed)
+ // Niche edge case - possibly where CC's on an email reply to a ticket?
+ $contact_sql = mysqli_query($mysqli, "SELECT contact_email FROM contacts WHERE contact_id = '$ticket_reply_contact'");
+ $row = mysqli_fetch_array($contact_sql);
+ if ($from !== $row['contact_email']) {
+ $ticket_reply_type = 'Internal';
+ $ticket_reply_contact = '0';
+ $message = "WARNING: Contact email mismatch $message"; // Add a warning at the start of the message - for the techs benefit (think phishing/scams)
+ }
+
+ // Sanitize ticket reply
+ $comment = trim(mysqli_real_escape_string($mysqli,$message));
+
+ // Add the comment
+ mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$message', ticket_reply_type = '$ticket_reply_type', ticket_reply_time_worked = '00:00:00', ticket_reply_created_at = NOW(), ticket_reply_by = '$ticket_reply_contact', ticket_reply_ticket_id = '$ticket_id', company_id = '$session_company_id'");
+
+ // Update Ticket Last Response Field & set ticket to open as client has replied
+ mysqli_query($mysqli,"UPDATE tickets SET ticket_status = 'Open', ticket_updated_at = NOW() WHERE ticket_id = $ticket_id AND ticket_client_id = '$client_id' LIMIT 1");
+
+ echo "Updated existing ticket. ";
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket', log_action = 'Update', log_description = 'Client contact $from updated ticket $subject via email', log_created_at = NOW(), log_client_id = $client_id, company_id = $session_company_id");
+ }
+
+ }
- // It's closed - let's notify someone that a client tried to reply
- mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Ticket', notification = '$from attempted to re-open ticket ID $ticket_id ($config_ticket_prefix$ticket_number) - check inbox manually to see email', notification_timestamp = NOW(), notification_client_id = '$client_id', company_id = '$session_company_id'");
} else {
+ // Couldn't match this email to an existing ticket
- // Ticket is open, proceed.
+ // Check if we can match the sender to a pre-existing contact
+ $any_contact_sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_email = '$from' LIMIT 1");
+ $row = mysqli_fetch_array($any_contact_sql);
- // Check the email matches the contact's email - if it doesn't then mark the reply as internal (so the contact doesn't see it, and the tech can edit/delete if needed)
- // Niche edge case - possibly where CC's on an email reply to a ticket?
- $contact_sql = mysqli_query($mysqli, "SELECT contact_email FROM contacts WHERE contact_id = '$ticket_reply_contact'");
- $row = mysqli_fetch_array($contact_sql);
- if ($from !== $row['contact_email']) {
- $ticket_reply_type = 'Internal';
- $ticket_reply_contact = '0';
- $message = "WARNING: Contact email mismatch $message"; // Add a warning at the start of the message - for the techs benefit (think phishing/scams)
- }
+ $contact_name = $row['contact_name'];
+ $contact_id = $row['contact_id'];
+ $contact_email = $row['contact_email'];
+ $client_id = $row['contact_client_id'];
+ $session_company_id = $row['company_id'];
- // Sanitize ticket reply
- $comment = trim(mysqli_real_escape_string($mysqli,$message));
+ if ($from == $contact_email) {
- // Add the comment
- mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = '$message', ticket_reply_type = '$ticket_reply_type', ticket_reply_time_worked = '00:00:00', ticket_reply_created_at = NOW(), ticket_reply_by = '$ticket_reply_contact', ticket_reply_ticket_id = '$ticket_id', company_id = '$session_company_id'");
+ // Prep ticket details
+ $message = nl2br(htmlentities(strip_tags($message)));
+ $message = trim(mysqli_real_escape_string($mysqli,"Email from: $from at $date:-
$message"));
- // Update Ticket Last Response Field & set ticket to open as client has replied
- mysqli_query($mysqli,"UPDATE tickets SET ticket_status = 'Open', ticket_updated_at = NOW() WHERE ticket_id = $ticket_id AND ticket_client_id = '$client_id' LIMIT 1");
+ // Get the next Ticket Number and add 1 for the new ticket number
+ $ticket_number = $config_ticket_next_number;
+ $new_config_ticket_next_number = $config_ticket_next_number + 1;
+ mysqli_query($mysqli,"UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = $session_company_id");
+
+ mysqli_query($mysqli,"INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$message', ticket_priority = 'Low', ticket_status = 'Open', ticket_created_at = NOW(), ticket_created_by = '0', ticket_contact_id = $contact_id, ticket_client_id = $client_id, company_id = $session_company_id");
+ $id = mysqli_insert_id($mysqli);
+
+ // Logging
+ echo "Created new ticket. ";
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'Client contact $from created ticket $subject via email', log_created_at = NOW(), log_client_id = $client_id, company_id = $session_company_id");
+
+ // Get company name & phone
+ $sql = mysqli_query($mysqli,"SELECT company_name, company_phone FROM companies WHERE company_id = $session_company_id");
+ $row = mysqli_fetch_array($sql);
+ $company_phone = formatPhoneNumber($row['company_phone']);
+ $session_company_name = $row['company_name'];
+
+
+ // E-mail client notification that ticket has been created
+ if ($config_ticket_client_general_notifications == 1) {
+
+ $email_subject = "Ticket created - [$config_ticket_prefix$ticket_number] - $subject";
+ $email_body = "#--itflow--#
Hello, $contact_name
Thank you for your email. A ticket regarding \"$subject\" has been automatically created for you.
Ticket: $config_ticket_prefix$ticket_number Subject: $subject Status: Open https://$config_base_url/portal/ticket.php?id=$id
~ $session_company_name Support Department $config_ticket_from_email $company_phone";
+
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_ticket_from_email, $config_ticket_from_name,
+ $contact_email, $contact_name,
+ $email_subject, $email_body);
+
+ if ($mail !== true) {
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', notification_timestamp = NOW(), company_id = $session_company_id");
+ mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $session_company_id");
+ }
+
+ }
+
+
+ } else {
+
+ // Couldn't match this against a specific client contact -- do nothing for now
+ // In the future, we'll try to match on client domain
+ // or even log this to an inbox in the ITFlow portal or something to allow a new contact/ticket to be created manually
+
+ }
- echo "Updated existing ticket. ";
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket', log_action = 'Update', log_description = 'Client contact $from updated ticket $subject via email', log_created_at = NOW(), log_client_id = $client_id, company_id = $session_company_id");
}
- }
-
-
- } else {
- // Couldn't match this email to an existing ticket
-
- // Check if we can match the sender to a pre-existing contact
- $any_contact_sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_email = '$from' LIMIT 1");
- $row = mysqli_fetch_array($any_contact_sql);
-
- $contact_name = $row['contact_name'];
- $contact_id = $row['contact_id'];
- $contact_email = $row['contact_email'];
- $client_id = $row['contact_client_id'];
- $session_company_id = $row['company_id'];
-
- if ($from == $contact_email) {
-
- // Prep ticket details
- $message = nl2br(htmlentities(strip_tags($message)));
- $message = trim(mysqli_real_escape_string($mysqli,"Email from: $from at $date:-
$message"));
-
- // Get the next Ticket Number and add 1 for the new ticket number
- $ticket_number = $config_ticket_next_number;
- $new_config_ticket_next_number = $config_ticket_next_number + 1;
- mysqli_query($mysqli,"UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = $session_company_id");
-
- mysqli_query($mysqli,"INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$message', ticket_priority = 'Low', ticket_status = 'Open', ticket_created_at = NOW(), ticket_created_by = '0', ticket_contact_id = $contact_id, ticket_client_id = $client_id, company_id = $session_company_id");
- $id = mysqli_insert_id($mysqli);
-
- // Logging
- echo "Created new ticket. ";
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket', log_action = 'Create', log_description = 'Client contact $from created ticket $subject via email', log_created_at = NOW(), log_client_id = $client_id, company_id = $session_company_id");
-
- // Get company name & phone
- $sql = mysqli_query($mysqli,"SELECT company_name, company_phone FROM companies WHERE company_id = $session_company_id");
- $row = mysqli_fetch_array($sql);
- $company_phone = formatPhoneNumber($row['company_phone']);
- $session_company_name = $row['company_name'];
-
-
- // E-mail client notification that ticket has been created
-
- $email_subject = "Ticket created - [$config_ticket_prefix$ticket_number] - $subject";
- $email_body = "#--itflow--#
Hello, $contact_name
Thank you for your email. A ticket regarding \"$subject\" has been automatically created for you.
Ticket: $config_ticket_prefix$ticket_number Subject: $subject Status: Open https://$config_base_url/portal/ticket.php?id=$id
~ $session_company_name Support Department $config_ticket_from_email $company_phone";
-
- $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
- $config_ticket_from_email, $config_ticket_from_name,
- $contact_email, $contact_name,
- $email_subject, $email_body);
-
- if ($mail !== true) {
- mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $contact_email', notification_timestamp = NOW(), company_id = $session_company_id");
- mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $contact_email regarding $subject. $mail', company_id = $session_company_id");
- }
-
-
-
- } else {
-
- // Couldn't match this against a specific client contact -- do nothing for now
- // In the future, we'll try to match on client domain
- // or even log this to an inbox in the ITFlow portal or something to allow a new contact/ticket to be created manually
-
- }
}
-
- }
-
}
diff --git a/database_updates.php b/database_updates.php
index 2b596dce..29b046f7 100644
--- a/database_updates.php
+++ b/database_updates.php
@@ -7,342 +7,342 @@
// Check if our database versions are defined
// If undefined, the file is probably being accessed directly rather than called via post.php?update_db
-if (!defined("LATEST_DATABASE_VERSION") || !defined("CURRENT_DATABASE_VERSION") || !isset($mysqli)) {
- echo "Cannot access this file directly.";
- exit();
+if(!defined("LATEST_DATABASE_VERSION") || !defined("CURRENT_DATABASE_VERSION") || !isset($mysqli)){
+ echo "Cannot access this file directly.";
+ exit();
}
// Check if we need an update
-if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
+if(LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION){
- // We need updates!
+ // We need updates!
- if (CURRENT_DATABASE_VERSION == '0.0.1') {
- // Insert queries here required to update to DB version 0.0.2
+ if(CURRENT_DATABASE_VERSION == '0.0.1'){
+ // Insert queries here required to update to DB version 0.0.2
- mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_module_enable_itdoc` TINYINT(1) DEFAULT 1 AFTER `config_backup_path`");
- mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_module_enable_ticketing` TINYINT(1) DEFAULT 1 AFTER `config_module_enable_itdoc`");
- mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_module_enable_accounting` TINYINT(1) DEFAULT 1 AFTER `config_module_enable_ticketing`");
+ mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_module_enable_itdoc` TINYINT(1) DEFAULT 1 AFTER `config_backup_path`");
+ mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_module_enable_ticketing` TINYINT(1) DEFAULT 1 AFTER `config_module_enable_itdoc`");
+ mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_module_enable_accounting` TINYINT(1) DEFAULT 1 AFTER `config_module_enable_ticketing`");
- // Update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.2'");
- }
-
- if (CURRENT_DATABASE_VERSION == '0.0.2') {
- // Insert queries here required to update to DB version 0.0.3
-
- // Add document content raw column & index
- mysqli_query($mysqli, "ALTER TABLE `documents` ADD `document_content_raw` LONGTEXT NOT NULL AFTER `document_content`, ADD FULLTEXT `document_content_raw` (`document_content_raw`)");
-
- // Populate content raw column with existing document data
- $documents_sql = mysqli_query($mysqli, "SELECT * FROM `documents`");
- while ($row = mysqli_fetch_array($documents_sql)) {
- $id = $row['document_id'];
- $name = $row['document_name'];
- $content = $row['document_content'];
- $content_raw = trim(mysqli_real_escape_string($mysqli, strip_tags($name . " " . str_replace("<", " <", $content))));
-
- mysqli_query($mysqli, "UPDATE `documents` SET `document_content_raw` = '$content_raw' WHERE `document_id` = '$id'");
+ // Update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.2'");
}
- // Add API key client column
- mysqli_query($mysqli, "ALTER TABLE `api_keys` ADD `api_key_client_id` INT NOT NULL DEFAULT '0' AFTER `api_key_expire`");
+ if(CURRENT_DATABASE_VERSION == '0.0.2'){
+ // Insert queries here required to update to DB version 0.0.3
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.3'");
- }
+ // Add document content raw column & index
+ mysqli_query($mysqli, "ALTER TABLE `documents` ADD `document_content_raw` LONGTEXT NOT NULL AFTER `document_content`, ADD FULLTEXT `document_content_raw` (`document_content_raw`)");
- if (CURRENT_DATABASE_VERSION == '0.0.3') {
- // Insert queries here required to update to DB version 0.0.4
- // mysqli_query($mysqli, "ALTER TABLE .....");
+ // Populate content raw column with existing document data
+ $documents_sql = mysqli_query($mysqli, "SELECT * FROM `documents`");
+ while($row = mysqli_fetch_array($documents_sql)){
+ $id = $row['document_id'];
+ $name = $row['document_name'];
+ $content = $row['document_content'];
+ $content_raw = trim(mysqli_real_escape_string($mysqli, strip_tags($name . " " . str_replace("<", " <", $content))));
- // Update all tables updated/modified fields to be automatic
+ mysqli_query($mysqli, "UPDATE `documents` SET `document_content_raw` = '$content_raw' WHERE `document_id` = '$id'");
+ }
- mysqli_query($mysqli, "ALTER TABLE `accounts` CHANGE `account_created_at` `account_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `account_updated_at` `account_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;");
+ // Add API key client column
+ mysqli_query($mysqli, "ALTER TABLE `api_keys` ADD `api_key_client_id` INT NOT NULL DEFAULT '0' AFTER `api_key_expire`");
- mysqli_query($mysqli, "ALTER TABLE `api_keys` CHANGE `api_key_created_at` `api_key_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
-
- mysqli_query($mysqli, "ALTER TABLE `assets` CHANGE `asset_created_at` `asset_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `asset_updated_at` `asset_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;");
-
- mysqli_query($mysqli, "ALTER TABLE `calendars` CHANGE `calendar_created_at` `calendar_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `calendar_updated_at` `calendar_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `campaigns` CHANGE `campaign_created_at` `campaign_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `campaign_updated_at` `campaign_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `campaign_messages` CHANGE `message_created_at` `message_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `message_updated_at` `message_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `categories` CHANGE `category_created_at` `category_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `category_updated_at` `category_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `certificates` CHANGE `certificate_created_at` `certificate_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `certificate_updated_at` `certificate_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `clients` CHANGE `client_created_at` `client_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `client_updated_at` `client_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `companies` CHANGE `company_created_at` `company_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `company_updated_at` `company_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `contacts` CHANGE `contact_created_at` `contact_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `contact_updated_at` `contact_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `contracts` CHANGE `contract_created_at` `contract_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `contract_updated_at` `contract_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `custom_links` CHANGE `custom_link_created_at` `custom_link_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
-
- mysqli_query($mysqli, "ALTER TABLE `departments` CHANGE `department_created_at` `department_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `department_updated_at` `department_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `documents` CHANGE `document_created_at` `document_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `document_updated_at` `document_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `domains` CHANGE `domain_created_at` `domain_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `domain_updated_at` `domain_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `events` CHANGE `event_created_at` `event_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `event_updated_at` `event_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `expenses` CHANGE `expense_created_at` `expense_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `expense_updated_at` `expense_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `files` CHANGE `file_created_at` `file_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `file_updated_at` `file_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;");
-
- mysqli_query($mysqli, "ALTER TABLE `history` CHANGE `history_created_at` `history_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
-
- mysqli_query($mysqli, "ALTER TABLE `invoices` CHANGE `invoice_created_at` `invoice_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `invoice_updated_at` `invoice_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `invoice_items` CHANGE `item_created_at` `item_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `item_updated_at` `item_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `locations` CHANGE `location_created_at` `location_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `location_updated_at` `location_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `logins` CHANGE `login_created_at` `login_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `login_updated_at` `login_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `logs` CHANGE `log_created_at` `log_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
-
- mysqli_query($mysqli, "ALTER TABLE `networks` CHANGE `network_created_at` `network_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `network_updated_at` `network_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `notifications` CHANGE `notification_timestamp` `notification_timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
-
- mysqli_query($mysqli, "ALTER TABLE `payments` CHANGE `payment_created_at` `payment_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `payment_updated_at` `payment_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `products` CHANGE `product_created_at` `product_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `product_updated_at` `product_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `quotes` CHANGE `quote_created_at` `quote_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `quote_updated_at` `quote_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `records` CHANGE `record_created_at` `record_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `record_updated_at` `record_updated_at` DATETIME on update CURRENT_TIMESTAMP NOT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `recurring` CHANGE `recurring_created_at` `recurring_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `recurring_updated_at` `recurring_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `scheduled_tickets` CHANGE `scheduled_ticket_created_at` `scheduled_ticket_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `scheduled_ticket_updated_at` `scheduled_ticket_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `services` CHANGE `service_created_at` `service_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `service_updated_at` `service_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `shared_items` CHANGE `item_created_at` `item_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
-
- mysqli_query($mysqli, "ALTER TABLE `software` CHANGE `software_created_at` `software_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `software_updated_at` `software_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `tags` CHANGE `tag_created_at` `tag_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `tag_updated_at` `tag_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `taxes` CHANGE `tax_created_at` `tax_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `tax_updated_at` `tax_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `tickets` CHANGE `ticket_created_at` `ticket_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `ticket_updated_at` `ticket_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `ticket_replies` CHANGE `ticket_reply_created_at` `ticket_reply_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `ticket_reply_updated_at` `ticket_reply_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `transfers` CHANGE `transfer_created_at` `transfer_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `transfer_updated_at` `transfer_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `trips` CHANGE `trip_created_at` `trip_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `trip_updated_at` `trip_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `users` CHANGE `user_created_at` `user_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `user_updated_at` `user_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- mysqli_query($mysqli, "ALTER TABLE `vendors` CHANGE `vendor_created_at` `vendor_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `vendor_updated_at` `vendor_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
-
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE settings SET config_current_database_version = '0.0.4'");
-
- }
-
- if (CURRENT_DATABASE_VERSION == '0.0.4') {
- // Queries here required to update to DB version 0.0.5
-
- mysqli_query($mysqli, "ALTER TABLE `assets` DROP `asset_meshcentral_id`;");
- mysqli_query($mysqli, "ALTER TABLE `clients` DROP `client_meshcentral_group`;");
- mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_meshcentral_uri`, DROP `config_meshcentral_user`, DROP `config_meshcentral_secret`;");
-
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.5'");
- }
-
- if (CURRENT_DATABASE_VERSION == '0.0.5') {
- // Insert queries here required to update to DB version 0.0.6
-
- mysqli_query($mysqli, "UPDATE documents SET document_folder_id = 0");
-
- mysqli_query($mysqli, "DROP TABLE documents_tagged");
- mysqli_query($mysqli, "DROP TABLE document_tags");
-
-
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE settings SET config_current_database_version = '0.0.6'");
- }
-
- if (CURRENT_DATABASE_VERSION == '0.0.6') {
- // Insert queries here required to update to DB version 0.0.7
- mysqli_query($mysqli, "ALTER TABLE contacts ADD contact_department VARCHAR(200) NULL AFTER contact_title");
- mysqli_query($mysqli, "DROP TABLE departments");
- mysqli_query($mysqli, "ALTER TABLE contacts DROP contact_department_id");
-
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.7'");
- }
-
- if (CURRENT_DATABASE_VERSION == '0.0.7') {
- // Insert queries here required to update to DB version 0.0.8
-
- // Add contact_department column to tables without it (fresh installs) - this will cause an error if it already exists so catch and discard it
- try{
- mysqli_query($mysqli, "ALTER TABLE contacts ADD contact_department VARCHAR(200) NULL AFTER contact_title");
- } catch(Exception $e) {
- // Nothing
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.3'");
}
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.8'");
- }
+ if(CURRENT_DATABASE_VERSION == '0.0.3'){
+ // Insert queries here required to update to DB version 0.0.4
+ // mysqli_query($mysqli, "ALTER TABLE .....");
- if (CURRENT_DATABASE_VERSION == '0.0.8') {
- // Insert queries here required to update to DB version 0.0.9
+ // Update all tables updated/modified fields to be automatic
- mysqli_query($mysqli, "ALTER TABLE `revenues` CHANGE `revenue_created_at` `revenue_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `revenue_updated_at` `revenue_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+ mysqli_query($mysqli, "ALTER TABLE `accounts` CHANGE `account_created_at` `account_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `account_updated_at` `account_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.9'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `api_keys` CHANGE `api_key_created_at` `api_key_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
- if (CURRENT_DATABASE_VERSION == '0.0.9') {
- // Insert queries here required to update to DB version 0.0.9
- // Remove unused tables
- mysqli_query($mysqli, "DROP TABLE contracts");
- mysqli_query($mysqli, "DROP TABLE messages");
- mysqli_query($mysqli, "DROP TABLE roles");
+ mysqli_query($mysqli, "ALTER TABLE `assets` CHANGE `asset_created_at` `asset_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `asset_updated_at` `asset_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;");
- //Remove updated at as API keys can only be added or revoked
- mysqli_query($mysqli, "ALTER TABLE `api_keys` DROP `api_key_updated_at`");
+ mysqli_query($mysqli, "ALTER TABLE `calendars` CHANGE `calendar_created_at` `calendar_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `calendar_updated_at` `calendar_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.0'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `campaigns` CHANGE `campaign_created_at` `campaign_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `campaign_updated_at` `campaign_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- if (CURRENT_DATABASE_VERSION == '0.1.0') {
- // Insert queries here required to update to DB version 0.1.1
- // Logs don't get archived
- mysqli_query($mysqli, "ALTER TABLE `logs` DROP `log_archived_at`");
+ mysqli_query($mysqli, "ALTER TABLE `campaign_messages` CHANGE `message_created_at` `message_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `message_updated_at` `message_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- // Assets will eventualy have file associatons which could include a receipt.
- mysqli_query($mysqli, "ALTER TABLE `assets` DROP `asset_reciept`");
+ mysqli_query($mysqli, "ALTER TABLE `categories` CHANGE `category_created_at` `category_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `category_updated_at` `category_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- mysqli_query($mysqli, "ALTER TABLE `campaign_messages` DROP `message_updated_at`");
- // This will be a seperate table eventually called contact_documents because contact can have several documents
- mysqli_query($mysqli, "ALTER TABLE `documents` DROP `document_contact_id`");
+ mysqli_query($mysqli, "ALTER TABLE `certificates` CHANGE `certificate_created_at` `certificate_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `certificate_updated_at` `certificate_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- mysqli_query($mysqli, "ALTER TABLE `expenses` DROP `expense_asset_id`");
- mysqli_query($mysqli, "ALTER TABLE `files` DROP `file_contact_id`");
- mysqli_query($mysqli, "ALTER TABLE `history` DROP `history_archived_at`");
+ mysqli_query($mysqli, "ALTER TABLE `clients` CHANGE `client_created_at` `client_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `client_updated_at` `client_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.1'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `companies` CHANGE `company_created_at` `company_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `company_updated_at` `company_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- if (CURRENT_DATABASE_VERSION == '0.1.1') {
- // Insert queries here required to update to DB version 0.1.2
- // Create Many-to-Many Relationship tables for Assets, Contacts, Software and Vendors
+ mysqli_query($mysqli, "ALTER TABLE `contacts` CHANGE `contact_created_at` `contact_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `contact_updated_at` `contact_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- mysqli_query($mysqli, "CREATE TABLE `asset_documents` (`asset_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`,`document_id`))");
- mysqli_query($mysqli, "CREATE TABLE `asset_logins` (`asset_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`,`login_id`))");
- mysqli_query($mysqli, "CREATE TABLE `asset_files` (`asset_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`,`file_id`))");
+ mysqli_query($mysqli, "ALTER TABLE `contracts` CHANGE `contract_created_at` `contract_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `contract_updated_at` `contract_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- mysqli_query($mysqli, "CREATE TABLE `contact_documents` (`contact_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`document_id`))");
- mysqli_query($mysqli, "CREATE TABLE `contact_logins` (`contact_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`login_id`))");
- mysqli_query($mysqli, "CREATE TABLE `contact_files` (`contact_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`file_id`))");
+ mysqli_query($mysqli, "ALTER TABLE `custom_links` CHANGE `custom_link_created_at` `custom_link_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
- mysqli_query($mysqli, "CREATE TABLE `software_documents` (`software_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`software_id`,`document_id`))");
- mysqli_query($mysqli, "CREATE TABLE `software_logins` (`software_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`software_id`,`login_id`))");
- mysqli_query($mysqli, "CREATE TABLE `software_files` (`software_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`software_id`,`file_id`))");
+ mysqli_query($mysqli, "ALTER TABLE `departments` CHANGE `department_created_at` `department_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `department_updated_at` `department_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- mysqli_query($mysqli, "CREATE TABLE `vendor_documents` (`vendor_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`,`document_id`))");
- mysqli_query($mysqli, "CREATE TABLE `vendor_logins` (`vendor_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`,`login_id`))");
- mysqli_query($mysqli, "CREATE TABLE `vendor_files` (`vendor_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`,`file_id`))");
+ mysqli_query($mysqli, "ALTER TABLE `documents` CHANGE `document_created_at` `document_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `document_updated_at` `document_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.2'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `domains` CHANGE `domain_created_at` `domain_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `domain_updated_at` `domain_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- if (CURRENT_DATABASE_VERSION == '0.1.2') {
- // Insert queries here required to update to DB version 0.1.3
- mysqli_query($mysqli, "ALTER TABLE `logs` ADD `log_entity_id` INT NOT NULL DEFAULT '0' AFTER `log_user_id`");
+ mysqli_query($mysqli, "ALTER TABLE `events` CHANGE `event_created_at` `event_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `event_updated_at` `event_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.3'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `expenses` CHANGE `expense_created_at` `expense_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `expense_updated_at` `expense_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- if (CURRENT_DATABASE_VERSION == '0.1.3') {
- // Insert queries here required to update to DB version 0.1.4
- mysqli_query($mysqli, "ALTER TABLE assets ADD asset_status VARCHAR(200) NULL AFTER asset_mac");
+ mysqli_query($mysqli, "ALTER TABLE `files` CHANGE `file_created_at` `file_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `file_updated_at` `file_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL;");
- ///Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.4'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `history` CHANGE `history_created_at` `history_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
- if (CURRENT_DATABASE_VERSION == '0.1.4') {
- // Insert queries here required to update to DB version 0.1.5
- mysqli_query($mysqli, "ALTER TABLE `domains` ADD `domain_txt` TEXT NULL DEFAULT NULL AFTER `domain_mail_servers`");
+ mysqli_query($mysqli, "ALTER TABLE `invoices` CHANGE `invoice_created_at` `invoice_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `invoice_updated_at` `invoice_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.5'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `invoice_items` CHANGE `item_created_at` `item_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `item_updated_at` `item_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- if (CURRENT_DATABASE_VERSION == '0.1.5') {
- // Insert queries here required to update to DB version 0.1.6
- // Remove Mailing List Tables
- mysqli_query($mysqli, "DROP TABLE campaigns");
- mysqli_query($mysqli, "DROP TABLE campaign_messages");
+ mysqli_query($mysqli, "ALTER TABLE `locations` CHANGE `location_created_at` `location_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `location_updated_at` `location_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.6'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `logins` CHANGE `login_created_at` `login_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `login_updated_at` `login_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- if (CURRENT_DATABASE_VERSION == '0.1.6') {
- // Insert queries here required to update to DB version 0.1.7
- //Remove custom links
- mysqli_query($mysqli, "DROP TABLE custom_links");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.7'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `logs` CHANGE `log_created_at` `log_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
- if (CURRENT_DATABASE_VERSION == '0.1.7') {
- // Insert queries here required to update to DB version 0.1.8
- mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_backup_enable`");
- mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_backup_path`");
+ mysqli_query($mysqli, "ALTER TABLE `networks` CHANGE `network_created_at` `network_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `network_updated_at` `network_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.8'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `notifications` CHANGE `notification_timestamp` `notification_timestamp` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
- if (CURRENT_DATABASE_VERSION == '0.1.8') {
- // Insert queries here required to update to DB version 0.1.9
- mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_base_url`");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.9'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `payments` CHANGE `payment_created_at` `payment_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `payment_updated_at` `payment_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- if (CURRENT_DATABASE_VERSION == '0.1.9') {
- // Insert queries here required to update to DB version 0.2.0
- // Allow contacts to reset their portal password
- mysqli_query($mysqli, "ALTER TABLE contacts ADD contact_password_reset_token VARCHAR(200) NULL DEFAULT NULL AFTER contact_password_hash");
+ mysqli_query($mysqli, "ALTER TABLE `products` CHANGE `product_created_at` `product_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `product_updated_at` `product_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.0'");
- }
+ mysqli_query($mysqli, "ALTER TABLE `quotes` CHANGE `quote_created_at` `quote_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `quote_updated_at` `quote_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
- if (CURRENT_DATABASE_VERSION == '0.2.0') {
- //Insert queries here required to update to DB version 0.2.1
+ mysqli_query($mysqli, "ALTER TABLE `records` CHANGE `record_created_at` `record_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `record_updated_at` `record_updated_at` DATETIME on update CURRENT_TIMESTAMP NOT NULL; ");
- mysqli_query($mysqli, "ALTER TABLE `vendors`
+ mysqli_query($mysqli, "ALTER TABLE `recurring` CHANGE `recurring_created_at` `recurring_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `recurring_updated_at` `recurring_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `scheduled_tickets` CHANGE `scheduled_ticket_created_at` `scheduled_ticket_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `scheduled_ticket_updated_at` `scheduled_ticket_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `services` CHANGE `service_created_at` `service_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `service_updated_at` `service_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `shared_items` CHANGE `item_created_at` `item_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `software` CHANGE `software_created_at` `software_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `software_updated_at` `software_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `tags` CHANGE `tag_created_at` `tag_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `tag_updated_at` `tag_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `taxes` CHANGE `tax_created_at` `tax_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `tax_updated_at` `tax_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `tickets` CHANGE `ticket_created_at` `ticket_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `ticket_updated_at` `ticket_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `ticket_replies` CHANGE `ticket_reply_created_at` `ticket_reply_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `ticket_reply_updated_at` `ticket_reply_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `transfers` CHANGE `transfer_created_at` `transfer_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `transfer_updated_at` `transfer_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `trips` CHANGE `trip_created_at` `trip_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `trip_updated_at` `trip_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `users` CHANGE `user_created_at` `user_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `user_updated_at` `user_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ mysqli_query($mysqli, "ALTER TABLE `vendors` CHANGE `vendor_created_at` `vendor_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `vendor_updated_at` `vendor_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE settings SET config_current_database_version = '0.0.4'");
+
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.0.4'){
+ // Queries here required to update to DB version 0.0.5
+
+ mysqli_query($mysqli, "ALTER TABLE `assets` DROP `asset_meshcentral_id`;");
+ mysqli_query($mysqli, "ALTER TABLE `clients` DROP `client_meshcentral_group`;");
+ mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_meshcentral_uri`, DROP `config_meshcentral_user`, DROP `config_meshcentral_secret`;");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.5'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.0.5'){
+ // Insert queries here required to update to DB version 0.0.6
+
+ mysqli_query($mysqli, "UPDATE documents SET document_folder_id = 0");
+
+ mysqli_query($mysqli, "DROP TABLE documents_tagged");
+ mysqli_query($mysqli, "DROP TABLE document_tags");
+
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE settings SET config_current_database_version = '0.0.6'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.0.6'){
+ // Insert queries here required to update to DB version 0.0.7
+ mysqli_query($mysqli, "ALTER TABLE contacts ADD contact_department VARCHAR(200) NULL AFTER contact_title");
+ mysqli_query($mysqli, "DROP TABLE departments");
+ mysqli_query($mysqli, "ALTER TABLE contacts DROP contact_department_id");
+
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.7'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.0.7'){
+ // Insert queries here required to update to DB version 0.0.8
+
+ // Add contact_department column to tables without it (fresh installs) - this will cause an error if it already exists so catch and discard it
+ try{
+ mysqli_query($mysqli, "ALTER TABLE contacts ADD contact_department VARCHAR(200) NULL AFTER contact_title");
+ } catch(Exception $e) {
+ // Nothing
+ }
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.8'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.0.8'){
+ // Insert queries here required to update to DB version 0.0.9
+
+ mysqli_query($mysqli, "ALTER TABLE `revenues` CHANGE `revenue_created_at` `revenue_created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, CHANGE `revenue_updated_at` `revenue_updated_at` DATETIME on update CURRENT_TIMESTAMP NULL DEFAULT NULL; ");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.0.9'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.0.9'){
+ // Insert queries here required to update to DB version 0.0.9
+ // Remove unused tables
+ mysqli_query($mysqli, "DROP TABLE contracts");
+ mysqli_query($mysqli, "DROP TABLE messages");
+ mysqli_query($mysqli, "DROP TABLE roles");
+
+ //Remove updated at as API keys can only be added or revoked
+ mysqli_query($mysqli, "ALTER TABLE `api_keys` DROP `api_key_updated_at`");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.0'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.0'){
+ // Insert queries here required to update to DB version 0.1.1
+ // Logs don't get archived
+ mysqli_query($mysqli, "ALTER TABLE `logs` DROP `log_archived_at`");
+
+ // Assets will eventualy have file associatons which could include a receipt.
+ mysqli_query($mysqli, "ALTER TABLE `assets` DROP `asset_reciept`");
+
+ mysqli_query($mysqli, "ALTER TABLE `campaign_messages` DROP `message_updated_at`");
+ // This will be a seperate table eventually called contact_documents because contact can have several documents
+ mysqli_query($mysqli, "ALTER TABLE `documents` DROP `document_contact_id`");
+
+ mysqli_query($mysqli, "ALTER TABLE `expenses` DROP `expense_asset_id`");
+ mysqli_query($mysqli, "ALTER TABLE `files` DROP `file_contact_id`");
+ mysqli_query($mysqli, "ALTER TABLE `history` DROP `history_archived_at`");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.1'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.1'){
+ // Insert queries here required to update to DB version 0.1.2
+ // Create Many to Many Relationship tables for Assets, Contacts, Software and Vendors
+
+ mysqli_query($mysqli, "CREATE TABLE `asset_documents` (`asset_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`,`document_id`))");
+ mysqli_query($mysqli, "CREATE TABLE `asset_logins` (`asset_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`,`login_id`))");
+ mysqli_query($mysqli, "CREATE TABLE `asset_files` (`asset_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`asset_id`,`file_id`))");
+
+ mysqli_query($mysqli, "CREATE TABLE `contact_documents` (`contact_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`document_id`))");
+ mysqli_query($mysqli, "CREATE TABLE `contact_logins` (`contact_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`login_id`))");
+ mysqli_query($mysqli, "CREATE TABLE `contact_files` (`contact_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`file_id`))");
+
+ mysqli_query($mysqli, "CREATE TABLE `software_documents` (`software_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`software_id`,`document_id`))");
+ mysqli_query($mysqli, "CREATE TABLE `software_logins` (`software_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`software_id`,`login_id`))");
+ mysqli_query($mysqli, "CREATE TABLE `software_files` (`software_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`software_id`,`file_id`))");
+
+ mysqli_query($mysqli, "CREATE TABLE `vendor_documents` (`vendor_id` int(11) NOT NULL,`document_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`,`document_id`))");
+ mysqli_query($mysqli, "CREATE TABLE `vendor_logins` (`vendor_id` int(11) NOT NULL,`login_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`,`login_id`))");
+ mysqli_query($mysqli, "CREATE TABLE `vendor_files` (`vendor_id` int(11) NOT NULL,`file_id` int(11) NOT NULL, PRIMARY KEY (`vendor_id`,`file_id`))");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.2'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.2'){
+ // Insert queries here required to update to DB version 0.1.3
+ mysqli_query($mysqli, "ALTER TABLE `logs` ADD `log_entity_id` INT NOT NULL DEFAULT '0' AFTER `log_user_id`");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.3'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.3'){
+ // Insert queries here required to update to DB version 0.1.4
+ mysqli_query($mysqli, "ALTER TABLE assets ADD asset_status VARCHAR(200) NULL AFTER asset_mac");
+
+ ///Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.4'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.4'){
+ // Insert queries here required to update to DB version 0.1.5
+ mysqli_query($mysqli, "ALTER TABLE `domains` ADD `domain_txt` TEXT NULL DEFAULT NULL AFTER `domain_mail_servers`");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.5'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.5'){
+ // Insert queries here required to update to DB version 0.1.6
+ // Remove Mailing List Tables
+ mysqli_query($mysqli, "DROP TABLE campaigns");
+ mysqli_query($mysqli, "DROP TABLE campaign_messages");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.6'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.6'){
+ // Insert queries here required to update to DB version 0.1.7
+ //Remove custom links
+ mysqli_query($mysqli, "DROP TABLE custom_links");
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.7'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.7'){
+ // Insert queries here required to update to DB version 0.1.8
+ mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_backup_enable`");
+ mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_backup_path`");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.8'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.8'){
+ // Insert queries here required to update to DB version 0.1.9
+ mysqli_query($mysqli, "ALTER TABLE `settings` DROP `config_base_url`");
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.1.9'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.1.9'){
+ // Insert queries here required to update to DB version 0.2.0
+ // Allow contacts to reset their portal password
+ mysqli_query($mysqli, "ALTER TABLE contacts ADD contact_password_reset_token VARCHAR(200) NULL DEFAULT NULL AFTER contact_password_hash");
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.0'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.2.0'){
+ //Insert queries here required to update to DB version 0.2.1
+
+ mysqli_query($mysqli, "ALTER TABLE `vendors`
ADD `vendor_hours` VARCHAR(200) NULL DEFAULT NULL AFTER `vendor_website`,
ADD `vendor_sla` VARCHAR(200) NULL DEFAULT NULL AFTER `vendor_hours`,
ADD `vendor_code` VARCHAR(200) NULL DEFAULT NULL AFTER `vendor_sla`,
ADD `vendor_template_id` INT(11) DEFAULT 0 AFTER `vendor_archived_at`
");
- mysqli_query($mysqli, "ALTER TABLE `vendors`
+ mysqli_query($mysqli, "ALTER TABLE `vendors`
DROP `vendor_country`,
DROP `vendor_address`,
DROP `vendor_city`,
@@ -351,8 +351,8 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
DROP `vendor_global`
");
- //Create New Vendor Templates Table
- mysqli_query($mysqli, "CREATE TABLE `vendor_templates` (`vendor_template_id` int(11) AUTO_INCREMENT PRIMARY KEY,
+ //Create New Vendor Templates Table
+ mysqli_query($mysqli, "CREATE TABLE `vendor_templates` (`vendor_template_id` int(11) AUTO_INCREMENT PRIMARY KEY,
`vendor_template_name` varchar(200) NOT NULL,
`vendor_template_description` varchar(200) NULL DEFAULT NULL,
`vendor_template_phone` varchar(200) NULL DEFAULT NULL,
@@ -365,37 +365,37 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
`company_id` int(11) NOT NULL
)");
- //Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.1'");
- }
-
- if (CURRENT_DATABASE_VERSION == '0.2.1') {
- // Insert queries here required to update to DB version 0.2.2
- mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_ticket_email_parse` INT(1) NOT NULL DEFAULT '0' AFTER `config_ticket_from_email`");
- mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_imap_host` VARCHAR(200) NULL DEFAULT NULL AFTER `config_mail_from_name`, ADD `config_imap_port` INT(5) NULL DEFAULT NULL AFTER `config_imap_host`, ADD `config_imap_encryption` VARCHAR(200) NULL DEFAULT NULL AFTER `config_imap_port`;");
-
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.2'");
- }
-
- if (CURRENT_DATABASE_VERSION == '0.2.2') {
- // Insert queries here required to update to DB version 0.2.3
-
- // Add contact_important field to those who don't have it (installed before March 2022)
- try {
- mysqli_query($mysqli, "ALTER TABLE `contacts` ADD `contact_important` tinyint(1) NOT NULL DEFAULT 0 AFTER contact_password_reset_token;");
- } catch (Exception $e) {
- // Field already exists - that's fine
+ //Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.1'");
}
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.3'");
- }
+ if(CURRENT_DATABASE_VERSION == '0.2.1'){
+ // Insert queries here required to update to DB version 0.2.2
+ mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_ticket_email_parse` INT(1) NOT NULL DEFAULT '0' AFTER `config_ticket_from_email`");
+ mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_imap_host` VARCHAR(200) NULL DEFAULT NULL AFTER `config_mail_from_name`, ADD `config_imap_port` INT(5) NULL DEFAULT NULL AFTER `config_imap_host`, ADD `config_imap_encryption` VARCHAR(200) NULL DEFAULT NULL AFTER `config_imap_port`;");
- if (CURRENT_DATABASE_VERSION == '0.2.3') {
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.2'");
+ }
- //Create New interfaces Table
- mysqli_query($mysqli, "CREATE TABLE `interfaces` (`interface_id` int(11) AUTO_INCREMENT PRIMARY KEY,
+ if(CURRENT_DATABASE_VERSION == '0.2.2'){
+ // Insert queries here required to update to DB version 0.2.3
+
+ // Add contact_important field to those who don't have it (installed before March 2022)
+ try {
+ mysqli_query($mysqli, "ALTER TABLE `contacts` ADD `contact_important` tinyint(1) NOT NULL DEFAULT 0 AFTER contact_password_reset_token;");
+ } catch (Exception $e) {
+ // Field already exists - that's fine
+ }
+
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.3'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.2.3'){
+
+ //Create New interfaces Table
+ mysqli_query($mysqli, "CREATE TABLE `interfaces` (`interface_id` int(11) AUTO_INCREMENT PRIMARY KEY,
`interface_number` int(11) NULL DEFAULT NULL,
`interface_description` varchar(200) NULL DEFAULT NULL,
`interface_connected_asset` varchar(200) NULL DEFAULT NULL,
@@ -409,58 +409,72 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
`company_id` int(11) NOT NULL
)");
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.4'");
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.4'");
- }
+ }
- if (CURRENT_DATABASE_VERSION == '0.2.4') {
- mysqli_query($mysqli, "CREATE TABLE `contact_assets` (`contact_id` int(11) NOT NULL,`asset_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`asset_id`))");
+ if(CURRENT_DATABASE_VERSION == '0.2.4'){
+ mysqli_query($mysqli, "CREATE TABLE `contact_assets` (`contact_id` int(11) NOT NULL,`asset_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`asset_id`))");
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.5'");
- }
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.5'");
+ }
- if (CURRENT_DATABASE_VERSION == '0.2.5') {
- mysqli_query($mysqli, "ALTER TABLE `users` ADD `user_status` TINYINT(1) DEFAULT 1 AFTER `user_password`");
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.6'");
- }
+ if(CURRENT_DATABASE_VERSION == '0.2.5'){
+ mysqli_query($mysqli, "ALTER TABLE `users` ADD `user_status` TINYINT(1) DEFAULT 1 AFTER `user_password`");
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.6'");
+ }
- if (CURRENT_DATABASE_VERSION == '0.2.6') {
- // Insert queries here required to update to DB version 0.2.7
- mysqli_query($mysqli, "ALTER TABLE `contacts` ADD `contact_token_expire` DATETIME NULL DEFAULT NULL AFTER `contact_password_reset_token`");
+ if(CURRENT_DATABASE_VERSION == '0.2.6'){
+ // Insert queries here required to update to DB version 0.2.7
+ mysqli_query($mysqli, "ALTER TABLE `contacts` ADD `contact_token_expire` DATETIME NULL DEFAULT NULL AFTER `contact_password_reset_token`");
- // Update config.php var with new version var for use with docker
- file_put_contents("config.php", "\$repo_branch = 'master';" . PHP_EOL, FILE_APPEND);
+ // Update config.php var with new version var for use with docker
+ file_put_contents("config.php", "\$repo_branch = 'master';" . PHP_EOL, FILE_APPEND);
- // Then, update the database to the next sequential version
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.7'");
- }
+ // Then, update the database to the next sequential version
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.7'");
+ }
- if (CURRENT_DATABASE_VERSION == '0.2.7') {
+ if(CURRENT_DATABASE_VERSION == '0.2.7'){
- mysqli_query($mysqli, "ALTER TABLE `vendors` ADD `vendor_template` TINYINT(1) DEFAULT 0 AFTER `vendor_notes`");
- mysqli_query($mysqli, "ALTER TABLE `software` ADD `software_template` TINYINT(1) DEFAULT 0 AFTER `software_notes`");
- mysqli_query($mysqli, "ALTER TABLE `vendors` DROP `vendor_template_id`");
- mysqli_query($mysqli, "DROP TABLE vendor_templates");
+ mysqli_query($mysqli, "ALTER TABLE `vendors` ADD `vendor_template` TINYINT(1) DEFAULT 0 AFTER `vendor_notes`");
+ mysqli_query($mysqli, "ALTER TABLE `software` ADD `software_template` TINYINT(1) DEFAULT 0 AFTER `software_notes`");
+ mysqli_query($mysqli, "ALTER TABLE `vendors` DROP `vendor_template_id`");
+ mysqli_query($mysqli, "DROP TABLE vendor_templates");
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.8'");
- }
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.8'");
+ }
- if (CURRENT_DATABASE_VERSION == '0.2.8') {
+ if(CURRENT_DATABASE_VERSION == '0.2.8'){
- mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_theme` VARCHAR(200) DEFAULT 'blue' AFTER `config_module_enable_ticketing`");
+ mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_theme` VARCHAR(200) DEFAULT 'blue' AFTER `config_module_enable_ticketing`");
- mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.9'");
- }
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.2.9'");
+ }
-//if (CURRENT_DATABASE_VERSION == '0.2.9') {
- // Insert queries here required to update to DB version 0.3.0
+ if(CURRENT_DATABASE_VERSION == '0.2.9'){
- // Then, update the database to the next sequential version
- // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.3.0'");
- //}
+ mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_ticket_client_general_notifications` INT(1) NOT NULL DEFAULT '1' AFTER `config_ticket_email_parse`");
+
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.3.0'");
+ }
+
+ if(CURRENT_DATABASE_VERSION == '0.3.0'){
+ mysqli_query($mysqli, "ALTER TABLE `notifications` ADD `notification_user_id` TINYINT(1) DEFAULT 0 AFTER `notification_client_id`");
+
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.3.1'");
+ }
+
+
+ //if(CURRENT_DATABASE_VERSION == '0.3.1'){
+ // Insert queries here required to update to DB version 0.3.2
+
+ // Then, update the database to the next sequential version
+ // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.3.2'");
+ //}
-}else{
- // Up-to-date
-}
+} else {
+ // Up-to-date
+}
\ No newline at end of file
diff --git a/database_version.php b/database_version.php
index f8202a13..d814941c 100644
--- a/database_version.php
+++ b/database_version.php
@@ -5,4 +5,4 @@
* It is used in conjunction with database_updates.php
*/
-DEFINE("LATEST_DATABASE_VERSION", "0.2.9");
\ No newline at end of file
+DEFINE("LATEST_DATABASE_VERSION", "0.3.1");
\ No newline at end of file
diff --git a/db.sql b/db.sql
index 049f23b6..22bae51f 100644
--- a/db.sql
+++ b/db.sql
@@ -722,6 +722,7 @@ CREATE TABLE `notifications` (
`notification_dismissed_at` datetime DEFAULT NULL,
`notification_dismissed_by` int(11) DEFAULT NULL,
`notification_client_id` int(11) DEFAULT NULL,
+ `notification_user_id` tinyint(1) DEFAULT 0,
`company_id` int(11) NOT NULL,
PRIMARY KEY (`notification_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
@@ -1066,6 +1067,7 @@ CREATE TABLE `settings` (
`config_ticket_from_name` varchar(200) DEFAULT NULL,
`config_ticket_from_email` varchar(200) DEFAULT NULL,
`config_ticket_email_parse` int(1) NOT NULL DEFAULT 0,
+ `config_ticket_client_general_notifications` int(1) NOT NULL DEFAULT 1,
`config_enable_cron` tinyint(1) DEFAULT NULL,
`config_recurring_auto_send_invoice` tinyint(1) DEFAULT NULL,
`config_enable_alert_domain_expire` tinyint(1) DEFAULT NULL,
@@ -1079,6 +1081,7 @@ CREATE TABLE `settings` (
`config_module_enable_itdoc` tinyint(1) NOT NULL DEFAULT 1,
`config_module_enable_accounting` tinyint(1) NOT NULL DEFAULT 1,
`config_module_enable_ticketing` tinyint(1) NOT NULL DEFAULT 1,
+ `config_theme` varchar(200) DEFAULT 'blue',
PRIMARY KEY (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -1516,4 +1519,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2023-01-18 20:12:49
+-- Dump completed on 2023-01-22 20:00:27
diff --git a/functions.php b/functions.php
index f335e463..d6016ede 100644
--- a/functions.php
+++ b/functions.php
@@ -87,7 +87,6 @@ function get_ip() {
}
function get_web_browser($user_browser) {
- //$user_agent = $log_user_agent;
$browser = "Unknown Browser";
$browser_array = array(
'/msie/i' => " Internet Explorer",
diff --git a/get_settings.php b/get_settings.php
index 9ec809ab..6efad592 100644
--- a/get_settings.php
+++ b/get_settings.php
@@ -58,6 +58,7 @@ $config_ticket_next_number = $row['config_ticket_next_number'];
$config_ticket_from_name = $row['config_ticket_from_name'];
$config_ticket_from_email = $row['config_ticket_from_email'];
$config_ticket_email_parse = $row['config_ticket_email_parse'];
+$config_ticket_client_general_notifications = $row['config_ticket_client_general_notifications'];
// Alerts
$config_enable_cron = $row['config_enable_cron'];
diff --git a/guest_view_invoice.php b/guest_view_invoice.php
index 2309f9ea..39e53b9f 100644
--- a/guest_view_invoice.php
+++ b/guest_view_invoice.php
@@ -68,8 +68,10 @@ if (isset($_GET['invoice_id'], $_GET['url_key'])) {
$currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY);
$ip = strip_tags(mysqli_real_escape_string($mysqli,get_ip()));
- $os = strip_tags(mysqli_real_escape_string($mysqli,get_os()));
- $browser = strip_tags(mysqli_real_escape_string($mysqli,get_web_browser()));
+
+ $session_user_agent = strip_tags(mysqli_real_escape_string($mysqli,$_SERVER['HTTP_USER_AGENT']));
+ $os = strip_tags(mysqli_real_escape_string($mysqli,get_os($session_user_agent)));
+ $browser = strip_tags(mysqli_real_escape_string($mysqli,get_web_browser($session_user_agent)));
//Set Badge color based off of invoice status
if ($invoice_status == "Sent") {
diff --git a/guest_view_quote.php b/guest_view_quote.php
index c2e6695a..033fd9ee 100644
--- a/guest_view_quote.php
+++ b/guest_view_quote.php
@@ -64,10 +64,11 @@ if (isset($_GET['quote_id'], $_GET['url_key'])) {
//Set Currency Format
$currency_format = numfmt_create($company_locale, NumberFormatter::CURRENCY);
- $ip = get_ip();
- $os = get_os();
- $browser = get_web_browser();
- $device = get_device();
+ $ip = strip_tags(mysqli_real_escape_string($mysqli,get_ip()));
+
+ $session_user_agent = strip_tags(mysqli_real_escape_string($mysqli,$_SERVER['HTTP_USER_AGENT']));
+ $os = strip_tags(mysqli_real_escape_string($mysqli,get_os($session_user_agent)));
+ $browser = strip_tags(mysqli_real_escape_string($mysqli,get_web_browser($session_user_agent)));
//Update status to Viewed only if invoice_status = "Sent"
if ($quote_status == 'Sent') {
@@ -75,11 +76,11 @@ if (isset($_GET['quote_id'], $_GET['url_key'])) {
}
//Mark viewed in history
- mysqli_query($mysqli,"INSERT INTO history SET history_status = '$quote_status', history_description = 'Quote viewed - $ip - $os - $browser - $device', history_created_at = NOW(), history_quote_id = $quote_id, company_id = $company_id");
+ mysqli_query($mysqli,"INSERT INTO history SET history_status = '$quote_status', history_description = 'Quote viewed - $ip - $os - $browser', history_created_at = NOW(), history_quote_id = $quote_id, company_id = $company_id");
//Prevent SQL Error if client_name has ' in their name example Bill's Market
$client_name_escaped = mysqli_escape_string($mysqli,$row['client_name']);
- mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Quote Viewed', notification = 'Quote $quote_prefix$quote_number has been viewed by $client_name_escaped - $ip - $os - $browser - $device', notification_timestamp = NOW(), notification_client_id = $client_id, company_id = $company_id");
+ mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Quote Viewed', notification = 'Quote $quote_prefix$quote_number has been viewed by $client_name_escaped - $ip - $os - $browser', notification_timestamp = NOW(), notification_client_id = $client_id, company_id = $company_id");
?>
diff --git a/inc_client_top_head.php b/inc_client_top_head.php
index e45779a0..8f2a23bb 100644
--- a/inc_client_top_head.php
+++ b/inc_client_top_head.php
@@ -6,7 +6,7 @@ $location_phone = formatPhoneNumber($location_phone);
?>
-
+
diff --git a/login.php b/login.php
index f772f7bc..10a4626f 100644
--- a/login.php
+++ b/login.php
@@ -5,13 +5,41 @@ if (!file_exists('config.php')) {
exit;
}
-include("config.php");
-include("functions.php");
+require_once("config.php");
+require_once("functions.php");
+require_once("rfc6238.php");
// IP & User Agent for logging
$ip = strip_tags(mysqli_real_escape_string($mysqli,get_ip()));
$user_agent = strip_tags(mysqli_real_escape_string($mysqli,$_SERVER['HTTP_USER_AGENT']));
+// Block brute force password attacks - check recent failed login attempts for this IP
+// Block access if more than 15 failed login attempts have happened in the last 10 minutes
+$row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT(log_id) AS failed_login_count FROM logs WHERE log_ip = '$ip' AND log_type = 'Login' AND log_action = 'Failed' AND log_created_at > (NOW() - INTERVAL 10 MINUTE)"));
+$failed_login_count = $row['failed_login_count'];
+
+if ($failed_login_count >= 15) {
+
+ // Logging
+ mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Login', log_action = 'Blocked', log_description = '$ip was blocked access to login due to IP lockout', log_ip = '$ip', log_user_agent = '$user_agent'");
+
+ // Inform user & quit processing page
+ exit("
$config_app_name
Your IP address has been blocked due to repeated failed login attempts. Please try again later.
This action has been logged.");
+}
+
+// Query Settings for "default" company (as companies are being removed shortly)
+$sql_settings = mysqli_query($mysqli,"SELECT * FROM settings WHERE company_id = 1");
+$row = mysqli_fetch_array($sql_settings);
+
+// Mail
+$config_smtp_host = $row['config_smtp_host'];
+$config_smtp_port = $row['config_smtp_port'];
+$config_smtp_encryption = $row['config_smtp_encryption'];
+$config_smtp_username = $row['config_smtp_username'];
+$config_smtp_password = $row['config_smtp_password'];
+$config_mail_from_email = $row['config_mail_from_email'];
+$config_mail_from_name = $row['config_mail_from_name'];
+
// HTTP-Only cookies
ini_set("session.cookie_httponly", True);
@@ -26,45 +54,67 @@ if (isset($_POST['login'])) {
// Sessions should start after the user has POSTed data
session_start();
- // Check recent failed login attempts for this IP (more than 10 failed logins in 5 mins)
- $row = mysqli_fetch_assoc(mysqli_query($mysqli,"SELECT COUNT(log_id) AS failed_login_count FROM logs WHERE log_ip = '$ip' AND log_type = 'Login' AND log_action = 'Failed' AND log_created_at > (NOW() - INTERVAL 5 MINUTE)"));
- $failed_login_count = $row['failed_login_count'];
+ // Passed login brute force check
+ $email = strip_tags(mysqli_real_escape_string($mysqli, $_POST['email']));
+ $password = $_POST['password'];
- // Login brute force check
- if ($failed_login_count >= 10) {
+ $current_code = 0; // Default value
+ if (isset($_POST['current_code'])) {
+ $current_code = strip_tags(mysqli_real_escape_string($mysqli, $_POST['current_code']));
+ }
- // Logging
- mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Login', log_action = 'Failed', log_description = 'Failed login attempt due to IP lockout', log_ip = '$ip', log_user_agent = '$user_agent'");
+ $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM users LEFT JOIN user_settings on users.user_id = user_settings.user_id WHERE user_email = '$email' AND user_archived_at IS NULL AND user_status = 1"));
- // Send an alert only count hits 10 to reduce flooding alerts (using 1 as "default" company)
- if ($failed_login_count == 10) {
- mysqli_query($mysqli,"INSERT INTO notifications SET notification_type = 'Lockout', notification = '$ip was locked out for repeated failed login attempts.', notification_timestamp = NOW() company_id = '1'");
- }
+ // Check password
+ if ($row && password_verify($password, $row['user_password'])) {
- // Inform user
- $response = '
IP Lockout - Please try again later.
';
+ // User password correct (partial login)
- } else {
- // Passed login brute force check
- $email = strip_tags(mysqli_real_escape_string($mysqli, $_POST['email']));
- $password = $_POST['password'];
- if (isset($_POST['current_code'])) {
- $current_code = strip_tags(mysqli_real_escape_string($mysqli, $_POST['current_code']));
- }
+ // Set temporary user variables
+ $user_name = strip_tags(mysqli_real_escape_string($mysqli, $row['user_name']));
+ $user_id = $row['user_id'];
+ $user_email = $row['user_email'];
+ $token = $row['user_token'];
- $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM users LEFT JOIN user_settings on users.user_id = user_settings.user_id WHERE user_email = '$email' AND user_archived_at IS NULL AND user_status = 1"));
- if ($row && password_verify($password, $row['user_password'])) {
+ // Checking for user 2FA
+ if (empty($token) || TokenAuth6238::verify($token, $current_code)) {
- // User variables
- $token = $row['user_token'];
- $user_name = strip_tags(mysqli_real_escape_string($mysqli, $row['user_name']));
- $user_id = $row['user_id'];
+ // FULL LOGIN SUCCESS - 2FA not configured or was successful
+
+ // Check this login isn't suspicious
+ $sql_ip_prev_logins = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(log_id) AS ip_previous_logins FROM logs WHERE log_type = 'Login' AND log_action = 'Success' AND log_ip = '$ip' AND log_user_id = '$user_id'"));
+ $ip_previous_logins = $sql_ip_prev_logins['ip_previous_logins'];
+
+ $sql_ua_prev_logins = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(log_id) AS ua_previous_logins FROM logs WHERE log_type = 'Login' AND log_action = 'Success' AND log_user_agent = '$user_agent' AND log_user_id = '$user_id'"));
+ $ua_prev_logins = $sql_ua_prev_logins['ua_previous_logins'];
+
+ // Notify if both the user agent and IP are different
+ if (!empty($config_smtp_host) && $ip_previous_logins == 0 && $ua_prev_logins == 0) {
+ $subject = "$config_app_name new login for $user_name";
+ $body = "Hi $user_name,
A recent successful login to your $config_app_name account was considered a little unusual. If this was you, you can safely ignore this email!
IP Address: $ip User Agent: $user_agent
If you did not perform this login, your credentials may be compromised.
Thanks, ITFlow";
+
+ $mail = sendSingleEmail($config_smtp_host, $config_smtp_username, $config_smtp_password, $config_smtp_encryption, $config_smtp_port,
+ $config_mail_from_email, $config_mail_from_name,
+ $user_email, $user_name,
+ $subject, $body);
+ }
+
+
+ // Determine whether 2FA was used (for logs)
+ $extended_log = ''; // Default value
+ if ($current_code !== 0 ) {
+ $extended_log = 'with 2FA';
+ }
+
+ // Logging successful login
+ mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Login', log_action = 'Success', log_description = '$user_name successfully logged in $extended_log', log_ip = '$ip', log_user_agent = '$user_agent', log_user_id = $user_id");
// Session info
$_SESSION['user_id'] = $user_id;
$_SESSION['user_name'] = $user_name;
$_SESSION['user_role'] = $row['user_role'];
$_SESSION['csrf_token'] = bin2hex(random_bytes(78));
+ $_SESSION['logged'] = TRUE;
// Setup encryption session key
if (isset($row['user_specific_encryption_ciphertext']) && $row['user_role'] > 1) {
@@ -84,67 +134,66 @@ if (isset($_POST['login'])) {
}
}
- if (empty($token)) {
- // Full Login successful
-
- $_SESSION['logged'] = TRUE;
- mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Login', log_action = 'Success', log_description = '$user_name successfully logged in', log_ip = '$ip', log_user_agent = '$user_agent', log_user_id = $user_id");
-
- // Show start page/dashboard depending on role
- if ($row['user_role'] == 2) {
- header("Location: dashboard_technical.php");
- } else {
- header("Location: dashboard_financial.php");
- }
-
+ // Show start page/dashboard depending on role
+ if ($row['user_role'] == 2) {
+ header("Location: dashboard_technical.php");
} else {
- // Prompt for MFA
-
- $token_field = "
- ";
+ } else {
+
+ // MFA is configured and needs to be confirmed, or was unsuccessful
+
+ // HTML code for the token input field
+ $token_field = "
+
+
+
+
+
+
+
+
";
+
+ // Log/notify if MFA was unsuccessful
+ if ($current_code !== 0) {
+
+ // Logging
+ mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Login', log_action = '2FA Failed', log_description = '$user_name failed 2FA', log_ip = '$ip', log_user_agent = '$user_agent', log_created_at = NOW(), log_user_id = $user_id");
+
+ // Email the tech to advise their credentials may be compromised
+ if (!empty($config_smtp_host)) {
+ $subject = "Important: $config_app_name failed 2FA login attempt for $user_name";
+ $body = "Hi $user_name,
A recent login to your $config_app_name account was unsuccessful due to an incorrect 2FA code. If you did not attempt this login, your credentials may be compromised.
We hope the issue was resolved to your satisfaction. If you need further assistance, please raise a new ticket using the below details. Please do not reply to this email.
~ $session_company_name Support Department $config_ticket_from_email $company_phone";
@@ -6231,12 +6362,12 @@ if (isset($_POST['add_ticket_reply'])) {
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket Reply', log_action = 'Create', log_description = '$ticket_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
$_SESSION['alert_message'] = "Posted an update";
-
+
header("Location: " . $_SERVER["HTTP_REFERER"]);
-
+
}
-if (isset($_POST['edit_ticket_reply'])) {
+if(isset($_POST['edit_ticket_reply'])){
validateTechRole();
@@ -6256,12 +6387,12 @@ if (isset($_POST['edit_ticket_reply'])) {
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket Update Modify', log_action = 'Modify', log_description = '$ticket_update_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
$_SESSION['alert_message'] = "Ticket update modified";
-
+
header("Location: " . $_SERVER["HTTP_REFERER"]);
-
+
}
-if (isset($_GET['archive_ticket_reply'])) {
+if(isset($_GET['archive_ticket_reply'])){
validateAdminRole();
@@ -6273,12 +6404,12 @@ if (isset($_GET['archive_ticket_reply'])) {
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket Update', log_action = 'Archive', log_description = '$ticket_update_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
$_SESSION['alert_message'] = "Ticket update archived";
-
+
header("Location: " . $_SERVER["HTTP_REFERER"]);
-
+
}
-if (isset($_POST['merge_ticket'])) {
+if(isset($_POST['merge_ticket'])){
validateTechRole();
@@ -6289,7 +6420,7 @@ if (isset($_POST['merge_ticket'])) {
//Get current ticket details
$sql = mysqli_query($mysqli, "SELECT ticket_prefix, ticket_number, ticket_subject, ticket_details FROM tickets WHERE ticket_id = '$ticket_id'");
- if (mysqli_num_rows($sql) == 0) {
+ if(mysqli_num_rows($sql) == 0){
$_SESSION['alert_message'] = "No ticket with that ID found.";
header("Location: " . $_SERVER["HTTP_REFERER"]);
exit();
@@ -6302,7 +6433,7 @@ if (isset($_POST['merge_ticket'])) {
//Get merge into ticket id (as it may differ from the number)
$sql = mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE ticket_number = '$merge_into_ticket_number'");
- if (mysqli_num_rows($sql) == 0) {
+ if(mysqli_num_rows($sql) == 0){
$_SESSION['alert_message'] = "Cannot merge into that ticket.";
header("Location: " . $_SERVER["HTTP_REFERER"]);
exit();
@@ -6310,7 +6441,7 @@ if (isset($_POST['merge_ticket'])) {
$merge_row = mysqli_fetch_array($sql);
$merge_into_ticket_id = trim(mysqli_real_escape_string($mysqli,$merge_row['ticket_id']));
- if ($ticket_number == $merge_into_ticket_number) {
+ if($ticket_number == $merge_into_ticket_number){
$_SESSION['alert_message'] = "Cannot merge into the same ticket.";
header("Location: " . $_SERVER["HTTP_REFERER"]);
exit();
@@ -6331,7 +6462,7 @@ if (isset($_POST['merge_ticket'])) {
}
-if (isset($_GET['close_ticket'])) {
+if(isset($_GET['close_ticket'])){
validateTechRole();
@@ -6345,7 +6476,7 @@ if (isset($_GET['close_ticket'])) {
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket', log_action = 'Closed', log_description = '$ticket_id Closed', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, company_id = $session_company_id");
// Client notification email
- if (!empty($config_smtp_host)) {
+ if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1) {
// Get details
$ticket_sql = mysqli_query($mysqli,"SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_subject, company_phone FROM tickets
@@ -6364,7 +6495,7 @@ if (isset($_GET['close_ticket'])) {
$company_phone = formatPhoneNumber($row['company_phone']);
// Check email valid
- if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) {
+ if(filter_var($contact_email, FILTER_VALIDATE_EMAIL)){
$subject = "Ticket closed - [$ticket_prefix$ticket_number] - $ticket_subject | (do not reply)";
$body = "Hello, $contact_name
Your ticket regarding \"$ticket_subject\" has been closed.
We hope the issue was resolved to your satisfaction. If you need further assistance, please raise a new ticket using the below details. Please do not reply to this email.