Permalink
Browse files

fixup admin pages

  • Loading branch information...
1 parent 658738b commit e2850d25212dcddd78a75c5e52a6770688b278d4 Kevin Risden committed May 15, 2012
View
@@ -31,8 +31,8 @@
<hr>
<div class="span-4 colborder">
<a href="index.php">Home</a><br />
- <a href="index.php?page=tutors">List Tutors</a><br />
- <a href="index.php?page=add_tutor">Add Tutor</a><br />
+ <a href="index.php?page=tutors">Tutors</a><br />
+ <a href="index.php?page=courses">Courses</a><br />
<a href="index.php?page=help">Help</a>
</div>
<div class="span-18 last">
@@ -0,0 +1,14 @@
+<?php
+require_once("../../course_controller.php");
+require_once("display_admin.php");
+$course = new Course();
+?>
+<div>
+<h3>Add Course</h3>
+<form method="post" action="index.php?page=save_course">
+<input type="hidden" name="type" value="add" />
+<table>
+<?php display_edit_course($course); ?>
+</table>
+</form>
+</div>
@@ -1,6 +1,6 @@
<?php
require_once("../../tutor_controller.php");
-require_once("display_tutors_admin.php");
+require_once("display_admin.php");
$tutor = new Tutor();
?>
<div>
@@ -0,0 +1,8 @@
+<?
+require_once("../../course_controller.php");
+require_once("display_admin.php");
+?>
+<div>
+<h3>Courses - <a href="index.php?page=add_course">Add Course</a></h3>
+<?php display_courses_admin(get_courses_by_crn($mysqli,"","")); ?>
+</div>
@@ -31,4 +31,35 @@ function display_edit_tutor($tutor) {
<tr><td colspan=\"2\" style=\"text-align:center\"><input type=\"submit\" value=\"Save\" /></td></tr>
");
}
+
+function display_courses_admin($courses) {
+ if($courses) {
+ echo("<table>");
+ foreach($courses as $course) {
+ echo("<form method=\"POST\" action=\"index.php?page=save_course\"");
+ echo("<tr>");
+ echo("<td><a href=\"index.php?page=edit_course&amp;course_id=" . $course->CID . "\">Edit</a></td>");
+ echo("<td>" . $course->course_number . "</td>");
+ echo("<td>" . $course->course_description . "</td>");
+ echo("<input type=\"hidden\" name=\"course_id\" value=\"" . $course->CID . "\" />");
+ echo("<input type=\"hidden\" name=\"type\" value=\"delete\" />");
+ echo("<td><input type=\"submit\" value=\"Delete\" /></td>");
+ echo("</tr>");
+ echo("</form>");
+ }
+ echo("</table>");
+ } else {
+ echo("No results found.");
+ }
+}
+
+function display_edit_course($course) {
+ echo("
+ <input type=\"hidden\" name=\"course_id\" value=\"" . $course->CID . "\" />
+ <tr><td>Course Number:</td><td><input type=\"text\" name=\"course_number\" value=\"" . $course->course_number . "\" /></td></tr>
+ <tr><td>Course Description:</td><td><input type=\"text\" name=\"description\" value=\"" . $course->course_description . "\" /></td></tr>
+ <tr><td>Department:</td><td><input type=\"text\" name=\"department\" value=\"" . $course->department . "\" /></td></tr>
+ <tr><td colspan=\"2\" style=\"text-align:center\"><input type=\"submit\" value=\"Save\" /></td></tr>
+ ");
+}
?>
@@ -0,0 +1,17 @@
+<?php
+require_once("../../course_controller.php");
+require_once("display_admin.php");
+if(isset($_GET['course_id']))
+ $course = get_course_by_cid(getDBCon(),$_GET['course_id']);
+if(!isset($course)) die("<h3>Invalid Course Id</h3>");
+?>
+<div>
+<h3>Edit Course - <?php echo($course->course_number); ?></h3>
+<form method="post" action="index.php?page=save_course">
+<input type="hidden" name="type" value="update" />
+<input type="hidden" name="course_id" value="<?php echo($course->CID);?>" />
+<table>
+<?php display_edit_course($course); ?>
+</table>
+</form>
+</div>
@@ -1,6 +1,6 @@
<?php
require_once("../../tutor_controller.php");
-require_once("display_tutors_admin.php");
+require_once("display_admin.php");
if(isset($_GET['tutor_id']))
$tutor = get_tutor_by_id(getDBCon(),$_GET['tutor_id']);
if(!isset($tutor)) die("<h3>Invalid Tutor Id</h3>");
@@ -11,8 +11,39 @@
<input type="hidden" name="type" value="update" />
<input type="hidden" name="username" value="<?php echo($tutor->TID);?>" />
<table>
-<tr><td>Username:</td><td><?php echo($tutor->TID);?></td></tr>
<?php display_edit_tutor($tutor); ?>
</table>
</form>
+<h4>Courses</h4>
+<?php
+$all_courses = get_courses_by_crn($mysqli, "");
+$courses = get_tutor_courses_tutored($mysqli, $tutor->TID);
+?>
+<ul>
+<?php
+foreach($courses as $course) {
+ echo("<li>" . $course->course_number . " <a href=\"\">(X)</a></li>");
+}
+?>
+<select name="courses">
+<option value=""></option>
+<?php
+foreach(array_diff($all_courses,$courses) as $course) {
+ echo("<option value=\"" . $course->CID . "\">" . $course->course_number . "</option>");
+}
+?>
+</select>
+<input type="button" name="add" value="Add" />
+</ul>
+
+<h4>Timeslots</h4>
+<table>
+<tr><td>Time</td><td>Period</td><td>Day</td></tr>
+<?php
+$timeslots = get_tutor_timeslots($mysqli, $tutor->TID);
+foreach($timeslots as $timeslot) {
+ echo("<tr><td>" . $timeslot->Time . "</td><td>" . $timeslot->Period . "</td><td>" . $timeslot->DAYOFWEEK . "</td></tr>");
+}
+?>
+</table>
</div>
@@ -0,0 +1,34 @@
+<?php
+ require_once("../../course_controller.php");
+?>
+<div>
+<?php
+if(isset($_POST['course_number'])
+ && isset($_POST['description'])
+ && isset($_POST['department'])
+ && isset($_POST['course_id'])) {
+ if($_POST['type'] == "add") {
+ $result = add_course($mysqli, $_POST['department'],$_POST['course_number'],$_POST['description']);
+ } else if($_POST['type'] == "update") {
+ $result = update_course($mysqli,$_POST['course_id'],$_POST['department'],$_POST['course_number'], $_POST['description']);
+ } else {
+ $result = null;
+ }
+ if($result) {
+ echo("<h3>Course Saved</h3>");
+ } else {
+ echo("<h3>Course Save Failed</h3>");
+ }
+} else {
+ if($_POST['type'] == "delete") {
+ if(delete_course($mysqli, $_POST['course_id'])) {
+ echo("<h3>Course Deleted</h3>");
+ } else {
+ echo("<h3>Course Delete Failed</h3>");
+ }
+ } else {
+ echo("Invalid Data");
+ }
+}
+?>
+</div>
@@ -1,8 +1,8 @@
<?
require_once("../../tutor_controller.php");
-require_once("display_tutors_admin.php");
+require_once("display_admin.php");
?>
<div>
-<h3>List Tutors</h3>
+<h3>Tutors - <a href="index.php?page=add_tutor">Add Tutor</a></h3>
<?php display_tutors_admin(get_tutors_by_name($mysqli,"","")); ?>
</div>

0 comments on commit e2850d2

Please sign in to comment.