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

<form name="quarter" action="all_workshop_detail.php" method="POST">
<strong>Quarter:</strong>
<select name="show_quarter" onChange="submitQuarter()">
<?php
	
	$db = mysql_select_db($database_workshop, $sqlConn) or die("Could not select database $database_uclit");
	//fill up the personnel drop down box
	$sql_qtr = "SELECT distinct quarter, quarter_id FROM quarters ORDER BY quarter";
	$qtr_result = mysql_query($sql_qtr, $sqlConn) or die ("Unable to query: $sql_dept");
	echo "<option value='0' selected>Select...</option>";	
	while($qtr_row = mysql_fetch_array($qtr_result))
	{
		$qtr = $qtr_row['quarter'];
		$qtr_id = $qtr_row['quarter_id'];
		
		if($c_quarter == $qtr_id)
			echo "<option value='$qtr_id' selected>$qtr</option>";
		else
			echo "<option value='$qtr_id'>$qtr</option>";	
	}
?>
</select>

</form>	




<?php
	$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
			
			
			
			
			$get_qtr =$_POST['show_quarter'];
			
			if($get_qtr != "")
				{
				$c_quarter = $get_qtr;
				
				$ws_q = mysql_select_db($database_workshop, $sqlConn) or die("Could not select database $database_workshop");
				$sql_q = "SELECT  quarter, quarter_id FROM quarters WHERE quarter_id=$c_quarter ORDER BY quarter";
				$q_result = mysql_query($sql_q, $sqlConn) or die ("Unable to query: $sql_dept");
				
				while($q_row = @mysql_fetch_array($q_result))
				{
					$quarter_name = $q_row['quarter'];
				}

				echo"Selected Quarter: $quarter_name<br>";
				}

			$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, 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
					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.month_id, workshop_master.day_id	
					";
			$QuerryResult = mysql_query($sqlQuerry) or die("SELECT query workshop_master");			
			$c = count($QuerryResult);
			echo "Instructor: <strong>All Workshops offered</strong><br />";
			if($c != 0)
			{	
				echo "<table border=\"1\"class=\"sortable\" id=\"maintable\" >
						<tr>
							<td width=\"5%\" align=\"center\"><strong>Delete</strong></td>
                                                        <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>Detail</strong></td>
							<td width=\"10%\" align=\"center\"><strong>Email</strong></td>
							<td width=\"10%\" align=\"center\"><strong>Feedback</strong></td>
						</tr>
				";
					while($c_row = @mysql_fetch_array($QuerryResult))
					{
						$des = $c_row['w_name'];	
						$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='delete_workshop.php?mas_id=$m'><img src=\"delete.gif\" border ='0' align='right' alt=\"Delete\"></a></td> 
                                                                <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>$c/$cap</td>
								<td><a href='inst_workshop_detail.php?mas_id=$m&cap=$cap&size=$c&mode=email'>Email</a></td><td><a href='inst_workshop_detail.php?mas_id=$m&cap=$cap&size=$c&mode=feedback'>Feedback</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'); 
	
	?>
	
	
	<script type="text/javascript">
	function submitQuarter()
	{
	document.quarter.submit();
	}
	</script>
