diff --git a/admin_tag_add_modal.php b/admin_tag_add_modal.php index b0eaa4b4..5cd0705c 100644 --- a/admin_tag_add_modal.php +++ b/admin_tag_add_modal.php @@ -31,6 +31,7 @@ + diff --git a/admin_tag_edit_modal.php b/admin_tag_edit_modal.php index 319c63ad..f0fb9574 100644 --- a/admin_tag_edit_modal.php +++ b/admin_tag_edit_modal.php @@ -31,6 +31,7 @@ + diff --git a/admin_tags.php b/admin_tags.php index cce37dce..edd1249f 100644 --- a/admin_tags.php +++ b/admin_tags.php @@ -66,6 +66,8 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $tag_type_display = "Client Tag"; } elseif ( $tag_type == 2) { $tag_type_display = "Location Tag"; + } elseif ( $tag_type == 3) { + $tag_type_display = "Contact Tag"; } else { $tag_type_display = "Unknown Tag"; } diff --git a/client_contact_add_modal.php b/client_contact_add_modal.php index b7a0235f..14f46674 100644 --- a/client_contact_add_modal.php +++ b/client_contact_add_modal.php @@ -228,6 +228,27 @@ +
+ +
+
+ +
+ +
+
+ diff --git a/client_contact_details.php b/client_contact_details.php index b669835a..07283f62 100644 --- a/client_contact_details.php +++ b/client_contact_details.php @@ -59,6 +59,28 @@ if (isset($_GET['contact_id'])) { WHERE ticket_contact_id = $contact_id ORDER BY ticket_id DESC"); $ticket_count = mysqli_num_rows($sql_related_tickets); + // Tags + $contact_tag_name_display_array = array(); + $contact_tag_id_array = array(); + $sql_contact_tags = mysqli_query($mysqli, "SELECT * FROM contact_tags LEFT JOIN tags ON contact_tags.tag_id = tags.tag_id WHERE contact_id = $contact_id ORDER BY tag_name ASC"); + while ($row = mysqli_fetch_array($sql_contact_tags)) { + + $contact_tag_id = intval($row['tag_id']); + $contact_tag_name = nullable_htmlentities($row['tag_name']); + $contact_tag_color = nullable_htmlentities($row['tag_color']); + if (empty($contact_tag_color)) { + $contact_tag_color = "dark"; + } + $contact_tag_icon = nullable_htmlentities($row['tag_icon']); + if (empty($contact_tag_icon)) { + $contact_tag_icon = "tag"; + } + + $contact_tag_id_array[] = $contact_tag_id; + $contact_tag_name_display_array[] = "$contact_tag_name"; + } + $contact_tags_display = implode('', $contact_tag_name_display_array); + ?>
@@ -85,6 +107,12 @@ if (isset($_GET['contact_id'])) {
+ +
+ +
+
@@ -143,6 +171,19 @@ if (isset($_GET['contact_id'])) { + +
">

Related Assets

@@ -610,5 +651,9 @@ if (isset($_GET['contact_id'])) {
+
+ +
+
+ +
+ +
+
+
diff --git a/client_contacts.php b/client_contacts.php index 540c38ae..a75d73f9 100644 --- a/client_contacts.php +++ b/client_contacts.php @@ -6,15 +6,32 @@ $order = "ASC"; require_once "inc_all_client.php"; +// Tags Filter +if (isset($_GET['tags']) && is_array($_GET['tags']) && !empty($_GET['tags'])) { + // Sanitize each element of the status array + $sanitizedTags = array(); + foreach ($_GET['tags'] as $tag) { + // Escape each status to prevent SQL injection + $sanitizedTags[] = "'" . intval($tag) . "'"; + } + + // Convert the sanitized tags into a comma-separated string + $sanitizedTagsString = implode(",", $sanitizedTags); + $tag_query = "AND tags.tag_id IN ($sanitizedTagsString)"; +} //Rebuild URL $url_query_strings_sort = http_build_query($get_copy); -$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS * FROM contacts +$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS contacts.*, locations.*, GROUP_CONCAT(tags.tag_name) FROM contacts LEFT JOIN locations ON location_id = contact_location_id + LEFT JOIN contact_tags ON contact_tags.contact_id = contacts.contact_id + LEFT JOIN tags ON tags.tag_id = contact_tags.tag_id WHERE contact_$archive_query - AND (contact_name LIKE '%$q%' OR contact_title LIKE '%$q%' OR location_name LIKE '%$q%' OR contact_email LIKE '%$q%' OR contact_department LIKE '%$q%' OR contact_phone LIKE '%$phone_query%' OR contact_extension LIKE '%$q%' OR contact_mobile LIKE '%$phone_query%') - AND contact_client_id = $client_id + $tag_query + AND (contact_name LIKE '%$q%' OR contact_title LIKE '%$q%' OR location_name LIKE '%$q%' OR contact_email LIKE '%$q%' OR contact_department LIKE '%$q%' OR contact_phone LIKE '%$phone_query%' OR contact_extension LIKE '%$q%' OR contact_mobile LIKE '%$phone_query%' OR tag_name LIKE '%$q%') + AND contact_client_id = $client_id + GROUP BY contact_id ORDER BY contact_primary DESC, contact_important DESC, $sort $order LIMIT $record_from, $record_to" ); @@ -60,7 +77,23 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); -
+
+
+ +
+
+ +
Archived @@ -203,6 +236,28 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $sql_related_tickets = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_contact_id = $contact_id ORDER BY ticket_id DESC"); $ticket_count = mysqli_num_rows($sql_related_tickets); + // Tags + $contact_tag_name_display_array = array(); + $contact_tag_id_array = array(); + $sql_contact_tags = mysqli_query($mysqli, "SELECT * FROM contact_tags LEFT JOIN tags ON contact_tags.tag_id = tags.tag_id WHERE contact_id = $contact_id ORDER BY tag_name ASC"); + while ($row = mysqli_fetch_array($sql_contact_tags)) { + + $contact_tag_id = intval($row['tag_id']); + $contact_tag_name = nullable_htmlentities($row['tag_name']); + $contact_tag_color = nullable_htmlentities($row['tag_color']); + if (empty($contact_tag_color)) { + $contact_tag_color = "dark"; + } + $contact_tag_icon = nullable_htmlentities($row['tag_icon']); + if (empty($contact_tag_icon)) { + $contact_tag_icon = "tag"; + } + + $contact_tag_id_array[] = $contact_tag_id; + $contact_tag_name_display_array[] = "$contact_tag_name"; + } + $contact_tags_display = implode('', $contact_tag_name_display_array); + ?> @@ -234,6 +289,12 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
+ +
+ +
+ diff --git a/database_updates.php b/database_updates.php index 39ea33fb..1a154692 100644 --- a/database_updates.php +++ b/database_updates.php @@ -1937,10 +1937,15 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.5'"); } - // if (CURRENT_DATABASE_VERSION == '1.3.5') { - // // Insert queries here required to update to DB version 1.3.6 + if (CURRENT_DATABASE_VERSION == '1.3.5') { + mysqli_query($mysqli, "CREATE TABLE `contact_tags` (`contact_id` int(11) NOT NULL,`tag_id` int(11) NOT NULL, PRIMARY KEY (`contact_id`,`tag_id`))"); + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.6'"); + } + + // if (CURRENT_DATABASE_VERSION == '1.3.6') { + // // Insert queries here required to update to DB version 1.3.7 // // Then, update the database to the next sequential version - // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.6'"); + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.7'"); // } } else { diff --git a/database_version.php b/database_version.php index cb57d13f..f094eeb8 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", "1.3.5"); +DEFINE("LATEST_DATABASE_VERSION", "1.3.6"); diff --git a/db.sql b/db.sql index b09d052a..98cc8242 100644 --- a/db.sql +++ b/db.sql @@ -366,6 +366,20 @@ CREATE TABLE `contact_logins` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `contact_tags` +-- + +DROP TABLE IF EXISTS `contact_tags`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `contact_tags` ( + `contact_id` int(11) NOT NULL, + `tag_id` int(11) NOT NULL, + PRIMARY KEY (`contact_id`,`tag_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `contacts` -- @@ -1952,4 +1966,4 @@ CREATE TABLE `vendors` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-05-31 16:45:46 +-- Dump completed on 2024-06-01 14:25:19 diff --git a/post/contact.php b/post/contact.php index 7d4df316..32f65525 100644 --- a/post/contact.php +++ b/post/contact.php @@ -27,6 +27,14 @@ if (isset($_POST['add_contact'])) { $contact_id = mysqli_insert_id($mysqli); + // Add Tags + if (isset($_POST['tags'])) { + foreach($_POST['tags'] as $tag) { + $tag = intval($tag); + mysqli_query($mysqli, "INSERT INTO contact_tags SET contact_id = $contact_id, tag_id = $tag"); + } + } + //Update Primary contact in clients if primary contact is checked if ($contact_primary == 1) { mysqli_query($mysqli,"UPDATE contacts SET contact_primary = 0 WHERE contact_client_id = $client_id"); @@ -82,6 +90,17 @@ if (isset($_POST['edit_contact'])) { mysqli_query($mysqli,"UPDATE contacts SET contact_name = '$name', contact_title = '$title', contact_phone = '$phone', contact_extension = '$extension', contact_mobile = '$mobile', contact_email = '$email', contact_pin = '$pin', contact_notes = '$notes', contact_important = $contact_important, contact_billing = $contact_billing, contact_technical = $contact_technical, contact_auth_method = '$auth_method', contact_department = '$department', contact_location_id = $location_id WHERE contact_id = $contact_id"); + + // Tags + // Delete existing tags + mysqli_query($mysqli, "DELETE FROM contact_tags WHERE contact_id = $contact_id"); + + // Add new tags + foreach($_POST['tags'] as $tag) { + $tag = intval($tag); + mysqli_query($mysqli, "INSERT INTO contact_tags SET contact_id = $contact_id, tag_id = $tag"); + } + // Update Primary contact in clients if primary contact is checked if ($contact_primary == 1) { mysqli_query($mysqli,"UPDATE contacts SET contact_primary = 0 WHERE contact_client_id = $client_id"); @@ -448,6 +467,10 @@ if (isset($_GET['delete_contact'])) { mysqli_query($mysqli,"DELETE FROM contacts WHERE contact_id = $contact_id"); + // Tags + // Delete existing tags + mysqli_query($mysqli, "DELETE FROM contact_tags WHERE contact_id = $contact_id"); + //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Contact', log_action = 'Delete', log_description = '$session_name deleted contact $contact_name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $contact_id"); diff --git a/ticket_add_from_template_modal.php b/ticket_add_from_template_modal.php index 899e3b49..ef46c7f4 100644 --- a/ticket_add_from_template_modal.php +++ b/ticket_add_from_template_modal.php @@ -187,7 +187,7 @@ } ?> - + diff --git a/ticket_add_modal.php b/ticket_add_modal.php index 9cb3f7cb..aeede733 100644 --- a/ticket_add_modal.php +++ b/ticket_add_modal.php @@ -190,7 +190,7 @@ } ?> - +