Example #1
0
 function process()
 {
     $this->title = "Approve Scores";
     $this->template_name = 'pages/league/approvescores.tpl';
     $games = Game::load_many(array('league_id' => $this->league->league_id, 'game_date_past' => 1, '_extra_table' => 'score_entry se', '_extra' => 'se.game_id = s.game_id'));
     foreach ($games as $game) {
         $home = $game->get_score_entry($game->home_id);
         if (!$home) {
             $game->home_score_for = 'not entered';
             $game->home_score_against = 'not entered';
         } else {
             $game->home_score_for = $home->score_for;
             $game->home_score_against = $home->score_against;
         }
         $away = $game->get_score_entry($game->away_id);
         if (!$away) {
             $game->away_score_for = 'not entered';
             $game->away_score_against = 'not entered';
         } else {
             $game->away_score_for = $away->score_for;
             $game->away_score_against = $away->score_against;
         }
         $game->captains_email_list = player_rfc2822_address_list($game->get_captains(), true);
     }
     $this->smarty->assign('games', $games);
 }
Example #2
0
function send_mail($to_list, $from_person, $cc_list, $subject, $message)
{
    if (empty($message)) {
        return false;
    }
    $crlf = "\n";
    if (!is_array($to_list)) {
        $to_list = array($to_list);
    }
    $to = player_rfc2822_address_list($to_list);
    if (!$from_person) {
        $from_person = new Person();
        $from_person->email = variable_get('app_admin_email', 'webmaster@localhost');
        $from_person->fullname = variable_get('app_admin_name', 'Leaguerunner Administrator');
    }
    $from = $from_person->rfc2822_address();
    $headers = "From: {$from}{$crlf}";
    if ($cc_list) {
        $cc = player_rfc2822_address_list($cc_list);
        $headers .= "Cc: {$cc}{$crlf}";
    }
    if (empty($to) && empty($cc)) {
        return false;
    }
    return mail($to, $subject, $message, $headers, "-f {$from_person->email}");
}
Example #3
0
 function process()
 {
     $this->title = "{$this->team->name} » Emails";
     $this->template_name = 'pages/team/emails.tpl';
     $this->team->get_roster();
     $this->smarty->assign('list', player_rfc2822_address_list($this->team->roster, true));
     return true;
 }
Example #4
0
 function process()
 {
     $this->title = "{$this->league->fullname} » Captain Emails";
     $this->template_name = 'pages/league/captemail.tpl';
     $captains = $this->league->get_captains();
     if (!count($captains)) {
         error_exit("That league contains no teams.");
     }
     $this->smarty->assign('list', player_rfc2822_address_list($captains, true));
     return true;
 }
Example #5
0
 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"');
 }