<?php
session_start();
require_once('mysqli_connect.php');

// ---- Safety stuff: must be logged in + admin ----
if (!isset($_SESSION['user_id'])) {
  header("Location: login.php");
  exit();
}
if (($_SESSION['role'] ?? '') !== 'admin' && ($_SESSION['role'] ?? '') !== 'super_admin') {
  die("Access denied. Coaches/admins only.");
}

$coach_id = (int)$_SESSION['user_id'];
$role = $_SESSION['role'] ?? '';

$errors = [];
$team = null;
$roster = [];
$team_id = isset($_GET['team_id']) ? (int)$_GET['team_id'] : 0;

function h($s){ return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }

// ---- Get team info ----
// super_admin can open any team
if ($team_id <= 0) {
  $errors[] = "No team selected.";
} else {
  if ($role === 'super_admin') {
    $q = "SELECT team_id, team_name, sport, season, notes, is_active
          FROM teams
          WHERE team_id = $team_id
          LIMIT 1";
  }
  
// else Anthony
    else {
        $q = "SELECT team_id, team_name, sport, season, notes, is_active
          FROM teams
          WHERE team_id = $team_id
          LIMIT 1";
    }

  $r = mysqli_query($dbc, $q);

  if ($r && mysqli_num_rows($r) === 1) {
    $team = mysqli_fetch_assoc($r);
  } else {
    $errors[] = "Team not found or you do not have access.";
  }
}

// ---- Pull roster ---- Anthony
if ($team) {
  $q = "SELECT
          u.user_id,
          u.first_name,
          u.last_name,
          u.photo,
          rp.jersey_num,
          rp.position
        FROM rostered_players rp
        JOIN users u ON u.user_id = rp.user_id
        WHERE rp.team_id = $team_id
        ORDER BY rp.jersey_num IS NULL, rp.jersey_num, u.last_name, u.first_name";
  $r = mysqli_query($dbc, $q);

  if ($r) {
    while ($row = mysqli_fetch_assoc($r)) {
      $roster[] = $row;
    }
  }
}


?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Team Roster View • Sideline</title>
  <link rel="icon" type="image/x-icon" href="images/sideline_logo.ico">
   <style>
