mirror of https://github.com/itflow-org/itflow
Allow searching the main clients list by client tags.
- DB Change: Prefixed columns in client_tags table with client_tags_ - Updated existing SQL references to client_tags.client_id and client_tags.tag_id to new names - clients.php: Added SQL joins/where/groupby logic to allow searching via tags
This commit is contained in:
parent
7805a8ee45
commit
67ea16e4fc
10
clients.php
10
clients.php
|
|
@ -14,14 +14,20 @@ $sql = mysqli_query(
|
|||
"SELECT SQL_CALC_FOUND_ROWS * FROM clients
|
||||
LEFT JOIN contacts ON clients.primary_contact = contacts.contact_id AND contact_archived_at IS NULL
|
||||
LEFT JOIN locations ON clients.primary_location = locations.location_id AND location_archived_at IS NULL
|
||||
LEFT JOIN client_tags on client_tags.client_tags_client_id = clients.client_id
|
||||
LEFT JOIN tags on tags.tag_id = client_tags.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%'
|
||||
AND client_archived_at IS NULL
|
||||
AND DATE(client_created_at) BETWEEN '$dtf' AND '$dtt'
|
||||
AND clients.company_id = $session_company_id
|
||||
GROUP BY client_id
|
||||
ORDER BY $sb $o LIMIT $record_from, $record_to
|
||||
");
|
||||
|
||||
var_dump(mysqli_error($mysqli));
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
?>
|
||||
|
|
@ -128,11 +134,11 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
|||
$client_updated_at = htmlentities($row['client_updated_at']);
|
||||
$client_archive_at = htmlentities($row['client_archived_at']);
|
||||
|
||||
//Client Tags
|
||||
// Client Tags
|
||||
|
||||
$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.tag_id = tags.tag_id WHERE client_tags.client_id = $client_id");
|
||||
$sql_client_tags = mysqli_query($mysqli, "SELECT * FROM client_tags LEFT JOIN tags ON client_tags.client_tags_tag_id = tags.tag_id WHERE client_tags.client_tags_client_id = $client_id");
|
||||
while ($row = mysqli_fetch_array($sql_client_tags)) {
|
||||
|
||||
$client_tag_id = intval($row['tag_id']);
|
||||
|
|
|
|||
|
|
@ -860,11 +860,20 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) {
|
|||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.3'");
|
||||
}
|
||||
|
||||
//if (CURRENT_DATABASE_VERSION == '0.4.3') {
|
||||
// Insert queries here required to update to DB version 0.4.4
|
||||
if (CURRENT_DATABASE_VERSION == '0.4.3') {
|
||||
// Insert queries here required to update to DB version 0.4.4
|
||||
mysqli_query($mysqli, "ALTER TABLE `client_tags` CHANGE `client_id` `client_tags_client_id` INT NOT NULL");
|
||||
mysqli_query($mysqli, "ALTER TABLE `client_tags` CHANGE `tag_id` `client_tags_tag_id` INT NOT NULL");
|
||||
|
||||
// Then, update the database to the next sequential version
|
||||
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.4'");
|
||||
mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.4'");
|
||||
}
|
||||
|
||||
//if (CURRENT_DATABASE_VERSION == '0.4.4') {
|
||||
// Insert queries here required to update to DB version 0.4.5
|
||||
|
||||
// Then, update the database to the next sequential version
|
||||
// mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.5'");
|
||||
//}
|
||||
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -5,4 +5,4 @@
|
|||
* It is used in conjunction with database_updates.php
|
||||
*/
|
||||
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.4.3");
|
||||
DEFINE("LATEST_DATABASE_VERSION", "0.4.4");
|
||||
|
|
|
|||
6
db.sql
6
db.sql
|
|
@ -207,9 +207,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_id` int(11) NOT NULL,
|
||||
`tag_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`client_id`,`tag_id`)
|
||||
`client_tags_client_id` int(11) NOT NULL,
|
||||
`client_tags_tag_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`client_tags_client_id`,`client_tags_tag_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ if (isset($_GET['client_id'])) {
|
|||
|
||||
$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.tag_id = tags.tag_id WHERE client_tags.client_id = $client_id");
|
||||
$sql_client_tags = mysqli_query($mysqli, "SELECT * FROM client_tags LEFT JOIN tags ON client_tags.client_tags_tag_id = tags.tag_id WHERE client_tags.client_tags_client_id = $client_id");
|
||||
while ($row = mysqli_fetch_array($sql_client_tags)) {
|
||||
|
||||
$client_tag_id = intval($row['tag_id']);
|
||||
|
|
|
|||
12
post.php
12
post.php
|
|
@ -674,7 +674,7 @@ if(isset($_GET['delete_company'])){
|
|||
$sql = mysqli_query($mysqli,"SELECT client_id FROM clients WHERE company_id = $company_id");
|
||||
while($row = mysqli_fetch_array($sql)){
|
||||
$client_id = $row['client_id'];
|
||||
mysqli_query($mysqli,"DELETE FROM client_tags WHERE client_id = $client_id");
|
||||
mysqli_query($mysqli,"DELETE FROM client_tags WHERE client_tags_client_id = $client_id");
|
||||
mysqli_query($mysqli,"DELETE FROM shared_items WHERE item_client_id = $client_id");
|
||||
}
|
||||
mysqli_query($mysqli,"DELETE FROM clients WHERE company_id = $company_id");
|
||||
|
|
@ -1835,7 +1835,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_id = $client_id, tag_id = $tag");
|
||||
mysqli_query($mysqli,"INSERT INTO client_tags SET client_tags_client_id = $client_id, tag_id = $tag");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1897,12 +1897,12 @@ if(isset($_POST['edit_client'])){
|
|||
|
||||
//Tags
|
||||
//Delete existing tags
|
||||
mysqli_query($mysqli,"DELETE FROM client_tags WHERE client_id = $client_id");
|
||||
mysqli_query($mysqli,"DELETE FROM client_tags WHERE client_tags_client_id = $client_id");
|
||||
|
||||
//Add new tags
|
||||
foreach($_POST['tags'] as $tag){
|
||||
$tag = intval($tag);
|
||||
mysqli_query($mysqli,"INSERT INTO client_tags SET client_id = $client_id, tag_id = $tag");
|
||||
mysqli_query($mysqli,"INSERT INTO client_tags SET client_tags_client_id = $client_id, client_tags_tag_id = $tag");
|
||||
}
|
||||
|
||||
//Logging
|
||||
|
|
@ -1972,7 +1972,7 @@ if(isset($_GET['delete_client'])){
|
|||
mysqli_query($mysqli,"DELETE FROM api_keys WHERE api_key_client_id = $client_id");
|
||||
mysqli_query($mysqli,"DELETE FROM assets WHERE asset_client_id = $client_id");
|
||||
mysqli_query($mysqli,"DELETE FROM certificates WHERE certificate_client_id = $client_id");
|
||||
mysqli_query($mysqli,"DELETE FROM client_tags WHERE client_id = $client_id");
|
||||
mysqli_query($mysqli,"DELETE FROM client_tags WHERE client_tags_client_id = $client_id");
|
||||
mysqli_query($mysqli,"DELETE FROM contacts WHERE contact_client_id = $client_id");
|
||||
mysqli_query($mysqli,"DELETE FROM documents WHERE document_client_id = $client_id");
|
||||
|
||||
|
|
@ -7744,7 +7744,7 @@ if(isset($_GET['deactivate_shared_item'])){
|
|||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Sharing', log_action = 'Delete', log_description = '$session_name deactivated shared $item_type link. Item ID: $item_related_id. Share ID $item_id', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $item_client_id, log_user_id = $session_user_id, log_entity_id = $item_id, company_id = $session_company_id");
|
||||
|
||||
$_SESSION['alert_message'] = "Link deactivated";
|
||||
|
||||
|
||||
header("Location: " . $_SERVER["HTTP_REFERER"]);
|
||||
}
|
||||
|
||||
|
|
|
|||
12
ticket.php
12
ticket.php
|
|
@ -28,7 +28,7 @@ if (isset($_GET['ticket_id'])) {
|
|||
$client_name = htmlentities($row['client_name']);
|
||||
$client_type = htmlentities($row['client_type']);
|
||||
$client_website = htmlentities($row['client_website']);
|
||||
|
||||
|
||||
$client_net_terms = intval($row['client_net_terms']);
|
||||
if ($client_net_terms == 0) {
|
||||
$client_net_terms = $config_default_net_terms;
|
||||
|
|
@ -51,7 +51,7 @@ if (isset($_GET['ticket_id'])) {
|
|||
$ticket_priority_display = "-";
|
||||
}
|
||||
$ticket_feedback = htmlentities($row['ticket_feedback']);
|
||||
|
||||
|
||||
$ticket_status = htmlentities($row['ticket_status']);
|
||||
if ($ticket_status == "Open") {
|
||||
$ticket_status_display = "<span class='p-2 badge badge-primary'>$ticket_status</span>";
|
||||
|
|
@ -60,12 +60,12 @@ if (isset($_GET['ticket_id'])) {
|
|||
} else {
|
||||
$ticket_status_display = "<span class='p-2 badge badge-secondary'>$ticket_status</span>";
|
||||
}
|
||||
|
||||
|
||||
$ticket_created_at = htmlentities($row['ticket_created_at']);
|
||||
$ticket_date = date('Y-m-d', strtotime($ticket_created_at));
|
||||
$ticket_updated_at = htmlentities($row['ticket_updated_at']);
|
||||
$ticket_closed_at = htmlentities($row['ticket_closed_at']);
|
||||
|
||||
|
||||
$ticket_assigned_to = intval($row['ticket_assigned_to']);
|
||||
if (empty($ticket_assigned_to)) {
|
||||
$ticket_assigned_to_display = "<span class='text-danger'>Not Assigned</span>";
|
||||
|
|
@ -141,7 +141,7 @@ if (isset($_GET['ticket_id'])) {
|
|||
//Client Tags
|
||||
$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.tag_id = tags.tag_id WHERE client_tags.client_id = $client_id");
|
||||
$sql_client_tags = mysqli_query($mysqli, "SELECT * FROM client_tags LEFT JOIN tags ON client_tags.client_tags_tag_id = tags.tag_id WHERE client_tags.client_tags_client_id = $client_id");
|
||||
while ($row = mysqli_fetch_array($sql_client_tags)) {
|
||||
|
||||
$client_tag_id = intval($row['tag_id']);
|
||||
|
|
@ -188,7 +188,7 @@ if (isset($_GET['ticket_id'])) {
|
|||
|
||||
// Get technicians to assign the ticket to
|
||||
$sql_assign_to_select = mysqli_query(
|
||||
$mysqli,
|
||||
$mysqli,
|
||||
"SELECT users.user_id, user_name FROM users
|
||||
LEFT JOIN user_companies ON users.user_id = user_companies.user_id
|
||||
LEFT JOIN user_settings on users.user_id = user_settings.user_id
|
||||
|
|
|
|||
Loading…
Reference in New Issue