<?php
session_start();
?>
<?
	include("user.php");
	include("class.php");
	include("topic.php");
	include("login.php");
	
	if ($_SESSION['user']) {
		if ($_SESSION['admin'] == 0)
			header("Location: index.php");
	}
	else
		header("Location: index.php");
	
	$classid = $_GET['id'];	
	
	if ($_POST['name']) {
		if (!get_magic_quotes_gpc()) {
			$_POST['name'] = addslashes($_POST['name']);
			$_POST['section'] = addslashes($_POST['section']);
			$_POST['term'] = addslashes($_POST['term']);
		}
		updateClass($classid, $_POST['name'], $_POST['section'], $_POST['term'], $_POST['year']);
	}
	
	if ($_POST['removeUserID']) {
		if (confirmPassword($_SESSION['user'], $_POST['deletepass']))
			removeUser($classid, $_POST['removeUserID']);
		$_POST['tabnum'] = 3;
	}
	
	if ($_SESSION['grant']) {
		$grant = explode('.', $_SESSION['grant']);
		if ($grant[0])
			setStudentAdmin($grant[1], $classid, true);
		else
			setStudentAdmin($grant[1], $classid, false);
		$_POST['tabnum'] = 3;
		unset($_SESSION['grant']);
	}
	else if ($_GET['grant']) {
		$_SESSION['grant'] = $_GET['grant'];
		header("Location: editclass.php?id=$classid");		
	}
	
	$tabnum = 1;
	
	if ($_POST['tabnum'])
		$tabnum = $_POST['tabnum'];
		
	if (strpos($_SERVER['HTTP_REFERER'], "edituser.php") !== false ||
	    strpos($_SERVER['HTTP_REFERER'], "editarticles.php") !== false)
		$tabnum = 3;
		
	if ($_POST['fname']) {
		$tabnum = 3;
		if (confirmPassword($_SESSION['user'], $_POST['adduserpass'])) {
			$chars = "abcdefghijkmnopqrstuvwxyz023456789";
			srand((double)microtime()*1000000);
			$i = 0;
			$randpass = '' ;
		
			while ($i <= 7) {
				$num = rand() % 33;
				$tmp = substr($chars, $num, 1);
				$randpass = $randpass.$tmp;
				$i++;
			}
			
			if (!get_magic_quotes_gpc()) {
				$fname = addslashes($_POST['fname']);
				$lname = addslashes($_POST['lname']);
				$email = addslashes($_POST['email']);
				$worked = addUser($fname, $lname, $email, $randpass, $_POST['adminlevel']);
				$newuser = getUser('Email', $email);
			}
			else {
				$worked = addUser($_POST['fname'], $_POST['lname'], $_POST['email'], 
										  $randpass, $_POST['adminlevel']);
				$newuser = getUser('Email', $_POST['email']);
			}
			
			enrollUser($classid, $newuser['ID']);
			
			if ($worked) {
				$curUser = getUserName($_SESSION['user']);
				$curName = $curUser['FirstName']." ".$curUser['LastName'];
				$address = "http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
				$address = substr($address, 0, -9);
				$body = "Hello, ".$_POST['fname']."!  You have been added as a user to Syllogistek, the".
						" Argument Library Software, by ".$curName.".  Please login to the system ".
						"at ".$address.".  The password generated for you is:\n\n\t".$randpass."\n\nYou".
						" may change this password from your user information screen once you log in.".
						"\n\n\nThis message has been generated automatically.  Please do not reply to ".
						"this message.";
				$body = wordwrap($body, 70);
				mail($_POST['email'], "Welcome to Syllogistek!", $body, "From: donotreply@syll.net");
			}
		}
		else
			echo("<span style='color:#FF3300;'>User has not been enrolled because validation failed.</span><br>");	
	}
	
	$class = getClass($classid);
	$roster = getRoster_Inst($classid);
		
	if ($_POST['topictext'] && $_POST['topictext'] != '') {
		if (!get_magic_quotes_gpc()) {
			$topictext = addslashes($_POST['topictext']);
			addTopic($classid, $topictext, $_POST['requiredargs']);
		}
		else
			addTopic($classid, $_POST['topictext'], $_POST['requiredargs']);
	}
	else if ($_POST['positiontext'] && $_POST['positiontext'] != '') {
		if (!get_magic_quotes_gpc()) {
			$positiontext = addslashes($_POST['positiontext']);
			addPosition($_POST['curTopic'], $positiontext);
		}
		else
			addPosition($_POST['curTopic'], $_POST['positiontext']);
	}
	else if ($_POST['reasontext'] && $_POST['reasontext'] != '') {
		if (!get_magic_quotes_gpc()) {
			$reasontext = addslashes($_POST['reasontext']);
			addReason($_POST['curPosition'], $reasontext, false);
		}
		else
			addReason($_POST['curPosition'], $_POST['reasontext'], false);
	}
	
	if ($_POST['curPosition']) {
		$c = $_POST['curPosition'];
		allowOther($c, isset($_POST['allowOther'.$c]));
	}
	
	if ($_POST['otherposition']) {
		$tabnum = 2;
		$otherpos = $_POST['otherposition'];
		$reasontext = $_POST['other'.$otherpos.'new'];
		if (!get_magic_quotes_gpc())
			$reasontext = addslashes($reasontext);
		$merging = array();
		$max = count(getReasons($otherpos, true));
		for($i = 0; $i < $max; $i++) {
			if ($_POST['others'.$otherpos.'_'.$i]) {
				array_push($merging, $_POST['others'.$otherpos.'_'.$i]);
			}
		} 
		mergeReasons($otherpos, $reasontext, $merging);
	}
	
	if ($_POST['type'] && $_POST['newdesc'] != '') {
		$t = $_POST['type'];
		if ($_POST['editDesc'] == 'Accept') {
			$desc = $_POST['newdesc'];
			if (!get_magic_quotes_gpc())
				$desc = addslashes($desc);
			if ($t == 'topic')
				editTopic($_POST['typeid'], $desc, $_POST['newreqargs']);
			if ($t == 'position')
				editPosition($_POST['typeid'], $desc);
			if ($t == 'reason')
				editReason($_POST['typeid'], $desc, false);
		}
		else if ($_POST['editDesc'] == 'Remove') {
			if ($t == 'topic')
				deleteTopic($_POST['typeid']);
			if ($t == 'position')
				deletePosition($_POST['typeid']);
			if ($t == 'reason')
				deleteReason($_POST['typeid']);
		}
	}
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edit Class Information</title>
<script language="javascript">
<!--
	document.onmousemove = getMouseLoc;
	var mouseX = 0;
	var mouseY = 0;
	
	function switchField(tab) {
		document.getElementById('basicinfo').style.display='none';
		document.getElementById('topicinfo').style.display='none';
		document.getElementById('rosterinfo').style.display='none';
		switch (tab) {
			case 1:	document.getElementById('basicinfo').style.display='block';
					document.getElementById('basic').innerHTML="<b>Class Information</b>";
					document.getElementById('topics').innerHTML=
						"<a href='javascript:switchField(2)'>Topics</a>";
					document.getElementById('roster').innerHTML=
						"<a href='javascript:switchField(3)'>Roster</a>";
					break;
			case 2:	document.getElementById('topicinfo').style.display='block';
					document.getElementById('topics').innerHTML="<b>Topics</b>";
					document.getElementById('basic').innerHTML=
						"<a href='javascript:switchField(1)'>Class Information</a>";
					document.getElementById('roster').innerHTML=
						"<a href='javascript:switchField(3)'>Roster</a>";
					break;
			case 3:	document.getElementById('rosterinfo').style.display='block';
					document.getElementById('roster').innerHTML="<b>Roster</b>";
					document.getElementById('topics').innerHTML=
						"<a href='javascript:switchField(2)'>Topics</a>";
					document.getElementById('basic').innerHTML=
						"<a href='javascript:switchField(1)'>Class Information</a>";
					break;
		}
	}
	
	function expandTopic(num) {
		document.getElementById('resetedit').click();
		div = document.getElementById('topic'+num+'pos');
		last = document.getElementById('curTopic').value;
		if (last != 0 && last != num) {
			if ((lpos = document.getElementById('curPosition').value) != 0) {
				document.getElementById('position'+lpos+'reas').style.display='none';
				document.getElementById('position'+lpos).innerHTML=
				'<img src="img/plus-8.png" onclick="expandPosition('+lpos+','+last+')">';
				document.getElementById('undertopic'+last).style.display='block';
				document.getElementById('curPosition').value = 0;
			}
			document.getElementById('topic'+last+'pos').style.display='none';
			document.getElementById('topic'+last).innerHTML=
				'<img src="img/plus-8.png" onclick="expandTopic('+last+')">';
		}
		if (div.style.display=='none') {
			document.getElementById('topic'+num).innerHTML=
				'<img src="img/minus-8.png" onclick="expandTopic('+num+')">';
			div.style.display='block';
			document.getElementById('curTopic').value = num;
			return;
		}
		if (div.style.display=='block') {
			document.getElementById('topic'+num).innerHTML=
				'<img src="img/plus-8.png" onclick="expandTopic('+num+')">';
			div.style.display='none';
			document.getElementById('curTopic').value = 0;
			return;
		}
	}
	
	function expandPosition(num, topic) {
		document.getElementById('resetedit').click();
		div = document.getElementById('position'+num+'reas');
		last = document.getElementById('curPosition').value;
		if (last != 0 && last != num) {
			document.getElementById('position'+last+'reas').style.display='none';
			ltopic = document.getElementById('lastTopic').value;
			document.getElementById('position'+last).innerHTML=
				'<img src="img/plus-8.png" onclick="expandPosition('+last+','+ltopic+')">';
		}
		document.getElementById('lastTopic').value = topic;
		if (div.style.display=='none') {
			document.getElementById('position'+num).innerHTML=
				'<img src="img/minus-8.png" onclick="expandPosition('+num+','+topic+')">';
			div.style.display='block';
			document.getElementById('curPosition').value = num;
			document.getElementById('undertopic'+topic).style.display='none';
			return;
		}
		if (div.style.display=='block') {
			document.getElementById('position'+num).innerHTML=
				'<img src="img/plus-8.png" onclick="expandPosition('+num+','+topic+')">';
			div.style.display='none';
			document.getElementById('curPosition').value = 0;
			document.getElementById('undertopic'+topic).style.display='block';
			return;
		}
	}
	
	function setupPosition(topic) {
		document.getElementById('positiontext').value = document.getElementById('positiontext'+topic).value;
	}
	
	function setupReason(pos) {
		document.getElementById('reasontext').value = document.getElementById('reasontext'+pos).value;
	}
	
	function edit(type, id, disable) {
		div = document.getElementById('editing');
		div.style.top = (mouseY-250)+'px';
		div.style.left = (mouseX-200)+'px';
		div.style.display = 'block';
		document.getElementById('type').value = type;
		document.getElementById('typeid').value = id;
		text = document.getElementById(type+id+'text').innerHTML;
		if (type == 'topic') {
			text_arr = text.split(" ");
			num = text_arr[0].substring(1, text_arr[0].length-1);
			text = "";
			for (i = 1; i < text_arr.length; i++)
				text += text_arr[i]+" ";
			text = text.substring(0, text.length-1);
			document.getElementById('newreqargs').style.display = 'block';
			document.getElementById('newreqargs').value = num;
		}
		document.getElementById('newdesc').value = text;
		document.getElementById('removeEdit').disabled = disable;
	}
	
	function closeEdit() {
		document.getElementById('newdesc').value = '';
		document.getElementById('newreqargs').style.display = 'none';
		document.getElementById('editing').style.display = 'none';
	}
	
	function getMouseLoc(e) {
		if (!e) var e = window.event;
		if (e.pageX || e.pageY) 	{
			mouseX = e.pageX;
			mouseY = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			mouseX = e.clientX + document.body.scrollLeft
				+ document.documentElement.scrollLeft;
			mouseY = e.clientY + document.body.scrollTop
				+ document.documentElement.scrollTop;
		}
	}
	
	function goBack() {
		window.location = "classes.php";
	}
	
	function submitForm(id) {
		document.edittopics.submit();
	}
	
	function checkAddUser() {
		var email = document.getElementById('email').value;
		index = email.indexOf('@');
		var wrong = index <= 0 || index == (email.length-1)
		var fname = document.getElementById('fname').value;
		var lname = document.getElementById('lname').value;
		var noNames = !fname || !lname;
		if (wrong || noNames || noMatch) {
			if (wrong)
				document.getElementById('noemail').style.display = 'block';
			if (noNames)
				document.getElementById('noname').style.display = 'block';
			return false;
		}
		return true;
	}
	
	function enrollUser(display) {
		if (display)
			document.getElementById('add').style.display = 'block';
		else
			document.getElementById('add').style.display = 'none';
	}
	
	function viewOthers(position, display) {
		if (display) {
			document.getElementById('others'+position).style.display = 'block';
			document.getElementById('otherposition').value = position;
		}
		else
			document.getElementById('others'+position).style.display = 'none';
	}
	
	function removeUser(user, show) {
		if (show) {
			div = document.getElementById('removeConfirm');
			div.style.top = mouseY+'px';
			div.style.left = (mouseX+10)+'px';
			div.style.display = 'block';
			document.getElementById('removeUserID').value = user;
			document.getElementById('yesremove').disabled = false;
		}
		else {
			document.getElementById('removeConfirm').style.display = 'none';
			document.getElementById('removeUserID').value = 0;
			document.getElementById('yesremove').disabled = true;
		}
	}
	
	function setStudentAdmin(user, admin) {
		loc = 'editclass.php?id=<? echo $classid; ?>';
		if (admin)
			loc += '&grant=1.'+user;
		else
			loc += '&grant=0.'+user;
		window.location = loc;
	}
	
	function resetCurrent() {
		kind = document.getElementById('type').value;
		if (kind == 'position')
			document.getElementById('curPosition').value = null;
		if (kind == 'topic') {
			document.getElementById('lastTopic').value = null;
			document.getElementById('curTopic').value = null;
		}
	}
	
