mirror of
https://github.com/itflow-org/itflow
synced 2026-08-10 01:27:15 +00:00
clientScopeSql sweep whicn now removed the extra unessesary client joins
This commit is contained in:
@@ -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"
|
||||
);
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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"
|
||||
);
|
||||
|
||||
|
||||
@@ -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"
|
||||
);
|
||||
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
<?php
|
||||
// Badge Counts
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('contact_id') AS num FROM contacts LEFT JOIN clients ON contact_client_id = client_id WHERE contact_archived_at IS NULL AND client_archived_at IS NULL $access_permission_query"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('contact_id') AS num FROM contacts LEFT JOIN clients ON contact_client_id = client_id WHERE contact_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('contact_client_id') . ""));
|
||||
$num_contacts = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('location_id') AS num FROM locations LEFT JOIN clients ON location_client_id = client_id WHERE location_archived_at IS NULL AND client_archived_at IS NULL $access_permission_query"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('location_id') AS num FROM locations LEFT JOIN clients ON location_client_id = client_id WHERE location_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('location_client_id') . ""));
|
||||
$num_locations = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('asset_id') AS num FROM assets LEFT JOIN clients ON asset_client_id = client_id WHERE asset_archived_at IS NULL AND client_archived_at IS NULL $access_permission_query"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('asset_id') AS num FROM assets LEFT JOIN clients ON asset_client_id = client_id WHERE asset_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('asset_client_id') . ""));
|
||||
$num_assets = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('service_id') AS num FROM services LEFT JOIN clients ON service_client_id = client_id WHERE client_archived_at IS NULL $access_permission_query"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('service_id') AS num FROM services LEFT JOIN clients ON service_client_id = client_id WHERE client_archived_at IS NULL " . clientScopeSql('service_client_id') . ""));
|
||||
$num_services = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('credential_id') AS num FROM credentials LEFT JOIN clients ON credential_client_id = client_id WHERE credential_archived_at IS NULL AND client_archived_at IS NULL $access_permission_query"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('credential_id') AS num FROM credentials LEFT JOIN clients ON credential_client_id = client_id WHERE credential_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('credential_client_id') . ""));
|
||||
$num_credentials = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('network_id') AS num FROM networks LEFT JOIN clients ON network_client_id = client_id WHERE network_archived_at IS NULL AND client_archived_at IS NULL $access_permission_query"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('network_id') AS num FROM networks LEFT JOIN clients ON network_client_id = client_id WHERE network_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('network_client_id') . ""));
|
||||
$num_networks = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('domain_id') AS num FROM domains LEFT JOIN clients ON domain_client_id = client_id WHERE domain_archived_at IS NULL AND client_archived_at IS NULL $access_permission_query"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('domain_id') AS num FROM domains LEFT JOIN clients ON domain_client_id = client_id WHERE domain_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('domain_client_id') . ""));
|
||||
$num_domains = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('certificate_id') AS num FROM certificates LEFT JOIN clients ON certificate_client_id = client_id WHERE certificate_archived_at IS NULL AND client_archived_at IS NULL $access_permission_query"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('certificate_id') AS num FROM certificates LEFT JOIN clients ON certificate_client_id = client_id WHERE certificate_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('certificate_client_id') . ""));
|
||||
$num_certificates = $row['num'];
|
||||
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('software_id') AS num FROM software LEFT JOIN clients ON software_client_id = client_id WHERE software_archived_at IS NULL AND client_archived_at IS NULL $access_permission_query"));
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('software_id') AS num FROM software LEFT JOIN clients ON software_client_id = client_id WHERE software_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('software_client_id') . ""));
|
||||
$num_software = $row['num'];
|
||||
|
||||
?>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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"
|
||||
);
|
||||
|
||||
|
||||
@@ -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"
|
||||
);
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -50,7 +50,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -54,7 +54,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -48,7 +48,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -169,7 +169,7 @@ ob_start();
|
||||
<option value="0">- Select a Client (Optional) -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -36,7 +36,7 @@ ob_start();
|
||||
<option value="0">- No Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -182,7 +182,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql_clients = 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_clients = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name_select = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -205,7 +205,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE 1 = 1 $access_permission_query ORDER BY client_name ASC");
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE 1 = 1 " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name_select = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -32,7 +32,7 @@ ob_start();
|
||||
<option value="">- Select a Client -</option>
|
||||
<?php
|
||||
//select unarchived clients
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -55,7 +55,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -54,7 +54,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -30,7 +30,7 @@ ob_start();
|
||||
<select class="form-control select2" name="client_id">
|
||||
<option value="0">- No Client -</option>
|
||||
<?php
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -33,7 +33,7 @@ ob_start();
|
||||
<?php
|
||||
|
||||
//select unarchived clients
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -213,7 +213,7 @@ ob_start();
|
||||
<option value="0">- Client (Optional) -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -244,7 +244,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE 1 = 1 $access_permission_query ORDER BY client_name ASC");
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE 1 = 1 " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name_select = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -32,7 +32,7 @@ ob_start();
|
||||
<option value="">- Select a Client -</option>
|
||||
<?php
|
||||
//select unarchived clients
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -58,7 +58,7 @@ ob_start();
|
||||
<option value="">- Select a Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -57,7 +57,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -68,7 +68,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -33,7 +33,7 @@ ob_start();
|
||||
<option value="">- Select Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = 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 = 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");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name_select = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -62,7 +62,7 @@ ob_start();
|
||||
<option value="">- Select a Client -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_lead = 0 AND client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_lead = 0 AND client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']); ?>
|
||||
|
||||
@@ -42,7 +42,7 @@ ob_start();
|
||||
</div>
|
||||
<select class="form-control select2" name="new_client_id" id="client_select" required>
|
||||
<?php
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_lead = 0 AND client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_lead = 0 AND client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -4,14 +4,8 @@ require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
// 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)";
|
||||
}
|
||||
if ($client_deny_string) {
|
||||
$access_permission_query_overide .= " AND ticket_client_id NOT IN ($client_deny_string)";
|
||||
}
|
||||
// Tickets with no client stay visible to restricted agents - clientScopeSql() includes 0
|
||||
$access_permission_query_overide = clientScopeSql('ticket_client_id');
|
||||
|
||||
$ticket_id = intval($_GET['id']);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ $ticket_sql = mysqli_query(
|
||||
LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id
|
||||
LEFT JOIN categories ON ticket_category = category_id
|
||||
WHERE ticket_id = $ticket_id
|
||||
$access_permission_query
|
||||
" . clientScopeSql('ticket_client_id') . "
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ $sql_merge = mysqli_query($mysqli, "SELECT * FROM tickets
|
||||
LEFT JOIN clients ON client_id = ticket_client_id
|
||||
WHERE ticket_closed_at IS NULL
|
||||
AND ticket_id != $ticket_id
|
||||
$access_permission_query
|
||||
" . clientScopeSql('ticket_client_id') . "
|
||||
ORDER BY ticket_status ASC, ticket_id DESC"
|
||||
);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ $ticket_sql = mysqli_query(
|
||||
LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id
|
||||
LEFT JOIN categories ON ticket_category = category_id
|
||||
WHERE ticket_id = $ticket_id
|
||||
$access_permission_query
|
||||
" . clientScopeSql('ticket_client_id') . "
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ ob_start();
|
||||
<option value="0">- Client (Optional) -</option>
|
||||
<?php
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at is NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at is NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -150,7 +150,7 @@ ob_start();
|
||||
<option value="">- Client (Optional) -</option>
|
||||
<?php
|
||||
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name_select = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -151,7 +151,7 @@ ob_start();
|
||||
<option value="">- Client (Optional) -</option>
|
||||
<?php
|
||||
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL $access_permission_query ORDER BY client_name ASC");
|
||||
$sql_clients = mysqli_query($mysqli, "SELECT * FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name_select = escapeHtml($row['client_name']);
|
||||
|
||||
@@ -63,7 +63,7 @@ $sql = mysqli_query(
|
||||
LEFT JOIN locations ON location_id = network_location_id
|
||||
WHERE $archive_query
|
||||
AND (network_name LIKE '%$q%' OR network_description LIKE '%$q%' OR network_vlan LIKE '%$q%' OR network LIKE '%$q%' OR network_gateway LIKE '%$q%' OR network_subnet LIKE '%$q%' OR network_primary_dns LIKE '%$q%' OR network_secondary_dns LIKE '%$q%' OR network_dhcp_range LIKE '%$q%' OR location_name LIKE '%$q%' OR client_name LIKE '%$q%')
|
||||
$access_permission_query
|
||||
" . clientScopeSql('network_client_id') . "
|
||||
$location_query
|
||||
$client_query
|
||||
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
||||
@@ -153,7 +153,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
FROM clients
|
||||
JOIN networks ON network_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)) {
|
||||
|
||||
@@ -1442,7 +1442,7 @@ if (isset($_POST['export_assets'])) {
|
||||
$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
|
||||
|
||||
@@ -408,7 +408,7 @@ if (isset($_POST['export_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 certificate_name ASC"
|
||||
|
||||
@@ -452,7 +452,7 @@ if (isset($_POST['export_clients'])) {
|
||||
AND $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
|
||||
|
||||
@@ -1349,7 +1349,7 @@ if (isset($_POST['export_contacts'])) {
|
||||
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 '%$q%' OR contact_mobile LIKE '%$q%' OR client_name LIKE '%$q%' OR tag_name LIKE '%$q%')
|
||||
$access_permission_query
|
||||
" . clientScopeSql('contact_client_id') . "
|
||||
$client_query
|
||||
$location_query
|
||||
GROUP BY contact_id
|
||||
|
||||
@@ -487,7 +487,7 @@ if (isset($_POST['export_credentials'])) {
|
||||
WHERE $archive_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%')
|
||||
$access_permission_query
|
||||
" . clientScopeSql('credential_client_id') . "
|
||||
$client_query
|
||||
GROUP BY c.credential_id
|
||||
ORDER BY c.credential_name ASC"
|
||||
|
||||
@@ -530,7 +530,7 @@ if (isset($_POST['export_domains'])) {
|
||||
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 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 domains.domain_name ASC"
|
||||
|
||||
@@ -370,7 +370,7 @@ if (isset($_POST['export_expenses'])) {
|
||||
$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 expense_date ASC"
|
||||
);
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ if (isset($_POST['export_income'])) {
|
||||
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
|
||||
|
||||
|
||||
@@ -730,7 +730,7 @@ if (isset($_POST['export_invoices'])) {
|
||||
$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 invoice_number ASC"
|
||||
);
|
||||
@@ -823,7 +823,7 @@ if (isset($_GET['export_invoice_pdf'])) {
|
||||
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
|
||||
WHERE invoice_id = $invoice_id
|
||||
$access_permission_query
|
||||
" . clientScopeSql('invoice_client_id') . "
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
@@ -1052,7 +1052,7 @@ if (isset($_GET['export_invoice_packing_slip'])) {
|
||||
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
|
||||
WHERE invoice_id = $invoice_id
|
||||
$access_permission_query
|
||||
" . clientScopeSql('invoice_client_id') . "
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
|
||||
@@ -463,7 +463,7 @@ if (isset($_POST['export_locations'])) {
|
||||
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 '%$q%' OR client_name LIKE '%$q%' OR tag_name LIKE '%$q%')
|
||||
$access_permission_query
|
||||
" . clientScopeSql('location_client_id') . "
|
||||
$client_query
|
||||
GROUP BY location_id
|
||||
ORDER BY location_name ASC"
|
||||
|
||||
@@ -238,7 +238,7 @@ if (isset($_POST['export_networks'])) {
|
||||
LEFT JOIN locations ON location_id = network_location_id
|
||||
WHERE $archive_query
|
||||
AND (network_name LIKE '%$q%' OR network_description LIKE '%$q%' OR network_vlan LIKE '%$q%' OR network LIKE '%$q%' OR network_gateway LIKE '%$q%' OR network_primary_dns LIKE '%$q%' OR network_secondary_dns LIKE '%$q%' OR client_name LIKE '%$q%')
|
||||
$access_permission_query
|
||||
" . clientScopeSql('network_client_id') . "
|
||||
$location_query
|
||||
$client_query
|
||||
ORDER BY network_name ASC"
|
||||
|
||||
@@ -732,7 +732,7 @@ if (isset($_POST['export_quotes'])) {
|
||||
LEFT JOIN categories ON quote_category_id = category_id
|
||||
WHERE (CONCAT(quote_prefix,quote_number) LIKE '%$q%' OR quote_scope LIKE '%$q%' OR category_name LIKE '%$q%' OR quote_status LIKE '%$q%' OR quote_amount LIKE '%$q%' OR client_name LIKE '%$q%')
|
||||
AND DATE(quote_date) BETWEEN '$dtf' AND '$dtt'
|
||||
$access_permission_query
|
||||
" . clientScopeSql('quote_client_id') . "
|
||||
$client_query
|
||||
ORDER BY quote_number ASC"
|
||||
);
|
||||
@@ -774,7 +774,7 @@ if (isset($_GET['export_quote_pdf'])) {
|
||||
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
|
||||
WHERE quote_id = $quote_id
|
||||
$access_permission_query
|
||||
" . clientScopeSql('quote_client_id') . "
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
|
||||
@@ -666,7 +666,7 @@ if (isset($_POST['export_recurring_invoices'])) {
|
||||
AND DATE(recurring_invoice_created_at) BETWEEN '$dtf' AND '$dtt'
|
||||
$status_query
|
||||
$client_query
|
||||
$access_permission_query
|
||||
" . clientScopeSql('recurring_invoice_client_id') . "
|
||||
ORDER BY recurring_invoice_number ASC"
|
||||
);
|
||||
|
||||
|
||||
@@ -296,7 +296,7 @@ if (isset($_POST['export_software'])) {
|
||||
LEFT JOIN vendors ON vendor_id = software_vendor_id
|
||||
WHERE (software_name LIKE '%$q%' OR software_type LIKE '%$q%' OR software_key LIKE '%$q%' OR client_name LIKE '%$q%')
|
||||
AND $archive_query
|
||||
$access_permission_query
|
||||
" . clientScopeSql('software_client_id') . "
|
||||
$client_query
|
||||
$expire_query
|
||||
ORDER BY software_name ASC"
|
||||
|
||||
@@ -2871,12 +2871,8 @@ if (isset($_POST['export_tickets'])) {
|
||||
$ticket_project_snippet = '';
|
||||
}
|
||||
|
||||
// Client access override - the only way tickets without a client reach 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');
|
||||
|
||||
// Date Filter
|
||||
$dtf = escapeSql(!empty($_POST['dtf']) ? $_POST['dtf'] : '1970-01-01');
|
||||
|
||||
@@ -133,7 +133,7 @@ if (isset($_POST['export_trips'])) {
|
||||
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 trip_date ASC"
|
||||
);
|
||||
|
||||
|
||||
@@ -398,7 +398,7 @@ if (isset($_POST['export_vendors'])) {
|
||||
WHERE $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 '%$q%')
|
||||
$client_query
|
||||
$access_permission_query
|
||||
" . clientScopeSql('vendor_client_id') . "
|
||||
ORDER BY vendor_name ASC"
|
||||
);
|
||||
|
||||
|
||||
@@ -19,14 +19,7 @@ if (isset($_GET['client_id'])) {
|
||||
|
||||
// Perms & Project client access snippet
|
||||
enforceUserPermission('module_support');
|
||||
$project_permission_snippet = '';
|
||||
|
||||
if ($client_access_string) {
|
||||
$project_permission_snippet .= " AND (project_client_id IN ($client_access_string) OR project_client_id = 0)";
|
||||
}
|
||||
if ($client_deny_string) {
|
||||
$project_permission_snippet .= " AND project_client_id NOT IN ($client_deny_string)";
|
||||
}
|
||||
$project_permission_snippet = clientScopeSql('project_client_id');
|
||||
|
||||
if (isset($_GET['project_id'])) {
|
||||
$project_id = intval($_GET['project_id']);
|
||||
|
||||
@@ -18,14 +18,7 @@ if (isset($_GET['client_id'])) {
|
||||
// Perms & Project client access snippet
|
||||
enforceUserPermission('module_support');
|
||||
|
||||
$project_permission_snippet = '';
|
||||
|
||||
if ($client_access_string) {
|
||||
$project_permission_snippet .= " AND (project_client_id IN ($client_access_string) OR project_client_id = 0)";
|
||||
}
|
||||
if ($client_deny_string) {
|
||||
$project_permission_snippet .= " AND project_client_id NOT IN ($client_deny_string)";
|
||||
}
|
||||
$project_permission_snippet = clientScopeSql('project_client_id');
|
||||
|
||||
// Project Completed Status Query
|
||||
if (isset($_GET['status']) && $_GET['status'] == 1) {
|
||||
|
||||
@@ -21,7 +21,7 @@ if (isset($_GET['quote_id'])) {
|
||||
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
|
||||
WHERE quote_id = $quote_id
|
||||
$access_permission_query
|
||||
" . clientScopeSql('quote_client_id') . "
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ $sql = mysqli_query(
|
||||
LEFT JOIN categories ON quote_category_id = category_id
|
||||
WHERE (CONCAT(quote_prefix,quote_number) LIKE '%$q%' OR quote_scope LIKE '%$q%' OR category_name LIKE '%$q%' OR quote_status LIKE '%$q%' OR quote_amount LIKE '%$q%' OR client_name LIKE '%$q%')
|
||||
AND DATE(quote_date) BETWEEN '$dtf' AND '$dtt'
|
||||
$access_permission_query
|
||||
" . clientScopeSql('quote_client_id') . "
|
||||
$client_query
|
||||
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
||||
);
|
||||
|
||||
@@ -18,7 +18,7 @@ $sql = mysqli_query(
|
||||
LEFT JOIN clients ON recurring_expense_client_id = client_id
|
||||
WHERE DATE(recurring_expense_created_at) BETWEEN '$dtf' AND '$dtt'
|
||||
AND (vendor_name LIKE '%$q%' OR client_name LIKE '%$q%' OR category_name LIKE '%$q%' OR account_name LIKE '%$q%' OR recurring_expense_description LIKE '%$q%' OR recurring_expense_amount LIKE '%$q%')
|
||||
$access_permission_query
|
||||
" . clientScopeSql('recurring_expense_client_id') . "
|
||||
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
||||
);
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ $sql = mysqli_query(
|
||||
AND DATE(recurring_invoice_created_at) BETWEEN '$dtf' AND '$dtt'
|
||||
$status_query
|
||||
$client_query
|
||||
$access_permission_query
|
||||
" . clientScopeSql('recurring_invoice_client_id') . "
|
||||
|
||||
ORDER BY $sort $order LIMIT $record_from, $record_to");
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ $sql = mysqli_query(
|
||||
LEFT JOIN users ON user_id = recurring_ticket_assigned_to
|
||||
LEFT JOIN ticket_templates ON ticket_template_id = recurring_ticket_ticket_template_id
|
||||
WHERE (recurring_tickets.recurring_ticket_subject LIKE '%$q%' OR category_name LIKE '%$q%')
|
||||
$access_permission_query
|
||||
" . clientScopeSql('recurring_ticket_client_id') . "
|
||||
$category_query
|
||||
$assigned_agent_query
|
||||
$billable_query
|
||||
|
||||
@@ -37,7 +37,7 @@ $sql = mysqli_query(
|
||||
LEFT JOIN clients ON client_id = service_client_id
|
||||
WHERE (service_name LIKE '%$q%' OR service_description LIKE '%$q%' OR service_category LIKE '%$q%' OR client_name LIKE '%$q%')
|
||||
AND client_archived_at IS NULL
|
||||
$access_permission_query
|
||||
" . clientScopeSql('service_client_id') . "
|
||||
$client_query
|
||||
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
||||
);
|
||||
@@ -85,7 +85,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
FROM clients
|
||||
JOIN services ON service_client_id = client_id
|
||||
WHERE client_archived_at IS NULL
|
||||
$access_permission_query
|
||||
" . clientScopeSql('clients.client_id') . "
|
||||
ORDER BY client_name ASC
|
||||
");
|
||||
while ($row = mysqli_fetch_assoc($sql_clients_filter)) {
|
||||
|
||||
@@ -68,7 +68,7 @@ $sql = mysqli_query(
|
||||
LEFT JOIN vendors ON vendor_id = software_vendor_id
|
||||
WHERE (software_name LIKE '%$q%' OR software_type LIKE '%$q%' OR software_key LIKE '%$q%' OR client_name LIKE '%$q%')
|
||||
AND $archive_query
|
||||
$access_permission_query
|
||||
" . clientScopeSql('software_client_id') . "
|
||||
$client_query
|
||||
$expire_query
|
||||
ORDER BY $sort $order LIMIT $record_from, $record_to");
|
||||
@@ -131,7 +131,7 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
FROM clients
|
||||
JOIN software ON software_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)) {
|
||||
|
||||
@@ -9,11 +9,8 @@ if (isset($_GET['client_id'])) {
|
||||
$client_url = '';
|
||||
}
|
||||
|
||||
// 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');
|
||||
|
||||
// Perms
|
||||
enforceUserPermission('module_support');
|
||||
|
||||
@@ -247,11 +247,8 @@ if ($q !== '') {
|
||||
$active_filters[] = array('label' => '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
|
||||
|
||||
@@ -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"
|
||||
);
|
||||
|
||||
|
||||
@@ -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"
|
||||
);
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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)";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user