Beispiel #1
0
    public static function showTables()
    {
        global $lng, $tours;
        title($lng->getTrn('name', 'LeagueTables'));
        // Selector for the tournament
        $tour_id = 0;
        if (isset($_POST['tour_id'])) {
            $tour_id = $_POST['tour_id'];
        } else {
            if (isset($_GET['tour_id'])) {
                $tour_id = $_GET['tour_id'];
            }
        }
        $firstTour = 0;
        ?>
    <div class='boxWide'>
        <h3 class='boxTitle2'><?php 
        echo $lng->getTrn('tours', 'LeagueTables');
        ?>
</h3>
        <div class='boxBody'>
			<form method="POST">
				<select name="tour_id">
					<?php 
        $rTours = array_reverse($tours, true);
        foreach ($rTours as $trid => $desc) {
            if ($firstTour == 0) {
                $firstTour = $trid;
            }
            echo "<option value='{$trid}'" . ($trid == $tour_id ? 'SELECTED' : '') . " >{$desc['tname']}</option>\n";
        }
        /*Replace the prior foreach with this once lid is known.
          foreach ($rTours as $trif => $desc) {
            if($firstTour == 0 && $lid == $_SESSION["NS_node_id"]) {
              $firstTour = $trid;
            }
            if($lid == $_SESSION["NS_node_id"]) {
              echo "<option value='$trid'" . ($trid==$tour_id ? 'SELECTED' : '') . " >$desc[tname]</option>\n";
            }
          }
          */
        ?>
				</select>
				<input type="submit" value="OK">
			</form>
        </div>
    </div>
    <?php 
        if ($tour_id == 0) {
            $tour_id = $firstTour;
        }
        // create the tournament and get the sorting rules
        $tour = new Tour($tour_id);
        $SR = array_map(create_function('$val', 'return $val[0]."mv_".substr($val,1);'), $tour->getRSSortRule());
        // load all the teams according to the sorting rule
        list($teams, ) = Stats::getRaw(T_OBJ_TEAM, array(T_NODE_TOURNAMENT => $tour_id), array(1, 1000), $SR, false);
        // Dump all the raw info for the first team as debug so I can work out the fields
        /*
        echo "<!--\n";
        foreach (array_keys($teams[0]) as $field) {
        	echo $field. "=" . $teams[0][$field] . "\n";
        }
        echo "-->\n";
        */
        // Hard coded list of fields to show - matching existing SLOBB/ECBBL league tables
        $fields = array($lng->getTrn('table-coach', 'LeagueTables') => 'f_cname', $lng->getTrn('table-name', 'LeagueTables') => 'name', $lng->getTrn('table-race', 'LeagueTables') => 'f_rname', $lng->getTrn('table-tv', 'LeagueTables') => 'tv', $lng->getTrn('table-played', 'LeagueTables') => 'mv_played', $lng->getTrn('table-won', 'LeagueTables') => 'mv_won', $lng->getTrn('table-draw', 'LeagueTables') => 'mv_draw', $lng->getTrn('table-loss', 'LeagueTables') => 'mv_lost', $lng->getTrn('table-td', 'LeagueTables') => 'mv_sdiff', $lng->getTrn('table-cas', 'LeagueTables') => 'mv_tcdiff', $lng->getTrn('table-points', 'LeagueTables') => 'mv_pts');
        $unplayedTeams = self::getUnplayedTeamsForTournament($tour_id);
        $confs = 0;
        if (Module::isRegistered('Conference')) {
            $confs = Conference::getConferencesForTour($tour_id);
        }
        // Now the clean output.
        ?>
	<div class='boxWide'>
		<h3 class='boxTitle<?php 
        echo T_HTMLBOX_STATS;
        ?>
'><?php 
        echo $tour->name;
        ?>
</h3>
<?php 
        if ($confs == 0 || empty($confs)) {
            // no conferences at all, or not for this league - normal format
            echo <<<EOQ
\t\t<div class='boxBody'>
\t\t\t<table class="boxTable">
EOQ;
            $i = 0;
            self::showHeader($fields);
            self::showPlayedTeams($teams, $fields, $i);
            self::showUnplayedTeams($unplayedTeams, $i);
            echo <<<EOQ
\t\t\t</table>
\t\t</div>
EOQ;
        } else {
            // conferences - so show them one at a time
            $allConfIds = array();
            foreach ($confs as $conf) {
                $allConfIds = array_merge($allConfIds, $conf->teamIds);
                echo <<<EOQ
\t\t<div class='boxWide'>
\t\t\t<h4 class='boxTitleConf'>{$conf->name}</h4>
\t\t\t\t<table class="boxTable">
EOQ;
                $i = 0;
                self::showHeader($fields);
                self::showPlayedTeams($teams, $fields, $i, $conf->teamIds);
                self::showMissingConferenceTeams($teams, $i, $conf);
                echo <<<EOQ
\t\t\t\t</table>
\t\t</div>
EOQ;
            }
            // now check to see if we have teams that aren't in a conference and show them
            $allConfIds = array_unique($allConfIds);
            if (sizeof($allConfIds) < sizeof($teams) + sizeof($unplayedTeams)) {
                $title = $lng->getTrn('no-conf', 'LeagueTables');
                echo <<<EOQ
\t\t<div class='boxWide'>
\t\t\t<h4 class='boxTitleConf'>{$title}</h4>
\t\t\t<table class="boxTable">
EOQ;
                $noConfTeam = array();
                $noConfUPTeam = array();
                foreach ($teams as $t) {
                    if (!in_array($t['team_id'], $allConfIds)) {
                        array_push($noConfTeam, $t);
                    }
                }
                foreach ($unplayedTeams as $t) {
                    if (!in_array($t->team_id, $allConfIds)) {
                        array_push($noConfUPTeam, $t);
                    }
                }
                $i = 0;
                self::showHeader($fields);
                self::showPlayedTeams($noConfTeam, $fields, $i);
                self::showUnplayedTeams($noConfUPTeam, $i);
                echo <<<EOQ
\t\t\t</table>
\t\t</div>
EOQ;
            }
        }
        echo "</div>";
    }
