Option to show all contacts for the domain.

This commit is contained in:
FusionPBX
2022-01-21 19:32:49 -07:00
committed by GitHub
parent 63e1f7741e
commit 98255b14bf

View File

@@ -186,7 +186,8 @@ include "root.php";
}
}
private function contact_append(&$contacts, &$line, $domain_uuid, $device_user_uuid, $is_group) {
private function contact_append(&$contacts, &$line, $domain_uuid, $device_user_uuid, $category) {
$sql = "select c.contact_uuid, c.contact_organization, c.contact_name_given, c.contact_name_family, ";
$sql .= "c.contact_type, c.contact_category, p.phone_label,";
$sql .= "p.phone_number, p.phone_extension, p.phone_primary ";
@@ -194,7 +195,7 @@ include "root.php";
$sql .= "where c.contact_uuid = p.contact_uuid ";
$sql .= "and p.phone_type_voice = '1' ";
$sql .= "and c.domain_uuid = :domain_uuid ";
if ($is_group) {
if ($category == 'groups') {
$sql .= "and c.contact_uuid in ( ";
$sql .= " select contact_uuid from v_contact_groups ";
$sql .= " where group_uuid in ( ";
@@ -202,55 +203,57 @@ include "root.php";
$sql .= " where user_uuid = :device_user_uuid ";
$sql .= " and domain_uuid = :domain_uuid ";
$sql .= " )) ";
$parameters['device_user_uuid'] = $device_user_uuid;
}
else {
if ($category == 'users') {
$sql .= "and c.contact_uuid in ( ";
$sql .= " select contact_uuid from v_contact_users ";
$sql .= " where user_uuid = :device_user_uuid ";
$sql .= " and domain_uuid = :domain_uuid ";
$sql .= ") ";
$parameters['device_user_uuid'] = $device_user_uuid;
}
$parameters['device_user_uuid'] = $device_user_uuid;
$parameters['domain_uuid'] = $domain_uuid;
$database = new database;
$user_contacts = $database->select($sql, $parameters, 'all');
if (is_array($user_contacts)) {
foreach ($user_contacts as &$row) {
$database_contacts = $database->select($sql, $parameters, 'all');
if (is_array($database_contacts)) {
$x = 0;
foreach ($database_contacts as &$row) {
$uuid = $row['contact_uuid'];
$phone_label = strtolower($row['phone_label']);
$contact_category = strtolower($row['contact_category']);
$contact = array();
$contacts[] = &$contact;
$contact['category'] = $is_group ? 'groups' : 'users';
$contact['contact_uuid'] = $row['contact_uuid'];
$contact['contact_type'] = $row['contact_type'];
$contact['contact_category'] = $row['contact_category'];
$contact['contact_organization'] = $row['contact_organization'];
$contact['contact_name_given'] = $row['contact_name_given'];
$contact['contact_name_family'] = $row['contact_name_family'];
$contact['numbers'] = array();
$contact['category'] = ($category == 'all') ? 'groups' : $category;
$contact['contact_uuid'] = $row['contact_uuid'];
$contact['contact_type'] = $row['contact_type'];
$contact['contact_category'] = $row['contact_category'];
$contact['contact_organization'] = $row['contact_organization'];
$contact['contact_name_given'] = $row['contact_name_given'];
$contact['contact_name_family'] = $row['contact_name_family'];
$contact['numbers'] = array();
$numbers = &$contact['numbers'];
if (($row['phone_primary'] == '1') || (!isset($contact['phone_number']))) {
$contact['phone_label'] = $phone_label;
$contact['phone_number'] = $row['phone_number'];
$contact['phone_extension'] = $row['phone_extension'];
$contact['phone_label'] = $phone_label;
$contact['phone_number'] = $row['phone_number'];
$contact['phone_extension'] = $row['phone_extension'];
}
$numbers[] = array(
line_number => $line['line_number'],
phone_label => $phone_label,
phone_number => $row['phone_number'],
phone_extension => $row['phone_extension'],
phone_primary => $row['phone_primary'],
);
$numbers[$x]['line_number'] = $line['line_number'];
$numbers[$x]['phone_label'] = $phone_label;
$numbers[$x]['phone_number'] = $row['phone_number'];
$numbers[$x]['phone_extension'] = $row['phone_extension'];
$numbers[$x]['phone_primary'] = $row['phone_primary'];
$contact['phone_number_' . $phone_label] = $row['phone_number'];
unset($contact, $numbers, $uuid, $phone_label);
$x++;
}
unset($parameters);
}
}
@@ -885,16 +888,22 @@ include "root.php";
$view->assign("user", $lines);
//get the list of contact directly assigned to the user
if (is_uuid($device_user_uuid) && is_uuid($domain_uuid)) {
//get the contacts assigned to the groups and add to the contacts array
if ($_SESSION['provision']['contact_groups']['boolean'] == "true") {
$this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, true);
}
//get the contacts assigned to the user and add to the contacts array
if ($_SESSION['provision']['contact_users']['boolean'] == "true") {
$this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, false);
}
if (is_uuid($domain_uuid)) {
if ($_SESSION['provision']['contact_permissions']['boolean'] == "true") {
//get the contacts assigned to the groups and add to the contacts array
if (is_uuid($device_user_uuid) && $_SESSION['provision']['contact_groups']['boolean'] == "true") {
$this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, 'groups');
}
//get the contacts assigned to the user and add to the contacts array
if (is_uuid($device_user_uuid) && $_SESSION['provision']['contact_users']['boolean'] == "true") {
$this->contact_append($contacts, $line, $domain_uuid, $device_user_uuid, 'users');
}
}
else {
//show all contacts for the domain
$this->contact_append($contacts, $line, $domain_uuid, null, 'all');
}
}
//get the extensions and add them to the contacts array