diff --git a/admin_tag_add_modal.php b/admin_tag_add_modal.php
index e3654f61..b0eaa4b4 100644
--- a/admin_tag_add_modal.php
+++ b/admin_tag_add_modal.php
@@ -30,6 +30,7 @@
diff --git a/admin_tag_edit_modal.php b/admin_tag_edit_modal.php
index 0d21df3b..319c63ad 100644
--- a/admin_tag_edit_modal.php
+++ b/admin_tag_edit_modal.php
@@ -30,6 +30,7 @@
diff --git a/admin_tags.php b/admin_tags.php
index 939e4c4c..cce37dce 100644
--- a/admin_tags.php
+++ b/admin_tags.php
@@ -62,6 +62,13 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$tag_id = intval($row['tag_id']);
$tag_name = nullable_htmlentities($row['tag_name']);
$tag_type = intval($row['tag_type']);
+ if ( $tag_type == 1) {
+ $tag_type_display = "Client Tag";
+ } elseif ( $tag_type == 2) {
+ $tag_type_display = "Location Tag";
+ } else {
+ $tag_type_display = "Unknown Tag";
+ }
$tag_color = nullable_htmlentities($row['tag_color']);
$tag_icon = nullable_htmlentities($row['tag_icon']);
@@ -72,7 +79,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
-
|
+ |
-
-
-
-
@@ -180,6 +176,27 @@
+
+
diff --git a/client_location_edit_modal.php b/client_location_edit_modal.php
index 7c140b93..5e76eae5 100644
--- a/client_location_edit_modal.php
+++ b/client_location_edit_modal.php
@@ -194,6 +194,27 @@
+
+
diff --git a/client_locations.php b/client_locations.php
index c92cedf9..8fce22c1 100644
--- a/client_locations.php
+++ b/client_locations.php
@@ -12,10 +12,13 @@ $url_query_strings_sort = http_build_query($get_copy);
$sql = mysqli_query(
$mysqli,
- "SELECT SQL_CALC_FOUND_ROWS * FROM locations
+ "SELECT SQL_CALC_FOUND_ROWS locations.*, GROUP_CONCAT(tags.tag_name) AS tag_names FROM locations
+ LEFT JOIN location_tags ON location_tags.location_id = locations.location_id
+ LEFT JOIN tags ON tags.tag_id = location_tags.tag_id
WHERE location_client_id = $client_id
AND location_$archive_query
- AND (location_name LIKE '%$q%' OR location_description LIKE '%$q%' OR location_address LIKE '%$q%' OR location_phone LIKE '%$phone_query%')
+ AND (location_name LIKE '%$q%' OR location_description LIKE '%$q%' OR location_address LIKE '%$q%' OR location_phone LIKE '%$phone_query%' OR tags.tag_name LIKE '%$q%')
+ GROUP BY locations.location_id
ORDER BY location_primary DESC, $sort $order LIMIT $record_from, $record_to"
);
@@ -118,6 +121,29 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$location_primary_display = "";
}
+ // Tags
+
+ $location_tag_name_display_array = array();
+ $location_tag_id_array = array();
+ $sql_location_tags = mysqli_query($mysqli, "SELECT * FROM location_tags LEFT JOIN tags ON location_tags.tag_id = tags.tag_id WHERE location_tags.location_id = $location_id ORDER BY tag_name ASC");
+ while ($row = mysqli_fetch_array($sql_location_tags)) {
+
+ $location_tag_id = intval($row['tag_id']);
+ $location_tag_name = nullable_htmlentities($row['tag_name']);
+ $location_tag_color = nullable_htmlentities($row['tag_color']);
+ if (empty($location_tag_color)) {
+ $location_tag_color = "dark";
+ }
+ $location_tag_icon = nullable_htmlentities($row['tag_icon']);
+ if (empty($location_tag_icon)) {
+ $location_tag_icon = "tag";
+ }
+
+ $location_tag_id_array[] = $location_tag_id;
+ $location_tag_name_display_array[] = "$location_tag_name";
+ }
+ $location_tags_display = implode('', $location_tag_name_display_array);
+
?>
|
|
@@ -128,6 +154,12 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
>
+
+
+
+
+
diff --git a/database_updates.php b/database_updates.php
index 5ad87177..bf3396c7 100644
--- a/database_updates.php
+++ b/database_updates.php
@@ -1924,12 +1924,22 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.3'");
}
- // if (CURRENT_DATABASE_VERSION == '1.3.3') {
+ if (CURRENT_DATABASE_VERSION == '1.3.3') {
// // Insert queries here required to update to DB version 1.3.3
// // Then, update the database to the next sequential version
- // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.4'");
+ mysqli_query($mysqli, "CREATE TABLE `location_tags` (`location_id` int(11) NOT NULL,`tag_id` int(11) NOT NULL, PRIMARY KEY (`location_id`,`tag_id`))");
+ mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.4'");
+ }
+
+ // if (CURRENT_DATABASE_VERSION == '1.3.4') {
+ // // Insert queries here required to update to DB version 1.3.5
+ // // Then, update the database to the next sequential version
+ // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.5'");
// }
} else {
// Up-to-date
}
+
+
+
diff --git a/database_version.php b/database_version.php
index 8ddd52ae..66bdffd9 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.3");
+DEFINE("LATEST_DATABASE_VERSION", "1.3.4");
diff --git a/db.sql b/db.sql
index 4493b81d..8e0daeeb 100644
--- a/db.sql
+++ b/db.sql
@@ -751,6 +751,20 @@ CREATE TABLE `invoices` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
+--
+-- Table structure for table `location_tags`
+--
+
+DROP TABLE IF EXISTS `location_tags`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `location_tags` (
+ `location_id` int(11) NOT NULL,
+ `tag_id` int(11) NOT NULL,
+ PRIMARY KEY (`location_id`,`tag_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
--
-- Table structure for table `locations`
--
@@ -1938,4 +1952,4 @@ CREATE TABLE `vendors` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2024-05-29 17:56:36
+-- Dump completed on 2024-05-31 16:12:51
diff --git a/post/location.php b/post/location.php
index f9e81e9f..d1d48248 100644
--- a/post/location.php
+++ b/post/location.php
@@ -19,6 +19,14 @@ if(isset($_POST['add_location'])){
$location_id = mysqli_insert_id($mysqli);
+ // Add Tags
+ if (isset($_POST['tags'])) {
+ foreach($_POST['tags'] as $tag) {
+ $tag = intval($tag);
+ mysqli_query($mysqli, "INSERT INTO location_tags SET location_id = $location_id, tag_id = $tag");
+ }
+ }
+
// Update Primay location in clients if primary location is checked
if ($location_primary == 1) {
mysqli_query($mysqli,"UPDATE locations SET location_primary = 0 WHERE location_client_id = $client_id");
@@ -82,6 +90,16 @@ if(isset($_POST['edit_location'])){
mysqli_query($mysqli,"UPDATE locations SET location_primary = 1 WHERE location_id = $location_id");
}
+ // Tags
+ // Delete existing tags
+ mysqli_query($mysqli, "DELETE FROM location_tags WHERE location_id = $location_id");
+
+ // Add new tags
+ foreach($_POST['tags'] as $tag) {
+ $tag = intval($tag);
+ mysqli_query($mysqli, "INSERT INTO location_tags SET location_id = $location_id, tag_id = $tag");
+ }
+
//Check to see if a file is attached
if($_FILES['file']['tmp_name'] != ''){
@@ -174,6 +192,10 @@ if(isset($_GET['delete_location'])){
mysqli_query($mysqli,"DELETE FROM locations WHERE location_id = $location_id");
+ // Tags
+ // Delete existing tags
+ mysqli_query($mysqli, "DELETE FROM location_tags WHERE location_id = $location_id");
+
//Logging
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Location', log_action = 'Delete', log_description = '$session_name deleted location $location_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 = $location_id");
|