Example #1
0
 public function indexAction()
 {
     if (session::isAdmin()) {
         http::locationHeader('/event/admin/index?all=1');
     }
     if (session::isUser()) {
         http::locationHeader('/event/user/index');
     }
 }
Example #2
0
 /**
  * is account locked
  * @return boolean
  */
 public static function locked()
 {
     $user = self::getAccount(session::getUserId());
     if (empty($user)) {
         return false;
     }
     if ($user['locked'] == 1) {
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * Get all pairs as an array excluding pair with user
  * @return array $ary array of pairs
  */
 public function getFormHalveAry()
 {
     $eDb = new eDb();
     $halve = $eDb->getAllHalveNotInHele(session::getUserId());
     $ary = [];
     $ary[0] = 'Ingen halv valgt';
     foreach ($halve as $halv) {
         $ary[$halv['id']] = $halv['name'];
     }
     return $ary;
 }
Example #4
0
 /**
  * set account timezone (account_timezone)
  */
 public static function setAccountTimezone()
 {
     // set user timezone - only in web mode
     if (!conf::isCli()) {
         $timezone = cache::get('account_timezone', session::getUserId());
         if ($timezone) {
             date_default_timezone_set($timezone);
         } else {
             self::setCookieTimezone();
         }
     }
 }
Example #5
0
 /**
  * method for getting admin options
  * @param string $url base url
  * @param string $id the item
  * @param string $options
  * @return string $str menu options
  */
 public static function getAdminOptions($url, $id, $options = null)
 {
     $str = '';
     if (session::isAdmin()) {
         $str .= html::createLink("{$url}/edit/{$id}", lang::translate('Edit'));
         $str .= MENU_SUB_SEPARATOR;
         $str .= html::createLink("{$url}/delete/{$id}", lang::translate('Delete'));
     }
     if (isset($options['view'])) {
         $str .= MENU_SUB_SEPARATOR;
         $str .= html::createLink("{$url}/view/{$id}", lang::translate('View'));
     }
     return $str;
 }
Example #6
0
 /**
  * Display pairs as a HTML table
  * @param array $rows
  */
 public function displayPairs($rows)
 {
     $str = table::tableBegin(array('class' => 'uk-table uk-table-hover uk-table-striped uk-table-condensed'));
     foreach ($rows as $row) {
         $a = session::getAccount($row['user_a']);
         $b = session::getAccount($row['user_b']);
         $str .= table::trBegin();
         $str .= table::td($a['username'], array('class' => 'uk-width-3-10'));
         $str .= table::td($b['username'], array('class' => ''));
         $str .= table::trEnd();
     }
     $str .= table::tableEnd();
     echo $str;
 }
Example #7
0
 /**
  * transforms a menu array into a menu link
  * @param array $menu
  * @return string $str
  */
 public static function parseMenuLinkFromArray($menu)
 {
     if (!isset($menu['extra'])) {
         $menu['extra'] = array();
     }
     if (isset($menu['auth']) && !empty($menu['auth'])) {
         if (!session::checkAccessClean($menu['auth'])) {
             return false;
         }
         return html::createLink($menu['url'], $menu['title'], $menu['extra']);
     } else {
         return html::createLink($menu['url'], $menu['title'], $menu['extra']);
     }
 }
Example #8
0
 /**
  * function for checking if we need to redirect with 301
  * if param url is not equal to current url, then 
  * we redirect to url given
  * 
  * @param string $url the rul to check against and redirect to.
  * @param array $options set a action message with array ('message' => 'message');  
  */
 public static function permMovedHeader($redirect, $options = array())
 {
     if (isset($options['message'])) {
         session::setActionMessage($options['message']);
     }
     if ($_SERVER['REQUEST_URI'] != $redirect) {
         header("HTTP/1.1 301 Moved Permanently");
         self::locationHeader($redirect);
     }
 }
Example #9
0
 /**
  * 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'];
 }
Example #10
0
 /**
  * method for relocate user to login, and after correct login 
  * redirect to the page where he was. You can set message to
  * be shown on login screen.
  *  
  * @param string $message 
  */
 public static function loginThenRedirect($message)
 {
     unset($_SESSION['return_to']);
     if (!session::isUser()) {
         $_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
         session::setActionMessage($message);
         http::locationHeader('/account/login/index');
         die;
     }
 }
Example #11
0
 /**
  * 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;
 }
Example #12
0
 /**
  * Create a 'hel' and all 'helmembers'
  * @param array $ary _POST
  * @return boolean $res result from R::store
  */
 public function createHel($ary)
 {
     $e = new eDb();
     // create hel
     $hel = rb::getBean('hel');
     $hel->user_id = session::getUserId();
     // Attach halve ids
     $my_halv = $e->getUserHalvFromUserId(session::getUserId());
     $hel->halv_a = $ary['halv'];
     $hel->halv_b = $my_halv['id'];
     // Attach all 8 members
     $hel = $this->attachMembersForHel($hel, $ary);
     return R::store($hel);
 }
Example #13
0
 /**
  * /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();
 }
Example #14
0
 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'];
 }