missing stuff dealing with group permissions

This commit is contained in:
Nuno Miguel Reis
2013-07-29 17:22:40 +00:00
parent 28d41d3e35
commit 2fed568403

View File

@@ -139,14 +139,250 @@
$sql .= "'$menu_item_title' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
}
}
}
}
foreach($apps as $row) {
foreach ($row['permissions'] as $menu) {
//set the variables
if ($menu['groups']) {
foreach ($menu['groups'] as $group) {
//if the item uuid is not currently in the db then add it
$sql = "select * from v_group_permissions ";
$sql .= "where permission_name = '".$menu['name']."' ";
$sql .= "and domain_uuid = '".$row2['domain_uuid']."' ";
$sql .= "and group_name = '$group' ";
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
unset ($prep_statement);
if (count($result) == 0) {
//insert the default menu into the database
$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);
}
}
}
}
}
}
//if there are no groups listed in v_menu_item_groups under menu_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' ";
$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
//add the record
$sql = "insert into v_menu_item_groups ";
$sql .= "(";
$sql .= "menu_uuid, ";
$sql .= "menu_item_uuid, ";
$sql .= "group_name ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$this->menu_uuid."', ";
$sql .= "'".$sub_row['uuid']."', ";
$sql .= "'".$group."' ";
$sql .= ")";
$db->exec($sql);
unset($sql);
}
}
}
}
} //end function
//restore the menu
function restore2() {
//set the variables
$db = $this->db;
//get the $apps array from the installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
$x=0;
foreach ($config_list as &$config_path) {
include($config_path);
$x++;
}
//use the app array to restore the default menu
//$db->beginTransaction();
foreach ($apps as $row) {
foreach ($row['menu'] as $menu) {
//set the variables
$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_language, ";
$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 .= "'$menu_item_language', ";
$sql .= "'$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 .= "'$menu_item_title' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
}
}
}
}
}
$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) {
//set the variables
if ($menu['groups']) {
foreach ($menu['groups'] as $group) {
//if the item uuid is not currently in the db then add it
$sql = "select * from v_group_permissions ";
$sql .= "where permission_name = '".$menu['name']."' ";
$sql .= "and domain_uuid = '".$row2['domain_uuid']."' ";
$sql .= "and group_name = '$group' ";
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
unset ($prep_statement);
if (count($result) == 0) {
//insert the default menu into the database
$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);
//if there are no groups listed in v_menu_item_groups under menu_uuid then add the default 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) {
@@ -219,13 +455,25 @@
$sql .= ") ";
$sql .= "and menu_item_uuid is not null ";
$sql .= ") ";
$sql .= "order by i.menu_item_order asc ";
$sql .= "order by i.menu_item_order desc ";
}
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach($result as $field) {
$sql2 = "select * from v_menu_languages ";
$sql2 .= "where menu_language = 'en-us' ";
$sql2 .= "and menu_item_uuid = '".$field['menu_item_uuid']."' ";
$prep_statement2 = $db->prepare(check_sql($sql2));
$prep_statement2->execute();
$result2 = $prep_statement2->fetchAll(PDO::FETCH_NAMED);
foreach($result2 as $field2) {
$menu_icon_name=$field2['menu_item_title'];
}
unset($prep_statement2, $sql2, $result2);
$menu_tags = '';
switch ($field['menu_item_category']) {
case "internal":