<?php
	include('/var/www/html/uclit/protected/common/login/check.php');
	include('/var/www/html/uclit/protected/common/css_login/css_head2.php');
	include('/var/www/html/uclit/protected/connections/db_work.php');
	mysql_select_db($database_workshop, $sqlConn) or die("Could not select database");
	
	if(isset($_GET['mas_id']) && $_GET['mas_id'] != "")	
	{
		$mas_id = $_GET['mas_id'];
		$class = $_GET['class'];
		$sqlQuerry = "SELECT worshopmaster_registrant.mas_reg_id,registrants.reg_id, registrants.reg_name,registrants.reg_status, registrants.reg_dept,worshopmaster_registrant.attend_fl
				FROM
					worshopmaster_registrant, registrants
				WHERE
					worshopmaster_registrant.master_id='$mas_id' and
					registrants.reg_id=worshopmaster_registrant.reg_id and
					worshopmaster_registrant.reg_wait_list<>1
				ORDER BY 
					registrants.reg_name
					";
					
		$QuerryResult = mysql_query($sqlQuerry) or die("SELECT query failed");
		echo "
			<center>
			<h1>$class</h1>
			<form name='attend' method='POST' action='getattendance.php'>
			<table border='1'>
				<tr>
					<th>Attendance</th>
					<th>Number</th>
					<th>Name</th>
					<th>Status</th>
					<th>College</th>
					<th>In Class</th>
					<th>Delete</th>
				</tr>
		";
		$num = 1;
		while($row = @mysql_fetch_array($QuerryResult))
		{
			$id = $row['reg_id'];
			$m_reg_id = $row['mas_reg_id'];
			$n = $row['reg_name'];
			$s = $row['reg_status'];
			$c = $row['reg_dept'];
			$att = $row['attend_fl'];
			echo "
				<tr>
					<td align='middle'><input type='checkbox' name='namelist[]' value='$id'/></td>
					<td align='middle'>$num</td>
					<td>$n</td>
					<td>$s</td>
					<td>$c</td>
				";
				if($att == "1")
				{
					echo "<td>Attended</td>";
				}
				else
				{
					echo "<td>Not Attended</td>";
				}
			echo "
				<td><a href='remove.php?m_id=$mas_id&r_id=$id&mas_reg_id=$m_reg_id&class=$class'>Delete</a></td>	
				</tr>
			";
				$num++;
		}
		echo "
			<tr>
				<td colspan='6' align='left'>
					<input type='hidden' name='mas_id' value='$mas_id' />
					<input type='hidden' name='class' value='$class' />
					<input type='submit' name='getattend' value='Submit Attendance' />
				</td>
			</tr>
			</table>
			</form>
			<a href='workshop_detail.php'>Go to Workshop Details</a>
			</center>
		";
		//end actual class list
		////////////////////////////////////////////////////
		//listing all waiting list students
			$sqlQuerry = "SELECT registrants.reg_name,registrants.reg_email,registrants.reg_status,registrants.reg_dept
					FROM
						worshopmaster_registrant, registrants
					WHERE
						worshopmaster_registrant.master_id='$mas_id' and
						registrants.reg_id=worshopmaster_registrant.reg_id and
						worshopmaster_registrant.reg_wait_list='1'
						";
						
			$QuerryResult = mysql_query($sqlQuerry) or die("SELECT query failed");
			$listCount = count($QuerryResult);
			if( $listCount > 0)
			{
				echo "
					<center>
					<h1>Wait List</h1>
					<table border='1'>
						<tr>
							<td><strong>Number</strong></td>
							<td><strong>Name</strong></td>
							<td><strong>Status</strong></td>
							<td><strong>College</strong></td>
							<td><strong>Email</strong></td>
						</tr>
				";
				$num = 1;
				$QuerryResult = mysql_query($sqlQuerry) or die("SELECT query failed");
				while($row = @mysql_fetch_array($QuerryResult))
				{
					$n = $row['reg_name'];
					$s = $row['reg_status'];
					$e = $row['reg_email'];
					$c = $row['reg_dept'];
					echo "
						<tr>
							<td>$num</td>
							<td>$n</td>
							<td>$s</td>
							<td>$c</td>
							<td><a href='mailto:$e'>$e</a></td>
						</tr>
					";
						$num++;
				}
				echo "</table>
					<a href='workshop_detail.php'>Go to Workshop Details</a><br /><br ><hr />
					<i>Note: Wait List means that the class has reached its capacity.  You may not be in the actual class list until someone drops from the class.  
						Please check the current list before attending the workshop.  If someone drops from the class, the wait list will be trasferred over to the class list according to the order of registration.</i>
					</center>
				";
			}
	}
	else
	{
		echo "Invalid entry to this page<br />
				Please return to <a href='workshop_detail.php'>workshop detail</a>.<br />
		";
	}
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
?>