/** * function for inserting user * @param array $values * @return boolean $res */ function useradd_db_insert($values) { $database = admin::getDbInfo(); if (!$database) { return db_no_url(); } admin::changeDB($database['dbname']); $db = new db(); $res = $db->insert('account', $values); return $res; }
/** * Delete a module from registry * @return boolean true or throws an error on failure */ public function deleteRegistry() { $db = new db(); $result = $db->delete('modules', 'module_name', $this->installInfo['NAME']); return $result; }
/** * function that alllows the install to add a user */ function web_install_add_user() { $layout = new layout('zimpleza'); $errors = array(); if (isset($_POST['submit'])) { $_POST = html::specialEncode($_POST); if (empty($_POST['pass1'])) { $errors[] = 'Please enter a password'; } if ($_POST['pass1'] != $_POST['pass2']) { $errors[] = 'Not same passwords'; } if (empty($_POST['email'])) { $errors[] = 'Please enter an email'; } if (!empty($errors)) { html::errors($errors); } else { $db = new db(); $_POST = html::specialDecode($_POST); $values = array(); $values['email'] = $_POST['email']; $values['password'] = md5($_POST['pass1']); // MD5 $values['username'] = $_POST['email']; $values['verified'] = 1; $values['admin'] = 1; $values['super'] = 1; $values['type'] = 'email'; $db->insert('account', $values); http::locationHeader("/account/login/index", 'Account created. You may log in'); //web_install_add_user(); } } web_install_user_form(); }
/** * function for inserting user * @param array $values * @return boolean $res */ function useradd_db_insert($values) { $database = admin::getDbInfo(conf::getMainIni('url')); if (!$database) { return db_no_url(); } $db = new db(); $res = $db->insert('account', $values); return $res; }
/** * method for getting child menus to a module. * @param string $module * @return array children menus items */ public static function getChildrenMenus($module) { $db = new db(); $children = $db->selectAll('menus', null, array('parent' => $module)); foreach ($children as $key => $val) { $children[$key]['title'] = lang::translate($val['title']); } return $children; }
/** * Checks if any table exist in database * @return boolean */ public static function tablesExists() { $db = new db(); $ret = $db->connect(array('dont_die' => 1)); if ($ret == 'NO_DB_CONN') { return false; } $info = admin::getDbInfo(); if (!$info) { common::echoMessage('No databse url in config.ini'); } if ($info['scheme'] == 'mysql' || $info['scheme'] == 'mysqli') { $rows = $db->selectQuery("SHOW TABLES"); if (empty($rows)) { return false; } return true; } if ($info['scheme'] == 'sqlite') { $sql = "SELECT name FROM sqlite_master WHERE type='table' AND name='modules'"; $rows = $db->selectQuery($sql); if (empty($rows)) { return false; } return true; } }
function get_table_create($table) { $db = new db(); $sql = "DESCRIBE {$table}"; return $db->selectQuery($sql); }
/** * Method for setting a profile's template * @param string $template * @return boolean $res */ public function setProfileTemplate($template = null) { $db = new db(); $db->connect(); if (isset($template)) { $this->profileTemplate = $template; } $ini_file = conf::pathHtdocs() . "/templates/{$this->profileTemplate}/{$this->profileTemplate}.ini"; $ini_file_dist = $ini_file . "-dist"; if (conf::isCli()) { if (file_exists($ini_file_dist)) { copy($ini_file_dist, $ini_file); } } $values = array('template' => $this->profileTemplate); return $db->update('settings', $values, 1); }
/** * method for killing all cookie sessions * unsets the system cookie and unsets session credentials * @param int $user_id */ public static function killAllSessions($user_id) { // only keep one system cookie (e.g. if user clears his cookies) $db = new db(); $db->delete('system_cookie', 'account_id', $user_id); setcookie("system_cookie", "", time() - 3600, "/"); unset($_SESSION['id'], $_SESSION['admin'], $_SESSION['super'], $_SESSION['account_type']); session_destroy(); }
/** * method for getting all modules from db. This is the first time we * connect to database. * * @return array $ary array with all rows from modules table */ public static function getAllModules() { if (!empty(self::$modules)) { return self::$modules; } static $modules = null; if ($modules) { return $modules; } // we connect here because this should be // the first time we use the database // in the system $db = new db(); return $db->selectAll('modules'); }
/** * function for getting an account * @param int $id user_id * @return array $row from account */ public static function getAccount($id = null) { if (!$id) { $id = session::getUserId(); } $db = new db(); $row = $db->selectOne('account', 'id', $id); return $row; }
/** * /event/user/halv */ public function helAction() { $this->checkAccess(); $eDb = new eDb(); $halv = $eDb->getUserHalvFromUserId(session::getUserId()); if (empty($halv)) { http::locationHeader('/event/user/index', 'Du skal være del af en halv kvadrille for at oprette en hel'); } http::prg(); if (isset($_POST['send'])) { $this->validateHel(); if (empty($this->errors)) { // Prepare $ary = db::prepareToPostArray(array('halv'), true); R::begin(); // Delete other hele $eDb->deleteHelFromUserId(session::getUserId()); // Create $id = $eDb->createHel($ary); // Set a better name $name = $eDb->getUsersStrFromHel($id); $bean = rb::getBean('hel', 'id', $id); $bean->name = $name; R::store($bean); $res = R::commit(); if (!$res) { R::rollback(); } http::locationHeader('/event/user/index'); } else { echo html::getErrors($this->errors); } } echo $this->formCreateHel(); }
/** * clone a complete database * @param string $database * @param string $newDatabase * @return boolean $res */ public static function cloneDB($database, $newDatabase) { $db = new db(); $rows = $db->selectQuery('show tables'); $tables = array(); foreach ($rows as $table) { $tables[] = array_pop($table); } $db->rawQuery("CREATE DATABASE `{$newDatabase}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci"); foreach ($tables as $cTable) { self::changeDB($newDatabase); $create = $db->rawQuery("CREATE TABLE {$cTable} LIKE " . $database . "." . $cTable); if (!$create) { $error = true; } $db->rawQuery("INSERT INTO {$cTable} SELECT * FROM " . $database . "." . $cTable); } return !isset($error) ? true : false; }
/** * function for getting an account * @param int $id user_id * @return array $row from account */ public static function getAccount($id) { $db = new db(); $row = $db->selectOne('account', 'id', $id); return $row; }
public function run() { // Register an autoloader for loading modules from mopdules dir $m = new modules(); $m->autoloadRegister(); // define HTML constants common::defineConstants(); // define global constants - based on base path conf::defineCommon(); // set include paths conf::setIncludePath(); // load config file conf::load(); // set log level - based on config.ini log::setLogLevel(); // utf-8 ini_set('default_charset', 'UTF-8'); // load config/config.ini // check if there exists a shared ini file // shared ini is used if we want to enable settings between hosts // which share same code base. // e.g. when updating all sites, it is a good idea to set the following flag // site_update = 1 // this flag will send correct 503 headers, when we are updating our site. // if site is being updaing we send temporarily headers // and display an error message if (conf::getMainIni('site_update')) { http::temporarilyUnavailable(); } // set a unified server_name if not set in config file. $server_name = conf::getMainIni('server_name'); if (!$server_name) { conf::setMainIni('server_name', $_SERVER['SERVER_NAME']); } // redirect to uniform server name is set in config.ini // e.g. www.testsite.com => testsite.com $server_redirect = conf::getMainIni('server_redirect'); if (isset($server_redirect)) { http::redirectHeaders($server_redirect); } // redirect to https is set in config.ini // force anything into ssl mode $server_force_ssl = conf::getMainIni('server_force_ssl'); if (isset($server_force_ssl)) { http::sslHeaders(); } // catch all output ob_start(); // Create a db connection $db = new db(); // init module loader. $ml = new moduleloader(); // initiate uri uri::getInstance(); // runlevel 1: merge db config $ml->runLevel(1); // select all db settings and merge them with ini file settings $db_settings = $db->selectOne('settings', 'id', 1); // merge db settings with config/config.ini settings // db settings override ini file settings conf::$vars['coscms_main'] = array_merge(conf::$vars['coscms_main'], $db_settings); // run level 2: set locales $ml->runLevel(2); // set locales intl::setLocale(); // set default timezone intl::setTimezone(); // runlevel 3 - init session $ml->runLevel(3); // start session session::initSession(); $res = session::checkAccount(); if (!$res) { // To prevent http::locationHeader('/'); } // set account timezone if enabled - can only be done after session // as user needs to be logged in intl::setAccountTimezone(); // run level 4 - load language $ml->runLevel(4); // load all language files $l = new lang(); $base = conf::pathBase(); $htdocs = conf::pathHtdocs(); $l->setDirsInsideDir("{$base}/modules/"); $l->setDirsInsideDir("{$htdocs}/templates/"); $l->setSingleDir("{$base}/vendor/diversen/simple-php-classes"); $l->setSingleDir("{$base}/vendor/diversen/simple-pager"); $l->loadLanguage(conf::getMainIni('language')); // runlevel 5 $ml->runLevel(5); // load routes if any dispatch::setDbRoutes(); // runlevel 6 $ml->runLevel(6); // check db routes or load by defaults $db_route = dispatch::getMatchRoutes(); if (!$db_route) { $ml->setModuleInfo(); $ml->initModule(); } // Init layout. Sets template name // load correct CSS. St menus if any. Etc. $layout = new layout(); // we first load menus here so we can se what happened when we // init our module. In case of a 404 not found error we don't want // to load module menus $layout->loadMenus(); // init blocks $layout->initBlocks(); // if any matching route was found we check for a method or function if ($db_route) { $str = dispatch::call($db_route['method']); } else { // or we use default module parsing $str = $ml->getParsedModule(); } // set view vars $vars['content'] = $str; // run level 7 $ml->runLevel(7); // echo module content echo $str = \mainTemplate::view($vars); conf::$vars['final_output'] = ob_get_contents(); ob_end_clean(); // Last divine intervention // e.g. Dom or Tidy $ml->runLevel(8); echo conf::$vars['final_output']; }