// -->
</script>
</head>

<? include("header.php"); ?>
Select what portion of the class you would like to edit using the links below.<br />
Only one link can be active for editing at any given time.<br /><br />
<table style='font-variant:small-caps' cellpadding='5px'>
	<tr>
		<td align='center'><div id='basic'>
			<? 	if ($tabnum != 1)
					echo("<a href='javascript:switchField(1)'>Class Information</a>");
				else
					echo("<b>Class Information</b>");
			?>
		</div></td>
		<td align='center'><div id='topics'>
			<? 	if ($tabnum != 2)
					echo("<a href='javascript:switchField(2)'>Topics</a>");
				else
					echo("<b>Topics</b>");
			?>
		</div></td>
		<td align='center'><div id='roster'>
			<? 	if ($tabnum != 3)
					echo("<a href='javascript:switchField(3)'>Roster</a>");
				else
					echo("<b>Roster</b>");
			?>
		</div></td>
	</tr>
</table>

<div id='basicinfo' style='position:relative; top:5px; left:10px;<? if ($tabnum != 1) echo " display: none" ?>'>
<form id='editclass' name='editclass' submit='editclass.php?id=<? echo $classid ?>' method='POST' >
<input type='hidden' name='tabnum' value='1' />
<table>
	<tr>
		<td align='right' style='font-weight:bold'>Class Name:</td>
		<td align='left'><input id='name' name='name' value="<? echo $class['CourseName'] ?>" /></td>
	</tr>
	<tr>
		<td align='right' style='font-weight:bold'>Section:</td>
		<td align='left'><input id='section' name='section' value='<? echo $class['SectionLetter'] ?>'  /></td>
	</tr>
	<tr>
		<td align='right' style='font-weight:bold'>Term:</td>
		<td align='left'><input id='term' name='term' value='<? echo $class['Term'] ?>'  /></td>
	</tr>
	<tr>
		<td align='right' style='font-weight:bold'>Year:</td>
		<td align='left'><input id='year' name='year' value='<? echo $class['Year'] ?>'  /></td>
	</tr>
	<tr>
		<td></td>
		<td align='left'><input type='submit' value='Accept' /></td>
	</tr>
