From b0a0310b070fd1721c40020125896d012f6d8292 Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Sat, 14 Feb 2015 05:32:43 +0000 Subject: [PATCH] Phrases: Ability to sequence playback of audio files in the IVR, initial groundwork for other switch phrase manipulation. --- app/ivr_menu/ivr_menu_edit.php | 110 +++-- app/phrases/app_config.php | 147 ++++++ app/phrases/app_defaults.php | 103 ++++ app/phrases/app_languages.php | 219 +++++++++ app/phrases/app_menu.php | 21 + app/phrases/phrase_delete.php | 71 +++ app/phrases/phrase_detail_delete.php | 63 +++ app/phrases/phrase_edit.php | 463 ++++++++++++++++++ app/phrases/phrases.php | 154 ++++++ .../resources/functions/save_phrases_xml.php | 81 +++ app/phrases/root.php | 50 ++ resources/templates/conf/lang/de/de.xml | 21 +- resources/templates/conf/lang/en/en.xml | 3 +- resources/templates/conf/lang/fr/fr.xml | 23 +- resources/templates/conf/lang/he/he.xml | 21 +- resources/templates/conf/lang/ru/ru.xml | 19 +- 16 files changed, 1492 insertions(+), 77 deletions(-) create mode 100644 app/phrases/app_config.php create mode 100644 app/phrases/app_defaults.php create mode 100644 app/phrases/app_languages.php create mode 100644 app/phrases/app_menu.php create mode 100644 app/phrases/phrase_delete.php create mode 100644 app/phrases/phrase_detail_delete.php create mode 100644 app/phrases/phrase_edit.php create mode 100644 app/phrases/phrases.php create mode 100644 app/phrases/resources/functions/save_phrases_xml.php create mode 100644 app/phrases/root.php diff --git a/app/ivr_menu/ivr_menu_edit.php b/app/ivr_menu/ivr_menu_edit.php index 53784036bd..80c35963b4 100644 --- a/app/ivr_menu/ivr_menu_edit.php +++ b/app/ivr_menu/ivr_menu_edit.php @@ -353,7 +353,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " ".$text['label-extension'].":\n"; echo "\n"; echo "\n"; - echo " \n"; + echo " \n"; echo "
\n"; echo $text['description-extension']."\n"; echo "\n"; @@ -374,6 +374,7 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo " tb.type='text';\n"; echo " tb.name=obj.name;\n"; echo " tb.setAttribute('class', 'formfld');\n"; + echo " tb.setAttribute('style', 'width: 380px;');\n"; echo " tb.value=obj.options[obj.selectedIndex].value;\n"; echo " tbb=document.createElement('INPUT');\n"; echo " tbb.setAttribute('class', 'btn');\n"; @@ -396,30 +397,17 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; } if (if_group("superadmin")) { - echo " \n"; } else { - echo " \n"; } - //select - if (if_group("superadmin")) { - if (!$tmp_selected) { - echo "\n"; - if (file_exists($_SESSION['switch']['recordings']['dir']."/".$ivr_menu_greet_long)) { - echo " \n"; - } elseif (substr($ivr_menu_greet_long, -3) == "wav" || substr($ivr_menu_greet_long, -3) == "mp3") { - echo " \n"; - } - echo "\n"; - } - unset($tmp_selected); - } //misc optgroup if (if_group("superadmin")) { echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; echo "\n"; } //recordings @@ -435,10 +423,10 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { else { if ($ivr_menu_greet_long == $_SESSION['switch']['recordings']['dir']."/".$file && strlen($ivr_menu_greet_long) > 0) { $tmp_selected = true; - echo " \n"; + echo " \n"; } else { - echo " \n"; + echo " \n"; } } } @@ -446,6 +434,22 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { closedir($dh); echo "\n"; } + //phrases + echo "\n"; + $sql = "select * from v_phrases where domain_uuid = '".$domain_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + if ($ivr_menu_greet_long == "phrase:".$row["phrase_name"].".".$domain_uuid) { + $tmp_selected = true; + echo " \n"; + } else { + echo " \n"; + } + } + unset ($prep_statement); + echo "\n"; //sounds $dir_path = $_SESSION['switch']['sounds']['dir']; recur_sounds_dir($_SESSION['switch']['sounds']['dir']); @@ -457,13 +461,26 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { } if ($ivr_menu_greet_long == $key) { $tmp_selected = true; - echo " \n"; + echo " \n"; } else { - echo " \n"; + echo " \n"; } } } echo "\n"; + //select + if (if_group("superadmin")) { + if (!$tmp_selected) { + echo "\n"; + if (file_exists($_SESSION['switch']['recordings']['dir']."/".$ivr_menu_greet_long)) { + echo " \n"; + } elseif (substr($ivr_menu_greet_long, -3) == "wav" || substr($ivr_menu_greet_long, -3) == "mp3") { + echo " \n"; + } + echo "\n"; + } + unset($tmp_selected); + } echo " \n"; echo "
\n"; echo $text['description-greet_long']."\n"; @@ -477,14 +494,19 @@ if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { echo "\n"; echo "\n"; - echo " \n"; + } + else { + echo "\n"; + echo " \n"; echo "
\n"; echo $text['description-greet_short']."\n"; diff --git a/app/phrases/app_config.php b/app/phrases/app_config.php new file mode 100644 index 0000000000..17e48f24cf --- /dev/null +++ b/app/phrases/app_config.php @@ -0,0 +1,147 @@ + \ No newline at end of file diff --git a/app/phrases/app_defaults.php b/app/phrases/app_defaults.php new file mode 100644 index 0000000000..449d167adc --- /dev/null +++ b/app/phrases/app_defaults.php @@ -0,0 +1,103 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +if ($domains_processed == 1) { + + //define array of settings + $x = 0; + $array[$x]['default_setting_category'] = 'switch'; + $array[$x]['default_setting_subcategory'] = 'phrases'; + $array[$x]['default_setting_name'] = 'dir'; + $array[$x]['default_setting_value'] = '/usr/local/freeswitch/conf/lang'; + $array[$x]['default_setting_enabled'] = 'true'; + $array[$x]['default_setting_description'] = ''; + $x++; + + //iterate and add each, if necessary + foreach ($array as $index => $default_settings) { + + //add default settings + $sql = "select count(*) as num_rows from v_default_settings "; + $sql .= "where default_setting_category = '".$default_settings['default_setting_category']."' "; + $sql .= "and default_setting_subcategory = '".$default_settings['default_setting_subcategory']."' "; + $sql .= "and default_setting_name = '".$default_settings['default_setting_name']."' "; + $prep_statement = $db->prepare($sql); + if ($prep_statement) { + $prep_statement->execute(); + $row = $prep_statement->fetch(PDO::FETCH_ASSOC); + unset($prep_statement); + if ($row['num_rows'] == 0) { + $orm = new orm; + $orm->name('default_settings'); + $orm->save($array[$index]); + $message = $orm->message; + //print_r($message); + } + unset($row); + } + + } + + + //create phrases folder and add include line in xml for each language found + if (strlen($_SESSION['switch']['phrases']['dir']) > 0) { + if (is_readable($_SESSION['switch']['phrases']['dir'])) { + $conf_lang_folders = glob($_SESSION['switch']['phrases']['dir']."/*"); + foreach ($conf_lang_folders as $conf_lang_folder) { + //create phrases folder, if necessary + if (!file_exists($conf_lang_folder."/phrases/")) { + mkdir($conf_lang_folder."/phrases/", 0777); + } + //parse language, open xml file + $conf_lang = substr($conf_lang_folder, -2); + if (file_exists($conf_lang_folder."/".$conf_lang.".xml")) { + $conf_lang_xml_file_lines = file($conf_lang_folder."/".$conf_lang.".xml"); + //check for phrases inclusion + $phrases_include_found = false; + foreach ($conf_lang_xml_file_lines as $conf_lang_xml_file_line) { + if (substr_count($conf_lang_xml_file_line, "phrases/*.xml") > 0) { $phrases_include_found = true; } + } + if (!$phrases_include_found) { + //loop through lines to find closing macros index + foreach ($conf_lang_xml_file_lines as $conf_lang_xml_file_line_index => $conf_lang_xml_file_line) { + if (substr_count($conf_lang_xml_file_line, "") > 0) { + array_splice($conf_lang_xml_file_lines, $conf_lang_xml_file_line_index, 0, "\t\t\t\t\n"); + } + } + //re-write xml file contents + $conf_lang_xml_str = implode("", $conf_lang_xml_file_lines); + $fh = fopen($conf_lang_folder."/".$conf_lang.".xml", "w"); + fwrite($fh, $conf_lang_xml_str); + fclose($fh); + } + } //if + } //foreach + } //if + } //if + +} + +?> \ No newline at end of file diff --git a/app/phrases/app_languages.php b/app/phrases/app_languages.php new file mode 100644 index 0000000000..84b3e95208 --- /dev/null +++ b/app/phrases/app_languages.php @@ -0,0 +1,219 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2014 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + + $text['title_phrases']['en-us'] = "Phrases"; + $text['title_phrases']['es-cl'] = "Grabaciones"; + $text['title_phrases']['pt-pt'] = "Gravações"; + $text['title_phrases']['fr-fr'] = "Guides Vocaux"; + + $text['title-add_phrase']['en-us'] = "Add Phrase"; + $text['title-add_phrase']['es-cl'] = "Añadir Frase"; + $text['title-add_phrase']['pt-pt'] = "Añadir Frase"; + $text['title-add_phrase']['fr-fr'] = "Ajouter Phrase"; + + $text['title-edit_phrase']['en-us'] = "Edit Phrase"; + $text['title-edit_phrase']['es-cl'] = "Editar Frase"; + $text['title-edit_phrase']['pt-pt'] = "Editar Frase"; + $text['title-edit_phrase']['fr-fr'] = "Modifier Phrase"; + + $text['header_phrases']['en-us'] = "Phrases"; + $text['header_phrases']['es-cl'] = "Grabaciones"; + $text['header_phrases']['pt-pt'] = "Gravações"; + $text['header_phrases']['fr-fr'] = "Guides Vocaux"; + + $text['header-add_phrase']['en-us'] = "Add Phrase"; + $text['header-add_phrase']['es-cl'] = "Añadir Frase"; + $text['header-add_phrase']['pt-pt'] = "Añadir Frase"; + $text['header-add_phrase']['fr-fr'] = "Ajouter Phrase"; + + $text['header-edit_phrase']['en-us'] = "Edit Phrase"; + $text['header-edit_phrase']['es-cl'] = "Editar Frase"; + $text['header-edit_phrase']['pt-pt'] = "Editar Frase"; + $text['header-edit_phrase']['fr-fr'] = "Modifier Phrase"; + + $text['description-phrases']['en-us'] = "Create phrases of audio files to be played in sequence."; + $text['description-phrases']['es-cl'] = "Crear frases de archivos de audio para ser jugados en secuencia."; + $text['description-phrases']['pt-pt'] = "Criar frases de arquivos de áudio para serem tocados em sequência."; + $text['description-phrases']['fr-fr'] = "Créer des phrases de fichiers audio à jouer dans l'ordre."; + + $text['label-name']['en-us'] = "Name"; + $text['label-name']['es-cl'] = "Nombre"; + $text['label-name']['pt-pt'] = "Nome"; + $text['label-name']['fr-fr'] = "Nom"; + + $text['description-name']['en-us'] = "Name for the phrase (Example: 'xyz_audio')"; + $text['description-name']['es-cl'] = "Nombre de la grabación. ejemplo: grabacion_x"; + $text['description-name']['pt-pt'] = "Nome da gravação. exemplo: recording_x"; + $text['description-name']['fr-fr'] = "Nom de l'enregistrement. exemple: enregistrement_x"; + + $text['label-language']['en-us'] = "Language"; + $text['label-language']['es-cl'] = "Idioma"; + $text['label-language']['pt-pt'] = "Língua"; + $text['label-language']['fr-fr'] = "Langue"; + + $text['description-language']['en-us'] = "Language used in the phrase."; + $text['description-language']['es-cl'] = "El lenguaje utilizado en la frase."; + $text['description-language']['pt-pt'] = "Linguagem utilizada na frase."; + $text['description-language']['fr-fr'] = "Langue utilisée dans la phrase."; + + $text['label-structure']['en-us'] = "Structure"; + $text['label-structure']['es-cl'] = ""; + $text['label-structure']['pt-pt'] = ""; + $text['label-structure']['fr-fr'] = ""; + + $text['description-structure']['en-us'] = "Define the various components that make up the phrase."; + $text['description-structure']['es-cl'] = ""; + $text['description-structure']['pt-pt'] = ""; + $text['description-structure']['fr-fr'] = ""; + + $text['label-function']['en-us'] = "Function"; + $text['label-function']['es-cl'] = ""; + $text['label-function']['pt-pt'] = ""; + $text['label-function']['fr-fr'] = ""; + + $text['label-file']['en-us'] = "File"; + $text['label-file']['es-cl'] = ""; + $text['label-file']['pt-pt'] = ""; + $text['label-file']['fr-fr'] = ""; + + $text['label-order']['en-us'] = "Order"; + $text['label-order']['es-cl'] = "Orden"; + $text['label-order']['pt-pt'] = "Ordem"; + $text['label-order']['fr-fr'] = "Ordre"; + + $text['label-play_file']['en-us'] = "Play File"; + $text['label-play_file']['es-cl'] = ""; + $text['label-play_file']['pt-pt'] = ""; + $text['label-play_file']['fr-fr'] = ""; + + $text['label-say']['en-us'] = "Say"; + $text['label-say']['es-cl'] = ""; + $text['label-say']['pt-pt'] = ""; + $text['label-say']['fr-fr'] = ""; + + $text['label-execute']['en-us'] = "Execute"; + $text['label-execute']['es-cl'] = ""; + $text['label-execute']['pt-pt'] = ""; + $text['label-execute']['fr-fr'] = ""; + + $text['label-description']['en-us'] = "Description"; + $text['label-description']['es-cl'] = "Descripción"; + $text['label-description']['pt-pt'] = "Descrição"; + $text['label-description']['fr-fr'] = "Description"; + + $text['label-tools']['en-us'] = "Tools"; + $text['label-tools']['es-cl'] = "Instrumentos"; + $text['label-tools']['pt-pt'] = "Ferramentas"; + $text['label-tools']['fr-fr'] = "Outils"; + + $text['label-play']['en-us'] = "Play"; + $text['label-play']['es-cl'] = "Reproducir"; + $text['label-play']['pt-pt'] = "Tocar"; + $text['label-play']['fr-fr'] = "Jouer"; + + $text['label-pause']['en-us'] = "Pause"; + $text['label-pause']['es-cl'] = "Pausa"; + $text['label-pause']['pt-pt'] = "Pausa"; + $text['label-pause']['fr-fr'] = "Pause"; + + $text['label-enabled']['en-us'] = "Enabled"; + $text['label-enabled']['es-cl'] = "Activado"; + $text['label-enabled']['pt-pt'] = "Habilitada"; + $text['label-enabled']['fr-fr'] = "Actif"; + + $text['description-enabled']['en-us'] = "Set the status of the phrase."; + $text['description-enabled']['es-cl'] = "Ajuste el estado de la frase."; + $text['description-enabled']['pt-pt'] = "Defina o status da frase."; + $text['description-enabled']['fr-fr'] = "Définition de l'état de la phrase."; + + $text['label-true']['en-us'] = "True"; + $text['label-true']['es-cl'] = "Verdadero"; + $text['label-true']['pt-pt'] = "Sim"; + $text['label-true']['fr-fr'] = "Oui"; + + $text['label-false']['en-us'] = "False"; + $text['label-false']['es-cl'] = "Falso"; + $text['label-false']['pt-pt'] = "Não"; + $text['label-false']['fr-fr'] = "Non"; + + $text['confirm-delete']['en-us'] = "Do you really want to delete this?"; + $text['confirm-delete']['es-cl'] = "¿Realmente desea eliminar esto?"; + $text['confirm-delete']['pt-pt'] = "Deseja realmente remover isto?"; + $text['confirm-delete']['fr-fr'] = "Voulez-vous vraiment supprimer cela?"; + + $text['message-add']['en-us'] = "Add Complete"; + $text['message-add']['es-cl'] = "Agregar Completado"; + $text['message-add']['pt-pt'] = "Adição Efectuada"; + $text['message-add']['fr-fr'] = "Ajouté"; + + $text['message-update']['en-us'] = "Update Complete"; + $text['message-update']['es-cl'] = "Actualización Completada"; + $text['message-update']['pt-pt'] = "Actualização Efectuada"; + $text['message-update']['fr-fr'] = "Mis à jour"; + + $text['message-delete']['en-us'] = "Delete Complete"; + $text['message-delete']['es-cl'] = "Eliminación Completa"; + $text['message-delete']['pt-pt'] = "Remoçãoo Realizada"; + $text['message-delete']['fr-fr'] = "Supprimé"; + + $text['message-required']['en-us'] = "Please provide: "; + $text['message-required']['es-cl'] = "Por favor ingrese: "; + $text['message-required']['pt-pt'] = "Por favor forneça: "; + $text['message-required']['fr-fr'] = "Merci d'indiquer: "; + + $text['button-add']['en-us'] = "Add"; + $text['button-add']['es-cl'] = "Agregar"; + $text['button-add']['pt-pt'] = "Adicionar"; + $text['button-add']['fr-fr'] = "Ajouter"; + + $text['button-edit']['en-us'] = "Edit"; + $text['button-edit']['es-cl'] = "Editar"; + $text['button-edit']['pt-pt'] = "Editar"; + $text['button-edit']['fr-fr'] = "Editer"; + + $text['button-delete']['en-us'] = "Delete"; + $text['button-delete']['es-cl'] = "Eliminar"; + $text['button-delete']['pt-pt'] = "Remover"; + $text['button-delete']['fr-fr'] = "Supprimer"; + + $text['button-back']['en-us'] = "Back"; + $text['button-back']['es-cl'] = "Volver"; + $text['button-back']['pt-pt'] = "Voltar"; + $text['button-back']['fr-fr'] = "Retour"; + + $text['button-save']['en-us'] = "Save"; + $text['button-save']['es-cl'] = "Guardar"; + $text['button-save']['pt-pt'] = "Gravar"; + $text['button-save']['fr-fr'] = "Sauvegarder"; + + $text['button-advanced']['en-us'] = "Advanced"; + $text['button-advanced']['es-cl'] = "Avanzado"; + $text['button-advanced']['pt-pt'] = "Avançadas"; + $text['button-advanced']['fr-fr'] = "Afficher les paramètres avancés"; + + + +?> diff --git a/app/phrases/app_menu.php b/app/phrases/app_menu.php new file mode 100644 index 0000000000..1a4e65f8f3 --- /dev/null +++ b/app/phrases/app_menu.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/app/phrases/phrase_delete.php b/app/phrases/phrase_delete.php new file mode 100644 index 0000000000..449b4d5b59 --- /dev/null +++ b/app/phrases/phrase_delete.php @@ -0,0 +1,71 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +require_once "resources/functions/save_phrases_xml.php"; + +if (permission_exists('phrase_delete')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//get values + $phrase_uuid = $_GET["id"]; + +if ($phrase_uuid != '') { + //delete phrase details + $sql = "delete from v_phrase_details "; + $sql .= "where phrase_uuid = '".$phrase_uuid."' "; + $sql .= "and domain_uuid = '".$domain_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + unset($sql); + + //delete phrase + $sql = "delete from v_phrases "; + $sql .= "where phrase_uuid = '".$phrase_uuid."' "; + $sql .= "and domain_uuid = '".$domain_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + unset ($prep_statement); +} + +save_phrases_xml(); + +//redirect the user + $_SESSION["message"] = $text['message-delete']; + header("Location: phrases.php"); + return; +?> \ No newline at end of file diff --git a/app/phrases/phrase_detail_delete.php b/app/phrases/phrase_detail_delete.php new file mode 100644 index 0000000000..e8bf123580 --- /dev/null +++ b/app/phrases/phrase_detail_delete.php @@ -0,0 +1,63 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +require_once "resources/functions/save_phrases_xml.php"; + +if (permission_exists('phrase_delete')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//get values + $phrase_detail_uuid = check_str($_GET["pdid"]); + $phrase_uuid = check_str($_GET["pid"]); + +//delete the detail entry + if ($phrase_detail_uuid != '' && $phrase_uuid != '') { + $sql = "delete from v_phrase_details "; + $sql .= " where phrase_detail_uuid = '".$phrase_detail_uuid."'"; + $sql .= " and phrase_uuid = '".$phrase_uuid."' "; + $sql .= " and domain_uuid = '".$domain_uuid."' "; + $db->exec(check_sql($sql)); + unset($sql); + } + +save_phrases_xml(); + +//redirect the user + $_SESSION['message'] = $text['message-delete']; + header('Location: phrase_edit.php?id='.$phrase_uuid); + +?> \ No newline at end of file diff --git a/app/phrases/phrase_edit.php b/app/phrases/phrase_edit.php new file mode 100644 index 0000000000..6a00983b68 --- /dev/null +++ b/app/phrases/phrase_edit.php @@ -0,0 +1,463 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2015 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; +require_once "resources/functions/save_phrases_xml.php"; + +if (permission_exists('phrase_add') || permission_exists('phrase_edit')) { + //access granted +} +else { + echo "access denied"; + exit; +} + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//set the action as an add or an update + if (isset($_REQUEST["id"])) { + $action = "update"; + $phrase_uuid = check_str($_REQUEST["id"]); + } + else { + $action = "add"; + } + +//get the form value and set to php variables + if (count($_POST)>0) { + $phrase_name = check_str($_POST["phrase_name"]); + $phrase_language = check_str($_POST["phrase_language"]); + $phrase_enabled = check_str($_POST["phrase_enabled"]); + $phrase_description = check_str($_POST["phrase_description"]); + + //clean the name + $phrase_name = str_replace(" ", "_", $phrase_name); + $phrase_name = str_replace("'", "", $phrase_name); + } + + +if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { + + $msg = ''; + if ($action == "update") { + $phrase_uuid = check_str($_POST["phrase_uuid"]); + } + + //check for all required data + if (strlen($phrase_name) == 0) { $msg .= $text['message-required']." ".$text['label-name']."
\n"; } + if (strlen($phrase_language) == 0) { $msg .= $text['message-required']." ".$text['label-language']."
\n"; } + if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { + 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 ($_POST["persistformvar"] != "true") { + if ($action == "add" && permission_exists('phrase_add')) { + $phrase_uuid = uuid(); + $sql = "insert into v_phrases "; + $sql .= "( "; + $sql .= "domain_uuid, "; + $sql .= "phrase_uuid, "; + $sql .= "phrase_name, "; + $sql .= "phrase_language, "; + $sql .= "phrase_enabled, "; + $sql .= "phrase_description "; + $sql .= ") "; + $sql .= "values "; + $sql .= "( "; + $sql .= "'".$domain_uuid."', "; + $sql .= "'".$phrase_uuid."', "; + $sql .= "'".$phrase_name."', "; + $sql .= "'".$phrase_language."', "; + $sql .= "'".$phrase_enabled."', "; + $sql .= "'".$phrase_description."' "; + $sql .= ") "; + //echo $sql."

"; + $db->exec(check_sql($sql)); + unset($sql); + + if ($_POST['phrase_detail_function'] != '') { + $_POST['phrase_detail_tag'] = 'action'; // default, for now + $_POST['phrase_detail_group'] = "0"; // one group, for now + + $phrase_detail_uuid = uuid(); + $sql = "insert into v_phrase_details "; + $sql .= "( "; + $sql .= "phrase_detail_uuid, "; + $sql .= "phrase_uuid, "; + $sql .= "domain_uuid, "; + $sql .= "phrase_detail_order, "; + $sql .= "phrase_detail_tag, "; + $sql .= "phrase_detail_pattern, "; + $sql .= "phrase_detail_function, "; + $sql .= "phrase_detail_data, "; + $sql .= "phrase_detail_method, "; + $sql .= "phrase_detail_type, "; + $sql .= "phrase_detail_group "; + $sql .= " ) "; + $sql .= "values "; + $sql .= "( "; + $sql .= "'".$phrase_detail_uuid."', "; + $sql .= "'".$phrase_uuid."', "; + $sql .= "'".$domain_uuid."', "; + $sql .= "'".$_POST['phrase_detail_order']."', "; + $sql .= "'".$_POST['phrase_detail_tag']."', "; + $sql .= "'".$_POST['phrase_detail_pattern']."', "; + $sql .= "'".$_POST['phrase_detail_function']."', "; + $sql .= "'".$_POST['phrase_detail_data']."', "; + $sql .= "'".$_POST['phrase_detail_method']."', "; + $sql .= "'".$_POST['phrase_detail_type']."', "; + $sql .= "'".$_POST['phrase_detail_group']."' "; + $sql .= ") "; + //echo $sql."

"; + $db->exec(check_sql($sql)); + unset($sql); + } + + save_phrases_xml(); + + $_SESSION["message"] = $text['message-add']; + header("Location: phrase_edit.php?id=".$phrase_uuid); + return; + + } //if ($action == "add") + + if ($action == "update" && permission_exists('phrase_edit')) { + //update the database with the new data + $sql = "update v_phrases set "; + $sql .= "phrase_name = '".$phrase_name."', "; + $sql .= "phrase_language = '".$phrase_language."', "; + $sql .= "phrase_enabled = '".$phrase_enabled."', "; + $sql .= "phrase_description = '".$phrase_description."' "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and phrase_uuid = '".$phrase_uuid."' "; + $db->exec(check_sql($sql)); + unset($sql); + + if ($_POST['phrase_detail_function'] != '') { + $_POST['phrase_detail_tag'] = 'action'; // default, for now + $_POST['phrase_detail_group'] = "0"; // one group, for now + + $phrase_detail_uuid = uuid(); + $sql = "insert into v_phrase_details "; + $sql .= "( "; + $sql .= "phrase_detail_uuid, "; + $sql .= "phrase_uuid, "; + $sql .= "domain_uuid, "; + $sql .= "phrase_detail_order, "; + $sql .= "phrase_detail_tag, "; + $sql .= "phrase_detail_pattern, "; + $sql .= "phrase_detail_function, "; + $sql .= "phrase_detail_data, "; + $sql .= "phrase_detail_method, "; + $sql .= "phrase_detail_type, "; + $sql .= "phrase_detail_group "; + $sql .= ") "; + $sql .= "values "; + $sql .= "( "; + $sql .= "'".$phrase_detail_uuid."', "; + $sql .= "'".$phrase_uuid."', "; + $sql .= "'".$domain_uuid."', "; + $sql .= "'".$_POST['phrase_detail_order']."', "; + $sql .= "'".$_POST['phrase_detail_tag']."', "; + $sql .= "'".$_POST['phrase_detail_pattern']."', "; + $sql .= "'".$_POST['phrase_detail_function']."', "; + $sql .= "'".$_POST['phrase_detail_data']."', "; + $sql .= "'".$_POST['phrase_detail_method']."', "; + $sql .= "'".$_POST['phrase_detail_type']."', "; + $sql .= "'".$_POST['phrase_detail_group']."' "; + $sql .= ") "; + //echo $sql."

"; + $db->exec(check_sql($sql)); + unset($sql); + } + + save_phrases_xml(); + + $_SESSION["message"] = $text['message-update']; + header("Location: phrase_edit.php?id=".$phrase_uuid); + return; + + } //if ($action == "update") + + } //if ($_POST["persistformvar"] != "true") + +} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) + +//pre-populate the form + if (count($_GET)>0 && $_POST["persistformvar"] != "true") { + $phrase_uuid = $_GET["id"]; + $sql = "select * from v_phrases "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $sql .= "and phrase_uuid = '".$phrase_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + foreach ($result as &$row) { + $phrase_name = $row["phrase_name"]; + $phrase_language = $row["phrase_language"]; + $phrase_enabled = $row["phrase_enabled"]; + $phrase_description = $row["phrase_description"]; + break; //limit to 1 row + } + unset ($prep_statement); + } + +//show the header + require_once "resources/header.php"; + if ($action == 'add') { $document['title'] = $text['title-add_phrase']; } + if ($action == 'update') { $document['title'] = $text['title-edit_phrase']; } + +//show the content + 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 (if_group("superadmin")) { + 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 ""; + + echo "
"; + if ($action == "add") { echo "".$text['title-add_phrase'].""; } + if ($action == "update") { echo "".$text['title-edit_phrase'].""; } + echo "

"; + echo "
"; + echo " "; + 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-language']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo " ".$text['description-language']."\n"; + echo "
".$text['label-structure'].""; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + if (strlen($phrase_uuid) > 0) { + $sql = "select * from v_phrase_details "; + $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' "; + $sql .= "and phrase_uuid = '".$phrase_uuid."' "; + $sql .= "order by phrase_detail_order asc "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $result_count = count($result); + foreach($result as $field) { + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "\n"; + } + } + unset($sql, $result); + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + + echo " \n"; + echo "
".$text['label-function']."".$text['label-file']."".$text['label-order']."
".$field['phrase_detail_function']." ".$field['phrase_detail_data']." ".$field['phrase_detail_order']." "; + echo "".$v_link_label_delete.""; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + + echo " ".$text['description-structure']."\n"; + echo "
\n"; + echo "
\n"; + echo " ".$text['label-enabled']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + echo $text['description-enabled']."\n"; + echo "
\n"; + echo " ".$text['label-description']."\n"; + echo "\n"; + echo " \n"; + echo "
\n"; + if ($action == "update") { + echo " \n"; + } + echo "
"; + echo " \n"; + echo "
"; + echo "
"; + +//include the footer + require_once "resources/footer.php"; +?> \ No newline at end of file diff --git a/app/phrases/phrases.php b/app/phrases/phrases.php new file mode 100644 index 0000000000..3f9f98048b --- /dev/null +++ b/app/phrases/phrases.php @@ -0,0 +1,154 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2015 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; + +//add multi-lingual support + $language = new text; + $text = $language->get(); + +//get the http get values and set them as php variables + $order_by = $_GET["order_by"]; + $order = $_GET["order"]; + +//check the permission + if (!permission_exists('phrase_view')) { + echo "access denied"; + exit; + } + +//add paging + require_once "resources/paging.php"; + +//include the header + require_once "resources/header.php"; + $document['title'] = $text['title-phrases']; + +//begin the content + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo " ".$text['header_phrases']."\n"; + echo "

\n"; + echo " ".$text['description-phrases']."\n"; + echo "
"; + echo "
\n"; + + $sql = "select * from v_phrases "; + $sql .= "where domain_uuid = '".$domain_uuid."' "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $num_rows = count($result); + unset ($prep_statement, $result, $sql); + + $rows_per_page = 50; + $param = ""; + $page = $_GET['page']; + if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } + list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); + $offset = $rows_per_page * $page; + + $sql = "select * from v_phrases "; + $sql .= "where domain_uuid = '$domain_uuid' "; + $sql .= "order by ".((strlen($order_by) > 0) ? $order_by." ".$order." " : "phrase_name asc "); + $sql .= "limit ".$rows_per_page." offset ".$offset." "; + $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); + $result_count = count($result); + unset ($prep_statement, $sql); + + $c = 0; + $row_style["0"] = "row_style0"; + $row_style["1"] = "row_style1"; + + echo "\n"; + echo "\n"; + echo th_order_by('phrase_name', $text['label-name'], $order_by, $order); + echo th_order_by('phrase_language', $text['label-language'], $order_by, $order); + echo th_order_by('phrase_enabled', $text['label-enabled'], $order_by, $order); + echo th_order_by('phrase_description', $text['label-description'], $order_by, $order); + echo "\n"; + echo "\n"; + + if ($result_count > 0) { + foreach($result as $row) { + $tr_link = (permission_exists('phrase_edit')) ? "href='phrase_edit.php?id=".$row['phrase_uuid']."'" : null; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "\n"; + + $c = ($c==0) ? 1 : 0; + } //end foreach + unset($sql, $result, $row_count); + } //end if results + + echo "\n"; + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
"; + if (permission_exists('phrase_add')) { + echo "".$v_link_label_add.""; + } + echo "
".$row['phrase_name']."".$row['phrase_language']." ".$text['label-'.$row['phrase_enabled']]." ".$row['phrase_description']." "; + if (permission_exists('phrase_edit')) { + echo "".$v_link_label_edit.""; + } + if (permission_exists('phrase_delete')) { + echo "".$v_link_label_delete.""; + } + echo "
 "; + if (permission_exists('phrase_add')) { + echo "".$v_link_label_add.""; + } + echo "
\n"; + + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo "
 ".$paging_controls.""; + echo "
\n"; + + echo "
\n"; + +//include the footer + require_once "resources/footer.php"; + +?> \ No newline at end of file diff --git a/app/phrases/resources/functions/save_phrases_xml.php b/app/phrases/resources/functions/save_phrases_xml.php new file mode 100644 index 0000000000..6c7921d0ae --- /dev/null +++ b/app/phrases/resources/functions/save_phrases_xml.php @@ -0,0 +1,81 @@ +prepare(check_sql($sql)); + $prep_statement->execute(); + $result = $prep_statement->fetchAll(PDO::FETCH_ASSOC); + + $prev_language = ''; + foreach ($result as $row) { + + if ($row['phrase_language'] != $prev_language) { + if ($prev_language != '') { + //output xml & close previous file + $xml .= "\n"; + fwrite($fout, $xml); + unset($xml); + fclose($fout); + } + + //create/open new xml file for writing + $xml_path = $_SESSION['switch']['phrases']['dir']."/".$row['phrase_language']."/phrases/".$domain_uuid.".xml"; + $fout = fopen($xml_path, "w"); + $xml = "\n"; + } + + //build xml + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + + $sql2 = "select * from v_phrase_details "; + $sql2 .= "where domain_uuid = '".$domain_uuid."' "; + $sql2 .= "and phrase_uuid = '".$row['phrase_uuid']."' "; + $sql2 .= "order by phrase_detail_order"; + $prep_statement2 = $db->prepare(check_sql($sql2)); + $prep_statement2->execute(); + $result2 = $prep_statement2->fetchAll(PDO::FETCH_ASSOC); + foreach ($result2 as &$row2) { + $xml .= " \n"; + } + unset($prep_statement2); + $xml .= " \n"; + $xml .= " \n"; + $xml .= " \n"; + + $prev_language = $row['phrase_language']; + + } + + //output xml & close previous file + $xml .= "\n"; + + fwrite($fout, $xml); + unset($xml); + fclose($fout); + + unset($prep_statement); + + //apply settings + $_SESSION["reload_xml"] = true; + +} +?> \ No newline at end of file diff --git a/app/phrases/root.php b/app/phrases/root.php new file mode 100644 index 0000000000..7b882438ea --- /dev/null +++ b/app/phrases/root.php @@ -0,0 +1,50 @@ + + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +// make sure the PATH_SEPARATOR is defined + if (!defined("PATH_SEPARATOR")) { + if ( strpos( $_ENV[ "OS" ], "Win" ) !== false ) { define("PATH_SEPARATOR", ";"); } else { define("PATH_SEPARATOR", ":"); } + } + +// make sure the document_root is set + $_SERVER["SCRIPT_FILENAME"] = str_replace("\\", "/", $_SERVER["SCRIPT_FILENAME"]); + $_SERVER["DOCUMENT_ROOT"] = str_replace($_SERVER["PHP_SELF"], "", $_SERVER["SCRIPT_FILENAME"]); + $_SERVER["DOCUMENT_ROOT"] = realpath($_SERVER["DOCUMENT_ROOT"]); + //echo "DOCUMENT_ROOT: ".$_SERVER["DOCUMENT_ROOT"]."
\n"; + //echo "PHP_SELF: ".$_SERVER["PHP_SELF"]."
\n"; + //echo "SCRIPT_FILENAME: ".$_SERVER["SCRIPT_FILENAME"]."
\n"; + +// if the project directory exists then add it to the include path otherwise add the document root to the include path + if (is_dir($_SERVER["DOCUMENT_ROOT"].'/fusionpbx')){ + if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', '/fusionpbx'); } + set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER["DOCUMENT_ROOT"].'/fusionpbx' ); + } + else { + if(!defined('PROJECT_PATH')) { define('PROJECT_PATH', ''); } + set_include_path( get_include_path() . PATH_SEPARATOR . $_SERVER['DOCUMENT_ROOT'] ); + } + +?> \ No newline at end of file diff --git a/resources/templates/conf/lang/de/de.xml b/resources/templates/conf/lang/de/de.xml index 1b44c9a1dd..761811ecff 100644 --- a/resources/templates/conf/lang/de/de.xml +++ b/resources/templates/conf/lang/de/de.xml @@ -1,11 +1,12 @@ - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/resources/templates/conf/lang/en/en.xml b/resources/templates/conf/lang/en/en.xml index 0133450806..690222950c 100644 --- a/resources/templates/conf/lang/en/en.xml +++ b/resources/templates/conf/lang/en/en.xml @@ -8,7 +8,8 @@ + - + \ No newline at end of file diff --git a/resources/templates/conf/lang/fr/fr.xml b/resources/templates/conf/lang/fr/fr.xml index acdf4f2591..f106dbc240 100644 --- a/resources/templates/conf/lang/fr/fr.xml +++ b/resources/templates/conf/lang/fr/fr.xml @@ -1,12 +1,13 @@ - - - - - - - - - - - + + + + + + + + + + + + \ No newline at end of file diff --git a/resources/templates/conf/lang/he/he.xml b/resources/templates/conf/lang/he/he.xml index fe7c5d8a01..dc65b87cc4 100644 --- a/resources/templates/conf/lang/he/he.xml +++ b/resources/templates/conf/lang/he/he.xml @@ -1,11 +1,12 @@ - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/resources/templates/conf/lang/ru/ru.xml b/resources/templates/conf/lang/ru/ru.xml index 686e840860..8aff4fb766 100644 --- a/resources/templates/conf/lang/ru/ru.xml +++ b/resources/templates/conf/lang/ru/ru.xml @@ -1,13 +1,14 @@ - - - - - - - - - + + + + + + + + + +