Beispiel #2
0
 public static function standings($obj, $node, $node_id, array $opts)
 {
     /*
         Makes various kinds of standings tables.
         $obj and $node types are STATS_* types.
     
         $opts = array(
            'url' => page URL on which table is to be displayed (required!)
            'GET_SS' => GET Sorting suffix
            'return_objects' => bool
            'teams_from' => [T_OBJ_COACH|T_OBJ_RACE] when $obj = T_OBJ_TEAM and this is set, only teams related to this object type (teams_from), of ID = $opts[teams_from_id] are fetched.
            'teams_from_id' => ID (int) see "teams_from" for details.
         );
     */
     global $lng, $settings, $objFields_avg;
     $tblTitle = '';
     $objs = $fields = $extra = array();
     $fields_before = $fields_after = array();
     // To be merged with $fields.
     if (!array_key_exists('GET_SS', $opts)) {
         $opts['GET_SS'] = '';
     } else {
         $extra['GETsuffix'] = $opts['GET_SS'];
     }
     # GET Sorting Suffix
     $PAGE = isset($_GET["page"]) ? (int) $_GET["page"] : 1;
     $PAGELENGTH = 0;
     # Infinite, is overrided in below switch/case..
     $extra['noHelp'] = false;
     $W_TEAMS_FROM = array_key_exists('teams_from', $opts);
     $enableRaceSelector = $obj == T_OBJ_PLAYER || $obj == T_OBJ_TEAM && (!isset($opts['teams_from']) || $opts['teams_from'] != T_OBJ_RACE);
     # NO filters for teams of a coach on the coach's teams list.
     $_COACH_TEAM_LIST = $W_TEAMS_FROM && $opts['teams_from'] == T_OBJ_COACH;
     if ($_COACH_TEAM_LIST) {
         list(, , $T_STATE) = HTMLOUT::nodeSelector(array('nonodes' => true, 'state' => true));
         # Produces a state selector.
         $_SELECTOR = array(false, false, $T_STATE, T_RACE_ALL, 'GENERAL', 'mv_played', self::T_NS__ffilter_ineq_gt, 0);
     } else {
         $_SELECTOR = HTMLOUT::nodeSelector(array('force_node' => array($node, $node_id), 'race' => $enableRaceSelector, 'sgrp' => true, 'ffilter' => true, 'obj' => $obj));
     }
     list($sel_node, $sel_node_id, $sel_state, $sel_race, $sel_sgrp, $sel_ff_field, $sel_ff_ineq, $sel_ff_limit) = $_SELECTOR;
     $filter_node = array($sel_node => $sel_node_id);
     $filter_race = $sel_race != T_RACE_ALL ? array(T_OBJ_RACE => $sel_race) : array();
     $filter_having = array('having' => array($sel_ff_field . ($sel_ff_ineq == self::T_NS__ffilter_ineq_gt ? '>=' : '<=') . $sel_ff_limit));
     if ($_COACH_TEAM_LIST && $sel_state != T_STATE_ALLTIME) {
         $filter_having['having'][] = 'rdy IS TRUE';
         $filter_having['having'][] = 'retired IS FALSE';
     }
     $SGRP_GEN = $sel_sgrp == 'GENERAL';
     $ALL_TIME = self::_isNodeAllTime($obj, $sel_node, $sel_node_id);
     $manualSort = isset($_GET["sort{$opts['GET_SS']}"]);
     $sortRule = array_merge($manualSort ? array(($_GET["dir{$opts['GET_SS']}"] == 'a' ? '+' : '-') . $_GET["sort{$opts['GET_SS']}"]) : array(), $obj == T_OBJ_TEAM && $sel_node == T_NODE_TOURNAMENT && is_object($tr = new Tour($sel_node_id)) ? array_map(create_function('$val', 'return $val[0]."mv_".substr($val,1);'), $tr->getRSSortRule()) : sort_rule($obj));
     $set_avg = isset($_GET['pms']) && $_GET['pms'];
     // Per match stats?
     echo '<br><a href="' . $opts['url'] . '&amp;pms=' . ($set_avg ? 0 : 1) . '"><b>' . $lng->getTrn('common/' . ($set_avg ? 'ats' : 'pms')) . "</b></a><br><br>\n";
     // Common $obj type fields.
     $fields = self::_getDefFields($obj, $sel_node, $sel_node_id);
     // Was a different (non-general) stats group selected?
     if (!$SGRP_GEN) {
         $grps_short = getESGroups(true, true);
         $grps_long = getESGroups(true, false);
         $fields_short = $grps_short[$sel_sgrp];
         $fields_long = $grps_long[$sel_sgrp];
         $fields = array_combine(array_strpack('mv_%s', $fields_long), array_map(create_function('$f', 'return array("desc" => $f);'), $fields_short));
         $objFields_avg = array_merge($objFields_avg, array_map(create_function('$k', 'return substr($k, 3);'), array_keys($fields)));
     }
     switch ($obj) {
         case STATS_PLAYER:
             $tblTitle = $lng->getTrn('menu/statistics_menu/player_stn');
             $fields_before = array('name' => array('desc' => $lng->getTrn('common/player'), 'href' => array('link' => urlcompile(T_URL_PROFILE, T_OBJ_PLAYER, false, false, false), 'field' => 'obj_id', 'value' => 'player_id')), 'f_tname' => array('desc' => $lng->getTrn('common/team'), 'href' => array('link' => urlcompile(T_URL_PROFILE, T_OBJ_TEAM, false, false, false), 'field' => 'obj_id', 'value' => 'owned_by_team_id')));
             $PAGELENGTH = $settings['standings']['length_players'];
             list($objs, $PAGES) = Stats::getRaw(T_OBJ_PLAYER, $filter_node + $filter_having + $filter_race, array($PAGE, $PAGELENGTH), $sortRule, $set_avg);
             break;
         case STATS_TEAM:
             $tblTitle = $lng->getTrn('menu/statistics_menu/team_stn');
             $fields_before = array('name' => array('desc' => $lng->getTrn('common/name'), 'href' => array('link' => urlcompile(T_URL_PROFILE, T_OBJ_TEAM, false, false, false), 'field' => 'obj_id', 'value' => 'team_id')));
             // Show teams standings list only for teams owned by... ?
             switch ($W_TEAMS_FROM ? $opts['teams_from'] : false) {
                 case T_OBJ_COACH:
                     $fields_before['f_rname'] = array('desc' => $lng->getTrn('common/race'), 'href' => array('link' => urlcompile(T_URL_PROFILE, T_OBJ_RACE, false, false, false), 'field' => 'obj_id', 'value' => 'f_race_id'));
                     list($objs, $PAGES) = Stats::getRaw(T_OBJ_TEAM, $filter_node + $filter_having + $filter_race + array(T_OBJ_COACH => (int) $opts['teams_from_id']), false, $sortRule, $set_avg);
                     break;
                 case T_OBJ_RACE:
                     $fields_before['f_cname'] = array('desc' => $lng->getTrn('common/coach'), 'href' => array('link' => urlcompile(T_URL_PROFILE, T_OBJ_COACH, false, false, false), 'field' => 'obj_id', 'value' => 'owned_by_coach_id'));
                     $PAGELENGTH = $settings['standings']['length_teams'];
                     list($objs, $PAGES) = Stats::getRaw(T_OBJ_TEAM, $filter_node + $filter_having + array(T_OBJ_RACE => (int) $opts['teams_from_id']), array($PAGE, $PAGELENGTH), $sortRule, $set_avg);
                     break;
                     // All teams
                 // All teams
                 default:
                     $PAGELENGTH = $settings['standings']['length_teams'];
                     list($objs, $PAGES) = Stats::getRaw(T_OBJ_TEAM, $filter_node + $filter_having + $filter_race, array($PAGE, $PAGELENGTH), $sortRule, $set_avg);
             }
             // Translating race name
             foreach ($objs as &$o) {
                 $o['f_rname'] = $lng->getTrn('race/' . strtolower(str_replace(' ', '', $o['f_rname'])));
             }
             break;
         case STATS_RACE:
             $tblTitle = $lng->getTrn('menu/statistics_menu/race_stn');
             $fields_before = array('name' => array('desc' => $lng->getTrn('common/race'), 'href' => array('link' => urlcompile(T_URL_PROFILE, T_OBJ_RACE, false, false, false), 'field' => 'obj_id', 'value' => 'race_id')));
             $dash_empty = false;
             if ($sel_node == T_NODE_TOURNAMENT) {
                 $dash_empty = 'mv_team_cnt';
             } else {
                 if ($ALL_TIME) {
                     $dash_empty = 'rg_team_cnt';
                 }
             }
             if ($dash_empty) {
                 $extra['dashed'] = array('condField' => $dash_empty, 'fieldVal' => 0, 'noDashFields' => array('name'));
             }
             list($objs, $PAGES) = Stats::getRaw(T_OBJ_RACE, $filter_node + $filter_having, false, $sortRule, $set_avg);
             // Translating race name
             foreach ($objs as &$o) {
                 $o['name'] = $lng->getTrn('race/' . strtolower(str_replace(' ', '', $o['name'])));
             }
             break;
         case STATS_COACH:
             $tblTitle = $lng->getTrn('menu/statistics_menu/coach_stn');
             $fields_before = array('name' => array('desc' => $lng->getTrn('common/coach'), 'href' => array('link' => urlcompile(T_URL_PROFILE, T_OBJ_COACH, false, false, false), 'field' => 'obj_id', 'value' => 'coach_id')));
             $PAGELENGTH = $settings['standings']['length_coaches'];
             list($objs, $PAGES) = Stats::getRaw(T_OBJ_COACH, $filter_node + $filter_having, array($PAGE, $PAGELENGTH), $sortRule, $set_avg);
             break;
         case STATS_STAR:
             $tblTitle = $lng->getTrn('menu/statistics_menu/star_stn');
             $fields_before = array('name' => array('desc' => $lng->getTrn('common/star'), 'href' => array('link' => urlcompile(T_URL_PROFILE, T_OBJ_STAR, false, false, false), 'field' => 'obj_id', 'value' => 'star_id')), 'cost' => array('desc' => 'Price', 'kilo' => true, 'suffix' => 'k'), 'ma' => array('desc' => 'Ma'), 'st' => array('desc' => 'St'), 'ag' => array('desc' => 'Ag'), 'av' => array('desc' => 'Av'));
             $extra['dashed'] = array('condField' => 'mv_played', 'fieldVal' => 0, 'noDashFields' => array('name'));
             list($objs, $PAGES) = Stats::getRaw(T_OBJ_STAR, $filter_node + $filter_having, false, $sortRule, $set_avg);
             break;
     }
     foreach ($objs as $idx => $obj) {
         $objs[$idx] = (object) $obj;
     }
     if (!$SGRP_GEN) {
         $tmp = $fields_before['name'];
         $fields_before = $fields_after = array();
         $fields_before['name'] = $tmp;
     }
     $fields = array_merge($fields_before, $fields, $fields_after);
     // Add average marker on fields (*).
     if ($set_avg) {
         foreach (array_keys($fields) as $f) {
             $f_cut = preg_replace('/^\\w\\w\\_/', '', $f);
             if (in_array($f_cut, $objFields_avg)) {
                 $fields[$f]['desc'] .= '*';
             }
         }
     }
     $extra['page'] = $PAGE;
     $extra['pages'] = $PAGES;
     $extra['pagelength'] = $PAGELENGTH;
     HTMLOUT::sort_table($tblTitle, $opts['url'] . ($set_avg ? '&amp;pms=1' : ''), $objs, $fields, $sortRule, array(), $extra);
     return array_key_exists('return_objects', $opts) && $opts['return_objects'] ? array($objs, $sortRule) : true;
 }
