mirror of
https://github.com/itflow-org/itflow
synced 2026-03-11 16:24:50 +00:00
DB Update Shorten Client Tag Fields and add Delete Client Tags to Delete Client and cleanup clients query
This commit is contained in:
26
clients.php
26
clients.php
@@ -44,24 +44,24 @@ $url_query_strings_sort = http_build_query($get_copy);
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"
|
||||
SELECT SQL_CALC_FOUND_ROWS clients.*, contacts.*, locations.*, GROUP_CONCAT(tags.tag_name) AS tag_names
|
||||
SELECT SQL_CALC_FOUND_ROWS clients.*, contacts.*, locations.*, GROUP_CONCAT(tag_name)
|
||||
FROM clients
|
||||
LEFT JOIN contacts ON clients.client_id = contacts.contact_client_id AND contact_primary = 1
|
||||
LEFT JOIN locations ON clients.client_id = locations.location_client_id AND location_primary = 1
|
||||
LEFT JOIN client_tags ON client_tags.client_tag_client_id = clients.client_id
|
||||
LEFT JOIN tags ON tags.tag_id = client_tags.client_tag_tag_id
|
||||
WHERE (clients.client_name LIKE '%$q%' OR clients.client_type LIKE '%$q%' OR clients.client_referral LIKE '%$q%'
|
||||
OR contacts.contact_email LIKE '%$q%' OR contacts.contact_name LIKE '%$q%' OR contacts.contact_phone LIKE '%$phone_query%'
|
||||
OR contacts.contact_mobile LIKE '%$phone_query%' OR locations.location_address LIKE '%$q%'
|
||||
OR locations.location_city LIKE '%$q%' OR locations.location_state LIKE '%$q%' OR locations.location_zip LIKE '%$q%'
|
||||
OR tags.tag_name LIKE '%$q%' OR clients.client_tax_id_number LIKE '%$q%')
|
||||
AND clients.client_$archive_query
|
||||
AND DATE(clients.client_created_at) BETWEEN '$dtf' AND '$dtt'
|
||||
AND clients.client_lead = $leads
|
||||
LEFT JOIN client_tags ON client_tags.client_id = clients.client_id
|
||||
LEFT JOIN tags ON tags.tag_id = client_tags.tag_id
|
||||
WHERE (client_name LIKE '%$q%' OR client_type LIKE '%$q%' OR client_referral LIKE '%$q%'
|
||||
OR contact_email LIKE '%$q%' OR contact_name LIKE '%$q%' OR contact_phone LIKE '%$phone_query%'
|
||||
OR contact_mobile LIKE '%$phone_query%' OR location_address LIKE '%$q%'
|
||||
OR location_city LIKE '%$q%' OR location_state LIKE '%$q%' OR location_zip LIKE '%$q%'
|
||||
OR tag_name LIKE '%$q%' OR client_tax_id_number LIKE '%$q%')
|
||||
AND client_$archive_query
|
||||
AND DATE(client_created_at) BETWEEN '$dtf' AND '$dtt'
|
||||
AND client_lead = $leads
|
||||
$access_permission_query
|
||||
$industry_query
|
||||
$referral_query
|
||||
GROUP BY clients.client_id
|
||||
GROUP BY client_id
|
||||
ORDER BY $sort $order
|
||||
LIMIT $record_from, $record_to
|
||||
");
|
||||
@@ -246,7 +246,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
$client_tag_name_display_array = array();
|
||||
$client_tag_id_array = array();
|
||||
$sql_client_tags = mysqli_query($mysqli, "SELECT * FROM client_tags LEFT JOIN tags ON client_tags.client_tag_tag_id = tags.tag_id WHERE client_tags.client_tag_client_id = $client_id ORDER BY tag_name ASC");
|
||||
$sql_client_tags = mysqli_query($mysqli, "SELECT * FROM client_tags LEFT JOIN tags ON client_tags.tag_id = tags.tag_id WHERE client_id = $client_id ORDER BY tag_name ASC");
|
||||
while ($row = mysqli_fetch_array($sql_client_tags)) {
|
||||
|
||||
$client_tag_id = intval($row['tag_id']);
|
||||
|
||||
@@ -1931,10 +1931,16 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
||||
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
|
||||
if (CURRENT_DATABASE_VERSION == '1.3.4') {
|
||||
mysqli_query($mysqli, "ALTER TABLE `client_tags` CHANGE `client_tag_client_id` `client_id` INT(11) NOT NULL");
|
||||
mysqli_query($mysqli, "ALTER TABLE `client_tags` CHANGE `client_tag_tag_id` `tag_id` INT(11) NOT NULL");
|
||||
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
|
||||
// // Then, update the database to the next sequential version
|
||||
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.5'");
|
||||
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '1.3.6'");
|
||||
// }
|
||||
|
||||
} else {
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
* It is used in conjunction with database_updates.php
|
||||
*/
|
||||
|
||||
DEFINE("LATEST_DATABASE_VERSION", "1.3.4");
|
||||
DEFINE("LATEST_DATABASE_VERSION", "1.3.5");
|
||||
|
||||
8
db.sql
8
db.sql
@@ -250,9 +250,9 @@ DROP TABLE IF EXISTS `client_tags`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `client_tags` (
|
||||
`client_tag_client_id` int(11) NOT NULL,
|
||||
`client_tag_tag_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`client_tag_client_id`,`client_tag_tag_id`)
|
||||
`client_id` int(11) NOT NULL,
|
||||
`tag_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`client_id`,`tag_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@@ -1952,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-31 16:12:51
|
||||
-- Dump completed on 2024-05-31 16:45:46
|
||||
|
||||
@@ -65,7 +65,7 @@ if (isset($_POST['add_client'])) {
|
||||
if (isset($_POST['tags'])) {
|
||||
foreach($_POST['tags'] as $tag) {
|
||||
$tag = intval($tag);
|
||||
mysqli_query($mysqli, "INSERT INTO client_tags SET client_tag_client_id = $client_id, client_tag_tag_id = $tag");
|
||||
mysqli_query($mysqli, "INSERT INTO client_tags SET client_id = $client_id, tag_id = $tag");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,12 +135,12 @@ if (isset($_POST['edit_client'])) {
|
||||
|
||||
// Tags
|
||||
// Delete existing tags
|
||||
mysqli_query($mysqli, "DELETE FROM client_tags WHERE client_tag_client_id = $client_id");
|
||||
mysqli_query($mysqli, "DELETE FROM client_tags WHERE client_id = $client_id");
|
||||
|
||||
// Add new tags
|
||||
foreach($_POST['tags'] as $tag) {
|
||||
$tag = intval($tag);
|
||||
mysqli_query($mysqli, "INSERT INTO client_tags SET client_tag_client_id = $client_id, client_tag_tag_id = $tag");
|
||||
mysqli_query($mysqli, "INSERT INTO client_tags SET client_id = $client_id, tag_id = $tag");
|
||||
}
|
||||
|
||||
// Logging
|
||||
@@ -297,6 +297,9 @@ if (isset($_GET['delete_client'])) {
|
||||
mysqli_query($mysqli, "DELETE FROM trips WHERE trip_client_id = $client_id");
|
||||
mysqli_query($mysqli, "DELETE FROM vendors WHERE vendor_client_id = $client_id");
|
||||
|
||||
// Delete tags
|
||||
mysqli_query($mysqli, "DELETE FROM client_tags WHERE client_id = $client_id");
|
||||
|
||||
//Delete Client Files
|
||||
removeDirectory('uploads/clients/$client_id');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user