Portions created by the Initial Developer are Copyright (C) 2017-2023 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes files require_once dirname(__DIR__, 4) . "/resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('extension_caller_id')) { //add multi-lingual support $language = new text; $text = $language->get($_SESSION['domain']['language']['code'], 'app/extensions'); //connect to the database if (!isset($database)) { $database = new database; } //add or update the database if (isset($_POST['extensions']) && is_array($_POST['extensions']) && @sizeof($_POST['extensions']) != 0) { //validate the token $token = new token; if (!$token->validate($_SERVER["DOCUMENT_ROOT"].'/extensions/resources/dashboard/caller_id.php')) { message::add($text['message-invalid_token'],'negative'); header('Location: /core/dashboard/'); exit; } //build a new array to make sure it only contains what the user is allowed to change $x=0; foreach ($_POST['extensions'] as $row) { //loop through the extensions $found = false; foreach ($_SESSION['user']['extension'] as $field) { if ($field['extension_uuid'] == $row['extension_uuid']) { //set as found $found = true; } } //build the array on what is allowed. if ($found) { if (permission_exists('outbound_caller_id_select')) { $caller_id = explode('@', $row['outbound_caller_id']); $outbound_caller_id_name = $caller_id[0]; $outbound_caller_id_number = $caller_id[1]; } else { $outbound_caller_id_name = $row['outbound_caller_id_name']; $outbound_caller_id_number = $row['outbound_caller_id_number']; } $array['extensions'][$x]['extension_uuid'] = $row['extension_uuid']; $array['extensions'][$x]['outbound_caller_id_name'] = $outbound_caller_id_name; if (is_numeric($outbound_caller_id_number)) { $array['extensions'][$x]['outbound_caller_id_number'] = $outbound_caller_id_number; } } //increment the row id $x++; } //create temp array for session update $array_temp = $array; //add the dialplan permission $p = new permissions; $p->add("extension_edit", "temp"); //save to the data $database->app_name = 'extensions'; $database->app_uuid = 'e68d9689-2769-e013-28fa-6214bf47fca3'; $message = $database->save($array); //update the session array if ($message['message'] == 'OK' && $message['code'] == '200') { foreach ($array_temp['extensions'] as $row) { $x=0; foreach ($_SESSION['user']['extension'] as $field) { if ($field['extension_uuid'] == $row['extension_uuid']) { $_SESSION['user']['extension'][$x]['outbound_caller_id_name'] = $row['outbound_caller_id_name']; $_SESSION['user']['extension'][$x]['outbound_caller_id_number'] = $row['outbound_caller_id_number']; } $x++; } } } unset($array_temp); //remove the temporary permission $p->delete("extension_edit", "temp"); //clear the cache $cache = new cache; foreach($_SESSION['user']['extension'] as $field) { $cache->delete("directory:".$field['destination']."@".$field['user_context']); } //set the message message::add($text['message-update']); //redirect the browser header("Location: /core/dashboard/"); exit; } //get the extensions $extensions = $_SESSION['user']['extension']; //get the destinations if (permission_exists('outbound_caller_id_select')) { $sql = "select destination_caller_id_name, destination_caller_id_number from v_destinations "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and destination_type = 'inbound' "; $sql .= "order by destination_caller_id_name asc, destination_caller_id_number asc"; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $destinations = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); } //set defaults unset($stats); $stats['defined'] = $stats['undefined'] = 0; //determine stats if (is_array($extensions) && @sizeof($extensions) != 0) { foreach ($extensions as $row) { if (is_numeric($row['outbound_caller_id_number'])) { $stats['defined']++; } else { $stats['undefined']++; } } } //set the row style $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; //create token $object = new token; $token = $object->create($_SERVER["DOCUMENT_ROOT"].'/extensions/resources/dashboard/caller_id.php'); //caller id echo "
\n"; echo "
\n"; echo " ".$text['label-caller_id_number']."\n"; //doughnut chart if (!isset($dashboard_chart_type) || $dashboard_chart_type == "doughnut") { echo "
\n"; echo "\n"; } if ($dashboard_chart_type == "number") { echo " ".$stats['undefined'].""; } echo "
\n"; //details if ($dashboard_details_state != 'disabled') { echo "
\n"; echo "
"; if (is_array($extensions) && @sizeof($extensions) != 0) { echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'collapse'=>false,'style'=>"position: absolute; margin-top: -35px; margin-left: -72px;"]); } echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (!permission_exists('outbound_caller_id_select')) { echo "\n"; } echo "\n"; //data if (is_array($extensions) && @sizeof($extensions) != 0) { $x = 0; foreach ($extensions as $row) { $tr_link = PROJECT_PATH."/app/extensions/extension_edit.php?id=".$row['extension_uuid']; echo "\n"; echo " \n"; //select caller id if (permission_exists('outbound_caller_id_select')) { echo "\n"; } //input caller id else { echo "\n"; echo "\n"; } echo "\n"; $x++; $c = ($c) ? 0 : 1; } unset($extensions); } echo "
".$text['label-extension']."".$text['label-caller_id']."".$text['label-destination']."
"; echo "".escape($row['destination']).""; if (is_uuid($row['extension_uuid'])) { echo "\n"; } echo "
\n"; echo "
"; //$n++; echo "\n"; echo "
\n"; echo ""; } echo "
\n"; } ?>