/**
  * @return void
  * @desc Re-build from data posted by this control the data object this control
  * is editing
  */
 function BuildPostedDataObject()
 {
     $user = new User();
     $user->SetId($_POST['item']);
     $user->SetFirstName($_POST['name_first']);
     $user->SetLastName($_POST['name_last']);
     $user->SetName($_POST['known_as']);
     $user->SetEmail($_POST['email']);
     $user->SetAccountDisabled(isset($_POST['disabled']));
     $roles = $this->roles_editor->DataObjects()->GetItems();
     foreach ($roles as $role) {
         $user->Roles()->Add($role);
     }
     $this->SetDataObject($user);
 }
 /**
  * @return void
  * @desc Re-build from data posted by this control the data object this control is editing
  */
 function BuildPostedDataObject()
 {
     $o_person = new User();
     if (isset($_POST['known_as'])) {
         $o_person->SetName($_POST['known_as']);
     }
     if (isset($_POST['email'])) {
         $o_person->SetEmail($_POST['email']);
     }
     if (isset($_POST['password1'])) {
         $o_person->SetPassword($_POST['password1']);
     }
     if (isset($_POST['password2'])) {
         $o_person->SetPasswordConfirmation($_POST['password2']);
     }
     $this->SetDataObject($o_person);
 }
 /**
  * Notifies the moderator(s) for a match that it has been added or updated. If no arguments, send all outstanding notifications.
  * @param int $match_id
  * @return void
  */
 public function NotifyMatchModerator($match_id = null)
 {
     # Check in the queue whether to actually send the email, because even if "Save" is clicked on a match it may not have
     # been updated if the data didn't change. If the data changed there should be an entry in the queue.
     require_once 'data/queue-action.enum.php';
     $queue = $this->GetSettings()->GetTable('Queue');
     $user = $this->GetSettings()->GetTable('User');
     $this->Lock($queue);
     $sql = "SELECT DISTINCT {$queue}.data, {$queue}.action, {$user}.user_id, {$user}.known_as, {$user}.email\r\n\t\tFROM {$queue} LEFT JOIN {$user} ON {$queue}.user_id = {$user}.user_id\r\n\t\tWHERE action IN (" . QueueAction::MATCH_ADDED . "," . QueueAction::MATCH_UPDATED . ") ";
     $match_ids = array();
     if (is_null($match_id)) {
         # Get any notifications from over an hour ago. That should only be ones where the user clicked away from an add/update wizard before the last page.
         # Want to avoid logging an update on p1 of a wizard and sending an email before they finish p4 and submit.
         $sql .= "AND {$queue}.date_added < " . (gmdate('U') - 60 * 60);
     } else {
         # Check in the queue for the specific match
         $sql .= "AND {$queue}.data " . Sql::ProtectNumeric($match_id, false, true);
     }
     $result = $this->GetDataConnection()->query($sql);
     while ($row = $result->fetch()) {
         $user_who_updated_match = new User($row->user_id, $row->known_as);
         $user_who_updated_match->SetEmail($row->email);
         $match_ids[(int) $row->data] = array($user_who_updated_match, (int) $row->action == QueueAction::MATCH_ADDED);
     }
     $result->closeCursor();
     unset($result);
     if (count($match_ids)) {
         # Now that we know what notification to send, remove those match(es) from the queue
         $sql = "DELETE FROM {$queue} WHERE action IN (" . QueueAction::MATCH_ADDED . "," . QueueAction::MATCH_UPDATED . ") AND data IN (" . join(', ', array_keys($match_ids)) . ") ";
         $this->GetDataConnection()->query($sql);
     }
     $this->Unlock();
     # Get info on the matches needed to send the email
     if (count($match_ids)) {
         $s_match = $this->GetSettings()->GetTable('Match');
         $s_season = $this->GetSettings()->GetTable('Season');
         $s_season_match = $this->GetSettings()->GetTable('SeasonMatch');
         $s_comp = $this->GetSettings()->GetTable('Competition');
         $s_ground = $this->GetSettings()->GetTable('Ground');
         $s_mt = $this->GetSettings()->GetTable('MatchTeam');
         $sql = "SELECT {$s_match}.match_id, {$s_match}.match_title, {$s_match}.start_time, {$s_match}.start_time_known, {$s_match}.match_type, {$s_match}.short_url,\r\n\t\t\t{$s_match}.home_bat_first, {$s_match}.match_notes, {$s_match}.home_runs, {$s_match}.home_wickets, {$s_match}.away_runs, {$s_match}.away_wickets,\r\n\t\t\t{$s_season}.season_id, {$s_season}.season_name, {$s_season}.start_year, {$s_season}.end_year, " . $s_comp . '.competition_id, ' . $s_comp . '.competition_name, ' . $s_comp . '.notification_email, ' . "{$s_ground}.ground_id, {$s_ground}.saon, {$s_ground}.paon, {$s_ground}.town,\r\n\t\t\thome_team.team_id AS home_team_id, home_team.team_name AS home_team_name,\r\n\t\t\taway_team.team_id AS away_team_id, away_team.team_name AS away_team_name\r\n\t\t\tFROM ((((((({$s_match} LEFT OUTER JOIN {$s_season_match} ON {$s_match}.match_id = {$s_season_match}.match_id) " . 'LEFT OUTER JOIN ' . $s_season . ' ON ' . $s_season_match . '.season_id = ' . $s_season . '.season_id) ' . 'LEFT OUTER JOIN ' . $s_comp . ' ON ' . $s_season . '.competition_id = ' . $s_comp . '.competition_id) ' . 'LEFT OUTER JOIN ' . $s_ground . ' ON ' . $s_match . '.ground_id = ' . $s_ground . '.ground_id) ' . 'LEFT OUTER JOIN ' . $s_mt . ' AS home_link ON ' . $s_match . '.match_id = home_link.match_id AND home_link.team_role = ' . TeamRole::Home() . ') ' . 'LEFT OUTER JOIN nsa_team AS home_team ON home_link.team_id = home_team.team_id AND home_link.team_role = ' . TeamRole::Home() . ")\r\n\t\t\tLEFT OUTER JOIN {$s_mt} AS away_link ON {$s_match}.match_id = away_link.match_id AND away_link.team_role = " . TeamRole::Away() . ') ' . 'LEFT OUTER JOIN nsa_team AS away_team ON away_link.team_id = away_team.team_id AND away_link.team_role = ' . TeamRole::Away() . "\r\n\t\t\tWHERE {$s_match}.match_id IN (" . join(', ', array_keys($match_ids)) . ") ";
         # run query
         $result = $this->GetDataConnection()->query($sql);
         $this->BuildItems($result);
         $result->closeCursor();
         unset($result);
         # send email
         require_once 'data-change-notifier.class.php';
         $o_notify = new DataChangeNotifier($this->GetSettings());
         foreach ($this->GetItems() as $match) {
             $o_notify->MatchUpdated($match, $match_ids[$match->GetId()][0], $match_ids[$match->GetId()][1]);
         }
     }
 }
 /**
  * When a user's credentials have been validated, get more info on that user
  * @param int $user_id
  * @return User
  */
 public function ReadDataForValidUser($user_id)
 {
     $user = null;
     $sql = "SELECT user_id, known_as, name_first, name_last, email, \r\n        disabled, activated, requested_email\r\n        FROM nsa_user WHERE user_id = " . Sql::ProtectNumeric($user_id);
     $result = $this->GetDataConnection()->query($sql);
     $row = $result->fetch();
     if ($row) {
         $user = new User();
         $user->SetId($row->user_id);
         $user->SetName($row->known_as);
         $user->SetFirstName($row->name_first);
         $user->SetLastName($row->name_last);
         $user->SetEmail($row->email);
         $user->SetRequestedEmail($row->requested_email);
         $user->SetAccountActivated($row->activated);
         $user->SetAccountDisabled($row->disabled);
     }
     return $user;
 }