public static function sort_table($title, $lnk, array $objs, array $fields, array $std_sort, $sort = array(), $extra = array()) { /* extra fields: tableWidth => CSS style width value dashed => array( 'condField' => field name, // When an object has this field's (condField) = fieldVal, then a "-" is put in the place of all values. 'fieldVal' => field value, 'noDashFields' => array('field 1', 'field 2') // ...unless the field name is one of those specified in the array 'noDashFields'. ); remove => array( 'condField' => field name, // When an object has this field's (condField) = fieldVal, then the entry/row is not printed in the html table. 'fieldVal' => field value, ); GETsuffix => suffix to paste into "dir" and "sort" GET strings. color => true/false. Boolean telling wheter or not we should look into each object for the field "HTMLfcolor" and "HTMLbcolor", and use these color codes to color the obj's row. Note: the object must contain the two previously stated fields, or else black-on-white is used as default. doNr => true/false. Boolean telling wheter or not to print the "Nr." column. limit => int. Stop printing rows when this row number is reached. anchor => string. Will create table sorting links, that include this identifier as an anchor. noHelp => true/false. Will enable/disable help link [?]. noSRdisp => true/false. Will force not to show the table sort rule used/parsed. page => current page being viewed pages => total number of pages */ global $settings, $lng; if (array_key_exists('remove', $extra)) { $objs = array_filter($objs, create_function('$obj', 'return ($obj->' . $extra['remove']['condField'] . ' != ' . $extra['remove']['fieldVal'] . ');')); } $MASTER_SORT = array_merge($sort, $std_sort); if (!empty($MASTER_SORT)) { objsort($objs, $MASTER_SORT); } $no_print_fields = array(); $DONR = !array_key_exists('doNr', $extra) || $extra['doNr'] ? true : false; $LIMIT = array_key_exists('limit', $extra) ? $extra['limit'] : -1; $ANCHOR = array_key_exists('anchor', $extra) ? $extra['anchor'] : false; $NOSRDISP = array_key_exists('noSRdisp', $extra) ? $extra['noSRdisp'] : false; $GETSUFX = array_key_exists('GETsuffix', $extra) ? $extra['GETsuffix'] : ''; $PAGES = array_key_exists('pages', $extra) ? $extra['pages'] : false; $PAGE = array_key_exists('page', $extra) ? $extra['page'] : 1; $PAGELENGTH = array_key_exists('pagelength', $extra) ? $extra['pagelength'] : 0; if ($DONR) { $fields = array_merge(array('nr' => array('desc' => '#')), $fields); array_push($no_print_fields, 'nr'); } $CP = count($fields); ?> <table class="common" <?php echo array_key_exists('tableWidth', $extra) ? "style='width: {$extra['tableWidth']};'" : ''; ?> > <tr class="commonhead"> <td colspan="<?php echo $CP; ?> "><b> <?php echo $title; ?> <?php if (!array_key_exists('noHelp', $extra) || !$extra['noHelp']) { ?> <a TARGET="_blank" href="html/table_desc.html">[?]</a><?php } ?> </b></td> </tr> <tr> <?php foreach ($fields as $f => $attr) { echo "<td><i>{$attr['desc']}</i></td>"; } ?> </tr> <tr> <?php foreach ($fields as $f => $attr) { if (in_array($f, $no_print_fields) || array_key_exists('nosort', $attr) && $attr['nosort']) { echo "<td></td>"; continue; } $sort = 'sort' . $GETSUFX; $dir = 'dir' . $GETSUFX; $anc = ''; if ($ANCHOR) { $anc = "#{$ANCHOR}"; } echo "<td><b><a href='{$lnk}&page=1&{$sort}={$f}&{$dir}=a{$anc}' title='Sort ascending'>+</a>/<a href='{$lnk}&page=1&{$sort}={$f}&{$dir}=d{$anc}' title='Sort descending'>-</a></b></td>"; } ?> </tr> <tr><td colspan="<?php echo $CP; ?> "><hr></td></tr> <?php $i = 1 + ($PAGE && $PAGELENGTH ? ($PAGE - 1) * $PAGELENGTH : 0); foreach ($objs as $o) { $DASH = array_key_exists('dashed', $extra) && $o->{$extra['dashed']['condField']} == $extra['dashed']['fieldVal'] ? true : false; if (array_key_exists('color', $extra)) { $td = "<td style='background-color: " . (isset($o->HTMLbcolor) ? $o->HTMLbcolor : 'white') . "; color: " . (isset($o->HTMLfcolor) ? $o->HTMLfcolor : 'black') . ";'>"; } else { $td = '<td>'; } echo "<tr>"; if ($DONR) { echo $td . $i . "</td>"; } foreach ($fields as $f => $a) { // Field => attributes if (!in_array($f, $no_print_fields)) { if ($DASH && !in_array($f, $extra['dashed']['noDashFields'])) { echo $td . "-</td>"; continue; } $cpy = $o->{$f}; // Don't change the objects themselves! Make copies! if (array_key_exists('kilo', $a) && $a['kilo']) { $cpy /= 1000; } $cpy = (string) $cpy; if (is_numeric($cpy) && !ctype_digit($cpy[0] == '-' ? substr($cpy, 1) : $cpy)) { $cpy = sprintf("%1.2f", $cpy); } if (array_key_exists('suffix', $a) && $a['suffix']) { $cpy .= $a['suffix']; } if (array_key_exists('color', $a) && $a['color']) { $cpy = "<font color='{$a['color']}'>" . $cpy . "</font>"; } if (array_key_exists('href', $a) && $a['href']) { $href = isset($o->href) ? $o->href : $a['href']; $cpy = "<a href='{$href['link']}" . (isset($href['field']) ? "&{$href['field']}=" . $o->{$href['value']} : '') . "'>" . $cpy . "</a>"; } if (isset($o->{"{$f}_color"})) { echo "<td style='background-color: " . $o->{"{$f}_color"} . "; color: black;'>" . $cpy . "</td>"; } else { echo $td . $cpy . "</td>"; } } } echo "</tr>\n"; if ($i++ == $LIMIT) { break; } } if (!$NOSRDISP) { ?> <tr> <td colspan="<?php echo $CP; ?> "> <hr> </td> </tr> <tr> <td align="right" colspan="<?php echo $CP; ?> "> <?php if ($PAGES) { ?> <div style='float:left;'><?php echo $lng->getTrn('common/page') . " "; $primary_sort = isset($_GET["sort{$GETSUFX}"]) ? "&sort{$GETSUFX}=" . $_GET["sort{$GETSUFX}"] . "&dir{$GETSUFX}=" . $_GET["dir{$GETSUFX}"] : ''; $pageslist = array_strpack('<a href=\\"' . $lnk . '&page=%s' . $primary_sort . '\\">%s</a>', range(1, $PAGES)); $pageslist[$PAGE - 1] = "<b>{$PAGE}</b>"; echo implode(', ', $pageslist); ?> </div> <?php } ?> <div style='float:right;'><i><?php echo $lng->getTrn('common/sortedagainst'); ?> : <?php echo implode(', ', rule_dict($MASTER_SORT)); ?> </i></div> </td> </tr> <?php } echo "</table>\n"; }
public static function tours() { global $rules, $settings, $lng, $coach; title($lng->getTrn('menu/matches_menu/tours')); $flist = Coach::allowedNodeAccess(Coach::NODE_STRUCT__TREE, is_object($coach) ? $coach->coach_id : false); $tourObjs = array(); $flist_JShides = array(); $divsToFoldUp = array(); // Run through the tours to see which nodes should be hidden. $ENABLE_LEAG_HIDING = in_array('league', $settings['tourlist_hide_nodes']); $ENABLE_DIV_HIDING = in_array('division', $settings['tourlist_hide_nodes']); $ENABLE_TOUR_HIDING = in_array('tournament', $settings['tourlist_hide_nodes']); foreach ($flist as $lid => $divs) { $HIDE_LEAG = $ENABLE_LEAG_HIDING; foreach ($divs as $did => $tours) { if ($did == 'desc') { continue; } $HIDE_DIV = $ENABLE_DIV_HIDING; $FOLDUP_DIV = $settings['tourlist_foldup_fin_divs']; foreach ($tours as $trid => $desc) { if ($trid == 'desc') { continue; } $tourObjs[$trid] = new Tour($trid); if ($ENABLE_TOUR_HIDING && $tourObjs[$trid]->is_finished) { $flist_JShides[] = "trid_{$trid}"; } $HIDE_DIV &= $tourObjs[$trid]->is_finished; $FOLDUP_DIV &= $tourObjs[$trid]->is_finished; } if ($HIDE_DIV) { $flist_JShides[] = "did_{$did}"; } if ($FOLDUP_DIV) { $divsToFoldUp[] = $did; } $HIDE_LEAG &= $HIDE_DIV; } if ($HIDE_LEAG) { $flist_JShides[] = "lid_{$lid}"; } } // Print show hidden button. ?> <script language="JavaScript" type="text/javascript"> function showFullTourList() { var hidden=[<?php echo array_strpack("'%s'", $flist_JShides, ','); ?> ]; for (var h in hidden) { slideToggleFast(hidden[h]+'_head'); slideToggleFast(hidden[h]+'_cont'); } return; } </script> <?php echo "<a href='javascript:void(0)' onClick='showFullTourList();'>" . $lng->getTrn('matches/tours/showhidden') . "</a><br>"; // Print fixture list. foreach ($flist as $lid => $divs) { # Container echo "<div id='lid_{$lid}_cont' class='leaguesNCont' style='" . (in_array("lid_{$lid}", $flist_JShides) ? "display:none;" : '') . "'>"; # Title echo "<div class='leagues'><b><a href='javascript:void(0);' onClick=\"slideToggleFast('lid_{$lid}');\">[+/-]</a> " . $flist[$lid]['desc']['lname'] . "</b></div>\n"; # Body echo "<div id='lid_{$lid}'>"; foreach ($divs as $did => $tours) { if ($did == 'desc') { continue; } # Container echo "<div id='did_{$did}_cont' class='divisionsNCont' style='" . (in_array("did_{$did}", $flist_JShides) ? "display:none;" : '') . "'>"; # Title echo "<div class='divisions'><b><a href='javascript:void(0);' onClick=\"slideToggleFast('did_{$did}');\">[+/-]</a> " . $flist[$lid][$did]['desc']['dname'] . "</b></div>"; # Body echo "<div id='did_{$did}' " . (in_array($did, $divsToFoldUp) ? 'style="display:none;"' : '') . ">"; foreach ($tours as $trid => $desc) { if ($trid == 'desc') { continue; } # Container echo "<div id='trid_{$trid}_cont' class='toursNCont' style='" . (in_array("trid_{$trid}", $flist_JShides) ? "display:none;" : '') . "'>"; # Title echo "<div class='tours'><a href='index.php?section=matches&type=tourmatches&trid={$trid}'>" . $flist[$lid][$did][$trid]['desc']['tname'] . "</a>"; $tr = $tourObjs[$trid]; # We already have loaded these - reuse them! $suffix = ''; if ($tr->is_finished) { $suffix .= '- <i>' . $lng->getTrn('common/finished') . '</i> '; } if ($tr->locked) { $suffix .= '- <i>' . $lng->getTrn('common/locked') . '</i> '; } if (!empty($suffix)) { echo ' ' . $suffix; } echo "</div>\n"; # tour title container echo "</div>\n"; # tour container } echo "</div>\n"; # div body container echo "</div>\n"; # div container } echo "</div>\n"; # league body container echo "</div>\n"; # league container } }
* GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ define('T_NO_STARTUP', true); require 'header.php'; HTMLOUT::frame_begin(false, false); title("OBBLM upgrade script"); if (isset($_POST['version'])) { $upgradeMsgs = upgrade_database($_POST['version'], array('lrb' => isset($_POST['lrb']) ? $_POST['lrb'] : false)); echo "<br><b><font color='green'>Finished</font></b>"; if (!empty($upgradeMsgs)) { echo "<br><br><b>IMPORTANT</b>:<br><ul>"; echo array_strpack('<li>%s</li>', $upgradeMsgs, "\n"); echo "</ul>"; } echo "<br><hr><br>"; } ?> Please make sure that the MySQL user and database you have specified in <i>settings.php</i> exist and are valid AND that the rules fields of the old settings file are consistant with the new settings file for those fields which are common.<br><br> Now, click the appropriate SQL code to run depending on the version upgrade you are doing.<br><br> <b>Please note:</b> <ul> <li><b>ALWAYS</b> make sure you have a backup/dump of your OBBLM database before running the upgrade script.</li> <li>If upgrading across two or more versions simply run the SQL code for the next version, one after the other until the latest version is reached.</li> <li>If upgrading <i>from</i> versions <i>previous</i> of v. 0.75 you must consult the <i>INSTALL</i> file and run the listed SQL queries <u>manually</u>.</li> </ul> <br>
private static function _entry($mid, $pid, array $input, $ES = array(), $IMPORT = false) { /** * Updates match data of player. * * When saving mercs pass the extra input fields: f_team_id, nr, skills * When saving stars pass the extra input fields: f_team_id * **/ if ($IMPORT) { // Statuses $LOCKED = $PLAYED = false; // Node IDs $mid = T_IMPORT_MID; $input['f_tour_id'] = $input['f_did'] = $input['f_lid'] = 0; } else { // Statuses $result = mysql_query("SELECT locked, IF(date_played IS NULL OR date_played = '', FALSE, TRUE) AS 'played' FROM matches WHERE match_id = {$mid}"); list($LOCKED, $PLAYED) = mysql_fetch_array($result); // Node IDs $query = "SELECT tour_id AS 'f_tour_id', did AS 'f_did', f_lid AS 'f_lid' FROM matches,tours,divisions WHERE matches.f_tour_id = tours.tour_id AND tours.f_did = divisions.did AND matches.match_id = {$mid}"; $result = mysql_query($query); $input = array_merge($input, mysql_fetch_assoc($result)); } /* Relation IDs */ $rels = array(); switch ($pid) { case $pid > 0: # Ordinary player? $query = "SELECT owned_by_team_id AS 'f_team_id', f_cid AS 'f_coach_id', f_rid AS 'f_race_id' FROM players WHERE player_id = {$pid}"; $result = mysql_query($query); $rels = mysql_fetch_assoc($result); break; case $pid <= ID_STARS_BEGIN || $pid == ID_MERCS: # Star player or Mercenary? $query = "SELECT owned_by_coach_id AS 'f_coach_id', f_race_id AS 'f_race_id' FROM teams WHERE team_id = {$input['f_team_id']}"; $result = mysql_query($query); $rels = mysql_fetch_assoc($result); /* Special $input field processing. */ switch ($pid) { case $pid <= ID_STARS_BEGIN: # Star player? // Star match_data should not be counted/considered as race stats when a team of a given race hires the star. $rels['f_race_id'] = 'NULL'; break; case ID_MERCS: # Mercenary? // Mercs use the injs/agn fields differently from ordinary players. // Nr: #Merc hired by that team. // Skills: Extra skill bought count for the merc. $input['inj'] = $input['nr']; unset($input['nr']); $input['agn1'] = $input['skills']; unset($input['skills']); $input['agn2'] = NONE; break; } break; } $input = array_merge($input, $rels); /* Other match data */ $input['mg'] = $MG = (int) (Player::getPlayerStatus($pid, $mid) == MNG); // Missed (this) Game (ie. had a MNG from previous match)? $input['f_player_id'] = $pid; $input['f_match_id'] = $mid; /* Verify input */ global $T_PMD; $EXPECTED = $T_PMD; # We will be modifying (sorting) the contents, therefore we make a copy. sort($EXPECTED); ksort($input); if (array_keys($input) !== $EXPECTED) { return false; } // Make sure $T_PMD_ACH input data is numeric global $T_PMD_ACH; foreach ($T_PMD_ACH as $field) { if (!is_numeric($input[$field])) { $input[$field] = 0; } } /* Post/pre match fixes Before we write player's match data, we need to check if player's status was... - Set to DEAD? In which case we must delete all the player's match data from matches played after this match (if any played). - Set to MNG? In which case we must zero set the player's match data from match played after this match (if this match is not the latest). */ $status = true; if ($PLAYED) { # Must be played to have a date to compare with. if ($input['inj'] == DEAD) { $query = "DELETE FROM match_data USING match_data INNER JOIN matches \n WHERE match_data.f_match_id = matches.match_id AND f_player_id = {$pid} AND date_played > (SELECT date_played FROM matches WHERE match_id = {$mid})"; $status &= mysql_query($query); } elseif ($input['inj'] != NONE) { # Player has MNG status. global $T_PMD_ACH, $T_PMD_IR, $T_PMD_INJ; $status &= mysql_query("UPDATE match_data SET " . array_strpack('%s = 0', array_merge($T_PMD_ACH, $T_PMD_IR), ',') . ',' . array_strpack('%s = ' . NONE, $T_PMD_INJ, ',') . "\n mg = TRUE \n WHERE f_player_id = {$pid} AND f_match_id = (\n SELECT match_id FROM matches, match_data WHERE \n match_data.f_match_id = matches.match_id AND \n date_played IS NOT NULL AND \n date_played > (SELECT date_played FROM matches WHERE match_id = {$mid}) AND \n f_player_id = {$pid} \n ORDER BY date_played ASC LIMIT 1)"); } } /* Injury corrections THIS IS NO LONGER USED - see issue 462 http://code.google.com/p/obblm/issues/detail?id=462 */ /* Insert data into MySQL */ // Delete entry if already exists (we don't use MySQL UPDATE on rows for simplicity) if (!$IMPORT && $pid != ID_MERCS) { $status &= mysql_query("DELETE FROM match_data WHERE f_player_id = {$pid} AND f_match_id = {$mid}"); } $query = 'INSERT INTO match_data (' . implode(',', $EXPECTED) . ') VALUES (' . implode(',', array_values($input)) . ')'; $result = mysql_query($query) or status(false, 'Failed to save player entry with PID = ' . $pid . '<br><br>' . mysql_error() . '<br><br>' . $query); return $result && (!empty($ES) ? self::ESentry(array('f_pid' => $input['f_player_id'], 'f_tid' => $input['f_team_id'], 'f_cid' => $input['f_coach_id'], 'f_rid' => $input['f_race_id'], 'f_mid' => $input['f_match_id'], 'f_trid' => $input['f_tour_id'], 'f_did' => $input['f_did'], 'f_lid' => $input['f_lid']), $ES) : true) && $status; }
public function getSkillsStr($HTML = false) { /** * Compiles skills string. **/ $this->setSkills(); $chrs = array(); $extras = empty($this->extra_skills) ? array() : array_strpack($HTML ? '<u>%s</u>' : '%s*', skillsTrans($this->extra_skills)); if ($this->ach_ma > 0) { array_push($chrs, "+{$this->ach_ma} Ma"); } if ($this->ach_st > 0) { array_push($chrs, "+{$this->ach_st} St"); } if ($this->ach_ag > 0) { array_push($chrs, "+{$this->ach_ag} Ag"); } if ($this->ach_av > 0) { array_push($chrs, "+{$this->ach_av} Av"); } $defs = skillsTrans($this->def_skills); if ($HTML) { $defs = array_strpack('<i>%s</i>', $defs); } $skillstr = array_merge($defs, skillsTrans(array_merge($this->ach_nor_skills, $this->ach_dob_skills))); return implode(', ', array_merge($skillstr, $extras, $chrs)); }