示例#1
0
 public function restore()
 {
     //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_menu.php");
     $x = 0;
     foreach ($config_list as &$config_path) {
         $y = 0;
         try {
             //echo "[".$x ."] ".$config_path."\n";
             include $config_path;
             $x++;
         } catch (Exception $e) {
             echo 'exception caught: ' . $e->getMessage() . "\n";
             exit;
         }
     }
     //begin the transaction
     if ($db_type == "sqlite") {
         $db->beginTransaction();
     }
     //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_icon = $menu['icon'];
             $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, ";
                     $sql .= "menu_item_icon, ";
                     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}', ";
                     $sql .= "'{$menu_item_icon}', ";
                     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);
                     }
                 }
             }
         }
     }
     //make sure the default user groups exist
     $group = new groups();
     $group->defaults();
     //get default global group_uuids
     $sql = "select group_uuid, group_name from v_groups ";
     $sql .= "where domain_uuid is null ";
     $sql .= "and ( ";
     $sql .= "\tgroup_name = 'public' ";
     $sql .= "\tor group_name = 'user' ";
     $sql .= "\tor group_name = 'admin' ";
     $sql .= "\tor group_name = 'superadmin' ";
     $sql .= "\tor 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) {
             if (isset($sub_row['groups'])) {
                 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 menu_uuid = '" . $this->menu_uuid . "' ";
                     $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);
                     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 .= "group_uuid ";
                         $sql .= ") ";
                         $sql .= "values ";
                         $sql .= "( ";
                         $sql .= "'" . uuid() . "', ";
                         $sql .= "'" . $this->menu_uuid . "', ";
                         $sql .= "'" . $sub_row['uuid'] . "', ";
                         $sql .= "'" . $group . "', ";
                         $sql .= "'" . $group_uuids[$group] . "' ";
                         $sql .= ") ";
                         //echo $sql."<br>";
                         $db->exec(check_sql($sql));
                         unset($sql);
                     }
                 }
             }
         }
     }
     //commit the transaction
     if ($db_type == "sqlite") {
         $db->commit();
     }
 }
示例#2
0
	License.

	The Original Code is FusionPBX

	The Initial Developer of the Original Code is
	Mark J Crane <*****@*****.**>
	Portions created by the Initial Developer are Copyright (C) 2008-2012
	the Initial Developer. All Rights Reserved.

	Contributor(s):
	Mark J Crane <*****@*****.**>
*/
if ($domains_processed == 1) {
    //if the default groups do not exist add them
    $group = new groups();
    $group->defaults();
    //find rows that have a null group_uuid and set the correct group_uuid
    $sql = "select * from v_group_users ";
    $sql .= "where group_uuid is null; ";
    $prep_statement = $db->prepare(check_sql($sql));
    if ($prep_statement) {
        $prep_statement->execute();
        $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
        $db->beginTransaction();
        foreach ($result as $row) {
            if (strlen($row['group_name']) > 0) {
                //get the group_uuid
                $sql = "select group_uuid from v_groups ";
                $sql .= "where group_name = '" . $row['group_name'] . "' ";
                $prep_statement_sub = $db->prepare($sql);
                $prep_statement_sub->execute();