diff --git a/app/destinations/resources/classes/destinations.php b/app/destinations/resources/classes/destinations.php index 0f78de65c6..b1a962d848 100644 --- a/app/destinations/resources/classes/destinations.php +++ b/app/destinations/resources/classes/destinations.php @@ -163,6 +163,10 @@ if (!class_exists('destinations')) { //set the global variables global $db_type; + //set defaults + $select_style = ''; + $onchange = ''; + //get the domain_name $sql = "select domain_name from v_domains "; $sql .= "where domain_uuid = :domain_uuid "; @@ -171,7 +175,7 @@ if (!class_exists('destinations')) { $this->domain_name = $database->select($sql, $parameters, 'column'); //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 if (!is_array($this->destinations)) { @@ -296,7 +300,7 @@ if (!class_exists('destinations')) { $response .= " tb.className='formfld';\n"; $response .= " tb.setAttribute('id', '".$destination_id."');\n"; $response .= " tb.setAttribute('style', '".$select_style."');\n"; - if ($onchange != '') { + if (!empty($onchange)) { $response .= " tb.setAttribute('onchange', \"".$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[2]);\n"; $response .= " document.getElementById('btn_select_to_input_".$destination_id."').style.visibility = 'visible';\n"; - if ($onchange != '') { + if (!empty($onchange)) { $response .= " ".$onchange.";\n"; } $response .= "}\n"; @@ -337,7 +341,7 @@ if (!class_exists('destinations')) { $name = $row['name']; $label = $row['label']; - $destination = $row['field']['destination']; + $destination = $row['field']['destination'] ?? ''; //add multi-lingual support 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); } - 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 .= " \n"; $label2 = $label; 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("transfer", "", $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 .= " \n"; } } @@ -537,6 +541,10 @@ if (!class_exists('destinations')) { //set the global variables global $db_type; + //set default values + $destination_name = ''; + $destination_id = ''; + //get the domain_name $sql = "select domain_name from v_domains "; $sql .= "where domain_uuid = :domain_uuid "; @@ -653,7 +661,7 @@ if (!class_exists('destinations')) { $name = $row['name']; $label = $row['label']; - $destination = $row['field']['destination']; + $destination = $row['field']['destination'] ?? ''; //add multi-lingual support 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); } - 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; foreach ($row['result']['data'] as $data) { $select_value = $row['select_value'][$destination_type]; $select_label = $row['select_label']; foreach ($row['field'] as $key => $value) { - if ($key == 'destination' and is_array($value)){ - if ($value['type'] == 'csv') { + if ($key == 'destination' and !empty($value)){ + if (!empty($value['type']) && $value['type'] == 'csv') { $array = explode($value['delimiter'], $data[$key]); $select_value = str_replace("\${destination}", $array[0], $select_value); $select_label = str_replace("\${destination}", $array[0], $select_label); @@ -714,7 +722,7 @@ if (!class_exists('destinations')) { $select_label = str_replace("✉", 'email-icon', $select_label); $select_label = escape(trim($select_label)); $select_label = str_replace('email-icon', '✉', $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); } $array[$label][$select_label] = $select_value; } @@ -722,9 +730,12 @@ if (!class_exists('destinations')) { } } 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("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("XML ".$this->domain_name, "", $destination_label); $array[$label][$destination_label] = $destination_value; diff --git a/app/ivr_menus/ivr_menu_edit.php b/app/ivr_menus/ivr_menu_edit.php index 7f67fe611b..34f4c45078 100644 --- a/app/ivr_menus/ivr_menu_edit.php +++ b/app/ivr_menus/ivr_menu_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - 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. Contributor(s): @@ -113,7 +113,7 @@ $ivr_menu_options = $_POST["ivr_menu_options"]; $ivr_menu_invalid_sound = $_POST["ivr_menu_invalid_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_key = $_POST["ivr_menu_confirm_key"]; $ivr_menu_tts_engine = $_POST["ivr_menu_tts_engine"]; @@ -173,7 +173,7 @@ $parameters['ivr_menu_uuid'] = $ivr_menu_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); - if (is_array($row) && @sizeof($row) != 0) { + if (!empty($row)) { if (!permission_exists('ivr_menu_domain')) { $domain_uuid = $row["domain_uuid"]; } @@ -252,9 +252,9 @@ //seperate the language components into language, dialect and voice $language_array = explode("/",$ivr_menu_language); - $ivr_menu_language = $language_array[0]; - $ivr_menu_dialect = $language_array[1]; - $ivr_menu_voice = $language_array[2]; + $ivr_menu_language = $language_array[0] ?? 'en'; + $ivr_menu_dialect = $language_array[1] ?? 'us'; + $ivr_menu_voice = $language_array[2] ?? 'callie'; //prepare the array $array['ivr_menus'][0]["ivr_menu_uuid"] = $ivr_menu_uuid; @@ -297,13 +297,13 @@ $y = 0; foreach ($ivr_menu_options as $row) { 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']; } else { $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 $ivr_menu_option_action = "menu-exec-app"; $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_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++; } } @@ -352,7 +352,7 @@ } $dialplan_xml .= " \n"; - if ($_SESSION['ivr_menu']['application']['text'] == "lua") { + if (!empty($_SESSION['ivr_menu']['application']['text']) && $_SESSION['ivr_menu']['application']['text'] == "lua") { $dialplan_xml .= " \n"; } else { @@ -408,8 +408,7 @@ if ( $action == 'update' && permission_exists('ivr_menu_option_delete') - && is_array($ivr_menu_options_delete) - && @sizeof($ivr_menu_options_delete) != 0 + && !empty($ivr_menu_options_delete) ) { $obj = new ivr_menu; $obj->ivr_menu_uuid = $ivr_menu_uuid; @@ -436,8 +435,10 @@ $parameters['ivr_menu_parent_uuid'] = $ivr_menu_parent_uuid; $database = new database; $parent_uuids = $database->select($sql, $parameters, "all"); - foreach ($parent_uuids as $x => $row) { - $cache->delete("configuration:ivr.conf:".$row['ivr_menu_parent_uuid']); + if (!empty($parent_uuids)) { + foreach ($parent_uuids as $x => $row) { + $cache->delete("configuration:ivr.conf:".$row['ivr_menu_parent_uuid']); + } } //set the add message if ($action == "add" && permission_exists('ivr_menu_add')) { @@ -511,7 +512,9 @@ $ivr_menu_language = $ivr_menu_language ?? ''; $ivr_menu_dialect = $ivr_menu_language ?? ''; $ivr_menu_voice = $ivr_menu_voice ?? ''; - + $select_style = $select_style ?? ''; + $onkeyup = $onkeyup ?? ''; + //get the ivr menu options $sql = "select * from v_ivr_menu_options "; $sql .= "where domain_uuid = :domain_uuid "; @@ -733,7 +736,7 @@ echo "\n"; echo " \n"; echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; } echo "\n"; 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 ""; echo " \n"; echo " \n"; @@ -1288,7 +1291,7 @@ } //recordings $tmp_selected = false; - if (is_array($recordings)) { + if (is_array($recordings) && !empty($_SESSION['switch']['recordings']['dir'])) { echo "\n"; foreach ($recordings as &$row) { $recording_name = $row["recording_name"]; @@ -1341,7 +1344,7 @@ echo "\n"; } //select - if (if_group("superadmin")) { + if (if_group("superadmin") && !empty($_SESSION['switch']['recordings']['dir'])) { if (!$tmp_selected && !empty($ivr_menu_invalid_sound)) { echo "\n"; if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_invalid_sound)) { @@ -1377,7 +1380,7 @@ } //recordings $tmp_selected = false; - if (is_array($recordings)) { + if (is_array($recordings) && !empty($_SESSION['switch']['recordings']['dir'])) { echo "\n"; foreach ($recordings as &$row) { $recording_name = $row["recording_name"]; @@ -1430,7 +1433,7 @@ echo "\n"; } //select - if (if_group("superadmin")) { + if (if_group("superadmin") && !empty($_SESSION['switch']['recordings']['dir'])) { if (!$tmp_selected && !empty($ivr_menu_exit_sound)) { echo "\n"; if (file_exists($_SESSION['switch']['recordings']['dir']."/".$_SESSION['domain_name']."/".$ivr_menu_exit_sound)) { diff --git a/app/ivr_menus/ivr_menus.php b/app/ivr_menus/ivr_menus.php index d47ae126cb..eccda77402 100644 --- a/app/ivr_menus/ivr_menus.php +++ b/app/ivr_menus/ivr_menus.php @@ -46,15 +46,20 @@ $language = new text; $text = $language->get(); +//define defaults + $action = ''; + $search = ''; + $ivr_menus = ''; + //get posted data - if (is_array($_POST['ivr_menus'])) { + if (!empty($_POST['ivr_menus'])) { $action = $_POST['action']; $search = $_POST['search']; $ivr_menus = $_POST['ivr_menus']; } //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) { case 'copy': if (permission_exists('ivr_menu_add')) { @@ -76,62 +81,73 @@ break; } - header('Location: ivr_menus.php'.($search != '' ? '?search='.urlencode($search) : null)); + header('Location: ivr_menus.php'.(!empty($search) ? '?search='.urlencode($search) : null)); exit; } //get order and order by - $order_by = $_GET["order_by"]; - $order = $_GET["order"]; + $order_by = $_GET["order_by"] ?? ''; + $order = $_GET["order"] ?? ''; -//add the search term - $search = strtolower($_GET["search"]); - if (!empty($search)) { - $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.'%'; - } +//add the search variable + $search = $_GET["search"] ?? ''; + $show = $_GET["show"] ?? ''; +//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 $sql = "select count(*) from v_ivr_menus "; $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) "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; } - $database = new database; - $total_ivr_menus = $database->select($sql, $parameters, 'column'); - $num_rows = $total_ivr_menus; - -//prepare to page the results - if ($sql_search) { - $sql .= $sql_search; - $database = new database; - $num_rows = $database->select($sql, $parameters, 'column'); + 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.'%'; } + $database = new database; + $num_rows = $database->select($sql, $parameters ?? '', 'column'); //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); - if ($_GET['show'] == "all" && permission_exists('ivr_menu_all')) { + if ($show == "all" && permission_exists('ivr_menu_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_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true); $offset = $rows_per_page * $page; //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 .= limit_offset($rows_per_page, $offset); $database = new database; - $ivr_menus = $database->select($sql, $parameters, 'all'); + $ivr_menus = $database->select($sql, $parameters ?? '', 'all'); unset($sql, $parameters); //create token @@ -146,10 +162,10 @@ echo "
\n"; echo "
".$text['title-ivr_menus']." (".$num_rows.")
\n"; echo "
\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']); } - 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');"]); } if (permission_exists('ivr_menu_edit') && $ivr_menus) { @@ -160,7 +176,7 @@ } echo "