Example #1
0
 public static function create(array $input)
 {
     /**
      * Creates a new coach.
      *
      * Input: name, realname, passwd, mail, phone, ring, settings, def_leagues (array of LIDs)
      **/
     global $settings;
     if (empty($input['name']) || empty($input['passwd']) || get_alt_col('coaches', 'name', $input['name'], 'coach_id') || !in_array($input['ring'], self::$RINGS[self::T_RING_GROUP_GLOBAL])) {
         return false;
     }
     $query = "INSERT INTO coaches (name, realname, passwd, mail, phone, ring, settings) \r\n                    VALUES ('" . mysql_real_escape_string($input['name']) . "',\r\n                            '" . mysql_real_escape_string($input['realname']) . "', \r\n                            '" . md5($input['passwd']) . "', \r\n                            '" . mysql_real_escape_string($input['mail']) . "', \r\n                            '" . mysql_real_escape_string($input['phone']) . "', \r\n                            " . $input['ring'] . ",\r\n                            '" . array_strpack_assoc('%k=%v', $input['settings'], ',') . "')";
     if (($status = mysql_query($query)) && is_numeric($cid = mysql_insert_id())) {
         // Set default memberships
         $newCoach = new Coach($cid);
         foreach (array_merge($settings['default_leagues'], $input['def_leagues']) as $lid) {
             $status &= $newCoach->setRing(self::T_RING_GROUP_LOCAL, self::T_RING_LOCAL_REGULAR, $lid);
         }
     }
     return $status ? $cid : false;
 }
Example #2
0
 public function update(array $input)
 {
     /* 
         Updates general match data. 
         
         $input must contain the keys defined in $core_tables, with the exception of the $filter contents below.
     */
     // Verify input
     global $core_tables;
     $filter = array('match_id', 'round', 'f_tour_id', 'locked', 'date_played', 'date_modified', 'date_created', 'team1_id', 'team2_id');
     $EXPECTED = array_diff(array_keys($core_tables['matches']), $filter);
     sort($EXPECTED);
     $PASSED = array_keys($input);
     sort($PASSED);
     if ($PASSED !== $EXPECTED) {
         return false;
     }
     // Input check.
     if ($this->locked || !get_alt_col('coaches', 'coach_id', $input['submitter_id'], 'coach_id')) {
         # If invalid submitter ID (coach ID) then quit.
         return false;
     }
     // Determine if team fan-factors are within the "> 0" limit. If not, don't save the negative fan-factor.
     $team1 = new Team($this->team1_id);
     $team2 = new Team($this->team2_id);
     if ($team1->rg_ff - $this->ffactor1 + $input['ffactor1'] < 0) {
         $input['ffactor1'] = $this->ffactor1;
     }
     if ($team2->rg_ff - $this->ffactor2 + $input['ffactor2'] < 0) {
         $input['ffactor2'] = $this->ffactor2;
     }
     // Entry corrections
     $input['date_played'] = $this->is_played ? 'date_played' : 'NOW()';
     $input['date_modified'] = 'NOW()';
     // Update match entry.
     $query = "UPDATE matches SET " . array_strpack_assoc('%k = %v', $input, ',') . " WHERE match_id = {$this->match_id}";
     if (!mysql_query($query)) {
         return false;
     }
     // Update team treasury
     $team1->dtreasury($input['income1'] - $this->income1);
     $team2->dtreasury($input['income2'] - $this->income2);
     return true;
 }