Beispiel #1
0
 public function startSite($siteId, $userId = '')
 {
     $result = false;
     $this->setMode(Ampoliros::MODE_SITE);
     global $env;
     if (isset($GLOBALS['gEnv']['runtime']['site']['init']) and $GLOBALS['gEnv']['runtime']['site']['init'] == true) {
         return;
     }
     // Site id
     //
     $GLOBALS['gEnv']['site']['id'] = $siteId;
     $env['currentsite'] =& $GLOBALS['gEnv']['site']['id'];
     $env['currentsiteid'] =& $env['currentsite'];
     // Site data
     //
     $sitesquery = $GLOBALS['gEnv']['root']['db']->Execute('SELECT * FROM sites WHERE siteid=' . $GLOBALS['gEnv']['root']['db']->Format_Text($siteId));
     if ($sitesquery->NumRows()) {
         $GLOBALS['gEnv']['site']['data'] = $sitesquery->Fields();
         $env['sitedata'] =& $GLOBALS['gEnv']['site']['data'];
         $sitesquery->Free();
         // Check if site is active
         //
         if ($this->getInterface() != Ampoliros::INTERFACE_WEB and $GLOBALS['gEnv']['site']['data']['siteactive'] == $GLOBALS['gEnv']['root']['db']->fmtfalse) {
             $this->abort('Site disabled');
         }
         // Site log
         //
         define('SITE_LOG', SITESTUFF_PATH . $GLOBALS['gEnv']['site']['data']['siteid'] . '/log/site.log');
         $GLOBALS['gEnv']['site']['log'] = SITE_LOG;
         // Current site serial number
         //
         $GLOBALS['gEnv']['site']['serial'] = $GLOBALS['gEnv']['site']['data']['id'];
         $env['currentsiteserial'] = $GLOBALS['gEnv']['site']['serial'];
         // Site database
         //
         $dbargs['dbtype'] = $GLOBALS['gEnv']['site']['data']['sitedbtype'];
         $dbargs['dbname'] = $GLOBALS['gEnv']['site']['data']['sitedbname'];
         $dbargs['dbhost'] = $GLOBALS['gEnv']['site']['data']['sitedbhost'];
         $dbargs['dbport'] = $GLOBALS['gEnv']['site']['data']['sitedbport'];
         $dbargs['dbuser'] = $GLOBALS['gEnv']['site']['data']['sitedbuser'];
         $dbargs['dbpass'] = $GLOBALS['gEnv']['site']['data']['sitedbpassword'];
         $dbargs['dblog'] = $GLOBALS['gEnv']['site']['data']['sitedblog'];
         $GLOBALS['gEnv']['site']['dblog'] =& $GLOBALS['gEnv']['site']['data']['sitedblog'];
         $db_fact = new DBLayerFactory();
         $GLOBALS['gEnv']['site']['db'] = $db_fact->NewDBLayer($dbargs);
         $env['db'] = $GLOBALS['gEnv']['site']['db'];
         if (!$GLOBALS['gEnv']['site']['db']->Connect($dbargs)) {
             if (!defined('MISC_LIBRARY')) {
                 include LIBRARY_PATH . 'misc.library';
             }
             $adloc = new Locale('amp_misc_auth', $GLOBALS['gEnv']['root']['locale']['language']);
             AmpDie($adloc->GetStr('nodb'));
         }
         // Hui theme
         //
         $tmpquery = $GLOBALS['gEnv']['site']['db']->Execute('SELECT val ' . 'FROM sitesettings ' . 'WHERE keyname=' . $GLOBALS['gEnv']['site']['db']->Format_Text('sitetheme'));
         $GLOBALS['gEnv']['site']['theme'] = $tmpquery->Fields('val');
         // Site cgi
         //
         if (strlen($GLOBALS['gEnv']['site']['data']['siteurl'])) {
             $tmp = parse_url($GLOBALS['gEnv']['site']['data']['siteurl']);
             $GLOBALS['gEnv']['site']['cgi'] = $tmp['scheme'] . '://' . $tmp['host'] . CGI_URL;
         } else {
             $GLOBALS['gEnv']['site']['cgi'] = CGI_URL;
         }
         $env['sitecgi'] =& $GLOBALS['gEnv']['site']['cgi'];
         unset($tmp);
         // Site country
         //
         $tmpquery = $GLOBALS['gEnv']['site']['db']->Execute('SELECT val ' . 'FROM sitesettings ' . 'WHERE keyname=' . $GLOBALS['gEnv']['site']['db']->Format_Text('sitecountry'));
         $GLOBALS['gEnv']['site']['locale']['country'] = strlen($tmpquery->Fields('val')) ? $tmpquery->Fields('val') : AMP_COUNTRY;
         $env['sitecountry'] = $GLOBALS['gEnv']['site']['locale']['country'];
         // Site language
         //
         $tmpquery = $GLOBALS['gEnv']['site']['db']->Execute('SELECT val ' . 'FROM sitesettings ' . 'WHERE keyname=' . $GLOBALS['gEnv']['site']['db']->Format_Text('sitelanguage'));
         $GLOBALS['gEnv']['site']['locale']['language'] = strlen($tmpquery->Fields('val')) ? $tmpquery->Fields('val') : AMP_LANG;
         $env['sitelanguage'] = $GLOBALS['gEnv']['site']['locale']['language'];
         // User
         //
         if (!strlen($userId)) {
             $userId = $siteId;
         }
         // User id
         //
         $GLOBALS['gEnv']['user']['id'] = $userId;
         $env['currentuser'] =& $GLOBALS['gEnv']['user']['id'];
         // Hui theme
         //
         $tmpquery = $GLOBALS['gEnv']['site']['db']->Execute('SELECT val ' . 'FROM sitesettings ' . 'WHERE keyname=' . $GLOBALS['gEnv']['site']['db']->Format_Text($GLOBALS['gEnv']['user']['id'] . '-theme'));
         $GLOBALS['gEnv']['user']['theme'] = $tmpquery->Fields('val');
         if (!strlen($GLOBALS['gEnv']['user']['theme'])) {
             if (!strlen($GLOBALS['gEnv']['site']['theme'])) {
                 import('com.solarix.ampoliros.module.ModuleConfig');
                 $mod_cfg = new ModuleConfig($GLOBALS['gEnv']['root']['db'], 'ampoliros');
                 if (strlen($mod_cfg->GetKey('hui-root-theme'))) {
                     $GLOBALS['gEnv']['site']['theme'] = $mod_cfg->GetKey('hui-root-theme');
                     if (!strlen($GLOBALS['gEnv']['site']['theme'])) {
                         $GLOBALS['gEnv']['site']['theme'] = $GLOBALS['gEnv']['hui']['theme']['default'];
                     }
                 } else {
                     $GLOBALS['gEnv']['site']['theme'] = $GLOBALS['gEnv']['hui']['theme']['default'];
                 }
                 unset($mod_cfg);
             }
             $GLOBALS['gEnv']['user']['theme'] = $GLOBALS['gEnv']['site']['theme'];
         }
         $GLOBALS['gEnv']['hui']['theme']['name'] = $GLOBALS['gEnv']['user']['theme'];
         // User country
         //
         $tmpquery = $GLOBALS['gEnv']['site']['db']->Execute('SELECT val FROM sitesettings WHERE keyname=' . $GLOBALS['gEnv']['site']['db']->Format_Text($GLOBALS['gEnv']['user']['id'] . '-country'));
         $GLOBALS['gEnv']['user']['locale']['country'] = $env[$GLOBALS['gEnv']['user']['id'] . '-country'] = strlen($tmpquery->Fields('val')) ? $tmpquery->Fields('val') : $GLOBALS['gEnv']['site']['locale']['country'];
         $env['currentuser-country'] = $GLOBALS['gEnv']['user']['locale']['country'];
         // User language
         //
         $tmpquery = $GLOBALS['gEnv']['site']['db']->Execute('SELECT val FROM sitesettings WHERE keyname=' . $GLOBALS['gEnv']['site']['db']->Format_Text($GLOBALS['gEnv']['user']['id'] . '-language'));
         $GLOBALS['gEnv']['user']['locale']['language'] = $env[$GLOBALS['gEnv']['user']['id'] . '-language'] = strlen($tmpquery->Fields('val')) ? $tmpquery->Fields('val') : $GLOBALS['gEnv']['site']['locale']['language'];
         $env['currentuser-language'] = $GLOBALS['gEnv']['user']['locale']['language'];
         $env['sitelocale'] = $GLOBALS['gEnv']['user']['locale']['language'];
         // Old one
         $tmpquery = $GLOBALS['gEnv']['root']['db']->Execute('SELECT id,fname,lname,email,groupid FROM users WHERE username='******'gEnv']['root']['db']->Format_Text($GLOBALS['gEnv']['user']['id']));
         // User datas
         //
         $GLOBALS['gEnv']['user']['group'] = $tmpquery->Fields('groupid');
         $GLOBALS['gEnv']['user']['serial'] = $tmpquery->Fields('id');
         $GLOBALS['gEnv']['user']['data']['lname'] = $tmpquery->Fields('lname');
         $GLOBALS['gEnv']['user']['data']['fname'] = $tmpquery->Fields('fname');
         $GLOBALS['gEnv']['user']['data']['email'] = $tmpquery->Fields('email');
         $env['currentusercname'] = $tmpquery->Fields('fname') . ' ' . $tmpquery->Fields('lname');
         $env['currentgroupserial'] = $GLOBALS['gEnv']['user']['group'];
         $env['currentuserserial'] = $GLOBALS['gEnv']['user']['serial'];
         $tmpquery->Free();
         $result = true;
     }
     $GLOBALS['gEnv']['runtime']['site']['init'] = true;
     return $result;
 }
 public function update($updatemode, $params, $siteprescript = '', $sitepostscript = '')
 {
     $result = FALSE;
     if ($this->site) {
         $sitesquery = $this->ampdb->Execute('SELECT * FROM sites');
         $modquery = $this->ampdb->Execute('SELECT id FROM modules WHERE modid=' . $this->ampdb->Format_Text($this->modname));
         $modid = $modquery->Fields('id');
     }
     switch ($updatemode) {
         case Module::UPDATE_MODE_ADD:
             if ($this->DoInstallAction($params)) {
                 $result = TRUE;
                 if ($this->site) {
                     if ($sitesquery->NumRows() > 0) {
                         while (!$sitesquery->eof) {
                             $sitedata = $sitesquery->Fields();
                             $actquery = $this->ampdb->Execute('SELECT * FROM activemodules WHERE siteid=' . (int) $sitedata['id'] . ' AND moduleid=' . (int) $modid);
                             if ($actquery->NumRows()) {
                                 $args['dbtype'] = $sitedata['sitedbtype'];
                                 $args['dbname'] = $sitedata['sitedbname'];
                                 $args['dbhost'] = $sitedata['sitedbhost'];
                                 $args['dbport'] = $sitedata['sitedbport'];
                                 $args['dbuser'] = $sitedata['sitedbuser'];
                                 $args['dbpass'] = $sitedata['sitedbpassword'];
                                 $args['dblog'] = $sitedata['sitedblog'];
                                 import('com.solarix.ampoliros.db.DBLayerFactory');
                                 $db_fact = new DBLayerFactory();
                                 $this->sitedb = $db_fact->NewDBLayer($args);
                                 $this->sitedb->Connect($args);
                                 if (!$this->Enable($sitesquery->Fields('id'), $params)) {
                                     $result = FALSE;
                                 }
                             }
                             $actquery->Free();
                             $sitesquery->MoveNext();
                         }
                     }
                 }
             }
             break;
         case Module::UPDATE_MODE_REMOVE:
             if ($this->DoUninstallAction($params)) {
                 $result = TRUE;
                 if ($this->site) {
                     if ($sitesquery->NumRows() > 0) {
                         while (!$sitesquery->eof) {
                             $sitedata = $sitesquery->Fields();
                             $actquery = $this->ampdb->Execute('SELECT * FROM activemodules WHERE siteid=' . (int) $sitedata['id'] . ' AND moduleid=' . (int) $modid);
                             if ($actquery->NumRows()) {
                                 $args['dbtype'] = $sitedata['sitedbtype'];
                                 $args['dbname'] = $sitedata['sitedbname'];
                                 $args['dbhost'] = $sitedata['sitedbhost'];
                                 $args['dbport'] = $sitedata['sitedbport'];
                                 $args['dbuser'] = $sitedata['sitedbuser'];
                                 $args['dbpass'] = $sitedata['sitedbpassword'];
                                 $args['dblog'] = $sitedata['sitedblog'];
                                 import('com.solarix.ampoliros.db.DBLayerFactory');
                                 $db_fact = new DBLayerFactory();
                                 $this->sitedb = $db_fact->NewDBLayer($args);
                                 $this->sitedb->Connect($args);
                                 if (!$this->Disable($sitesquery->Fields('id'), $params)) {
                                     $result = FALSE;
                                 }
                             }
                             $actquery->Free();
                             $sitesquery->MoveNext();
                         }
                     }
                 }
             }
             break;
         case Module::UPDATE_MODE_CHANGE:
             if ($this->DoUpdateAction($params)) {
                 $result = TRUE;
                 if ($this->site) {
                     if ($sitesquery->NumRows() > 0) {
                         while (!$sitesquery->eof) {
                             $sitedata = $sitesquery->Fields();
                             $actquery = $this->ampdb->Execute('SELECT * FROM activemodules WHERE siteid=' . (int) $sitedata['id'] . ' AND moduleid=' . (int) $modid);
                             if ($actquery->NumRows()) {
                                 $args['dbtype'] = $sitedata['sitedbtype'];
                                 $args['dbname'] = $sitedata['sitedbname'];
                                 $args['dbhost'] = $sitedata['sitedbhost'];
                                 $args['dbport'] = $sitedata['sitedbport'];
                                 $args['dbuser'] = $sitedata['sitedbuser'];
                                 $args['dbpass'] = $sitedata['sitedbpassword'];
                                 $args['dblog'] = $sitedata['sitedblog'];
                                 import('com.solarix.ampoliros.db.DBLayerFactory');
                                 $db_fact = new DBLayerFactory();
                                 $this->sitedb = $db_fact->NewDBLayer($args);
                                 $this->sitedb->Connect($args);
                                 if (strlen($siteprescript) and file_exists($siteprescript)) {
                                     include $siteprescript;
                                 }
                                 if (!$this->DoUpdateSiteAction($sitesquery->Fields('id'), $params)) {
                                     $result = FALSE;
                                 }
                                 if (strlen($sitepostscript) and file_exists($sitepostscript)) {
                                     include $sitepostscript;
                                 }
                             }
                             $actquery->Free();
                             $sitesquery->MoveNext();
                         }
                     }
                 }
             }
             break;
         default:
             import('com.solarix.ampoliros.io.log.Logger');
             $log = new Logger(AMP_LOG);
             $log->LogEvent('ampoliros.modules_library.moduleelement_class.update', 'Invalid update mode', LOGGER_ERROR);
             break;
     }
     if ($this->site) {
         $sitesquery->Free();
         $modquery->Free();
     }
     return $result;
 }
