Portions created by the Initial Developer are Copyright (C) 2008-2020 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions 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 (is_uuid($_REQUEST["id"])) { $action = "update"; $phrase_uuid = $_REQUEST["id"]; } else { $action = "add"; } //get the form value and set to php variables if (count($_POST) > 0) { //process the http post data by submitted action if ($_POST['action'] != '' && is_uuid($_POST['phrase_uuid'])) { $array[0]['checked'] = 'true'; $array[0]['uuid'] = $_POST['phrase_uuid']; switch ($_POST['action']) { case 'delete': if (permission_exists('phrase_delete')) { $obj = new phrases; $obj->delete($array); } break; } header('Location: phrases.php'); exit; } if (permission_exists('phrase_domain')) { $domain_uuid = $_POST["domain_uuid"]; } $phrase_name = $_POST["phrase_name"]; $phrase_language = $_POST["phrase_language"]; $phrase_enabled = $_POST["phrase_enabled"]; $phrase_description = $_POST["phrase_description"]; $phrase_details_delete = $_POST["phrase_details_delete"]; //clean the name $phrase_name = str_replace(" ", "_", $phrase_name); $phrase_name = str_replace("'", "", $phrase_name); } //process the changes from the http post if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //get the uuid if ($action == "update") { $phrase_uuid = $_POST["phrase_uuid"]; } //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: phrases.php'); exit; } //check for all required data $msg = ''; 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 the phrase if ($_POST["persistformvar"] != "true") { if ($action == "add" && permission_exists('phrase_add')) { //build data array $phrase_uuid = uuid(); $array['phrases'][0]['domain_uuid'] = $domain_uuid; $array['phrases'][0]['phrase_uuid'] = $phrase_uuid; $array['phrases'][0]['phrase_name'] = $phrase_name; $array['phrases'][0]['phrase_language'] = $phrase_language; $array['phrases'][0]['phrase_enabled'] = $phrase_enabled; $array['phrases'][0]['phrase_description'] = $phrase_description; if ($_POST['phrase_detail_function'] != '') { if ($_POST['phrase_detail_function'] == 'execute' && substr($_POST['phrase_detail_data'], 0,5) != "sleep" && !permission_exists("phrase_execute")) { header("Location: phrase_edit.php"); exit; } $_POST['phrase_detail_tag'] = 'action'; // default, for now $_POST['phrase_detail_group'] = "0"; // one group, for now if ($_POST['phrase_detail_data'] != '') { $phrase_detail_uuid = uuid(); $array['phrase_details'][0]['phrase_detail_uuid'] = $phrase_detail_uuid; $array['phrase_details'][0]['phrase_uuid'] = $phrase_uuid; $array['phrase_details'][0]['domain_uuid'] = $domain_uuid; $array['phrase_details'][0]['phrase_detail_order'] = $_POST['phrase_detail_order']; $array['phrase_details'][0]['phrase_detail_tag'] = $_POST['phrase_detail_tag']; $array['phrase_details'][0]['phrase_detail_pattern'] = $_POST['phrase_detail_pattern']; $array['phrase_details'][0]['phrase_detail_function'] = $_POST['phrase_detail_function']; $array['phrase_details'][0]['phrase_detail_data'] = $_POST['phrase_detail_data']; $array['phrase_details'][0]['phrase_detail_method'] = $_POST['phrase_detail_method']; $array['phrase_details'][0]['phrase_detail_type'] = $_POST['phrase_detail_type']; $array['phrase_details'][0]['phrase_detail_group'] = $_POST['phrase_detail_group']; } } //execute insert $p = new permissions; $p->add('phrase_detail_add', 'temp'); $database = new database; $database->app_name = 'phrases'; $database->app_uuid = '5c6f597c-9b78-11e4-89d3-123b93f75cba'; $database->save($array); unset($array); $p->delete('phrase_detail_add', 'temp'); //save the xml to the file system if the phrase directory is set //save_phrases_xml(); //clear the cache $cache = new cache; $cache->delete("languages:".$phrase_language.".".$phrase_uuid); //clear the destinations session array if (isset($_SESSION['destinations']['array'])) { unset($_SESSION['destinations']['array']); } //send a redirect message::add($text['message-add']); header("Location: phrase_edit.php?id=".$phrase_uuid); exit; } //update the phrase if ($action == "update" && permission_exists('phrase_edit')) { //build data array $array['phrases'][0]['domain_uuid'] = $domain_uuid; $array['phrases'][0]['phrase_uuid'] = $phrase_uuid; $array['phrases'][0]['phrase_name'] = $phrase_name; $array['phrases'][0]['phrase_language'] = $phrase_language; $array['phrases'][0]['phrase_enabled'] = $phrase_enabled; $array['phrases'][0]['phrase_description'] = $phrase_description; if ($_POST['phrase_detail_function'] != '') { if ($_POST['phrase_detail_function'] == 'execute' && substr($_POST['phrase_detail_data'], 0,5) != "sleep" && !permission_exists("phrase_execute")) { header("Location: phrase_edit.php?id=".$phrase_uuid); exit; } $_POST['phrase_detail_tag'] = 'action'; // default, for now $_POST['phrase_detail_group'] = "0"; // one group, for now if ($_POST['phrase_detail_data'] != '') { $phrase_detail_uuid = uuid(); $array['phrase_details'][0]['phrase_detail_uuid'] = $phrase_detail_uuid; $array['phrase_details'][0]['phrase_uuid'] = $phrase_uuid; $array['phrase_details'][0]['domain_uuid'] = $domain_uuid; $array['phrase_details'][0]['phrase_detail_order'] = $_POST['phrase_detail_order']; $array['phrase_details'][0]['phrase_detail_tag'] = $_POST['phrase_detail_tag']; $array['phrase_details'][0]['phrase_detail_pattern'] = $_POST['phrase_detail_pattern']; $array['phrase_details'][0]['phrase_detail_function'] = $_POST['phrase_detail_function']; $array['phrase_details'][0]['phrase_detail_data'] = $_POST['phrase_detail_data']; $array['phrase_details'][0]['phrase_detail_method'] = $_POST['phrase_detail_method']; $array['phrase_details'][0]['phrase_detail_type'] = $_POST['phrase_detail_type']; $array['phrase_details'][0]['phrase_detail_group'] = $_POST['phrase_detail_group']; } } //execute update/insert $p = new permissions; $p->add('phrase_detail_add', 'temp'); $database = new database; $database->app_name = 'phrases'; $database->app_uuid = '5c6f597c-9b78-11e4-89d3-123b93f75cba'; $database->save($array); unset($array); $p->delete('phrase_detail_add', 'temp'); //remove checked phrase details if ( is_array($phrase_details_delete) && @sizeof($phrase_details_delete) != 0 ) { $obj = new phrases; $obj->phrase_uuid = $phrase_uuid; $obj->delete_details($phrase_details_delete); } //clear the cache $cache = new cache; $cache->delete("languages:".$phrase_language.".".$phrase_uuid); //clear the destinations session array if (isset($_SESSION['destinations']['array'])) { unset($_SESSION['destinations']['array']); } //send a redirect message::add($text['message-update']); header("Location: phrase_edit.php?id=".$phrase_uuid); exit;; } } } //pre-populate the form if (count($_GET)>0 && $_POST["persistformvar"] != "true") { $phrase_uuid = $_GET["id"]; $sql = "select * from v_phrases "; $sql .= "where ( "; $sql .= " domain_uuid = :domain_uuid or "; $sql .= " domain_uuid is null "; $sql .= ") "; $sql .= "and phrase_uuid = :phrase_uuid "; $parameters['domain_uuid'] = $domain_uuid; $parameters['phrase_uuid'] = $phrase_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && @sizeof($row) != 0) { $phrase_name = $row["phrase_name"]; $phrase_language = $row["phrase_language"]; $phrase_enabled = $row["phrase_enabled"]; $phrase_description = $row["phrase_description"]; } unset($sql, $parameters, $row); } //get the phrase details if (is_uuid($phrase_uuid)) { $sql = "select * from v_phrase_details "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and phrase_uuid = :phrase_uuid "; $sql .= "order by phrase_detail_order asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $parameters['phrase_uuid'] = $phrase_uuid; $database = new database; $phrase_details = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); } //get the recording names from the database. $sql = "select recording_name, recording_filename from v_recordings "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "order by recording_name asc "; $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $database = new database; $recordings = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header if ($action == 'add') { $document['title'] = $text['title-add_phrase']; } if ($action == 'update') { $document['title'] = $text['title-edit_phrase']; } require_once "resources/header.php"; //js to control action form input echo "\n"; //show the content echo "
\n"; echo "
\n"; echo "
"; if ($action == "add") { echo "".$text['title-add_phrase'].""; } if ($action == "update") { echo "".$text['title-edit_phrase'].""; } echo "
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'phrases.php']); if ($action == "update" && permission_exists('phrase_delete')) { echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>'margin-left: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','style'=>'margin-left: 15px;']); echo "
\n"; echo "
\n"; echo "
\n"; if ($action == "update" && permission_exists('phrase_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 "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo ""; echo ""; echo ""; echo ""; if (permission_exists('phrase_domain')) { 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-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"; if ($phrase_details) { echo " \n"; } echo " \n"; if (is_array($phrase_details) && @sizeof($phrase_details) != 0) { foreach($phrase_details as $x => $field) { //clean up output for display if ($field['phrase_detail_function'] == 'play-file' && substr($field['phrase_detail_data'], 0, 21) == '${lua streamfile.lua ') { $phrase_detail_function = $text['label-play']; $phrase_detail_data = str_replace('${lua streamfile.lua ', '', $field['phrase_detail_data']); $phrase_detail_data = str_replace('}', '', $phrase_detail_data); } else if ($field['phrase_detail_function'] == 'execute' && substr($field['phrase_detail_data'], 0, 6) == 'sleep(') { $phrase_detail_function = $text['label-pause']; $phrase_detail_data = str_replace('sleep(', '', $field['phrase_detail_data']); $phrase_detail_data = str_replace(')', '', $phrase_detail_data); $phrase_detail_data = ($phrase_detail_data / 1000).'s'; // seconds } else if ($field['phrase_detail_function'] == 'play-file') { $phrase_detail_function = $text['label-play']; $phrase_detail_data = str_replace($_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/', '', $field['phrase_detail_data']); } else { $phrase_detail_function = $field['phrase_detail_function']; $phrase_detail_data = $field['phrase_detail_data']; } echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; } } unset($phrase_details, $field); echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
".$text['label-function']."".$text['label-action']."".$text['label-order']."\n"; echo " ".$text['label-delete']."\n"; echo " \n"; echo "
".escape($phrase_detail_function)." ".escape($phrase_detail_data)." ".$field['phrase_detail_order']." "; if (is_uuid($field['phrase_detail_uuid'])) { echo " \n"; echo " \n"; } echo "
\n"; echo " \n"; echo " \n"; echo " "; if (if_group("superadmin")) { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo button::create(['type'=>'submit','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add']]); echo "
\n"; echo " ".$text['description-structure']."\n"; echo "
\n"; echo "
\n"; echo " ".$text['label-domain']."\n"; echo "\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 "
"; echo "

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