Example #1
0
/**
 * Perform database initialization.
 *
 * @param boolean $create_database
 * @return boolean
 */
function database_initialize($create_database)
{
    global $db, $db_config, $data_path;
    $result = false;
    $database_exists = false;
    $sql_file = 'units/database/init.sql';
    $xml_file = $data_path . 'system_init.xml';
    if (!file_exists($sql_file) || !file_exists($xml_file)) {
        trigger_error('Can not initialize database, missing configuration!', E_USER_ERROR);
        return $result;
    }
    // make a log entry
    trigger_error('Initializing database: ' . $db_config['name'], E_USER_NOTICE);
    // get initialization SQL
    $sql = file_get_contents($sql_file);
    // create database if needed
    if ($create_database) {
        try {
            $db->create($db_config['name']);
            $db->select($db_config['name']);
            $database_exists = true;
        } catch (Exception $error) {
            $database_exists = false;
        }
    } else {
        $database_exists = true;
    }
    // create database
    if ($database_exists && $db->multi_query($sql)) {
        $module_manager = ModuleManager::getInstance();
        $module_handler = ModuleHandler::getInstance();
        $admin_manager = UserManager::getInstance();
        // populate tables
        $raw_data = file_get_contents($xml_file);
        $data = new XMLParser($raw_data, $xml_file);
        $data->parse();
        // go over XML file and insert data
        foreach ($data->document->tagChildren as $item) {
            switch ($item->tagName) {
                case 'module':
                    // insert data
                    $module_manager->insertData(array('name' => $item->tagAttrs['name'], 'order' => $item->tagAttrs['order'], 'preload' => $item->tagAttrs['preload'] == 'yes' ? 1 : 0, 'active' => 1));
                    // initialize module
                    $module = $module_handler->_loadModule($item->tagAttrs['name']);
                    if (!is_null($module)) {
                        $module->onInit();
                    }
                    break;
                case 'user':
                    $salt = hash('sha256', UserManager::SALT . strval(time()));
                    $password = hash_hmac('sha256', $item->tagAttrs['password'], $salt);
                    $admin_manager->insertData(array('username' => $item->tagAttrs['username'], 'password' => $password, 'fullname' => $item->tagAttrs['fullname'], 'level' => $item->tagAttrs['level'], 'verified' => 1, 'salt' => $salt));
                    break;
            }
        }
        // set result
        $result = true;
    }
    return $result;
}
Example #2
0
 /**
  * Initialise and activate module
  */
 private function initialiseModule_Commit()
 {
     $module_name = fix_chars($_REQUEST['module_name']);
     if (!in_array($module_name, $this->protected_modules)) {
         // module is not protected
         $manager = ModuleManager::getInstance();
         $max_order = $manager->getItemValue("MAX(`order`)", array('preload' => 0));
         if (is_null($max_order)) {
             $max_order = -1;
         }
         $manager->insertData(array('order' => $max_order + 1, 'name' => $module_name, 'preload' => 0, 'active' => 1));
         $handler = ModuleHandler::getInstance();
         $module = $handler->_loadModule($module_name);
         if (!is_null($module)) {
             $module->onInit();
             $message = $this->getLanguageConstant('message_module_initialised');
         }
     } else {
         $message = $this->getLanguageConstant('message_module_protected');
     }
     $template = new TemplateHandler('message.xml', $this->path . 'templates/');
     $template->setMappedModule($this->name);
     $params = array('message' => $message, 'action' => window_Close($this->name . '_module_dialog') . ";" . window_ReloadContent('system_modules'));
     $template->restoreXML();
     $template->setLocalParams($params);
     $template->parse();
 }
Example #3
0
        }
    }
}
$language = $_SESSION['language'];
$language_rtl = $language_handler->isRTL();
// turn off URL rewrite for backend
if ($section == 'backend' || $section == 'backend_module') {
    $url_rewrite = false;
}
// start database engine
if ($db_use && !database_connect()) {
    die('There was an error while trying to connect database.');
}
// transfer display control
$cache = CacheHandler::getInstance();
$module_handler = ModuleHandler::getInstance();
if ($cache->isCached()) {
    // only include specified modules
    $module_handler->loadModules(true);
    // show cached page
    $cache->printCache();
} else {
    // get main section handler so we can transfer control
    $section_handler = MainSectionHandler::getInstance();
    // load all the modules
    $module_handler->loadModules();
    // show page and cache it along the way
    $cache->startCapture();
    $section_handler->transferControl($section, $action, $language);
    $cache->endCapture();
}