Beispiel #3
0
function sec_main()
{
    global $settings, $rules, $coach, $lng, $leagues;
    MTS('Main start');
    list($sel_lid, $HTML_LeagueSelector) = HTMLOUT::simpleLeagueSelector();
    $IS_GLOBAL_ADMIN = is_object($coach) && $coach->ring == Coach::T_RING_GLOBAL_ADMIN;
    /*
     *  Was any main board actions made?
     */
    if (isset($_POST['type']) && is_object($coach) && $coach->isNodeCommish(T_NODE_LEAGUE, $sel_lid)) {
        if (get_magic_quotes_gpc()) {
            if (isset($_POST['title'])) {
                $_POST['title'] = stripslashes($_POST['title']);
            }
            if (isset($_POST['txt'])) {
                $_POST['txt'] = stripslashes($_POST['txt']);
            }
        }
        $msg = isset($_POST['msg_id']) ? new Message((int) $_POST['msg_id']) : null;
        switch ($_POST['type']) {
            case 'msgdel':
                status($msg->delete());
                break;
            case 'msgnew':
                status(Message::create(array('f_coach_id' => $coach->coach_id, 'f_lid' => $IS_GLOBAL_ADMIN && isset($_POST['BC']) && $_POST['BC'] ? Message::T_BROADCAST : $sel_lid, 'title' => $_POST['title'], 'msg' => $_POST['txt'])));
                break;
            case 'msgedit':
                status($msg->edit($_POST['title'], $_POST['txt']));
                break;
            case 'pin':
                status($msg->pin(1));
                break;
            case 'unpin':
                status($msg->pin(0));
                break;
        }
    }
    /*
     *  Now we are ready to generate the HTML code.
     */
    ?>
    <div class="main_head"><?php 
    echo $settings['league_name'];
    ?>
</div>
    <div class='main_leftColumn'>
        <div class="main_leftColumn_head">
            <?php 
    echo "<div class='main_leftColumn_welcome'>\n";
    echo $settings['welcome'];
    echo "</div>\n";
    echo "<div class='main_leftColumn_left'>\n";
    if (count($leagues) > 1) {
        echo $HTML_LeagueSelector;
    }
    echo "</div>\n";
    echo "<div class='main_leftColumn_right'>\n";
    if (is_object($coach) && $coach->isNodeCommish(T_NODE_LEAGUE, $sel_lid)) {
        echo "<a href='javascript:void(0);' onClick=\"slideToggle('msgnew');\">" . $lng->getTrn('main/newmsg') . "</a>&nbsp;\n";
    }
    if (Module::isRegistered('RSSfeed')) {
        echo "<a href='handler.php?type=rss'>RSS</a>\n";
    }
    echo "</div>\n";
    ?>
            <div style="display:none; clear:both;" id="msgnew">
                <br><br>
                <form method="POST">
                    <textarea name="title" rows="1" cols="50"><?php 
    echo $lng->getTrn('common/notitle');
    ?>
</textarea><br><br>
                    <textarea name="txt" rows="15" cols="50"><?php 
    echo $lng->getTrn('common/nobody');
    ?>
</textarea><br><br>
                    <?php 
    if ($IS_GLOBAL_ADMIN) {
        echo $lng->getTrn('main/broadcast');
        ?>
<input type="checkbox" name="BC"><br><br><?php 
    }
    ?>
                    <input type="hidden" name="type" value="msgnew">
                    <input type="submit" value="<?php 
    echo $lng->getTrn('common/submit');
    ?>
">
                </form>
            </div>
        </div>

        <?php 
    /*
        Generate main board.
    
        Left column is the message board, consisting of both commissioner messages and game summaries/results.
        To generate this table we create a general array holding the content of both.
    */
    $j = 1;
    $prevPinned = 0;
    foreach (TextSubSys::getMainBoardMessages($settings['fp_messageboard']['length'], $sel_lid, $settings['fp_messageboard']['show_team_news'], $settings['fp_messageboard']['show_match_summaries']) as $e) {
        if ($prevPinned == 1 && !$e->pinned) {
            echo "<hr>\n";
        }
        $prevPinned = $e->pinned;
        echo "<div class='boxWide'>\n";
        echo "<h3 class='boxTitle{$e->cssidx}'>{$e->title}</h3>\n";
        echo "<div class='boxBody'>\n";
        $fmtMsg = fmtprint($e->message);
        # Basic supported syntax: linebreaks.
        echo "\r\n                    <div id='e{$j}' class='expandable'>{$fmtMsg}</div>\r\n                    <script type='text/javascript'>\r\n                      \$('#e{$j}').expander({\r\n                        slicePoint:       300,\r\n                        expandText:       '" . $lng->getTrn('main/more') . "',\r\n                        collapseTimer:    0,\r\n                        userCollapseText: ''\r\n                      });\r\n                      </script>";
        echo "<br><hr>\n";
        echo "<table class='boxTable'><tr>\n";
        switch ($e->type) {
            case T_TEXT_MATCH_SUMMARY:
                echo "<td align='left' width='100%'>" . $lng->getTrn('main/posted') . " " . textdate($e->date) . " " . (isset($e->date_mod) && $e->date_mod != $e->date ? "(" . $lng->getTrn('main/lastedit') . " " . textdate($e->date_mod) . ") " : '') . $lng->getTrn('main/by') . " {$e->author}</td>\n";
                echo "<td align='right'><a href='index.php?section=matches&amp;type=report&amp;mid={$e->match_id}'>" . $lng->getTrn('common/view') . "</a></td>\n";
                break;
            case T_TEXT_MSG:
                echo "<td align='left' width='100%'>" . $lng->getTrn('main/posted') . " " . textdate($e->date) . " " . $lng->getTrn('main/by') . " {$e->author}</td>\n";
                if (is_object($coach) && ($IS_GLOBAL_ADMIN || $coach->coach_id == $e->author_id)) {
                    // Only admins may delete messages, or if it's a commissioner's own message.
                    echo "<td align='right'><a href='javascript:void(0);' onClick=\"slideToggle('msgedit{$e->msg_id}');\">" . $lng->getTrn('common/edit') . "</a></td>\n";
                    echo "<td align='right'>";
                    $fieldname = 'pin';
                    if ($e->pinned) {
                        $fieldname = 'unpin';
                    }
                    echo inlineform(array('type' => "{$fieldname}", 'msg_id' => $e->msg_id), "{$fieldname}{$e->msg_id}", $lng->getTrn("main/{$fieldname}"));
                    echo "</td>";
                    echo "<td align='right'>";
                    echo inlineform(array('type' => 'msgdel', 'msg_id' => $e->msg_id), "msgdel{$e->msg_id}", $lng->getTrn('common/delete'));
                    echo "</td>";
                }
                break;
            case T_TEXT_TNEWS:
                echo "<td align='left' width='100%'>" . $lng->getTrn('main/posted') . " " . textdate($e->date) . "</td>\n";
                break;
        }
        ?>
                    </tr></table>
                    <?php 
        if ($e->type == T_TEXT_MSG) {
            echo "<div style='display:none;' id='msgedit{$e->msg_id}'>\n";
            echo "<hr><br>\n";
            echo '<form method="POST">
                            <textarea name="title" rows="1" cols="50">' . $e->title . '</textarea><br><br>
                            <textarea name="txt" rows="15" cols="50">' . $e->message . '</textarea><br><br>
                            <input type="hidden" name="type" value="msgedit">
                            <input type="hidden" name="msg_id" value="' . $e->msg_id . '">
                            <input type="submit" value="' . $lng->getTrn('common/submit') . '">
                        </form>';
            echo "</div>";
        }
        ?>
                </div>
            </div>
            <?php 
        $j++;
    }
    ?>

    </div>
    <?php 
    MTS('Board messages generated');
    /*
        The right hand side column optionally (depending on settings) contains standings, latest game results, touchdown and casualties stats.
        We will now generate the stats, so that they are ready to be printed in correct order.
    */
    echo "<div class='main_rightColumn'>\n";
    $boxes_all = array_merge($settings['fp_standings'], $settings['fp_leaders'], $settings['fp_events'], $settings['fp_latestgames']);
    usort($boxes_all, create_function('$a,$b', 'return (($a["box_ID"] > $b["box_ID"]) ? 1 : (($a["box_ID"] < $b["box_ID"]) ? -1 : 0) );'));
    $boxes = array();
    foreach ($boxes_all as $box) {
        # These fields distinguishes the box types.
        if (isset($box['fields'])) {
            $box['dispType'] = 'standings';
        } else {
            if (isset($box['field'])) {
                $box['dispType'] = 'leaders';
            } else {
                if (isset($box['content'])) {
                    $box['dispType'] = 'events';
                } else {
                    $box['dispType'] = 'latestgames';
                }
            }
        }
        switch ($box['type']) {
            case 'league':
                $_type = T_NODE_LEAGUE;
                break;
            case 'division':
                $_type = T_NODE_DIVISION;
                break;
            case 'tournament':
                $_type = T_NODE_TOURNAMENT;
                break;
            default:
                $_type = T_NODE_LEAGUE;
        }
        $box['type'] = $_type;
        $boxes[] = $box;
    }
    // Used in the below standings dispType boxes.
    global $core_tables, $ES_fields;
    $_MV_COLS = array_merge(array_keys($core_tables['mv_teams']), array_keys($ES_fields));
    $_MV_RG_INTERSECT = array_intersect(array_keys($core_tables['teams']), array_keys($core_tables['mv_teams']));
    // Let's print those boxes!
    foreach ($boxes as $box) {
        switch ($box['dispType']) {
            case 'standings':
                $_BAD_COLS = array();
                # Halt on these columns/fields.
                switch ($box['type']) {
                    case T_NODE_TOURNAMENT:
                        if (!get_alt_col('tours', 'tour_id', $box['id'], 'tour_id')) {
                            break 2;
                        }
                        $tour = new Tour($box['id']);
                        $SR = array_map(create_function('$val', 'return $val[0]."mv_".substr($val,1);'), $tour->getRSSortRule());
                        break;
                    case T_NODE_DIVISION:
                        $_BAD_COLS = array('elo', 'swon', 'slost', 'sdraw', 'win_pct');
                        # Divisions do not have pre-calculated, MV, values of these fields.
                        // Fall through!
                    # Divisions do not have pre-calculated, MV, values of these fields.
                    // Fall through!
                    case T_NODE_LEAGUE:
                    default:
                        global $hrs;
                        $SR = $hrs[$box['HRS']]['rule'];
                        foreach ($SR as &$f) {
                            $field = substr($f, 1);
                            if (in_array($field, $_MV_RG_INTERSECT)) {
                                if (in_array($field, $_BAD_COLS)) {
                                    # E.g. divisions have no win_pct record for teams like the mv_teams table (for tours) has.
                                    fatal("Sorry, the element '{$field}' in your specified house sortrule #{$box['HRS']} is not supported for your chosen type (ie. tournament/division/league).");
                                }
                                $f = $f[0] . "rg_" . substr($f, 1);
                            } else {
                                $f = $f[0] . "mv_" . substr($f, 1);
                            }
                        }
                        break;
                }
                list($teams, ) = Stats::getRaw(T_OBJ_TEAM, array($box['type'] => $box['id']), array(1, $box['length']), $SR, false);
                ?>
            <div class='boxWide'>
                <h3 class='boxTitle<?php 
                echo T_HTMLBOX_STATS;
                ?>
'><?php 
                echo $box['title'];
                ?>
</h3>
                <div class='boxBody'>
                    <table class="boxTable">
                        <?php 
                echo "<tr>\n";
                foreach ($box['fields'] as $title => $f) {
                    echo "<td><i>{$title}</i></td>\n";
                }
                echo "</tr>\n";
                foreach ($teams as $t) {
                    if (!$t['retired']) {
                        echo "<tr>\n";
                        foreach ($box['fields'] as $title => $f) {
                            if (in_array($f, $_MV_COLS)) {
                                $f = 'mv_' . $f;
                            }
                            echo "<td>";
                            if ($settings['fp_links'] && $f == 'name') {
                                echo "<a href='" . urlcompile(T_URL_PROFILE, T_OBJ_TEAM, $t['team_id'], false, false) . "'>{$t['name']}</a>";
                            } elseif (is_numeric($t[$f]) && !ctype_digit($t[$f][0] == '-' ? substr($t[$f], 1) : $t[$f])) {
                                echo sprintf('%1.2f', $t[$f]);
                            } else {
                                echo in_array($f, array('tv')) ? $t[$f] / 1000 : $t[$f];
                            }
                            echo "</td>\n";
                        }
                        echo "</tr>\n";
                    }
                }
                ?>
                    </table>
                    <?php 
                if (isset($box['infocus']) && $box['infocus']) {
                    echo "<hr>";
                    _infocus($teams);
                }
                ?>
                </div>
            </div>
            <?php 
                MTS('Standings table generated');
                break;
            case 'latestgames':
                if ($box['length'] <= 0) {
                    break;
                }
                ?>
            <div class="boxWide">
                <h3 class='boxTitle<?php 
                echo T_HTMLBOX_MATCH;
                ?>
'><?php 
                echo $box['title'];
                ?>
</h3>
                <div class='boxBody'>
                    <table class="boxTable">
                        <tr>
                            <td style="text-align: right;" width="50%"><i><?php 
                echo $lng->getTrn('common/home');
                ?>
</i></td>
                            <td> </td>
                            <td style="text-align: left;" width="50%"><i><?php 
                echo $lng->getTrn('common/away');
                ?>
</i></td>
                            <td><i><?php 
                echo $lng->getTrn('common/date');
                ?>
</i></td>
                            <td> </td>
                        </tr>
                        <?php 
                list($matches, $pages) = Match::getMatches(array(1, $box['length']), $box['type'], $box['id'], false);
                foreach ($matches as $m) {
                    echo "<tr valign='top'>\n";
                    $t1name = $settings['fp_links'] ? "<a href='" . urlcompile(T_URL_PROFILE, T_OBJ_TEAM, $m->team1_id, false, false) . "'>{$m->team1_name}</a>" : $m->team1_name;
                    $t2name = $settings['fp_links'] ? "<a href='" . urlcompile(T_URL_PROFILE, T_OBJ_TEAM, $m->team2_id, false, false) . "'>{$m->team2_name}</a>" : $m->team2_name;
                    echo "<td style='text-align: right;'>{$t1name}</td>\n";
                    echo "<td><nobr>{$m->team1_score}&mdash;{$m->team2_score}</nobr></td>\n";
                    echo "<td style='text-align: left;'>{$t2name}</td>\n";
                    echo "<td>" . str_replace(' ', '&nbsp;', textdate($m->date_played, true)) . "</td>";
                    echo "<td><a href='index.php?section=matches&amp;type=report&amp;mid={$m->match_id}'>Show</a></td>";
                    echo "</tr>";
                }
                ?>
                    </table>
                </div>
            </div>
            <?php 
                MTS('Latest matches table generated');
                break;
            case 'leaders':
                $f = 'mv_' . $box['field'];
                list($players, ) = Stats::getRaw(T_OBJ_PLAYER, array($box['type'] => $box['id']), array(1, $box['length']), array('-' . $f), false);
                ?>
            <div class="boxWide">
                <h3 class='boxTitle<?php 
                echo T_HTMLBOX_STATS;
                ?>
'><?php 
                echo $box['title'];
                ?>
</h3>
                <div class='boxBody'>
                    <table class="boxTable">
                        <tr>
                            <td><i><?php 
                echo $lng->getTrn('common/name');
                ?>
</i></td>
                            <?php 
                if ($box['show_team']) {
                    ?>
<td><i><?php 
                    echo $lng->getTrn('common/team');
                    ?>
</i></td><?php 
                }
                ?>
                            <td><i>#</i></td>
                            <td><i><?php 
                echo $lng->getTrn('common/value');
                ?>
</i></td>
                        </tr>
                        <?php 
                foreach ($players as $p) {
                    echo "<tr>\n";
                    echo "<td>" . ($settings['fp_links'] ? "<a href='" . urlcompile(T_URL_PROFILE, T_OBJ_PLAYER, $p['player_id'], false, false) . "'>{$p['name']}</a>" : $p['name']) . "</td>\n";
                    if ($box['show_team']) {
                        echo "<td>" . ($settings['fp_links'] ? "<a href='" . urlcompile(T_URL_PROFILE, T_OBJ_TEAM, $p['owned_by_team_id'], false, false) . "'>{$p['f_tname']}</a>" : $p['f_tname']) . "</td>\n";
                    }
                    echo "<td>" . $p[$f] . "</td>\n";
                    echo "<td>" . $p['value'] / 1000 . "k</td>\n";
                    echo "</tr>";
                }
                ?>
                    </table>
                </div>
            </div>
            <?php 
                MTS('Leaders standings generated');
                break;
            case 'events':
                $events = _events($box['content'], $box['type'], $box['id'], $box['length']);
                ?>
            <div class="boxWide">
                <h3 class='boxTitle<?php 
                echo T_HTMLBOX_STATS;
                ?>
'><?php 
                echo $box['title'];
                ?>
</h3>
                <div class='boxBody'>
                    <table class="boxTable">
                        <?php 
                $head = array_pop($events);
                echo "<tr>\n";
                foreach ($head as $col => $name) {
                    echo "<td><i>{$name}</i></td>\n";
                }
                echo "</tr>\n";
                foreach ($events as $e) {
                    echo "<tr>\n";
                    foreach ($head as $col => $name) {
                        switch ($col) {
                            case 'date':
                                $e->{$col} = str_replace(' ', '&nbsp;', textdate($e->{$col}, true));
                                break;
                            case 'name':
                                if ($settings['fp_links']) {
                                    $e->{$col} = "<a href='" . urlcompile(T_URL_PROFILE, T_OBJ_PLAYER, $e->pid, false, false) . "'>" . $e->{$col} . "</a>";
                                }
                                break;
                            case 'tname':
                                if ($settings['fp_links']) {
                                    $e->{$col} = "<a href='" . urlcompile(T_URL_PROFILE, T_OBJ_TEAM, $e->f_tid, false, false) . "'>" . $e->{$col} . "</a>";
                                }
                                break;
                            case 'rname':
                                if ($settings['fp_links']) {
                                    $e->{$col} = "<a href='" . urlcompile(T_URL_PROFILE, T_OBJ_RACE, $e->f_rid, false, false) . "'>" . $e->{$col} . "</a>";
                                }
                                break;
                            case 'f_pos_name':
                                if ($settings['fp_links']) {
                                    $e->{$col} = "<a href='" . urlcompile(T_URL_PROFILE, T_OBJ_RACE, $e->f_rid, false, false) . "'>" . $e->{$col} . "</a>";
                                }
                                break;
                            case 'value':
                                $e->{$col} = $e->{$col} / 1000 . 'k';
                                break;
                        }
                        echo "<td>" . $e->{$col} . "</td>\n";
                    }
                    echo "</tr>\n";
                }
                ?>
                    </table>
                </div>
            </div>
            <?php 
                MTS('Events box generated');
                break;
        }
    }
    ?>
    </div>
    <div class="main_foot">
        <?php 
    HTMLOUT::dnt();
    ?>
        <br>
        <a TARGET="_blank" href="http://nicholasmr.dk/index.php?sec=obblm">OBBLM official website</a><br><br>
        This web site is completely unofficial and in no way endorsed by Games Workshop Limited.
        <br>
        Bloodquest, Blood Bowl, the Blood Bowl logo, The Blood Bowl Spike Device, Chaos, the Chaos device, the Chaos logo, Games Workshop, Games Workshop logo, Nurgle, the Nurgle device, Skaven, Tomb Kings, and all associated marks, names, races, race insignia, characters, vehicles, locations, units, illustrations and images from the Blood Bowl game, the Warhammer world are either (R), TM and/or (C) Games Workshop Ltd 2000-2006, variably registered in the UK and other countries around the world. Used without permission. No challenge to their status intended. All Rights Reserved to their respective owners.
    </div>
    <?php 
}