diff --git a/core/menu/menu_item_edit.php b/core/menu/menu_item_edit.php index 40b9bcb87e..50c804c589 100644 --- a/core/menu/menu_item_edit.php +++ b/core/menu/menu_item_edit.php @@ -41,15 +41,14 @@ else { //get the menu_uuid $menu_uuid = check_str($_REQUEST["id"]); $menu_item_uuid = check_str($_REQUEST['menu_item_uuid']); - $group_name = check_str($_REQUEST['group_name']); + $group_uuid_name = check_str($_REQUEST['group_uuid_name']); + $menu_item_group_uuid = check_str($_REQUEST['menu_item_group_uuid']); -//delete the group from the user - if ($_REQUEST["a"] == "delete" && permission_exists("menu_delete")) { +//delete the group from the menu item + if ($_REQUEST["a"] == "delete" && permission_exists("menu_delete") && $menu_item_group_uuid != '') { //delete the group from the users $sql = "delete from v_menu_item_groups "; - $sql .= "where menu_uuid = '".$menu_uuid."' "; - $sql .= "and menu_item_uuid = '".$menu_item_uuid."' "; - $sql .= "and group_name = '".$group_name."' "; + $sql .= "where menu_item_group_uuid = '".$menu_item_group_uuid."' "; $db->exec(check_sql($sql)); //redirect the browser $_SESSION["message"] = $text['message-delete']; @@ -211,7 +210,10 @@ else { } //add a group to the menu - if ($_REQUEST["a"] != "delete" && strlen($group_name) > 0 && permission_exists('menu_add')) { + if ($_REQUEST["a"] != "delete" && strlen($group_uuid_name) > 0 && permission_exists('menu_add')) { + $group_data = explode('|', $group_uuid_name); + $group_uuid = $group_data[0]; + $group_name = $group_data[1]; //add the group to the menu if (strlen($menu_item_uuid) > 0) { $menu_item_group_uuid = uuid(); @@ -220,14 +222,16 @@ else { $sql_insert .= "menu_item_group_uuid, "; $sql_insert .= "menu_uuid, "; $sql_insert .= "menu_item_uuid, "; - $sql_insert .= "group_name "; + $sql_insert .= "group_name, "; + $sql_insert .= "group_uuid "; $sql_insert .= ")"; $sql_insert .= "values "; $sql_insert .= "("; $sql_insert .= "'".$menu_item_group_uuid."', "; $sql_insert .= "'".$menu_uuid."', "; $sql_insert .= "'".$menu_item_uuid."', "; - $sql_insert .= "'".$group_name."' "; + $sql_insert .= "'".$group_name."', "; + $sql_insert .= "'".$group_uuid."' "; $sql_insert .= ")"; $db->exec($sql_insert); } @@ -270,14 +274,21 @@ else { } } - //redirect the user + //set response message if ($action == "add") { $_SESSION["message"] = $text['message-add']; } if ($action == "update") { $_SESSION["message"] = $text['message-update']; } - header("Location: menu_edit.php?id=".$menu_uuid); + + //redirect the user + if ($_REQUEST['submit'] == $text['button-add']) { + header("Location: menu_item_edit.php?id=".$menu_uuid."&menu_item_uuid=".$menu_item_uuid."&menu_uuid=".$menu_uuid); + } + else { + header("Location: menu_edit.php?id=".$menu_uuid); + } return; } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) @@ -383,53 +394,78 @@ else { echo " ".$text['label-groups'].""; echo " "; - echo "\n"; - $sql = "SELECT * FROM v_menu_item_groups "; - $sql .= "where menu_uuid=:menu_uuid "; - $sql .= "and menu_item_uuid=:menu_item_uuid "; + //group list + $sql = "select "; + $sql .= " mig.*, g.domain_uuid as group_domain_uuid "; + $sql .= "from "; + $sql .= " v_menu_item_groups as mig, "; + $sql .= " v_groups as g "; + $sql .= "where "; + $sql .= " mig.group_uuid = g.group_uuid "; + $sql .= " and ("; + $sql .= " g.domain_uuid = :domain_uuid "; + $sql .= " or g.domain_uuid is null "; + $sql .= " ) "; + $sql .= " and mig.menu_uuid = :menu_uuid "; + $sql .= " and mig.menu_item_uuid = :menu_item_uuid "; + $sql .= "order by "; + $sql .= " g.domain_uuid desc, "; + $sql .= " g.group_name asc "; $prep_statement = $db->prepare(check_sql($sql)); + $prep_statement->bindParam(':domain_uuid', $domain_uuid); $prep_statement->bindParam(':menu_uuid', $menu_uuid); $prep_statement->bindParam(':menu_item_uuid', $menu_item_uuid); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); - foreach($result as $field) { - if (strlen($field['group_name']) > 0) { - echo "\n"; - echo " \n"; - echo "
".$field['group_name']."\n"; - if (permission_exists('group_member_delete') || if_group("superadmin")) { - echo " $v_link_label_delete\n"; + if ($result_count > 0) { + echo "\n"; + foreach($result as $field) { + if (strlen($field['group_name']) > 0) { + echo "\n"; + echo " \n"; + if (permission_exists('group_member_delete') || if_group("superadmin")) { + echo " "; + } + echo "\n"; + $assigned_groups[] = $field['group_uuid']; } - echo " \n"; - echo "\n"; - $assigned_groups[] = $field['group_name']; } + echo "
"; + echo $field['group_name'].(($field['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$field['group_domain_uuid']]['domain_name'] : null); + echo " "; + echo "".$v_link_label_delete.""; + echo "
\n"; } - echo "
\n"; + unset($sql, $prep_statement, $result, $result_count); - echo "
\n"; - $sql = "SELECT * FROM v_groups "; + //group select + $sql = "select * from v_groups "; $sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; - $sql .= "order by group_name asc "; + if (sizeof($assigned_groups) > 0) { + $sql .= "and group_uuid not in ('".implode("','",$assigned_groups)."') "; + } + $sql .= "order by domain_uuid desc, group_name asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); - echo "\n"; + echo " \n"; + foreach($result as $field) { + if ($field['group_name'] == "superadmin" && !if_group("superadmin")) { continue; } //only show the superadmin group to other superadmins + if ($field['group_name'] == "admin" && (!if_group("superadmin") && !if_group("admin") )) { continue; } //only show the admin group to other admins + if (!in_array($field["group_uuid"], $assigned_groups)) { + echo " \n"; } } + echo ""; + echo "\n"; } - echo ""; - echo "\n"; - unset($sql, $result); + unset($sql, $prep_statement, $result); + echo " "; echo " "; diff --git a/core/menu/menu_item_list.php b/core/menu/menu_item_list.php index aad2458328..d3c5beac6c 100644 --- a/core/menu/menu_item_list.php +++ b/core/menu/menu_item_list.php @@ -65,24 +65,26 @@ function build_db_child_menu_list ($db, $menu_item_level, $menu_item_uuid, $c) { $menu_item_title = $row2[menu_item_title]; $menu_item_link = $row2[menu_item_link]; //get the groups that have been assigned to the menu - $sql = ""; - $sql .= "select group_name from v_menu_item_groups "; - $sql .= "where menu_uuid = '$menu_uuid' "; - $sql .= "and menu_item_uuid = '".$menu_item_uuid."' "; + $sql = "select "; + $sql .= " g.group_name, g.domain_uuid as group_domain_uuid "; + $sql .= "from "; + $sql .= " v_menu_item_groups as mig, "; + $sql .= " v_groups as g "; + $sql .= "where "; + $sql .= " mig.group_uuid = g.group_uuid "; + $sql .= " and mig.menu_uuid = '".$menu_uuid."' "; + $sql .= " and mig.menu_item_uuid = '".$menu_item_uuid."' "; + $sql .= "order by "; + $sql .= " g.domain_uuid desc, "; + $sql .= " g.group_name asc "; $sub_prep_statement = $db->prepare(check_sql($sql)); $sub_prep_statement->execute(); $sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED); - $group_list = ""; - $x = 0; + unset($group_list); foreach ($sub_result as &$sub_row) { - if ($x == 0) { - $group_list = $sub_row["group_name"]; - } - else { - $group_list .= ", ".$sub_row["group_name"]; - } - $x++; + $group_list[] = $sub_row["group_name"].(($sub_row['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$sub_row['group_domain_uuid']]['domain_name'] : null); } + $group_list = implode(', ', $group_list); unset ($sub_prep_statement); //display the main body of the list switch ($menu_item_category) { @@ -226,23 +228,26 @@ else { $menu_item_protected = $row['menu_item_protected']; //get the groups that have been assigned to the menu - $sql = "select group_name from v_menu_item_groups "; - $sql .= "where menu_uuid = '$menu_uuid' "; - $sql .= "and menu_item_uuid = '$menu_item_uuid' "; + $sql = "select "; + $sql .= " g.group_name, g.domain_uuid as group_domain_uuid "; + $sql .= "from "; + $sql .= " v_menu_item_groups as mig, "; + $sql .= " v_groups as g "; + $sql .= "where "; + $sql .= " mig.group_uuid = g.group_uuid "; + $sql .= " and mig.menu_uuid = '".$menu_uuid."' "; + $sql .= " and mig.menu_item_uuid = '".$menu_item_uuid."' "; + $sql .= "order by "; + $sql .= " g.domain_uuid desc, "; + $sql .= " g.group_name asc "; $sub_prep_statement = $db->prepare(check_sql($sql)); $sub_prep_statement->execute(); $sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED); - $group_list = ""; - $x = 0; + unset($group_list); foreach ($sub_result as &$sub_row) { - if ($x == 0) { - $group_list = $sub_row["group_name"]; - } - else { - $group_list .= ", ".$sub_row["group_name"]; - } - $x++; + $group_list[] = $sub_row["group_name"].(($sub_row['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$sub_row['group_domain_uuid']]['domain_name'] : null); } + $group_list = implode(', ', $group_list); unset ($sub_prep_statement); //add the type link based on the typd of the menu