<?php

require_once './functions.php';
if (isset($_POST['eventNo'])) {
    $eventNo = $_POST['eventNo'];
    $memberID = $_POST['email'];
    $didAttend = $_POST['didAttend'];
    //get the current attends info
    $sql = "select didAttend from attends where memberID='{$memberID}' and eventNo='{$eventNo}'";
    $attendses = mysql_query($sql);
    //make a new attends relationship, if it doesn't already exist
    if (mysql_num_rows($attendses) == 0) {
        $sql = "INSERT INTO attends (memberID, shouldAttend, didAttend, eventNo, minutesLate, confirmed) VALUES ('{$memberID}', '0', '{$didAttend}', '{$eventNo}', '0', '1')";
        mysql_query($sql);
    } else {
        $sql = "update attends set confirmed='1', didAttend='{$didAttend}' where memberID='{$memberID}' and eventNo='{$eventNo}'";
        mysql_query($sql);
    }
    //get the user's first and last name
    $sql = "select * from member where email='{$memberID}'";
    $member = mysql_fetch_array(mysql_query($sql));
    $firstName = $member['firstName'];
    $lastName = $member['lastName'];
    //get the updated attendance info and th recalculated grade
    echo getEventAttendanceRows($eventNo);
} else {
    echo "Something went wrong :/";
}
			border-top: 1pt solid black;
			border-bottom: 1pt solid black;
			border-left: 1pt solid black;
			border-right: 1pt solid black;
		}
		.data {
			border-top: 1px dotted #000000;
			border-bottom: 1px dotted #000000;
		}
	</style>
	<script type="text/javascript" src="./js/drewJS.js"></script>
</head>

<?php 
if (isset($_COOKIE['email'])) {
    require_once './functions.php';
    $userEmail = $_COOKIE['email'];
}
if (isset($_POST['eventNo'])) {
    $eventNo = $_POST['eventNo'];
    $sql = "select name from event where eventNo='{$eventNo}'";
    $event = mysql_fetch_array(mysql_query($sql));
    $name = $event['name'];
    $html = "<html>\n\t\t<p style='text-align: center; font-weight: bold;'>{$name} Attendance</p> \n\t\t<p id='attendanceList'>\n\t\t\t<table id='{$eventNo}" . "_table'>\n\t\t\t\t" . getEventAttendanceRows($eventNo) . "\n\t\t\t</table>\n\t\t</p>\n\t\t</html>";
} else {
    $html = "<(><)> Something went wrong <(><)>";
}
echo $html;
?>

<?php

require_once './functions.php';
$eventNo = mysql_real_escape_string($_POST['eventNo']);
if (!attendancePermission($USER, $eventNo)) {
    die("Access denied");
}
if (!isset($eventNo)) {
    die("Missing event number");
}
$sql = "select `name`, `section` from `event` where `eventNo` = '{$eventNo}'";
$event = mysql_fetch_array(mysql_query($sql));
$name = $event['name'];
$html = "<div class='pull-right'><button class='btn' onclick='excuseall({$eventNo})'>Excuse Unconfirmed</button></div>\n<p style='text-align: center; font-weight: bold;'>{$name} Attendance</p> \n<p id='attendanceList'><table id='{$eventNo}" . "_table'>" . getEventAttendanceRows($eventNo) . "</table></p>";
echo $html;