Beispiel #3
0
 if (!file_exists(TMP_PATH . '.languageset')) {
     @touch(TMP_PATH . '.settinglanguage', time());
     // !!! $page->add( new HTMLScript( 'JavaScript1.2', 'parent.frames.sum.location.reload()', '' ) );
     $pass_data = $pass_disp->GetEventData();
     $country = $pass_data['country'];
     if (!strlen($country)) {
         $country = AMP_COUNTRY;
     }
     $args['dbname'] = AMP_DBNAME;
     $args['dbhost'] = AMP_DBHOST;
     $args['dbport'] = AMP_DBPORT;
     $args['dbuser'] = AMP_DBUSER;
     $args['dbpass'] = AMP_DBPASS;
     $args['dbtype'] = AMP_DBTYPE;
     $args['dblog'] = AMP_DBLOG;
     $layer = new DBLayerFactory();
     $tmpdb = $layer->NewDBLayer($args);
     if ($tmpdb->Connect($args)) {
         $loc_country = new LocaleCountry($country);
         $country_language = $loc_country->Language();
         $language_locale = new Locale('amp_misc_locale', AMP_LANG);
         $selected_language = $pass_disp->GetEventData();
         $selected_language = $selected_language['language'];
         $hui_vgroup = new HuiVertGroup('vgroup');
         $language_query =& $tmpdb->Execute('SELECT * ' . 'FROM languages');
         while (!$language_query->eof) {
             $languages[$language_query->Fields('langshort')] = $language_locale->GetStr($language_query->Fields('langname'));
             $language_query->MoveNext();
         }
         $hui_locale_grid = new HuiGrid('localegrid');
         $hui_locale_grid->AddChild(new HuiLabel('languagelabel', array('label' => $amp_locale->GetStr('language_label'))), 0, 0);
Beispiel #4
0
 function Disable($siteid)
 {
     $result = FALSE;
     import('com.solarix.ampoliros.util.Hook');
     $hook = new Hook($this->ampdb, 'ampoliros', 'module.disable');
     if ($hook->CallHooks('calltime', $this, array('siteserial' => $siteid, 'modserial' => $this->serial)) == HOOK_RESULT_OK) {
         if ($this->serial) {
             // Checks if the module exists in modules table
             //
             $modquery =& $this->ampdb->Execute('SELECT * FROM modules WHERE id=' . (int) $this->serial);
             if ($modquery->NumRows() == 1) {
                 $moddata = $modquery->Fields();
                 if ($moddata['onlyextension'] != $this->ampdb->fmttrue) {
                     // Checks if the structure file still exists
                     //
                     if (file_exists(MODULE_PATH . $moddata['modid'] . '/' . Module::STRUCTURE_FILE)) {
                         $this->modname = $moddata['modid'];
                         $sitequery = $this->ampdb->Execute('SELECT * FROM sites WHERE id=' . $this->ampdb->Format_Text((int) $siteid));
                         $sitedata = $sitequery->Fields();
                         $args['dbtype'] = $sitedata['sitedbtype'];
                         $args['dbname'] = $sitedata['sitedbname'];
                         $args['dbhost'] = $sitedata['sitedbhost'];
                         $args['dbport'] = $sitedata['sitedbport'];
                         $args['dbuser'] = $sitedata['sitedbuser'];
                         $args['dbpass'] = $sitedata['sitedbpassword'];
                         $args['dblog'] = $sitedata['sitedblog'];
                         import('com.solarix.ampoliros.db.DBLayerFactory');
                         $db_fact = new DBLayerFactory();
                         $this->sitedb = $db_fact->NewDBLayer($args);
                         $this->sitedb->Connect($args);
                         // Dependencies check
                         //
                         $this->unmetdeps = array();
                         $this->unmetsuggs = array();
                         $moddeps = new ModuleDep($this->ampdb);
                         $pendingdeps = $moddeps->CheckSiteDependingModules($this->modname, $sitedata['siteid'], FALSE);
                         $modenabled = $moddeps->IsEnabled($this->modname, $sitedata['siteid']);
                         // If dependencies are ok, go on
                         //
                         if ($pendingdeps == FALSE and $modenabled == TRUE) {
                             $result = $this->HandleStructure(MODULE_PATH . $moddata['modid'] . '/' . Module::STRUCTURE_FILE, Module::INSTALL_MODE_DISABLE, MODULE_PATH . $moddata['modid'] . '/', $siteid);
                             $modquery = $this->ampdb->Execute('SELECT id FROM modules WHERE modid=' . $this->ampdb->Format_Text($this->modname));
                             $this->ampdb->Execute('DELETE FROM activemodules WHERE moduleid=' . (int) $this->serial . ' AND siteid=' . $this->ampdb->Format_Text($siteid));
                             $this->ampdb->Execute('DELETE FROM disabledsubmodules WHERE moduleid=' . (int) $this->serial . ' AND siteid=' . (int) $siteid);
                             if ($GLOBALS['gEnv']['core']['config']->Value('ALERT_ON_MODULE_SITE_OPERATION') == '1') {
                                 Carthag::import('com.solarix.ampoliros.security.SecurityLayer');
                                 $amp_security = new SecurityLayer();
                                 $amp_security->SendAlert('Module ' . $moddata['modid'] . ' has been disabled from site ' . $sitedata['siteid']);
                                 unset($amp_security);
                             }
                             if ($hook->CallHooks('moduledisabled', $this, array('siteserial' => $siteid, 'modserial' => $this->serial)) != HOOK_RESULT_OK) {
                                 $result = false;
                             }
                         } else {
                             if ($modenabled == FALSE) {
                             } else {
                                 $this->unmetdeps = $pendingdeps;
                             }
                         }
                         //if ( $result == TRUE ) $this->mLog->LogEvent( 'Ampoliros', 'Uninstalled module '.$this->modname, LOGGER_NOTICE );
                         $sitequery->Free();
                     } else {
                         import('com.solarix.ampoliros.io.log.Logger');
                         $log = new Logger(AMP_LOG);
                         $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'Structure file ' . MODULE_PATH . $moddata['modid'] . '/' . Module::STRUCTURE_FILE . ' for module ' . $moddata['modid'] . ' was not found', LOGGER_ERROR);
                     }
                 } else {
                     import('com.solarix.ampoliros.io.log.Logger');
                     $log = new Logger(AMP_LOG);
                     $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'Tried to disable module ' . $moddata['modid'] . ', but it is an extension only module', LOGGER_ERROR);
                 }
             } else {
                 import('com.solarix.ampoliros.io.log.Logger');
                 $log = new Logger(AMP_LOG);
                 $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'A module with serial ' . $this->serial . ' was not found in modules table', LOGGER_ERROR);
             }
             $modquery->Free();
         } else {
             import('com.solarix.ampoliros.io.log.Logger');
             $log = new Logger(AMP_LOG);
             $log->LogEvent('ampoliros.modules_library.modules_class.disable', 'Empty module serial', LOGGER_ERROR);
         }
     }
     return $result;
 }
