function perform($edit = array()) { $fields = array(); if (validate_nonblank($edit['username'])) { $fields['username'] = $edit['username']; } if (validate_nonblank($edit['email'])) { $fields['email'] = $edit['email']; } if (count($fields) < 1) { info_exit("You must supply at least one of username or email address"); } /* Now, try and find the user */ $user = Person::load($fields); /* Now, we either have one or zero users. Regardless, we'll present * the user with the same output; that prevents them from using this * to guess valid usernames. */ if ($user) { /* Generate a password */ $pass = generate_password(); $user->set_password($pass); if (!$user->save()) { error_exit("Error setting password"); } /* And fire off an email */ $rc = send_mail($user, false, false, _person_mail_text('password_reset_subject', array('%site' => variable_get('app_name', 'Leaguerunner'))), _person_mail_text('password_reset_body', array('%fullname' => "{$user->firstname} {$user->lastname}", '%username' => $user->username, '%password' => $pass, '%site' => variable_get('app_name', 'Leaguerunner')))); if ($rc == false) { error_exit("System was unable to send email to that user. Please contact system administrator."); } } }
function process() { global $lr_session; $this->title = "{$this->team->name} » Spirit"; $this->template_name = 'pages/team/spirit.tpl'; // load the league $league = League::load(array('league_id' => $this->team->league_id)); // if the person doesn't have permission to see this team's spirit, bail out if (!$lr_session->has_permission('team', 'view', $this->team->team_id, 'spirit')) { info_exit("You do not have permission to view this team's spirit results"); } if ($league->display_sotg == 'coordinator_only' && !$lr_session->is_coordinator_of($league->league_id)) { error_exit("Spirit results are restricted to coordinator-only"); } $s = new Spirit(); $s->display_numeric_sotg = $league->display_numeric_sotg(); /* * Grab schedule info */ $games = Game::load_many(array('either_team' => $this->team->team_id, '_order' => 'g.game_date')); if (!is_array($games)) { info_exit('There are no games scheduled for this team'); } $this->smarty->assign('question_keys', array_merge(array('full'), $s->question_keys(), array('score_entry_penalty'))); $this->smarty->assign('question_headings', $s->question_headings()); $this->smarty->assign('num_spirit_columns', count($s->question_headings()) + 1); $this->smarty->assign('num_comment_columns', count($s->question_headings()) + 2); $rows = array(); foreach ($games as $game) { if (!$game->is_finalized()) { continue; } if ($game->home_id == $this->team->team_id) { $opponent_id = $game->away_id; $opponent_name = $game->away_name; $home_away = '(home)'; } else { $opponent_id = $game->home_id; $opponent_name = $game->home_name; $home_away = '(away)'; } $thisrow = array('game_id' => $game->game_id, 'day_id' => $game->day_id, 'given_by_id' => $opponent_id, 'given_by_name' => $opponent_name, 'has_entry' => 0); # Fetch spirit answers for games $entry = $game->get_spirit_entry($this->team->team_id); if (!$entry) { $rows[] = $thisrow; continue; } $thisrow['has_entry'] = 1; $thisrow = array_merge($thisrow, (array) $s->fetch_game_spirit_items_html($entry)); // can only see comments if you're a coordinator if ($lr_session->has_permission('league', 'view', $this->team->league_id, 'spirit')) { $thisrow[] = $entry['comments']; } $rows[] = $thisrow; } $this->smarty->assign('spirit_detail', $rows); return true; }
function process() { global $lr_session; // Using these multiple times, so saving them $is_admin = $lr_session->is_admin(); $is_captain = $lr_session->is_captain_of($this->team->team_id); $this->title = "{$this->team->name} » Roster Status"; if ($this->team->roster_deadline > 0 && !$lr_session->is_admin() && time() > $this->team->roster_deadline) { info_exit('The roster deadline has passed.'); } if (!$this->player) { $this->title = "{$this->team->name} » Add Player"; if (!($is_admin || $is_captain)) { error_exit("You cannot add a person to that team!"); } $new_handler = new person_search(); $new_handler->smarty =& $this->smarty; $new_handler->initialize(); $new_handler->ops['Add to ' . $this->team->name] = 'team/roster/' . $this->team->team_id; $new_handler->process(); $this->template_name = $new_handler->template_name; return true; } if (!$this->player->is_player()) { error_exit('Only registered players can be added to a team.'); } $events = $this->player->is_eligible_for($this->team->team_id); if ($events !== true) { // Captains and admins can modify players even if they haven't registered for events. // That way, the onus is on the player to register, saving captains the hassle. // So, only disable the roster change for players if (!($is_admin || $is_captain)) { $this->smarty->assign('prerequisites', $events); $this->smarty->assign('disabled', 'disabled="disabled"'); } } $this->positions = Team::get_roster_positions(); $this->currentStatus = $this->team->get_roster_status($this->player->user_id); $this->permittedStates = $this->permitted_roster_states(); $edit =& $_POST['edit']; if ($this->player->status != 'active' && $edit['status'] && $edit['status'] != 'none') { error_exit("Inactive players may only be removed from a team. Please contact this player directly to have them activate their account."); } if ($edit['step'] != 'perform') { $this->smarty->assign('current_status', $this->positions[$this->currentStatus]); $this->smarty->assign('player', $this->player); $this->smarty->assign('team', $this->team); $this->smarty->assign('states', $this->permittedStates); return true; } if (!array_key_exists($edit['status'], $this->permittedStates)) { error_exit("You do not have permission to set that status."); } if (!$this->team->set_roster_status($this->player->user_id, $edit['status'], $this->currentStatus)) { error_exit("Could not set roster status for {$this->player->fullname}"); } local_redirect(url("team/view/" . $this->team->team_id)); return true; }
function process() { global $lr_session; $this->title = 'Registration ' . $this->registration->formatted_order_id() . ' » Add Payment'; $this->smarty->assign('reg', $this->registration); $this->smarty->assign('event', $this->event); // TODO: should be get_user() for consistency. $this->smarty->assign('registrant', $this->registration->user()); $edit = $_POST['edit']; $payment = new RegistrationPayment(); $payment->set('order_id', $this->registration->order_id); $payment->set('entered_by', $lr_session->user->user_id); $fields = array('payment_type', 'payment_amount', 'payment_method', 'paid_by', 'date_paid'); foreach ($fields as $field) { $payment->set($field, $edit[$field]); } $dataInvalid = $payment->validate(); if ($dataInvalid) { info_exit($dataInvalid . '<br>Please use your back button to return to the form, fix these errors, and try again.'); } switch ($edit['step']) { default: case 'confirm': $this->smarty->assign('payment', $payment); $this->template_name = 'pages/registration/addpayment.tpl'; break; case 'submit': if (!$payment->save()) { error_exit("Internal error: couldn't save payment"); } switch ($payment->payment_type) { case 'Deposit': $this->registration->set('payment', 'Deposit Paid'); break; case 'Full': case 'Remaining Balance': $this->registration->set('payment', 'Paid'); break; } if (!$this->registration->save()) { error_exit("Internal error: couldn't save changes to registration"); } local_redirect(url("registration/view/" . $this->registration->order_id)); break; } return true; }
function render_schedule() { if ($this->league->schedule_type == 'none') { info_exit("This league does not have a schedule or standings."); } $sth = Game::query(array('league_id' => $this->league->league_id, 'published' => 1, '_order' => 'g.game_date, g.game_start, field_code')); $currentTime = time(); $games = array(); while ($game = $sth->fetchObject('Game')) { $game->event_status = 'pre-event'; if ($currentTime > $game->timestamp) { $game->event_status = 'post-event'; } $games[] = $game; } $this->smarty->assign('games', $games); }
function save() { $dataInvalid = $this->isDataInvalid(); if ($dataInvalid) { info_exit($dataInvalid . '<br>Please use your back button to return to the form, fix these errors, and try again.'); } $this->registration = new Registration(); $this->registration->set('user_id', $this->registrant_id); $this->registration->set('registration_id', $this->event->registration_id); $this->registration->set('total_amount', $this->event->total_cost()); if ($this->event->cost == 0) { $this->registration->set('payment', 'Paid'); } // TODO: transaction, so that we roll back the registration if we can't save_answers() if (!$this->registration->save()) { error_exit('Could not create registration record.'); } if ($this->formbuilder && !$this->registration->save_answers($this->formbuilder, $_POST[$this->event->formkey()])) { error_exit('Error saving registration question answers.'); } return; }
function generateConfirm(&$edit, $datestamp) { $dataInvalid = $this->isDataInvalid($edit); if ($dataInvalid) { info_exit($dataInvalid . "<br>Please use your back button to return to the form, fix these errors, and try again"); } $this->smarty->assign('start_date', $datestamp); $this->smarty->assign('edit', $edit); $leagues = array(); foreach ($edit['availability'] as $league_id) { $league = League::load(array('league_id' => $league_id)); $leagues[$league_id] = $league->fullname; } $this->smarty->assign('leagues', $leagues); return true; }
function perform(&$edit) { $dataInvalid = $this->isDataInvalid($edit); if ($this->formbuilder) { $this->formbuilder->bulk_set_answers($_POST[$this->event->formkey()]); $dataInvalid .= $this->formbuilder->answers_invalid(); } if ($dataInvalid) { info_exit($dataInvalid . '<br>Please use your back button to return to the form, fix these errors, and try again.'); } $this->registration->set('payment', $edit['payment']); $this->registration->set('notes', $edit['notes']); if (!$this->registration->save()) { error_exit("Internal error: couldn't save changes to the registration details"); } if ($this->formbuilder) { if (!$this->registration->save_answers($this->formbuilder, $_POST[$this->event->formkey()])) { error_exit('Error saving registration question answers.'); } } return true; }
function generateConfirm($edit, $opponent, $spirit = null) { if ($edit['defaulted'] != 'us' && $edit['defaulted'] != 'them') { $questions = $this->spirit->as_formbuilder(); $questions->bulk_set_answers($spirit); } else { $questions = null; } $dataInvalid = $this->isDataInvalid($edit, $questions); if ($dataInvalid) { info_exit($dataInvalid . '<br>Please use your back button to return to the form, fix these errors, and try again.'); } $this->smarty->assign('interim_game_result', $this->interim_game_result($edit, $opponent)); $this->smarty->assign('edit_hidden_fields', $edit); $this->smarty->assign('spirit_hidden_fields', $spirit); if ($edit['defaulted'] != 'us' && $edit['defaulted'] != 'them') { $this->smarty->assign('spirit_answers', $questions->render_viewable()); } return true; }