diff --git a/includes/lib_switch.php b/includes/lib_switch.php
index 3388587d95..a9b6a8f170 100644
--- a/includes/lib_switch.php
+++ b/includes/lib_switch.php
@@ -3333,237 +3333,6 @@ if (!function_exists('phone_letter_to_number')) {
}
-if (!function_exists('sync_directory')) {
- function sync_directory() {
-
- global $domain_uuid, $db;
-
- $tmp = "include(\"config.js\");\n";
- $tmp .= "//var sounds_dir\n";
- $tmp .= "var admin_pin = \"\";\n";
- $tmp .= "var search_type = \"\";\n";
- $tmp .= "//var tmp_dir\n";
- $tmp .= "var digitmaxlength = 0;\n";
- $tmp .= "var timeoutpin = 5000;\n";
- $tmp .= "var timeouttransfer = 5000;\n";
- $tmp .= "\n";
- $tmp .= "var dtmf = new Object( );\n";
- $tmp .= "dtmf.digits = \"\";\n";
- $tmp .= "\n";
- $tmp .= "function mycb( session, type, obj, arg ) {\n";
- $tmp .= " try {\n";
- $tmp .= " if ( type == \"dtmf\" ) {\n";
- $tmp .= " console_log( \"info\", \"digit: \"+obj.digit+\"\\n\" );\n";
- $tmp .= " if ( obj.digit == \"#\" ) {\n";
- $tmp .= " //console_log( \"info\", \"detected pound sign.\\n\" );\n";
- $tmp .= " exit = true;\n";
- $tmp .= " return( false );\n";
- $tmp .= " }\n";
- $tmp .= " if ( obj.digit == \"*\" ) {\n";
- $tmp .= " //console_log( \"info\", \"detected pound sign.\\n\" );\n";
- $tmp .= " exit = true;\n";
- $tmp .= " return( false );\n";
- $tmp .= " }\n";
- $tmp .= " dtmf.digits += obj.digit;\n";
- $tmp .= " if ( dtmf.digits.length >= digitmaxlength ) {\n";
- $tmp .= " exit = true;\n";
- $tmp .= " return( false );\n";
- $tmp .= " }\n";
- $tmp .= " }\n";
- $tmp .= " } catch (e) {\n";
- $tmp .= " console_log( \"err\", e+\"\\n\" );\n";
- $tmp .= " }\n";
- $tmp .= " return( true );\n";
- $tmp .= "} //end function mycb\n";
- $tmp .= "\n";
- $tmp .= "function directory_search(search_type) {\n";
- $tmp .= "\n";
- $tmp .= " digitmaxlength = 3;\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-enter_person.wav\");\n";
- $tmp .= " if (search_type == \"last_name\") {\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-last_name.wav\", mycb, \"dtmf\");\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-to_search_by.wav\", mycb, \"dtmf\");\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-first_name.wav\", mycb, \"dtmf\");\n";
- $tmp .= " }\n";
- $tmp .= " if (search_type == \"first_name\") {\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-first_name.wav\", mycb, \"dtmf\");\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-to_search_by.wav\", mycb, \"dtmf\");\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-last_name.wav\", mycb, \"dtmf\");\n";
- $tmp .= " }\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-press.wav\", mycb, \"dtmf\");\n";
- $tmp .= " session.execute(\"say\", \"en name_spelled iterated 1\");\n";
- $tmp .= " session.collectInput( mycb, dtmf, timeoutpin );\n";
- $tmp .= " var dtmf_search = dtmf.digits;\n";
- $tmp .= " //console_log( \"info\", \"--\" + dtmf.digits + \"--\\n\" );\n";
- $tmp .= " if (dtmf_search == \"1\") {\n";
- $tmp .= " //console_log( \"info\", \"press 1 detected: \" + dtmf.digits + \"\\n\" );\n";
- $tmp .= " //console_log( \"info\", \"press 1 detected: \" + search_type + \"\\n\" );\n";
- $tmp .= " if (search_type == \"last_name\") {\n";
- $tmp .= " //console_log( \"info\", \"press 1 detected last_name: \" + search_type + \"\\n\" );\n";
- $tmp .= " search_type = \"first_name\";\n";
- $tmp .= " }\n";
- $tmp .= " else {\n";
- $tmp .= " //console_log( \"info\", \"press 1 detected first_name: \" + search_type + \"\\n\" );\n";
- $tmp .= " search_type = \"last_name\";\n";
- $tmp .= " }\n";
- $tmp .= " dtmf_search = \"\";\n";
- $tmp .= " dtmf.digits = \"\";\n";
- $tmp .= " directory_search(search_type);\n";
- $tmp .= " return;\n";
- $tmp .= " }\n";
- $tmp .= " console_log( \"info\", \"first 3 letters of first or last name: \" + dtmf.digits + \"\\n\" );\n";
- $tmp .= "\n";
- $tmp .= " //session.execute(\"say\", \"en name_spelled pronounced mark\");\n";
- $tmp .= " //\n";
- $tmp .= " //session.execute(\"say\", \"en number iterated 12345\");\n";
- $tmp .= " //session.execute(\"say\", \"en number pronounced 1001\");\n";
- $tmp .= " //session.execute(\"say\", \"en short_date_time pronounced [timestamp]\");\n";
- $tmp .= " //session.execute(\"say\", \"en CURRENT_TIME pronounced CURRENT_TIME\");\n";
- $tmp .= " //session.execute(\"say\", \"en CURRENT_DATE pronounced CURRENT_DATE\");\n";
- $tmp .= " //session.execute(\"say\", \"en CURRENT_DATE_TIME pronounced CURRENT_DATE_TIME\");\n";
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= " //take each name and convert it to the equivalent number in php when this file is generated\n";
- $tmp .= " //then test each number see if it matches the user dtmf search keys\n";
- $tmp .= "\n";
- $tmp .= " var result_array = new Array();\n";
- $tmp .= " var x = 0;\n";
-
- //get a list of extensions and the users assigned to them
- $sql = "select * from v_extensions ";
- $sql .= "where domain_uuid = '$domain_uuid' ";
- $sql .= "and enabled = 'true'; ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $x = 0;
- $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- foreach ($result as &$row) {
- $extension = $row["extension"];
- $effective_caller_id_name = $row["effective_caller_id_name"];
- //$user_list = $row["user_list"];
- //$user_list = trim($user_list, "|");
- //$username_array = explode ("|", $user_list);
- foreach ($username_array as &$username) {
- if (strlen($username) > 0) {
- $sql = "select * from v_users ";
- $sql .= "where domain_uuid = '$domain_uuid' ";
- $sql .= "and username = '$username' ";
- $sql .= "and user_enabled = 'true' ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $tmp_result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
- foreach ($tmp_result as &$row_tmp) {
- $user_first_name = $row_tmp["user_first_name"];
- $user_last_name = $row_tmp["user_last_name"];
- if ($user_first_name == "na") { $user_first_name = ""; }
- if ($user_last_name == "na") { $user_last_name = ""; }
- if ($user_first_name == "admin") { $user_first_name = ""; }
- if ($user_last_name == "admin") { $user_last_name = ""; }
- if ($user_first_name == "superadmin") { $user_first_name = ""; }
- if ($user_last_name == "superadmin") { $user_last_name = ""; }
- if (strlen($user_first_name.$user_last_name) == 0) {
- $name_array = explode (" ", $effective_caller_id_name);
- $user_first_name = $name_array[0];
- if (count($name_array) > 1) {
- $user_last_name = $name_array[1];
- }
- }
-
- break; //limit to 1 row
- }
- $f1 = phone_letter_to_number(substr($user_first_name, 0,1));
- $f2 = phone_letter_to_number(substr($user_first_name, 1,1));
- $f3 = phone_letter_to_number(substr($user_first_name, 2,1));
-
- $l1 = phone_letter_to_number(substr($user_last_name, 0,1));
- $l2 = phone_letter_to_number(substr($user_last_name, 1,1));
- $l3 = phone_letter_to_number(substr($user_last_name, 2,1));
-
- //echo $sql." extension: $extension first_name $user_first_name last_name $user_last_name $tmp
";
-
- $tmp .= " if (search_type == \"first_name\" && dtmf_search == \"".$f1.$f2.$f3."\" || search_type == \"last_name\" && dtmf_search == \"".$l1.$l2.$l3."\") {\n";
- $tmp .= " result_array[x]=new Array()\n";
- $tmp .= " result_array[x]['first_name'] =\"".$user_first_name."\";\n";
- $tmp .= " result_array[x]['last_name'] =\"".$user_last_name."\";\n";
- $tmp .= " result_array[x]['extension'] = \"".$extension."\";\n";
- $tmp .= " //console_log( \"info\", \"found: ".$user_first_name." ".$user_last_name."\\n\" );\n";
- $tmp .= " x++;\n";
- $tmp .= " }\n";
- }
- }
- }
- unset ($prep_statement);
-
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= " //say the number of results that matched\n";
- $tmp .= " \$result_count = result_array.length;\n";
- $tmp .= " session.execute(\"say\", \"en number iterated \"+\$result_count);\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-result_match.wav\", mycb, \"dtmf\");\n";
- $tmp .= "\n";
- $tmp .= " //clear values\n";
- $tmp .= " dtmf_search = 0;\n";
- $tmp .= " dtmf.digits = '';\n";
- $tmp .= "\n";
- $tmp .= " if (\$result_count == 0) {\n";
- $tmp .= " //session.execute(\"transfer\", \"*347 XML ".$_SESSION["context"]."\");\n";
- $tmp .= " directory_search(search_type);\n";
- $tmp .= " return;\n";
- $tmp .= " }\n";
- $tmp .= "\n";
- $tmp .= " session.execute(\"set\", \"tts_engine=flite\");\n";
- $tmp .= " session.execute(\"set\", \"tts_voice=rms\"); //rms //kal //awb //slt\n";
- $tmp .= " session.execute(\"set\", \"playback_terminators=#\");\n";
- $tmp .= " //session.speak(\"flite\",\"kal\",\"Thanks for.. calling\");\n";
- $tmp .= "\n";
- $tmp .= " i=1;\n";
- $tmp .= " for ( i in result_array ) {\n";
- $tmp .= "\n";
- $tmp .= " //say first name and last name is at extension 1001\n";
- $tmp .= " //session.execute(\"speak\", result_array[i]['first_name']);\n";
- $tmp .= " //session.execute(\"speak\", result_array[i]['last_name']);\n";
- $tmp .= " session.execute(\"say\", \"en name_spelled pronounced \"+result_array[i]['first_name']);\n";
- $tmp .= " session.execute(\"sleep\", \"500\");\n";
- $tmp .= " session.execute(\"say\", \"en name_spelled pronounced \"+result_array[i]['last_name']);\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-at_extension.wav\", mycb, \"dtmf\");\n";
- $tmp .= " session.execute(\"say\", \"en number pronounced \"+result_array[i]['extension']);\n";
- $tmp .= "\n";
- $tmp .= " //to select this entry press 1\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-to_select_entry.wav\", mycb, \"dtmf\");\n";
- $tmp .= " session.streamFile( sounds_dir+\"/en/us/callie/directory/48000/dir-press.wav\", mycb, \"dtmf\");\n";
- $tmp .= " session.execute(\"say\", \"en number iterated 1\");\n";
- $tmp .= "\n";
- $tmp .= " //console_log( \"info\", \"first name: \" + result_array[i]['first_name'] + \"\\n\" );\n";
- $tmp .= " //console_log( \"info\", \"last name: \" + result_array[i]['last_name'] + \"\\n\" );\n";
- $tmp .= " //console_log( \"info\", \"extension: \" + result_array[i]['extension'] + \"\\n\" );\n";
- $tmp .= "\n";
- $tmp .= " //if 1 is pressed then transfer the call\n";
- $tmp .= " dtmf.digits = session.getDigits(1, \"#\", 3000);\n";
- $tmp .= " if (dtmf.digits == \"1\") {\n";
- $tmp .= " console_log( \"info\", \"directory: call transfered to: \" + result_array[i]['extension'] + \"\\n\" );\n";
- $tmp .= " session.execute(\"transfer\", result_array[i]['extension']+\" XML ".$_SESSION["context"]."\");\n";
- $tmp .= " }\n";
- $tmp .= "\n";
- $tmp .= " }\n";
- $tmp .= "}\n";
- $tmp .= "\n";
- $tmp .= "\n";
- $tmp .= "if ( session.ready() ) {\n";
- $tmp .= " session.answer();\n";
- $tmp .= " search_type = \"last_name\";\n";
- $tmp .= " directory_search(search_type);\n";
- $tmp .= " session.hangup(\"NORMAL_CLEARING\");\n";
- $tmp .= "}\n";
- $tmp .= "";
-
- //write the file
- $fout = fopen($switch_scripts_dir."/directory.js","w");
- fwrite($fout, $tmp);
- fclose($fout);
-
- } //end sync_directory
-} //end if function exists
-
if (!function_exists('save_ivr_menu_xml')) {
function save_ivr_menu_xml() {
global $db, $domain_uuid;