mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2025-12-30 00:53:50 +00:00
Phrases - Edit: Add bulk delete of Details, dynamic delete button action. Remove deprecated Detail delete script.
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
<?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>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2019
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
*/
|
||||
//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_delete')) {
|
||||
//access granted
|
||||
}
|
||||
else {
|
||||
echo "access denied";
|
||||
exit;
|
||||
}
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
//get values
|
||||
$phrase_detail_uuid = $_GET["pdid"];
|
||||
$phrase_uuid = $_GET["pid"];
|
||||
$phrase_language = $_GET["lang"];
|
||||
|
||||
//delete the detail entry
|
||||
if (is_uuid($phrase_detail_uuid) && is_uuid($phrase_uuid)) {
|
||||
//build array
|
||||
$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;
|
||||
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('phrase_detail_delete', 'temp');
|
||||
|
||||
//execute delete
|
||||
$database = new database;
|
||||
$database->app_name = 'phrases';
|
||||
$database->app_uuid = '5c6f597c-9b78-11e4-89d3-123b93f75cba';
|
||||
$database->delete($array);
|
||||
unset($array);
|
||||
|
||||
//revoke temporary permissions
|
||||
$p->delete('phrase_detail_delete', '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);
|
||||
|
||||
//set message
|
||||
message::add($text['message-delete']);
|
||||
}
|
||||
|
||||
//redirect the user
|
||||
header('Location: phrase_edit.php?id='.$phrase_uuid);
|
||||
exit;
|
||||
|
||||
?>
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
The Initial Developer of the Original Code is
|
||||
Mark J Crane <markjcrane@fusionpbx.com>
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2019
|
||||
Portions created by the Initial Developer are Copyright (C) 2008-2020
|
||||
the Initial Developer. All Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
@@ -54,6 +54,26 @@
|
||||
|
||||
//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"];
|
||||
}
|
||||
@@ -61,6 +81,7 @@
|
||||
$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);
|
||||
@@ -199,6 +220,16 @@
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
//save the xml to the file system if the phrase directory is set
|
||||
save_phrases_xml();
|
||||
|
||||
@@ -404,6 +435,9 @@
|
||||
echo " </div>\n";
|
||||
echo " <div class='actions'>\n";
|
||||
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'link'=>'phrases.php']);
|
||||
if ($action == "update") {
|
||||
echo button::create(['type'=>'submit','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'action','value'=>'delete','style'=>'margin-left: 15px;','onclick'=>"if (!confirm('".$text['confirm-delete']."')) { this.blur(); return false; }"]);
|
||||
}
|
||||
echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'style'=>'margin-left: 15px;']);
|
||||
echo " </div>\n";
|
||||
echo " <div style='clear: both;'></div>\n";
|
||||
@@ -436,15 +470,20 @@
|
||||
echo "<tr>";
|
||||
echo "<td class='vncell' valign='top'>".$text['label-structure']."</td>";
|
||||
echo "<td class='vtable' align='left'>";
|
||||
echo " <table cellpadding='0' cellspacing='0'>\n";
|
||||
echo " <table border='0' cellpadding='0' cellspacing='0'>\n";
|
||||
echo " <tr>\n";
|
||||
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";
|
||||
echo " <td></td>\n";
|
||||
if ($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 (is_array($phrase_details) && @sizeof($phrase_details) != 0) {
|
||||
foreach($phrase_details as $field) {
|
||||
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'];
|
||||
@@ -469,15 +508,18 @@
|
||||
echo " <td class='vtable'>".escape($phrase_detail_function)." </td>\n";
|
||||
echo " <td class='vtable'>".escape($phrase_detail_data)." </td>\n";
|
||||
echo " <td class='vtable' style='text-align: center;'>".$field['phrase_detail_order']." </td>\n";
|
||||
echo " <td class='list_control_icons' style='text-align: left;'>";
|
||||
echo "<a href='phrase_detail_delete.php?pdid=".escape($field['phrase_detail_uuid'])."&pid=".escape($phrase_uuid)."&a=delete&lang=".escape($phrase_language)."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">".$v_link_label_delete."</a>";
|
||||
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";
|
||||
}
|
||||
}
|
||||
unset($phrase_details, $field);
|
||||
echo "<tr>\n";
|
||||
echo " <td class='vtable' align='left' nowrap='nowrap'>\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";
|
||||
echo " <option value='play-file'>".$text['label-play']."</option>\n";
|
||||
echo " <option value='execute'>".$text['label-pause']."</option>\n";
|
||||
@@ -486,14 +528,14 @@
|
||||
}
|
||||
echo " </select>\n";
|
||||
echo " </td>\n";
|
||||
echo " <td class='vtable' align='left' nowrap='nowrap'>\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='◁' 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'>\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);
|
||||
|
||||
@@ -40,6 +40,11 @@ if (!class_exists('phrases')) {
|
||||
private $toggle_field;
|
||||
private $toggle_values;
|
||||
|
||||
/**
|
||||
* declare public variables
|
||||
*/
|
||||
public $phrase_uuid;
|
||||
|
||||
/**
|
||||
* called when the object is created
|
||||
*/
|
||||
@@ -158,6 +163,83 @@ if (!class_exists('phrases')) {
|
||||
}
|
||||
}
|
||||
|
||||
public function delete_details($records) {
|
||||
//assign private variables
|
||||
$this->permission_prefix = 'phrase_';
|
||||
$this->list_page = 'phrase_edit.php?id='.$this->phrase_uuid;
|
||||
$this->table = 'phrase_details';
|
||||
$this->uuid_prefix = 'phrase_detail_';
|
||||
|
||||
if (permission_exists($this->permission_prefix.'edit')) {
|
||||
|
||||
//add multi-lingual support
|
||||
$language = new text;
|
||||
$text = $language->get();
|
||||
|
||||
//validate the token
|
||||
$token = new token;
|
||||
if (!$token->validate($_SERVER['PHP_SELF'])) {
|
||||
message::add($text['message-invalid_token'],'negative');
|
||||
header('Location: '.$this->list_page);
|
||||
exit;
|
||||
}
|
||||
|
||||
//delete multiple records
|
||||
if (is_array($records) && @sizeof($records) != 0) {
|
||||
|
||||
//filter out unchecked phrases, build the delete array
|
||||
foreach ($records as $x => $record) {
|
||||
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
|
||||
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
|
||||
$array[$this->table][$x]['phrase_uuid'] = $this->phrase_uuid;
|
||||
$array[$this->table][$x]['domain_uuid'] = $_SESSION['domain_uuid'];
|
||||
}
|
||||
}
|
||||
|
||||
//get phrase languages
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
$sql = "select phrase_language as lang from v_phrases ";
|
||||
$sql .= "where domain_uuid = :domain_uuid ";
|
||||
$sql .= "and phrase_uuid = :phrase_uuid ";
|
||||
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
|
||||
$parameters['phrase_uuid'] = $this->phrase_uuid;
|
||||
$database = new database;
|
||||
$phrase_language = $database->select($sql, $parameters, 'column');
|
||||
unset($sql, $parameters, $rows, $row);
|
||||
}
|
||||
|
||||
//delete the checked rows
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
|
||||
//grant temporary permissions
|
||||
$p = new permissions;
|
||||
$p->add('phrase_detail_delete', 'temp');
|
||||
|
||||
//execute delete
|
||||
$database = new database;
|
||||
$database->app_name = $this->app_name;
|
||||
$database->app_uuid = $this->app_uuid;
|
||||
$database->delete($array);
|
||||
unset($array);
|
||||
|
||||
//revoke temporary permissions
|
||||
$p->delete('phrase_detail_delete', 'temp');
|
||||
|
||||
//save the xml
|
||||
save_phrases_xml();
|
||||
|
||||
//clear the cache
|
||||
if ($phrase_language != '') {
|
||||
$cache = new cache;
|
||||
$cache->delete("languages:".$phrase_language);
|
||||
}
|
||||
|
||||
}
|
||||
unset($records, $phrase_language);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* toggle records
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user