<?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'); 
  
	if(isset($_GET['type']) && $_GET['type'] == "edit") 
	{
		$id = $_GET['id'];
		$type = $_GET['type'];
		mysql_select_db($database_workshop, $sqlConn) or die("Could not select database");
		$sqlQuerry = "select * from workshop_detail where w_id='$id'";
		$QuerryResult = mysql_query($sqlQuerry) or die("SELECT query failed");
		
		
		while($class_row = @mysql_fetch_array($QuerryResult))
		{	
			$wname = $class_row['w_name'];
			$wdes = $class_row['w_description'];
			$wid = $class_row['w_id'];
			$wprereq = $class_row['w_prereq'];
			$wques = $class_row['w_pre_question'];
			$wsurvey = $class_row['w_survey'];
			
		}
		echo "<h1>Editing Workshop</h1>";
		echo "
			<form name='administer' method='POST' action='update_administer.php'>
			<strong>Class Name:</strong><br />
			<input type='text' name='cname' value='$wname'  size='50'/>
			<br />
			<strong>Class Description:</strong><br />
			<textarea name='cdes' cols='50' rows='10'>$wdes</textarea>
			<br />
			<strong>Pre-Requisite:</strong><br />
			
			<input type='text' name='cprereq' value='$wprereq'  size='50' />
			<br />
			<strong>Class Survey:</strong><br />
			<textarea name='csurvey' cols='50' rows='1'>$wsurvey</textarea>
			<br />
			<input type='hidden' name='id' value='$id' />
			<input type='hidden' name='cques' value='$wques' />
			<input type='hidden' name='type' value='$type' /><br />
			<input type='button' name='edit' value='Edit This Workshop' onClick='EditCheckReq()'/>
			<input type='button' name='back' value='Cancel' onClick='goBack()'/>

			</form>
			";
	}
	else if( isset($_GET['type']) && $_GET['type'] == "add")
	{
		$type = $_GET['type'];
		echo "<h1>Adding Workshop</h1>";
		echo "
			<form name='administer' method='POST' action='update_administer.php'>
			<strong>Class Name:</strong><br />
			<input type='text' name='cname' value=''  size='50'/>
			<br />
			<strong>Class Description:</strong><br />
			<textarea name='cdes' cols='50' rows='10'></textarea>
			<br />
			<strong>Pre-Requisite:</strong><br />
			<select name='cprereq'>
				<option value=''>Select...</option>
			";
			mysql_select_db($database_workshop, $sqlConn) or die("Could not select database");
			$sqlC = "select w_name from workshop_detail";
			$CResult = mysql_query($sqlC) or die("SELECT query failed");
			while($c_row = @mysql_fetch_array($CResult))
			{	
				$c = $c_row['w_name'];
				echo "<option value='$c'>$c</option>";
			}
			echo "
			</select>
			
			<br />
			<strong>Class Survey:</strong><br />
			<textarea name='csurvey' cols='50' rows='1'></textarea>
			<br />
			<input type='hidden' name='cques' value='' />
			<input type='hidden' name='type' value='$type' /><br />
			<input type='button' name='add' value='Add This Workshop' onClick='AddCheckReq()'/>
			<input type='button' name='back' value='Cancel' onClick='goBack()'/>
			</form>
			";

	}
	else
	{
		echo "Invalid entry into this form.  Please return to <a href='list_administer.php'>Administer List</a><br />";
	}
	include('/var/www/html/uclit/protected/common/css_foot.php'); 
	?>
	<script type="text/javascript">
	function EditCheckReq()
	{
		var n = document.administer.cname.value;
		var d = document.administer.cdes.value;
		var p = document.administer.cprereq.value;
		var q = document.administer.cques.value;

		var msg = "Invalid field(s):\n";
		var c = 0;
		if(n == "")
		{
			msg += "Class Name\n";
			c++;
		}
		if(d == "")
		{
			msg += "Class Description\n";
			c++;
		}
		if(p != "")
		{
			document.administer.cques.value = "1";
		}
		else
		{
			document.administer.cques.value = "0";
		}
		if(c != 0)
		{
			window.alert(msg);
		}	
		else
		{
			document.administer.submit();	
		}	
	}
	function AddCheckReq()
	{
		EditCheckReq();
	}
	function goBack()
	{
		window.location='http://ul.uc.edu/uclit/protected/workshop/list_administer.php';
	}
	</script>