Beispiel #5
0
 public function create($sitedata, $createDb = true)
 {
     $result = false;
     $hook = new Hook($this->ampdb, 'ampoliros', 'site.create');
     if ($hook->CallHooks('calltime', $this, array('sitedata' => $sitedata)) == HOOK_RESULT_OK) {
         $goon = true;
         if ($GLOBALS['gEnv']['core']['edition'] == AMP_EDITION_ENTERPRISE) {
             $check_query =& $GLOBALS['gEnv']['root']['db']->Execute('SELECT count(*) AS sites ' . 'FROM sites');
             if ($check_query->Fields('sites') > 0) {
                 $goon = false;
             }
         }
         if ($goon) {
             // Default settings and settings tuning
             //
             $nextseq = $this->ampdb->NextSeqValue('sites_id_seq');
             $sitedata['siteid'] = $this->defopt(strtolower(str_replace(' ', '', trim($sitedata['siteid']))), $nextseq);
             //$sitedata['sitemd5id']            = md5( $sitedata['siteid'] );
             $sitedata['sitemd5id'] = md5(microtime());
             $sitedata['sitepath'] = $this->defopt(trim($sitedata['sitepath']), SITES_TREE . $sitedata['siteid']);
             $sitedata['sitename'] = $this->defopt(trim($sitedata['sitename']), $sitedata['siteid'] . ' site');
             $sitedata['sitepassword'] = $this->defopt(trim($sitedata['sitepassword']), $sitedata['siteid']);
             $sitedata['sitedbname'] = $this->defopt(strtolower(str_replace(' ', '', trim($sitedata['sitedbname']))), 'amp' . $sitedata['siteid'] . 'site');
             $sitedata['sitedbhost'] = $this->defopt(trim($sitedata['sitedbhost']), AMP_DBHOST);
             $sitedata['sitedbport'] = $this->defopt(trim($sitedata['sitedbport']), AMP_DBPORT);
             $sitedata['sitedbuser'] = $this->defopt(str_replace(' ', '', trim($sitedata['sitedbuser'])), AMP_DBUSER);
             $sitedata['sitedbpassword'] = $this->defopt(trim($sitedata['sitedbpassword']), AMP_DBPASS);
             $sitedata['sitedblog'] = $this->defopt(trim($sitedata['sitedblog']), SITESTUFF_PATH . $sitedata['siteid'] . '/log/db.log');
             $sitedata['sitedbtype'] = $this->defopt(trim($sitedata['sitedbtype']), AMP_DBTYPE);
             $sitedata['sitecreationdate'] = isset($sitedata['sitecreationdate']) ? trim($sitedata['sitecreationdate']) : time();
             $sitedata['siteexpirydate'] = isset($sitedata['siteexpirytime']) ? trim($sitedata['siteexpirydate']) : time();
             $sitedata['siteactive'] = isset($sitedata['siteactive']) ? $sitedata['siteactive'] : $this->ampdb->fmttrue;
             $sitedata['maxusers'] = isset($sitedata['maxusers']) ? $sitedata['maxusers'] : '0';
             if (!isset($sitedata['sitenotes'])) {
                 $sitedata['sitenotes'] = '';
             }
             $args['dbtype'] = strlen($sitedata['sitedbtype']) ? $sitedata['sitedbtype'] : AMP_DBTYPE;
             $args['dbname'] = $sitedata['sitedbname'];
             $args['dbhost'] = $sitedata['sitedbhost'];
             $args['dbport'] = $sitedata['sitedbport'];
             $args['dbuser'] = $sitedata['sitedbuser'];
             $args['dbpass'] = $sitedata['sitedbpassword'];
             $args['dblog'] = $sitedata['sitedblog'];
             if ($this->ampdb->Execute('INSERT INTO sites VALUES ( ' . $nextseq . ',' . $this->ampdb->Format_Text($sitedata['siteid']) . ',' . $this->ampdb->Format_Text($sitedata['sitemd5id']) . ',' . $this->ampdb->Format_Text($sitedata['sitepath']) . ',' . $this->ampdb->Format_Text($sitedata['sitename']) . ',' . $this->ampdb->Format_Text(md5($sitedata['sitepassword'])) . ',' . $this->ampdb->Format_Text($sitedata['siteurl']) . ',' . $this->ampdb->Format_Text($sitedata['sitedbname']) . ',' . $this->ampdb->Format_Text($sitedata['sitedbhost']) . ',' . $this->ampdb->Format_Text($sitedata['sitedbport']) . ',' . $this->ampdb->Format_Text($sitedata['sitedbuser']) . ',' . $this->ampdb->Format_Text($sitedata['sitedbpassword']) . ',' . $this->ampdb->Format_Text($sitedata['sitedblog']) . ',' . $this->ampdb->Format_Text($sitedata['sitedbtype']) . ',' . $this->ampdb->Format_Date($sitedata['sitecreationdate']) . ',' . $this->ampdb->Format_Date($sitedata['siteexpirydate']) . ',' . $this->ampdb->Format_Text($sitedata['siteactive']) . ',' . $this->ampdb->Format_Text($sitedata['sitenotes']) . ',' . $sitedata['maxusers'] . ')')) {
                 $this->siteid = $sitedata['siteid'];
                 $this->siteserial = $nextseq;
                 $this->sitelog = new Logger(SITESTUFF_PATH . $sitedata['siteid'] . '/log/site.log');
                 // Directory tree creation
                 $this->makedir($sitedata['sitepath']);
                 $this->makedir($sitedata['sitepath'] . '/media');
                 $this->makedir(SITESTUFF_PATH . $sitedata['siteid']);
                 $this->makedir(SITESTUFF_PATH . $sitedata['siteid'] . '/log');
                 $this->makedir(SITESTUFF_PATH . $sitedata['siteid'] . '/templates');
                 $this->makedir(SITESTUFF_PATH . $sitedata['siteid'] . '/etc');
                 // Site database population
                 //if ( strcmp( $sitedata['sitedbhost'], AMP_DBHOST ) == 0 )
                 //{
                 // Site database host is the same of the mall one
                 // Database creation
                 $args['name'] = $sitedata['sitedbname'];
                 //$this->ampdb->createdb( $args );
                 import('com.solarix.ampoliros.db.DBLayerFactory');
                 $db_fact = new DBLayerFactory();
                 $tmpdb = $db_fact->NewDBLayer($args);
                 if ($createDb) {
                     if ($tmpdb->Connect($args)) {
                         $tmpdb->DropDB($args);
                         $tmpdb->Close();
                     }
                 }
                 if (!$createDb or $created = $tmpdb->CreateDB($args)) {
                     if (isset($created) and $created == true) {
                         $this->sitelog->LogEvent($sitedata['siteid'], 'Database ' . $args['dbname'] . ' created', LOGGER_NOTICE);
                     }
                     if ($tmpdb->Connect($args)) {
                         $this->sitedb =& $tmpdb;
                         //$xmldb = new XmlDb( $tmpdb, DBLAYER_PARSER_SQL_CREATE );
                         $tmpquery = $this->ampdb->Execute('SELECT id ' . 'FROM modules ' . 'WHERE modid=' . $this->ampdb->Format_Text('ampoliros'));
                         if ($this->EnableModule($tmpquery->Fields('id'))) {
                             //$tmpsets = new SiteSettings( $tmpdb );
                             //$tmpsets->EditKey( 'sitelocale', AMP_LANG );
                             $tmpuser = new User($this->ampdb, $nextseq);
                             $tmpuser->CreateAdminUser($sitedata['siteid'], $sitedata['sitepassword']);
                             import('com.solarix.ampoliros.io.log.Logger');
                             $log = new Logger(AMP_LOG);
                             $log->LogEvent($sitedata['siteid'], 'Created new site ' . $sitedata['siteid'], LOGGER_NOTICE);
                             $this->sitelog->LogEvent($sitedata['siteid'], 'Created site ' . $sitedata['siteid'], LOGGER_NOTICE);
                             if ($hook->CallHooks('sitecreated', $this, array('sitedata' => $sitedata)) != HOOK_RESULT_ABORT) {
                                 $result = true;
                             }
                             global $gEnv;
                             if ($gEnv['core']['config']->Value('ALERT_ON_SITE_OPERATION') == '1') {
                                 Carthag::import('com.solarix.ampoliros.security.SecurityLayer');
                                 $amp_security = new SecurityLayer();
                                 $amp_security->SendAlert('A site has been created with id ' . $sitedata['siteid']);
                                 unset($amp_security);
                             }
                         } else {
                             import('com.solarix.ampoliros.io.log.Logger');
                             $log = new Logger(AMP_LOG);
                             $log->LogEvent('ampoliros.sites_library.site_class.create', 'Unable to enable Ampoliros to the site', LOGGER_ERROR);
                         }
                     } else {
                         import('com.solarix.ampoliros.io.log.Logger');
                         $log = new Logger(AMP_LOG);
                         $log->LogEvent('ampoliros.sites_library.site_class.create', 'Unable to connect to site database', LOGGER_ERROR);
                     }
                 } else {
                     import('com.solarix.ampoliros.io.log.Logger');
                     $log = new Logger(AMP_LOG);
                     $log->LogEvent('ampoliros.sites_library.site_class.create', 'Unable to create site database', LOGGER_ERROR);
                 }
             } else {
                 import('com.solarix.ampoliros.io.log.Logger');
                 $log = new Logger(AMP_LOG);
                 $log->LogEvent('ampoliros.sites_library.site_class.create', 'Unable to insert site row in sites table', LOGGER_ERROR);
             }
         } else {
             import('com.solarix.ampoliros.io.log.Logger');
             $log = new Logger(AMP_LOG);
             $log->LogEvent('ampoliros.sites_library.site_class.create', 'Tried to create another site in Enterprise edition', LOGGER_WARNING);
         }
     }
     return $result;
 }