IVR Menu code changes for PHP 8.1

This commit is contained in:
markjcrane 2023-05-16 22:51:16 -06:00
parent 8bd20b97cd
commit 2afda399e6
7 changed files with 446 additions and 402 deletions

View File

@ -163,6 +163,10 @@ if (!class_exists('destinations')) {
//set the global variables //set the global variables
global $db_type; global $db_type;
//set defaults
$select_style = '';
$onchange = '';
//get the domain_name //get the domain_name
$sql = "select domain_name from v_domains "; $sql = "select domain_name from v_domains ";
$sql .= "where domain_uuid = :domain_uuid "; $sql .= "where domain_uuid = :domain_uuid ";
@ -171,7 +175,7 @@ if (!class_exists('destinations')) {
$this->domain_name = $database->select($sql, $parameters, 'column'); $this->domain_name = $database->select($sql, $parameters, 'column');
//create a single destination select list //create a single destination select list
if ($_SESSION['destinations']['select_mode']['text'] == 'default') { if (!empty($_SESSION['destinations']['select_mode']['text']) && $_SESSION['destinations']['select_mode']['text'] == 'default') {
//get the destinations //get the destinations
if (!is_array($this->destinations)) { if (!is_array($this->destinations)) {
@ -296,7 +300,7 @@ if (!class_exists('destinations')) {
$response .= " tb.className='formfld';\n"; $response .= " tb.className='formfld';\n";
$response .= " tb.setAttribute('id', '".$destination_id."');\n"; $response .= " tb.setAttribute('id', '".$destination_id."');\n";
$response .= " tb.setAttribute('style', '".$select_style."');\n"; $response .= " tb.setAttribute('style', '".$select_style."');\n";
if ($onchange != '') { if (!empty($onchange)) {
$response .= " tb.setAttribute('onchange', \"".$onchange."\");\n"; $response .= " tb.setAttribute('onchange', \"".$onchange."\");\n";
$response .= " tb.setAttribute('onkeyup', \"".$onchange."\");\n"; $response .= " tb.setAttribute('onkeyup', \"".$onchange."\");\n";
} }
@ -320,7 +324,7 @@ if (!class_exists('destinations')) {
$response .= " obj[0].parentNode.removeChild(obj[1]);\n"; $response .= " obj[0].parentNode.removeChild(obj[1]);\n";
$response .= " obj[0].parentNode.removeChild(obj[2]);\n"; $response .= " obj[0].parentNode.removeChild(obj[2]);\n";
$response .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n"; $response .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n";
if ($onchange != '') { if (!empty($onchange)) {
$response .= " ".$onchange.";\n"; $response .= " ".$onchange.";\n";
} }
$response .= "}\n"; $response .= "}\n";
@ -337,7 +341,7 @@ if (!class_exists('destinations')) {
$name = $row['name']; $name = $row['name'];
$label = $row['label']; $label = $row['label'];
$destination = $row['field']['destination']; $destination = $row['field']['destination'] ?? '';
//add multi-lingual support //add multi-lingual support
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) { if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) {
@ -345,7 +349,7 @@ if (!class_exists('destinations')) {
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name); $text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name);
} }
if (is_array($row['result']['data']) && count($row['result']['data']) > 0 and !empty($row['select_value'][$destination_type])) { if (!empty($row['result']['data']) && !empty($row['select_value'][$destination_type])) {
$response .= " <optgroup label='".$text2['title-'.$label]."'>\n"; $response .= " <optgroup label='".$text2['title-'.$label]."'>\n";
$label2 = $label; $label2 = $label;
foreach ($row['result']['data'] as $data) { foreach ($row['result']['data'] as $data) {
@ -412,7 +416,7 @@ if (!class_exists('destinations')) {
$destination_label = str_replace("menu-exec-app", "", $destination_label); $destination_label = str_replace("menu-exec-app", "", $destination_label);
$destination_label = str_replace("transfer", "", $destination_label); $destination_label = str_replace("transfer", "", $destination_label);
$destination_label = str_replace("XML ".$this->domain_name, "", $destination_label); $destination_label = str_replace("XML ".$this->domain_name, "", $destination_label);
if ($destination_value != '' || $destination_label != '') { if (!empty($destination_value) || !empty($destination_label)) {
$response .= " <option value='".escape($destination_value)."' selected='selected'>".trim($destination_label)."</option>\n"; $response .= " <option value='".escape($destination_value)."' selected='selected'>".trim($destination_label)."</option>\n";
} }
} }
@ -537,6 +541,10 @@ if (!class_exists('destinations')) {
//set the global variables //set the global variables
global $db_type; global $db_type;
//set default values
$destination_name = '';
$destination_id = '';
//get the domain_name //get the domain_name
$sql = "select domain_name from v_domains "; $sql = "select domain_name from v_domains ";
$sql .= "where domain_uuid = :domain_uuid "; $sql .= "where domain_uuid = :domain_uuid ";
@ -653,7 +661,7 @@ if (!class_exists('destinations')) {
$name = $row['name']; $name = $row['name'];
$label = $row['label']; $label = $row['label'];
$destination = $row['field']['destination']; $destination = $row['field']['destination'] ?? '';
//add multi-lingual support //add multi-lingual support
if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) { if (file_exists($_SERVER["PROJECT_ROOT"]."/app/".$name."/app_languages.php")) {
@ -661,14 +669,14 @@ if (!class_exists('destinations')) {
$text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name); $text2 = $language2->get($_SESSION['domain']['language']['code'], 'app/'.$name);
} }
if (is_array($row['result']['data']) && !empty($row['select_value'][$destination_type])) { if (!empty($row['result']['data']) && !empty($row['select_value'][$destination_type])) {
$label2 = $label; $label2 = $label;
foreach ($row['result']['data'] as $data) { foreach ($row['result']['data'] as $data) {
$select_value = $row['select_value'][$destination_type]; $select_value = $row['select_value'][$destination_type];
$select_label = $row['select_label']; $select_label = $row['select_label'];
foreach ($row['field'] as $key => $value) { foreach ($row['field'] as $key => $value) {
if ($key == 'destination' and is_array($value)){ if ($key == 'destination' and !empty($value)){
if ($value['type'] == 'csv') { if (!empty($value['type']) && $value['type'] == 'csv') {
$array = explode($value['delimiter'], $data[$key]); $array = explode($value['delimiter'], $data[$key]);
$select_value = str_replace("\${destination}", $array[0], $select_value); $select_value = str_replace("\${destination}", $array[0], $select_value);
$select_label = str_replace("\${destination}", $array[0], $select_label); $select_label = str_replace("\${destination}", $array[0], $select_label);
@ -714,7 +722,7 @@ if (!class_exists('destinations')) {
$select_label = str_replace("&#9993", 'email-icon', $select_label); $select_label = str_replace("&#9993", 'email-icon', $select_label);
$select_label = escape(trim($select_label)); $select_label = escape(trim($select_label));
$select_label = str_replace('email-icon', '&#9993', $select_label); $select_label = str_replace('email-icon', '&#9993', $select_label);
if ($select_value == $destination_value) { $selected = "selected='selected' "; $select_found = true; } else { $selected = ''; } if (!empty($destination_value) && $select_value == $destination_value) { $selected = "selected='selected' "; $select_found = true; } else { $selected = ''; }
if ($label2 == 'destinations') { $select_label = format_phone($select_label); } if ($label2 == 'destinations') { $select_label = format_phone($select_label); }
$array[$label][$select_label] = $select_value; $array[$label][$select_label] = $select_value;
} }
@ -722,9 +730,12 @@ if (!class_exists('destinations')) {
} }
} }
if (!$select_found) { if (!$select_found) {
if(!empty($destination_value)) $destination_label = $destination_label ?? '';
$destination_value = $destination_value ?? '';
if(!empty($destination_value)) {
$destination_label = str_replace(":", " ", $destination_value); $destination_label = str_replace(":", " ", $destination_value);
$destination_label = str_replace("menu-exec-app", "", $destination_label ?? ''); }
$destination_label = str_replace("menu-exec-app", "", $destination_label);
$destination_label = str_replace("transfer", "", $destination_label); $destination_label = str_replace("transfer", "", $destination_label);
$destination_label = str_replace("XML ".$this->domain_name, "", $destination_label); $destination_label = str_replace("XML ".$this->domain_name, "", $destination_label);
$array[$label][$destination_label] = $destination_value; $array[$label][$destination_label] = $destination_value;

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2020 Portions created by the Initial Developer are Copyright (C) 2008-2023
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
@ -113,7 +113,7 @@
$ivr_menu_options = $_POST["ivr_menu_options"]; $ivr_menu_options = $_POST["ivr_menu_options"];
$ivr_menu_invalid_sound = $_POST["ivr_menu_invalid_sound"]; $ivr_menu_invalid_sound = $_POST["ivr_menu_invalid_sound"];
$ivr_menu_exit_sound = $_POST["ivr_menu_exit_sound"]; $ivr_menu_exit_sound = $_POST["ivr_menu_exit_sound"];
$ivr_menu_pin_number = $_POST["ivr_menu_pin_number"]; $ivr_menu_pin_number = $_POST["ivr_menu_pin_number"] ?? '';
$ivr_menu_confirm_macro = $_POST["ivr_menu_confirm_macro"]; $ivr_menu_confirm_macro = $_POST["ivr_menu_confirm_macro"];
$ivr_menu_confirm_key = $_POST["ivr_menu_confirm_key"]; $ivr_menu_confirm_key = $_POST["ivr_menu_confirm_key"];
$ivr_menu_tts_engine = $_POST["ivr_menu_tts_engine"]; $ivr_menu_tts_engine = $_POST["ivr_menu_tts_engine"];
@ -173,7 +173,7 @@
$parameters['ivr_menu_uuid'] = $ivr_menu_uuid; $parameters['ivr_menu_uuid'] = $ivr_menu_uuid;
$database = new database; $database = new database;
$row = $database->select($sql, $parameters, 'row'); $row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) { if (!empty($row)) {
if (!permission_exists('ivr_menu_domain')) { if (!permission_exists('ivr_menu_domain')) {
$domain_uuid = $row["domain_uuid"]; $domain_uuid = $row["domain_uuid"];
} }
@ -252,9 +252,9 @@
//seperate the language components into language, dialect and voice //seperate the language components into language, dialect and voice
$language_array = explode("/",$ivr_menu_language); $language_array = explode("/",$ivr_menu_language);
$ivr_menu_language = $language_array[0]; $ivr_menu_language = $language_array[0] ?? 'en';
$ivr_menu_dialect = $language_array[1]; $ivr_menu_dialect = $language_array[1] ?? 'us';
$ivr_menu_voice = $language_array[2]; $ivr_menu_voice = $language_array[2] ?? 'callie';
//prepare the array //prepare the array
$array['ivr_menus'][0]["ivr_menu_uuid"] = $ivr_menu_uuid; $array['ivr_menus'][0]["ivr_menu_uuid"] = $ivr_menu_uuid;
@ -297,13 +297,13 @@
$y = 0; $y = 0;
foreach ($ivr_menu_options as $row) { foreach ($ivr_menu_options as $row) {
if (isset($row['ivr_menu_option_digits']) && $row['ivr_menu_option_digits'] != '') { if (isset($row['ivr_menu_option_digits']) && $row['ivr_menu_option_digits'] != '') {
if (is_uuid($row['ivr_menu_option_uuid'])) { if (!empty($row['ivr_menu_option_uuid']) && is_uuid($row['ivr_menu_option_uuid'])) {
$ivr_menu_option_uuid = $row['ivr_menu_option_uuid']; $ivr_menu_option_uuid = $row['ivr_menu_option_uuid'];
} }
else { else {
$ivr_menu_option_uuid = uuid(); $ivr_menu_option_uuid = uuid();
} }
if (is_numeric($row["ivr_menu_option_param"])) { if (isset($row["ivr_menu_option_param"]) && is_numeric($row["ivr_menu_option_param"])) {
//add the ivr menu syntax //add the ivr menu syntax
$ivr_menu_option_action = "menu-exec-app"; $ivr_menu_option_action = "menu-exec-app";
$ivr_menu_option_param = "transfer ".$row["ivr_menu_option_param"]." XML ".$ivr_menu_context; $ivr_menu_option_param = "transfer ".$row["ivr_menu_option_param"]." XML ".$ivr_menu_context;
@ -324,7 +324,7 @@
} }
$array['ivr_menus'][0]['ivr_menu_options'][$y]["ivr_menu_option_order"] = $row["ivr_menu_option_order"]; $array['ivr_menus'][0]['ivr_menu_options'][$y]["ivr_menu_option_order"] = $row["ivr_menu_option_order"];
$array['ivr_menus'][0]['ivr_menu_options'][$y]["ivr_menu_option_description"] = $row["ivr_menu_option_description"]; $array['ivr_menus'][0]['ivr_menu_options'][$y]["ivr_menu_option_description"] = $row["ivr_menu_option_description"];
$array['ivr_menus'][0]["ivr_menu_options"][$y]["ivr_menu_option_enabled"] = $row['ivr_menu_option_enabled'] ?: 'false'; $array['ivr_menus'][0]["ivr_menu_options"][$y]["ivr_menu_option_enabled"] = !empty($row['ivr_menu_option_enabled']) ?: 'false';
$y++; $y++;
} }
} }
@ -352,7 +352,7 @@
} }
$dialplan_xml .= " <action application=\"set\" data=\"ivr_menu_uuid=".xml::sanitize($ivr_menu_uuid)."\"/>\n"; $dialplan_xml .= " <action application=\"set\" data=\"ivr_menu_uuid=".xml::sanitize($ivr_menu_uuid)."\"/>\n";
if ($_SESSION['ivr_menu']['application']['text'] == "lua") { if (!empty($_SESSION['ivr_menu']['application']['text']) && $_SESSION['ivr_menu']['application']['text'] == "lua") {
$dialplan_xml .= " <action application=\"lua\" data=\"ivr_menu.lua\"/>\n"; $dialplan_xml .= " <action application=\"lua\" data=\"ivr_menu.lua\"/>\n";
} }
else { else {
@ -408,8 +408,7 @@
if ( if (
$action == 'update' $action == 'update'
&& permission_exists('ivr_menu_option_delete') && permission_exists('ivr_menu_option_delete')
&& is_array($ivr_menu_options_delete) && !empty($ivr_menu_options_delete)
&& @sizeof($ivr_menu_options_delete) != 0
) { ) {
$obj = new ivr_menu; $obj = new ivr_menu;
$obj->ivr_menu_uuid = $ivr_menu_uuid; $obj->ivr_menu_uuid = $ivr_menu_uuid;
@ -436,8 +435,10 @@
$parameters['ivr_menu_parent_uuid'] = $ivr_menu_parent_uuid; $parameters['ivr_menu_parent_uuid'] = $ivr_menu_parent_uuid;
$database = new database; $database = new database;
$parent_uuids = $database->select($sql, $parameters, "all"); $parent_uuids = $database->select($sql, $parameters, "all");
foreach ($parent_uuids as $x => $row) { if (!empty($parent_uuids)) {
$cache->delete("configuration:ivr.conf:".$row['ivr_menu_parent_uuid']); foreach ($parent_uuids as $x => $row) {
$cache->delete("configuration:ivr.conf:".$row['ivr_menu_parent_uuid']);
}
} }
//set the add message //set the add message
if ($action == "add" && permission_exists('ivr_menu_add')) { if ($action == "add" && permission_exists('ivr_menu_add')) {
@ -511,7 +512,9 @@
$ivr_menu_language = $ivr_menu_language ?? ''; $ivr_menu_language = $ivr_menu_language ?? '';
$ivr_menu_dialect = $ivr_menu_language ?? ''; $ivr_menu_dialect = $ivr_menu_language ?? '';
$ivr_menu_voice = $ivr_menu_voice ?? ''; $ivr_menu_voice = $ivr_menu_voice ?? '';
$select_style = $select_style ?? '';
$onkeyup = $onkeyup ?? '';
//get the ivr menu options //get the ivr menu options
$sql = "select * from v_ivr_menu_options "; $sql = "select * from v_ivr_menu_options ";
$sql .= "where domain_uuid = :domain_uuid "; $sql .= "where domain_uuid = :domain_uuid ";
@ -733,7 +736,7 @@
echo "<td class='vtable' align='left'>\n"; echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' type='text' name='ivr_menu_language'>\n"; echo " <select class='formfld' type='text' name='ivr_menu_language'>\n";
echo " <option></option>\n"; echo " <option></option>\n";
if (!empty($ivr_menu_language)) { if (!empty($ivr_menu_language) && !empty($ivr_menu_dialect) && !empty($ivr_menu_voice)) {
$language_formatted = $ivr_menu_language."-".$ivr_menu_dialect." ".$ivr_menu_voice; $language_formatted = $ivr_menu_language."-".$ivr_menu_dialect." ".$ivr_menu_voice;
echo " <option value='".escape($ivr_menu_language.'/'.$ivr_menu_dialect.'/'.$ivr_menu_voice)."' selected='selected'>".escape($language_formatted)."</option>\n"; echo " <option value='".escape($ivr_menu_language.'/'.$ivr_menu_dialect.'/'.$ivr_menu_voice)."' selected='selected'>".escape($language_formatted)."</option>\n";
} }
@ -749,7 +752,7 @@
} }
} }
echo "<br />\n"; echo "<br />\n";
echo $text['description-language']."\n"; //echo $text['description-language']."\n";
echo "</td>\n"; echo "</td>\n";
echo "</tr>\n"; echo "</tr>\n";
@ -770,7 +773,7 @@
$script .= " tb.className='formfld';\n"; $script .= " tb.className='formfld';\n";
$script .= " tb.setAttribute('id', '".$destination_id."');\n"; $script .= " tb.setAttribute('id', '".$destination_id."');\n";
$script .= " tb.setAttribute('style', '".$select_style."');\n"; $script .= " tb.setAttribute('style', '".$select_style."');\n";
if ($on_change != '') { if (!empty($on_change)) {
$script .= " tb.setAttribute('onchange', \"".$on_change."\");\n"; $script .= " tb.setAttribute('onchange', \"".$on_change."\");\n";
$script .= " tb.setAttribute('onkeyup', \"".$on_change."\");\n"; $script .= " tb.setAttribute('onkeyup', \"".$on_change."\");\n";
} }
@ -794,7 +797,7 @@
$script .= " obj[0].parentNode.removeChild(obj[1]);\n"; $script .= " obj[0].parentNode.removeChild(obj[1]);\n";
$script .= " obj[0].parentNode.removeChild(obj[2]);\n"; $script .= " obj[0].parentNode.removeChild(obj[2]);\n";
$script .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n"; $script .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n";
if ($on_change != '') { if (!empty($on_change)) {
$script .= " ".$on_change.";\n"; $script .= " ".$on_change.";\n";
} }
$script .= "}\n"; $script .= "}\n";
@ -813,7 +816,7 @@
} }
//recordings //recordings
$tmp_selected = false; $tmp_selected = false;
if (is_array($recordings)) { if (!empty($recordings) && !empty($_SESSION['switch']['recordings']['dir'])) {
echo "<optgroup label='Recordings'>\n"; echo "<optgroup label='Recordings'>\n";
foreach ($recordings as &$row) { foreach ($recordings as &$row) {
$recording_name = $row["recording_name"]; $recording_name = $row["recording_name"];
@ -833,7 +836,7 @@
echo "</optgroup>\n"; echo "</optgroup>\n";
} }
//phrases //phrases
if (is_array($phrases)) { if (!empty($phrases)) {
echo "<optgroup label='Phrases'>\n"; echo "<optgroup label='Phrases'>\n";
foreach ($phrases as &$row) { foreach ($phrases as &$row) {
if ($ivr_menu_greet_long == "phrase:".$row["phrase_uuid"]) { if ($ivr_menu_greet_long == "phrase:".$row["phrase_uuid"]) {
@ -848,7 +851,7 @@
} }
//sounds //sounds
/* /*
if (is_array($sound_files)) { if (!empty($sound_files)) {
echo "<optgroup label='Sounds'>\n"; echo "<optgroup label='Sounds'>\n";
foreach ($sound_files as $value) { foreach ($sound_files as $value) {
if (!empty($value)) { if (!empty($value)) {
@ -868,7 +871,7 @@
} }
*/ */
//select //select
if (if_group("superadmin")) { if (if_group("superadmin") && !empty($_SESSION['switch']['recordings']['dir'])) {
if (!$tmp_selected && !empty($ivr_menu_greet_long)) { if (!$tmp_selected && !empty($ivr_menu_greet_long)) {
echo "<optgroup label='Selected'>\n"; echo "<optgroup label='Selected'>\n";
if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_greet_long)) { if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_greet_long)) {
@ -911,7 +914,7 @@
$script .= " tb.className='formfld';\n"; $script .= " tb.className='formfld';\n";
$script .= " tb.setAttribute('id', '".$destination_id."');\n"; $script .= " tb.setAttribute('id', '".$destination_id."');\n";
$script .= " tb.setAttribute('style', '".$select_style."');\n"; $script .= " tb.setAttribute('style', '".$select_style."');\n";
if ($on_change != '') { if (!empty($on_change)) {
$script .= " tb.setAttribute('onchange', \"".$on_change."\");\n"; $script .= " tb.setAttribute('onchange', \"".$on_change."\");\n";
$script .= " tb.setAttribute('onkeyup', \"".$on_change."\");\n"; $script .= " tb.setAttribute('onkeyup', \"".$on_change."\");\n";
} }
@ -935,7 +938,7 @@
$script .= " obj[0].parentNode.removeChild(obj[1]);\n"; $script .= " obj[0].parentNode.removeChild(obj[1]);\n";
$script .= " obj[0].parentNode.removeChild(obj[2]);\n"; $script .= " obj[0].parentNode.removeChild(obj[2]);\n";
$script .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n"; $script .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n";
if ($on_change != '') { if (!empty($on_change)) {
$script .= " ".$on_change.";\n"; $script .= " ".$on_change.";\n";
} }
$script .= "}\n"; $script .= "}\n";
@ -954,7 +957,7 @@
} }
//recordings //recordings
$tmp_selected = false; $tmp_selected = false;
if (!empty($recordings)) { if (!empty($recordings) && !empty($_SESSION['switch']['recordings']['dir'])) {
echo "<optgroup label='Recordings'>\n"; echo "<optgroup label='Recordings'>\n";
foreach ($recordings as &$row) { foreach ($recordings as &$row) {
$recording_name = $row["recording_name"]; $recording_name = $row["recording_name"];
@ -1009,7 +1012,7 @@
} }
*/ */
//select //select
if (if_group("superadmin")) { if (if_group("superadmin") && !empty($_SESSION['switch']['recordings']['dir'])) {
if (!$tmp_selected && !empty($ivr_menu_greet_short)) { if (!$tmp_selected && !empty($ivr_menu_greet_short)) {
echo "<optgroup label='Selected'>\n"; echo "<optgroup label='Selected'>\n";
if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_greet_short)) { if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_greet_short)) {
@ -1062,7 +1065,7 @@
} }
echo "<td class='formfld' align='center'>\n"; echo "<td class='formfld' align='center'>\n";
if (!is_uuid($field['ivr_menu_option_uuid'])) { // new record if (empty($field['ivr_menu_option_uuid'])) { // new record
if (substr($_SESSION['theme']['input_toggle_style']['text'], 0, 6) == 'switch') { if (substr($_SESSION['theme']['input_toggle_style']['text'], 0, 6) == 'switch') {
$onkeyup = "onkeyup=\"document.getElementById('ivr_menu_options_".$x."_ivr_menu_option_enabled').checked = (this.value != '' ? true : false);\""; // switch $onkeyup = "onkeyup=\"document.getElementById('ivr_menu_options_".$x."_ivr_menu_option_enabled').checked = (this.value != '' ? true : false);\""; // switch
} }
@ -1115,12 +1118,12 @@
else { else {
echo " <select class='formfld' id='ivr_menu_options_".$x."_ivr_menu_option_enabled' name='ivr_menu_options[".$x."][ivr_menu_option_enabled]'>\n"; echo " <select class='formfld' id='ivr_menu_options_".$x."_ivr_menu_option_enabled' name='ivr_menu_options[".$x."][ivr_menu_option_enabled]'>\n";
echo " <option value='false'>".$text['option-false']."</option>\n"; echo " <option value='false'>".$text['option-false']."</option>\n";
echo " <option value='true' ".($field['ivr_menu_option_enabled'] == 'true' ? "selected='selected'" : null).">".$text['option-true']."</option>\n"; echo " <option value='true' ".(!empty($field['ivr_menu_option_enabled']) && $field['ivr_menu_option_enabled'] == 'true' ? "selected='selected'" : null).">".$text['option-true']."</option>\n";
echo " </select>\n"; echo " </select>\n";
} }
echo "</td>\n"; echo "</td>\n";
if ($show_option_delete && permission_exists('ivr_menu_option_delete')) { if ($show_option_delete && permission_exists('ivr_menu_option_delete')) {
if (is_uuid($field['ivr_menu_option_uuid'])) { if (!empty($field['ivr_menu_option_uuid']) && is_uuid($field['ivr_menu_option_uuid'])) {
echo "<td class='vtable' style='text-align: center; padding-bottom: 3px;'>"; echo "<td class='vtable' style='text-align: center; padding-bottom: 3px;'>";
echo " <input type='checkbox' name='ivr_menu_options_delete[".$x."][checked]' value='true' class='chk_delete checkbox_options' onclick=\"edit_delete_action('options');\">\n"; echo " <input type='checkbox' name='ivr_menu_options_delete[".$x."][checked]' value='true' class='chk_delete checkbox_options' onclick=\"edit_delete_action('options');\">\n";
echo " <input type='hidden' name='ivr_menu_options_delete[".$x."][uuid]' value='".escape($field['ivr_menu_option_uuid'])."' />\n"; echo " <input type='hidden' name='ivr_menu_options_delete[".$x."][uuid]' value='".escape($field['ivr_menu_option_uuid'])."' />\n";
@ -1288,7 +1291,7 @@
} }
//recordings //recordings
$tmp_selected = false; $tmp_selected = false;
if (is_array($recordings)) { if (is_array($recordings) && !empty($_SESSION['switch']['recordings']['dir'])) {
echo "<optgroup label='Recordings'>\n"; echo "<optgroup label='Recordings'>\n";
foreach ($recordings as &$row) { foreach ($recordings as &$row) {
$recording_name = $row["recording_name"]; $recording_name = $row["recording_name"];
@ -1341,7 +1344,7 @@
echo "</optgroup>\n"; echo "</optgroup>\n";
} }
//select //select
if (if_group("superadmin")) { if (if_group("superadmin") && !empty($_SESSION['switch']['recordings']['dir'])) {
if (!$tmp_selected && !empty($ivr_menu_invalid_sound)) { if (!$tmp_selected && !empty($ivr_menu_invalid_sound)) {
echo "<optgroup label='Selected'>\n"; echo "<optgroup label='Selected'>\n";
if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_invalid_sound)) { if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_invalid_sound)) {
@ -1377,7 +1380,7 @@
} }
//recordings //recordings
$tmp_selected = false; $tmp_selected = false;
if (is_array($recordings)) { if (is_array($recordings) && !empty($_SESSION['switch']['recordings']['dir'])) {
echo "<optgroup label='Recordings'>\n"; echo "<optgroup label='Recordings'>\n";
foreach ($recordings as &$row) { foreach ($recordings as &$row) {
$recording_name = $row["recording_name"]; $recording_name = $row["recording_name"];
@ -1430,7 +1433,7 @@
echo "</optgroup>\n"; echo "</optgroup>\n";
} }
//select //select
if (if_group("superadmin")) { if (if_group("superadmin") && !empty($_SESSION['switch']['recordings']['dir'])) {
if (!$tmp_selected && !empty($ivr_menu_exit_sound)) { if (!$tmp_selected && !empty($ivr_menu_exit_sound)) {
echo "<optgroup label='Selected'>\n"; echo "<optgroup label='Selected'>\n";
if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_exit_sound)) { if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_exit_sound)) {

View File

@ -46,15 +46,20 @@
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//define defaults
$action = '';
$search = '';
$ivr_menus = '';
//get posted data //get posted data
if (is_array($_POST['ivr_menus'])) { if (!empty($_POST['ivr_menus'])) {
$action = $_POST['action']; $action = $_POST['action'];
$search = $_POST['search']; $search = $_POST['search'];
$ivr_menus = $_POST['ivr_menus']; $ivr_menus = $_POST['ivr_menus'];
} }
//process the http post data by action //process the http post data by action
if ($action != '' && is_array($ivr_menus) && @sizeof($ivr_menus) != 0) { if (!empty($action) && is_array($ivr_menus) && @sizeof($ivr_menus) != 0) {
switch ($action) { switch ($action) {
case 'copy': case 'copy':
if (permission_exists('ivr_menu_add')) { if (permission_exists('ivr_menu_add')) {
@ -76,62 +81,73 @@
break; break;
} }
header('Location: ivr_menus.php'.($search != '' ? '?search='.urlencode($search) : null)); header('Location: ivr_menus.php'.(!empty($search) ? '?search='.urlencode($search) : null));
exit; exit;
} }
//get order and order by //get order and order by
$order_by = $_GET["order_by"]; $order_by = $_GET["order_by"] ?? '';
$order = $_GET["order"]; $order = $_GET["order"] ?? '';
//add the search term //add the search variable
$search = strtolower($_GET["search"]); $search = $_GET["search"] ?? '';
if (!empty($search)) { $show = $_GET["show"] ?? '';
$sql_search = "and (";
$sql_search .= "lower(ivr_menu_name) like :search ";
$sql_search .= "or lower(ivr_menu_extension) like :search ";
$sql_search .= "or lower(ivr_menu_enabled) like :search ";
$sql_search .= "or lower(ivr_menu_description) like :search ";
$sql_search .= ")";
$parameters['search'] = '%'.$search.'%';
}
//set from session variables
$list_row_edit_button = !empty($_SESSION['theme']['list_row_edit_button']['boolean']) ? $_SESSION['theme']['list_row_edit_button']['boolean'] : 'false';
//prepare to page the results //prepare to page the results
$sql = "select count(*) from v_ivr_menus "; $sql = "select count(*) from v_ivr_menus ";
$sql .= "where true "; $sql .= "where true ";
if ($_GET['show'] != "all" || !permission_exists('ivr_menu_all')) { if (!empty($show) && $show != "all" || !permission_exists('ivr_menu_all')) {
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) "; $sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
} }
$database = new database; if (!empty($search)) {
$total_ivr_menus = $database->select($sql, $parameters, 'column'); $search = strtolower($search);
$num_rows = $total_ivr_menus; $sql .= "and (";
$sql .= " lower(ivr_menu_name) like :search ";
//prepare to page the results $sql .= " or lower(ivr_menu_extension) like :search ";
if ($sql_search) { $sql .= " or lower(ivr_menu_enabled) like :search ";
$sql .= $sql_search; $sql .= " or lower(ivr_menu_description) like :search ";
$database = new database; $sql .= ")";
$num_rows = $database->select($sql, $parameters, 'column'); $parameters['search'] = '%'.$search.'%';
} }
$database = new database;
$num_rows = $database->select($sql, $parameters ?? '', 'column');
//prepare to page the results //prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $rows_per_page = (!empty($_SESSION['domain']['paging']['numeric'])) ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = "&search=".urlencode($search); $param = "&search=".urlencode($search);
if ($_GET['show'] == "all" && permission_exists('ivr_menu_all')) { if ($show == "all" && permission_exists('ivr_menu_all')) {
$param .= "&show=all"; $param .= "&show=all";
} }
$page = is_numeric($_GET['page']) ? $_GET['page'] : 0; $page = !empty($_GET['page']) ? $_GET['page'] : 0;
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page); list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true); list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page; $offset = $rows_per_page * $page;
//get the list //get the list
$sql = str_replace('count(*)', '*', $sql); $sql = "select * from v_ivr_menus ";
$sql .= "where true ";
if (!empty($show) && $show != "all" || !permission_exists('ivr_menu_all')) {
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
}
if (!empty($search)) {
$search = strtolower($search);
$sql .= "and (";
$sql .= " lower(ivr_menu_name) like :search ";
$sql .= " or lower(ivr_menu_extension) like :search ";
$sql .= " or lower(ivr_menu_enabled) like :search ";
$sql .= " or lower(ivr_menu_description) like :search ";
$sql .= ")";
$parameters['search'] = '%'.$search.'%';
}
$sql .= order_by($order_by, $order, 'ivr_menu_name', 'asc'); $sql .= order_by($order_by, $order, 'ivr_menu_name', 'asc');
$sql .= limit_offset($rows_per_page, $offset); $sql .= limit_offset($rows_per_page, $offset);
$database = new database; $database = new database;
$ivr_menus = $database->select($sql, $parameters, 'all'); $ivr_menus = $database->select($sql, $parameters ?? '', 'all');
unset($sql, $parameters); unset($sql, $parameters);
//create token //create token
@ -146,10 +162,10 @@
echo "<div class='action_bar' id='action_bar'>\n"; echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-ivr_menus']." (".$num_rows.")</b></div>\n"; echo " <div class='heading'><b>".$text['title-ivr_menus']." (".$num_rows.")</b></div>\n";
echo " <div class='actions'>\n"; echo " <div class='actions'>\n";
if (permission_exists('ivr_menu_add') && (!is_numeric($_SESSION['limit']['ivr_menus']['numeric']) || $total_ivr_menus < $_SESSION['limit']['ivr_menus']['numeric'])) { if (permission_exists('ivr_menu_add') && (empty($_SESSION['limit']['ivr_menus']['numeric']) || $num_rows < $_SESSION['limit']['ivr_menus']['numeric'])) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'ivr_menu_edit.php']); echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','link'=>'ivr_menu_edit.php']);
} }
if (permission_exists('ivr_menu_add') && $ivr_menus && (!is_numeric($_SESSION['limit']['ivr_menus']['numeric']) || $total_ivr_menus < $_SESSION['limit']['ivr_menus']['numeric'])) { if (permission_exists('ivr_menu_add') && $ivr_menus && (empty($_SESSION['limit']['ivr_menus']['numeric']) || $num_rows < $_SESSION['limit']['ivr_menus']['numeric'])) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]);
} }
if (permission_exists('ivr_menu_edit') && $ivr_menus) { if (permission_exists('ivr_menu_edit') && $ivr_menus) {
@ -160,7 +176,7 @@
} }
echo "<form id='form_search' class='inline' method='get'>\n"; echo "<form id='form_search' class='inline' method='get'>\n";
if (permission_exists('ivr_menu_all')) { if (permission_exists('ivr_menu_all')) {
if ($_GET['show'] == 'all') { if ($show == 'all') {
echo " <input type='hidden' name='show' value='all'>"; echo " <input type='hidden' name='show' value='all'>";
} }
else { else {
@ -199,22 +215,22 @@
echo "<tr class='list-header'>\n"; echo "<tr class='list-header'>\n";
if (permission_exists('ivr_menu_add') || permission_exists('ivr_menu_edit') || permission_exists('ivr_menu_delete')) { if (permission_exists('ivr_menu_add') || permission_exists('ivr_menu_edit') || permission_exists('ivr_menu_delete')) {
echo " <th class='checkbox'>\n"; echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".($ivr_menus ?: "style='visibility: hidden;'").">\n"; echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(!empty($ivr_menus) ?: "style='visibility: hidden;'").">\n";
echo " </th>\n"; echo " </th>\n";
} }
if ($_GET['show'] == "all" && permission_exists('ivr_menu_all')) { if ($show == "all" && permission_exists('ivr_menu_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param, "class='shrink'"); echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param, "class='shrink'");
} }
echo th_order_by('ivr_menu_name', $text['label-name'], $order_by, $order); echo th_order_by('ivr_menu_name', $text['label-name'], $order_by, $order);
echo th_order_by('ivr_menu_extension', $text['label-extension'], $order_by, $order); echo th_order_by('ivr_menu_extension', $text['label-extension'], $order_by, $order);
echo th_order_by('ivr_menu_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'"); echo th_order_by('ivr_menu_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('ivr_menu_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'"); echo th_order_by('ivr_menu_description', $text['label-description'], $order_by, $order, null, "class='hide-sm-dn'");
if (permission_exists('ivr_menu_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { if (permission_exists('ivr_menu_edit') && $list_row_edit_button == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n"; echo " <td class='action-button'>&nbsp;</td>\n";
} }
echo "</tr>\n"; echo "</tr>\n";
if (is_array($ivr_menus) && @sizeof($ivr_menus) != 0) { if (!empty($ivr_menus)) {
$x = 0; $x = 0;
foreach($ivr_menus as $row) { foreach($ivr_menus as $row) {
if (permission_exists('ivr_menu_edit')) { if (permission_exists('ivr_menu_edit')) {
@ -227,7 +243,7 @@
echo " <input type='hidden' name='ivr_menus[$x][uuid]' value='".escape($row['ivr_menu_uuid'])."' />\n"; echo " <input type='hidden' name='ivr_menus[$x][uuid]' value='".escape($row['ivr_menu_uuid'])."' />\n";
echo " </td>\n"; echo " </td>\n";
} }
if ($_GET['show'] == "all" && permission_exists('ivr_menu_all')) { if ($show == "all" && permission_exists('ivr_menu_all')) {
if (!empty($_SESSION['domains'][$row['domain_uuid']]['domain_name'])) { if (!empty($_SESSION['domains'][$row['domain_uuid']]['domain_name'])) {
$domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name']; $domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name'];
} }
@ -255,7 +271,7 @@
} }
echo " </td>\n"; echo " </td>\n";
echo " <td class='description overflow hide-sm-dn'>".escape($row['ivr_menu_description'])."&nbsp;</td>\n"; echo " <td class='description overflow hide-sm-dn'>".escape($row['ivr_menu_description'])."&nbsp;</td>\n";
if (permission_exists('ivr_menu_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { if (permission_exists('ivr_menu_edit') && $list_row_edit_button == 'true') {
echo " <td class='action-button'>"; echo " <td class='action-button'>";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n"; echo " </td>\n";

View File

@ -17,7 +17,7 @@
The Initial Developer of the Original Code is The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com> Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2008-2019 Portions created by the Initial Developer are Copyright (C) 2008-2023
the Initial Developer. All Rights Reserved. the Initial Developer. All Rights Reserved.
Contributor(s): Contributor(s):
@ -81,96 +81,99 @@ if (!class_exists('ivr_menu')) {
$this->permission_prefix = 'ivr_menu_'; $this->permission_prefix = 'ivr_menu_';
$this->table = 'ivr_menus'; $this->table = 'ivr_menus';
$this->uuid_prefix = 'ivr_menu_'; $this->uuid_prefix = 'ivr_menu_';
//return if permission does not exist
if (!permission_exists($this->permission_prefix.'delete')) {
return false;
}
if (permission_exists($this->permission_prefix.'delete')) { //add multi-lingual support
$language = new text;
$text = $language->get();
//add multi-lingual support //validate the token
$language = new text; $token = new token;
$text = $language->get(); if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//validate the token //delete multiple records
$token = new token; if (!empty($records)) {
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//delete multiple records //filter out unchecked ivr menus, build where clause for below
if (is_array($records) && @sizeof($records) != 0) { foreach ($records as $record) {
if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) {
$uuids[] = "'".$record['uuid']."'";
}
}
//filter out unchecked ivr menus, build where clause for below //get necessary ivr menu details
foreach ($records as $record) { if (!empty($uuids)) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { $sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid, ivr_menu_context from v_".$this->table." ";
$uuids[] = "'".$record['uuid']."'"; $sql .= "where (domain_uuid = :domain_uuid) ";
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$ivr_menus[$row['uuid']]['dialplan_uuid'] = $row['dialplan_uuid'];
$ivr_menu_contexts[] = $row['ivr_menu_context'];
} }
} }
unset($sql, $parameters, $rows, $row);
}
//get necessary ivr menu details //build the delete array
if (is_array($uuids) && @sizeof($uuids) != 0) { $x = 0;
$sql = "select ".$this->uuid_prefix."uuid as uuid, dialplan_uuid, ivr_menu_context from v_".$this->table." "; foreach ($ivr_menus as $ivr_menu_uuid => $ivr_menu) {
$sql .= "where (domain_uuid = :domain_uuid) "; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $ivr_menu_uuid;
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") "; $array['ivr_menu_options'][$x]['ivr_menu_uuid'] = $ivr_menu_uuid;
$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $array['dialplans'][$x]['dialplan_uuid'] = $ivr_menu['dialplan_uuid'];
$x++;
}
//delete the checked rows
if (!empty($array)) {
//grant temporary permissions
$p = new permissions;
$p->add('ivr_menu_option_delete', 'temp');
$p->add('dialplan_delete', 'temp');
//execute delete
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $database->app_name = $this->app_name;
if (is_array($rows) && @sizeof($rows) != 0) { $database->app_uuid = $this->app_uuid;
foreach ($rows as $row) { $database->delete($array);
$ivr_menus[$row['uuid']]['dialplan_uuid'] = $row['dialplan_uuid']; unset($array);
$ivr_menu_contexts[] = $row['ivr_menu_context'];
//revoke temporary permissions
$p->delete('ivr_menu_option_delete', 'temp');
$p->delete('dialplan_delete', 'temp');
//clear the cache
if (is_array($ivr_menu_contexts) && @sizeof($ivr_menu_contexts) != 0) {
$ivr_menu_contexts = array_unique($ivr_menu_contexts);
$cache = new cache;
foreach ($ivr_menu_contexts as $ivr_menu_context) {
$cache->delete("dialplan:".$ivr_menu_context);
} }
} }
unset($sql, $parameters, $rows, $row);
}
//build the delete array //clear the destinations session array
$x = 0; if (isset($_SESSION['destinations']['array'])) {
foreach ($ivr_menus as $ivr_menu_uuid => $ivr_menu) { unset($_SESSION['destinations']['array']);
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $ivr_menu_uuid; }
$array['ivr_menu_options'][$x]['ivr_menu_uuid'] = $ivr_menu_uuid;
$array['dialplans'][$x]['dialplan_uuid'] = $ivr_menu['dialplan_uuid'];
$x++;
}
//delete the checked rows //set message
if (is_array($array) && @sizeof($array) != 0) { message::add($text['message-delete']);
}
unset($records, $ivr_menus);
}
//grant temporary permissions
$p = new permissions;
$p->add('ivr_menu_option_delete', 'temp');
$p->add('dialplan_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('ivr_menu_option_delete', 'temp');
$p->delete('dialplan_delete', 'temp');
//clear the cache
if (is_array($ivr_menu_contexts) && @sizeof($ivr_menu_contexts) != 0) {
$ivr_menu_contexts = array_unique($ivr_menu_contexts);
$cache = new cache;
foreach ($ivr_menu_contexts as $ivr_menu_context) {
$cache->delete("dialplan:".$ivr_menu_context);
}
}
//clear the destinations session array
if (isset($_SESSION['destinations']['array'])) {
unset($_SESSION['destinations']['array']);
}
//set message
message::add($text['message-delete']);
}
unset($records, $ivr_menus);
}
}
} }
public function delete_options($records) { public function delete_options($records) {
@ -179,65 +182,67 @@ if (!class_exists('ivr_menu')) {
$this->table = 'ivr_menu_options'; $this->table = 'ivr_menu_options';
$this->uuid_prefix = 'ivr_menu_option_'; $this->uuid_prefix = 'ivr_menu_option_';
if (permission_exists($this->permission_prefix.'delete')) { //return if permission does not exist
if (!permission_exists($this->permission_prefix.'delete')) {
return false;
}
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//validate the token //validate the token
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page); header('Location: '.$this->list_page);
exit; exit;
} }
//delete multiple records //delete multiple records
if (is_array($records) && @sizeof($records) != 0) { if (!empty($records)) {
//filter out unchecked ivr menu options, build delete array //filter out unchecked ivr menu options, build delete array
$x = 0; $x = 0;
foreach ($records as $record) { foreach ($records as $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid']; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
$array[$this->table][$x]['ivr_menu_uuid'] = $this->ivr_menu_uuid; $array[$this->table][$x]['ivr_menu_uuid'] = $this->ivr_menu_uuid;
$x++; $x++;
}
} }
}
//get ivr menu context //get ivr menu context
if (is_array($array) && @sizeof($array) != 0 && is_uuid($this->ivr_menu_uuid)) { if (!empty($array) && !empty($this->ivr_menu_uuid) && is_uuid($this->ivr_menu_uuid)) {
$sql = "select ivr_menu_context from v_ivr_menus "; $sql = "select ivr_menu_context from v_ivr_menus ";
$sql .= "where (domain_uuid = :domain_uuid) "; $sql .= "where (domain_uuid = :domain_uuid) ";
$sql .= "and ivr_menu_uuid = :ivr_menu_uuid "; $sql .= "and ivr_menu_uuid = :ivr_menu_uuid ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['ivr_menu_uuid'] = $this->ivr_menu_uuid; $parameters['ivr_menu_uuid'] = $this->ivr_menu_uuid;
$database = new database;
$ivr_menu_context = $database->select($sql, $parameters, 'column');
unset($sql, $parameters);
}
//delete the checked rows
if (!empty($array)) {
//execute delete
$database = new database; $database = new database;
$ivr_menu_context = $database->select($sql, $parameters, 'column'); $database->app_name = $this->app_name;
unset($sql, $parameters); $database->app_uuid = $this->app_uuid;
} $database->delete($array);
unset($array);
//delete the checked rows //clear the cache
if (is_array($array) && @sizeof($array) != 0) { if (!empty($ivr_menu_context)) {
$cache = new cache;
$cache->delete("dialplan:".$ivr_menu_context);
}
//execute delete }
$database = new database; unset($records);
$database->app_name = $this->app_name; }
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
//clear the cache
if ($ivr_menu_context != '') {
$cache = new cache;
$cache->delete("dialplan:".$ivr_menu_context);
}
}
unset($records);
}
}
} }
/** /**
@ -251,91 +256,93 @@ if (!class_exists('ivr_menu')) {
$this->toggle_field = 'ivr_menu_enabled'; $this->toggle_field = 'ivr_menu_enabled';
$this->toggle_values = ['true','false']; $this->toggle_values = ['true','false'];
if (permission_exists($this->permission_prefix.'edit')) { //return if permission does not exist
if (!permission_exists($this->permission_prefix.'edit')) {
return false;
}
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//validate the token //validate the token
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page); header('Location: '.$this->list_page);
exit; exit;
} }
//toggle the checked records //toggle the checked records
if (is_array($records) && @sizeof($records) != 0) { if (!empty($records)) {
//get current toggle state //get current toggle state
foreach($records as $x => $record) { foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
$uuids[] = "'".$record['uuid']."'"; $uuids[] = "'".$record['uuid']."'";
}
}
if (!empty($uuids)) {
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, dialplan_uuid from v_".$this->table." ";
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$ivr_menus[$row['uuid']]['state'] = $row['toggle'];
$ivr_menus[$row['uuid']]['dialplan_uuid'] = $row['dialplan_uuid'];
} }
} }
if (is_array($uuids) && @sizeof($uuids) != 0) { unset($sql, $parameters, $rows, $row);
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle, dialplan_uuid from v_".$this->table." "; }
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") "; //build update array
$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $x = 0;
foreach ($ivr_menus as $uuid => $ivr_menu) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array[$this->table][$x][$this->toggle_field] = $ivr_menu['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$array['dialplans'][$x]['dialplan_uuid'] = $ivr_menu['dialplan_uuid'];
$array['dialplans'][$x]['dialplan_enabled'] = $ivr_menu['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$x++;
}
//save the changes
if (!empty($array)) {
//grant temporary permissions
$p = new permissions;
$p->add('dialplan_edit', 'temp');
//save the array
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $database->app_name = $this->app_name;
if (is_array($rows) && @sizeof($rows) != 0) { $database->app_uuid = $this->app_uuid;
foreach ($rows as $row) { $database->save($array);
$ivr_menus[$row['uuid']]['state'] = $row['toggle']; unset($array);
$ivr_menus[$row['uuid']]['dialplan_uuid'] = $row['dialplan_uuid'];
} //revoke temporary permissions
$p->delete('dialplan_edit', 'temp');
//clear the cache
$cache = new cache;
$cache->delete("dialplan:".$_SESSION['domain_name']);
foreach ($ivr_menus as $ivr_menu_uuid => $ivr_menu) {
$cache->delete("configuration:ivr.conf:".$ivr_menu_uuid);
} }
unset($sql, $parameters, $rows, $row);
}
//build update array //clear the destinations session array
$x = 0; if (isset($_SESSION['destinations']['array'])) {
foreach ($ivr_menus as $uuid => $ivr_menu) { unset($_SESSION['destinations']['array']);
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid; }
$array[$this->table][$x][$this->toggle_field] = $ivr_menu['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$array['dialplans'][$x]['dialplan_uuid'] = $ivr_menu['dialplan_uuid'];
$array['dialplans'][$x]['dialplan_enabled'] = $ivr_menu['state'] == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$x++;
}
//save the changes //set message
if (is_array($array) && @sizeof($array) != 0) { message::add($text['message-toggle']);
}
unset($records, $states);
}
//grant temporary permissions
$p = new permissions;
$p->add('dialplan_edit', 'temp');
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('dialplan_edit', 'temp');
//clear the cache
$cache = new cache;
$cache->delete("dialplan:".$_SESSION['domain_name']);
foreach ($ivr_menus as $ivr_menu_uuid => $ivr_menu) {
$cache->delete("configuration:ivr.conf:".$ivr_menu_uuid);
}
//clear the destinations session array
if (isset($_SESSION['destinations']['array'])) {
unset($_SESSION['destinations']['array']);
}
//set message
message::add($text['message-toggle']);
}
unset($records, $states);
}
}
} }
/** /**
@ -347,136 +354,138 @@ if (!class_exists('ivr_menu')) {
$this->table = 'ivr_menus'; $this->table = 'ivr_menus';
$this->uuid_prefix = 'ivr_menu_'; $this->uuid_prefix = 'ivr_menu_';
if (permission_exists($this->permission_prefix.'add')) { //return if permission does not exist
if (!permission_exists($this->permission_prefix.'add')) {
return false;
}
//add multi-lingual support //add multi-lingual support
$language = new text; $language = new text;
$text = $language->get(); $text = $language->get();
//validate the token //validate the token
$token = new token; $token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) { if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative'); message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page); header('Location: '.$this->list_page);
exit; exit;
} }
//copy the checked records //copy the checked records
if (is_array($records) && @sizeof($records) != 0) { if (!empty($records)) {
//get checked records //get checked records
foreach($records as $x => $record) { foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid']) && is_uuid($record['uuid'])) {
$uuids[] = "'".$record['uuid']."'"; $uuids[] = "'".$record['uuid']."'";
}
} }
}
//create insert array from existing data //create insert array from existing data
if (is_array($uuids) && @sizeof($uuids) != 0) { if (!empty($uuids)) {
//primary table //primary table
$sql = "select * from v_".$this->table." "; $sql = "select * from v_".$this->table." ";
$sql .= "where domain_uuid = :domain_uuid "; $sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") "; $sql .= "and ".$this->uuid_prefix."uuid in (".implode(', ', $uuids).") ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database; $database = new database;
$rows = $database->select($sql, $parameters, 'all'); $rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) { if (!empty($rows)) {
$y = $z = 0; $y = $z = 0;
foreach ($rows as $x => $row) { foreach ($rows as $x => $row) {
$new_ivr_menu_uuid = uuid(); $new_ivr_menu_uuid = uuid();
$new_dialplan_uuid = uuid(); $new_dialplan_uuid = uuid();
//copy data //copy data
$array[$this->table][$x] = $row; $array[$this->table][$x] = $row;
//overwrite //overwrite
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_ivr_menu_uuid; $array[$this->table][$x][$this->uuid_prefix.'uuid'] = $new_ivr_menu_uuid;
$array[$this->table][$x]['dialplan_uuid'] = $new_dialplan_uuid; $array[$this->table][$x]['dialplan_uuid'] = $new_dialplan_uuid;
$array[$this->table][$x]['ivr_menu_description'] = trim($row['ivr_menu_description'].' ('.$text['label-copy'].')'); $array[$this->table][$x]['ivr_menu_description'] = trim($row['ivr_menu_description'].' ('.$text['label-copy'].')');
//ivr menu options sub table //ivr menu options sub table
$sql_2 = "select * from v_ivr_menu_options where ivr_menu_uuid = :ivr_menu_uuid"; $sql_2 = "select * from v_ivr_menu_options where ivr_menu_uuid = :ivr_menu_uuid";
$parameters_2['ivr_menu_uuid'] = $row['ivr_menu_uuid']; $parameters_2['ivr_menu_uuid'] = $row['ivr_menu_uuid'];
$database = new database; $database = new database;
$rows_2 = $database->select($sql_2, $parameters_2, 'all'); $rows_2 = $database->select($sql_2, $parameters_2, 'all');
if (is_array($rows_2) && @sizeof($rows_2) != 0) { if (!empty($rows_2)) {
foreach ($rows_2 as $row_2) { foreach ($rows_2 as $row_2) {
//copy data
$array['ivr_menu_options'][$y] = $row_2;
//overwrite
$array['ivr_menu_options'][$y]['ivr_menu_option_uuid'] = uuid();
$array['ivr_menu_options'][$y]['ivr_menu_uuid'] = $new_ivr_menu_uuid;
//increment
$y++;
}
}
unset($sql_2, $parameters_2, $rows_2, $row_2);
//ivr menu dialplan record
$sql_3 = "select * from v_dialplans where dialplan_uuid = :dialplan_uuid";
$parameters_3['dialplan_uuid'] = $row['dialplan_uuid'];
$database = new database;
$dialplan = $database->select($sql_3, $parameters_3, 'row');
if (is_array($dialplan) && @sizeof($dialplan) != 0) {
//copy data //copy data
$array['dialplans'][$z] = $dialplan; $array['ivr_menu_options'][$y] = $row_2;
//overwrite //overwrite
$array['dialplans'][$z]['dialplan_uuid'] = $new_dialplan_uuid; $array['ivr_menu_options'][$y]['ivr_menu_option_uuid'] = uuid();
$dialplan_xml = $dialplan['dialplan_xml']; $array['ivr_menu_options'][$y]['ivr_menu_uuid'] = $new_ivr_menu_uuid;
$dialplan_xml = str_replace($row['ivr_menu_uuid'], $new_ivr_menu_uuid, $dialplan_xml); //replace source ivr_menu_uuid with new
$dialplan_xml = str_replace($dialplan['dialplan_uuid'], $new_dialplan_uuid, $dialplan_xml); //replace source dialplan_uuid with new
$array['dialplans'][$z]['dialplan_xml'] = $dialplan_xml;
$array['dialplans'][$z]['dialplan_description'] = trim($dialplan['dialplan_description'].' ('.$text['label-copy'].')');
//increment //increment
$z++; $y++;
} }
unset($sql_3, $parameters_3, $dialplan); }
unset($sql_2, $parameters_2, $rows_2, $row_2);
//ivr menu dialplan record
$sql_3 = "select * from v_dialplans where dialplan_uuid = :dialplan_uuid";
$parameters_3['dialplan_uuid'] = $row['dialplan_uuid'];
$database = new database;
$dialplan = $database->select($sql_3, $parameters_3, 'row');
if (!empty($dialplan)) {
//copy data
$array['dialplans'][$z] = $dialplan;
//overwrite
$array['dialplans'][$z]['dialplan_uuid'] = $new_dialplan_uuid;
$dialplan_xml = $dialplan['dialplan_xml'];
$dialplan_xml = str_replace($row['ivr_menu_uuid'], $new_ivr_menu_uuid, $dialplan_xml); //replace source ivr_menu_uuid with new
$dialplan_xml = str_replace($dialplan['dialplan_uuid'], $new_dialplan_uuid, $dialplan_xml); //replace source dialplan_uuid with new
$array['dialplans'][$z]['dialplan_xml'] = $dialplan_xml;
$array['dialplans'][$z]['dialplan_description'] = trim($dialplan['dialplan_description'].' ('.$text['label-copy'].')');
//increment
$z++;
}
unset($sql_3, $parameters_3, $dialplan);
}
} }
unset($sql, $parameters, $rows, $row); }
} unset($sql, $parameters, $rows, $row);
}
//save the changes and set the message //save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) { if (!empty($array)) {
//grant temporary permissions //grant temporary permissions
$p = new permissions; $p = new permissions;
$p->add('ivr_menu_option_add', 'temp'); $p->add('ivr_menu_option_add', 'temp');
$p->add('dialplan_add', 'temp'); $p->add('dialplan_add', 'temp');
//save the array //save the array
$database = new database; $database = new database;
$database->app_name = $this->app_name; $database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid; $database->app_uuid = $this->app_uuid;
$database->save($array); $database->save($array);
unset($array); unset($array);
//revoke temporary permissions //revoke temporary permissions
$p = new permissions; $p = new permissions;
$p->delete('ivr_menu_option_add', 'temp'); $p->delete('ivr_menu_option_add', 'temp');
$p->delete('dialplan_add', 'temp'); $p->delete('dialplan_add', 'temp');
//clear the cache //clear the cache
$cache = new cache; $cache = new cache;
$cache->delete("dialplan:".$_SESSION['domain_name']); $cache->delete("dialplan:".$_SESSION['domain_name']);
//set message //set message
message::add($text['message-copy']); message::add($text['message-copy']);
} }
unset($records); unset($records);
} }
}
} }
} }

View File

@ -72,11 +72,14 @@ if (!class_exists('switch_recordings')) {
$parameters['domain_uuid'] = $this->domain_uuid; $parameters['domain_uuid'] = $this->domain_uuid;
$database = new database; $database = new database;
$result = $database->select($sql, $parameters, 'all'); $result = $database->select($sql, $parameters, 'all');
if (is_array($result) && @sizeof($result) != 0) { if (!empty($result)) {
foreach ($result as &$row) { foreach ($result as &$row) {
$recordings[$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name']."/".$row['recording_filename']] = $row['recording_filename']; $recordings[$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name']."/".$row['recording_filename']] = $row['recording_filename'];
} }
} }
else {
$recordings = false;
}
unset($sql, $parameters, $result, $row); unset($sql, $parameters, $result, $row);
return $recordings; return $recordings;
} }
@ -104,7 +107,7 @@ if (!class_exists('switch_recordings')) {
//get recording filename, build delete array //get recording filename, build delete array
foreach ($records as $x => $record) { foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) { if (!empty($record['checked']) && $record['checked'] == 'true' && !empty($record['uuid'])) {
//get filename //get filename
$sql = "select recording_filename from v_recordings "; $sql = "select recording_filename from v_recordings ";

View File

@ -61,7 +61,7 @@ if (!class_exists('ringbacks')) {
$ringtones_list[$ringtone] = $label; $ringtones_list[$ringtone] = $label;
} }
} }
$this->ringtones_list = $ringtones_list; $this->ringtones_list = $ringtones_list ?? '';
unset($sql, $ringtones, $ringtone, $ringtones_list); unset($sql, $ringtones, $ringtone, $ringtones_list);
//get the default_ringback label //get the default_ringback label

View File

@ -46,15 +46,17 @@ if (!class_exists('tones')) {
$sql .= "order by var_name asc "; $sql .= "order by var_name asc ";
$database = new database; $database = new database;
$tones = $database->select($sql, null, 'all'); $tones = $database->select($sql, null, 'all');
foreach ($tones as $tone) { if (!empty($tones)) {
$tone = $tone['var_name']; foreach ($tones as $tone) {
$label = $text['label-'.$tone]; $tone = $tone['var_name'];
if ($label == "") { $label = $text['label-'.$tone];
$label = $tone; if ($label == "") {
$label = $tone;
}
$tone_list[$tone] = $label;
} }
$tone_list[$tone] = $label;
} }
$this->tones = $tone_list; $this->tones = $tone_list ?? '';
unset($sql, $tones, $tone, $tone_list); unset($sql, $tones, $tone, $tone_list);
} }
@ -64,4 +66,4 @@ if (!class_exists('tones')) {
} }
} }
?> ?>