Menu: Restore Default now restores unprotected menu items and their default groups. Removed Restore All function (no longer necessary). Hide Restore Default button for menus other than the default menu.

This commit is contained in:
Nate Jones 2015-05-12 03:03:09 +00:00
parent a3b256b4d9
commit fba18b1c6b
3 changed files with 42 additions and 211 deletions

View File

@ -173,10 +173,7 @@ if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
}
echo "<td width='70%' align='right'>\n";
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='menu.php'\" value='".$text['button-back']."'>\n";
if (permission_exists('menu_restore') && $action == "update") {
echo " <input type='button' class='btn' value='".$text['button-restore_all']."' onclick=\"document.location.href='menu_restore_all_default.php?menu_uuid=$menu_uuid&menu_language=$menu_language';\" />";
}
if (permission_exists('menu_restore') && $action == "update") {
if (permission_exists('menu_restore') && $action == "update" && $menu_uuid == 'b4750c3f-2a86-b00d-b7d0-345c14eca286') {
echo " <input type='button' class='btn' value='".$text['button-restore_default']."' onclick=\"document.location.href='menu_restore_default.php?menu_uuid=$menu_uuid&menu_language=$menu_language';\" />";
}
echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";

View File

@ -17,8 +17,6 @@ $apps[$x]['menu'][0]['path'] = "/core/user_settings/user_edit.php";
$apps[$x]['menu'][0]['groups'][] = "user";
$apps[$x]['menu'][0]['groups'][] = "admin";
$apps[$x]['menu'][0]['groups'][] = "superadmin";
$apps[$x]['menu'][0]['groups'][] = "user";
$apps[$x]['menu'][0]['groups'][] = "admin";
$apps[$x]['menu'][1]['title']['en-us'] = "User Dashboard";
$apps[$x]['menu'][1]['title']['es-cl'] = "Dashboard Usuario";
@ -34,6 +32,8 @@ $apps[$x]['menu'][1]['uuid'] = "92c8ffdb-3c82-4f08-aec0-82421ec41bb5";
$apps[$x]['menu'][1]['parent_uuid'] = "02194288-6d56-6d3e-0b1a-d53a2bc10788";
$apps[$x]['menu'][1]['category'] = "internal";
$apps[$x]['menu'][1]['path'] = "/core/user_settings/user_dashboard.php";
$apps[$x]['menu'][1]['groups'][] = "user";
$apps[$x]['menu'][1]['groups'][] = "admin";
$apps[$x]['menu'][1]['groups'][] = "superadmin";
?>

View File

@ -33,11 +33,18 @@
function delete() {
//set the variable
$db = $this->db;
//remove the menu languages
//remove existing menu languages
$sql = "delete from v_menu_languages ";
$sql .= "where menu_uuid = '".$this->menu_uuid."' ";
$db->exec(check_sql($sql));
//remove the old menu
//remove existing unprotected menu item groups
$sql = "delete from v_menu_item_groups ";
$sql .= "where menu_uuid = '".$this->menu_uuid."' ";
$sql .= "and menu_item_uuid in ( ";
$sql .= " select menu_item_uuid from v_menu_items where menu_item_protected <> 'true' or menu_item_protected is null ";
$sql .= ") ";
$db->exec(check_sql($sql));
//remove existing unprotected menu items
$sql = "delete from v_menu_items ";
$sql .= "where menu_uuid = '".$this->menu_uuid."' ";
$sql .= "and (menu_item_protected <> 'true' ";
@ -163,13 +170,33 @@
}
}
//get default global group_uuids
$sql = "select group_uuid, group_name from v_groups ";
$sql .= "where domain_uuid is null ";
$sql .= "and ( ";
$sql .= " group_name = 'public' ";
$sql .= " or group_name = 'user' ";
$sql .= " or group_name = 'admin' ";
$sql .= " or group_name = 'superadmin' ";
$sql .= " or group_name = 'agent' ";
$sql .= ") ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $row) {
$group_uuids[$row['group_name']] = $row['group_uuid'];
}
unset($sql, $prep_statement, $result);
//if there are no groups listed in v_menu_item_groups under menu_item_uuid then add the default groups
foreach($apps as $app) {
foreach ($app['menu'] as $sub_row) {
foreach ($sub_row['groups'] as $group) {
$sql = "select count(*) as count from v_menu_item_groups ";
$sql .= "where menu_item_uuid = '".$sub_row['uuid']."' ";
$sql .= "and group_name = '$group' ";
$sql .= "and group_name = '".$group."' ";
$sql .= "and group_uuid = '".$group_uuids[$group]."' ";
//echo $sql."<br>";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC);
@ -177,19 +204,22 @@
if ($sub_result['count'] == 0) {
//no menu item groups found add the defaults
$sql = "insert into v_menu_item_groups ";
$sql .= "(";
$sql .= "( ";
$sql .= "menu_item_group_uuid, ";
$sql .= "menu_uuid, ";
$sql .= "menu_item_uuid, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "group_name, ";
$sql .= "group_uuid ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "( ";
$sql .= "'".uuid()."', ";
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'".$sub_row['uuid']."', ";
$sql .= "'".$group."' ";
$sql .= ")";
$sql .= "'".$group."', ";
$sql .= "'".$group_uuids[$group]."' ";
$sql .= ") ";
//echo $sql."<br>";
$db->exec(check_sql($sql));
unset($sql);
}
@ -204,202 +234,6 @@
} //end function
//restore the menu and group permissions
function restore_all() {
//set the variables
$db = $this->db;
//begin the transaction
$db->beginTransaction();
//get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_{config,menu}.php",GLOB_BRACE);
$x = 0;
foreach ($config_list as &$config_path) {
$y = 0;
try {
include($config_path);
$x++;
}
catch (Exception $e) {
echo 'exception caught: ' . $e->getMessage() . "\n";
exit;
}
}
//use the app array to restore the default menu
foreach ($apps as $row) {
foreach ($row['menu'] as $menu) {
//set the variables
if (strlen($menu['title'][$this->menu_language]) > 0) {
$menu_item_title = $menu['title'][$this->menu_language];
}
else {
$menu_item_title = $menu['title']['en-us'];
}
$menu_item_uuid = $menu['uuid'];
$menu_item_parent_uuid = $menu['parent_uuid'];
$menu_item_category = $menu['category'];
$menu_item_path = $menu['path'];
$menu_item_order = $menu['order'];
$menu_item_description = $menu['desc'];
//if the item uuid is not currently in the db then add it
$sql = "select * from v_menu_items ";
$sql .= "where menu_uuid = '".$this->menu_uuid."' ";
$sql .= "and menu_item_uuid = '$menu_item_uuid' ";
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
if (count($result) == 0) {
//insert the default menu into the database
$sql = "insert into v_menu_items ";
$sql .= "(";
$sql .= "menu_item_uuid, ";
$sql .= "menu_uuid, ";
$sql .= "menu_item_title, ";
$sql .= "menu_item_link, ";
$sql .= "menu_item_category, ";
if (strlen($menu_item_order) > 0) {
$sql .= "menu_item_order, ";
}
if (strlen($menu_item_parent_uuid) > 0) {
$sql .= "menu_item_parent_uuid, ";
}
$sql .= "menu_item_description ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$menu_item_uuid."', ";
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'".check_str($menu_item_title)."', ";
$sql .= "'$menu_item_path', ";
$sql .= "'$menu_item_category', ";
if (strlen($menu_item_order) > 0) {
$sql .= "'$menu_item_order', ";
}
if (strlen($menu_item_parent_uuid) > 0) {
$sql .= "'$menu_item_parent_uuid', ";
}
$sql .= "'$menu_item_description' ";
$sql .= ")";
if ($menu_item_uuid == $menu_item_parent_uuid) {
//echo $sql."<br />\n";
}
else {
$db->exec(check_sql($sql));
}
unset($sql);
//set the menu languages
foreach ($menu["title"] as $menu_language => $menu_item_title) {
$menu_language_uuid = uuid();
$sql = "insert into v_menu_languages ";
$sql .= "(";
$sql .= "menu_language_uuid, ";
$sql .= "menu_item_uuid, ";
$sql .= "menu_uuid, ";
$sql .= "menu_language, ";
$sql .= "menu_item_title ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$menu_language_uuid."', ";
$sql .= "'".$menu_item_uuid."', ";
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'".$menu_language."', ";
$sql .= "'".check_str($menu_item_title)."' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
}
}
}
}
//set default group permissions
$sql = "delete from v_group_permissions ";
$db->query($sql);
unset($sql);
$sql2 = "select domain_uuid from v_domains ";
$prep_statement2 = $db->prepare(check_sql($sql2));
$prep_statement2->execute();
$result2 = $prep_statement2->fetchAll(PDO::FETCH_ASSOC);
foreach($result2 as $row2) {
unset ($prep_statement2, $sql2);
foreach($apps as $row) {
foreach ($row['permissions'] as $menu) {
if ($menu['groups']) {
foreach ($menu['groups'] as $group) {
//assign the groups to the permissions
$sql = "insert into v_group_permissions ";
$sql .= "(";
$sql .= "group_permission_uuid, ";
$sql .= "domain_uuid, ";
$sql .= "permission_name, ";
$sql .= "group_name ";
$sql .= ") ";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'".$row2["domain_uuid"]."', ";
$sql .= "'".$menu['name']."', ";
$sql .= "'".$group."' ";
$sql .= ");";
$db->exec(check_sql($sql));
unset($sql);
}
}
}
}
}
unset($sql2, $result2);
//set the default groups in v_menu_item_groups
$sql = "delete from v_menu_item_groups ";
$db->query($sql);
unset($sql);
foreach($apps as $app) {
foreach ($app['menu'] as $sub_row) {
foreach ($sub_row['groups'] as $group) {
//if there are no groups listed in v_menu_item_groups under menu_uuid then add the default groups
$sql = "select count(*) as count from v_menu_item_groups ";
$sql .= "where menu_item_uuid = '".$sub_row['uuid']."' ";
$sql .= "and group_name = '$group' ";
$prep_statement = $db->prepare($sql);
$prep_statement->execute();
$sub_result = $prep_statement->fetch(PDO::FETCH_ASSOC);
unset ($prep_statement);
if ($sub_result['count'] == 0) {
//no menu item groups found add the defaults
$sql = "insert into v_menu_item_groups ";
$sql .= "(";
$sql .= "menu_item_group_uuid, ";
$sql .= "menu_uuid, ";
$sql .= "menu_item_uuid, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".uuid()."', ";
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'".$sub_row['uuid']."', ";
$sql .= "'".$group."' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
}
}
}
//commit the transaction
$db->commit();
} //end function
//create the menu
function build_html($sql, $menu_item_level) {