TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 884
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 455
  • Total: 455

Roster Page - modified

Started by tarmer, April 11, 2008, 02:31:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tarmer

Excellent.... No hurry - As you can is fine

I appreciate it

JPDeni

I have something that you can look at to be sure this is what you want.

http://www.jpdeni.com/snippets/index.php?page=8&team=1

I'm sure those statistics are way off, but I just had to put something in there. :)

I still have to write the code for editing stuff. Do you want the awards (championships and cups) for the team to be displayed on the top of the roster?

tarmer

Those are excellent... Very well done

The awards should be at the top of the page -

Thanks much - looking forward to seeing the finished product

Thank you for the endevor

JPDeni

Cool! I just wanted to be sure we were on the same "page". ;)

I'll probably have this finished some time tomorrow.

tarmer

Again ...  Thanks for all of the work - Looking forward to seeing it

JPDeni

Best laid plans... :)

Migraine hit. It's better today.

A couple more questions... Can awards only be won by one team? For example, I'm assuming that there is only one winner of the 2007 Championship and 2006 World Cup. Is my assumption correct?

Do you need to be able to delete teams or players? Do you need to have players' names alphabetized by last name?

I've done a bit of adjusting on the printout.

tarmer


Sorry about Migrane (they are a pain - pardon the pun) glad you are up and about again

QuoteA couple more questions... Can awards only be won by one team? For example, I'm assuming that there is only one winner of the 2007 Championship and 2006 World Cup. Is my assumption correct?

There will be 1 Champion per Division (Division 1 - Division 2) per year
There will only be 1 cup winner per year
Yes you are correct

QuoteDo you need to be able to delete teams or players? Do you need to have players' names alphabetized by last name?

This is the tricky one - Players may get released from teams so they no longer appear on a roster BUT once their name is in the DB it would be great if they did not have to be re-created just re-used should they get put on another team (as they will have career stats that would be a pain to re-create from memory) - Does that make sense ?

And last name would be great....

Thanks

JPDeni

Finally!!

Give this a try:


global $db_prefix, $scripturl, $user_info, $settings;

$positions = array('Goalkeeper','Defender','Midfielder','Forward');

//Add more countries here. Don't worry about them being in alphabetical order.
//For abbreviations see http://www.checkdomain.com/list.html or the install.xml file in the "Country Flags" mod
$countries = array (
                    'ar' => 'Argentina',
                    'es' => 'Spain',
                    'uk' => 'England',
                   );

//Use the .png flag images from the "Country Flags" mod -- http://custom.simplemachines.org/mods/index.php?mod=417
//The flag images should go into /Themes/default/images/flags/ -- If you put them somewhere else, enter the URL to the folder here
$flag_dir = $settings['default_theme_url'] . '/images/flags/';

// Create database tables
// You can delete this next bit after you run it once
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
db_query("CREATE TABLE IF NOT EXISTS {$db_prefix}jpd_fanteams (
`team_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`teamOwner` TINYTEXT NOT NULL ,
`teamOwnerID` INT( 11 ) NOT NULL DEFAULT '0',
`teamName` TINYTEXT NOT NULL ,
`teamStadium` TINYTEXT NOT NULL ,
PRIMARY KEY ( `team_id` )
) ENGINE = MYISAM", __FILE__, __LINE__);

db_query("CREATE TABLE IF NOT EXISTS {$db_prefix}jpd_fanplayers (
`player_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`team_id` INT( 11 ) NOT NULL DEFAULT '0',
`playerFName` TINYTEXT NOT NULL ,
`playerLName` TINYTEXT NOT NULL ,
`playerPosition` TINYTEXT NOT NULL ,
`playerNationality` TINYTEXT NOT NULL ,
`playerSalary` TINYTEXT NOT NULL ,
`playerGoals` INT( 3 ) NOT NULL DEFAULT '0',
`playerAssists` INT( 3 ) NOT NULL DEFAULT '0',
`playerCleanSheets` INT( 3 ) NOT NULL DEFAULT '0',
PRIMARY KEY ( `player_id` )
) ENGINE = MYISAM", __FILE__, __LINE__);