:root {
  --bg: #f6f7fb;
  --card: #fff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e5e7eb;
  --dark: #111827;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #f59e0b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, Segoe UI, Arial, sans-serif;
  background: var(--bg);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(to right, #251F47, #111827, #2B784A);
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand { font-weight: 800; letter-spacing: .3px; }

.nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.nav a {
  background: #FFFFFF;
  color: #251F47;
  border: 1px solid rgba(255,255,255,.18);
  padding: 8px 10px;
  border-radius: 12px;
  cursor: pointer;
  opacity: .95;
}

.nav a.active { border-color: #fff; opacity: 1; }

.container {
  max-width: 1100px;
  margin: 22px auto;
  padding: 0 16px;
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(auto, 1fr);
}

.grid2 {
    display:grid;
    gap: 14px;
    grid-template-columns:(1, 1fr);
    grid-template-rows:375px 375px;
}

.col-6 { grid-column-start: 1; grid-column-end: 2; grid-row-start: 2; }
.col-right-pop { grid-column-start: 1; grid-column-end: 2; grid-row-start: 2; align-self:start; }
.col-right { grid-column-start: 1; grid-column-end: 2: grid-row-start: 1; grid-row-end: 2; align-self:start;}
.col-12 {grid-column-start: 1; grid-column-end: 3; grid-row-start: 1; grid-row-end: 2; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(2,6,23,.05);
}

h1, h2, h3 { margin: 0 0 10px; color: var(--text); }

p { margin: 8px 0; color: var(--muted); }

.titleRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.stack { display: flex; flex-direction: column; gap: 10px; }

.btn {
  background: var(--dark);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  display: inline-block;
}

.btn.secondary {
  background: #251F47;
  color: #fff;
  border: 1px solid var(--line);
  float:right;
}

.btn.tertiary {
  background: #ffffff;
  color: #251F47;
  border: 1px solid #251F47;
}

.split { display: flex; gap: 10px; flex-wrap: wrap; }

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: .95rem;
  vertical-align: top;
}

th { color: #334155; font-weight: 700; }

.notice {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px dashed var(--line);
  background: #fab4b7;
  color: #334155;

}

.success {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid #bbf7d0;
  background: #ecfdf5;
  color: #166534;
  margin-top: 10px;

}

.bottomLayout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  grid-column: span 12;
  align-items: start;
}

.rightColumn { display: flex; flex-direction: column; gap: 14px; }

.welcomeBox {
      background: linear-gradient(to right, #FFFFFF, #C5E8B7, #2B784A);
      color: #111827;
      padding: 18px 20px;
      border-radius: 14px;
      margin-bottom: 10px;
}

img{
    border:solid 3px #251F47;
    border-radius:10px;
    height:150px;
    width:130px;
    float:right;
    margin-right:20px;
}

input, select {
    width: 80%;
    padding: 6px;
    border: 2px solid var(--line);
    border-radius: 12px;
    margin-bottom: 10px;
}

.user_info{
    font-weight:bold;
    margin-left: 20px;
    padding-bottom: 20px;
    
}

hr{
    border:solid 1.5px #251F47;
}

  </style>
</head>
<body>


<!--topbar-->
<header class="topbar">
  <div class="brand"><a href="coach_dashboard.php">Sideline <span style="opacity:.8;font-weight:600">Team Roster View</span></a></div>
  <div class="nav">
    <a href="logout.php">Logout</a>
  </div>
</header>

<main class="container">
<section class="grid">

<!--green gradient welcome-->
<div class="col-12">
<div class="welcomeBox" style="display:flex; align-items:center; gap:15px;">
    <h2>Team Roster View</h2>
</div>
</div>
        
<div class = "card col-6">
    <h3>Get To Know The Team!</h3>
    <br>
        
    <!--pull full team roster based on team_id from rostered_players and coaches-->
    <form  action = "team_roster.php?team_id=<?= (int)$team_id?>" method = "POST">
    
    <?php $q = "SELECT
        u.user_id,
        u.first_name,
        u.last_name,
        u.photo,
        rp.jersey_num,
        rp.position
        FROM rostered_players rp
        JOIN users u ON u.user_id = rp.user_id
        WHERE rp.team_id = $team_id
        ORDER BY rp.jersey_num IS NULL, rp.jersey_num, u.last_name, u.first_name";
        
        $r = mysqli_query($dbc, $q);

        /*display all players in rostered_players with the specified team_id
        and provide each an edit/view/delete button for coach use*/
        while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){
            echo"<img src = \"images/".$row['photo']."\" height = 100px width = 100px>".
            "<br><br><div class = \"user_info\"><p>Name: ".$row['first_name']." ".$row['last_name']."</p> <p> Number: ".$row['jersey_num']."</p> <p>Position:  ".$row['position']."</p></div><br>";
        
            echo "<div class = \"split\">";
            echo "<button class = \"btn secondary\" type=\"submit\" name=\"id\" value=\"".$row['user_id']."\">View Profile</button>";
            echo "<button class = \"btn secondary\" type=\"submit\" name=\"update_info\" value=\"".$row['user_id']."\">Edit</button>";
            echo "<button class = \"btn tertiary\" type=\"submit\" name=\"del_id\" value=\"".$row['user_id']."\">Remove Player</button>";
            echo "</div>";
            echo "<hr><br><br>";
        }
        
        /*display all coaches in rostered_coaches with the specified team_id*/      
        $q2 = "SELECT
        u.user_id,
        u.first_name,
        u.last_name,
        u.photo,
        rc.position
        FROM rostered_coaches rc
        JOIN users u ON u.user_id = rc.user_id
        WHERE rc.team_id = $team_id
        ORDER BY u.last_name, u.first_name";
        
    $r2 = mysqli_query($dbc, $q2);

    while($row2 = mysqli_fetch_array($r2, MYSQLI_ASSOC)){
         echo"<img src = \"images/".$row2['photo']."\" height = 100px width = 100px>".
            "<br><br><div class = \"user_info\"><p>Name: ".$row2['first_name']." ".$row2['last_name']."</p> <p>Position:  ".$row2['position']."</p></div><br>";
        
        
        echo "<div class = \"split\">";
        echo "<button class = \"btn secondary\" type=\"submit\" name=\"id\" value=\"".$row2['user_id']."\">View Profile</button>";
        echo "</div>";
        echo "<hr><br><br>";
    }
    ?>
    </form>
</div>






<!--REMOVE PLAYER FROM TEAM-->
<!--make sure that the player id is set to romove player from the team-->
<?php
if (isset($_POST['del_id'])){
    $del_id = (int)$_POST['del_id'];

    $q2 = "SELECT * FROM rostered_players
           WHERE team_id = $team_id AND user_id = $del_id";
          
    $r2 = mysqli_query($dbc, $q2);
    

    if ($r2 && mysqli_num_rows($r2) > 0) {
        
        /*remove player information from rostered_players*/
        $q3 = "DELETE FROM rostered_players
        WHERE team_id = $team_id AND user_id = $del_id";
          
        $r3 = mysqli_query($dbc, $q3);
        echo"<div class = \"success\"><p>Player has been removed from the team.</p><br>";
        echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
        
    } 
        
    /*if player id is not set*/
    else {
    echo "<div class = \"notice\"><p>User not found on this team.</p><br>";
    echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
    }
}
?>


<section class="grid2">
    
    <!--VIEW PROFILE-->
<!--make sure that the player id is set to view profile information-->
<?php
if (isset($_POST['id'])){
    $id = (int)$_POST['id'];
    
    $q = "SELECT * FROM users
          WHERE user_id = $id";
          
    $r = mysqli_query($dbc, $q);
    
    
    if ($r && mysqli_num_rows($r) > 0) {
        $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
        
    /*display profile information*/
    echo "<div class = \"card col-right-pop\">
    <img src = \"images/".$row['photo']."\" height = 100px width = 100px><div class = \"user_info\">".
         $row['first_name']." ".
         $row['last_name']."</div>
         <br>
         <div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">Cancel</a></div>
         </div>";
    } 
    
    /*if player id is not set*/
    else {
    echo "<p><div class = \"notice\">No user found.</p><br>";
    echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
    }
}
?>



<!--UPDATE PLAYER INFO ON TEAM FORM-->
<!--make sure that the player id is set to uptade their info-->
<?php
if (isset($_POST['update_info'])){
    $user_upd = (int)$_POST['update_info'];

    $q2 = "SELECT * FROM rostered_players
          WHERE team_id = $team_id AND user_id = $user_upd";
          
        
    $r2 = mysqli_query($dbc, $q2);
    
    
    if ($r2 && mysqli_num_rows($r2) > 0) {
    
        /*get player info from users to display the first and plast name of the player being edited*/
        $q3 = "SELECT * FROM users
        WHERE user_id = $user_upd";
            
        $r3 = mysqli_query($dbc, $q3);
    
        $row3 = mysqli_fetch_array($r3, MYSQLI_ASSOC);


        /*get player info from rostered players to prefill the inputs for the new update form*/
        $q4 = "SELECT * FROM rostered_players
        WHERE user_id = $user_upd AND team_id = $team_id";
            
        $r4 = mysqli_query($dbc, $q4);
    
        $row4 = mysqli_fetch_array($r4, MYSQLI_ASSOC);

        /*create the update form when edit player button is selected*/
        echo"<div class = \"card col-right-pop\">
        <h2>Update ".$row3['first_name']." ".$row3['last_name']."'s Information</h2>
      
        <form action = \"team_roster.php?team_id=$team_id\" method = \"POST\">
            
        <!--set the player's jersey number-->
        <label>Player Jersey Number<span style=\"color:#991b1b\">*</span></label>
        <input name=\"j_num\" placeholder=\"12\" value = \"$row4[jersey_num]\" required>
        <br>
        <br>
        
        <!--set the player's position-->
        <label>Position<span style=\"color:#991b1b\">*</span></label>
        <br>
        <select name=\"position\" required>
        <option value=\"$row4[position]\">$row4[position]</option>";
        
            
            $q = "SELECT sport 
            FROM teams 
            WHERE team_id = '$team_id'";
            
            $r = mysqli_query($dbc, $q);
            $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
            
            /*dynamic dropdown to mirror team_id sport positions*/
            if($row['sport']== "Baseball"){
            echo"<option value=\"left field\">left field</option>";
            echo"<option value=\"center field\">center field</option>";
            echo"<option value=\"right field\">right field</option>";
            echo"<option value=\"shortstop\">shortstop</option>";
            echo"<option value=\"second base\">second base</option>";
            echo"<option value=\"third base\">third base</option>";
            echo"<option value=\"first base\">first base</option>";
            echo"<option value=\"catcher\">catcher</option>";
            echo"<option value=\"pitcher\">pitcher</option>";
            }
            
            elseif($row['sport']== "Football"){
            echo"<option value=\"quarterback\">quarterback</option>";
            echo"<option value=\"left tackle\">left tackle</option>";
            echo"<option value=\"left guard\">left guard</option>";
            echo"<option value=\"center\">center</option>";
            echo"<option value=\"right tackle\">right tackle</option>";
            echo"<option value=\"right guard\">right guard</option>";
            echo"<option value=\"half back\">half back</option>";
            echo"<option value=\"full back\">full back</option>";
            echo"<option value=\"tight end\">tight end</option>";
            echo"<option value=\"wide reciever\">wide reciever</option>";
            echo"<option value=\"nose tackle\">nose tackle</option>";
            echo"<option value=\"defensive tackle\">defensive tackle</option>";
            echo"<option value=\"defensive end\">defensive end</option>";
            echo"<option value=\"middle linebacker\">middle linebacker</option>";
            echo"<option value=\"outside linebacker\">outside linebacker</option>";
            echo"<option value=\"cornerback\">cornerback</option>";
            echo"<option value=\"safety\">safety</option>";
            echo"<option value=\"kicker\">kicker</option>";
            echo"<option value=\"longsnapper\">longsnapper</option>";
            }
            
            elseif($row['sport']== "Soccer"){
            echo"<option value=\"goalkeeper\">goalkeeper</option>";
            echo"<option value=\"wing back\">wing back</option>";
            echo"<option value=\"full back\">full back</option>";
            echo"<option value=\"sweeper\">sweeper</option>";
            echo"<option value=\"center back\">center back</option>";
            echo"<option value=\"winger\">winger</option>";
            echo"<option value=\"defensive midfielder\">defensive midfielder</option>";
            echo"<option value=\"center midfielder\">center midfielder</option>";
            echo"<option value=\"attacking midfielder\">attacking midfielder</option>";
            echo"<option value=\"striker\">striker</option>";
            echo"<option value=\"forward\">forward</option>";
            }
            
            elseif($row['sport']== "Basketball"){
            echo"<option value=\"point guard\">point guard</option>";
            echo"<option value=\"shooting guard\">shooting guard</option>";
            echo"<option value=\"small forward\">small forward</option>";
            echo"<option value=\"power forward\">power forward</option>";
            echo"<option value=\"center\">center</option>";
            }
            
          echo"</select>
          <br>
          <br>
          
        <!--submit buttons-->  
        <div class = \"split\">
          <button class = \"btn secondary\" type=\"submit\" name=\"push_upd\" value=\"$user_upd\">Update</button>
          <div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">Cancel</a></div>
        </div>
     
      </form>
</div>";

    } else {
    echo "<p><div class = \"notice\">No user found.</p><br>";
    echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
    }
}
?>

<!--UPDATE PLAYER INFO ON TEAM ACTION-->
<!--make sure that the player id is set to uptade their info-->
<?php
if (isset($_POST['push_upd'])){
    $push_upd = (int)$_POST['push_upd'];
    $j_num = $_POST['j_num'];
    $position = $_POST['position'];

    $q2 = "SELECT * FROM rostered_players
          WHERE team_id = $team_id AND user_id = $push_upd";
          
    $r2 = mysqli_query($dbc, $q2);
    
    
    if ($r2 && mysqli_num_rows($r2) > 0) {
        
        /*get the number of users from rostered_players that have the same jersey number
        and are on the same team as the player whose info is attempting to be changed*/
        $q4 = "SELECT jersey_num FROM rostered_players
        WHERE team_id = $team_id AND jersey_num = $j_num";
            
        $r4 = mysqli_query($dbc, $q4);
        $rowj_check = mysqli_fetch_array($r4, MYSQLI_ASSOC);
        $rowjCount = mysqli_num_rows($r4);
            
        /*get the jersey number of the player whose info is being updated*/
        $q5 = "SELECT jersey_num FROM rostered_players
        WHERE team_id = $team_id AND user_id = $push_upd";
            
        $r5 = mysqli_query($dbc, $q5);
        $row5 = mysqli_fetch_array($r5, MYSQLI_ASSOC);
        
        /*update can go through if the jersey number remains the same or there are no matching 
        jersey numbers on the team already*/
        if (($rowjCount == 0) || ($row5['jersey_num'] == $j_num)){

            /*update rostered_player information*/ 
            $q3 = "UPDATE rostered_players
            SET jersey_num = $j_num, position = '$position'
            WHERE user_id = $push_upd AND team_id = $team_id";
    
            $r3 = mysqli_query($dbc, $q3);
            
             echo "<div class = \"success\"><p>Player information has been updated.</p><br>";
            echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
            
        }
        
        else{
            
             echo "<div class = \"notice\"><p>A player on the team already has this jersey number. Please select a new one to use.</p><br>";
            echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
        }
        
    } 
    
    else {
    echo "<div class = \"notice\"><p>No user found.</p><br>";
    echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
    }
}
?>

<!--ADD PLAYER TO TEAM-->
<!--make sure that the team id is set-->
<?php
if (isset($_POST['add_player'])){
    $team_id = (int)$_POST['add_player'];
    
    /*add new players/coaches to a team by unique email*/
    $email =    $_POST['email'];
    $j_num =    $_POST['j_num'];
    $position = $_POST['position'];
    
    
    /*check if there is already a player with the jersey attempting to be added*/
    $q4 = "SELECT jersey_num FROM rostered_players
    WHERE team_id = $team_id AND jersey_num = $j_num";
            
    $r4 = mysqli_query($dbc, $q4);
    $rowjCount = mysqli_num_rows($r4);
            
        /*proceed if there are none of the same jersey numbers already*/    
        if($rowjCount == 0){

        /*return user with matching email to add their user_id to rostered_players*/
        $q = "SELECT * FROM users
        WHERE email = '$email';";
        
        $r = mysqli_query($dbc, $q);
        $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
    
        $rowCount = mysqli_num_rows($r);
    
            /*make sure that the email is a signed-up user and NOT already a player on the team*/
            if($rowCount == 1){
            $user_id = $row['user_id'];
            
                $q5 = "SELECT * FROM rostered_players
                        WHERE user_id = $user_id AND team_id = $team_id";
                        
                $r5 =  mysqli_query($dbc, $q5);
                
                $rowCount2 = mysqli_num_rows($r5);
                
                    if($rowCount2 ==  0){
                        
    
                /*insert matching player into rostered players along with other required fields*/
                $q2 = "INSERT INTO rostered_players (jersey_num, position, user_id, team_id)
                VALUES ($j_num, '$position', $user_id, $team_id)";
                
                $r2 = mysqli_query($dbc, $q2);
                
                echo"<div class = \"success\">";
                echo "<p>".$row['first_name']." ".$row['last_name']." has been added to the team!</p><br>";
                echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
                
            }
            
                else{
                    echo"<div class = \"notice\">";
                     echo"That player is already on the team. Please try another email.</p><br>";
                         echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
                }
            }
                
            else{
                echo"<div class = \"notice\">";
                echo"<p>That player email does not exist. Please try another email.</p><br>"; 
                echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
            }
        }
        else{
            echo"<div class = \"notice\">";
                echo"<p>A player on the team already has this jersey number. Please try another number.</p><br>";
                echo"<div class = \"btn tertiary\"><a href=\"team_roster.php?team_id=$team_id\">OK</a></div></div>";
            }
}
?>


    <!--create a form so coaches may add players to their team through emails(unique)-->
    <div class = "card col-right">
      <h2>Add a Player To the Team</h2>
      
        <form action = "team_roster.php?team_id=<?= (int)$team_id?>" method = "POST">
            
        <!--set the player's email-->
        <label>Player Email<span style="color:#991b1b">*</span></label>
        <br>
        <input name="email" placeholder="example@gmail.com" required>
        <br>
        <br>
        
        <!--set the player's jersey number-->
        <label>Player Jersey Number<span style="color:#991b1b">*</span></label>
        <input name="j_num" placeholder="12" required>
        <br>
        <br>
        
        <!--set the player's position with select input-->
        <label>Position<span style="color:#991b1b">*</span></label>
        <br>
        <select name="position" required>
        <option value="">-- Select a position --</option>
        
            <?php 
            $team_id = isset($_GET['team_id']) ? (int)$_GET['team_id'] : 0;
            
            
            $q = "SELECT sport 
            FROM teams 
            WHERE team_id = '$team_id'";
            
            $r = mysqli_query($dbc, $q);
            $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
            
            /*dynamic dropdown to mirror team_id sport positions*/
            if($row['sport']== "Baseball"){
            echo"<option value=\"left field\">left field</option>";
            echo"<option value=\"center field\">center field</option>";
            echo"<option value=\"right field\">right field</option>";
            echo"<option value=\"shortstop\">shortstop</option>";
            echo"<option value=\"second base\">second base</option>";
            echo"<option value=\"third base\">third base</option>";
            echo"<option value=\"first base\">first base</option>";
            echo"<option value=\"catcher\">catcher</option>";
            echo"<option value=\"pitcher\">pitcher</option>";
            }
            
            elseif($row['sport']== "Football"){
            echo"<option value=\"quarterback\">quarterback</option>";
            echo"<option value=\"left tackle\">left tackle</option>";
            echo"<option value=\"left guard\">left guard</option>";
            echo"<option value=\"center\">center</option>";
            echo"<option value=\"right tackle\">right tackle</option>";
            echo"<option value=\"right guard\">right guard</option>";
            echo"<option value=\"half back\">half back</option>";
            echo"<option value=\"full back\">full back</option>";
            echo"<option value=\"tight end\">tight end</option>";
            echo"<option value=\"wide reciever\">wide reciever</option>";
            echo"<option value=\"nose tackle\">nose tackle</option>";
            echo"<option value=\"defensive tackle\">defensive tackle</option>";
            echo"<option value=\"defensive end\">defensive end</option>";
            echo"<option value=\"middle linebacker\">middle linebacker</option>";
            echo"<option value=\"outside linebacker\">outside linebacker</option>";
            echo"<option value=\"cornerback\">cornerback</option>";
            echo"<option value=\"safety\">safety</option>";
            echo"<option value=\"kicker\">kicker</option>";
            echo"<option value=\"longsnapper\">longsnapper</option>";
            }
            
            elseif($row['sport']== "Soccer"){
            echo"<option value=\"goalkeeper\">goalkeeper</option>";
            echo"<option value=\"wing back\">wing back</option>";
            echo"<option value=\"full back\">full back</option>";
            echo"<option value=\"sweeper\">sweeper</option>";
            echo"<option value=\"center back\">center back</option>";
            echo"<option value=\"winger\">winger</option>";
            echo"<option value=\"defensive midfielder\">defensive midfielder</option>";
            echo"<option value=\"center midfielder\">center midfielder</option>";
            echo"<option value=\"attacking midfielder\">attacking midfielder</option>";
            echo"<option value=\"striker\">striker</option>";
            echo"<option value=\"forward\">forward</option>";
            }
            
            elseif($row['sport']== "Basketball"){
            echo"<option value=\"point guard\">point guard</option>";
            echo"<option value=\"shooting guard\">shooting guard</option>";
            echo"<option value=\"small forward\">small forward</option>";
            echo"<option value=\"power forward\">power forward</option>";
            echo"<option value=\"center\">center</option>";
            }
            ?>
          </select>
          <br>
          <br>
          
        <!--submit buttons-->
        <div class = "split">
          <button class = "btn secondary" type="submit" name="add_player" value="<?php echo$team_id?>">Add Player</button>
          <div class = "btn tertiary"><a href="coach_dashboard.php">Dashboard Return</a></div>
        </div>
        
        </form>
    </div>
    </section>
</section>
</main>

</body>
</html>