From 62791e4eb3cd906598f58725da9efa7c33bdacaa Mon Sep 17 00:00:00 2001 From: K-Flagman <105959875+k-flagman@users.noreply.github.com> Date: Sat, 17 May 2025 12:50:02 -0700 Subject: [PATCH] [CORE] [MENU] Feature Assign/Unassign User Groups (#7373) --- core/menu/app_languages.php | 50 ++++++++++ core/menu/menu_item_list.php | 41 +++++++- resources/app_languages.php | 26 +++++ resources/classes/menu.php | 177 +++++++++++++++++++++++++++++++++++ resources/classes/modal.php | 3 + themes/default/template.php | 13 ++- 6 files changed, 305 insertions(+), 5 deletions(-) diff --git a/core/menu/app_languages.php b/core/menu/app_languages.php index 35cd87c29e..a3d830e62f 100644 --- a/core/menu/app_languages.php +++ b/core/menu/app_languages.php @@ -1242,4 +1242,54 @@ $text['confirm-restore']['zh-cn'] = "您将要恢复此菜单上所有未受 $text['confirm-restore']['ja-jp'] = "このメニュー上のすべての保護されていない項目を復元しようとしています。"; $text['confirm-restore']['ko-kr'] = "이 메뉴에서 모든 보호되지 않은 항목을 복원하려고 합니다."; +$text['button-assign']['en-us'] = "Assign"; +$text['button-assign']['en-gb'] = "Assign"; +$text['button-assign']['ar-eg'] = "تعيين"; +$text['button-assign']['de-at'] = "Zuweisen"; +$text['button-assign']['de-ch'] = "Zuweisen"; +$text['button-assign']['de-de'] = "Zuweisen"; +$text['button-assign']['el-gr'] = "Ανάθεση"; +$text['button-assign']['es-cl'] = "Asignar"; +$text['button-assign']['es-mx'] = "Asignar"; +$text['button-assign']['fr-ca'] = "Attribuer"; +$text['button-assign']['fr-fr'] = "Attribuer"; +$text['button-assign']['he-il'] = "הקצה"; +$text['button-assign']['it-it'] = "Assegna"; +$text['button-assign']['nl-nl'] = "Toewijzen"; +$text['button-assign']['pl-pl'] = "Przypisz"; +$text['button-assign']['pt-br'] = "Atribuir"; +$text['button-assign']['pt-pt'] = "Atribuir"; +$text['button-assign']['ro-ro'] = "Atribuie"; +$text['button-assign']['ru-ru'] = "Назначить"; +$text['button-assign']['sv-se'] = "Tilldela"; +$text['button-assign']['uk-ua'] = "Призначити"; +$text['button-assign']['zh-cn'] = "分配"; +$text['button-assign']['ja-jp'] = "割り当てる"; +$text['button-assign']['ko-kr'] = "할당하다"; + +$text['button-unassign']['en-us'] = "Unassign"; +$text['button-unassign']['en-gb'] = "Unassign"; +$text['button-unassign']['ar-eg'] = "إلغاء التعيين"; +$text['button-unassign']['de-at'] = "Entfernen"; +$text['button-unassign']['de-ch'] = "Entfernen"; +$text['button-unassign']['de-de'] = "Entfernen"; +$text['button-unassign']['el-gr'] = "Αφαίρεση"; +$text['button-unassign']['es-cl'] = "Desasignar"; +$text['button-unassign']['es-mx'] = "Desasignar"; +$text['button-unassign']['fr-ca'] = "Désattribuer"; +$text['button-unassign']['fr-fr'] = "Désattribuer"; +$text['button-unassign']['he-il'] = "בטל הקצאה"; +$text['button-unassign']['it-it'] = "Disassegna"; +$text['button-unassign']['nl-nl'] = "Verwijderen"; +$text['button-unassign']['pl-pl'] = "Cofnij przypisanie"; +$text['button-unassign']['pt-br'] = "Desatribuir"; +$text['button-unassign']['pt-pt'] = "Desatribuir"; +$text['button-unassign']['ro-ro'] = "Dezafectare"; +$text['button-unassign']['ru-ru'] = "Убрать назначение"; +$text['button-unassign']['sv-se'] = "Avdela"; +$text['button-unassign']['uk-ua'] = "Скасувати призначення"; +$text['button-unassign']['zh-cn'] = "取消分配"; +$text['button-unassign']['ja-jp'] = "割り当て解除"; +$text['button-unassign']['ko-kr'] = "할당 해제"; + ?> diff --git a/core/menu/menu_item_list.php b/core/menu/menu_item_list.php index bdd8b1aee7..5ed02fb2b5 100644 --- a/core/menu/menu_item_list.php +++ b/core/menu/menu_item_list.php @@ -45,6 +45,7 @@ $action = $_POST['action']; $menu_uuid = $_POST['menu_uuid']; $menu_items = $_POST['menu_items']; + $group_uuid = $_POST['group_uuid']; } //process the http post data by action @@ -62,6 +63,18 @@ $obj->delete_items($menu_items); } break; + case 'group_items_add': + if (permission_exists('menu_item_edit')) { + $obj = new menu; + $obj->assign_items($menu_items, $menu_uuid, $group_uuid); + } + break; + case 'group_items_delete': + if (permission_exists('menu_item_delete')) { + $obj = new menu; + $obj->unassign_items($menu_items, $menu_uuid, $group_uuid); + } + break; } header('Location: menu_edit.php?id='.urlencode($menu_uuid)); @@ -159,7 +172,7 @@ echo "\n"; if (permission_exists('menu_item_edit') || permission_exists('menu_item_delete')) { echo " \n"; - echo " \n"; + echo " \n"; echo " \n"; echo " \n"; } @@ -231,6 +244,12 @@ $result = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); + //get the group list + $sql = "select group_uuid, group_name from v_groups "; + $database = new database; + $groups = $database->select($sql, $parameters, 'all'); + unset($sql, $parameters); + //create token $object = new token; $token = $object->create('/core/menu/menu_item_list.php'); @@ -243,6 +262,24 @@ echo "
\n"; echo "
".$text['header-menu_items']."
\n"; echo "
\n"; + echo " \n"; + + if (permission_exists('menu_item_add') && $result) { + echo button::create(['type'=>'button','label'=>$text['button-assign'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_group_items_add','class' => 'btn btn-default revealed','collapse'=>'hide-xs','style'=>'display: none;','onclick'=>"list_action_set('group_items_add'); list_form_submit('form_list');"]); + } + if (permission_exists('menu_item_delete') && $result) { + echo button::create(['type'=>'button','label'=>$text['button-unassign'],'icon'=>$_SESSION['theme']['button_icon_cancel'],'name'=>'btn_group_items_delete','class' => 'btn btn-default revealed','style'=>'display: none; margin-right: 35px;','collapse'=>'hide-xs','onclick'=>"modal_open('modal-delete','btn_delete');"]); + } + if (permission_exists('menu_item_delete') && $result) { + echo modal::create(['id'=>'modal-delete','type'=>'unassign', 'actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_group_items_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('group_items_delete'); list_form_submit('form_list');"])]); + } echo button::create(['type'=>'button','id'=>'action_bar_sub_button_back','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'collapse'=>'hide-xs','style'=>'margin-right: 15px; display: none;','link'=>'menu.php']); if (permission_exists('menu_item_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','collapse'=>'hide-xs','link'=>'menu_item_edit.php?id='.urlencode($menu_uuid)]); @@ -347,7 +384,7 @@ echo "\n"; if (permission_exists('menu_item_edit') || permission_exists('menu_item_delete')) { echo "\n"; - echo " \n"; + echo " \n"; echo " \n"; echo "\n"; } diff --git a/resources/app_languages.php b/resources/app_languages.php index ed191331ee..4e9a2cd4e7 100644 --- a/resources/app_languages.php +++ b/resources/app_languages.php @@ -675,6 +675,32 @@ $text['confirm-toggle']['ja-jp'] = "あなたは本当にこれをTOGGLEした $text['confirm-toggle']['ko-kr'] = "정말 토글하시겠습니까?"; $text['confirm-toggle']['ka-ge'] = "ნამდვილად გსურთ გადართვა?"; +$text['confirm-unassign']['en-us'] = "Do you really want to UNASSIGN this?"; +$text['confirm-unassign']['en-gb'] = "Do you really want to UNASSIGN this?"; +$text['confirm-unassign']['ar-eg'] = "هل تريد حقا أن تفصل هذا؟"; +$text['confirm-unassign']['de-at'] = "Wollen Sie das wirklich abmelden?"; +$text['confirm-unassign']['de-ch'] = "Wollen Sie das wirklich abmelden?"; +$text['confirm-unassign']['de-de'] = "Wollen Sie das wirklich abmelden?"; +$text['confirm-unassign']['el-gr'] = "Επιβεβαιώστε ότι επιθυμείτε να αποδεσμεύσετε"; +$text['confirm-unassign']['es-cl'] = "¿Realmente desea desasignar esto?"; +$text['confirm-unassign']['es-mx'] = "¿Realmente desea desasignar esto?"; +$text['confirm-unassign']['fr-ca'] = "Voulez-vous vraiment désassigner cela?"; +$text['confirm-unassign']['fr-fr'] = "Voulez-vous vraiment désassigner cela?"; +$text['confirm-unassign']['he-il'] = "האם אתה באמת רוצה לבטל את ההקצאה הזו?"; +$text['confirm-unassign']['it-it'] = "Vuoi veramente disassociare questo?"; +$text['confirm-unassign']['nl-nl'] = "Wil je dit echt ONTBINDEN?"; +$text['confirm-unassign']['pl-pl'] = "Czy na pewno chcesz to ODBLOKOWAĆ?"; +$text['confirm-unassign']['pt-br'] = "Deseja realmente desassociar?"; +$text['confirm-unassign']['pt-pt'] = "Deseja realmente desassociar isto?"; +$text['confirm-unassign']['ro-ro'] = "Chiar vrei să dezactivezi asta?"; +$text['confirm-unassign']['ru-ru'] = "Вы действительно хотите отменить назначение?"; +$text['confirm-unassign']['sv-se'] = "Vill du verkligen avregistrera detta?"; +$text['confirm-unassign']['uk-ua'] = "Ви дійсно бажаєте скасувати призначення?"; +$text['confirm-unassign']['tr-tr'] = "Bunu gerçekten devre dışı bırakmak istiyor musunuz?"; +$text['confirm-unassign']['zh-cn'] = "你真的要取消分配这个吗?"; +$text['confirm-unassign']['ja-jp'] = "本当にこれを解除しますか?"; +$text['confirm-unassign']['ko-kr'] = "정말로 이 할당을 해제하시겠습니까?"; + $text['button-apply']['en-us'] = "Apply"; $text['button-apply']['en-gb'] = "Apply"; $text['button-apply']['ar-eg'] = "يتقدم"; diff --git a/resources/classes/menu.php b/resources/classes/menu.php index 7a723441c1..9908827f7a 100644 --- a/resources/classes/menu.php +++ b/resources/classes/menu.php @@ -362,6 +362,183 @@ unset($sql, $parameters); } + public function assign_items($records, $menu_uuid, $group_uuid) { + //assign the variables + $this->name = 'menu_item'; + $this->table = 'menu_items'; + + if (permission_exists($this->name.'_add')) { + + //add multi-lingual support + $language = new text; + $text = $language->get(); + + //validate the token + $token = new token; + if (!$token->validate('/core/menu/menu_item_list.php')) { + message::add($text['message-invalid_token'],'negative'); + header('Location: '.$this->location); + exit; + } + + //assign multiple records + if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) { + + //define the group_name, group_uuid, menu_uuid + if (!empty($records) && @sizeof($records) != 0) { + $sql = "select group_name, group_uuid from v_groups "; + $sql .= "where group_uuid = :group_uuid "; + $parameters['group_uuid'] = $group_uuid; + $database = new database; + $group = $database->select($sql, $parameters, 'row'); + } + + //build the delete array + $x = 0; + foreach ($records as $record) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { + //build array + $uuids[] = "'".$record['uuid']."'"; + //assign menu item groups + $array['menu_item_groups'][$x]['menu_item_group_uuid'] = uuid(); + $array['menu_item_groups'][$x]['menu_uuid'] = $menu_uuid; + $array['menu_item_groups'][$x][$this->name.'_uuid'] = $record['uuid']; + $array['menu_item_groups'][$x]['group_name'] = $group['group_name']; + $array['menu_item_groups'][$x]['group_uuid'] = $group['group_uuid']; + //increment + $x++; + } + } + + unset($records); + + //exlude exist rows + if (!empty($array) && @sizeof($array) != 0) { + $sql = "select menu_uuid, menu_item_uuid, "; + $sql .= "group_uuid from v_menu_item_groups "; + $database = new database; + $menu_item_groups = $database->select($sql, null, 'all'); + $array['menu_item_groups'] = array_filter($array['menu_item_groups'], function($ar) use ($menu_item_groups) { + foreach ($menu_item_groups as $existingArrayItem) { + if ($ar['menu_uuid'] == $existingArrayItem['menu_uuid'] && $ar['menu_item_uuid'] == $existingArrayItem['menu_item_uuid'] && $ar['group_uuid'] == $existingArrayItem['group_uuid']) { + return false; + } + } + return true; + }); + unset($menu_item_groups); + } + + //add the checked rows fro group + if (!empty($array) && is_array($array) && @sizeof($array) != 0) { + //execute save + $database = new database; + $database->app_name = $this->app_name; + $database->app_uuid = $this->app_uuid; + $database->save($array); + unset($array); + //set message + message::add($text['message-add']); + } + } + } + } + + public function unassign_items($records, $menu_uuid, $group_uuid) { + //assign the variables + $this->name = 'menu_item'; + $this->table = 'menu_items'; + + if (permission_exists($this->name.'_add')) { + + //add multi-lingual support + $language = new text; + $text = $language->get(); + + //validate the token + $token = new token; + if (!$token->validate('/core/menu/menu_item_list.php')) { + message::add($text['message-invalid_token'],'negative'); + header('Location: '.$this->location); + exit; + } + + //assign multiple records + if (is_array($records) && @sizeof($records) != 0 && !empty($group_uuid)) { + + //define the group_name, group_uuid, menu_uuid + if (!empty($records) && @sizeof($records) != 0) { + $sql = "select group_name, group_uuid from v_groups "; + $sql .= "where group_uuid = :group_uuid "; + $parameters['group_uuid'] = $group_uuid; + $database = new database; + $group = $database->select($sql, $parameters, 'row'); + } + + //build the delete array + $x = 0; + foreach ($records as $record) { + if (!empty($record['checked']) && $record['checked'] == 'true' && is_uuid($record['uuid'])) { + //build array + $uuids[] = "'".$record['uuid']."'"; + //assign menu item groups + $array['menu_item_groups'][$x]['menu_uuid'] = $menu_uuid; + $array['menu_item_groups'][$x][$this->name.'_uuid'] = $record['uuid']; + $array['menu_item_groups'][$x]['group_name'] = $group['group_name']; + $array['menu_item_groups'][$x]['group_uuid'] = $group['group_uuid']; + //increment + $x++; + } + } + + unset($records); + + //include child menu items and their main_uuid too + if (!empty($uuids) && @sizeof($uuids) != 0) { + $sql = "select menu_uuid, menu_item_uuid as uuid from v_".$this->table." "; + $sql .= "where menu_item_parent_uuid in (".implode(', ', $uuids).") "; + $database = new database; + $rows = $database->select($sql, null, 'all'); + if (!empty($rows) && @sizeof($rows) != 0) { + foreach ($rows as $row) { + //assign menu item groups + $array['menu_item_groups'][$x]['menu_uuid'] = $row['menu_uuid']; + $array['menu_item_groups'][$x][$this->name.'_uuid'] = $row['uuid']; + $array['menu_item_groups'][$x]['group_name'] = $group['group_name']; + $array['menu_item_groups'][$x]['group_uuid'] = $group['group_uuid']; + //increment + $x++; + } + } + } + + unset($uuids); + + //add the checked rows fro group + if (!empty($array) && is_array($array) && @sizeof($array) != 0) { + //grant temporary permissions + $p = new permissions; + $p->add('menu_language_delete', 'temp'); + $p->add('menu_item_group_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('menu_language_delete', 'temp'); + $p->delete('menu_item_group_delete', 'temp'); + + //set message + message::add($text['message-delete']); + } + } + } + } + /** * restore the menu */ diff --git a/resources/classes/modal.php b/resources/classes/modal.php index bf2e41d5fa..4fc244b27a 100644 --- a/resources/classes/modal.php +++ b/resources/classes/modal.php @@ -54,6 +54,9 @@ $array['title'] = $text['modal_title-confirmation']; $array['message'] = $text['confirm-delete']; break; + case 'unassign': + $array['title'] = $text['modal_title-confirmation']; + $array['message'] = $text['confirm-unassign']; default: //general $array['title'] = !empty($array['title']) ? $array['title'] : $text['modal_title-confirmation']; } diff --git a/themes/default/template.php b/themes/default/template.php index 88b65f46d1..944aa8abe9 100644 --- a/themes/default/template.php +++ b/themes/default/template.php @@ -900,14 +900,14 @@ btn_delete = document.getElementById("btn_delete"); btn_download = document.getElementById("btn_download"); btn_transcribe = document.getElementById("btn_transcribe"); - btn_resend = document.getElementById("btn_resend"); + any_revealed = document.getElementsByClassName('revealed'); if (checked == true) { if (btn_copy) { btn_copy.style.display = "inline"; } if (btn_toggle) { btn_toggle.style.display = "inline"; } if (btn_delete) { btn_delete.style.display = "inline"; } if (btn_download) { btn_download.style.display = "inline"; } if (btn_transcribe) { btn_transcribe.style.display = "inline"; } - if (btn_resend) { btn_resend.style.display = "inline"; } + if (any_revealed) { [...any_revealed].map(btn => btn.style.display = "inline"); } } else { if (btn_copy) { btn_copy.style.display = "none"; } @@ -915,7 +915,7 @@ if (btn_delete) { btn_delete.style.display = "none"; } if (btn_download) { btn_download.style.display = "none"; } if (btn_transcribe) { btn_transcribe.style.display = "none"; } - if (btn_resend) { btn_resend.style.display = "none"; } + if (any_revealed) { [...any_revealed].map(btn => btn.style.display = "none"); } } } {/literal} @@ -938,6 +938,13 @@ document.getElementById('btn_check_none').style.display = 'none'; } } + any_revealed = document.getElementsByClassName('revealed'); + if (checkbox_checked == true) { + if (any_revealed) { [...any_revealed].map(btn => btn.style.display = "inline"); } + } + else { + if (any_revealed) { [...any_revealed].map(btn => btn.style.display = "none"); } + } } function list_all_check() {