<!DOCTYPE html>
<html lang="en">
    <head>
        <title>SignMeUp - Event Management - Admin Home</title>
    
    	<?php include("includes/head.php"); ?>
    	<?php include("includes/connect.php"); ?>
    	<style>
    	    /*hide the events with CSS to avoid a flash of content when hiding with JQuery */
    	    .event ol{
    	        display:none;
    	    }
    	</style>
    
    </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 h4").click(function(){
                    $(this).parent().find('ol').slideToggle();
                });//end h4 click
            });//end ready

        </script>
    </body>
</html>