[CORE] [MENU] Feature Assign/Unassign User Groups (#7373)

This commit is contained in:
K-Flagman
2025-05-17 12:50:02 -07:00
committed by GitHub
parent a67ddbaa41
commit 62791e4eb3
6 changed files with 305 additions and 5 deletions

View File

@@ -1242,4 +1242,54 @@ $text['confirm-restore']['zh-cn'] = "您将要恢复此菜单上所有<i>未受
$text['confirm-restore']['ja-jp'] = "このメニュー上のすべての<i>保護されていない</i>項目を復元しようとしています。"; $text['confirm-restore']['ja-jp'] = "このメニュー上のすべての<i>保護されていない</i>項目を復元しようとしています。";
$text['confirm-restore']['ko-kr'] = "이 메뉴에서 모든 <i>보호되지 않은</i> 항목을 복원하려고 합니다."; $text['confirm-restore']['ko-kr'] = "이 메뉴에서 모든 <i>보호되지 않은</i> 항목을 복원하려고 합니다.";
$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'] = "할당 해제";
?> ?>

View File

@@ -45,6 +45,7 @@
$action = $_POST['action']; $action = $_POST['action'];
$menu_uuid = $_POST['menu_uuid']; $menu_uuid = $_POST['menu_uuid'];
$menu_items = $_POST['menu_items']; $menu_items = $_POST['menu_items'];
$group_uuid = $_POST['group_uuid'];
} }
//process the http post data by action //process the http post data by action
@@ -62,6 +63,18 @@
$obj->delete_items($menu_items); $obj->delete_items($menu_items);
} }
break; 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)); header('Location: menu_edit.php?id='.urlencode($menu_uuid));
@@ -159,7 +172,7 @@
echo "<tr class='list-row' href='".$list_row_url."'>\n"; echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('menu_item_edit') || permission_exists('menu_item_delete')) { if (permission_exists('menu_item_edit') || permission_exists('menu_item_delete')) {
echo " <td class='checkbox'>\n"; echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='menu_items[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n"; echo " <input type='checkbox' name='menu_items[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='menu_items[$x][uuid]' value='".escape($menu_item_uuid)."' />\n"; echo " <input type='hidden' name='menu_items[$x][uuid]' value='".escape($menu_item_uuid)."' />\n";
echo " </td>\n"; echo " </td>\n";
} }
@@ -231,6 +244,12 @@
$result = $database->select($sql, $parameters, 'all'); $result = $database->select($sql, $parameters, 'all');
unset($sql, $parameters); 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 //create token
$object = new token; $object = new token;
$token = $object->create('/core/menu/menu_item_list.php'); $token = $object->create('/core/menu/menu_item_list.php');
@@ -243,6 +262,24 @@
echo "<div class='action_bar' id='action_bar_sub'>\n"; echo "<div class='action_bar' id='action_bar_sub'>\n";
echo " <div class='heading'><b id='heading_sub'>".$text['header-menu_items']."</b><div class='count'><span id='num_rows'></span></div></div>\n"; echo " <div class='heading'><b id='heading_sub'>".$text['header-menu_items']."</b><div class='count'><span id='num_rows'></span></div></div>\n";
echo " <div class='actions'>\n"; echo " <div class='actions'>\n";
echo " <select class='formfld revealed' id='group_uuid' name='group_uuid' style='display: none;'>\n";
echo " <option value=''>Select Group</option>\n";
if (!empty($groups)) {
foreach ($groups as $row) {
echo " <option value='".urlencode($row["group_uuid"])."'>".escape($row['group_name'])." ".escape($row['group_description'])."</option>\n";
}
}
echo " </select>\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']); 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')) { 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)]); 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 "<tr class='list-row' href='".$list_row_url."'>\n"; echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('menu_item_edit') || permission_exists('menu_item_delete')) { if (permission_exists('menu_item_edit') || permission_exists('menu_item_delete')) {
echo "<td class='checkbox'>\n"; echo "<td class='checkbox'>\n";
echo " <input type='checkbox' name='menu_items[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n"; echo " <input type='checkbox' name='menu_items[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='menu_items[$x][uuid]' value='".escape($menu_item_uuid)."' />\n"; echo " <input type='hidden' name='menu_items[$x][uuid]' value='".escape($menu_item_uuid)."' />\n";
echo "</td>\n"; echo "</td>\n";
} }

View File

@@ -675,6 +675,32 @@ $text['confirm-toggle']['ja-jp'] = "あなたは本当にこれをTOGGLEした
$text['confirm-toggle']['ko-kr'] = "정말 토글하시겠습니까?"; $text['confirm-toggle']['ko-kr'] = "정말 토글하시겠습니까?";
$text['confirm-toggle']['ka-ge'] = "ნამდვილად გსურთ გადართვა?"; $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-us'] = "Apply";
$text['button-apply']['en-gb'] = "Apply"; $text['button-apply']['en-gb'] = "Apply";
$text['button-apply']['ar-eg'] = "يتقدم"; $text['button-apply']['ar-eg'] = "يتقدم";

View File

@@ -362,6 +362,183 @@
unset($sql, $parameters); 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 * restore the menu
*/ */

View File

@@ -54,6 +54,9 @@
$array['title'] = $text['modal_title-confirmation']; $array['title'] = $text['modal_title-confirmation'];
$array['message'] = $text['confirm-delete']; $array['message'] = $text['confirm-delete'];
break; break;
case 'unassign':
$array['title'] = $text['modal_title-confirmation'];
$array['message'] = $text['confirm-unassign'];
default: //general default: //general
$array['title'] = !empty($array['title']) ? $array['title'] : $text['modal_title-confirmation']; $array['title'] = !empty($array['title']) ? $array['title'] : $text['modal_title-confirmation'];
} }

View File

@@ -900,14 +900,14 @@
btn_delete = document.getElementById("btn_delete"); btn_delete = document.getElementById("btn_delete");
btn_download = document.getElementById("btn_download"); btn_download = document.getElementById("btn_download");
btn_transcribe = document.getElementById("btn_transcribe"); btn_transcribe = document.getElementById("btn_transcribe");
btn_resend = document.getElementById("btn_resend"); any_revealed = document.getElementsByClassName('revealed');
if (checked == true) { if (checked == true) {
if (btn_copy) { btn_copy.style.display = "inline"; } if (btn_copy) { btn_copy.style.display = "inline"; }
if (btn_toggle) { btn_toggle.style.display = "inline"; } if (btn_toggle) { btn_toggle.style.display = "inline"; }
if (btn_delete) { btn_delete.style.display = "inline"; } if (btn_delete) { btn_delete.style.display = "inline"; }
if (btn_download) { btn_download.style.display = "inline"; } if (btn_download) { btn_download.style.display = "inline"; }
if (btn_transcribe) { btn_transcribe.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 { else {
if (btn_copy) { btn_copy.style.display = "none"; } if (btn_copy) { btn_copy.style.display = "none"; }
@@ -915,7 +915,7 @@
if (btn_delete) { btn_delete.style.display = "none"; } if (btn_delete) { btn_delete.style.display = "none"; }
if (btn_download) { btn_download.style.display = "none"; } if (btn_download) { btn_download.style.display = "none"; }
if (btn_transcribe) { btn_transcribe.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} {/literal}
@@ -938,6 +938,13 @@
document.getElementById('btn_check_none').style.display = 'none'; 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() { function list_all_check() {