public static function create(array $input, array $opts) { /** * Creates a new player. * * Input: nr, f_pos_id, name, team_id **/ global $rules, $DEA, $T_ALL_PLAYER_NR; $lid = get_alt_col('teams', 'team_id', $input['team_id'], 'f_lid'); setupGlobalVars(T_SETUP_GLOBAL_VARS__LOAD_LEAGUE_SETTINGS, array('lid' => (int) $lid)); // Load correct $rules for league. // Do these fixes because we can't define class statics using string interpolation for $rules. self::$T_CREATE_ERROR_MSGS[self::T_CREATE_ERROR__TEAM_FULL] .= " You have filled all {$rules['max_team_players']} available positions."; self::$T_CREATE_ERROR_MSGS[self::T_CREATE_ERROR__JM_LIMIT_REACHED] .= " Your team is now able to fill {$rules['journeymen_limit']} positions."; $JM = isset($opts['JM']) && $opts['JM']; $FREE = isset($opts['free']) && $opts['free']; $FORCE = isset($opts['force']) && $opts['force']; # When forcing ($FORCE is true) we ignore these errors: $ignoreableErrors = array(self::T_CREATE_ERROR__TEAM_FULL, self::T_CREATE_ERROR__POS_LIMIT_REACHED, self::T_CREATE_ERROR__INSUFFICIENT_FUNDS, self::T_CREATE_ERROR__NUMBER_OCCUPIED, self::T_CREATE_ERROR__JM_LIMIT_REACHED, self::T_CREATE_ERROR__INVALID_JM_POS); $EXPECTED = self::$createEXPECTED; sort($EXPECTED); ksort($input); // Input error handler if (!get_alt_col('teams', 'team_id', (int) $input['team_id'], 'team_id')) { return array(self::T_CREATE_ERROR__INVALID_TEAM, null); } else { $team = new Team((int) $input['team_id']); } $errors = array(self::T_CREATE_ERROR__UNEXPECTED_INPUT => $EXPECTED !== array_keys($input), self::T_CREATE_ERROR__TEAM_FULL => !$JM && $team->isFull(), self::T_CREATE_ERROR__INVALID_POS => !$team->isPlayerPosValid((int) $input['f_pos_id']), self::T_CREATE_ERROR__POS_LIMIT_REACHED => !$team->isPlayerBuyable((int) $input['f_pos_id']), self::T_CREATE_ERROR__INSUFFICIENT_FUNDS => $team->treasury - ($price = $JM || $FREE ? 0 : self::price((int) $input['f_pos_id'])) < 0, self::T_CREATE_ERROR__INVALID_NUMBER => !in_array($input['nr'], $T_ALL_PLAYER_NR), self::T_CREATE_ERROR__NUMBER_OCCUPIED => $team->isPlayerNumberOccupied((int) $input['nr']), self::T_CREATE_ERROR__JM_LIMIT_REACHED => $JM && $team->isJMLimitReached(), self::T_CREATE_ERROR__INVALID_JM_POS => $JM && $DEA[$team->f_rname]['players'][get_alt_col('game_data_players', 'pos_id', (int) $input['f_pos_id'], 'pos')]['qty'] < 12); foreach ($errors as $exitStatus => $halt) { if ($halt && !($FORCE && in_array($exitStatus, $ignoreableErrors))) { return array($exitStatus, null); } } $input['owned_by_team_id'] = (int) $input['team_id']; unset($input['team_id']); $input['name'] = "'" . mysql_real_escape_string($input['name']) . "'"; $input['date_bought'] = 'NOW()'; $input['type'] = $JM ? PLAYER_TYPE_JOURNEY : PLAYER_TYPE_NORMAL; foreach (array('ach_ma', 'ach_st', 'ach_ag', 'ach_av', 'extra_spp') as $f) { $input[$f] = 0; } $query = "INSERT INTO players (" . implode(',', array_keys($input)) . ") VALUES (" . implode(',', array_values($input)) . ")"; if (mysql_query($query)) { $pid = mysql_insert_id(); $team->dtreasury(-1 * $price); } else { self::$T_CREATE_SQL_ERROR['query'] = $query; self::$T_CREATE_SQL_ERROR['error'] = mysql_error(); return array(self::T_CREATE_ERROR__SQL_QUERY_FAIL, null); } SQLTriggers::run(T_SQLTRIG_PLAYER_NEW, array('id' => $pid, 'obj' => (object) array('player_id' => $pid, 'owned_by_team_id' => (int) $input['owned_by_team_id']))); # Update PV and TV. return array(self::T_CREATE_SUCCESS, $pid); }
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; }
# The status must be set as the "inj" (not agn) field for EVERY match (import) entry. # This is because MySQL may pick a random match data entry from which to get the status from. $pstatus = $T_INJS_REV[strtoupper($p->status)]; # Injuries foreach (array('ma', 'st', 'ag', 'av', 'ni') as $inj) { $agn = $T_INJS_REV[strtoupper($inj)]; while ($p->{$inj}-- > 0) { $status2 &= Match::ImportEntry($pid, array_merge(array_fill_keys(array_merge($T_PMD_ACH, $T_PMD_IR), 0), array_combine($T_PMD_INJ, array($pstatus, $agn, $p->{$inj}-- > 0 ? $agn : NONE)))); } } # Set player achievements $status2 &= Match::ImportEntry($pid, array_merge(array_intersect_key((array) $p, array_fill_keys($T_PMD_ACH, null)), array_combine($T_PMD_INJ, array($pstatus, NONE, NONE)), array_fill_keys($T_PMD_IR, 0))); status($status2, "Added to '{$t->name}' player '{$p->name}'"); } # Set correct treasury. $team->dtreasury($t->treasury * 1000 - $team->treasury); // $t->treasury + $delta = XML value $team->postImportSync(); } if ($ROLLBACK) { status($team->delete(), 'Successfully deleted new team due to error.'); } } } title($lng->getTrn('menu/admin_menu/import')); ?> This page allows you to create a customized team for an existing coach.<br> This is useful if you and your league wish to avoid starting from scratch in order to use OBBLM.<br> <br> <b>Note</b>: If you discover errors after having imported your team, you can either repair the errors<br> via the admin tools in the coach corner, or simply delete the team and import a new.<br>