/**
  * module initialization tasks
  *
  * @param object $request
  * @param object $tpl Template instance
  * 
  * @return void
  */
 function init(&$request, $tpl = null)
 {
     $this->request =& $request;
     if (!isset($this->site) && !Request::isCurrentModuleAnInstallModule()) {
         //site could be setted if ViewRss is called for multiple sites
         $site = $this->request->getSiteId();
         if ($site) {
             if (get_class($this) != "adminupdate") {
                 $this->site = new Site($site);
             }
         }
     }
     if (!Request::isCurrentModuleAGraphModule()) {
         if (!is_null($tpl)) {
             $this->tpl =& $tpl;
         } else {
             if (isset($this->site)) {
                 $this->tpl =& new TemplateEngine($this->viewTemplate, $this->site->getPathTheme());
             } else {
                 $this->tpl =& new TemplateEngine($this->viewTemplate);
             }
         }
     }
 }
 function loadSiteId()
 {
     if ($this->getModuleName() == 'list_logos') {
         return true;
     }
     $site = getRequestVar('site', Site::getFirstSiteAvailable(), 'int');
     $db =& Db::getInstance();
     if ($db->isReady() && $db->areAllTablesInstalled() && !Request::isCurrentModuleAnInstallModule()) {
         // check site asked is ok
         if ($site != -1) {
             $r = query("SELECT idsite \n\t\t\t\t\t\tFROM " . T_SITE);
             $idSite = array();
             while ($l = mysql_fetch_assoc($r)) {
                 $idSite[] = $l['idsite'];
             }
             if (sizeof($idSite) == 0) {
                 $GLOBALS['header_error_message_tpl'] = $GLOBALS['lang']['generique_aucune_site_bdd'];
                 Request::redirectToModule('admin_site_general&action=add');
                 $site = false;
             } elseif (!in_array($site, $idSite)) {
                 $site = 0;
             }
         }
     }
     $this->site = (int) $site;
 }
 /**
  * load site Info
  * 
  * @return array site info (name of logo.suffix, params_include_only, params_exclude)
  */
 function loadInfo()
 {
     if (!Request::isPhpmvLogModule()) {
         $db =& Db::getInstance();
         if (!$db->isReady() || !$db->areAllTablesInstalled() || Request::isCurrentModuleAnInstallModule()) {
             return array();
         }
     }
     $siteInfo = array();
     $fileAdress = INCLUDE_PATH . "/config/site_info.php";
     // file exists and is correct
     if (is_file($fileAdress)) {
         require $fileAdress;
         if (sizeof($siteInfo) != 0) {
             return $siteInfo;
         }
     }
     $r = query("SELECT idsite, name, logo, params_choice, params_names, idpdf, path_theme" . " FROM " . T_SITE);
     if (mysql_num_rows($r) == 0) {
         $GLOBALS['content_message_tpl'] = $GLOBALS['lang']['generique_aucune_site_bdd'];
         return;
     } else {
         while ($l = mysql_fetch_assoc($r)) {
             $siteInfo[$l['idsite']] = $l;
         }
         // ip to exclude
         // select excluded Ip2long
         $r2 = query("SELECT ip_min, ip_max, idsite " . " FROM " . T_IP_IGNORE);
         if (mysql_num_rows($r2) > 0) {
             $i = 0;
             while ($l2 = mysql_fetch_assoc($r2)) {
                 $siteInfo[$l2['idsite']]['ips'][] = array($l2['ip_min'], $l2['ip_max']);
             }
         }
         saveConfigFile($fileAdress, $siteInfo, 'siteInfo');
         return $siteInfo;
     }
 }
 /**
  * Charge le module demand�
  *
  */
 function loadModule()
 {
     $moduleName = $this->request->getModuleName();
     $db =& Db::getInstance();
     if (ereg('admin', $moduleName)) {
         $this->lang->reloadLangFile();
     }
     if (!$moduleName) {
         $moduleName = $this->defaultModuleName;
     }
     if ($moduleName == 'list_logos') {
         $authorized = true;
     } else {
         $b_writeDir = checkDirWritable();
         /**
          * very first : logo selection is allowed
          */
         /**
          * first look if installation is needed 
          */
         if (!is_file(INCLUDE_PATH . "/config/config.php") || !defined('DB_HOST') || !defined('SU_LOGIN') || !defined('INSTALL_OK')) {
             if (!Request::isCurrentModuleAnInstallModule()) {
                 Request::redirectToModule('install_welcome');
             }
             $authorized = true;
         } else {
             if (!$db->isReady() && substr_count(Request::getCurrentCompleteUrl(), 'mod=login') === 0 && substr_count(Request::getCurrentCompleteUrl(), 'mod=logout') === 0) {
                 Request::redirectToModule('admin_db_config');
             } else {
                 if ($b_writeDir === false) {
                     // case there is a write problem, we load server_info page to indicate the user the problem
                     $moduleName = 'admin_server_info';
                     $authorized = true;
                 } else {
                     if ($db->isReady()) {
                         if (version_compare($db->getVersion(), PHPMV_VERSION) == -1) {
                             $moduleName = 'admin_update';
                             $authorized = true;
                         } else {
                             if (version_compare($db->getVersion(), PHPMV_VERSION) == 1) {
                                 trigger_error("There is a problem : your database is more recent than your phpMyVisites files! Try to upload the last release of phpMyVisites on your server.", E_USER_ERROR);
                             }
                         }
                     }
                 }
             }
         }
     }
     /**
      * else it's ok! Load module
      */
     // update module in the object request, used for hidden field in the login form
     $this->request->setModuleName($moduleName);
     // manage the user, is he authorized to see this module ?
     $me =& User::getInstance();
     if (isset($authorized) || $me->isAuthorized($moduleName) || $this->request->isCrontabAllowed()) {
         $module = Module::factory($moduleName);
     } else {
         $module = Module::factory('login');
     }
     if (!is_subclass_of($module, 'Module')) {
         trigger_error('Unable to load: ' . $moduleName . ' module', E_USER_ERROR);
     }
     $module->init($this->request, null);
     $this->module =& $module;
 }