Portions created by the Initial Developer are Copyright (C) 2008-2026 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane Luis Daniel Lucio Quiroz */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (!(permission_exists('ivr_menu_add') || permission_exists('ivr_menu_edit'))) { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //initialize the settings object $settings = new settings(['database' => $database, 'domain_uuid' => $_SESSION['domain_uuid'] ?? '', 'user_uuid' => $_SESSION['user_uuid'] ?? '']); //set the defaults $ivr_menu_name = ''; $ivr_menu_extension = ''; $ivr_menu_cid_prefix = ''; $ivr_menu_greet_long = ''; $ivr_menu_greet_short = ''; $ivr_menu_description = ''; $ivr_menu_ringback = $settings->get('ivr_menu','default_ringback', 'local_stream://default'); $recording_name = ''; $recording_message = ''; $recording_description = ''; $recording_speed = '1.0'; $recording_uuid = ''; $speed_enabled = false; $speed_options = []; $translate_enabled = false; $language_enabled = false; //set the variables $domain_uuid = $_SESSION['domain_uuid']; $domain_name = $_SESSION['domain_name']; //set speech enabled and engine variables $speech_enabled = class_exists('speech') && $settings->get('speech', 'enabled', false); $speech_engine = $settings->get('speech', 'engine', ''); //add the speech object and get the voices and languages arrays if ($speech_enabled && !empty($speech_engine)) { $speech = new speech($settings); $voices = $speech->get_voices(); $recording_extension = $speech->get_format(); $speed_enabled = $speech->is_speed_enabled(); $speed_options = $speed_enabled ? $speech->get_speed_options() : []; // Determine the aray type single, or multi $voices_array_type = array_type($voices); // Sort the array by language code keys alphabetically if ($voices_array_type == 'multi') { ksort($voices); } } //initialize the destinations object $destination = new destinations; //initialize the ringbacks object $ringbacks = new ringbacks; //get the list of domains $domains = domains::all(); //validate the ringback if (!$ringbacks->valid($ivr_menu_ringback)) { //set to default when it is not valid $ivr_menu_ringback = ''; } // Set variables from http GET parameters $page = is_numeric($_GET['page'] ?? '') ? $_GET['page'] : 0; $order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', ($_GET['order_by'] ?? 'ivr_menu_name')); $order = ($_GET['order'] ?? '') === 'desc' ? 'desc' : 'asc'; $search = $_GET['search'] ?? ''; $show = $_GET['show'] ?? ''; // Build the query string $param = []; if (!empty($page)) { $param['page'] = $page; } if (!empty($_GET['order_by'])) { $param['order_by'] = $order_by; } if (!empty($_GET['order'])) { $param['order'] = $order; } if (!empty($search)) { $param['search'] = $search; } if (!empty($show) && $show == 'all' && permission_exists('ivr_menu_all')) { $param['show'] = $show; } $query_string = http_build_query($param); //action add or update if (!empty($_REQUEST["id"]) && is_uuid($_REQUEST["id"]) || !empty($_REQUEST["ivr_menu_uuid"]) && is_uuid($_REQUEST["ivr_menu_uuid"])) { $action = "update"; $ivr_menu_uuid = $_REQUEST["id"]; if (!empty($_REQUEST["ivr_menu_uuid"])) { $ivr_menu_uuid = $_REQUEST["ivr_menu_uuid"]; } } else { $action = "add"; } //get total ivr menu count from the database, check limit, if defined if ($action == 'add' && $settings->get('limit', 'ivr_menus') != '') { $sql = "select count(*) as num_rows from v_ivr_menus where domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $domain_uuid; $total_ivr_menus = $database->select($sql, $parameters, 'column'); unset($sql, $parameters); if ($total_ivr_menus >= $settings->get('limit', 'ivr_menus')) { message::add($text['message-maximum_ivr_menus'].' '.$settings->get('limit', 'ivr_menus'), 'negative'); header('Location: ivr_menus.php'.($query_string ? '?'.$query_string : '')); exit; } } //get http post values and set them to php variables if (!empty($_POST)) { //process the http post data by submitted action if (!empty($_POST['action']) && is_uuid($_POST['ivr_menu_uuid'])) { $array[0]['checked'] = 'true'; $array[0]['uuid'] = $_POST['ivr_menu_uuid']; switch ($_POST['action']) { case 'copy': if (permission_exists('ivr_menu_add')) { $obj = new ivr_menu; $obj->copy($array); } break; case 'delete': if (permission_exists('ivr_menu_delete')) { $obj = new ivr_menu; $obj->delete($array); } break; } header('Location: ivr_menus.php'.($query_string ? '?'.$query_string : '')); exit; } //get ivr menu $ivr_menu_name = $_POST["ivr_menu_name"]; $ivr_menu_extension = $_POST["ivr_menu_extension"]; $ivr_menu_parent_uuid = $_POST["ivr_menu_parent_uuid"]; $ivr_menu_greet_long = $_POST["ivr_menu_greet_long"]; $ivr_menu_greet_short = $_POST["ivr_menu_greet_short"]; $ivr_menu_language = $_POST["ivr_menu_language"]; $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_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"]; $ivr_menu_tts_voice = $_POST["ivr_menu_tts_voice"]; $ivr_menu_confirm_attempts = $_POST["ivr_menu_confirm_attempts"]; $ivr_menu_timeout = $_POST["ivr_menu_timeout"]; $ivr_menu_inter_digit_timeout = $_POST["ivr_menu_inter_digit_timeout"]; $ivr_menu_max_failures = $_POST["ivr_menu_max_failures"]; $ivr_menu_max_timeouts = $_POST["ivr_menu_max_timeouts"]; $ivr_menu_digit_len = $_POST["ivr_menu_digit_len"]; $ivr_menu_direct_dial = $_POST["ivr_menu_direct_dial"]; $ivr_menu_ringback = $_POST["ivr_menu_ringback"]; $ivr_menu_cid_prefix = $_POST["ivr_menu_cid_prefix"]; $ivr_menu_enabled = $_POST["ivr_menu_enabled"]; $ivr_menu_description = $_POST["ivr_menu_description"]; $ivr_menu_options_delete = $_POST["ivr_menu_options_delete"] ?? null; $dialplan_uuid = $_POST["dialplan_uuid"] ?? null; //set the context for users that do not have the permission if (permission_exists('ivr_menu_context')) { $ivr_menu_context = $_POST["ivr_menu_context"]; } else if ($action == 'add') { $ivr_menu_context = $_SESSION['domain_name']; } //process the values $ivr_menu_exit_action = $_POST["ivr_menu_exit_action"]; //$ivr_menu_exit_action = "transfer:1001 XML default"; $timeout_action_array = explode(":", $ivr_menu_exit_action); $ivr_menu_exit_app = array_shift($timeout_action_array); $ivr_menu_exit_data = join(':', $timeout_action_array); //set the default ivr_menu_option_action if (empty($ivr_menu_option_action)) { $ivr_menu_option_action = "menu-exec-app"; } } //process the http data if (!empty($_POST) && empty($_POST["persistformvar"])) { //set the domain_uuid if (permission_exists('ivr_menu_domain')) { $domain_uuid = $_POST["domain_uuid"]; } else { $_POST["domain_uuid"] = $_SESSION['domain_uuid']; $domain_uuid = $_SESSION['domain_uuid']; } //if the user doesn't have the correct permission then //override domain_uuid and ivr_menu_context values if ($action == 'update' && is_uuid($ivr_menu_uuid)) { $sql = "select * from v_ivr_menus "; $sql .= "where ivr_menu_uuid = :ivr_menu_uuid "; $parameters['ivr_menu_uuid'] = $ivr_menu_uuid; $row = $database->select($sql, $parameters, 'row'); if (!empty($row)) { if (!permission_exists('ivr_menu_domain')) { $domain_uuid = $row["domain_uuid"]; } if (!permission_exists('ivr_menu_context')) { $ivr_menu_context = $row["ivr_menu_context"]; } } unset($sql, $parameters, $row); } //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: ivr_menus.php'.($query_string ? '?'.$query_string : '')); exit; } //check for all required data $msg = ''; if (empty($ivr_menu_name)) { $msg .= $text['message-required'].$text['label-name']."
\n"; } if (empty($ivr_menu_extension)) { $msg .= $text['message-required'].$text['label-extension']."
\n"; } if (empty($ivr_menu_greet_long)) { $msg .= $text['message-required'].$text['label-greet_long']."
\n"; } //if (empty($ivr_menu_greet_short)) { $msg .= $text['message-required'].$text['label-greet_short']."
\n"; } //if (empty($ivr_menu_invalid_sound)) { $msg .= $text['message-required'].$text['label-invalid_sound']."
\n"; } //if (empty($ivr_menu_exit_sound)) { $msg .= $text['message-required'].$text['label-exit_sound']."
\n"; } //if (empty($ivr_menu_confirm_macro)) { $msg .= $text['message-required'].$text['label-comfirm_macro']."
\n"; } //if (empty($ivr_menu_confirm_key)) { $msg .= $text['message-required'].$text['label-comfirm_key']."
\n"; } //if (empty($ivr_menu_tts_engine)) { $msg .= $text['message-required'].$text['label-tts_engine']."
\n"; } //if (empty($ivr_menu_tts_voice)) { $msg .= $text['message-required'].$text['label-tts_voice']."
\n"; } if (empty($ivr_menu_confirm_attempts)) { $msg .= $text['message-required'].$text['label-comfirm_attempts']."
\n"; } if (empty($ivr_menu_timeout)) { $msg .= $text['message-required'].$text['label-timeout']."
\n"; } //if (empty($ivr_menu_exit_app)) { $msg .= $text['message-required'].$text['label-exit_action']."
\n"; } if (empty($ivr_menu_inter_digit_timeout)) { $msg .= $text['message-required'].$text['label-inter_digit_timeout']."
\n"; } if (empty($ivr_menu_max_failures)) { $msg .= $text['message-required'].$text['label-max_failures']."
\n"; } if (empty($ivr_menu_max_timeouts)) { $msg .= $text['message-required'].$text['label-max_timeouts']."
\n"; } if (empty($ivr_menu_digit_len)) { $msg .= $text['message-required'].$text['label-digit_length']."
\n"; } //if (empty($ivr_menu_direct_dial)) { $msg .= $text['message-required'].$text['label-direct_dial']."
\n"; } //if (empty($ivr_menu_ringback)) { $msg .= $text['message-required'].$text['label-ring_back']."
\n"; } //if (empty($ivr_menu_description)) { $msg .= $text['message-required'].$text['label-description']."
\n"; } if (!empty($msg) && !empty($_POST["persistformvar"])) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //add or update the database if (empty($_POST["persistformvar"])) { //used for debugging if (!empty($_POST["debug"]) && $_POST["debug"] == "true") { unset($_POST["debug"]); echo "
\n";
						print_r($_POST);
						echo "
\n"; exit; } //add a uuid to ivr_menu_uuid if it is empty if ($action == 'add') { $ivr_menu_uuid = uuid(); } //add a uuid to dialplan_uuid if it is empty if (!is_uuid($dialplan_uuid)) { $dialplan_uuid = uuid(); } //seperate the language components into language, dialect and voice $language_array = explode("/",$ivr_menu_language); $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; $array['ivr_menus'][0]["domain_uuid"] = $domain_uuid; $array['ivr_menus'][0]["dialplan_uuid"] = $dialplan_uuid; $array['ivr_menus'][0]["ivr_menu_name"] = $ivr_menu_name; $array['ivr_menus'][0]["ivr_menu_extension"] = $ivr_menu_extension; $array['ivr_menus'][0]["ivr_menu_parent_uuid"] = $ivr_menu_parent_uuid; $array['ivr_menus'][0]["ivr_menu_language"] = $ivr_menu_language; $array['ivr_menus'][0]["ivr_menu_dialect"] = $ivr_menu_dialect; $array['ivr_menus'][0]["ivr_menu_voice"] = $ivr_menu_voice; $array['ivr_menus'][0]["ivr_menu_greet_long"] = $ivr_menu_greet_long; $array['ivr_menus'][0]["ivr_menu_greet_short"] = $ivr_menu_greet_short; $array['ivr_menus'][0]["ivr_menu_invalid_sound"] = $ivr_menu_invalid_sound; $array['ivr_menus'][0]["ivr_menu_exit_sound"] = $ivr_menu_exit_sound; $array['ivr_menus'][0]["ivr_menu_pin_number"] = $ivr_menu_pin_number; $array['ivr_menus'][0]["ivr_menu_confirm_macro"] = $ivr_menu_confirm_macro; $array['ivr_menus'][0]["ivr_menu_confirm_key"] = $ivr_menu_confirm_key; $array['ivr_menus'][0]["ivr_menu_tts_engine"] = $ivr_menu_tts_engine; $array['ivr_menus'][0]["ivr_menu_tts_voice"] = $ivr_menu_tts_voice; $array['ivr_menus'][0]["ivr_menu_confirm_attempts"] = $ivr_menu_confirm_attempts; $array['ivr_menus'][0]["ivr_menu_timeout"] = $ivr_menu_timeout; if ($destination->valid($ivr_menu_exit_app.":".$ivr_menu_exit_data)) { $array['ivr_menus'][0]["ivr_menu_exit_app"] = $ivr_menu_exit_app; $array['ivr_menus'][0]["ivr_menu_exit_data"] = $ivr_menu_exit_data; } else { $ivr_menu_exit_app = ""; } $array['ivr_menus'][0]["ivr_menu_inter_digit_timeout"] = $ivr_menu_inter_digit_timeout; $array['ivr_menus'][0]["ivr_menu_max_failures"] = $ivr_menu_max_failures; $array['ivr_menus'][0]["ivr_menu_max_timeouts"] = $ivr_menu_max_timeouts; $array['ivr_menus'][0]["ivr_menu_digit_len"] = $ivr_menu_digit_len; $array['ivr_menus'][0]["ivr_menu_direct_dial"] = $ivr_menu_direct_dial; if (!empty($ivr_menu_ringback) && $ringbacks->valid($ivr_menu_ringback)) { $array['ivr_menus'][0]["ivr_menu_ringback"] = $ivr_menu_ringback; } $array['ivr_menus'][0]["ivr_menu_cid_prefix"] = $ivr_menu_cid_prefix; $array['ivr_menus'][0]["ivr_menu_context"] = $ivr_menu_context; $array['ivr_menus'][0]["ivr_menu_enabled"] = $ivr_menu_enabled; $array['ivr_menus'][0]["ivr_menu_description"] = $ivr_menu_description; $y = 0; foreach ($ivr_menu_options as $row) { if (isset($row['ivr_menu_option_digits']) && $row['ivr_menu_option_digits'] != '') { 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 (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; } else { //seperate the action and the param $options_array = explode(":", $row["ivr_menu_option_param"]); $ivr_menu_option_action = array_shift($options_array); $ivr_menu_option_param = join(':', $options_array); } $array['ivr_menus'][0]['ivr_menu_options'][$y]["domain_uuid"] = $domain_uuid; $array['ivr_menus'][0]['ivr_menu_options'][$y]["ivr_menu_uuid"] = $ivr_menu_uuid; $array['ivr_menus'][0]['ivr_menu_options'][$y]["ivr_menu_option_uuid"] = $ivr_menu_option_uuid; $array['ivr_menus'][0]['ivr_menu_options'][$y]["ivr_menu_option_digits"] = $row["ivr_menu_option_digits"]; $array['ivr_menus'][0]['ivr_menu_options'][$y]["ivr_menu_option_action"] = $ivr_menu_option_action; if ($destination->valid($ivr_menu_option_action.":".$ivr_menu_option_param, 'ivr')) { $array['ivr_menus'][0]['ivr_menu_options'][$y]["ivr_menu_option_param"] = $ivr_menu_option_param; } $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']; $y++; } } //build the xml dialplan $dialplan_xml = "\n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; if ($settings->get('ivr_menu', 'answer', false)) { $dialplan_xml .= " \n"; } $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; if (!empty($ivr_menu_ringback) && $ringbacks->valid($ivr_menu_ringback)) { $dialplan_xml .= " \n"; } if (!empty($ivr_menu_language)) { $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; } if (!empty($ivr_menu_ringback) && $ringbacks->valid($ivr_menu_ringback)) { $dialplan_xml .= " \n"; } $dialplan_xml .= " \n"; if (!empty($settings->get('ivr_menu', 'application')) && $settings->get('ivr_menu', 'application') == "lua") { $dialplan_xml .= " \n"; } else { if (!empty($ivr_menu_cid_prefix)) { $dialplan_xml .= " \n"; $dialplan_xml .= " \n"; } $dialplan_xml .= " \n"; } if (!empty($ivr_menu_exit_app)) { $dialplan_xml .= " \n"; } $dialplan_xml .= " \n"; $dialplan_xml .= "\n"; //build the dialplan array $array['dialplans'][0]["domain_uuid"] = $domain_uuid; $array['dialplans'][0]["dialplan_uuid"] = $dialplan_uuid; $array['dialplans'][0]["dialplan_name"] = $ivr_menu_name; $array['dialplans'][0]["dialplan_number"] = $ivr_menu_extension; if (isset($ivr_menu_context)) { $array['dialplans'][0]["dialplan_context"] = $ivr_menu_context; } $array['dialplans'][0]["dialplan_continue"] = 'false'; $array['dialplans'][0]["dialplan_xml"] = $dialplan_xml; $array['dialplans'][0]["dialplan_order"] = "101"; $array['dialplans'][0]["dialplan_enabled"] = $ivr_menu_enabled; $array['dialplans'][0]["dialplan_description"] = $ivr_menu_description; $array['dialplans'][0]["app_uuid"] = "a5788e9b-58bc-bd1b-df59-fff5d51253ab"; //add the dialplan permission $p = permissions::new(); if ($action == "add") { $p->add("dialplan_add", "temp"); } else if ($action == "update") { $p->add("dialplan_edit", "temp"); } //build the recording array $recording_types = ['greet_long', 'greet_short']; foreach ($recording_types as $x => $type) { $recording_name = $_POST[$type]['recording_name'] ?? ''; $recording_voice = $_POST[$type]['recording_voice'] ?? ''; $recording_speed = $_POST[$type]['recording_speed'] ?? '1.0'; $recording_message = $_POST[$type]['recording_message'] ?? ''; $recording_desc = $_POST[$type]['recording_description'] ?? ''; if (permission_exists('recording_edit') && !empty($recording_message)) { $recording_uuid = uuid(); if (empty($recording_name)) { $recording_name = 'recording'.$ivr_menu_extension.($type == $recording_types[1] ? '-short' : null).'-'.str_pad(random_int(0, 9999), 4, '0', STR_PAD_LEFT); } //set the recording format for approved types if (!in_array($recording_extension, ['mp3', 'wav'], true)) { //default to wav $recording_extension = 'wav'; } //build the setting object and get the recording path $recording_path = $settings->get('switch', 'recordings').'/'.$domain_name; //create the file name $recording_filename = empty($_POST[$type]['recording_filename'] ?? '') ? preg_replace('#[^a-zA-Z0-9_\-]#', '_', $recording_name) : $_POST[$type]['recording_filename']; if (!str_ends_with($recording_filename, ".$recording_extension")) { $recording_filename .= ".$recording_extension"; } //text to audio - make a new audio file from the message $speech->audio_path = $recording_path; $speech->audio_filename = $recording_filename; $speech->audio_voice = $recording_voice; if ($speed_enabled) { $speech->audio_speed = (float)$recording_speed; } $speech->audio_message = $recording_message; $speech->speech(); //fix invalid riff & data header lengths in generated wave file if ($speech_engine == 'openai') { $recording_filename_temp = str_replace('.'.$recording_extension, '.tmp.'.$recording_extension, $recording_filename); if (file_exists($recording_path.'/'.$recording_filename)) { exec('sox --ignore-length '.escapeshellarg($recording_path.'/'.$recording_filename).' '.escapeshellarg($recording_path.'/'.$recording_filename_temp)); } if (file_exists($recording_path.'/'.$recording_filename_temp)) { recursive_delete($recording_path.'/'.$recording_filename); exec('mv '.escapeshellarg($recording_path.'/'.$recording_filename_temp).' '.escapeshellarg($recording_path.'/'.$recording_filename)); } unset($recording_filename_temp); } $array['recordings'][$x]['domain_uuid'] = $domain_uuid; $array['recordings'][$x]['recording_uuid'] = $recording_uuid; $array['recordings'][$x]['recording_filename'] = $recording_filename; $array['recordings'][$x]['recording_name'] = $recording_name; $array['recordings'][$x]['recording_voice'] = $speech_enabled ? $recording_voice : null; $array['recordings'][$x]['recording_speed'] = ($speech_enabled && $speed_enabled) ? $recording_speed : null; $array['recordings'][$x]['recording_message'] = $speech_enabled ? $recording_message : null; $array['recordings'][$x]['recording_description'] = $recording_desc; // Update IVR menu fields directly $array['ivr_menus'][0]["ivr_menu_{$type}"] = $recording_filename; } } //save to the data $database->save($array); $message = $database->message; //remove the temporary permission $p->delete("dialplan_add", "temp"); $p->delete("dialplan_edit", "temp"); //remove checked options if ( $action == 'update' && permission_exists('ivr_menu_option_delete') && !empty($ivr_menu_options_delete) ) { $obj = new ivr_menu; $obj->ivr_menu_uuid = $ivr_menu_uuid; $obj->delete_options($ivr_menu_options_delete); } //clear the cache $cache = new cache; $cache->delete("dialplan:".$_SESSION["context"]); $cache->delete("configuration:ivr.conf:".$ivr_menu_uuid); //get all ivr parent menus $sql = "with recursive ivr_menus as ( "; $sql .=" select ivr_menu_parent_uuid "; $sql .=" from v_ivr_menus "; $sql .=" where ivr_menu_parent_uuid = :ivr_menu_parent_uuid "; $sql .=" and ivr_menu_enabled = true "; $sql .=" union all "; $sql .=" select parent.ivr_menu_parent_uuid "; $sql .=" from v_ivr_menus as parent, ivr_menus as child "; $sql .=" where parent.ivr_menu_uuid = child.ivr_menu_parent_uuid "; $sql .=" and parent.ivr_menu_enabled = true "; $sql .=" ) "; $sql .=" select * from ivr_menus "; $parameters['ivr_menu_parent_uuid'] = $ivr_menu_parent_uuid; $parent_uuids = $database->select($sql, $parameters, "all"); 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')) { message::add($text['message-add']); } //set the update message if ($action == "update" && permission_exists('ivr_menu_edit')) { message::add($text['message-update']); } //redirect the user header("Location: ivr_menu_edit.php?id=".urlencode($ivr_menu_uuid).($query_string ? '&'.$query_string : '')); return; } } //pre-populate the form if (empty($ivr_menu_uuid)) { $ivr_menu_uuid = $_REQUEST["id"] ?? null; } if (!empty($ivr_menu_uuid) && is_uuid($ivr_menu_uuid) && empty($_POST["persistformvar"])) { $ivr = new ivr_menu; $ivr->domain_uuid = $_SESSION["domain_uuid"]; $ivr->ivr_menu_uuid = $ivr_menu_uuid; $ivr_menus = $ivr->find(); if (!empty($ivr_menus)) { foreach ($ivr_menus as $row) { $dialplan_uuid = $row["dialplan_uuid"]; $ivr_menu_name = $row["ivr_menu_name"]; $ivr_menu_extension = $row["ivr_menu_extension"]; $ivr_menu_parent_uuid = $row["ivr_menu_parent_uuid"]; $ivr_menu_language = $row["ivr_menu_language"]; $ivr_menu_dialect = $row["ivr_menu_dialect"]; $ivr_menu_voice = $row["ivr_menu_voice"]; $ivr_menu_greet_long = $row["ivr_menu_greet_long"]; $ivr_menu_greet_short = $row["ivr_menu_greet_short"]; $ivr_menu_invalid_sound = $row["ivr_menu_invalid_sound"]; $ivr_menu_exit_sound = $row["ivr_menu_exit_sound"]; $ivr_menu_pin_number = $row["ivr_menu_pin_number"]; $ivr_menu_confirm_macro = $row["ivr_menu_confirm_macro"]; $ivr_menu_confirm_key = $row["ivr_menu_confirm_key"]; $ivr_menu_tts_engine = $row["ivr_menu_tts_engine"]; $ivr_menu_tts_voice = $row["ivr_menu_tts_voice"]; $ivr_menu_confirm_attempts = $row["ivr_menu_confirm_attempts"]; $ivr_menu_timeout = $row["ivr_menu_timeout"]; $ivr_menu_exit_app = $row["ivr_menu_exit_app"]; $ivr_menu_exit_data = $row["ivr_menu_exit_data"]; $ivr_menu_inter_digit_timeout = $row["ivr_menu_inter_digit_timeout"]; $ivr_menu_max_failures = $row["ivr_menu_max_failures"]; $ivr_menu_max_timeouts = $row["ivr_menu_max_timeouts"]; $ivr_menu_digit_len = $row["ivr_menu_digit_len"]; $ivr_menu_direct_dial = $row["ivr_menu_direct_dial"]; $ivr_menu_ringback = $row["ivr_menu_ringback"]; $ivr_menu_cid_prefix = $row["ivr_menu_cid_prefix"]; $ivr_menu_context = $row["ivr_menu_context"]; $ivr_menu_enabled = $row["ivr_menu_enabled"]; $ivr_menu_description = $row["ivr_menu_description"]; //replace the dash with a space $ivr_menu_name = str_replace("-", " ", $ivr_menu_name); if (!empty($ivr_menu_exit_app)) { $ivr_menu_exit_action = $ivr_menu_exit_app.":".$ivr_menu_exit_data; } } } unset($ivr_menus, $row); } //set defaults $ivr_menu_language = $ivr_menu_language ?? ''; $ivr_menu_dialect = $ivr_menu_dialect ?? ''; $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 "; $sql .= "and ivr_menu_uuid = :ivr_menu_uuid "; $sql .= "order by natural_sort(ivr_menu_option_digits::text) asc, ivr_menu_option_order asc; "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['ivr_menu_uuid'] = $ivr_menu_uuid; $ivr_menu_options = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //get the ivr menus $sql = "select * from v_ivr_menus "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "order by v_ivr_menus asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $ivr_menus = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //add an empty row to the options array if (count($ivr_menu_options) == 0) { $rows = $settings->get('ivr_menu', 'option_add_rows'); $id = 0; $show_option_delete = false; } if (count($ivr_menu_options) > 0) { $rows = $settings->get('ivr_menu', 'option_edit_rows'); $id = count($ivr_menu_options)+1; $show_option_delete = true; } for ($x = 0; $x < $rows; $x++) { $ivr_menu_options[$id]['ivr_menu_option_digits'] = ''; $ivr_menu_options[$id]['ivr_menu_option_action'] = ''; $ivr_menu_options[$id]['ivr_menu_option_param'] = ''; $ivr_menu_options[$id]['ivr_menu_option_order'] = ''; $ivr_menu_options[$id]['ivr_menu_option_description'] = ''; $ivr_menu_options[$id]['ivr_menu_option_enabled'] = true; $id++; } //set the defaults if (empty($ivr_menu_timeout)) { $ivr_menu_timeout = '3000'; } if (empty($ivr_menu_ringback)) { $ivr_menu_ringback = ''; } if (empty($ivr_menu_invalid_sound)) { $ivr_menu_invalid_sound = ''; } //if (empty($ivr_menu_confirm_key)) { $ivr_menu_confirm_key = '#'; } if (empty($ivr_menu_tts_engine)) { $ivr_menu_tts_engine = 'flite'; } if (empty($ivr_menu_tts_voice)) { $ivr_menu_tts_voice = 'rms'; } if (empty($ivr_menu_confirm_attempts)) { if (!empty($settings->get('ivr_menu', 'confirm_attempts'))) { $ivr_menu_confirm_attempts = $settings->get('ivr_menu', 'confirm_attempts'); } else { $ivr_menu_confirm_attempts = '1'; } } if (empty($ivr_menu_inter_digit_timeout)) { if (!empty($settings->get('ivr_menu', 'inter_digit_timeout'))) { $ivr_menu_inter_digit_timeout = $settings->get('ivr_menu', 'inter_digit_timeout'); } else { $ivr_menu_inter_digit_timeout = '2000'; } } if (empty($ivr_menu_max_failures)) { if (!empty($settings->get('ivr_menu', 'max_failures'))) { $ivr_menu_max_failures = $settings->get('ivr_menu', 'max_failures'); } else { $ivr_menu_max_failures = '1'; } } if (empty($ivr_menu_max_timeouts)) { if (!empty($settings->get('ivr_menu', 'max_timeouts'))) { $ivr_menu_max_timeouts = $settings->get('ivr_menu', 'max_timeouts'); } else { $ivr_menu_max_timeouts = '1'; } } if (empty($ivr_menu_digit_len)) { $ivr_menu_digit_len = '5'; } if (!isset($ivr_menu_context)) { $ivr_menu_context = $_SESSION['domain_name']; } if (!isset($ivr_menu_exit_action)) { $ivr_menu_exit_action = ''; } $ivr_menu_direct_dial = $ivr_menu_direct_dial ?? false; $ivr_menu_enabled = $ivr_menu_enabled ?? true; //get installed languages $language_paths = glob($settings->get('switch', 'sounds')."/*/*/*"); foreach ($language_paths as $key => $path) { $path = str_replace($settings->get('switch', 'sounds').'/', "", $path); $path_array = explode('/', $path); if (count($path_array) <> 3 || strlen($path_array[0]) <> 2 || strlen($path_array[1]) <> 2) { unset($language_paths[$key]); } $language_paths[$key] = str_replace($settings->get('switch', 'sounds')."/","",$language_paths[$key] ?? ''); if (empty($language_paths[$key])) { unset($language_paths[$key]); } } //get the sounds $sounds = new sounds; $sounds->sound_types = ['miscellaneous','recordings','phrases']; $audio_files[0] = $sounds->get(); unset($sounds); $sounds = new sounds; $audio_files[1] = $sounds->get(); unset($sounds); //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //included the header $document['title'] = $text['title-ivr_menu']; require_once "resources/header.php"; //show the content echo "\n"; if (permission_exists('recording_play') || permission_exists('recording_download')) { echo "\n"; } if (permission_exists('ivr_menu_audio_edit')) { echo "\n"; } echo "
\n"; echo "
\n"; echo "
".$text['header-ivr_menu']."
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','link'=>'ivr_menus.php'.($query_string ? '?'.$query_string : '')]); if ($action == "update") { if (permission_exists('ivr_menu_add') && (empty($settings->get('limit', 'ivr_menus')) || $total_ivr_menus < $settings->get('limit', 'ivr_menus'))) { $button_margin = 'margin-left: 15px;'; echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$settings->get('theme', 'button_icon_copy'),'name'=>'btn_copy','style'=>$button_margin,'onclick'=>"modal_open('modal-copy','btn_copy');"]); } if (permission_exists('ivr_menu_delete') || permission_exists('ivr_menu_option_delete')) { $button_margin = 'margin-left: 0px;'; echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('theme', 'button_icon_delete'),'name'=>'btn_delete','style'=>$button_margin,'onclick'=>"modal_open('modal-delete','btn_delete');"]); } } echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$settings->get('theme', 'button_icon_save'),'id'=>'btn_save','style'=>'margin-left: 15px']); echo "
\n"; echo "
\n"; echo "
\n"; if ($action == "update") { if (permission_exists('ivr_menu_add') && (empty($settings->get('limit', 'ivr_menus')) || $total_ivr_menus < $settings->get('limit', 'ivr_menus'))) { echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'copy','onclick'=>"modal_close();"])]); } if (permission_exists('ivr_menu_delete') || permission_exists('ivr_menu_option_delete')) { echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]); } } echo $text['description-ivr_menu']."\n"; echo "

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " "; echo " "; echo " "; echo " "; echo "\n"; echo "\n"; echo "\n"; echo "\n"; // Greet recording tts styles echo "\n"; $instance_id = 'ivr_menu_greet_long'; $instance_label = 'greet_long'; $instance_value = $ivr_menu_greet_long; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $instance_id = 'ivr_menu_greet_short'; $instance_label = 'greet_short'; $instance_value = $ivr_menu_greet_short; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " "; echo " "; echo " "; echo " "; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; $instance_id = 'ivr_menu_invalid_sound'; $instance_label = 'invalid_sound'; $instance_value = $ivr_menu_invalid_sound; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo "\n"; $instance_id = 'ivr_menu_exit_sound'; $instance_label = 'exit_sound'; $instance_value = $ivr_menu_exit_sound; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; if (permission_exists('ivr_menu_domain')) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; } //echo "
\n"; echo " ".$text['label-name']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-name']."\n"; echo "
\n"; echo " ".$text['label-extension']."\n"; echo "\n"; echo " get('ivr_menu', 'extension_range') ?? '')."\">\n"; echo "
\n"; echo $text['description-extension']."\n"; echo "
".$text['label-ivr_menu_parent_uuid'].""; echo ""; echo "
\n"; echo " ".$text['label-language']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-language']."\n"; echo "
\n"; echo " ".$text['label-'.$instance_label]."\n"; echo "
\n"; echo "\n"; if (permission_exists('ivr_menu_audio_edit')) { echo ""; } if ((permission_exists('recording_play') || permission_exists('recording_download')) && (!empty($playable) || empty($instance_value))) { switch (pathinfo($playable, PATHINFO_EXTENSION)) { case 'wav' : $mime_type = 'audio/wav'; break; case 'mp3' : $mime_type = 'audio/mpeg'; break; case 'ogg' : $mime_type = 'audio/ogg'; break; } echo ""; echo button::create(['type'=>'button','title'=>$text['label-play'].' / '.$text['label-pause'],'icon'=>$settings->get('theme', 'button_icon_play'),'id'=>'recording_button_'.$instance_id,'style'=>'display: '.(!empty($mime_type) ? 'inline' : 'none'),'onclick'=>"recording_play('".$instance_id."', document.getElementById('".$instance_id."').value, document.getElementById('".$instance_id."').options[document.getElementById('".$instance_id."').selectedIndex].parentNode.getAttribute('data-type'));"]); unset($playable, $mime_type); } echo "
\n"; if ($speech_enabled && !empty($speech_engine)) { echo "
\n"; echo " ".$text['label-recording_name']."
\n"; echo " \n"; echo "

