fusionpbx/app/phrases/phrase_edit.php

655 lines
26 KiB
PHP
Raw Permalink Normal View History

<?php
/*
FusionPBX
Version: MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
2023-06-07 00:05:05 +02:00
Portions created by the Initial Developer are Copyright (C) 2008-2023
the Initial Developer. All Rights Reserved.
Contributor(s):
Mark J Crane <markjcrane@fusionpbx.com>
*/
2022-10-11 00:35:14 +02:00
//includes files
Use magic constant dir (#6711) * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ * use magic constant __DIR__ to load only functions.php * replace spaces with tab character * update dirname command to use levels instead of nesting * use magic constant __DIR__ * update dirname command to use levels instead of nesting * Update access_control_edit.php * Update access_control_import.php * Update access_controls.php * Update dnd.php * Update access_controls_reload.php * Update call_center_agents.php * Update call_center_agents.php * Update fax_queue.php * Update login.php * Update pdo.php * Update pdo_vm.php * Update switch.php * Update index.php * Update css.php * Update v_mailto.php * Update fax_to_email.php --------- Co-authored-by: FusionPBX <markjcrane@gmail.com>
2023-06-15 19:28:23 +02:00
require_once dirname(__DIR__, 2) . "/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();
//add the defaults
$phrase_name = '';
$phrase_language = '';
$phrase_description = '';
//set the action as an add or an update
if (!empty($_REQUEST["id"])) {
$action = "update";
2019-08-12 12:34:48 +02:00
$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 (!empty($_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')) {
2019-08-12 12:34:48 +02:00
$domain_uuid = $_POST["domain_uuid"];
}
2019-08-12 12:34:48 +02:00
$phrase_name = $_POST["phrase_name"];
$phrase_language = $_POST["phrase_language"];
2023-06-07 00:05:05 +02:00
$phrase_enabled = $_POST["phrase_enabled"] ?? 'false';
2019-08-12 12:34:48 +02:00
$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 && empty($_POST["persistformvar"])) {
//get the uuid
if ($action == "update") {
2019-08-12 12:34:48 +02:00
$phrase_uuid = $_POST["phrase_uuid"];
}
2019-09-19 14:45:47 +02:00
//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 (empty($phrase_name)) { $msg .= $text['message-required']." ".$text['label-name']."<br>\n"; }
if (empty($phrase_language)) { $msg .= $text['message-required']." ".$text['label-language']."<br>\n"; }
if (!empty($msg) && empty($_POST["persistformvar"])) {
require_once "resources/header.php";
require_once "resources/persist_form_var.php";
echo "<div align='center'>\n";
echo "<table><tr><td>\n";
echo $msg."<br />";
echo "</td></tr></table>\n";
persistformvar($_POST);
echo "</div>\n";
require_once "resources/footer.php";
return;
}
//add the phrase
2023-06-08 21:51:18 +02:00
if (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true") {
if ($action == "add" && permission_exists('phrase_add')) {
2019-08-12 12:34:48 +02:00
//build data array
$phrase_uuid = uuid();
2019-08-12 12:34:48 +02:00
$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;
2015-03-10 01:47:42 +01:00
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();
2019-08-12 12:34:48 +02:00
$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'];
2023-06-08 21:51:18 +02:00
$array['phrase_details'][0]['phrase_detail_pattern'] = $_POST['phrase_detail_pattern'] ?? null;
2019-08-12 12:34:48 +02:00
$array['phrase_details'][0]['phrase_detail_function'] = $_POST['phrase_detail_function'];
$array['phrase_details'][0]['phrase_detail_data'] = $_POST['phrase_detail_data'];
2023-06-08 21:51:18 +02:00
$array['phrase_details'][0]['phrase_detail_method'] = $_POST['phrase_detail_method'] ?? null;
$array['phrase_details'][0]['phrase_detail_type'] = $_POST['phrase_detail_type'] ?? null;
2019-08-12 12:34:48 +02:00
$array['phrase_details'][0]['phrase_detail_group'] = $_POST['phrase_detail_group'];
}
}
2019-08-12 12:34:48 +02:00
//execute insert
2024-11-29 21:57:01 +01:00
$p = permissions::new();
2019-08-12 12:34:48 +02:00
$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();
2019-02-05 18:37:30 +01:00
//clear the cache
$cache = new cache;
2020-03-12 17:41:10 +01:00
$cache->delete("languages:".$phrase_language.".".$phrase_uuid);
//clear the destinations session array
if (isset($_SESSION['destinations']['array'])) {
unset($_SESSION['destinations']['array']);
}
//send a redirect
2018-08-31 05:09:01 +02:00
message::add($text['message-add']);
header("Location: phrase_edit.php?id=".$phrase_uuid);
2019-08-12 12:34:48 +02:00
exit;
}
//update the phrase
if ($action == "update" && permission_exists('phrase_edit')) {
2019-08-12 12:34:48 +02:00
//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();
2019-08-12 12:34:48 +02:00
$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'];
2023-06-08 21:51:18 +02:00
$array['phrase_details'][0]['phrase_detail_pattern'] = $_POST['phrase_detail_pattern'] ?? null;
2019-08-12 12:34:48 +02:00
$array['phrase_details'][0]['phrase_detail_function'] = $_POST['phrase_detail_function'];
$array['phrase_details'][0]['phrase_detail_data'] = $_POST['phrase_detail_data'];
2023-06-08 21:51:18 +02:00
$array['phrase_details'][0]['phrase_detail_method'] = $_POST['phrase_detail_method'] ?? null;
$array['phrase_details'][0]['phrase_detail_type'] = $_POST['phrase_detail_type'] ?? null;
2019-08-12 12:34:48 +02:00
$array['phrase_details'][0]['phrase_detail_group'] = $_POST['phrase_detail_group'];
}
}
2019-08-12 12:34:48 +02:00
//execute update/insert
2024-11-29 21:57:01 +01:00
$p = permissions::new();
2019-08-12 12:34:48 +02:00
$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);
}
2019-02-06 02:37:52 +01:00
//clear the cache
$cache = new cache;
2020-03-12 17:41:10 +01:00
$cache->delete("languages:".$phrase_language.".".$phrase_uuid);
//clear the destinations session array
if (isset($_SESSION['destinations']['array'])) {
unset($_SESSION['destinations']['array']);
}
//send a redirect
2018-08-31 05:09:01 +02:00
message::add($text['message-update']);
header("Location: phrase_edit.php?id=".$phrase_uuid);
2019-08-12 12:34:48 +02:00
exit;;
2019-08-12 12:34:48 +02:00
}
2019-08-12 12:34:48 +02:00
}
2019-08-12 12:34:48 +02:00
}
//pre-populate the form
if (count($_GET)>0 && empty($_POST["persistformvar"])) {
2019-08-12 12:34:48 +02:00
$phrase_uuid = $_GET["id"];
$sql = "select * from v_phrases ";
$sql .= "where ( ";
2019-08-12 12:34:48 +02:00
$sql .= " domain_uuid = :domain_uuid or ";
$sql .= " domain_uuid is null ";
$sql .= ") ";
2019-08-12 12:34:48 +02:00
$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"];
}
2019-08-12 12:34:48 +02:00
unset($sql, $parameters, $row);
}
Set default for enabled (#6556) * Set default for enabled * Update conference_profile_edit.php * Update call_block_edit.php * Update conference_control_edit.php * Update conference_control_detail_edit.php * Update conference_profile_edit.php * Update conference_profile_param_edit.php * Update conference_edit.php * Update destination_edit.php * Update device_edit.php * Update device_profile_edit.php * Update device_vendor_edit.php * Update email_template_edit.php * Update extension_edit.php * Update module_edit.php * Update phrase_edit.php * Update ring_group_edit.php * Update sip_profile_edit.php * Update stream_edit.php * Update time_condition_edit.php * Update var_edit.php * Update voicemail_edit.php * Update call_block_edit.php * Update default_setting_edit.php * Update domain_setting_edit.php * Update domain_edit.php * Update user_edit.php * Update bridge_edit.php * Update sip_profile_edit.php * Update sofia_global_setting_edit.php * Update call_flow_edit.php * Update email_template_edit.php * Update call_flow_edit.php * Update bridge_edit.php * Update email_template_edit.php * Update sip_profile_edit.php * Update sofia_global_setting_edit.php * Update bridge_edit.php * Update call_flow_edit.php * Update conference_control_edit.php * Update sip_profile_edit.php * Update stream_edit.php * Update default_setting_edit.php * Update email_template_edit.php * Update extension_setting_edit.php * Update default_setting_edit.php * Update dashboard_edit.php * Update dashboard_edit.php * Update default_setting_edit.php
2023-02-17 22:21:41 +01:00
//set the defaults
if (empty($phrase_enabled)) { $phrase_enabled = 'true'; }
Set default for enabled (#6556) * Set default for enabled * Update conference_profile_edit.php * Update call_block_edit.php * Update conference_control_edit.php * Update conference_control_detail_edit.php * Update conference_profile_edit.php * Update conference_profile_param_edit.php * Update conference_edit.php * Update destination_edit.php * Update device_edit.php * Update device_profile_edit.php * Update device_vendor_edit.php * Update email_template_edit.php * Update extension_edit.php * Update module_edit.php * Update phrase_edit.php * Update ring_group_edit.php * Update sip_profile_edit.php * Update stream_edit.php * Update time_condition_edit.php * Update var_edit.php * Update voicemail_edit.php * Update call_block_edit.php * Update default_setting_edit.php * Update domain_setting_edit.php * Update domain_edit.php * Update user_edit.php * Update bridge_edit.php * Update sip_profile_edit.php * Update sofia_global_setting_edit.php * Update call_flow_edit.php * Update email_template_edit.php * Update call_flow_edit.php * Update bridge_edit.php * Update email_template_edit.php * Update sip_profile_edit.php * Update sofia_global_setting_edit.php * Update bridge_edit.php * Update call_flow_edit.php * Update conference_control_edit.php * Update sip_profile_edit.php * Update stream_edit.php * Update default_setting_edit.php * Update email_template_edit.php * Update extension_setting_edit.php * Update default_setting_edit.php * Update dashboard_edit.php * Update dashboard_edit.php * Update default_setting_edit.php
2023-02-17 22:21:41 +01:00
2016-08-13 21:28:44 +02:00
//get the phrase details
if (!empty($phrase_uuid)) {
2016-08-13 21:28:44 +02:00
$sql = "select * from v_phrase_details ";
2019-08-12 12:34:48 +02:00
$sql .= "where domain_uuid = :domain_uuid ";
$sql .= "and phrase_uuid = :phrase_uuid ";
2016-08-13 21:28:44 +02:00
$sql .= "order by phrase_detail_order asc ";
2019-08-12 12:34:48 +02:00
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$parameters['phrase_uuid'] = $phrase_uuid;
$database = new database;
$phrase_details = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
2016-08-13 21:28:44 +02:00
}
2021-03-10 08:01:18 +01:00
//get the recording names from the database.
$sql = "select recording_name, recording_filename from v_recordings ";
2019-08-12 12:34:48 +02:00
$sql .= "where domain_uuid = :domain_uuid ";
2016-08-13 21:28:44 +02:00
$sql .= "order by recording_name asc ";
2019-08-12 12:34:48 +02:00
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$recordings = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
2016-08-13 21:28:44 +02:00
2019-09-19 14:45:47 +02:00
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
2020-02-06 03:48:43 +01:00
//include the header
if ($action == 'add') { $document['title'] = $text['title-add_phrase']; }
if ($action == 'update') { $document['title'] = $text['title-edit_phrase']; }
2020-02-06 03:48:43 +01:00
require_once "resources/header.php";
//js to control action form input
echo "<script type='text/javascript'>\n";
echo "function load_action_options(selected_index) {\n";
echo " var obj_action = document.getElementById('phrase_detail_data');\n";
echo " if (selected_index == 0 || selected_index == 1) {\n";
echo " if (obj_action.type == 'text') {\n";
echo " action_to_select();\n";
echo " var obj_action = document.getElementById('phrase_detail_data');\n";
echo " obj_action.setAttribute('style', 'width: 300px; min-width: 300px; max-width: 300px;');\n";
echo " }\n";
echo " else {\n";
echo " clear_action_options();\n";
echo " }\n";
echo " }\n";
if (if_group("superadmin")) {
echo " else {\n";
echo " document.getElementById('phrase_detail_data_switch').style.display='none';\n";
echo " obj_action.setAttribute('style', 'width: 300px; min-width: 300px; max-width: 300px;');\n";
echo " }\n";
}
echo " if (selected_index == 0) {\n"; //play
echo " obj_action.options[obj_action.options.length] = new Option('', '');\n"; //blank option
//recordings
$tmp_selected = false;
2019-08-12 12:34:48 +02:00
if (is_array($recordings) && @sizeof($recordings) != 0) {
echo "var opt_group = document.createElement('optgroup');\n";
echo "opt_group.label = \"".$text['label-recordings']."\";\n";
foreach ($recordings as $row) {
2023-06-08 21:51:18 +02:00
if (!empty($_SESSION['recordings']['storage_type']['text']) && $_SESSION['recordings']['storage_type']['text'] == 'base64') {
echo "opt_group.appendChild(new Option(\"".$row["recording_name"]."\", \"\${lua streamfile.lua ".$row["recording_filename"]."}\"));\n";
}
else {
echo "opt_group.appendChild(new Option(\"".$row["recording_name"]."\", \"".$_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row["recording_filename"]."\"));\n";
}
}
echo "obj_action.appendChild(opt_group);\n";
}
2019-08-12 12:34:48 +02:00
unset($recordings, $row);
//sounds
2016-08-13 21:28:44 +02:00
$file = new file;
$sound_files = $file->sounds();
2019-08-12 12:34:48 +02:00
if (is_array($sound_files) && @sizeof($sound_files) != 0) {
echo "var opt_group = document.createElement('optgroup');\n";
echo "opt_group.label = \"".$text['label-sounds']."\";\n";
2016-08-13 21:28:44 +02:00
foreach ($sound_files as $value) {
if (!empty($value)) {
2019-08-12 12:34:48 +02:00
echo "opt_group.appendChild(new Option(\"".$value."\", \"".$value."\"));\n";
}
}
echo "obj_action.appendChild(opt_group);\n";
}
2019-08-12 12:34:48 +02:00
unset($sound_files, $row);
echo " }\n";
echo " else if (selected_index == 1) {\n"; //pause
echo " obj_action.options[obj_action.options.length] = new Option('', '');\n"; //blank option
for ($s = 0.1; $s <= 5; $s = $s + 0.1) {
2019-08-12 12:34:48 +02:00
echo " obj_action.options[obj_action.options.length] = new Option('".number_format($s, 1)."s', 'sleep(".($s * 1000).")');\n";
}
echo " }\n";
if (if_group("superadmin")) {
echo " else if (selected_index == 2) {\n"; //execute
echo " action_to_input();\n";
echo " }\n";
}
echo "}\n";
echo "function clear_action_options() {\n";
echo " var len, groups, par;\n";
echo " sel = document.getElementById('phrase_detail_data');\n";
echo " groups = sel.getElementsByTagName('optgroup');\n";
echo " len = groups.length;\n";
echo " for (var i=len; i; i--) {\n";
echo " sel.removeChild( groups[i-1] );\n";
echo " }\n";
echo " len = sel.options.length;\n";
echo " for (var i=len; i; i--) {\n";
echo " par = sel.options[i-1].parentNode;\n";
echo " par.removeChild( sel.options[i-1] );\n";
echo " }\n";
echo "}\n";
if (if_group("superadmin")) {
echo "function action_to_input() {\n";
echo " obj = document.getElementById('phrase_detail_data');\n";
echo " tb = document.createElement('INPUT');\n";
echo " tb.type = 'text';\n";
echo " tb.name = obj.name;\n";
echo " tb.id = obj.id;\n";
echo " tb.value = obj.options[obj.selectedIndex].value;\n";
echo " tb.className = 'formfld';\n";
echo " tb_width = (document.getElementById('phrase_detail_function').selectedIndex == 2) ? '300px' : '267px';\n";
echo " tb.setAttribute('style', 'width: '+tb_width+'; min-width: '+tb_width+'; max-width: '+tb_width+';');\n";
echo " obj.parentNode.insertBefore(tb, obj);\n";
echo " obj.parentNode.removeChild(obj);\n";
echo " if (document.getElementById('phrase_detail_function').selectedIndex != 2) {\n";
echo " tb.setAttribute('style', 'width: 263px; min-width: 263px; max-width: 263px;');\n";
echo " document.getElementById('phrase_detail_data_switch').style.display='';\n";
echo " }\n";
echo " else {\n";
echo " tb.focus();\n";
echo " }\n";
echo "}\n";
echo "function action_to_select() {\n";
echo " obj = document.getElementById('phrase_detail_data');\n";
echo " sb = document.createElement('SELECT');\n";
echo " sb.name = obj.name;\n";
echo " sb.id = obj.id;\n";
echo " sb.className = 'formfld';\n";
echo " sb.setAttribute('style', 'width: 300px; min-width: 300px; max-width: 300px;');\n";
echo " sb.setAttribute('onchange', 'action_to_input();');\n";
echo " obj.parentNode.insertBefore(sb, obj);\n";
echo " obj.parentNode.removeChild(obj);\n";
echo " document.getElementById('phrase_detail_data_switch').style.display='none';\n";
echo " clear_action_options();\n";
echo "}\n";
}
echo "</script>\n";
//show the content
echo "<form method='post' name='frm' id='frm'>\n";
2020-02-06 03:48:43 +01:00
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'>";
if ($action == "add") {
echo "<b>".$text['title-add_phrase']."</b>";
}
if ($action == "update") {
echo "<b>".$text['title-edit_phrase']."</b>";
}
echo " </div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','link'=>'phrases.php']);
2020-03-26 20:45:34 +01:00
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;']);
2020-02-06 03:48:43 +01:00
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
2020-03-26 20:45:34 +01:00
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 "<div class='card'>\n";
2020-02-06 03:48:43 +01:00
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
2020-02-06 03:48:43 +01:00
echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap>\n";
echo " ".$text['label-name']."\n";
echo "</td>\n";
2020-02-06 03:48:43 +01:00
echo "<td width='70%' class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='phrase_name' maxlength='255' value=\"".escape($phrase_name)."\">\n";
echo " <br />\n";
echo " ".$text['description-name']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
echo " ".$text['label-language']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='phrase_language' maxlength='255' value=\"".escape($phrase_language)."\">\n";
echo " <br />\n";
echo " ".$text['description-language']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>";
echo "<td class='vncell' valign='top'>".$text['label-structure']."</td>";
echo "<td class='vtable' align='left'>";
echo " <table border='0' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
2020-02-06 03:48:43 +01:00
echo " <td class='vtable'><strong>".$text['label-function']."</strong></td>\n";
echo " <td class='vtable'><strong>".$text['label-action']."</strong></td>\n";
echo " <td class='vtable' style='text-align: center;'><strong>".$text['label-order']."</strong></td>\n";
if (!empty($phrase_details)) {
echo " <td class='vtable edit_delete_checkbox_all' onmouseover=\"swap_display('delete_label_details', 'delete_toggle_details');\" onmouseout=\"swap_display('delete_label_details', 'delete_toggle_details');\">\n";
echo " <span id='delete_label_details'>".$text['label-delete']."</span>\n";
echo " <span id='delete_toggle_details'><input type='checkbox' id='checkbox_all_details' name='checkbox_all' onclick=\"edit_all_toggle('details');\"></span>\n";
echo " </td>\n";
}
echo " </tr>\n";
if (!empty($phrase_details)) {
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 ') {
2016-08-13 21:28:44 +02:00
$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);
}
2019-08-12 12:34:48 +02:00
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
}
2019-08-12 12:34:48 +02:00
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']);
}
2016-08-13 21:28:44 +02:00
else {
$phrase_detail_function = $field['phrase_detail_function'];
$phrase_detail_data = $field['phrase_detail_data'];
}
echo "<tr>\n";
2018-06-13 08:13:12 +02:00
echo " <td class='vtable'>".escape($phrase_detail_function)."&nbsp;</td>\n";
echo " <td class='vtable'>".escape($phrase_detail_data)."&nbsp;</td>\n";
echo " <td class='vtable' style='text-align: center;'>".$field['phrase_detail_order']."&nbsp;</td>\n";
echo " <td class='vtable' style='text-align: center; padding-bottom: 3px;'>";
if (is_uuid($field['phrase_detail_uuid'])) {
echo " <input type='checkbox' name='phrase_details_delete[".$x."][checked]' value='true' class='chk_delete checkbox_details' onclick=\"edit_delete_action('details');\">\n";
echo " <input type='hidden' name='phrase_details_delete[".$x."][uuid]' value='".escape($field['phrase_detail_uuid'])."' />\n";
}
echo " </td>\n";
echo "</tr>\n";
}
}
2019-08-12 12:34:48 +02:00
unset($phrase_details, $field);
echo "<tr>\n";
echo " <td class='vtable' style='border-bottom: none;' align='left' nowrap='nowrap'>\n";
echo " <select name='phrase_detail_function' id='phrase_detail_function' class='formfld' onchange=\"load_action_options(this.selectedIndex);\">\n";
2016-08-13 21:28:44 +02:00
echo " <option value='play-file'>".$text['label-play']."</option>\n";
echo " <option value='execute'>".$text['label-pause']."</option>\n";
if (if_group("superadmin")) {
2016-08-13 21:28:44 +02:00
echo " <option value='execute'>".$text['label-execute']."</option>\n";
}
echo " </select>\n";
echo " </td>\n";
echo " <td class='vtable' style='border-bottom: none;' align='left' nowrap='nowrap'>\n";
echo " <select name='phrase_detail_data' id='phrase_detail_data' class='formfld' style='width: 300px; min-width: 300px; max-width: 300px;' ".((if_group("superadmin")) ? "onchange='action_to_input();'" : null)."></select>";
if (if_group("superadmin")) {
echo " <input id='phrase_detail_data_switch' type='button' class='btn' style='margin-left: 4px; display: none;' value='&#9665;' onclick=\"action_to_select(); load_action_options(document.getElementById('phrase_detail_function').selectedIndex);\">\n";
}
echo " <script>load_action_options(0);</script>\n";
echo " </td>\n";
echo " <td class='vtable' style='border-bottom: none;'>\n";
echo " <select name='phrase_detail_order' class='formfld'>\n";
for ($i = 0; $i <= 999; $i++) {
$i_padded = str_pad($i, 3, '0', STR_PAD_LEFT);
2018-06-13 08:13:12 +02:00
echo " <option value='".escape($i_padded)."'>".escape($i_padded)."</option>\n";
}
echo " </select>\n";
echo " </td>\n";
echo " <td>\n";
2020-02-07 14:52:58 +01:00
echo button::create(['type'=>'submit','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add']]);
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo " ".$text['description-structure']."\n";
echo " <br />\n";
echo "</td>";
echo "</tr>";
if (permission_exists('phrase_domain')) {
echo "<tr>\n";
echo "<td class='vncell' valign='top' nowrap='nowrap'>\n";
echo " ".$text['label-domain']."\n";
echo "</td>\n";
echo "<td class='vtable'>\n";
echo " <select name='domain_uuid' class='formfld'>\n";
if (empty($domain_uuid)) {
echo " <option value='' selected='selected'>".$text['label-global']."</option>\n";
}
else {
echo " <option value=''>".$text['label-global']."</option>\n";
}
foreach ($_SESSION['domains'] as $row) {
if ($row['domain_uuid'] == $domain_uuid) {
2018-06-13 08:13:12 +02:00
echo " <option value='".escape($row['domain_uuid'])."' selected='selected'>".escape($row['domain_name'])."</option>\n";
}
else {
2018-06-13 08:13:12 +02:00
echo " <option value='".escape($row['domain_uuid'])."'>".escape($row['domain_name'])."</option>\n";
}
}
echo " </select>\n";
echo "</td>\n";
echo "</tr>\n";
}
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
if (substr($_SESSION['theme']['input_toggle_style']['text'], 0, 6) == 'switch') {
echo " <label class='switch'>\n";
echo " <input type='checkbox' id='phrase_enabled' name='phrase_enabled' value='true' ".($phrase_enabled == 'true' ? "checked='checked'" : null).">\n";
echo " <span class='slider'></span>\n";
echo " </label>\n";
}
else {
echo " <select class='formfld' id='phrase_enabled' name='phrase_enabled'>\n";
echo " <option value='true' ".($phrase_enabled == 'true' ? "selected='selected'" : null).">".$text['option-true']."</option>\n";
echo " <option value='false' ".($phrase_enabled == 'false' ? "selected='selected'" : null).">".$text['option-false']."</option>\n";
echo " </select>\n";
}
echo " <br />\n";
echo $text['description-enabled']."\n";
echo "</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncell' valign='top' align='left' nowrap>\n";
echo " ".$text['label-description']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <input class='formfld' type='text' name='phrase_description' maxlength='255' value=\"".escape($phrase_description)."\">\n";
echo "</td>\n";
echo "</tr>\n";
2020-02-06 03:48:43 +01:00
echo "</table>";
echo "</div>\n";
2020-02-06 03:48:43 +01:00
echo "<br><br>";
if ($action == "update") {
2018-06-13 08:13:12 +02:00
echo " <input type='hidden' name='phrase_uuid' value='".escape($phrase_uuid)."'>\n";
}
2020-02-06 03:48:43 +01:00
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>";
//include the footer
require_once "resources/footer.php";
2016-08-13 21:28:44 +02:00
2020-03-12 17:41:10 +01:00
?>