function process() { $this->template_name = 'pages/fieldreport/day.tpl'; list($year, $month, $day) = preg_split("/[\\/-]/", $_GET['date']); $today = getdate(); $yyyy = is_numeric($year) ? $year : $today['year']; $mm = is_numeric($month) ? $month : $today['mon']; $dd = is_numeric($day) ? $day : $today['mday']; if (!validate_date_input($yyyy, $mm, $dd)) { error_exit('That date is not valid'); } $this->smarty->assign('date', sprintf("%4d/%02d/%02d", $yyyy, $mm, $dd)); $formattedDay = strftime('%A %B %d %Y', mktime(6, 0, 0, $mm, $dd, $yyyy)); $this->title = "Field Reports » {$formattedDay}"; $sth = FieldReport::query(array('date_played' => sprintf('%d-%d-%d', $yyyy, $mm, $dd), '_order' => 'field_id ASC')); $reports = array(); while ($r = $sth->fetchObject('FieldReport')) { $r->field = Field::load(array('fid' => $r->field_id)); $reports[] = $r; } $this->smarty->assign('reports', $reports); return true; }
function generateForm() { global $lr_session; # Alias, to avoid typing. Bleh. $game =& $this->game; $league =& $this->league; $game->load_score_entries(); $output = form_hidden('edit[step]', 'confirm'); $teams = $league->teams_as_array(); /* Now, since teams may not be in league any longer, we need to force * them to appear in the pulldown */ $teams[$game->home_id] = $game->home_name; $teams[$game->away_id] = $game->away_name; $output .= form_item("League/Division", l($league->fullname, "league/view/{$league->league_id}")); $output .= form_item("Home Team", l($game->home_name, "team/view/{$game->home_id}")); $output .= form_item("Away Team", l($game->away_name, "team/view/{$game->away_id}")); $output .= form_item("Date and Time", "{$game->game_date}, {$game->game_start} until " . $game->display_game_end() . $note); $field = Field::load(array('fid' => $game->fid)); $output .= form_item("Location", l("{$field->fullname} ({$game->field_code})", "field/view/{$game->fid}"), $note); if ($lr_session->is_coordinator_of($game->league_id)) { $output .= form_item("Site Ranking (home team)", $game->get_site_ranking($game->home_id)); $output .= form_item("Site Ranking (away team)", $game->get_site_ranking($game->away_id)); } $output .= form_item("Game Status", $game->status); if (isset($game->round)) { $output .= form_item("Round", $game->round); } $spirit_group = ''; $score_group = ''; /* * Now, for scores and spirit info. Possibilities: * - game has been finalized: * - everyone can see scores * - coordinator can edit scores/spirit * - game has not been finalized * - players only see "not yet submitted" * - captains can see submitted scores * - coordinator can see everything, edit final scores/spirit */ if ($game->approved_by) { // Game has been finalized if (!$this->can_edit) { // If we're not editing, display score. If we are, // it will show up below. switch ($game->status) { case 'home_default': $home_status = " (defaulted)"; break; case 'away_default': $away_status = " (defaulted)"; break; case 'forfeit': $home_status = " (forfeit)"; $away_status = " (forfeit)"; break; } $score_group .= form_item("Home ({$game->home_name} [rated: {$game->rating_home}]) Score", "{$game->home_score} {$home_status}"); $score_group .= form_item("Away ({$game->away_name} [rated: {$game->rating_away}]) Score", "{$game->away_score} {$away_status}"); } if ($game->home_score == $game->away_score && $game->rating_points == 0) { $score_group .= form_item("Rating Points", "No points were transferred between teams"); } else { if ($game->home_score >= $game->away_score) { $winner = l($game->home_name, "team/view/{$game->home_id}"); $loser = l($game->away_name, "team/view/{$game->away_id}"); } elseif ($game->home_score < $game->away_score) { $winner = l($game->away_name, "team/view/{$game->away_id}"); $loser = l($game->home_name, "team/view/{$game->home_id}"); } $score_group .= form_item("Rating Points", $game->rating_points, $winner . " gain " . $game->rating_points . " points and " . $loser . " lose " . $game->rating_points . " points"); } switch ($game->approved_by) { case APPROVAL_AUTOMATIC: $approver = 'automatic approval'; break; case APPROVAL_AUTOMATIC_HOME: $approver = 'automatic approval using home submission'; break; case APPROVAL_AUTOMATIC_AWAY: $approver = 'automatic approval using away submission'; break; case APPROVAL_AUTOMATIC_FORFEIT: $approver = 'game automatically forfeited due to lack of score submission'; break; default: $approver = Person::load(array('user_id' => $game->approved_by)); $approver = l($approver->fullname, "person/view/{$approver->user_id}"); } $score_group .= form_item("Score Approved By", $approver); } else { /* * Otherwise, scores are still pending. */ if ($lr_session->is_coordinator_of($game->league_id)) { $list = player_rfc2822_address_list($game->get_captains(), true); $output .= para(l('Click here to send an email', "mailto:{$list}") . ' to all captains.'); } $stats_group = ''; /* Use our ratings to try and predict the game outcome */ $homePct = $game->home_expected_win(); $awayPct = $game->away_expected_win(); $stats_group .= form_item("Chance to win", table(null, array(array($game->home_name, sprintf("%0.1f%%", 100 * $homePct)), array($game->away_name, sprintf("%0.1f%%", 100 * $awayPct)), array("View the " . l('Ratings Table', "game/ratings/{$game->game_id}") . " for this game.")))); $output .= form_group("Statistics", $stats_group); $score_group .= form_item('', "Score not yet finalized"); if ($lr_session->has_permission('game', 'view', $game, 'submission')) { $score_group .= form_item("Score as entered", $this->score_entry_display()); } } // Now, we always want to display this edit code if we have // permission to edit. if ($this->can_edit) { $score_group .= form_select('Game Status', 'edit[status]', $game->status, getOptionsFromEnum('schedule', 'status'), "To mark a game as defaulted, select the appropriate option here. Appropriate scores will automatically be entered."); $score_group .= form_textfield("Home ({$game->home_name} [rated: {$game->rating_home}]) score", 'edit[home_score]', $game->home_score, 2, 2); $score_group .= form_textfield("Away ({$game->away_name} [rated: {$game->rating_away}]) score", 'edit[away_score]', $game->away_score, 2, 2); } $output .= form_group("Scoring", $score_group); if ($lr_session->has_permission('game', 'view', $game, 'spirit')) { $ary = $game->get_spirit_entry($game->home_id); $s = new Spirit(); $formbuilder = $s->as_formbuilder(); if ($ary) { $formbuilder->bulk_set_answers($ary); // TODO: when not editable, display viewable tabular format with symbols $home_spirit_group = $this->can_edit ? $formbuilder->render_editable(true, 'home') : $formbuilder->render_viewable(true, 'home'); } else { $formbuilder->bulk_set_answers($s->default_spirit_answers()); $home_spirit_group = $this->can_edit ? $formbuilder->render_editable(true, 'home') : 'Not entered'; } $formbuilder->clear_answers(); $ary = $game->get_spirit_entry($game->away_id); if ($ary) { $formbuilder->bulk_set_answers($ary); $away_spirit_group = $this->can_edit ? $formbuilder->render_editable(true, 'away') : $formbuilder->render_viewable(true, 'away'); } else { $formbuilder->bulk_set_answers($s->default_spirit_answers()); $away_spirit_group = $this->can_edit ? $formbuilder->render_editable(true, 'away') : 'Not entered'; } $output .= form_group("Spirit assigned TO home ({$game->home_name})", $home_spirit_group); $output .= form_group("Spirit assigned TO away ({$game->away_name})", $away_spirit_group); } if ($lr_session->has_permission('field', 'view reports')) { $sth = FieldReport::query(array('game_id' => $this->game->game_id)); $header = array("Date Reported", "Reported By", "Report"); while ($r = $sth->fetchObject('FieldReport')) { $rows[] = array($r->created, l($r->reporting_user_fullname, url("person/view/" . $r->reporting_user_id)), $r->report_text); } $output .= form_group("This game's field reports for " . $field->fullname, "<div class='listtable'>" . table($header, $rows) . "</div>\n"); } if ($this->can_edit) { $output .= para(form_submit("submit") . form_reset("reset")); } return $script . form($output, 'post', null, 'id="score_form"'); }