/** * get the table * @param string $table * @param int $from * @param int $limit * @return string $html */ public function getTable($table, $from, $limit = 100) { $total = q::numRows('account')->fetch(); $p = new pagination($total); $rows = q::select($table)->limit($p->from, $limit)->fetch(); $str = "<table border =1><tr>"; $str .= $this->getTableHeaders($table); $str .= $this->getTableRows($rows); $str .= "</tr></table>"; $str .= $p->getPagerHTML(); return $str; }
/** * Get all jobs in a queue, which needs to be executed. Only name * if required * @param string $name * @param mixed $uniqueid if null then only the above param 'name' will be used * @param mixed $done null | 1 | 0 * @return array $rows */ public function getQueueRows($name, $uniqueid = null, $done = 0) { q::select($this->queue)->filter('name =', $name); if (!is_null($uniqueid)) { q::condition('AND'); q::filter('uniqueid =', $uniqueid); } if (is_int($done)) { q::condition('AND'); q::filter('done =', $done); } $rows = q::fetch(); return $rows; }
/** * method for loading menus. All Main menu entries is generated from * database, while all module or submodule menus are generated from * files (menu.inc). * */ public function loadMenus() { $num = uri::getInstance()->numFragments(); // always a module menu in web mode self::$menu['main'] = q::select('menus')->filter('parent =', 0)->condition('AND')->filter('admin_only =', 0)->order('weight')->fetch(); // admin item are special if (session::isAdmin()) { self::$menu['admin'] = q::select('menus')->filter('admin_only =', 1)->condition('OR')->filter('section !=', '')->order('weight')->fetch(); } self::setMainMenuTitles(); // if status is set we don't load module menus. Must be 404 or 403. // we then return empty array. module loader will know what to do when // including correct error pages. No menus from normal main module // should then be loaded. if (!empty(moduleloader::$status)) { return array(); } // get base menu from file. Base menu is always loaded if found. // we decide this from num fragments in uri. $module = uri::getInstance()->fragment(0); // if no module it must be 'frontpage_module' set // in configuration if (!$module) { $module = conf::getMainIni('frontpage_module'); $menu = self::getBaseModuleMenu($module); self::$menu['module'] = array_merge(self::$menu['module'], $menu); return; } // main module, e.g content if ($num >= 2) { $menu = self::getBaseModuleMenu($module); self::$menu['module'] = array_merge(self::$menu['module'], $menu); } // sub module e.g. content/article if ($num > 2) { $sub = uri::getInstance()->fragment(0) . '/' . uri::getInstance()->fragment(1); self::$menu['sub'] = self::getSubMenu($sub); } }
/** * Run the system */ 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(); if (conf::getMainIni('debug')) { log::enableDebug(); } // set public file folder in file class file::$basePath = conf::getFullFilesPath(); // 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_conn = array('url' => conf::getMainIni('url'), 'username' => conf::getMainIni('username'), 'password' => conf::getMainIni('password'), 'db_init' => conf::getMainIni('db_init')); // Other options // db_dont_persist = 0 // dont_die = 0 // Set to one and the connection don't die because of // e.g. no database etc. This will return NO_DB_CONN as string //$url = conf::getMainIni('url'); connect::connect($db_conn); // 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 = []; if (moduleloader::moduleExists('settings')) { $db_settings = q::select('settings')->filter('id =', 1)->fetchSingle(); } // 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(); // Se if user is logged in with SESSION if (!session::isUser()) { // If not logged in check system cookie // This will start the session, if an appropiate cookie exists session::checkSystemCookie(); } // Check account $res = session::checkAccount(); if (!$res) { // Redirect to main page if user is not allowed // With current SESSION or COOKIE 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('lang')); // runlevel 5 $ml->runLevel(5); // load routes if any dispatch::setDbRoutes(); // check db routes or load defaults $db_route = dispatch::getMatchRoutes(); if (!$db_route) { $ml->setModuleInfo(); $ml->initModule(); } else { dispatch::includeModule($db_route['method']); } // After module has been loaded. // You can e.g. override module ini settings $ml->runLevel(6); // 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']; }
/** * * Method checks an account based on session user_id. It checks: * a) if an account is locked * b) if the current user_id does not correspond to an account. * * In both cases all sessions are killed. * Method is run at boot. In diversen\boot * * @return void */ public static function checkAccount() { $user_id = session::getUserId(); if ($user_id) { $a = q::select('account')->filter('id =', $user_id)->fetchSingle(); // user may have been deleted if (empty($a)) { self::killSessionAll($user_id); return false; } if ($a['locked'] == 1) { self::killSessionAll($user_id); return false; } } return true; }
public function displayAll($rows) { $str = table::tableBegin(array('class' => 'uk-table uk-table-hover uk-table-striped uk-table-condensed')); foreach ($rows as $row) { $str .= table::trBegin(); $str .= table::td($row['username'], array('class' => 'uk-width-3-10')); $str .= table::td($row['email']); // Comment $dancer = q::select('dancer')->filter('user_id= ', $row['id'])->fetchSingle(); if (!empty($dancer)) { $str .= table::td(html::specialEncode($dancer['comment'])); } else { $str .= table::td(''); } $str .= table::trEnd(); } $str .= table::tableEnd(); echo $str; }
/** * for for selecting a partner */ public function formPartner() { $ary = q::select('dancer')->filter('user_id =', session::getUserId())->fetchSingle(); $f = new html(); $f->init($ary, 'submit', true); $f->formStart(); $f->legend('Basis data - ret eller indsæt'); $account = user::getAccount(session::getUserId()); $opt = array('disabled' => 'disabled'); $f->label('username', 'Dit navn'); $f->text('username', $account['username'], $opt); $sex = array('0' => 'Vælg køn', '1' => 'Kvinde', '2' => 'Mand'); $f->label('sex', 'Dit køn'); $f->selectAry('sex', $sex); $f->label('comment', 'Evt. kommentar'); $f->textareaSmall('comment'); // Partner $partners = $this->getDancersForDropdown(); $rows = []; $rows[0] = 'Ingen partner'; foreach ($partners as $partner) { if ($partner['username'] == $account['username']) { continue; } $rows[$partner['id']] = $partner['username']; } $label = <<<EOF Har du en partner, så vælg en fra listen. Når din partner har valgt dig, så udgør i et par, og i kan vælge en halv kvadrille EOF; $f->label('partner', $label); $f->selectAry('partner', $rows); $f->label('base'); $f->submit('submit', 'Opdater'); $f->formEnd(); echo $f->getStr(); }
/** * delete a string from cache * @param string $module * @param int $id * @return boolean $res db result */ private static function deleteDb($module, $id) { $id = self::generateId($module, $id); $row = q::select(self::$table)->filter('id =', $id)->fetchSingle(); if (!empty($row)) { return q::delete(self::$table)->filter('id =', $id)->exec(); } }