</table>
</form>
</div>

<div id='topicinfo' style='position:relative; top:5px; left:20px;<? if ($tabnum != 2) echo " display: none" ?>'>
<form id='edittopics' name='edittopics' submit='editclass.php?id=<? echo $classid ?>' method='POST' >
<input type='hidden' name='tabnum' value='2' />
<input type='hidden' id='curTopic' name='curTopic' value='<? if ($_POST['curTopic']) echo ($_POST['curTopic']); else echo 0; ?>' />
<input type='hidden' id='curPosition' name='curPosition' value='<? if ($_POST['curPosition']) echo ($_POST['curPosition']); else echo 0; ?>'  />
<input type='hidden' id='lastTopic' name='lastTopic' value='<? if ($_POST['lastTopic']) echo ($_POST['lastTopic']); else echo 0; ?>'  />
<input type='hidden' id='positiontext' name='positiontext'  />
<input type='hidden' id='reasontext' name='reasontext'  />
<?
	$topics = getTopics($classid);
	if ($topics) {
		foreach($topics as $t) {
			$i = $t['ID'];
			echo("<span id='topic".$i."'>");
			if ($i == $_POST['curTopic'])
				echo("<img src='img/minus-8.png' onclick='expandTopic(".$i.")'></span> &nbsp; ");
			else
				echo("<img src='img/plus-8.png' onclick='expandTopic(".$i.")'></span> &nbsp; ");
			echo(" <a href='javascript:edit(\"topic\",".$i.",");
			if (hasPositions($i))
				echo("true");
			else
				echo("false");
			echo(")' style='font-variant:small-caps; font-size:smaller;'>Edit</a>".
				 " &nbsp; <span id='topic".$i."text'>(".$t['RequiredArgs'].") ".$t['Topic']."</span>");
			echo("<div id='topic".$i."pos' style='position:relative; top:5px; left:35px; ");
			if ($i == $_POST['curTopic'])
				echo("display:block'>");
			else
				echo("display:none'>");
			$positions = getPositions($t['ID']);
			if ($positions) {
				foreach($positions as $p) {
					$j = $p['ID'];
					echo("<span id='position".$j."'>");
					if ($j == $_POST['curPosition'])
						echo("<img src='img/minus-8.png' onclick='expandPosition(".$j.",".$i.")'></span> &nbsp; ");
					else
						echo("<img src='img/plus-8.png' onclick='expandPosition(".$j.",".$i.")'></span> &nbsp; ");
					echo("<a href='javascript:edit(\"position\",".$j.",");
					if (hasReasons($j))
						echo("true");
					else
						echo("false");
					echo(")'  style='font-variant:small-caps; font-size:smaller;'>Edit</a>".
						 " &nbsp; <span id='position".$j."text'>".$p['Position']."</span>");
					echo("<div id='position".$j."reas' style='position:relative; top:5px; left:35px; ");
					if ($j == $_POST['curPosition'])
						echo("display:block'>");
					else
						echo("display:none'>");
					$reasons = getReasons($p['ID'], false);
					if ($reasons) {
						echo("<ul style='margin-top:0; margin-bottom:0; list-style-type:disc;".
							 " list-style-position:outside; position:relative; left:-20px;'>");
						foreach($reasons as $r) {
							$k = $r['ID'];
							echo("<li> &nbsp;<a href='javascript:edit(\"reason\",".$k.",");
							if (hasReasons($k))
								echo("true");
							else
								echo("false");
							echo(")' style='font-variant:small-caps; ".
								 "font-size:smaller;'>Edit</a> &nbsp; <span id='reason".$k."text'>".$r['Reason']."</span></li>");
						}
						echo("</ul><input type='checkbox' name='allowOther".$j."' ");
						if ($p['AllowOther'] == 1)
							echo("CHECKED");
						echo(" onchange='submitForm(".$j.")'> Allow 'Other' Reasons");
					}
					else {
						echo("There are no reasons assigned to this position.<br>");
						echo("<input type='checkbox' name='allowOther".$j."' ");
						if ($p['AllowOther'] == 1)
							echo("CHECKED");
						echo(" onchange='submitForm(".$j.")'> Allow 'Other' Reasons");
					}
					if (count(getReasons($p['ID'], true)) > 0) {
						echo(" &nbsp; <a href='javascript:viewOthers(".$p['ID'].", true)' style='font-variant:small-caps; font-size:smaller'>".
							 "View 'Other' reasons for this position</a>");
					}
					echo("<br><b>New Reason:</b><br><input type='text' id='reasontext".$j."' size=29 > ".
						 "<input type='submit' value='Add' onclick='setupReason(".$j.")'>");			
					echo("</div><br>");
				}
			}
			else
				echo("There are no positions assigned to this topic.<br>");
			echo("<span id='undertopic".$i."'");
			if ($_POST['curPosition'] != 0 && $_POST['curTopic'] == $i)
				echo("style='display:none;'");
			else
				echo("style='display:block;'");
			echo("><b>New Position:</b><br><input type='text' id='positiontext".$i."' size=29 > ".
				 "<input type='submit' value='Add' onclick='setupPosition(".$i.")'></span>");			
			echo("</div><br>");
		}
	}
	else
		echo("There are no topics assigned to this class.<br>");