\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-voice']."\n"; echo "
\n"; if ($speed_enabled) { echo "
\n"; echo " ".$text['label-speed']."\n"; echo "
\n"; } // Voice echo "
\n"; if (!empty($voices)) { if ($voices_array_type == 'single') { echo " \n"; } if ($voices_array_type == 'multi') { echo " \n"; echo " \n"; echo " \n"; echo "\n"; } } else { echo " \n"; } echo "
\n"; // Speed if ($speed_enabled) { echo "
\n"; echo " \n"; echo "
\n"; echo "
\n"; } echo "
\n"; echo "
\n"; echo " ".$text['label-message']."
\n"; echo " \n"; echo "
\n"; } echo $text['description-'.$instance_label]."\n"; echo "
\n"; echo " ".$text['label-'.$instance_label]."\n"; echo "
\n"; echo "\n"; if (permission_exists('ivr_menu_audio_edit')) { echo ""; } if ((permission_exists('recording_play') || permission_exists('recording_download')) && (!empty($playable) || empty($instance_value))) { switch (pathinfo($playable, PATHINFO_EXTENSION)) { case 'wav' : $mime_type = 'audio/wav'; break; case 'mp3' : $mime_type = 'audio/mpeg'; break; case 'ogg' : $mime_type = 'audio/ogg'; break; } echo ""; echo button::create(['type'=>'button','title'=>$text['label-play'].' / '.$text['label-pause'],'icon'=>$settings->get('theme', 'button_icon_play'),'id'=>'recording_button_'.$instance_id,'style'=>'display: '.(!empty($mime_type) ? 'inline' : 'none'),'onclick'=>"recording_play('".$instance_id."', document.getElementById('".$instance_id."').value, document.getElementById('".$instance_id."').options[document.getElementById('".$instance_id."').selectedIndex].parentNode.getAttribute('data-type'));"]); unset($playable, $mime_type); } echo "
\n"; if ($speech_enabled && !empty($speech_engine)) { echo "
\n"; echo " ".$text['label-recording_name']."
\n"; echo " \n"; echo "