db_query("CREATE TABLE IF NOT EXISTS {$db_prefix}jpd_fanawards (
`award_id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
`team_id` INT( 11 ) NOT NULL DEFAULT '0',
`awardType` TINYTEXT NOT NULL ,
`awardYear` INT( 4 ) NOT NULL DEFAULT '0',
PRIMARY KEY ( `award_id` )
) ENGINE = MYISAM", __FILE__, __LINE__);
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////

$teams = array();
$query =  db_query(
          "SELECT team_id,teamName
           FROM {$db_prefix}jpd_fanteams
           ORDER BY teamName", __FILE__, __LINE__);
while ($row = mysql_fetch_assoc($query))
  $teams[$row['team_id']] = $row['teamName'];
$page = $_GET['page'];
$printed = 0;

//**Add/Edit team form
if ((isset($_GET['addteam']) || isset($_GET['editteam'])) && $user_info['is_admin']) {
  if (isset($_GET['addteam'])) {
    $teamowner = "";
    $teamname = "";
    $teamstadium = "";
    $submit = "Add Team";
    $hidden = "addteam";
    $teamid = "";
  }
  else {
    $team = $_GET['team'];
    $query =  db_query(
          "SELECT *
           FROM {$db_prefix}jpd_fanteams
           WHERE team_id LIKE $team", __FILE__, __LINE__);
    $row = mysql_fetch_assoc($query);
    $teamowner = $row['teamOwner'];
    $teamname = $row['teamName'];
    $teamstadium = $row['teamStadium'];
    $teamid = $row['team_id'];
    $submit = "Edit Team";
    $hidden = "editteam";
  }
  echo '<form action="' . $scripturl . '?page=' . $page . '" method="POST">';
  echo '<center><table>
          <input type="hidden" name="' . $hidden . '" value="2">
          <input type="hidden" name="teamid" value="' . $teamid . '">
          <tr><td align="right">Team Owner:</td>
              <td align="left"><input type="text" name="teamOwner" value="' . $teamowner . '"></td></tr>
          <tr><td align="right">Team Name:</td>
              <td align="left"><input type="text" name="teamName" value="' . $teamname . '"></td></tr>
          <tr><td align="right">Team Stadium:</td>
              <td align="left"><input type="text" name="teamStadium" value="' . $teamstadium . '"></td></tr>
          <tr><td colspan="2" align="center"><INPUT type="submit" name="team" value="' . $submit . '"></td></tr>';
  echo '</table></center></form>';
  $printed = 1;
}
// Add team to database
elseif (isset($_POST['addteam']) && $_POST['addteam'] == 2 && $user_info['is_admin']) {
  $teamOwner = $_POST['teamOwner'];
  $teamName = $_POST['teamName'];
  $teamStadium = $_POST['teamStadium'];
  $query =  db_query(
          "SELECT ID_MEMBER
           FROM {$db_prefix}members
           WHERE realName LIKE '$teamOwner'
           LIMIT 1", __FILE__, __LINE__);
  $row = mysql_fetch_assoc($query);
  $teamOwnerID = $row['ID_MEMBER'];
  db_query("INSERT INTO `{$db_prefix}jpd_fanteams`
          (team_id,teamOwner,teamOwnerID,teamName,teamStadium)
           VALUES (NULL, '$teamOwner', '$teamOwnerID', '$teamName', '$teamStadium')", __FILE__, __LINE__);
}
//**Update team in database
elseif (isset($_POST['editteam']) && $_POST['editteam'] == 2 && $user_info['is_admin']) {
  $teamOwner = $_POST['teamOwner'];
  $teamName = $_POST['teamName'];
  $teamStadium = $_POST['teamStadium'];
  $team_id = $_POST['teamid'];
  $query =  db_query(
          "SELECT ID_MEMBER
           FROM {$db_prefix}members
           WHERE realName LIKE '$teamOwner'
           LIMIT 1", __FILE__, __LINE__);
  $row = mysql_fetch_assoc($query);
  $teamOwnerID = $row['ID_MEMBER'];
  db_query("UPDATE `{$db_prefix}jpd_fanteams`
            SET `teamOwner` = '$teamOwner' , `teamOwnerID` = '$teamOwnerID',
                `teamName` = '$teamName', `teamStadium` = '$teamStadium'
            WHERE `team_id` =$team_id", __FILE__, __LINE__);
}

//**Add/Edit award form
if ((isset($_GET['addaward']) || isset($_GET['editaward'])) && $user_info['is_admin']) {
  if (isset($_GET['addaward'])) {
    $team_id = '';
    $awardType = '';
    $awardYear = '';
    $award_id = '';
    $submit = "Add award";
    $hidden = "addaward";
  }
  else {
    $award_id = $_GET['award'];
    $query =  db_query(
          "SELECT *
           FROM {$db_prefix}jpd_fanawards
           WHERE award_id LIKE $award_id", __FILE__, __LINE__);
    $row = mysql_fetch_assoc($query);
    $team_id = $row['team_id'];
    $awardType = $row['awardType'];
    $awardYear = $row['awardYear'];
    $submit = "Edit award";
    $hidden = "editaward";
  }
  echo '<form action="' . $scripturl . '?page=' . $page . '" method="POST">';
  echo '<center><table>
          <input type="hidden" name="' . $hidden . '" value="2">
          <input type="hidden" name="award_id" value="' . $award_id . '">
          <tr><td align="right">Team:</td>
              <td align="left"><select name="team_id">
              <option value=""> </option>';
    foreach ($teams as $key => $team) {
      echo '<option value="' . $key . '"';
      if ($team_id == $key)
        echo ' SELECTED ';
      echo '>' . $team . '</option>';
    }
    echo '</select>';
           echo '</td></tr>
          <tr><td align="right">Award Type:</td>
              <td align="left"><input type="text" name="awardType" value="' . $awardType . '"></td></tr>
          <tr><td align="right">Year:</td>
              <td align="left"><input type="text" name="awardYear" value="' . $awardYear . '" size="4"></td></tr>
          <tr><td colspan="2" align="center"><INPUT type="submit" name="award" value="' . $submit . '"></td></tr>';
  echo '</table></center></form>'; 
  $printed = 1;
}

// Add award to database
elseif (isset($_POST['addaward']) && $_POST['addaward'] == 2 && $user_info['is_admin']) {
  $team_id = $_POST['team_id'];
  $awardType = $_POST['awardType'];
  $awardYear = $_POST['awardYear'];
  db_query("INSERT INTO `{$db_prefix}jpd_fanawards`
          (award_id,team_id,awardType,awardYear)
           VALUES (NULL, '$team_id', '$awardType', '$awardYear')", __FILE__, __LINE__);
}
//**Update an award in the database
elseif (isset($_POST['editaward']) && $_POST['editaward'] == 2 && $user_info['is_admin']) {
    $award_id = $_POST['award_id'];
    $team_id = $_POST['team_id'];
    $awardType = $_POST['awardType'];
    $awardYear = $_POST['awardYear'];
  db_query("UPDATE `{$db_prefix}jpd_fanawards`
            SET `award_id` = '$award_id', `team_id` = '$team_id', `awardType` = '$awardType',  `awardYear` = '$awardYear'
            WHERE `award_id` =$award_id", __FILE__, __LINE__);
}

//**Add/Edit player form
if ((isset($_GET['addplayer']) || isset($_GET['editplayer'])) && $user_info['is_admin']) {
  if (isset($_GET['addplayer'])) {
    $player_id = "";
    $team_id = "";
    $playerFName = "";
    $playerLName = "";
    $playerPosition = "";
    $playerNationality = "";
    $playerSalary = "";
    $playerGoals = "";
    $playerAssists = "";
    $playerCleanSheets = "";
    $submit = "Add Player";
    $hidden = "addplayer";
  }
  else {
    $player_id = $_GET['player'];
    $query =  db_query(
          "SELECT *
           FROM {$db_prefix}jpd_fanplayers
           WHERE player_id LIKE $player_id", __FILE__, __LINE__);
    $row = mysql_fetch_assoc($query);
    $team_id = $row['team_id'];
    $playerFName = $row['playerFName'];
    $playerLName = $row['playerLName'];
    $playerPosition = $row['playerPosition'];
    $playerNationality = $row['playerNationality'];
    $playerSalary = $row['playerSalary'];
    $playerGoals = $row['playerGoals'];
    $playerAssists = $row['playerAssists'];
    $playerCleanSheets = $row['playerCleanSheets'];
    $submit = "Edit Player";
    $hidden = "editplayer";
  }
  echo '<form action="' . $scripturl . '?page=' . $page . '" method="POST">';
  echo '<center><table>
          <input type="hidden" name="' . $hidden . '" value="2">
          <input type="hidden" name="player_id" value="' . $player_id . '">
          <tr><td align="right">Player Name:</td>
              <td align="left"><input type="text" name="playerFName" value="' . $playerFName . '"> <input type="text" name="playerLName" value="' . $playerLName . '"></td></tr>
          <tr><td align="right">Team:</td>
              <td align="left"><select name="team_id">
              <option value=""> </option>';
    foreach ($teams as $key => $team) {
      echo '<option value="' . $key . '"';
      if ($team_id == $key)
        echo ' SELECTED ';
      echo '>' . $team . '</option>';
    }
    echo '</select>';
           echo '</td></tr>
          <tr><td align="right">Position:</td>
              <td align="left"><select name="playerPosition">';
    foreach ($positions as $position) {
      echo '<option';
      if ($playerPosition == $position)
        echo ' SELECTED ';
      echo '>' . $position . '</option>';
    }
    echo '</select>';
           echo '</td></tr>
          <tr><td align="right">Nationality:</td>
              <td align="left"><select name="playerNationality">';
    asort($countries);
    foreach ($countries as $key => $country) {
      echo '<option value="' . $key . '"';
      if ($playerNationality == $key)
        echo ' SELECTED ';
      echo '>' . $country . '</option>';
    }
    echo '</select>';
           echo '</td></tr>
          <tr><td align="right">Salary:</td>
              <td align="left">$<input type="text" name="playerSalary" value="' . $playerSalary . '"></td></tr>
          <tr><td align="right">Career Number of Goals:</td>
              <td align="left"><input type="text" name="playerGoals" value="' . $playerGoals . '" size="3"></td></tr>
          <tr><td align="right">Career Number of Assists:</td>
              <td align="left"><input type="text" name="playerAssists" value="' . $playerAssists . '" size="3"></td></tr>
          <tr><td align="right">Career Number of Clean Sheets:</td>
              <td align="left"><input type="text" name="playerCleanSheets" value="' . $playerCleanSheets . '" size="3"></td></tr>
          <tr><td colspan="2" align="center"><INPUT type="submit" name="team" value="' . $submit . '"></td></tr>';
  echo '</table></center></form>';
  $printed = 1;
}

// Add player to database
elseif (isset($_POST['addplayer']) && $_POST['addplayer'] == 2 && $user_info['is_admin']) {
  $team_id = $_POST['team_id'];
  $playerName = $_POST['playerName'];
  $playerPosition = $_POST['playerPosition'];
  $playerNationality = $_POST['playerNationality'];
  $playerSalary = $_POST['playerSalary'];
  $playerGoals = $_POST['playerGoals'];
  $playerAssists = $_POST['playerAssists'];
  $playerCleanSheets = $_POST['playerCleanSheets'];
  db_query("INSERT INTO `{$db_prefix}jpd_fanplayers`
          (player_id,team_id,playerFName,playerLName,playerPosition,playerNationality,playerSalary,playerGoals,playerAssists,playerCleanSheets)
           VALUES (NULL, '$team_id', '$playerFName', '$playerLName', '$playerPosition', '$playerNationality', '$playerSalary', '$playerGoals', '$playerAssists', '$playerCleanSheets')", __FILE__, __LINE__);
}

//**Update player in database

elseif (isset($_POST['editplayer']) && $_POST['editplayer'] == 2 && $user_info['is_admin']) {
  $player_id = $_POST['player_id'];
  $team_id = $_POST['team_id'];
  $playerFName = $_POST['playerFName'];
  $playerLName = $_POST['playerLName'];
  $playerPosition = $_POST['playerPosition'];
  $playerNationality = $_POST['playerNationality'];
  $playerSalary = $_POST['playerSalary'];
  $playerGoals = $_POST['playerGoals'];
  $playerAssists = $_POST['playerAssists'];
  $playerCleanSheets = $_POST['playerCleanSheets'];
  db_query("UPDATE `{$db_prefix}jpd_fanplayers`
            SET `player_id` = '$player_id', `team_id` = '$team_id', `playerFName` = '$playerFName',  `playerLName` = '$playerLName',`playerPosition` = '$playerPosition',
                `playerNationality` = '$playerNationality', `playerSalary` = '$playerSalary', `playerGoals` = '$playerGoals',
                `playerAssists` = '$playerAssists', `playerCleanSheets` = '$playerCleanSheets'
            WHERE `player_id` =$player_id", __FILE__, __LINE__);
}

//**Display a team's roster
elseif (isset($_GET['team']) && !isset($_GET['editteam'])) {
  $team = $_GET['team'];
  $awards = array();
  $query =  db_query(
          "SELECT *
           FROM {$db_prefix}jpd_fanteams
           WHERE team_id LIKE '$team'", __FILE__, __LINE__);
  $row = mysql_fetch_assoc($query);
  $teamowner = '<a href="' . $scripturl . '?action=profile;u=' . $row['teamOwnerID'] . '">' . $row['teamOwner'] . '</a>';
  $teamstadium = $row['teamStadium'];
  $query =  db_query(
          "SELECT *
           FROM {$db_prefix}jpd_fanplayers
           WHERE team_id LIKE '$team'
           ORDER BY playerLName", __FILE__, __LINE__);
  while ($row = mysql_fetch_assoc($query)) {
    $roster[$row['playerPosition']][$row['player_id']]['name'] = $row['playerFName'] . ' ' . $row['playerLName'];
    $roster[$row['playerPosition']][$row['player_id']]['nationality'] = '<img src="' . $flag_dir . $row['playerNationality'] . '.png" alt="' . $countries[$row['playerNationality']] . '" />';
    $roster[$row['playerPosition']][$row['player_id']]['salary'] = $row['playerSalary'];
    $roster[$row['playerPosition']][$row['player_id']]['goals'] = $row['playerGoals'];
    $roster[$row['playerPosition']][$row['player_id']]['assists'] = $row['playerAssists'];
    $roster[$row['playerPosition']][$row['player_id']]['cleansheets'] = $row['playerCleanSheets'];
  }
  $query =  db_query(
          "SELECT *
           FROM {$db_prefix}jpd_fanawards
           WHERE team_id LIKE '$team'
           ORDER BY awardYear,awardType", __FILE__, __LINE__);
  while ($row = mysql_fetch_assoc($query))
    $awards[] = '<tr><td>' . $row['awardYear'] . '</td><td align="left">' . $row['awardType'] . '</td></tr>';
  echo '<table width="100%">
          <tr><td colspan="6" align="center" class="catbg" style="font-size: 120%;">' . $teams[$team];
  echo '<table><tr><td width="17%" align="right">Owner:</td><td width="16%" align="left">'. $teamowner . '</td><td width="34%">';
  echo '<table>';
  foreach ($awards as $award)
    echo $award;
  echo '</table>';
  echo '</td><td width="17%" align="right">Stadium:</td><td width="16%" align="left">'. $teamstadium . '</td></tr></table>';
  echo '</td></tr>';
  foreach ($positions as $position) {
    echo '<tr><td colspan="6" align="left" class="titlebg">' . $position . '</td></tr>';
    echo '<tr class="windowbg"><td align="center">Name</td>
              <td align="center">Nationality</td>
              <td align="center">Salary</td>
              <td align="center">Career Goals</td>
              <td align="center">Career Assists</td>
              <td align="center">Career Clean Sheets</td></tr>';
    if (isset($roster[$position])) {
      foreach ($roster[$position] as $player) {
        echo '<tr class="windowbg2">';
        echo '<td align="center">' . $player['name'] . '</td>';
        echo '<td align="center">' . $player['nationality'] . '</td>';
        echo '<td align="center">$' . $player['salary'] . '</td>';
        echo '<td align="center">' . $player['goals'] . '</td>';
        echo '<td align="center">' . $player['assists'] . '</td>';
        echo '<td align="center">' . $player['cleansheets'] . '</td>';
        echo '</tr>';
      }
    }
  }
  echo '<tr><td colspan="6" align="center" class="catbg">&nb' . 'sp;</td></tr>';
  echo '</table>';
  $printed = 1;
}

if ($printed == 1) { echo '<hr />'; }

echo '<form action="' . $scripturl . '" method="GET">';
echo '<center><table>
        <input type="hidden" name="page" value="' . $page . '">
        <tr><td align="right">Which team' . "'" . 's roster<br />do you want to see?</td>
            <td align="left"><select name="team">
            <option value=""> </option>';
  foreach ($teams as $key => $team)
    echo '<option value="' . $key . '">' . $team . '</option>';
  echo '</select>';
         echo '</td></tr>
        <tr><td colspan="2" align="center"><INPUT type="submit" name="go" value="Show Me"></td></tr>';
echo '</table></center></form>';


if ($user_info['is_admin']) {
  echo '<table>';

// Add or edit team
  echo '<form action="' . $scripturl . '" method="GET">
          <input type="hidden" name="page" value="' . $page . '">
          <tr><td align="right">Choose team to edit</td>
              <td align="left"><select name="team">
              <option value=""> </option>';
    foreach ($teams as $key => $team)
      echo '<option value="' . $key . '">' . $team . '</option>';
    echo '</select>';
           echo ' <INPUT type="submit" name="editteam" value="Edit"></td>
            <td><INPUT type="submit" name="addteam" value="Add new team"></td></tr>';
  echo '</form>';

//Add or edit player
  echo '<form action="' . $scripturl . '" method="GET">';
  echo '<input type="hidden" name="page" value="' . $page . '">
          <tr><td align="right">Choose player to edit</td>
              <td align="left"><select name="player">
              <option value=""> </option>';
    $query =  db_query(
          "SELECT *
           FROM {$db_prefix}jpd_fanplayers
           ORDER BY playerLName", __FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($query))
      echo '<option value="' . $row['player_id'] . '">' . $row['playerFName'] . ' ' . $row['playerLName'] . '</option>';
    echo '</select>';
           echo ' <INPUT type="submit" name="editplayer" value="Edit"></td>
           <td><INPUT type="submit" name="addplayer" value="Add new player"></td></tr>';
  echo '</form>';

//Add or edit award
  echo '<form action="' . $scripturl . '" method="GET">';
  echo '<input type="hidden" name="page" value="' . $page . '">
          <tr><td align="right">Choose award to edit</td>
              <td align="left"><select name="award">
              <option value=""> </option>';
    $query =  db_query(
          "SELECT *
           FROM {$db_prefix}jpd_fanawards
           ORDER BY awardYear,awardType", __FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($query))
      echo '<option value="' . $row['award_id'] . '">' . $row['awardYear'] . ' ' . $row['awardType'] . '</option>';
    echo '</select>';
           echo ' <INPUT type="submit" name="editaward" value="Edit"></td>
           <td><INPUT type="submit" name="addaward" value="Add new award"></td></tr>';
  echo '</form>';

  echo '</table>';
}


It needs to go into a php article -- not a block. Notice the information about the flag images right at the beginning of the code.

tarmer

Ok.. I pated it into a php article....  How does it get used ?.... Thanks Again

JPDeni

Take note of the page number for the article. Let's say it's page 8. Then go to

http://www.yourdomain.com/index.php?page=8

You'll see a dropdown list at the beginning, which won't have anything in it. Below that, since you're the admin, you'll see several forms for adding and editing teams, players and awards. Start by adding a team or several teams. Then add players. Add any awards that the teams have won.

It's really easiest just to take a look at it and do what seems logical. :)

This website is proudly hosted on Crocweb Cloud Website Hosting.