?>
<br /><b>Enter New Topic and Required Submissions:</b><br />
<input type='text' id='topictext' name='topictext' size=29 /> 
<input type='text' id='requiredargs' name='requiredargs' size=2 style='text-align:center' value=5 /> 
<input type='submit' value='Add' /><br />

<div id='editing' style='position:absolute; display:none; z-index:5; background-color:#FFFFCC;'>
<table border='1'>
<tr><td>
		<input type='hidden' name='tabnum' value='2' />
		<input type='hidden' id='type' name='type' />
		<input type='hidden' id='typeid' name='typeid' />
		<table cellpadding='2px'>
			<tr><td colspan='2';><b>New description:</b></td></tr>
			<tr>
				<td><input type='text' id='newdesc' name='newdesc' /></td>
				<td><input type='text' id='newreqargs' name='newreqargs' size=2 style='text-align:center; display:none' /></td>
			</tr>
			<tr>
				<td><input type='submit' name='editDesc' value='Accept' />
				    <input type='submit' id='removeEdit' name='editDesc' value='Remove' onclick='resetCurrent()'/></td>
				<td><input type='button' id='resetedit' value='Cancel' onclick='closeEdit()' /></td>
			</tr>
		</table>
</td></tr>
</table>
</div>

</form>
</div>