\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-voice']."\n"; echo "
\n"; if ($speed_enabled) { echo "
\n"; echo " ".$text['label-speed']."\n"; echo "
\n"; } // Voice echo "
\n"; if (!empty($voices)) { if ($voices_array_type == 'single') { echo " \n"; } if ($voices_array_type == 'multi') { echo " \n"; echo " \n"; echo " \n"; echo "\n"; } } else { echo " \n"; } echo "
\n"; // Speed if ($speed_enabled) { echo "
\n"; echo " \n"; echo "
\n"; echo "
\n"; } echo "
\n"; echo "
\n"; echo " ".$text['label-message']."
\n"; echo " \n"; echo "
\n"; } echo $text['description-'.$instance_label]."\n"; echo "
".$text['label-options'].""; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; if ($show_option_delete && permission_exists('ivr_menu_option_delete')) { echo " \n"; } echo " \n"; if (!empty($ivr_menu_options)) { $x = 0; foreach($ivr_menu_options as $field) { //add the primary key uuid if (!empty($field['ivr_menu_option_uuid'])) { echo " \n"; } echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if ($show_option_delete && permission_exists('ivr_menu_option_delete')) { if (!empty($field['ivr_menu_option_uuid']) && is_uuid($field['ivr_menu_option_uuid'])) { echo "\n"; } echo "\n"; $x++; } } unset($sql, $result); /* for ($c = 0; $c < 1; $c++) { echo " \n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; } */ echo "
".$text['label-option']."".$text['label-destination']."".$text['label-order']."".$text['label-description']."".$text['label-enabled']."\n"; echo " ".$text['label-delete']."\n"; echo " \n"; echo "
\n"; if (empty($field['ivr_menu_option_uuid'])) { // new record if (substr($settings->get('theme', 'input_toggle_style'), 0, 6) == 'switch') { $onkeyup = "onkeyup=\"document.getElementById('ivr_menu_options_".$x."_ivr_menu_option_enabled').checked = (this.value != '' ? true : false);\""; // switch } else { $onkeyup = "onkeyup=\"document.getElementById('ivr_menu_options_".$x."_ivr_menu_option_enabled').value = (this.value != '' ? true : false);\""; // select } } echo " \n"; echo "\n"; $destination_action = ''; if (!empty($field['ivr_menu_option_action'].$field['ivr_menu_option_param'])) { $destination_action = $field['ivr_menu_option_action'].':'.$field['ivr_menu_option_param']; } else { $destination_action = ''; } echo $destination->select('ivr', 'ivr_menu_options['.$x.'][ivr_menu_option_param]', $destination_action); unset($destination_action); echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; if ($input_toggle_style_switch) { echo " \n"; } echo " \n"; if ($input_toggle_style_switch) { echo " \n"; echo " \n"; } echo ""; echo " \n"; echo " \n"; } else { echo ""; } echo "
\n"; echo " \n"; echo "\n"; echo $destination->select('ivr', 'ivr_menu_options['.$c.'][ivr_menu_option_param]', $destination_action); echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "\n"; echo " \n"; echo "
\n"; echo " ".$text['description-options']."\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-timeout']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-timeout']."\n"; echo "
\n"; echo " ".$text['label-exit_action']."\n"; echo "\n"; echo $destination->select('dialplan', 'ivr_menu_exit_action', $ivr_menu_exit_action); echo "
\n"; echo " ".$text['description-exit_action']."\n"; echo "
\n"; echo " ".$text['label-direct_dial']."\n"; echo "\n"; if ($input_toggle_style_switch) { echo " \n"; } echo " \n"; if ($input_toggle_style_switch) { echo " \n"; echo " \n"; } echo "
\n"; echo $text['description-direct_dial']."\n"; echo "
\n"; echo " ".$text['label-ring_back']."\n"; echo " \n"; echo " ".$ringbacks->select('ivr_menu_ringback', $ivr_menu_ringback); echo "
\n"; echo " ".$text['description-ring_back']."\n"; echo "
\n"; echo " ".$text['label-caller_id_name_prefix']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo $text['description-caller_id_name_prefix']."\n"; echo "
 \n"; echo " ".button::create(['type'=>'button','label'=>$text['button-advanced'],'icon'=>'tools','onclick'=>'show_advanced_config();']); echo "
\n"; if (permission_exists('ivr_menu_context')) { echo "\n"; echo " \n"; echo " \n"; echo "\n"; } echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; echo "
\n"; echo " ".$text['label-context']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['description-enter-context']."\n"; echo "
\n"; echo " ".$text['label-enabled']."\n"; echo " \n"; if ($input_toggle_style_switch) { echo " \n"; } echo " \n"; if ($input_toggle_style_switch) { echo " \n"; echo " \n"; } echo "
\n"; echo " ".$text['description-enabled']."\n"; echo "
\n"; echo " ".$text['label-description']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['description-description']."\n"; echo "
"; echo "
\n"; echo "

"; if (is_uuid($ivr_menu_uuid)) { echo "\n"; echo "\n"; } echo "\n"; echo "
"; //include the footer require_once "resources/footer.php"; ?>