= $person_phone ?>= $person['contact_extension'] ? ' x' . escapeHtml($person['contact_extension']) : '' ?>
diff --git a/agent/clients.php b/agent/clients.php
index 36c16988f..f0f714053 100644
--- a/agent/clients.php
+++ b/agent/clients.php
@@ -154,7 +154,7 @@ $sql = mysqli_query(
clients.client_id, client_name, client_type, client_abbreviation, client_rate, client_currency_code,
client_lead, client_archived_at,
contact_id, contact_name, contact_phone, contact_phone_country_code, contact_extension,
- contact_mobile, contact_mobile_country_code, contact_email,
+ contact_mobile, contact_mobile_country_code, contact_email, contact_photo,
location_id, location_address, location_city, location_state, location_zip, location_country
FROM clients
LEFT JOIN contacts ON contact_id = (
@@ -524,7 +524,7 @@ $total_leads = intval($row['leads']);
- = $contact_name ?: 'Unnamed contact' ?>
+ = contactLink($client_id, $contact_id, $row['contact_name'], $row['contact_photo'], ['class' => 'text-reset']) ?>
= $contact_phone ?>
@@ -541,7 +541,7 @@ $total_leads = intval($row['leads']);
-
+
Add primary contact
diff --git a/agent/contact.php b/agent/contact.php
index 5495019a2..6582de976 100644
--- a/agent/contact.php
+++ b/agent/contact.php
@@ -1,5 +1,16 @@
Nothing to see here Go Back";
- require_once "../includes/footer.php";
- exit();
- }
+if (mysqli_num_rows($sql) == 0) {
+ echo "Nothing to see here Go Back";
+ require_once "../includes/footer.php";
+ exit();
+}
- $row = mysqli_fetch_assoc($sql);
- $client_id = intval($row['client_id']);
- $client_name = escapeHtml($row['client_name']);
- $contact_name = escapeHtml($row['contact_name']);
- $contact_title = escapeHtml($row['contact_title']);
- $contact_department =escapeHtml($row['contact_department']);
- $contact_phone_country_code = escapeHtml($row['contact_phone_country_code']);
- $contact_phone = escapeHtml(formatPhoneNumber($row['contact_phone'], $contact_phone_country_code));
- $contact_extension = escapeHtml($row['contact_extension']);
- $contact_mobile_country_code = escapeHtml($row['contact_mobile_country_code']);
- $contact_mobile = escapeHtml(formatPhoneNumber($row['contact_mobile'], $contact_mobile_country_code));
- $contact_email = escapeHtml($row['contact_email']);
- $contact_photo = escapeHtml($row['contact_photo']);
- $contact_pin = escapeHtml($row['contact_pin']);
- $contact_initials = initials($contact_name);
- $contact_notes = escapeHtml($row['contact_notes']);
- $contact_primary = intval($row['contact_primary']);
- $contact_important = intval($row['contact_important']);
- $contact_billing = intval($row['contact_billing']);
- $contact_technical = intval($row['contact_technical']);
- $contact_created_at = escapeHtml($row['contact_created_at']);
- $contact_location_id = intval($row['contact_location_id']);
- $location_name = escapeHtml($row['location_name']);
- $auth_method = escapeHtml($row['user_auth_method']);
- $contact_client_id = intval($row['contact_client_id']);
+$contact_row = mysqli_fetch_assoc($sql); // raw, for the helpers - $row gets reused below
+$row = $contact_row;
+$client_id = intval($row['client_id']);
+$client_name = escapeHtml($row['client_name']);
+$contact_name = escapeHtml($row['contact_name']);
+$contact_title = escapeHtml($row['contact_title']);
+$contact_department = escapeHtml($row['contact_department']);
+$contact_email = escapeHtml($row['contact_email']);
+$contact_pin = escapeHtml($row['contact_pin']);
+$contact_notes = escapeHtml($row['contact_notes']);
+$contact_primary = intval($row['contact_primary']);
+$contact_archived_at = $row['contact_archived_at'];
+$contact_created_at = escapeHtml($row['contact_created_at']);
+$contact_phone_link = contactPhoneLink($row['contact_phone'], $row['contact_phone_country_code'], $row['contact_extension']);
+$contact_mobile_link = contactPhoneLink($row['contact_mobile'], $row['contact_mobile_country_code']);
+$contact_phone_copy = escapeHtml(formatPhoneNumber($row['contact_phone'], $row['contact_phone_country_code']));
+$contact_mobile_copy = escapeHtml(formatPhoneNumber($row['contact_mobile'], $row['contact_mobile_country_code']));
+$contact_dial = $row['contact_phone'] ? 'phone' : ($row['contact_mobile'] ? 'mobile' : '');
+$contact_portal = contactPortalAccess($row['contact_user_id'], $row['user_auth_method']);
+$contact_role_line = implode(' · ', array_filter([$contact_title, $contact_department]));
- // Override Tab Title // No Sanitizing needed as this var will opnly be used in the tab title
- $page_title = $row['contact_name'];
+$can_edit = lookupUserPermission('module_client') >= 2;
+$can_delete = lookupUserPermission('module_client') >= 3;
+$can_credentials = lookupUserPermission('module_credential') >= 1;
+$can_support = lookupUserPermission('module_support') >= 1;
+$can_support_edit = lookupUserPermission('module_support') >= 2;
- // Check to see if Contact belongs to client
- if($contact_client_id !== $client_id) {
- exit();
- }
+// Override Tab Title // No Sanitizing needed as this var will only be used in the tab title
+$page_title = $row['contact_name'];
- // Related Assets Query - 1 to 1 relationship
- $sql_related_assets = mysqli_query($mysqli, "SELECT asset_created_at, asset_description, asset_favorite, asset_id, asset_install_date,
- asset_make, asset_model, asset_name, asset_notes, asset_os, asset_photo,
- asset_physical_location, asset_purchase_date, asset_serial, asset_status, asset_type,
- asset_uri, asset_uri_2, asset_warranty_expire, interface_ip, interface_ipv6, interface_mac,
- interface_nat_ip, tag_color, tag_icon, tag_id, tag_name FROM assets
- LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1
- LEFT JOIN asset_tags ON asset_tag_asset_id = asset_id
- LEFT JOIN tags ON tag_id = asset_tag_tag_id
- WHERE asset_contact_id = $contact_id
- GROUP BY asset_id
- ORDER BY asset_name ASC"
- );
- $asset_count = mysqli_num_rows($sql_related_assets);
+// Tags - functions/tags.php
+$contact_tags_display = tagPills('contact', $contact_id, tagsForRecord('contact', $contact_id), "contacts.php?client_id=$client_id&");
- // Linked Software Licenses
- $sql_linked_software = mysqli_query($mysqli, "SELECT software_expire, software_contacts.software_id, software_key, software_license_type,
- software_name, software_notes, software_purchase, software_seats, software_type,
- software_version FROM software_contacts, software
- WHERE software_contacts.contact_id = $contact_id
- AND software_contacts.software_id = software.software_id
- AND software_archived_at IS NULL
- ORDER BY software_name ASC"
- );
- $software_count = mysqli_num_rows($sql_linked_software);
+// Assets assigned to them
+$sql_related_assets = mysqli_query($mysqli, "SELECT asset_id, asset_name, asset_description, asset_type, asset_make, asset_model, asset_serial,
+ asset_status, asset_favorite, interface_ip
+ FROM assets
+ LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1
+ WHERE asset_contact_id = $contact_id
+ AND asset_archived_at IS NULL
+ ORDER BY asset_name ASC"
+);
+$asset_count = mysqli_num_rows($sql_related_assets);
- $linked_software = array();
-
- // Related Credentials Query 1 to 1 relationship
- $sql_related_credentials = mysqli_query($mysqli, "
- SELECT
- credentials.credential_id AS credentials_credential_id, -- Alias for credentials.credential_id
- credentials.*, -- All other columns from credentials
- credential_tags.*, -- All columns from credential_tags
- tags.* -- All columns from tags
+// Credentials - only for agents who may see them
+$credential_count = 0;
+if ($can_credentials) {
+ $sql_related_credentials = mysqli_query($mysqli, "SELECT credential_id, credential_name, credential_description, credential_uri,
+ credential_username, credential_otp_secret
FROM credentials
- LEFT JOIN credential_tags ON credential_tags.credential_id = credentials.credential_id
- LEFT JOIN tags ON tags.tag_id = credential_tags.tag_id
WHERE credential_contact_id = $contact_id
- GROUP BY credentials.credential_id
- ORDER BY credential_name ASC
- ");
+ AND credential_archived_at IS NULL
+ ORDER BY credential_name ASC"
+ );
$credential_count = mysqli_num_rows($sql_related_credentials);
+}
- // Related Tickets Query - 1 to 1 relationship
- $sql_related_tickets = mysqli_query($mysqli, "SELECT ticket_assigned_to, ticket_closed_at, ticket_created_at, ticket_id, ticket_number,
- ticket_prefix, ticket_priority, ticket_status, ticket_status_color, ticket_status_name,
- ticket_subject, ticket_updated_at, user_avatar, user_name FROM tickets
+// Tickets they raised or are the contact on - open ones first
+$related_tickets = [];
+$ticket_open_count = 0;
+if ($can_support) {
+ $sql_related_tickets = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_priority, ticket_created_at,
+ ticket_updated_at, ticket_resolved_at, ticket_closed_at, ticket_assigned_to, user_name, user_avatar, ticket_status_name, ticket_status_color
+ FROM tickets
LEFT JOIN users ON ticket_assigned_to = user_id
LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id
- WHERE ticket_contact_id = $contact_id ORDER BY ticket_id DESC");
- $ticket_count = mysqli_num_rows($sql_related_tickets);
+ WHERE ticket_contact_id = $contact_id
+ AND ticket_archived_at IS NULL
+ ORDER BY (ticket_resolved_at IS NULL AND ticket_closed_at IS NULL) DESC, ticket_number DESC"
+ );
+ while ($row = mysqli_fetch_assoc($sql_related_tickets)) {
+ $row['is_open'] = empty($row['ticket_resolved_at']) && empty($row['ticket_closed_at']);
+ $ticket_open_count += $row['is_open'] ? 1 : 0;
+ $related_tickets[] = $row;
+ }
+}
+$ticket_count = count($related_tickets);
- // Related Recurring Tickets Query
- $sql_related_recurring_tickets = mysqli_query($mysqli, "SELECT recurring_ticket_frequency, recurring_ticket_id, recurring_ticket_next_run,
- recurring_ticket_priority, recurring_ticket_subject FROM recurring_tickets
+// Recurring tickets
+$recurring_ticket_count = 0;
+if ($can_support) {
+ $sql_related_recurring_tickets = mysqli_query($mysqli, "SELECT recurring_ticket_id, recurring_ticket_subject, recurring_ticket_priority,
+ recurring_ticket_frequency, recurring_ticket_next_run
+ FROM recurring_tickets
WHERE recurring_ticket_contact_id = $contact_id
- ORDER BY recurring_ticket_next_run DESC"
+ ORDER BY recurring_ticket_next_run ASC"
);
$recurring_ticket_count = mysqli_num_rows($sql_related_recurring_tickets);
+}
+// Licenses, with seats in use counted in the same query instead of two queries per license
+$sql_linked_software = mysqli_query($mysqli, "SELECT software.software_id, software_name, software_version, software_type, software_license_type,
+ software_seats, software_expire,
+ (SELECT COUNT(*) FROM software_assets AS sa WHERE sa.software_id = software.software_id)
+ + (SELECT COUNT(*) FROM software_contacts AS sc WHERE sc.software_id = software.software_id) AS seats_used
+ FROM software_contacts
+ JOIN software ON software.software_id = software_contacts.software_id
+ WHERE software_contacts.contact_id = $contact_id
+ AND software_archived_at IS NULL
+ ORDER BY software_name ASC"
+);
+$software_count = mysqli_num_rows($sql_linked_software);
- // Tags - many to many relationship
- // Tags - functions/tags.php
- $contact_tags_display = tagPills('contact', $contact_id, tagsForRecord('contact', $contact_id), "contacts.php?client_id=$client_id&");
+// Documents
+$sql_linked_documents = mysqli_query($mysqli, "SELECT documents.document_id, document_name, document_description, document_created_at,
+ document_updated_at, user_name
+ FROM contact_documents
+ JOIN documents ON documents.document_id = contact_documents.document_id
+ LEFT JOIN users ON document_created_by = user_id
+ WHERE contact_documents.contact_id = $contact_id
+ AND document_archived_at IS NULL
+ ORDER BY document_name ASC"
+);
+$document_count = mysqli_num_rows($sql_linked_documents);
- // Notes - 1 to 1 relationship
- $sql_related_notes = mysqli_query($mysqli, "SELECT contact_note, contact_note_created_at, contact_note_id, contact_note_type, user_name FROM contact_notes LEFT JOIN users ON contact_note_created_by = user_id WHERE contact_note_contact_id = $contact_id AND contact_note_archived_at IS NULL ORDER BY contact_note_created_at DESC");
- $note_count = mysqli_num_rows($sql_related_notes);
+// Files
+$sql_linked_files = mysqli_query($mysqli, "SELECT files.file_id, file_name, file_description, file_ext, file_size, file_created_at
+ FROM contact_files
+ JOIN files ON files.file_id = contact_files.file_id
+ WHERE contact_files.contact_id = $contact_id
+ AND file_archived_at IS NULL
+ ORDER BY file_name ASC"
+);
+$file_count = mysqli_num_rows($sql_linked_files);
- // Note type icons, read from the categories list so the seeded icons
- // stay the single source of truth
- $note_type_icons = array();
- $sql_note_type_icons = mysqli_query($mysqli, "SELECT category_name, category_icon FROM categories WHERE category_type = 'contact_note_type'");
- while ($row = mysqli_fetch_assoc($sql_note_type_icons)) {
- $note_type_icons[escapeHtml($row['category_name'])] = escapeHtml($row['category_icon']);
- }
+// Services
+$sql_linked_services = mysqli_query($mysqli, "SELECT services.service_id, service_name, service_description, service_category, service_importance
+ FROM service_contacts
+ JOIN services ON services.service_id = service_contacts.service_id
+ WHERE service_contacts.contact_id = $contact_id
+ ORDER BY service_name ASC"
+);
+$service_count = mysqli_num_rows($sql_linked_services);
- // Linked Services
- $sql_linked_services = mysqli_query($mysqli, "SELECT service_category, service_description, service_contacts.service_id, service_importance,
- service_name FROM service_contacts, services
- WHERE service_contacts.contact_id = $contact_id
- AND service_contacts.service_id = services.service_id
- ORDER BY service_name ASC"
- );
- $service_count = mysqli_num_rows($sql_linked_services);
+// Notes
+$sql_related_notes = mysqli_query($mysqli, "SELECT contact_note, contact_note_created_at, contact_note_id, contact_note_type, user_name
+ FROM contact_notes
+ LEFT JOIN users ON contact_note_created_by = user_id
+ WHERE contact_note_contact_id = $contact_id
+ AND contact_note_archived_at IS NULL
+ ORDER BY contact_note_created_at DESC"
+);
+$note_count = mysqli_num_rows($sql_related_notes);
- $linked_services = array();
+// Note type icons, read from the categories list so the seeded icons stay the single source of truth
+$note_type_icons = [];
+$sql_note_type_icons = mysqli_query($mysqli, "SELECT category_name, category_icon FROM categories WHERE category_type = 'contact_note_type'");
+while ($row = mysqli_fetch_assoc($sql_note_type_icons)) {
+ $note_type_icons[escapeHtml($row['category_name'])] = escapeHtml($row['category_icon']);
+}
- // Linked Documents
- $sql_linked_documents = mysqli_query($mysqli, "SELECT document_created_at, document_description, documents.document_id, document_name,
- document_updated_at, user_name FROM contact_documents, documents
- LEFT JOIN users ON document_created_by = user_id
- WHERE contact_documents.contact_id = $contact_id
- AND contact_documents.document_id = documents.document_id
- AND document_archived_at IS NULL
- ORDER BY document_name ASC"
- );
- $document_count = mysqli_num_rows($sql_linked_documents);
+// The tabs, in the order a tech reaches for them
+$contact_tabs = [
+ 'assets' => ['label' => 'Assets', 'icon' => 'fa-desktop', 'count' => $asset_count],
+ 'credentials' => ['label' => 'Credentials', 'icon' => 'fa-key', 'count' => $credential_count],
+ 'tickets' => ['label' => 'Tickets', 'icon' => 'fa-life-ring', 'count' => $ticket_count, 'badge' => $ticket_open_count],
+ 'recurring' => ['label' => 'Recurring', 'icon' => 'fa-redo-alt', 'count' => $recurring_ticket_count],
+ 'licenses' => ['label' => 'Licenses', 'icon' => 'fa-cube', 'count' => $software_count],
+ 'documents' => ['label' => 'Documents', 'icon' => 'fa-file-alt', 'count' => $document_count],
+ 'files' => ['label' => 'Files', 'icon' => 'fa-paperclip', 'count' => $file_count],
+ 'services' => ['label' => 'Services', 'icon' => 'fa-stream', 'count' => $service_count],
+ 'notes' => ['label' => 'Notes', 'icon' => 'fa-sticky-note', 'count' => $note_count],
+];
+if (!$can_credentials) {
+ unset($contact_tabs['credentials']);
+}
+if (!$can_support) {
+ unset($contact_tabs['tickets'], $contact_tabs['recurring']);
+}
- $linked_documents = array();
+?>
- // Linked Files
- $sql_linked_files = mysqli_query($mysqli, "SELECT file_created_at, file_description, files.file_id, file_mime_type, file_name, file_size FROM contact_files, files
- WHERE contact_files.contact_id = $contact_id
- AND contact_files.file_id = files.file_id
- AND file_archived_at IS NULL
- ORDER BY file_name ASC"
- );
- $file_count = mysqli_num_rows($sql_linked_files);
+
+ -
+ = $client_name ?>
+
+ -
+ Contacts
+
+ - = $contact_name ?>
+
- $linked_files = array();
-
- ?>
-
-
-
-
-
-
-
-
- = $contact_name ?>
-
- = $contact_title ?>
-
-
-
-
-  ">
-
-
-
- = $contact_initials ?>
-
-
-
-
-
- = $contact_tags_display ?>
-
-
-
-
- = $location_name ?>
-
-
-
-
-
- x= $contact_extension ?>
-
-
-
- = $contact_pin ?>
-
- Primary Contact
-
- Important
-
- Technical
-
- Billing
-
- = date('Y-m-d', strtotime($contact_created_at)) ?>
-
-
-
-
-
-
-
-
+
+ |