<div id='rosterinfo' style='position:relative; top:5px; left:10px;<? if ($tabnum != 3) echo " display: none" ?>'>
<table cellpadding='6px'>
	<tr>
		<td><input type='button' value='Enroll User' onclick='enrollUser(true)' /></td>
	</tr>
<?
	foreach($roster as $r) {
		echo("<tr><td>");
		echo("<a href='editarticles.php?id=".$r['ID']."&class=$classid&ref=1' style='font-variant:small-caps'>".
			 $r['FirstName']." ".$r['LastName']."</a>");
		echo("<br>Email: <a href='mailto:".$r['Email']."'>".$r['Email']."</a><br>");
		echo("<a href='edituser.php?id=".$r['ID']."&return=editclass.php?id=".$classid."'".
			 " style='font-variant:small-caps;'>Edit</a> - ");
		echo("<a href='javascript:removeUser(".$r['ID'].", true)' ".
			 "style='font-variant:small-caps;'>Remove</a>");
		if ($_SESSION['admin'] < 0) {
			echo(" - <a style='font-variant:small-caps;' href='javascript:setStudentAdmin(".$r['ID']);
			if (hasStudentAdmin($r['ID'], $classid))
				echo(", false)'>Revoke Student Admin</a>");
			else
				echo(", true)'>Grant Student Admin</a>");
		}	
		echo("</td></tr>\n");
	}
