Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/functions/save_phrases_xml.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 (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) { if (permission_exists('phrase_domain')) { $domain_uuid = check_str($_POST["domain_uuid"]); } $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); } //process the changes from the http post if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //get the uuid if ($action == "update") { $phrase_uuid = check_str($_POST["phrase_uuid"]); } //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')) { //add the phrase to the database $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 if ($_POST['phrase_detail_data'] != '') { $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 .= "'".check_str($_POST['phrase_detail_order'])."', "; $sql .= "'".check_str($_POST['phrase_detail_tag'])."', "; $sql .= "'".check_str($_POST['phrase_detail_pattern'])."', "; $sql .= "'".check_str($_POST['phrase_detail_function'])."', "; $sql .= "'".check_str($_POST['phrase_detail_data'])."', "; $sql .= "'".check_str($_POST['phrase_detail_method'])."', "; $sql .= "'".check_str($_POST['phrase_detail_type'])."', "; $sql .= "'".check_str($_POST['phrase_detail_group'])."' "; $sql .= ") "; //echo $sql."

"; $db->exec(check_sql($sql)); unset($sql); } } //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); //send a redirect message::add($text['message-add']); header("Location: phrase_edit.php?id=".$phrase_uuid); return; } //if ($action == "add") //update the phrase 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 if ($_POST['phrase_detail_data'] != '') { $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 .= "'".check_str($_POST['phrase_detail_order'])."', "; $sql .= "'".check_str($_POST['phrase_detail_tag'])."', "; $sql .= "'".check_str($_POST['phrase_detail_pattern'])."', "; $sql .= "'".check_str($_POST['phrase_detail_function'])."', "; $sql .= "'".check_str($_POST['phrase_detail_data'])."', "; $sql .= "'".check_str($_POST['phrase_detail_method'])."', "; $sql .= "'".check_str($_POST['phrase_detail_type'])."', "; $sql .= "'".check_str($_POST['phrase_detail_group'])."' "; $sql .= ") "; //echo $sql."

"; $db->exec(check_sql($sql)); unset($sql); } } //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); //send a redirect message::add($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 = check_str($_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."' "; $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); } //get the phrase details 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(); $phrase_details = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset($sql, $prep_statement); } //get the recordings $sql = "select * from v_recordings "; $sql .= "where domain_uuid = '".$_SESSION["domain_uuid"]."' "; $sql .= "order by recording_name asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $recordings = $prep_statement->fetchAll(PDO::FETCH_ASSOC); unset($sql, $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']; } //js to control action form input echo "\n"; //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"; 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 "\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 (is_array($phrase_details)) { foreach($phrase_details as $field) { //clean up output for display if ($field['phrase_detail_function'] == 'execute' && substr($field['phrase_detail_data'], 0, 19) == '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); } elseif ($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 } elseif ($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"; } } echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
".$text['label-function']."".$text['label-action']."".$text['label-order']."
".escape($phrase_detail_function)." ".escape($phrase_detail_data)." ".$field['phrase_detail_order']." "; echo "".$v_link_label_delete.""; echo "
\n"; echo " \n"; echo " \n"; echo " "; if (if_group("superadmin")) { 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-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 "
\n"; if ($action == "update") { echo " \n"; } echo "
"; echo " \n"; echo "
"; echo "

"; echo "
"; //include the footer require_once "resources/footer.php"; ?>