Phone Systems), or one * client's, or one contact's (contact_id). Each row is who it was with - the contact, else the * caller ID name or number - the extension and agent on this side, when, how long they talked and * how it ended, and the ticket it went on. Add to Ticket puts it on one of the client's open * tickets, or a new one, as an internal note with its talk time * (modals/phone/phone_call_ticket.php, agent/post/phone.php). */ // Default Column Sortby Filter $sort = "phone_call_started_at"; $order = "DESC"; // If client_id is in URI then show client Side Bar and client header if (isset($_GET['client_id'])) { require_once "includes/inc_all_client.php"; $client_query = "AND phone_call_client_id = $client_id"; $client_url = "client_id=$client_id&"; } else { require_once "includes/inc_all.php"; $client_query = ''; $client_url = ''; } enforceUserPermission('module_support'); $page_title = 'Calls'; if (!phoneSystemsExist()) { ?>
No phone system is set up - an admin adds one in Admin > Integrations > Phone Systems.
= 2; $statuses = phoneCallStatuses(); $directions = phoneCallDirections(); // One contact's calls - from their page $contact_filter = intval($_GET['contact_id'] ?? 0); $contact_filter_name = ''; if ($contact_filter) { $contact_row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_name, contact_client_id FROM contacts WHERE contact_id = $contact_filter")); if ($contact_row && hasClientAccess($contact_row['contact_client_id'])) { $contact_filter_name = (string) $contact_row['contact_name']; } else { $contact_filter = 0; } } $contact_query = $contact_filter ? "AND phone_call_contact_id = $contact_filter" : ''; // The views - all of them, each way, missed ones, and callers nobody knows $shows = [ '' => ['label' => 'All', 'icon' => 'fa-list', 'sql' => '1 = 1'], 'inbound' => ['label' => 'Inbound', 'icon' => 'fa-arrow-down', 'sql' => "phone_call_direction = 'inbound'"], 'outbound' => ['label' => 'Outbound', 'icon' => 'fa-arrow-up', 'sql' => "phone_call_direction = 'outbound'"], 'missed' => ['label' => 'Missed', 'icon' => 'fa-phone-slash', 'sql' => "phone_call_direction = 'inbound' AND phone_call_status IN ('missed', 'voicemail')"], 'unknown' => ['label' => 'Unknown', 'icon' => 'fa-question', 'sql' => "phone_call_direction <> 'local' AND phone_call_contact_id = 0", 'title' => 'With numbers that aren\'t a contact\'s'], ]; $show = isset($shows[$_GET['show'] ?? '']) ? (string) ($_GET['show'] ?? '') : ''; $scope = clientScopeSql('phone_call_client_id') . " $client_query $contact_query"; $view_counts = []; foreach ($shows as $key => $view) { $view_counts[$key] = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM phone_calls WHERE {$view['sql']} $scope"))[0]); } $filter_url = function (array $change) { $get = array_merge($_GET, $change); unset($get['page']); $get = array_filter($get, function ($value) { return $value !== null && $value !== ''; }); return '?' . http_build_query($get); }; // Only these sort - an unknown column would take the page down $sortable_columns = [ 'phone_call_started_at' => "phone_call_started_at $order", 'who' => "COALESCE(contact_name, NULLIF(phone_call_name, ''), phone_call_number) $order, phone_call_started_at DESC", 'client_name' => "client_name IS NULL, client_name $order, phone_call_started_at DESC", 'phone_call_extension' => "phone_call_extension = '', phone_call_extension $order, phone_call_started_at DESC", 'phone_call_talk_seconds' => "phone_call_talk_seconds $order, phone_call_started_at DESC", ]; if (!isset($sortable_columns[$sort])) { $sort = 'phone_call_started_at'; } $phone_digits = preg_replace('/\D/', '', (string) $q); $number_search = strlen($phone_digits) >= 3 ? " OR phone_call_number LIKE '%" . escapeSql($phone_digits) . "%' OR phone_call_dialed LIKE '%" . escapeSql($phone_digits) . "%'" : ''; $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS phone_calls.*, phone_system_kind, phone_system_name, phone_system_web_url, contact_name, client_name, ticket_prefix, ticket_number, ticket_subject, user_name FROM phone_calls LEFT JOIN phone_systems ON phone_system_id = phone_call_system_id LEFT JOIN contacts ON contact_id = phone_call_contact_id AND phone_call_contact_id > 0 LEFT JOIN clients ON client_id = phone_call_client_id AND phone_call_client_id > 0 LEFT JOIN tickets ON ticket_id = phone_call_ticket_id AND phone_call_ticket_id > 0 LEFT JOIN users ON users.user_id = phone_call_user_id AND phone_call_user_id > 0 WHERE {$shows[$show]['sql']} $scope AND (contact_name LIKE '%$q%' OR phone_call_name LIKE '%$q%' OR client_name LIKE '%$q%' OR phone_call_extension LIKE '%$q%' OR user_name LIKE '%$q%'$number_search) ORDER BY {$sortable_columns[$sort]}, phone_call_id DESC LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); ?>

Calls with

">
Ticket
">
· · ·
-
-' ?> -
'calls', 'icon' => 'fa-phone-volume', 'title' => $show === 'missed' ? 'No missed calls' : null, 'text' => $show === '' ? 'Calls come in as the phone system sends them - each one with the contact it was with.' : '', 'filtered' => $q !== '', ]; $empty_state = array_filter($empty_state, function ($value) { return $value !== null; }); ?>