Ejemplo n.º 1
0
 public function setName($name)
 {
     if (!isset($name) || empty($name)) {
         return false;
     }
     $result = mysql_query("SELECT coach_id FROM coaches WHERE name = BINARY('" . mysql_real_escape_string($name) . "')");
     if ($result && mysql_num_rows($result) > 0) {
         return false;
     }
     // Duplicates not allowed.
     $query = "UPDATE coaches SET name = '" . mysql_real_escape_string($name) . "' WHERE coach_id = {$this->coach_id}";
     return mysql_query($query) && ($this->name = $name) && SQLTriggers::run(T_SQLTRIG_COACH_UPDATE_CHILD_RELS, array('id' => $this->coach_id, 'obj' => $this));
 }
Ejemplo n.º 2
0
 public static function create(array $input)
 {
     /**
      * Creates a new team.
      **/
     global $raceididx;
     $EXPECTED = self::$createEXPECTED;
     sort($EXPECTED);
     ksort($input);
     $errors = array(self::T_CREATE_ERROR__UNEXPECTED_INPUT => $EXPECTED !== array_keys($input), self::T_CREATE_ERROR__INVALID_RACE => !in_array((int) $input['f_race_id'], array_keys($raceididx)), self::T_CREATE_ERROR__INVALID_COACH => !get_alt_col('coaches', 'coach_id', (int) $input['owned_by_coach_id'], 'coach_id'), self::T_CREATE_ERROR__INVALID_NAME => get_alt_col('teams', 'name', mysql_real_escape_string($input['name']), 'team_id') || empty($input['name']), self::T_CREATE_ERROR__INVALID_LEAGUE => get_alt_col('coaches', 'coach_id', (int) $input['owned_by_coach_id'], 'ring') != Coach::T_RING_GLOBAL_ADMIN && 0 == (int) SQLFetchField("SELECT COUNT(*) FROM memberships WHERE lid = " . (int) $input['f_lid'] . " AND cid = " . (int) $input['owned_by_coach_id'] . " AND ring >= " . Coach::T_RING_LOCAL_REGULAR), self::T_CREATE_ERROR__INVALID_DIVISION => $input['f_did'] != self::T_NO_DIVISION_TIE && $input['f_lid'] != get_alt_col('divisions', 'did', (int) $input['f_did'], 'f_lid'));
     foreach ($errors as $exitStatus => $halt) {
         if ($halt) {
             return array($exitStatus, null);
         }
     }
     $input['name'] = "'" . mysql_real_escape_string($input['name']) . "'";
     # Need to quote strings when using INSERT statement.
     $query = "INSERT INTO teams (" . implode(',', $EXPECTED) . ") VALUES (" . implode(',', $input) . ")";
     if (mysql_query($query)) {
         $tid = mysql_insert_id();
     } 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_TEAM_NEW, array('id' => $tid, 'obj' => new self($tid)));
     return array(self::T_CREATE_SUCCESS, $tid);
 }
Ejemplo n.º 3
0
 public function finalizeMatchSubmit()
 {
     // Run triggers.
     SQLTriggers::run(T_SQLTRIG_MATCH_UPD, array('mid' => $this->match_id, 'trid' => $this->f_tour_id, 'tid1' => $this->team1_id, 'tid2' => $this->team2_id, 'played' => (int) $this->is_played));
     Module::runTriggers(T_TRIGGER_MATCH_SAVE, array($this->match_id));
     foreach (Star::getStars(false, false, STATS_MATCH, $this->match_id) as $s) {
         mysql_query("SELECT syncMVplayer({$s->star_id}, {$this->f_tour_id})");
     }
     return true;
 }
