fusionpbx/app/phrases/phrase_edit.php

624 lines
23 KiB
PHP
Raw 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
2024-11-23 15:59:28 +01:00
require_once dirname(__DIR__, 2) . "/resources/require.php";
require_once "resources/check_auth.php";
//check permissions
2024-11-23 15:59:28 +01:00
if (permission_exists('phrase_add') || permission_exists('phrase_edit')) {
//access granted
}
else {
echo "access denied";
exit;
}
function build_data_array_from_post(settings $settings) {
global $domain_uuid, $drop_rows;
$phrase_uuid = $_POST['phrase_uuid'];
2024-11-26 02:16:32 +01:00
$array = [];
$drop_rows = [];
$drop_row_count = 0;
//load sound files from the switch so we can validate selections
$sound_files = (new file)->sounds();
2024-11-26 02:16:32 +01:00
//update the phrase information
$array['phrases'][0]['domain_uuid'] = $domain_uuid;
$array['phrases'][0]['phrase_uuid'] = $phrase_uuid;
$array['phrases'][0]['phrase_name'] = $_POST['phrase_name'];
$array['phrases'][0]['phrase_language'] = $_POST['phrase_language'];
$array['phrases'][0]['phrase_enabled'] = $_POST['phrase_enabled'];
$array['phrases'][0]['phrase_description'] = $_POST['phrase_description'];
//recording_files are:
// 'recording_uuid' => 'recording.wav'
// OR
// 'recording_uuid' => '${lua streamfile.lua ' . base64_data .'}'
$recording_files = phrases::get_all_domain_recordings($settings);
//
// Create two arrays - one for rows to delete and one for new/updated rows
//
2024-11-26 02:16:32 +01:00
for ($i = 0; $i < count($_POST['phrase_detail_function']); $i++) {
//check for function to perform
$phrase_detail_function = $_POST['phrase_detail_function'][$i];
$phrase_detail_data = null;
$recording_uuid_or_file = '';
$phrase_detail_uuid = '';
//check for the empty rows to delete -- 0,false,null is valid
if (strlen($_POST['phrase_detail_data'][$i]) === 0
&& !empty($_POST['phrase_detail_uuid'][$i])
&& empty($_POST['slider'][$i])
&& empty($_POST['phrase_detail_text'][$i])) {
2024-11-26 02:16:32 +01:00
$drop_rows['phrase_details'][$drop_row_count++]['phrase_detail_uuid'] = $_POST['phrase_detail_uuid'][$i];
continue;
}
switch ($phrase_detail_function) {
case 'play-file':
//only save rows with data
if (!empty($_POST['phrase_detail_data'][$i])) {
$recording_uuid_or_file = $_POST['phrase_detail_data'][$i];
//check for valid recordings and files
if (is_uuid($recording_uuid_or_file)) {
//recording UUID
$phrase_detail_data = $recording_files[$recording_uuid_or_file];
} else {
//not a recording so must be valid path inside the switch recording files
if (in_array($recording_uuid_or_file, $sound_files)) {
//valid switch audio file
$phrase_detail_data = $recording_uuid_or_file;
} else {
//ignore an invalid audio file
continue(2);
}
}
//build data array
if ($_POST['phrase_detail_function'][$i] == 'execute' && substr($_POST['phrase_detail_data'][$i], 0,5) != "sleep" && !permission_exists("phrase_execute")) {
header("Location: phrase_edit.php?id=".$phrase_uuid);
exit;
}
}
break;
case 'pause':
//check for value
$phrase_detail_data = $_POST['slider'][$i];
break;
case 'execute':
//check for the empty rows to delete
if (empty($_POST['phrase_detail_text'][$i]) && !empty($_POST['phrase_detail_uuid'][$i])) {
$drop_rows['phrase_details'][$drop_row_count++]['phrase_detail_uuid'] = $_POST['phrase_detail_uuid'][$i];
continue(2);
}
$phrase_detail_data = $_POST['phrase_detail_text'][$i];
break;
}
2024-11-26 02:16:32 +01:00
$_POST['phrase_detail_tag'] = 'action'; // default, for now
$_POST['phrase_detail_group'] = "0"; // one group, for now
if ($phrase_detail_data !== null) {
2024-11-26 02:16:32 +01:00
if (!empty($_POST['phrase_detail_uuid'][$i])) {
//update existing records in the database
2024-11-26 02:16:32 +01:00
$phrase_detail_uuid = $_POST['phrase_detail_uuid'][$i];
} else {
//new record
2024-11-26 02:16:32 +01:00
$phrase_detail_uuid = uuid();
}
$array['phrase_details'][$i]['phrase_detail_uuid'] = $phrase_detail_uuid;
$array['phrase_details'][$i]['phrase_uuid'] = $phrase_uuid;
$array['phrase_details'][$i]['domain_uuid'] = $domain_uuid;
$array['phrase_details'][$i]['phrase_detail_order'] = $i;
$array['phrase_details'][$i]['phrase_detail_tag'] = $_POST['phrase_detail_tag'];
$array['phrase_details'][$i]['phrase_detail_pattern'] = $_POST['phrase_detail_pattern'] ?? null;
$array['phrase_details'][$i]['phrase_detail_function'] = $phrase_detail_function;
$array['phrase_details'][$i]['phrase_detail_data'] = $phrase_detail_data; //path and filename of recording
2024-11-26 02:16:32 +01:00
$array['phrase_details'][$i]['phrase_detail_method'] = $_POST['phrase_detail_method'] ?? null;
$array['phrase_details'][$i]['phrase_detail_type'] = $_POST['phrase_detail_type'] ?? null;
$array['phrase_details'][$i]['phrase_detail_group'] = $_POST['phrase_detail_group'];
}
}
return $array;
}
2024-11-24 14:08:28 +01:00
//set default domain
if (empty($domain_uuid)) {
$domain_uuid = $_SESSION['domain_uuid'] ?? '';
}
//set default user
if (empty($user_uuid)) {
$user_uuid = $_SESSION['user_uuid'] ?? '';
}
//add multi-lingual support
2024-11-23 15:59:28 +01:00
$language = new text;
$text = $language->get();
//ensure we have a database object
2024-11-23 15:59:28 +01:00
if (!($database instanceof database)) {
$database = database::new();
}
2024-11-24 14:08:28 +01:00
//ensure we have a settings object
if (!($settings instanceof settings)) {
$settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]);
}
//add the defaults
2024-11-23 15:59:28 +01:00
$phrase_name = '';
$phrase_language = '';
$phrase_description = '';
//set the action as an add or an update
2024-11-23 15:59:28 +01:00
if (!empty($_REQUEST["id"])) {
$action = "update";
$phrase_uuid = $_REQUEST["id"];
}
else {
$action = "add";
}
//get the form value and set to php variables
2024-11-23 15:59:28 +01:00
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;
}
2024-11-23 15:59:28 +01:00
header('Location: phrases.php');
exit;
}
2024-11-23 15:59:28 +01:00
if (permission_exists('phrase_domain')) {
$domain_uuid = $_POST["domain_uuid"];
}
2024-11-23 15:59:28 +01:00
$phrase_name = $_POST["phrase_name"];
$phrase_language = $_POST["phrase_language"];
$phrase_enabled = $_POST["phrase_enabled"] ?? 'false';
$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
2024-11-23 15:59:28 +01:00
if ($action == "update") {
$phrase_uuid = $_POST["phrase_uuid"];
}
2019-09-19 14:45:47 +02:00
//validate the token
2024-11-23 15:59:28 +01:00
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: phrases.php');
exit;
}
2019-09-19 14:45:47 +02:00
//check for all required data
2024-11-23 15:59:28 +01:00
$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
2024-11-23 15:59:28 +01:00
if (empty($_POST["persistformvar"]) || $_POST["persistformvar"] != "true") {
2024-11-26 02:16:32 +01:00
$message = '';
switch ($action) {
case 'add':
//redirect when they don't have permission to add a phrase
if (!permission_exists('phrase_add')) {
header('Location: phrases.php');
exit();
2024-11-23 15:59:28 +01:00
}
2024-11-26 02:16:32 +01:00
//set user feedback message to add
$message = $text['message-add'];
$phrase_uuid = uuid();
//do not break
case 'update':
//redirect when not adding and don't have permission to edit a phrase
if (empty($message)) {
if (!permission_exists('phrase_edit')) {
header('Location: phrases.php');
exit();
2024-11-23 15:59:28 +01:00
}
2024-11-26 02:16:32 +01:00
//set user feedback message to update
$message = $text['message-update'];
}
if (!empty($_POST['phrase_detail_function'])) {
$array = build_data_array_from_post($settings);
2024-11-23 15:59:28 +01:00
}
//execute update/insert
$p = permissions::new();
2024-11-23 15:59:28 +01:00
$p->add('phrase_detail_add', 'temp');
2024-11-25 22:19:15 +01:00
$p->add('phrase_detail_edit', 'temp');
$p->add('phrase_detail_delete', 'temp');
2024-11-23 15:59:28 +01:00
$database->app_name = 'phrases';
$database->app_uuid = '5c6f597c-9b78-11e4-89d3-123b93f75cba';
if (count($array) > 0) {
$database->save($array);
unset($array);
2024-11-25 22:19:15 +01:00
}
if (count($drop_rows) > 0) {
$database->delete($drop_rows);
unset($drop_rows);
2024-11-23 15:59:28 +01:00
}
2024-11-25 22:19:15 +01:00
$p->delete('phrase_detail_add', 'temp');
2024-11-26 02:16:32 +01:00
//clear the cache
$cache = new cache;
$cache->delete("languages:".$phrase_language.".".$phrase_uuid);
2024-11-26 02:16:32 +01:00
//clear the destinations session array
if (isset($_SESSION['destinations']['array'])) {
unset($_SESSION['destinations']['array']);
}
2024-11-26 02:16:32 +01:00
//send a redirect
message::add($message);
header("Location: phrase_edit.php?id=".$phrase_uuid);
exit;
2019-08-12 12:34:48 +02:00
}
2024-11-23 15:59:28 +01: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;
$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;
$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_uuid, recording_name, recording_filename, domain_uuid 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'];
$recordings = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
2016-08-13 21:28:44 +02:00
2024-12-02 19:16:48 +01:00
//get the switch sound files
$file = new file;
$sound_files = $file->sounds();
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";
//javascript constants for use in the selection option group
echo "<script>\n";
2024-12-03 00:06:53 +01:00
echo "window.permission_execute = " . (permission_exists('phrase_execute') ? 'true' : 'false') . ";\n";
2024-12-02 22:33:52 +01:00
echo "window.phrase_label_sounds = '" . ($text['label-sounds'] ?? 'Sounds') . "';\n";
echo "window.phrase_label_recordings = '" . ($text['label-recordings'] ?? 'Recordings') . "';\n";
2024-12-03 00:06:53 +01:00
//only include permissive actions
$phrase_commands = [];
if (permission_exists('phrase_play')) {
$phrase_commands[] = $text['label-play'] ?? 'Play';
$phrase_commands[] = $text['label-pause'] ?? 'Pause';
}
if (permission_exists('phrase_execute')) {
$phrase_commands[] = $text['label-execute'] ?? 'Execute';
}
echo "window.phrase_commands = " . json_encode($phrase_commands, true) . ";\n";
2024-11-24 14:08:28 +01:00
//existing details
if (!empty($phrase_details)) {
2024-12-02 19:16:48 +01:00
//update the array to include the recording name for display in select box
2024-11-24 14:08:28 +01:00
foreach ($phrase_details as &$row) {
2024-12-02 19:16:48 +01:00
$row['display_name'] = '';
2024-11-24 14:08:28 +01:00
$file = basename($row['phrase_detail_data']);
2024-12-02 19:16:48 +01:00
//get the display_name from recording name based on the file matched
foreach ($recordings as $key => $recordings_row) {
//match on filename first and then domain_uuid
if ($recordings_row['recording_filename'] === $file && $recordings_row['domain_uuid'] === $row['domain_uuid']) {
2024-12-02 19:16:48 +01:00
$row['display_name'] = $recordings[$key]['recording_name'];
break;
}
}
2024-12-02 19:16:48 +01:00
//check if display_name was not found in the recording names
if (strlen($row['display_name']) === 0) {
//try finding display_name in the switch sound files
if (!empty($sound_files)) {
//use optimized php function with strict comparison
$i = array_search($row['phrase_detail_data'], $sound_files, true);
//if found in the switch sound files
if ($i !== false) {
//set the display_name to the switch sound file name
$row['display_name'] = $sound_files[$i];
}
}
2024-11-24 14:08:28 +01:00
}
}
2024-12-02 19:16:48 +01:00
//send the phrase details to the browser as a global scope json array object
2024-12-13 21:13:04 +01:00
//echo "window.phrase_details = " . json_encode($phrase_details, true) . ";\n";
2024-11-25 22:19:15 +01:00
} else {
2024-12-02 19:16:48 +01:00
//send an empty array to the browser as a global scope json array object
2024-12-13 21:13:04 +01:00
//echo "window.phrase_details = [];\n";
2024-11-24 14:08:28 +01:00
}
//recording files
if ($recordings !== false) {
2024-12-02 19:16:48 +01:00
//send recordings to the browser as a global scope json array object
echo "window.phrase_recordings = " . json_encode($recordings, true) . ";\n";
2024-11-25 22:19:15 +01:00
} else {
//send an empty array
echo "window.phrase_recordings = [];\n";
}
if (!empty($sound_files)) {
2024-12-02 19:16:48 +01:00
//send sounds to the browser as a global scope json array object
echo "window.phrase_sounds = " . json_encode($sound_files, true) . ";\n";
}
echo "</script>\n";
2024-12-02 19:16:48 +01:00
//javascript to control action form input using drag and drop
echo "<script src='resources/javascript/phrase_edit.js'></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','onclick'=>'submit_phrase()','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";
//structure row
echo "<tr>";
echo "<td class='vncell' valign='top'>".$text['label-structure']."</td>";
echo "<td class='vtable' align='left'>";
2024-11-22 19:20:39 +01:00
//style for dragging rows
echo " <link rel=stylesheet href='resources/styles/phrase_edit.css' />";
//structure table
echo " <table border='0' cellpadding='0' cellspacing='0' id='phrases_table'>\n";
//headings
echo " <thead>\n";
echo " <tr>\n";
echo " <td class='vtable'><strong>" . ($text['label-order'] ?? 'Order') . "</strong></td>\n";
2020-02-06 03:48:43 +01:00
echo " <td class='vtable'><strong>".$text['label-action']."</strong></td>\n";
echo " <td class='vtable'><strong>".($text['label-recording'] ?? 'Recording')."</strong></td>\n";
echo " </tr>\n";
echo " </thead>\n";
//draggable rows are initially empty
echo "<tbody id='structure'>\n";
echo "</tbody>";
//show loading
echo "<tbody id='loading'><tr><td>&nbsp;</td><td><center>Loading...</center></td><td>&nbsp;</td></tr></tbody>\n";
//cloning row and buttons created outside of 'structure' table body
echo "<tbody>";
echo "<tr id='empty_row' style='display: none;'>\n";
2024-11-22 19:20:39 +01:00
echo " <td style='border-bottom: none;' nowrap='nowrap'><center><span class='fa-solid fa-arrows-up-down'></span></center></td>";
echo " <td class='vtable' style='border-bottom: none;' align='left' nowrap='nowrap'>\n";
2024-11-25 22:19:15 +01:00
echo " <select class='formfld' name='phrase_detail_function_empty' id='phrase_detail_function_empty' tag=''>\n";
2016-08-13 21:28:44 +02:00
echo " <option value='play-file'>".$text['label-play']."</option>\n";
echo " <option value='pause'>".$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 class='formfld' id='phrase_detail_data_empty' name='phrase_detail_data_empty' style='width: 300px; min-width: 300px; max-width: 300px;' tag=''></select>";
2024-11-25 22:19:15 +01:00
// if (if_group("superadmin")) {
// echo " <input id='phrase_detail_data_switch_empty' type='button' class='btn' style='margin-left: 4px; display: none;' value='&#9665;' onclick=\"action_to_select(); load_action_options(document.getElementById('phrase_detail_function_empty').selectedIndex);\">\n";
// }
echo " <input type=hidden name='empty_uuid' value=''>";
echo " <input class='formfld' type=text name='empty_phrase_detail_text' value='' style='width: 300px; min-width: 300px; max-width: 300px; display: none'>";
echo " <span style='white-space: nowrap; display: flex; align-items: center; gap: 10px;'>";
echo " <input class='form-control-range' type=range name='range' minrange='1' style='width: 250px; min-width: 250px; max-width: 250px; display: none'>";
echo " <input type='text' class='formfld' name='sleep' style='width: 40px; min-width: 40px; max-width: 40px; display: none'>";
echo " </span>";
echo " </td>\n";
echo "</tr>\n";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td class='vtable' style='align=center;' colspan='2'><center>";
echo button::create(['type'=>'button','icon'=>$_SESSION['theme']['button_icon_add'], 'label' => $text['label-add'], 'onclick' => 'add_row()']);
echo button::create(['type'=>'button','icon'=>'fa-solid fa-minus', 'label' => $text['label-delete'], 'onclick' => 'remove_row()']);
echo "</center></td>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "</tbody>\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";