<?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'); 

	//selecting all quarter and instructor
	$loggedinuser = $_SESSION['username'];
	
	$sqlpid = "SELECT personnel_id FROM users WHERE username='$loggedinuser'";
	$li = mysql_select_db($database_login, $sqlLoginConn) or die("Could not select database $database_login");
	$pidResult = mysql_query($sqlpid) or die("SELECT query failed from Login");

	while($p_row = @mysql_fetch_array($pidResult))
	{
		$pid = $p_row['personnel_id'];
	}
	if($pid != "")
	{
		$uc = mysql_select_db($database_uclit, $sqlUclitConn) or die("Could not select database $database_uclit");
		$sqlUser = "SELECT personnel_id,first_name,last_name, e_mail FROM personnel WHERE personnel_id='$pid'";
		$UserResult = mysql_query($sqlUser) or die("SELECT query failed from uclit_db");
		while($p_row = @mysql_fetch_array($UserResult))
		{
			$uname = $p_row['first_name']." ".$p_row['last_name'];
			$uemail = $p_row['e_mail'];
		}
		if($uname != "")
		{
			//begin reading from current_quarter.dat file for current quarter
			$fp = fopen("current_quarter.dat", "r"); 
			$c_quarter = ""; 

			while(!feof($fp)) 
			{ 
				$c_quarter .= fgets($fp, 4096); 
			} 
			fclose($fp); 
			//end reading current file
			
			
			$sqlInst_id = "SELECT inst_id FROM instructors WHERE personnel_id='$pid'";
			$ws = mysql_select_db($database_workshop, $sqlConn) or die("Could not select database $database_workshop");
			$Inst_idResult = mysql_query($sqlInst_id) or die("SELECT query failed from workshop");
			while($i_row = @mysql_fetch_array($Inst_idResult))
			{
				$inst_id = $i_row['inst_id'];
			}
		//selecting all current record for this quarter
		$sqlQuerry = "SELECT 
					workshop_master.master_id, workshop_detail.w_name, workshop_detail.w_survey, quarters.quarter, workshop_master.time, workshop_master.date, location.location,location.capasity, workshop_master.day_id, workshop_master.month_id
				FROM
					quarters, workshop_master, location, instructors, workshop_detail
				WHERE
					instructors.inst_id='$inst_id' and
					quarters.quarter_id='$c_quarter' and
					workshop_master.quarter_id='$c_quarter' and
					instructors.inst_id=workshop_master.inst_id and
					location.loc_id=workshop_master.loc_id and
					workshop_detail.w_id=workshop_master.w_id
				ORDER BY
					workshop_master.date	
					";
			$QuerryResult = mysql_query($sqlQuerry) or die("SELECT query workshop_master");			
			$c = count($QuerryResult);
			echo "Instructor: <strong>$uname</strong><br />";
			if($c != 0)
			{	
				echo "<table border=\"1\" class=\"sortable\" id=\"maintable\">
						<tr>
							<td width=\"25%\" align=\"center\"><strong>Class</strong></td>
							<td width=\"15%\" align=\"center\"><strong>Location</strong></td>
							<td width=\"10%\" align=\"center\"><strong>Date</strong></td>
							<td width=\"10%\" align=\"center\"><strong>Time</strong></td>
							<td width=\"10%\" align=\"center\"><strong>Email</strong></td>
							<td width=\"10%\" align=\"center\"><strong>Feedback</strong></td>
							<td width=\"10%\" align=\"center\"><strong>WaitList</strong></td>
						</tr>
				";
					while($c_row = @mysql_fetch_array($QuerryResult))
					{
						$des = $c_row['w_name'];
						$survey = $c_row['w_survey'];	
						$l = $c_row['location'];
                        $day = $c_row['day_id'];
                        $month = $c_row['month_id'];	
						$d = $c_row['date'];	
						$t = $c_row['time'];	
						$m = $c_row['master_id'];	
						$cap = $c_row['capasity'];
						
						$sqlCount ="SELECT COUNT(reg_id) as Total FROM worshopmaster_registrant WHERE master_id='$m'";
						$CountResult = mysql_query($sqlCount) or die("SELECT query failed");
						$c = 0;
						while($m_row = @mysql_fetch_array($CountResult))
						{
							$c = $m_row['Total'];
						}
						echo "
							<tr>
								<td><a href='inst_workshop_detail.php?mas_id=$m&cap=$cap&size=$c&mode=attendance&name=$des'>$des</a></td>
								<td>$l</td>
								<td>$d</td>
								<td>$t</td>
								<td align=\"center\"> <a href='inst_workshop_detail.php?mas_id=$m&cap=$cap&size=$c&mode=email'>Email</a></td>							<td align=\"center\"><a href='inst_workshop_detail.php?mas_id=$m&cap=$cap&size=$c&mode=feedback'>Feedback</a></td><td align=\"center\"><a href='inst_workshop_detail.php?mas_id=$m&cap=$cap&size=$c&mode=waitlist'>Waitlist</a></td>
							</tr>
						";
					}
				echo "</table>
					";
				}
				else
				{
					echo "You are not one of the instructors";
				}
			}
			else
			{
				echo "There are no workshop assigned to you this quarter.<br />";
			}
	}
	else
	{
		echo "You are not one of the users";
	}						
	include('/var/www/html/uclit/protected/common/css_login/css_foot2.php'); 
	
	?>
