Skip to content

Commit

Permalink
print team
Browse files Browse the repository at this point in the history
  • Loading branch information
tlentz committed Nov 30, 2016
1 parent 6501f7f commit d75d3e3
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 41 deletions.
87 changes: 78 additions & 9 deletions createTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,81 @@
$week = $_GET['week'];
}
?>

<?php
if($_SERVER['REQUEST_METHOD'] == "POST") {
$errors = array();

$QB = $_POST['QB'];
if($QB == '') {
$errors['QB'] = "QB is empty.";
}

$RB1 = $_POST['RB1'];
if($RB1 == '') {
$errors['RB1'] = "RB is empty.";
}

$RB2 = $_POST['RB2'];
if($RB2 == '') {
$errors['RB2'] = "RB is empty.";
}

$WR1 = $_POST['WR1'];
if($WR1 == '') {
$errors['WR1'] = "WR is empty.";
}

$WR2 = $_POST['WR2'];
if($WR2 == '') {
$errors['WR2'] = "WR is empty.";
}

$TE = $_POST['TE'];
if($TE == '') {
$errors['TE'] = "TE is empty.";
}

$FLEX = $_POST['FLEX'];
if($FLEX == '') {
$errors['FLEX'] = "FLEX is empty.";
}

$DF = $_POST['DF'];
if($DF == '') {
$errors['DF'] = "DF is empty.";
}

$PK = $_POST['PK'];
if($PK == '') {
$errors['PK'] = "PK is empty.";
}

if(empty($errors)) {
$userID = $_SESSION['user']['id'];
$weekID = $week;
if(hasTeam($userID,$weekID)) {
echo "<div class='alert alert-danger'><strong>Error!</strong> You already have a team for this week. You can edit your current team or delete your current team before creating a new one.</div>";
} else {
$query = "INSERT INTO FantasyTeam (userID,weekID,QB,RB1,RB2,WR1,WR2,TE,FLEX,DF,PK) VALUES ($userID,$weekID,$QB,$RB1,$RB2,$WR1,$WR2,$TE,$FLEX,$DF,$PK)";
$mysqli->query($query);
}
}
} else {
$errors = array();
}
?>

