Example #1
0
function setupGlobalVars($type, $opts = array())
{
    global $coach, $lng, $leagues, $divisions, $tours, $settings, $rules, $admin_menu;
    switch ($type) {
        case T_SETUP_GLOBAL_VARS__COMMON:
            $coach = isset($_SESSION['logged_in']) ? new Coach($_SESSION['coach_id']) : null;
            # Create global coach object.
            list($leagues, $divisions, $tours) = Coach::allowedNodeAccess(Coach::NODE_STRUCT__FLAT, is_object($coach) ? $coach->coach_id : false, $extraFields = array(T_NODE_TOURNAMENT => array('locked' => 'locked', 'type' => 'type', 'f_did' => 'f_did'), T_NODE_DIVISION => array('f_lid' => 'f_lid'), T_NODE_LEAGUE => array('tie_teams' => 'tie_teams')));
            setupGlobalVars(T_SETUP_GLOBAL_VARS__LOAD_LEAGUE_SETTINGS);
            $_LANGUAGE = is_object($coach) && isset($coach->settings['lang']) ? $coach->settings['lang'] : $settings['lang'];
            if (!is_object($lng)) {
                $lng = new Translations($_LANGUAGE);
            } else {
                $lng->setLanguage($_LANGUAGE);
            }
            break;
        case T_SETUP_GLOBAL_VARS__POST_LOAD_MODULES:
            $admin_menu = is_object($coach) ? $coach->getAdminMenu() : array();
            break;
        case T_SETUP_GLOBAL_VARS__LOAD_LEAGUE_SETTINGS:
            // Local league settings exist?
            $file = "localsettings/settings_ID.php";
            // Update selected node $_SESSION vars if node selector form submission made (will make HTMLOUT::getSelectedNodeLid(), below, catch the correct league straight as opposed to on second page reload).
            HTMLOUT::updateNodeSelectorLeagueVars();
            // Selected
            if (isset($opts['lid']) && is_numeric($opts['lid'])) {
                $id = $opts['lid'];
            } else {
                if ($_lid = HTMLOUT::getSelectedNodeLid()) {
                    $id = $_lid;
                } else {
                    if (is_object($coach) && isset($coach->settings['home_lid'])) {
                        $id = $coach->settings['home_lid'];
                    } else {
                        $id = isset($settings['default_visitor_league']) ? $settings['default_visitor_league'] : '';
                    }
                }
            }
            $settingsFile = str_replace("ID", $id, $file);
            if ($localsettings = file_exists($settingsFile) ? $settingsFile : false) {
                include $localsettings;
            } else {
                include str_replace("ID", 'none', $file);
                # Empty settings file.
            }
            break;
        case T_SETUP_GLOBAL_VARS__POST_COACH_LOGINOUT:
            setupGlobalVars(T_SETUP_GLOBAL_VARS__COMMON);
            setupGlobalVars(T_SETUP_GLOBAL_VARS__POST_LOAD_MODULES);
            break;
    }
}