<?php

require_once '../database_access.php';
//use session on this page
if (!isset($_SESSION)) {
    session_start();
}
if (isset($_GET["event_id"])) {
    $event_id = $_GET["event_id"];
} else {
    echo '<p class="error_message">Need an event ID</p>';
}
//get event from event id
$q = new EventQuery();
$event = $q->findPk($event_id);
//get interests
$interests = EventInterestQuery::create()->find();
//check if current user is interested in this event
$interested = FALSE;
foreach ($interests as $interest) {
    if ($interest->getInterestedUserID() == $_SESSION['uid']) {
        $interested = TRUE;
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
	<?php 
include_once '../basic_includes/sheets_and_scripts.php';
?>
<?php

require_once 'database_access.php';
$q = new EventQuery();
$events = $q->orderByStartTime()->find();
?>
<!DOCTYPE html>
<html>
<head>
  <?php 
include_once 'basic_includes/sheets_and_scripts.php';
?>
  <title>RPI Wanna Hangout</title>

</head>
<body>
    <div id="index">
	<?php 
include 'basic_includes/navbar.php';
?>
 
    <div class="jumbotron jBack">
    <div class="container">
    <h1>Let's Hangout!</h1>
    <p>Easily find and share events occuring on or off campus. Connect with your classmates.</p>
        <p>Live. Learn. Experience.</p>
    <div class="btn-group" role="group" aria-label="...">
        <a class="btn btn-info" type="button" href="explore.php">Learn More</a>
        <a class="btn btn-info" type="button" href="events/create.php">Create an Event</a>
    </div>
	</div>
<?php

require_once '../database_access.php';
$ei = new EventInterestQuery();
if (isset($_GET['event_id'])) {
    $event = EventQuery::create()->findPk($_GET['event_id']);
    if ($event) {
        $ei->filterByTarget_Event($event);
    } else {
        // TODO: throw error instead of blank page
        echo "<p>tried to filter by nonexistent event</p>";
    }
}
$ei->join('EventInterest.Interested');
$ei->withColumn('Interested.FirstName', 'authorFirstName');
$ei->withColumn('Interested.LastName', 'authorLastName');
echo $ei->find()->toJson();