<?php if($season == "" || $week == "") { ?>
<div class="alert alert-danger">
<strong>Error!</strong> Season and Week are not set.
</div>
<?php } else {
printCreatingTeamHeader($season,$week); ?>
<div class="alert alert-danger"><strong>Error!</strong> Season and Week are not set.</div>
<?php } else if (hasTeam($_SESSION['user']['id'],$week)) {
echo "<div class='alert alert-danger'><strong>Error!</strong> You already have a team for this week. You can edit your current team or delete your current team before creating a new one.</div>";
} else {
printCreatingTeamHeader($season,$week);
foreach($errors as $e) {
echo "<div class='alert alert-danger'><strong>Error!</strong> $e</div>";
}
?>
<form method="POST">
<?php //printPlayers("QB",isset($_POST['QB']) ? $_POST['QB'] : "",$week); ?>
<table class='table table-striped'>
Expand All @@ -31,10 +100,10 @@
<tr><td>RB</td><td><select class='form-control' name="RB2"><?php printPlayers("RB",isset($_POST['RB2']) ? $_POST['RB2'] : "",$week); ?></select></td></tr>
<tr><td>WR</td><td><select class='form-control' name="WR1"><?php printPlayers("WR",isset($_POST['WR1']) ? $_POST['WR1'] : "",$week); ?></select></td></tr>
<tr><td>WR</td><td><select class='form-control' name="WR2"><?php printPlayers("WR",isset($_POST['WR2']) ? $_POST['WR2'] : "",$week); ?></select></td></tr>
<tr><td>RB</td><td><select class='form-control' name="TE"><?php printPlayers("TE",isset($_POST['TE']) ? $_POST['TE'] : "",$week); ?></select></td></tr>
<tr><td>RB</td><td><select class='form-control' name="FLEX"><?php printPlayers("FLEX",isset($_POST['FLEX']) ? $_POST['FLEX'] : "",$week); ?></select></td></tr>
<tr><td>WR</td><td><select class='form-control' name="DF"><?php printPlayers("DF",isset($_POST['DF']) ? $_POST['DF'] : "",$week); ?></select></td></tr>
<tr><td>WR</td><td><select class='form-control' name="WR2"><?php printPlayers("PK",isset($_POST['PK']) ? $_POST['PK'] : "",$week); ?></select></td></tr>
<tr><td>TE</td><td><select class='form-control' name="TE"><?php printPlayers("TE",isset($_POST['TE']) ? $_POST['TE'] : "",$week); ?></select></td></tr>
<tr><td>FLEX</td><td><select class='form-control' name="FLEX"><?php printPlayers("FLEX",isset($_POST['FLEX']) ? $_POST['FLEX'] : "",$week); ?></select></td></tr>
<tr><td>DF</td><td><select class='form-control' name="DF"><?php printPlayers("DF",isset($_POST['DF']) ? $_POST['DF'] : "",$week); ?></select></td></tr>
<tr><td>PK</td><td><select class='form-control' name="PK"><?php printPlayers("PK",isset($_POST['PK']) ? $_POST['PK'] : "",$week); ?></select></td></tr>
</tbody>
</table>
<input class="btn btn-primary" type="submit" value="Create Team">
Expand Down
40 changes: 36 additions & 4 deletions includes/common_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ function printPlayers($pos,$player,$week) {
$query .= " AND (b.positionID = 2 OR b.positionID = 3 OR b.positionID = 4)";
break;
case "DF":
$query .= " AND b.positionID = 5";
$query .= " AND b.positionID = 6";
break;
case "PK":
$query .= " AND b.positionID = 6";
$query .= " AND b.positionID = 5";
break;
default:
$query = "";
Expand All @@ -88,8 +88,6 @@ function printPlayers($pos,$player,$week) {
$query .= " ORDER BY c.abbr ASC";
global $mysqli;
$players = r2a($mysqli->query($query));
//echo $query; die;
//pprint($players); die;
foreach($players as $p) {
if($player == $p['playerID']) {
echo "<option value='".$p['playerID']."' selected='selected'>".$p['abbr']." - ".$p['name']."</option>";
Expand Down Expand Up @@ -127,4 +125,38 @@ function getWeekNum($week) {
function pprint($arr) {
echo "<pre>"; print_r($arr); echo "</pre>";
}

function hasTeam($userID,$weekID) {
global $mysqli;
$query = "SELECT * FROM FantasyTeam
WHERE userID = $userID AND weekID = $weekID";
$result = $mysqli->query($query);
if($result->num_rows > 0) {
return true;
}
return false;
}

function getTeam($userID,$weekID) {
global $mysqli;
$query = "SELECT * FROM FantasyTeam
WHERE userID = $userID AND weekID = $weekID";
$teams = r2a($mysqli->query($query));

$playerIds = $teams[0];
$pos = array("QB","RB1","RB2","WR1","WR2","TE","FLEX","DF","PK");
$team = array();
foreach($pos as $p) {
$query = "SELECT a.*,b.name,b.positionID,c.abbr
FROM PlayerStat a
JOIN Player b
ON a.playerID = b.playerID
JOIN Team c
ON b.teamID = c.teamID
WHERE a.playerID = $playerIds[$p]
AND weekID = $weekID";
$team[$p] = r2a($mysqli->query($query))[0];
}
return $team;
}
?>
9 changes: 9 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ a:hover{
color: white;
font-size: 20px;
}

.stats {
font-size: 12px !important;
margin: 0 !important;
}

.pos {
font-size: 30px;
}
75 changes: 47 additions & 28 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
if(isset($_GET['week'])) {
$week = $_GET['week'];
}
$teams = array();
if($season != "" && $week == "") {
//$teams = getTeams($season,$week);
if($season != "" && $week != "") {
if(hasTeam($_SESSION['user']['id'],$week)) {
$team = getTeam($_SESSION['user']['id'],$week);
}
}
?>
<form method='GET'>
Expand All @@ -52,36 +53,54 @@
</div>
</div>

<div class="page-header text-center">
<h1>Your Team</h1>
</div>
<?php if(count($teams) > 1) { ?>
<div class="alert alert-warning">
No team this week.
</div>
<?php } else { ?>
<table class='table table-striped'>
<thead>
<th>Position</th>
<th>Player</th>
</thead>
<tbody>
<tr><td>QB</td><td>QB Name</td></tr>
<tr><td>RB</td><td>RB Name</td></tr>
<tr><td>RB</td><td>RB Name</td></tr>
<tr><td>WR</td><td>WR Name</td></tr>
<tr><td>WR</td><td>WR Name</td></tr>
<tr><td>TE</td><td>TE Name</td></tr>
<tr><td>FLEX</td><td>FLEX Name</td></tr>
<tr><td>DF</td><td>DF Name</td></tr>
<tr><td>PK</td><td>PK Name</td></tr>
</tbody>
</table>
<?php if($season != "" && $week != "") { ?>
<div class="page-header text-center">
<h1>Your Team</h1>
</div>
<?php if(!isset($team)) { ?>
<div class="alert alert-warning">
No team this week.
</div>
<?php } else { pprint($team) ?>
<table class='table table-striped'>
<thead>
<th>Position</th>
<th>Player</th>
<th>Points</th>
</thead>
<tbody>
<?php $pos = array("QB","RB1","RB2","WR1","WR2","TE","FLEX","DF","PK");
foreach($pos as $p) {
printPlayer($p, $team[$p]);
} ?>
</tbody>
</table>
<?php } ?>
<?php } ?>
</form>

<?php
include('includes/footer.php');

function printPlayer($pos,$player) {
echo "<tr><td class='pos'>$pos</td>";
echo "<td>".$player['name']." - ".$player['abbr'];
echo "<p class='stats'>";

if($pos == "QB") {
echo $player['passComp']."/".$player['passAtt']."\t".$player['passYds']."yds"."\t".$player['passTds']."TD"."\t".$player['interceptions']."INT";
} else if ($pos == "RB1" || $pos == "RB2" || ($pos == "FLEX" && $player['positionID'] == 2)) {
echo $player['rushYds']."yds"."\t".$player['rushTds']."TD"."\t".$player['fumbles']."FUM";
} else if ($pos == "WR1" || $pos == "WR2" || $pos == "TE" || ($pos == "FLEX" && ($player['positionID'] == 3 || $player['positionID'] == 4))) {
echo $player['recYds']."yds"."\t".$player['recTds']."TD"."\t".$player['fumbles']."FUM";
} else if ($pos == "DF") {
echo $player['defTYA']."YA"."\t".$player['defInt']."INT"."\t".$player['defFR']."FR"."\t".$player['defTds']."TD";
} else if($pos == "PK") {
echo ($player['fgAtt']-$player['fgMiss'])."/".$player['fgAtt']." FG\t".($player['xpAtt']-$player['xpMiss'])."/".$player['xpAtt']." XP";
}
echo "</p>";
echo "</td><td></td>";
}
?>

<script>
Expand Down

0 comments on commit d75d3e3

Please sign in to comment.