From 82893cbd57e277ba49a4a33fc2c4f8321866d5ba Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 4 Mar 2020 07:45:40 -0700 Subject: [PATCH] Phrases - Edit: Add bulk delete of Details, dynamic delete button action. Remove deprecated Detail delete script. --- app/phrases/phrase_detail_delete.php | 86 ----------------------- app/phrases/phrase_edit.php | 60 +++++++++++++--- app/phrases/resources/classes/phrases.php | 82 +++++++++++++++++++++ 3 files changed, 133 insertions(+), 95 deletions(-) delete mode 100644 app/phrases/phrase_detail_delete.php diff --git a/app/phrases/phrase_detail_delete.php b/app/phrases/phrase_detail_delete.php deleted file mode 100644 index e244990bab..0000000000 --- a/app/phrases/phrase_detail_delete.php +++ /dev/null @@ -1,86 +0,0 @@ - - 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_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; - -?> diff --git a/app/phrases/phrase_edit.php b/app/phrases/phrase_edit.php index 6dafe8a059..14f2a5db2b 100644 --- a/app/phrases/phrase_edit.php +++ b/app/phrases/phrase_edit.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - 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 " \n"; echo "
\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 "
\n"; echo "
\n"; @@ -436,15 +470,20 @@ echo ""; echo "".$text['label-structure'].""; echo ""; - echo " \n"; + echo "
\n"; 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 $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 " \n"; echo " \n"; echo " \n"; - echo " \n"; echo "\n"; } } unset($phrase_details, $field); 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']." "; - echo "".$v_link_label_delete.""; + echo " "; + if (is_uuid($field['phrase_detail_uuid'])) { + echo " \n"; + echo " \n"; + } echo "
\n"; + echo " \n"; echo " \n"; echo " \n"; + echo " \n"; echo " "; if (if_group("superadmin")) { echo " \n"; } echo " \n"; echo " \n"; + echo " \n"; echo "