?>
</table>
<table id='add' style='float:right; position:absolute; left:10em; top:-2em; 
		   			   display:none; background:#FFFFCC; padding:5px; z-index:2;' 
	   border='1' cellpadding='5px'>
	<tr><td>
		<h3 style='position:relative; left:15px;'>Enroll User</h3>
		<form id='adduserform' name='adduserform' submit='editclass.php?id=<? echo $classid ?>' method='POST' onSubmit='return checkAddUser()'>
		<table>
			<tr>
				<td align='right' style='font-weight:bold;'>First Name:</td>
				<td align='left'><input type='text' id='fname' name='fname' /></td>
				<td align='left'><div id='noname' style='display:none; color:#FF3300'>Name fields required!</div></td>
			</tr>
			<tr>
				<td align='right' style='font-weight:bold;'>Last Name:</td>
				<td align='left'><input type='text' id='lname' name='lname'  /></td>
			</tr>
			<tr>
				<td align='right' style='font-weight:bold;'>Email:</td>
				<td align='left'><input type='text' id='email' name='email'  /></td>
				<td align='left'><div id='noemail' style='display:none; color:#FF3300;'>Invalid email!</div></td>
			</tr>
			<tr>
				<td align='right' style='font-weight:bold;'>Admin:</td>
				<td align='left'>
					<select id='adminlevel' name='adminlevel'>
					<option value='0'>Student</option>
					<option value='-1'>Instructor</option>
					</select></td>
			</tr>
			<tr>
				<td colspan='3' style='font-weight:bold;'><b>Confirm your password to continue.</b></td>
			</tr>
			<tr>
				<td align='right' style='font-weight:bold;'>Password:</td>
				<td align='left'><input type='password' id='adduserpass' name='adduserpass' /></td>
			</tr>
			<tr>
				<td></td>
				<td align='left'><input type='submit' value='Add User' />
								 <input type='reset' value='Cancel' onclick='enrollUser(false)' /></td>
			</tr>
		</table>
		</form>
	</td></tr>

