diff --git a/agent/ajax.php b/agent/ajax.php index 40d7ca1d9..afbe60d45 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -294,7 +294,7 @@ if (isset($_GET['get_active_clients'])) { $mysqli, "SELECT client_id, client_name FROM clients WHERE client_archived_at IS NULL - $access_permission_query + " . clientScopeSql('clients.client_id') . " ORDER BY client_accessed_at DESC" ); @@ -320,7 +320,7 @@ if (isset($_GET['get_client_contacts'])) { "SELECT contact_id, contact_name, contact_title, contact_email, contact_primary, contact_important, contact_technical FROM contacts LEFT JOIN clients on contact_client_id = client_id WHERE contacts.contact_archived_at IS NULL AND contact_client_id = $client_id - $access_permission_query + " . clientScopeSql('contact_client_id') . " ORDER BY contact_primary DESC, contact_technical DESC, contact_important DESC, contact_name" ); @@ -350,7 +350,7 @@ if (isset($_GET['get_client_assets'])) { LEFT JOIN clients on asset_client_id = client_id LEFT JOIN contacts ON contact_id = asset_contact_id WHERE assets.asset_archived_at IS NULL AND asset_client_id = $client_id - $access_permission_query + " . clientScopeSql('asset_client_id') . " ORDER BY asset_type ASC, asset_favorite DESC, asset_name" ); @@ -379,7 +379,7 @@ if (isset($_GET['get_client_locations'])) { "SELECT location_id, location_name FROM locations LEFT JOIN clients on location_client_id = client_id WHERE locations.location_archived_at IS NULL AND location_client_id = $client_id - $access_permission_query + " . clientScopeSql('location_client_id') . " ORDER BY location_primary DESC, location_name ASC" ); @@ -408,7 +408,7 @@ if (isset($_GET['get_client_vendors'])) { "SELECT vendor_id, vendor_name FROM vendors LEFT JOIN clients on vendor_client_id = client_id WHERE vendors.vendor_archived_at IS NULL AND vendor_client_id = $client_id - $access_permission_query + " . clientScopeSql('vendor_client_id') . " ORDER BY vendor_name ASC" ); @@ -437,7 +437,7 @@ if (isset($_GET['get_client_projects'])) { "SELECT project_id, project_name FROM projects LEFT JOIN clients on project_client_id = client_id WHERE projects.project_archived_at IS NULL AND projects.project_completed_at IS NULL AND project_client_id = $client_id - $access_permission_query + " . clientScopeSql('project_client_id') . " ORDER BY project_name ASC" ); diff --git a/agent/assets.php b/agent/assets.php index 32eb370ce..bb0d8ded4 100644 --- a/agent/assets.php +++ b/agent/assets.php @@ -124,7 +124,7 @@ $row = mysqli_fetch_assoc(mysqli_query($mysqli, " LEFT JOIN tags ON tag_id = asset_tag_tag_id WHERE $archive_query $tag_query - $access_permission_query + " . clientScopeSql('asset_client_id') . " $client_query GROUP BY asset_id ) AS filtered_assets; @@ -161,7 +161,7 @@ $sql = mysqli_query( $tag_query AND (asset_name LIKE '%$q%' OR asset_description LIKE '%$q%' OR asset_type LIKE '%$q%' OR interface_ip LIKE '%$q%' OR interface_ipv6 LIKE '%$q%' OR interface_mac LIKE '%$q%' OR asset_make LIKE '%$q%' OR asset_model LIKE '%$q%' OR asset_serial LIKE '%$q%' OR asset_os LIKE '%$q%' OR contact_name LIKE '%$q%' OR location_name LIKE '%$q%' OR client_name LIKE '%$q%' OR tag_name LIKE '%$q%') AND ($type_query) - $access_permission_query + " . clientScopeSql('asset_client_id') . " $location_query $expire_query $client_query @@ -288,7 +288,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); FROM clients JOIN assets ON asset_client_id = client_id WHERE $archive_query - $access_permission_query + " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC "); while ($row = mysqli_fetch_assoc($sql_clients_filter)) { diff --git a/agent/calendar.php b/agent/calendar.php index ead5c3b93..ceb20d164 100644 --- a/agent/calendar.php +++ b/agent/calendar.php @@ -341,7 +341,7 @@ while ($row = mysqli_fetch_assoc($sql)) { } // Invoices Created - $sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN invoices ON client_id = invoice_client_id $client_query $access_permission_query"); + $sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN invoices ON client_id = invoice_client_id $client_query " . clientScopeSql('clients.client_id') . ""); while ($row = mysqli_fetch_assoc($sql)) { $event_id = intval($row['invoice_id']); $scope = strval($row['invoice_scope']); @@ -356,7 +356,7 @@ while ($row = mysqli_fetch_assoc($sql)) { } // Quotes Created - $sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN quotes ON client_id = quote_client_id $client_query $access_permission_query"); + $sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN quotes ON client_id = quote_client_id $client_query " . clientScopeSql('clients.client_id') . ""); while ($row = mysqli_fetch_assoc($sql)) { $event_id = intval($row['quote_id']); $event_title = json_encode($row['quote_prefix'] . $row['quote_number'] . " " . $row['quote_scope']); @@ -370,7 +370,7 @@ while ($row = mysqli_fetch_assoc($sql)) { LEFT JOIN tickets ON client_id = ticket_client_id LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id LEFT JOIN users ON ticket_assigned_to = user_id - $client_query $access_permission_query" + $client_query " . clientScopeSql('clients.client_id') . "" ); while ($row = mysqli_fetch_assoc($sql)) { $event_id = intval($row['ticket_id']); @@ -404,7 +404,7 @@ while ($row = mysqli_fetch_assoc($sql)) { $sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN recurring_tickets ON client_id = recurring_ticket_client_id LEFT JOIN users ON recurring_ticket_assigned_to = user_id - $client_query $access_permission_query" + $client_query " . clientScopeSql('clients.client_id') . "" ); while ($row = mysqli_fetch_assoc($sql)) { $event_id = intval($row['recurring_ticket_id']); @@ -429,7 +429,7 @@ while ($row = mysqli_fetch_assoc($sql)) { LEFT JOIN tickets ON client_id = ticket_client_id LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id LEFT JOIN users ON ticket_assigned_to = user_id - $client_query $access_permission_query AND ticket_schedule IS NOT NULL" + $client_query " . clientScopeSql('clients.client_id') . " AND ticket_schedule IS NOT NULL" ); while ($row = mysqli_fetch_assoc($sql)) { $event_id = intval($row['ticket_id']); @@ -460,7 +460,7 @@ while ($row = mysqli_fetch_assoc($sql)) { } // Vendors Added Created - $sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN vendors ON client_id = vendor_client_id $client_query $access_permission_query"); + $sql = mysqli_query($mysqli, "SELECT * FROM clients LEFT JOIN vendors ON client_id = vendor_client_id $client_query " . clientScopeSql('clients.client_id') . ""); while ($row = mysqli_fetch_assoc($sql)) { $event_id = intval($row['vendor_id']); $client_id = intval($row['client_id']); diff --git a/agent/certificates.php b/agent/certificates.php index 5b1219868..ce8dec84f 100644 --- a/agent/certificates.php +++ b/agent/certificates.php @@ -65,7 +65,7 @@ $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS * FROM certificates LEFT JOIN clients ON client_id = certificate_client_id WHERE $archive_query AND (certificate_name LIKE '%$q%' OR certificate_domain LIKE '%$q%' OR certificate_description LIKE '%$q%' OR certificate_issued_by LIKE '%$q%' OR client_name LIKE '%$q%') - $access_permission_query + " . clientScopeSql('certificate_client_id') . " $client_query $expire_query ORDER BY $sort $order LIMIT $record_from, $record_to" @@ -122,7 +122,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); FROM clients JOIN certificates ON certificate_client_id = client_id WHERE $archive_query - $access_permission_query + " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC "); while ($row = mysqli_fetch_assoc($sql_clients_filter)) { diff --git a/agent/clients.php b/agent/clients.php index 9c621dd79..cd831c582 100644 --- a/agent/clients.php +++ b/agent/clients.php @@ -67,7 +67,7 @@ $sql = mysqli_query( AND client_$archive_query AND DATE(client_created_at) BETWEEN '$dtf' AND '$dtt' $leads_query - $access_permission_query + " . clientScopeSql('clients.client_id') . " $tag_query $industry_query $referral_query diff --git a/agent/contacts.php b/agent/contacts.php index e716fcf84..933d02e42 100644 --- a/agent/contacts.php +++ b/agent/contacts.php @@ -74,7 +74,7 @@ $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS contacts.*, clients.*, WHERE $archive_query $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%' OR client_name LIKE '%$q%') - $access_permission_query + " . clientScopeSql('contact_client_id') . " $client_query $location_query GROUP BY contact_id @@ -193,7 +193,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); FROM clients JOIN contacts ON contact_client_id = client_id WHERE $archive_query - $access_permission_query + " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC "); while ($row = mysqli_fetch_assoc($sql_clients_filter)) { diff --git a/agent/credentials.php b/agent/credentials.php index cd59b4a67..3b9797fa9 100644 --- a/agent/credentials.php +++ b/agent/credentials.php @@ -90,7 +90,7 @@ $sql = mysqli_query( $tag_query AND (c.credential_name LIKE '%$q%' OR c.credential_description LIKE '%$q%' OR c.credential_uri LIKE '%$q%' OR tag_name LIKE '%$q%' OR client_name LIKE '%$q%') $location_query - $access_permission_query + " . clientScopeSql('credential_client_id') . " $client_query GROUP BY c.credential_id ORDER BY c.credential_favorite DESC, $sort $order LIMIT $record_from, $record_to" @@ -204,7 +204,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); FROM clients JOIN credentials ON credential_client_id = client_id WHERE $archive_query - $access_permission_query + " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC "); while ($row = mysqli_fetch_assoc($sql_clients_filter)) { diff --git a/agent/domains.php b/agent/domains.php index 3ab3d3bce..a04b4df13 100644 --- a/agent/domains.php +++ b/agent/domains.php @@ -78,7 +78,7 @@ $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS domains.*, clients.*, LEFT JOIN vendors AS webhost ON domains.domain_webhost = webhost.vendor_id WHERE (domains.domain_name LIKE '%$q%' OR domains.domain_description LIKE '%$q%' OR registrar.vendor_name LIKE '%$q%' OR dnshost.vendor_name LIKE '%$q%' OR mailhost.vendor_name LIKE '%$q%' OR webhost.vendor_name LIKE '%$q%' OR client_name LIKE '%$q%') AND $archive_query - $access_permission_query + " . clientScopeSql('domain_client_id') . " $client_query $expire_query ORDER BY $sort $order LIMIT $record_from, $record_to"); @@ -134,7 +134,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); FROM clients JOIN domains ON domain_client_id = client_id WHERE $archive_query - $access_permission_query + " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC "); while ($row = mysqli_fetch_assoc($sql_clients_filter)) { diff --git a/agent/expenses.php b/agent/expenses.php index beb8bbac6..1e82aacf2 100644 --- a/agent/expenses.php +++ b/agent/expenses.php @@ -52,7 +52,7 @@ $sql = mysqli_query( $category_query AND (vendor_name LIKE '%$q%' OR client_name LIKE '%$q%' OR category_name LIKE '%$q%' OR account_name LIKE '%$q%' OR expense_description LIKE '%$q%' OR expense_amount LIKE '%$q%') $account_query - $access_permission_query + " . clientScopeSql('expense_client_id') . " ORDER BY $sort $order LIMIT $record_from, $record_to" ); diff --git a/agent/global_search.php b/agent/global_search.php index a82c776a6..3d5017346 100644 --- a/agent/global_search.php +++ b/agent/global_search.php @@ -32,7 +32,7 @@ if (isset($_GET['query'])) { LEFT JOIN locations ON clients.client_id = locations.location_client_id AND location_primary = 1 WHERE client_archived_at IS NULL AND (client_name LIKE '%$query%' OR client_abbreviation LIKE '%$query%') - $access_permission_query + " . clientScopeSql('clients.client_id') . " ORDER BY client_id DESC LIMIT 5" ); @@ -44,7 +44,7 @@ if (isset($_GET['query'])) { OR contact_email LIKE '%$query%' OR contact_phone LIKE '%$phone_query%' OR contact_mobile LIKE '%$phone_query%') - $access_permission_query + " . clientScopeSql('contact_client_id') . " ORDER BY contact_id DESC LIMIT 5" ); @@ -52,7 +52,7 @@ if (isset($_GET['query'])) { LEFT JOIN clients ON vendor_client_id = client_id WHERE vendor_archived_at IS NULL AND (vendor_name LIKE '%$query%' OR vendor_phone LIKE '%$phone_query%') - $access_permission_query + " . clientScopeSql('vendor_client_id') . " ORDER BY vendor_id DESC LIMIT 5" ); @@ -60,7 +60,7 @@ if (isset($_GET['query'])) { LEFT JOIN clients ON domain_client_id = client_id WHERE domain_archived_at IS NULL AND domain_name LIKE '%$query%' - $access_permission_query + " . clientScopeSql('domain_client_id') . " ORDER BY domain_id DESC LIMIT 5" ); @@ -74,7 +74,7 @@ if (isset($_GET['query'])) { LEFT JOIN clients on document_client_id = clients.client_id WHERE document_archived_at IS NULL AND MATCH(document_content_raw) AGAINST ('$query') - $access_permission_query + " . clientScopeSql('document_client_id') . " ORDER BY document_id DESC LIMIT 5" ); @@ -84,7 +84,7 @@ if (isset($_GET['query'])) { WHERE file_archived_at IS NULL AND (file_name LIKE '%$query%' OR file_description LIKE '%$query%') - $access_permission_query + " . clientScopeSql('file_client_id') . " ORDER BY file_id DESC LIMIT 5" ); @@ -96,7 +96,7 @@ if (isset($_GET['query'])) { OR ticket_details LIKE '%$query%' OR CONCAT(ticket_prefix,ticket_number) LIKE '%$query%' OR ticket_number = '$ticket_num_query') - $access_permission_query + " . clientScopeSql('tickets.ticket_client_id') . " ORDER BY ticket_id DESC LIMIT 5" ); @@ -104,7 +104,7 @@ if (isset($_GET['query'])) { LEFT JOIN clients ON recurring_ticket_client_id = client_id WHERE (recurring_ticket_subject LIKE '%$query%' OR recurring_ticket_details LIKE '%$query%') - $access_permission_query + " . clientScopeSql('recurring_ticket_client_id') . " ORDER BY recurring_ticket_id DESC LIMIT 5" ); @@ -113,7 +113,7 @@ if (isset($_GET['query'])) { LEFT JOIN clients ON credential_client_id = client_id WHERE credential_archived_at IS NULL AND (credential_name LIKE '%$query%' OR credential_description LIKE '%$query%') - $access_permission_query + " . clientScopeSql('credential_client_id') . " ORDER BY credential_id DESC LIMIT 5" ); @@ -122,7 +122,7 @@ if (isset($_GET['query'])) { LEFT JOIN categories ON quote_category_id = category_id WHERE quote_archived_at IS NULL AND (CONCAT(quote_prefix,quote_number) LIKE '%$query%' OR quote_number LIKE '%$query%' OR quote_scope LIKE '%$query%') - $access_permission_query + " . clientScopeSql('quote_client_id') . " ORDER BY quote_number DESC LIMIT 5" ); @@ -131,7 +131,7 @@ if (isset($_GET['query'])) { LEFT JOIN categories ON invoice_category_id = category_id WHERE invoice_archived_at IS NULL AND (CONCAT(invoice_prefix,invoice_number) LIKE '%$query%' OR invoice_number LIKE '%$query%' OR invoice_scope LIKE '%$query%') - $access_permission_query + " . clientScopeSql('invoice_client_id') . " ORDER BY invoice_number DESC LIMIT 5" ); @@ -142,7 +142,7 @@ if (isset($_GET['query'])) { LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1 WHERE asset_archived_at IS NULL AND (asset_name LIKE '%$query%' OR asset_description LIKE '%$query%' OR asset_type LIKE '%$query%' OR asset_make LIKE '%$query%' OR asset_model LIKE '%$query%' OR asset_serial LIKE '%$query%' OR asset_os LIKE '%$query%' OR interface_ip LIKE '%$query%' OR interface_nat_ip LIKE '%$query%' OR interface_mac LIKE '%$query%' OR asset_status LIKE '%$query%') - $access_permission_query + " . clientScopeSql('asset_client_id') . " ORDER BY asset_name DESC LIMIT 5" ); @@ -151,7 +151,7 @@ if (isset($_GET['query'])) { LEFT JOIN clients ON ticket_client_id = client_id WHERE ticket_reply_archived_at IS NULL AND (ticket_reply LIKE '%$query%') - $access_permission_query + " . clientScopeSql('ticket_client_id') . " ORDER BY ticket_id DESC, ticket_reply_id ASC LIMIT 20" ); diff --git a/agent/includes/client_overview_side_nav.php b/agent/includes/client_overview_side_nav.php index 53d63c197..6b3c912d8 100644 --- a/agent/includes/client_overview_side_nav.php +++ b/agent/includes/client_overview_side_nav.php @@ -1,31 +1,31 @@ diff --git a/agent/includes/get_side_nav_counts.php b/agent/includes/get_side_nav_counts.php index 87dac0873..14bab8da9 100644 --- a/agent/includes/get_side_nav_counts.php +++ b/agent/includes/get_side_nav_counts.php @@ -2,31 +2,31 @@ // Get Main Side Bar Badge Counts // Active Clients Count -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('client_id') AS num FROM clients WHERE client_archived_at IS NULL $access_permission_query")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('client_id') AS num FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . "")); $num_active_clients = $row['num']; // Active Ticket Count -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('ticket_id') AS num FROM tickets LEFT JOIN clients ON client_id = ticket_client_id WHERE ticket_archived_at IS NULL AND ticket_closed_at IS NULL AND ticket_status != 4 $access_permission_query")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('ticket_id') AS num FROM tickets WHERE ticket_archived_at IS NULL AND ticket_closed_at IS NULL AND ticket_status != 4 " . clientScopeSql('ticket_client_id') . "")); $num_active_tickets = $row['num']; // Recurring Ticket Count -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_ticket_id') AS num FROM recurring_tickets LEFT JOIN clients ON client_id = recurring_ticket_client_id WHERE 1 = 1 $access_permission_query")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_ticket_id') AS num FROM recurring_tickets WHERE 1 = 1 " . clientScopeSql('recurring_ticket_client_id') . "")); $num_recurring_tickets = $row['num']; // Active Project Count -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('project_id') AS num FROM projects LEFT JOIN clients ON project_client_id = client_id WHERE project_archived_at IS NULL AND project_completed_at IS NULL $access_permission_query")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('project_id') AS num FROM projects WHERE project_archived_at IS NULL AND project_completed_at IS NULL " . clientScopeSql('project_client_id') . "")); $num_active_projects = $row['num']; // Open Invoices Count -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices LEFT JOIN clients ON invoice_client_id = client_id WHERE (invoice_status = 'Sent' OR invoice_status = 'Viewed' OR invoice_status = 'Partial' OR invoice_status = 'Draft') AND invoice_archived_at IS NULL $access_permission_query")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('invoice_id') AS num FROM invoices WHERE (invoice_status = 'Sent' OR invoice_status = 'Viewed' OR invoice_status = 'Partial' OR invoice_status = 'Draft') AND invoice_archived_at IS NULL " . clientScopeSql('invoice_client_id') . "")); $num_open_invoices = $row['num']; // Recurring Invoice Count -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_invoice_id') AS num FROM recurring_invoices LEFT JOIN clients ON recurring_invoice_client_id = client_id WHERE recurring_invoice_archived_at IS NULL $access_permission_query")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('recurring_invoice_id') AS num FROM recurring_invoices WHERE recurring_invoice_archived_at IS NULL " . clientScopeSql('recurring_invoice_client_id') . "")); $num_recurring_invoices = $row['num']; // Open Quotes Count -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('quote_id') AS num FROM quotes LEFT JOIN clients ON quote_client_id = client_id WHERE (quote_status = 'Sent' OR quote_status = 'Viewed') AND quote_archived_at IS NULL $access_permission_query")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('quote_id') AS num FROM quotes WHERE (quote_status = 'Sent' OR quote_status = 'Viewed') AND quote_archived_at IS NULL " . clientScopeSql('quote_client_id') . "")); $num_open_quotes = $row['num']; // Recurring Expenses Count diff --git a/agent/income.php b/agent/income.php index e74f044fa..31a98a02c 100644 --- a/agent/income.php +++ b/agent/income.php @@ -91,7 +91,7 @@ $income_query = LEFT JOIN categories ON invoice_category_id = category_id WHERE payment_archived_at IS NULL $payment_client_query - $access_permission_query + " . clientScopeSql('invoice_client_id') . " UNION ALL @@ -120,7 +120,8 @@ $income_query = LEFT JOIN transfers ON transfer_revenue_id = revenue_id WHERE revenue_archived_at IS NULL AND transfer_id IS NULL - $revenue_client_query"; + $revenue_client_query + " . clientScopeSql('revenue_client_id') . ""; $income_filter_query = "WHERE DATE(income_date) BETWEEN '$dtf' AND '$dtt' diff --git a/agent/invoice.php b/agent/invoice.php index 296d1c816..5bd6cb90c 100644 --- a/agent/invoice.php +++ b/agent/invoice.php @@ -21,7 +21,7 @@ if (isset($_GET['invoice_id'])) { LEFT JOIN contacts ON client_id = contact_client_id AND contact_primary = 1 LEFT JOIN locations ON client_id = location_client_id AND location_primary = 1 WHERE invoice_id = $invoice_id - $access_permission_query + " . clientScopeSql('invoice_client_id') . " LIMIT 1" ); diff --git a/agent/invoices.php b/agent/invoices.php index 7e5c7a517..e56a96527 100644 --- a/agent/invoices.php +++ b/agent/invoices.php @@ -11,7 +11,7 @@ if (isset($_GET['client_id'])) { $client_url = "client_id=$client_id&"; } else { require_once "includes/inc_all.php"; - $client_query = "$access_permission_query"; + $client_query = clientScopeSql('invoice_client_id'); $client_url = ''; } @@ -103,7 +103,7 @@ $sql = mysqli_query( $category_query AND DATE(invoice_date) BETWEEN '$dtf' AND '$dtt' AND (CONCAT(invoice_prefix,invoice_number) LIKE '%$q%' OR invoice_scope LIKE '%$q%' OR client_name LIKE '%$q%' OR invoice_status LIKE '%$q%' OR invoice_amount LIKE '%$q%' OR category_name LIKE '%$q%') - $access_permission_query + " . clientScopeSql('invoice_client_id') . " $client_query ORDER BY $sort $order LIMIT $record_from, $record_to" ); diff --git a/agent/locations.php b/agent/locations.php index e041987a8..a5eb1ffe0 100644 --- a/agent/locations.php +++ b/agent/locations.php @@ -64,7 +64,7 @@ $sql = mysqli_query( WHERE $archive_query $tag_query AND (location_name LIKE '%$q%' OR location_description LIKE '%$q%' OR location_address LIKE '%$q%' OR location_city LIKE '%$q%' OR location_state LIKE '%$q%' OR location_zip LIKE '%$q%' OR location_country LIKE '%$q%' OR location_phone LIKE '%$phone_query%' OR tag_name LIKE '%$q%' OR client_name LIKE '%$q%') - $access_permission_query + " . clientScopeSql('location_client_id') . " $client_query GROUP BY location_id ORDER BY location_primary DESC, $sort $order LIMIT $record_from, $record_to" @@ -154,7 +154,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); FROM clients JOIN locations ON location_client_id = client_id WHERE $archive_query - $access_permission_query + " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC "); while ($row = mysqli_fetch_assoc($sql_clients_filter)) { diff --git a/agent/modals/asset/asset_add.php b/agent/modals/asset/asset_add.php index c6da21baf..21cf097c2 100644 --- a/agent/modals/asset/asset_add.php +++ b/agent/modals/asset/asset_add.php @@ -12,7 +12,7 @@ if ($client_id) { $sql_location_select = mysqli_query($mysqli, "SELECT location_id, location_name FROM locations WHERE location_archived_at IS NULL AND location_client_id = $client_id ORDER BY location_name ASC"); $sql_contact_select = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_archived_at IS NULL AND contact_client_id = $client_id ORDER BY contact_name ASC"); } else { - $sql_client_select = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC"); + $sql_client_select = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC"); } // OS typeahead suggestions diff --git a/agent/modals/certificate/certificate_add.php b/agent/modals/certificate/certificate_add.php index 6fb80d1dd..29d2b33dc 100644 --- a/agent/modals/certificate/certificate_add.php +++ b/agent/modals/certificate/certificate_add.php @@ -50,7 +50,7 @@ ob_start(); diff --git a/agent/modals/contact/contact_add.php b/agent/modals/contact/contact_add.php index 5f7196562..294c071f3 100644 --- a/agent/modals/contact/contact_add.php +++ b/agent/modals/contact/contact_add.php @@ -7,7 +7,7 @@ $client_id = intval($_GET['client_id'] ?? 0); if ($client_id) { $sql_location_select = mysqli_query($mysqli, "SELECT location_id, location_name FROM locations WHERE location_archived_at IS NULL AND location_client_id = $client_id ORDER BY location_name ASC"); } else { - $sql_client_select = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC"); + $sql_client_select = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC"); } $sql_tags_select = mysqli_query($mysqli, "SELECT tag_id, tag_name FROM tags WHERE tag_type = 3 ORDER BY tag_name ASC"); diff --git a/agent/modals/credential/credential_add.php b/agent/modals/credential/credential_add.php index 7e0f4035e..4f5ebf339 100644 --- a/agent/modals/credential/credential_add.php +++ b/agent/modals/credential/credential_add.php @@ -54,7 +54,7 @@ ob_start(); diff --git a/agent/modals/domain/domain_add.php b/agent/modals/domain/domain_add.php index 50fae188b..1c57d62c6 100644 --- a/agent/modals/domain/domain_add.php +++ b/agent/modals/domain/domain_add.php @@ -48,7 +48,7 @@ ob_start(); diff --git a/agent/modals/expense/expense_add.php b/agent/modals/expense/expense_add.php index 32a865472..801150598 100644 --- a/agent/modals/expense/expense_add.php +++ b/agent/modals/expense/expense_add.php @@ -169,7 +169,7 @@ ob_start(); - No Client - - Select Client - - Select Client - - Select a Client - - Select Client - diff --git a/agent/modals/network/network_add.php b/agent/modals/network/network_add.php index 97eeafcf3..67abf4cef 100644 --- a/agent/modals/network/network_add.php +++ b/agent/modals/network/network_add.php @@ -54,7 +54,7 @@ ob_start(); diff --git a/agent/modals/project/project_add.php b/agent/modals/project/project_add.php index 09b0ef253..852efe405 100644 --- a/agent/modals/project/project_add.php +++ b/agent/modals/project/project_add.php @@ -30,7 +30,7 @@ ob_start(); - Client (Optional) - - Client (Optional) - - Client (Optional) - 'Search', 'value' => stripslashes(escapeHtml($q)), 'drop' => 'q'); } -// Ticket client access overide - This is the only way to show tickets without a client to agents with restricted client access -$access_permission_query_overide = ''; -if ($client_access_string) { - $access_permission_query_overide = "AND ticket_client_id IN (0,$client_access_string)"; -} +// Tickets with no client stay visible to restricted agents - clientScopeSql() includes 0 +$access_permission_query_overide = clientScopeSql('ticket_client_id'); /* * Columns the two views need. Explicit rather than SELECT * - the tickets diff --git a/agent/trips.php b/agent/trips.php index cd0458a3e..bc8abd7f6 100644 --- a/agent/trips.php +++ b/agent/trips.php @@ -24,7 +24,7 @@ $sql = mysqli_query( AND DATE(trip_date) BETWEEN '$dtf' AND '$dtt' AND trip_archived_at IS NULL $client_query - $access_permission_query + " . clientScopeSql('trip_client_id') . " ORDER BY $sort $order LIMIT $record_from, $record_to" ); diff --git a/agent/vendors.php b/agent/vendors.php index b8f2bd32b..000eedef4 100644 --- a/agent/vendors.php +++ b/agent/vendors.php @@ -23,7 +23,7 @@ $sql = mysqli_query( WHERE vendor_$archive_query AND (vendor_name LIKE '%$q%' OR vendor_description LIKE '%$q%' OR vendor_account_number LIKE '%$q%' OR vendor_website LIKE '%$q%' OR vendor_contact_name LIKE '%$q%' OR vendor_email LIKE '%$q%' OR vendor_phone LIKE '%$phone_query%') $client_query - $access_permission_query + " . clientScopeSql('vendor_client_id') . " ORDER BY $sort $order LIMIT $record_from, $record_to" ); diff --git a/functions/auth.php b/functions/auth.php index 570091e2a..d6acd13c7 100644 --- a/functions/auth.php +++ b/functions/auth.php @@ -84,8 +84,11 @@ function clientScopeSql($column) { $sql = ''; + // 0 is included deliberately: a record with no client isn't any client's data, so a + // restricted user keeps seeing it. This also matches the deny branch below, where 0 + // already passes NOT IN, and the old hand-rolled ticket override that did IN (0,...). if (!empty($client_access_array)) { - $sql .= " AND $column IN (" . implode(',', array_map('intval', $client_access_array)) . ")"; + $sql .= " AND $column IN (0," . implode(',', array_map('intval', $client_access_array)) . ")"; } if (!empty($client_deny_array)) { diff --git a/includes/load_user_session.php b/includes/load_user_session.php index 00c3997af..bfd61bb96 100644 --- a/includes/load_user_session.php +++ b/includes/load_user_session.php @@ -63,16 +63,7 @@ while ($row = mysqli_fetch_assoc($user_client_access_result)) { } } +// Client scoping for queries is built per-query by clientScopeSql() in functions/auth.php, +// which is column-aware. These strings remain for any caller that needs the raw lists. $client_access_string = implode(',', $client_access_array); $client_deny_string = implode(',', $client_deny_array); - -$access_permission_query = ""; -if (!$session_is_admin) { - // Restrict to the allow list (if any), then subtract the deny list - if ($client_access_string) { - $access_permission_query .= " AND clients.client_id IN ($client_access_string)"; - } - if ($client_deny_string) { - $access_permission_query .= " AND clients.client_id NOT IN ($client_deny_string)"; - } -}