<?php session_start(); ?>
<?php
	//secure the page to only Admins
	if(!isset($_SESSION['userType']) || $_SESSION['userType']!="Admin"){
		echo "<script>location.href='index.php?err=rights';</script>";
	}
		
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <title>SignMeUp - Event Management - Admin Home</title>

	<?php include("includes/head.php"); ?>
	<?php include("includes/connect.php"); ?>
	
  </head>
  <body>
  <header>
   <?php include("includes/nav.php"); ?>
</header>
<main role="main" class="container" >
	<h3>Admin Home - Event Management</h3>
	<?php
		//get all events in chronological order
		$sql="select * from events order by date, time";
		$result=$smeConn->query($sql);
		while($row=$result->fetch_assoc()){
			$eventid=$row['id'];
			$date=date('m/d/Y', strtotime($row['date']));
			$name=$row['name'];
			$time=date('h:i a', strtotime($row['time']));
			$loc=$row['location'];
			echo "<section class='event'>";
			echo "<h4>$name <small style='font-size:.5em'>$date - $time @ $loc</small></h4>";
			
			$partSql="select participants.user, users.last, users.first, users.phone, users.email, users.id from participants, users where participants.event=$eventid and users.id=participants.user order by users.last, users.first";
			$partRes=$smeConn->query($partSql);
			echo "<ol>";
			while($partRow=$partRes->fetch_assoc()){
				echo "<li class='row'>";
				echo "<span class='col-4'>".$partRow['last'].", ".$partRow['first']."</span>";
				echo "<span class='col-4'>".$partRow['phone']."</span>";
				echo "<span class='col-4'><a href='mailto:".$partRow['email']."'>".$partRow['email']."</a></span>";
				echo "</li>";
			}
			echo "</ol>";
			echo "</section>";
		}
	?>

</main><!-- /.container -->
<?php include("includes/footer.php"); ?>
<script>
	$(document).ready(function(){
		$('.event ol').hide();
		
		$('.event h4').click(function(){
			$(this).parent().find('ol').slideToggle();
		});//end h4 click
	});//end ready
</script>
</body>
</html>
