<div class="right_col" role="main">

    <div class="">
        
        
		<div class="page-title">
			<div class="title_left">
				<h3>Admin list - Team <?php echo getDetailByTable('teams',$_GET['id'])['title']; ?> <a href="index.php?pagecontent=team_admin&add=y"><button type="button" class="btn btn-dark">Add Adnin</button></a></h3>
				
			</div>
		</div>
		<div class="clearfix"></div>

        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
					<div class="x_title">
						<h2>Reservation</h2>
						<div class="clearfix"></div>
					</div>
					<div class="x_content">
						<form class="form-horizontal form-label-left" method="post">
							<!-- <input id="name" class="form-control col-md-7 col-xs-12" name="id" type="text" value="<?php echo $getId; ?>" hidden> -->

							<div class="form-group">
								<label class="control-label col-md-3 col-sm-3 col-xs-12">Admin</label>
								<div class="col-md-4 col-sm-3 col-xs-12">
                                    <select class="form-control" name="admin">
                                        <?php
                                            $result = mysqli_query($conn, "SELECT * FROM admin");
                                            while($row = mysqli_fetch_assoc($result)){
                                        ?>
                                        <option value="<?php echo $row['a_id']; ?>"><?php echo $row['a_username']; ?></option>
                                        <?php } ?>
                                    </select>
							    </div>
							</div>

                            
								  

							<div class="ln_solid"></div>

							<div class="form-group">
								<div class="col-md-6 col-md-offset-3">
									<button id="send" type="submit" class="btn btn-success" name="submit">Add</button>
								</div>
							</div>

						</form>
                        <?php
                            if(isset($_POST['submit'])){
                                $teamId = $_GET['id'];
                                $postAdminId = $_POST['admin'];
                                mysqli_query($conn,"INSERT INTO team_admin (team_id,admin_id) VALUES ($teamId,$postAdminId)");
                                header("Location: ?pagecontent=team_admin&id=".$_GET['id']);
                            }
                        ?>
					</div>
                </div>
            </div>
        </div>

		<div class="clearfix"></div>
		<div class="row">
			<div class="col-md-12 col-sm-12 col-xs-12">
				<div class="x_panel">
					<div class="x_content">
						<table id="datatable" class="table table-striped table-bordered">
							<thead>
								<tr>
									<th>Name</th>
									<th>Action</th>
								</tr>
							</thead>
							<tbody>
								<?php
                                    $id = $_GET['id'];
									$result=mysqli_query($conn, "SELECT * FROM team_admin WHERE team_id=$id");
									while($row = mysqli_fetch_array($result))
									{
								?>
								<tr>
									<td><?php echo getDetailByTable('admin',$row['admin_id'])['a_username']; ?></a></td>
						
									<td>
										<a href="?pagecontent=team_admin&remove=<?php echo $row['id']; ?>"><button class="btn btn-xs btn-danger">Remove</button></a>
									</td>
								</tr>
								<?php
									}
								?>
						</table>
					</div>
				</div>
			</div>
        </div>
    </div>
</div>


<?php
	if(isset($_REQUEST['remove'])){
		$id = $_REQUEST['remove'];
		mysqli_query($conn,"DELETE FROM team_admin WHERE id=$id");
		header('Location: ?pagecontent=team_admin');  
	}
?>