Phone Systems > a system's domains (functions/phone.php). Each domain (a FusionPBX
* tenant) it has sent anything about is linked to the client it is, or not linked yet - with the
* client it looks like suggested. A call on a client's domain is that client's; on your own
* company's, or one not linked, it is the caller's. Until the system has been heard from, the
* page says how to set it up (modals/phone/phone_system_setup.php). The handlers are
* admin/post/phone.php.
*/
// Default Column Sortby Filter
$sort = "phone_domain_name";
$order = "ASC";
require_once "includes/inc_all_admin.php";
$system = phoneTablesReady() ? phoneSystemRow($_GET['phone_system_id'] ?? 0) : null;
$kind = $system ? phoneKind($system) : null;
if (!$system || !$kind) { ?>
= $system ? 'This ITFlow doesn\'t know that phone system\'s kind.' : 'That phone system is gone - it may have been deleted.' ?> Phone Systems
['label' => 'All', 'icon' => 'fa-list', 'sql' => '1 = 1', 'title' => "Every domain $name has sent"],
'unlinked' => ['label' => 'Not linked', 'icon' => 'fa-unlink', 'sql' => 'phone_domain_client_id = 0', 'title' => 'Their calls go to whoever is calling'],
'linked' => ['label' => 'Linked', 'icon' => 'fa-link', 'sql' => 'phone_domain_client_id > 0', 'title' => 'Their calls are their client\'s'],
];
$show = isset($shows[$_GET['show'] ?? '']) ? (string) ($_GET['show'] ?? '') : '';
$view_counts = [];
foreach ($shows as $key => $view) {
$view_counts[$key] = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM phone_domains WHERE phone_domain_system_id = $phone_system_id AND {$view['sql']}"))[0]);
}
$filter_url = function (array $change) {
$get = array_merge($_GET, $change);
unset($get['page'], $get['setup']);
$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_domain_name' => "phone_domain_name $order",
'calls_month' => "calls_month $order, phone_domain_name ASC",
'phones' => "phones $order, phone_domain_name ASC",
'client_name' => "client_name IS NULL, client_name $order, phone_domain_name ASC",
'phone_domain_seen_at' => "phone_domain_seen_at IS NULL, phone_domain_seen_at $order, phone_domain_name ASC",
];
if (!isset($sortable_columns[$sort])) {
$sort = 'phone_domain_name';
}
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS phone_domains.*, client_name, client_abbreviation, client_archived_at,
(SELECT COUNT(*) FROM phone_calls WHERE phone_call_domain_id = phone_domains.phone_domain_id AND phone_call_started_at >= NOW() - INTERVAL 30 DAY) AS calls_month,
(SELECT COUNT(*) FROM phone_devices WHERE phone_device_domain_id = phone_domains.phone_domain_id) AS phones
FROM phone_domains
LEFT JOIN clients ON client_id = phone_domain_client_id AND phone_domain_client_id > 0
WHERE phone_domain_system_id = $phone_system_id AND {$shows[$show]['sql']}
AND (phone_domain_name LIKE '%$q%' OR client_name LIKE '%$q%')
ORDER BY {$sortable_columns[$sort]}, phone_domain_id ASC
LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
// The clients the suggestions name
$suggested_names = [];
if ($suggestions) {
$suggested_sql = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_id IN (" . implode(', ', array_map('intval', $suggestions)) . ")");
while ($row = mysqli_fetch_assoc($suggested_sql)) {
$suggested_names[intval($row['client_id'])] = $row['client_name'];
}
}
$calls_total = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM phone_calls WHERE phone_call_system_id = $phone_system_id"))[0]);
$own_client = intval($config_internal_client_id ?? 0);
?>