/**
  * Function for logging messages and errors. The log will be added in db (it will be not added 
  * if level is DEBUG and the conf variable "debug" is set to false), a log is shown on screen 
  * if conf variable "display_log" is set to true. If the level is LOG_LEVEL_FATAL_ERROR the
  * application will die immediately.
  * 
  * @param string $cathegory The cathegory of the error
  * @param int $level One of the predefined level constants
  * - LOG_LEVEL_FATAL_ERROR
  * - LOG_LEVEL_ERROR
  * - LOG_LEVEL_WARNING
  * - LOG_LEVEL_NOTICE
  * - LOG_LEVEL_DEBUG
  * @param string $message Description og the log entry
  * @param string $filename The filename where the log was generated (can use the __FILE__ keyword)
  * @param string $line The line where the log was generated (can use the __LINE__ keyword)
  * @static
  */
 function log($cathegory, $level, $message, $filename = '', $line = 0)
 {
     //prevent deadlock
     global $g_in_log;
     if (isset($g_in_log)) {
         exit("Fatal Error, contact webmaster (Error: Log Recursion)");
     }
     $g_in_log = true;
     $log_entry = new xLogEntry(0, $cathegory, $level, $message, $filename, $line, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', $_SERVER['REQUEST_URI'], time(), $_SERVER['REMOTE_ADDR'], NULL);
     if ($level != LOG_LEVEL_DEBUG || xConf::get('debug', false)) {
         $log_entry->m_stacktrace = xStackTrace::getCurrent(2);
         if (xConf::get('display_log', false)) {
             $log_entry->insertToScreen();
         }
         $log_entry->insert();
     }
     if ($level == LOG_LEVEL_FATAL_ERROR) {
         exit("Fatal Error, please contact the webmaster");
     }
     $g_in_log = NULL;
 }
 /**
  *
  */
 function install()
 {
     ob_start();
     //select DB
     if (xConf::get('db_type', 'mysql') == 'mysql') {
         $db = new xDBMysql();
         $db->connect(xConf::get('db_host', ''), xConf::get('db_user', ''), xConf::get('db_pass', ''), xConf::get('db_port', ''));
         xDB::setDB($db);
         $name = xConf::get('db_name', '');
         $db->query("DROP DATABASE {$name}");
         $db->query("CREATE DATABASE {$name}");
         $db->selectDB($name);
     } else {
         exit('Unknown database type');
     }
     //error handler
     set_error_handler('xanth_php_error_handler');
     $comp = new xModuleManager();
     $comp->initModules('engine', 'comp', false, false, array(new xFrameworkComponent()));
     $comp->invokeAll('xm_install', array($name = xConf::get('db_name', '')));
     $comp = new xModuleManager();
     $comp->initModules('extensions', 'ext', true, true);
     $comp->invokeAll('xm_install', array($name = xConf::get('db_name', '')));
     //print log
     echo xLogEntry::renderFromScreen();
     echo "Xanthin Successfully installed";
     ob_end_flush();
 }