Menu: Include domain for non-global groups in list and select.

This commit is contained in:
Nate Jones 2015-05-09 22:19:02 +00:00
parent 51c198a1db
commit 1d575d30ff
2 changed files with 107 additions and 66 deletions

View File

@ -41,15 +41,14 @@ else {
//get the menu_uuid //get the menu_uuid
$menu_uuid = check_str($_REQUEST["id"]); $menu_uuid = check_str($_REQUEST["id"]);
$menu_item_uuid = check_str($_REQUEST['menu_item_uuid']); $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 //delete the group from the menu item
if ($_REQUEST["a"] == "delete" && permission_exists("menu_delete")) { if ($_REQUEST["a"] == "delete" && permission_exists("menu_delete") && $menu_item_group_uuid != '') {
//delete the group from the users //delete the group from the users
$sql = "delete from v_menu_item_groups "; $sql = "delete from v_menu_item_groups ";
$sql .= "where menu_uuid = '".$menu_uuid."' "; $sql .= "where menu_item_group_uuid = '".$menu_item_group_uuid."' ";
$sql .= "and menu_item_uuid = '".$menu_item_uuid."' ";
$sql .= "and group_name = '".$group_name."' ";
$db->exec(check_sql($sql)); $db->exec(check_sql($sql));
//redirect the browser //redirect the browser
$_SESSION["message"] = $text['message-delete']; $_SESSION["message"] = $text['message-delete'];
@ -211,7 +210,10 @@ else {
} }
//add a group to the menu //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 //add the group to the menu
if (strlen($menu_item_uuid) > 0) { if (strlen($menu_item_uuid) > 0) {
$menu_item_group_uuid = uuid(); $menu_item_group_uuid = uuid();
@ -220,14 +222,16 @@ else {
$sql_insert .= "menu_item_group_uuid, "; $sql_insert .= "menu_item_group_uuid, ";
$sql_insert .= "menu_uuid, "; $sql_insert .= "menu_uuid, ";
$sql_insert .= "menu_item_uuid, "; $sql_insert .= "menu_item_uuid, ";
$sql_insert .= "group_name "; $sql_insert .= "group_name, ";
$sql_insert .= "group_uuid ";
$sql_insert .= ")"; $sql_insert .= ")";
$sql_insert .= "values "; $sql_insert .= "values ";
$sql_insert .= "("; $sql_insert .= "(";
$sql_insert .= "'".$menu_item_group_uuid."', "; $sql_insert .= "'".$menu_item_group_uuid."', ";
$sql_insert .= "'".$menu_uuid."', "; $sql_insert .= "'".$menu_uuid."', ";
$sql_insert .= "'".$menu_item_uuid."', "; $sql_insert .= "'".$menu_item_uuid."', ";
$sql_insert .= "'".$group_name."' "; $sql_insert .= "'".$group_name."', ";
$sql_insert .= "'".$group_uuid."' ";
$sql_insert .= ")"; $sql_insert .= ")";
$db->exec($sql_insert); $db->exec($sql_insert);
} }
@ -270,14 +274,21 @@ else {
} }
} }
//redirect the user //set response message
if ($action == "add") { if ($action == "add") {
$_SESSION["message"] = $text['message-add']; $_SESSION["message"] = $text['message-add'];
} }
if ($action == "update") { if ($action == "update") {
$_SESSION["message"] = $text['message-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; return;
} //if ($_POST["persistformvar"] != "true") } //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
@ -383,53 +394,78 @@ else {
echo " <td class='vncell' valign='top'>".$text['label-groups']."</td>"; echo " <td class='vncell' valign='top'>".$text['label-groups']."</td>";
echo " <td class='vtable'>"; echo " <td class='vtable'>";
echo "<table width='52%'>\n"; //group list
$sql = "SELECT * FROM v_menu_item_groups "; $sql = "select ";
$sql .= "where menu_uuid=:menu_uuid "; $sql .= " mig.*, g.domain_uuid as group_domain_uuid ";
$sql .= "and menu_item_uuid=:menu_item_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 = $db->prepare(check_sql($sql));
$prep_statement->bindParam(':domain_uuid', $domain_uuid);
$prep_statement->bindParam(':menu_uuid', $menu_uuid); $prep_statement->bindParam(':menu_uuid', $menu_uuid);
$prep_statement->bindParam(':menu_item_uuid', $menu_item_uuid); $prep_statement->bindParam(':menu_item_uuid', $menu_item_uuid);
$prep_statement->execute(); $prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result); $result_count = count($result);
foreach($result as $field) { if ($result_count > 0) {
if (strlen($field['group_name']) > 0) { echo "<table cellpadding='0' cellspacing='0' border='0'>\n";
echo "<tr>\n"; foreach($result as $field) {
echo " <td class='vtable'>".$field['group_name']."</td>\n"; if (strlen($field['group_name']) > 0) {
echo " <td>\n"; echo "<tr>\n";
if (permission_exists('group_member_delete') || if_group("superadmin")) { echo " <td class='vtable' style='white-space: nowrap; padding-right: 30px;' nowrap='nowrap'>";
echo " <a href='menu_item_edit.php?id=".$field['menu_uuid']."&group_name=".$field['group_name']."&menu_item_uuid=".$menu_item_uuid."&menu_item_parent_uuid=".$menu_item_parent_uuid."&a=delete' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>\n"; echo $field['group_name'].(($field['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$field['group_domain_uuid']]['domain_name'] : null);
echo " </td>\n";
if (permission_exists('group_member_delete') || if_group("superadmin")) {
echo " <td class='list_control_icons' style='width: 25px;'>";
echo "<a href='menu_item_edit.php?id=".$field['menu_uuid']."&menu_item_group_uuid=".$field['menu_item_group_uuid']."&menu_item_uuid=".$menu_item_uuid."&a=delete' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">".$v_link_label_delete."</a>";
echo " </td>";
}
echo "</tr>\n";
$assigned_groups[] = $field['group_uuid'];
} }
echo " </td>\n";
echo "</tr>\n";
$assigned_groups[] = $field['group_name'];
} }
echo "</table>\n";
} }
echo "</table>\n"; unset($sql, $prep_statement, $result, $result_count);
echo "<br />\n"; //group select
$sql = "SELECT * FROM v_groups "; $sql = "select * from v_groups ";
$sql .= "where (domain_uuid = '".$domain_uuid."' or domain_uuid is null) "; $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 = $db->prepare(check_sql($sql));
$prep_statement->execute(); $prep_statement->execute();
echo "<select name=\"group_name\" class='formfld' style='width: auto; margin-right: 3px;'>\n";
echo "<option value=\"\"></option>\n";
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach($result as $field) { $result_count = count($result);
if (!in_array($field['group_name'], $assigned_groups)) { if ($result_count > 0) {
if ($field['group_name'] == "superadmin" && if_group("superadmin")) { echo "<br />\n";
echo "<option value='".$field['group_name']."'>".$field['group_name']."</option>\n"; //only show the superadmin group to other users in the superadmin group echo "<select name='group_uuid_name' class='formfld' style='width: auto; margin-right: 3px;'>\n";
} echo " <option value=''></option>\n";
else { foreach($result as $field) {
echo "<option value='".$field['group_name']."'>".$field['group_name']."</option>\n"; 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 " <option value='".$field['group_uuid']."|".$field['group_name']."'>".$field['group_name'].(($field['domain_uuid'] != '') ? "@".$_SESSION['domains'][$field['domain_uuid']]['domain_name'] : null)."</option>\n";
} }
} }
echo "</select>";
echo "<input type='submit' class='btn' name='submit' value=\"".$text['button-add']."\">\n";
} }
echo "</select>"; unset($sql, $prep_statement, $result);
echo "<input type=\"submit\" class='btn' value=\"".$text['button-add']."\">\n";
unset($sql, $result);
echo " </td>"; echo " </td>";
echo " </tr>"; echo " </tr>";

View File

@ -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_title = $row2[menu_item_title];
$menu_item_link = $row2[menu_item_link]; $menu_item_link = $row2[menu_item_link];
//get the groups that have been assigned to the menu //get the groups that have been assigned to the menu
$sql = ""; $sql = "select ";
$sql .= "select group_name from v_menu_item_groups "; $sql .= " g.group_name, g.domain_uuid as group_domain_uuid ";
$sql .= "where menu_uuid = '$menu_uuid' "; $sql .= "from ";
$sql .= "and menu_item_uuid = '".$menu_item_uuid."' "; $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 = $db->prepare(check_sql($sql));
$sub_prep_statement->execute(); $sub_prep_statement->execute();
$sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED); $sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED);
$group_list = ""; unset($group_list);
$x = 0;
foreach ($sub_result as &$sub_row) { foreach ($sub_result as &$sub_row) {
if ($x == 0) { $group_list[] = $sub_row["group_name"].(($sub_row['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$sub_row['group_domain_uuid']]['domain_name'] : null);
$group_list = $sub_row["group_name"];
}
else {
$group_list .= ", ".$sub_row["group_name"];
}
$x++;
} }
$group_list = implode(', ', $group_list);
unset ($sub_prep_statement); unset ($sub_prep_statement);
//display the main body of the list //display the main body of the list
switch ($menu_item_category) { switch ($menu_item_category) {
@ -226,23 +228,26 @@ else {
$menu_item_protected = $row['menu_item_protected']; $menu_item_protected = $row['menu_item_protected'];
//get the groups that have been assigned to the menu //get the groups that have been assigned to the menu
$sql = "select group_name from v_menu_item_groups "; $sql = "select ";
$sql .= "where menu_uuid = '$menu_uuid' "; $sql .= " g.group_name, g.domain_uuid as group_domain_uuid ";
$sql .= "and menu_item_uuid = '$menu_item_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 = $db->prepare(check_sql($sql));
$sub_prep_statement->execute(); $sub_prep_statement->execute();
$sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED); $sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED);
$group_list = ""; unset($group_list);
$x = 0;
foreach ($sub_result as &$sub_row) { foreach ($sub_result as &$sub_row) {
if ($x == 0) { $group_list[] = $sub_row["group_name"].(($sub_row['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$sub_row['group_domain_uuid']]['domain_name'] : null);
$group_list = $sub_row["group_name"];
}
else {
$group_list .= ", ".$sub_row["group_name"];
}
$x++;
} }
$group_list = implode(', ', $group_list);
unset ($sub_prep_statement); unset ($sub_prep_statement);
//add the type link based on the typd of the menu //add the type link based on the typd of the menu