</table>
</div>
<br />
<input type='button' value='View Classes' onclick='goBack()' style='position:relative; left:15px; z-index:1' />
<form id='viewothers' name='viewothers' submit='editclass.php?id=<? echo $classid ?>' method='POST'>
<input type='hidden' id='otherposition' name='otherposition' />
<?
	foreach($topics as $t) {
		$positions = getPositions($t['ID']);
		foreach($positions as $p) {
			$reasons = getReasons($p['ID'], true);
			if (count($reasons) > 0) {
				echo("<table id='others".$p['ID']."' style='float:right; position:absolute; left:12em; top:6em;". 
		   			 "display:none; background:#FFFFCC; z-index:2;' border='1' cellpadding='5px'><tr><td>");
				echo("Select the reasons that can be consolidated and define a new reason to merge into.<br><br>");
				$i = 0;
				foreach($reasons as $r) {
					echo("<input type='checkbox' name='others".$p['ID']."_".$i."' value='".$r['ID']."'> ".$r['Reason']."<br>");
					$i++;
				}
				echo("<br><b>New Reason:</b><br><input type='text' name='other".$p['ID']."new'> <input type='submit' value='Add'>".
					 " <input type='reset' value='Cancel' onclick='viewOthers(".$p['ID'].", false)'></td></tr></table>");
			}
		}
	}
?>
</form>

<div id='removeConfirm' style='position:absolute; z-index:3; display:none; background-color:#FFFFCC;'>
<table border='1'>
<tr><td>
	<form id='deleteconfirm' name='deleteconfirm' submit='editclass.php?id=<? echo $_GET['id']; ?>' method='POST'>
		<table cellpadding='2px'>
			<input type='hidden' id='removeUserID' name='removeUserID' />
			<tr>
				<td colspan='2'><b>Confirm password.</b></td>
			</tr>
			<tr>
				<td align='right' style='font-weight:bold'>Password:</td>
				<td align='left'><input type='password' id='deletepass' name='deletepass' /></td>
			</tr>
			<tr>
				<td></td>
				<td><input type='submit' id='yesremove' name='yesremove' value='Confirm' disabled="disabled" />
				    <input type='reset' value='Cancel' onclick='removeUser(0, false)' /></td>
			</tr>
		</table>
	</form>
</td></tr>
</table>
</div>

<? include("footer.php"); ?>
</html>