Ejemplo n.º 4
0
 private function _handleActions($ALLOW_EDIT)
 {
     global $coach;
     $team = $this;
     // Copy. Used instead of $this for readability.
     // No request sent?
     if (!isset($_POST['type']) || !$ALLOW_EDIT) {
         return false;
     }
     // Handle request.
     if (get_magic_quotes_gpc()) {
         $_POST['name'] = stripslashes(isset($_POST['name']) ? $_POST['name'] : '');
         $_POST['skill'] = stripslashes(isset($_POST['skill']) ? $_POST['skill'] : '');
         $_POST['thing'] = stripslashes(isset($_POST['thing']) ? $_POST['thing'] : '');
         $_POST['teamtext'] = stripslashes(isset($_POST['teamtext']) ? $_POST['teamtext'] : '');
         $_POST['txt'] = stripslashes(isset($_POST['txt']) ? $_POST['txt'] : '');
     }
     $p = isset($_POST['player']) && $_POST['type'] != 'hire_player' ? new Player($_POST['player']) : null;
     switch ($_POST['type']) {
         case 'hire_player':
             list($exitStatus, $pid) = Player::create(array('nr' => $_POST['number'], 'f_pos_id' => $_POST['player'], 'team_id' => $team->team_id, 'name' => $_POST['name']), array('JM' => isset($_POST['as_journeyman']) && $_POST['as_journeyman']));
             status(!$exitStatus, $exitStatus ? Player::$T_CREATE_ERROR_MSGS[$exitStatus] : null);
             break;
         case 'hire_journeyman':
             status($p->hireJourneyman());
             break;
         case 'fire_player':
             status($p->sell());
             break;
         case 'unbuy_player':
             status($p->unbuy());
             break;
         case 'rename_player':
             status($p->rename($_POST['name']));
             break;
         case 'renumber_player':
             status($p->renumber($_POST['number']));
             break;
         case 'rename_team':
             status($team->rename($_POST['name']));
             break;
         case 'buy_goods':
             status($team->buy($_POST['thing']));
             break;
         case 'drop_goods':
             status($team->drop($_POST['thing']));
             break;
         case 'ready_state':
             status($team->setReady(isset($_POST['bool'])));
             break;
         case 'retire':
             status(isset($_POST['bool']) && $team->setRetired(true));
             break;
         case 'delete':
             status(isset($_POST['bool']) && $team->delete());
             break;
         case 'skill':
             $type = null;
             $p->setChoosableSkills();
             if (in_array($_POST['skill'], $p->choosable_skills['norm'])) {
                 $type = 'N';
             } elseif (in_array($_POST['skill'], $p->choosable_skills['doub'])) {
                 $type = 'D';
             } else {
                 $type = 'C';
             }
             # Assume it's a characteristic.
             status($p->addSkill($type, $type == 'C' ? (int) str_replace('ach_', '', $_POST['skill']) : (int) $_POST['skill']));
             break;
         case 'teamtext':
             status($team->saveText($_POST['teamtext']));
             break;
         case 'news':
             status($team->writeNews($_POST['txt']));
             break;
         case 'newsdel':
             status($team->deleteNews($_POST['news_id']));
             break;
         case 'newsedit':
             status($team->editNews($_POST['news_id'], $_POST['txt']));
             break;
         case 'pic':
             if ($_POST['add_del'] == 'add') {
                 if ($_POST['pic_obj'] == IMGTYPE_TEAMSTADIUM) {
                     list($status, $msg) = $team->saveStadiumPic(ImageSubSys::$defaultHTMLUploadName . '_stad');
                     status($status, !$status ? $msg : '');
                 } elseif ($_POST['pic_obj'] == IMGTYPE_TEAMLOGO) {
                     list($status, $msg) = $team->saveLogo(ImageSubSys::$defaultHTMLUploadName . '_logo');
                     status($status, !$status ? $msg : '');
                 }
             } else {
                 if ($_POST['pic_obj'] == IMGTYPE_TEAMSTADIUM) {
                     status($team->deleteStadiumPic());
                 } elseif ($_POST['pic_obj'] == IMGTYPE_TEAMLOGO) {
                     status($team->deleteLogo());
                 }
             }
             break;
     }
     // Administrator tools used?
     if ($coach->isNodeCommish(T_NODE_LEAGUE, $team->f_lid)) {
         switch ($_POST['type']) {
             case 'unhire_journeyman':
                 status($p->unhireJourneyman());
                 break;
             case 'unsell_player':
                 status($p->unsell());
                 break;
             case 'unbuy_goods':
                 status($team->unbuy($_POST['thing']));
                 break;
             case 'bank':
                 status($team->dtreasury($dtreas = ($_POST['sign'] == '+' ? 1 : -1) * $_POST['amount'] * 1000));
                 if (Module::isRegistered('LogSubSys')) {
                     Module::run('LogSubSys', array('createEntry', T_LOG_GOLDBANK, $coach->coach_id, "Coach '{$coach->name}' (ID={$coach->coach_id}) added a treasury delta for team '{$team->name}' (ID={$team->team_id}) of amount = {$dtreas}"));
                 }
                 SQLTriggers::run(T_SQLTRIG_TEAM_DPROPS, array('obj' => T_OBJ_TEAM, 'id' => $team->team_id));
                 break;
             case 'spp':
                 status($p->dspp(($_POST['sign'] == '+' ? 1 : -1) * $_POST['amount']));
                 break;
             case 'dval':
                 status($p->dval(($_POST['sign'] == '+' ? 1 : -1) * $_POST['amount'] * 1000));
                 break;
             case 'extra_skills':
                 $func = $_POST['sign'] == '+' ? 'addSkill' : 'rmSkill';
                 status($p->{$func}('E', $_POST['skill']));
                 break;
             case 'ach_skills':
                 $type = null;
                 if (in_array($_POST['skill'], $p->ach_nor_skills)) {
                     $type = 'N';
                 } elseif (in_array($_POST['skill'], $p->ach_dob_skills)) {
                     $type = 'D';
                 } else {
                     $type = 'C';
                 }
                 # Assume it's a characteristic.
                 status($p->rmSkill($type, $type == 'C' ? (int) str_replace('ach_', '', $_POST['skill']) : (int) $_POST['skill']));
                 break;
         }
     }
     $team->setStats(false, false, false);
     # Reload fields in case they changed after team actions made.
 }
Ejemplo n.º 5
0
 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);
 }