From 25d5d6e346b66fdd9dafd68db3a7b81aeed2b121 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Sat, 8 Mar 2014 15:08:56 +0000 Subject: [PATCH] Finished Edit test, now need to make add test and test assignment --- .htaccess | 1 + common/common.php | 7 ++ common/database/test.php | 6 +- index.php | 16 +++- login.php | 5 ++ test/edit.php | 157 ++++++++++++++++++++++++++++++++++++++- test/take.php | 2 +- 7 files changed, 182 insertions(+), 12 deletions(-) create mode 100644 .htaccess diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..51f292b --- /dev/null +++ b/.htaccess @@ -0,0 +1 @@ +ErrorDocument 404 /index.php?404=1 \ No newline at end of file diff --git a/common/common.php b/common/common.php index c0363f9..0152600 100644 --- a/common/common.php +++ b/common/common.php @@ -1,4 +1,11 @@ id,"title",$this->username,false); - update($this->id,"userID",$this->firstname,true); - update($this->id,"datecreated",$this->surname,false); + update($this->id,"title",$this->title,false); + update($this->id,"userID",$this->userID,true); + update($this->id,"datecreated",$this->datecreated,false); } } diff --git a/index.php b/index.php index 4067597..0557c2a 100644 --- a/index.php +++ b/index.php @@ -4,6 +4,14 @@ require "common/common.php"; auth(AUTH_PUPIL); showHeader("Dashboard"); + +if ($_GET['404']==1){ +?> +
+ That's a 404; We could not find that page :/ +
+

Dashboard

@@ -13,7 +21,7 @@ if ($current_user->isPupil()){ $ass = $current_user->tests(); foreach ($ass as $a){ - echo "".$a->test()->title."test()->id."\">Take"; + echo "".$a->test()->title."test()->id)."\">Take"; } }else if ($current_user->isStaff()){ ?> @@ -23,10 +31,10 @@ if ($current_user->isPupil()){
diff --git a/login.php b/login.php index 5bb734f..5c93e2c 100644 --- a/login.php +++ b/login.php @@ -26,4 +26,9 @@ showHeader("Log in"); Username:
Password:
+ +

+ Admin account: aw / pass
+ Pupil account: to / pass +

diff --git a/test/edit.php b/test/edit.php index cf6e58d..9b73385 100644 --- a/test/edit.php +++ b/test/edit.php @@ -11,36 +11,185 @@ if (!$test){ msgscrn("Test not found.","We were unable to find that test.","",""); } +// Perform event callbacks +if ($_GET['mode']=="prop" && isset($_POST['title']) && $_POST['title']!=""){ + // Change the test's properties + $test->title = $_POST['title']; + $test->save(); + header("location: edit.php?id={$test->id}"); + die(""); +}else if ( + $_GET['mode']=="nw" && + isset($_POST['word']) && + isset($_POST['def'])&& + $_POST['word']!="" && + $_POST['def']!="" + ){ + // Add a new word + $w = new Word(null); + $w->testID = $test->id; + $w->word = $_POST['word']; + $w->def = $_POST['def']; + $w->save(); + + // Split near word field into elements + $nws = explode(',', $_POST['nearword']); + foreach ($nws as $nw){ + $nearword_word = trim($nw); + if ($nearword_word){ + $nearword = new Nearword(null); + $nearword->wordID = $w->id; + $nearword->word = $nearword_word; + $nearword->save(); + } + } + + header("location: edit.php?id={$test->id}"); + die(""); +} + // Show test player page showHeader("Edit - {$test->title}"); echo "

{$test->title}

\n"; +// Gets the mode, and validates the type of the word id given (should be integer) +if ($_GET['mode']=="ew" && $_GET['word'] && is_numeric($_GET['word'])){ + $word = Word::get($_GET['word']); + if ($word){ + if ($_GET['submit']==1 && + isset($_POST['word']) && $_POST['word']!="" && + isset($_POST['def']) && $_POST['def']!="" && + isset($_POST['nearword'])){ + // Update word + $word->word = $_POST['word']; + $word->def = $_POST['def']; + $word->save(); + $handle->query("DELETE FROM nearword WHERE wordID = ".$word->id) or die("Error deleting near words from mysql database :/
".mysqli_error($handle)); + + // Split near word field into elements + $nws = explode(',', $_POST['nearword']); + foreach ($nws as $nw){ + $nearword_word = trim($nw); + if ($nearword_word){ + $nearword = new Nearword(null); + $nearword->wordID = $word->id; + $nearword->word = $nearword_word; + $nearword->save(); + } + } + + header("location: edit.php?id={$test->id}"); + die(""); + } + $nw = ""; + $list = $word->nearwords(); + foreach ($list as $n){ + // Add near word to list + $nw .= (($nw=="")?"":", ")."{$n->word}"; + } +?> +Back
+
+Edit Word +
+Word:
+Definition:
+Nearwords: + +

+ + +
+
+query("DELETE FROM word WHERE wordID = ".$word->id) or die("Error deleting words from mysql database :/
".mysqli_error($handle)); + $handle->query("DELETE FROM nearword WHERE wordID = ".$word->id) or die("Error deleting near words from mysql database :/
".mysqli_error($handle)); + $handle->query("DELETE FROM wrongword WHERE wordID = ".$word->id) or die("Error deleting wrong word records from mysql database :/
".mysqli_error($handle)); + header("location: edit.php?id={$test->id}"); + die(""); + } + $nw = ""; + $list = $word->nearwords(); + foreach ($list as $n){ + // Add near word to list + $nw .= (($nw=="")?"":", ")."{$n->word}"; + } + ?> +Back
+
+Delete Word + +
+Are you sure?

+Word: word;?>
+Definition: def;?>
+Nearwords: + +

+ + +
+
+
Test Properties -Title: +
+Title:

+
+
+Add Word + +
+Word:
+Definition:
+Nearwords:
+(^ Words that get 1/2 marks. Separate using commas) + +

+ + +
+
+ + + -\n"; + echo "\n"; } $words = $test->words(); foreach ($words as $w){ - orow($w->word,$w->def,"",$w->id); + $nw = ""; + $list = $w->nearwords(); + foreach ($list as $n){ + // Add near word to list + $nw .= (($nw=="")?"":", ")."{$n->word}"; + } + orow($w->word,$w->def,$nw,$w->id); } ?>
AnswerDefinitionNear words
$word$def$nearid}&w=$wid\" class=\"button\">Edit id}&delete_word=$wid\" class=\"button\">Delete
$word$def$nearid}&mode=ew&word=$wid\" class=\"button\">Edit id}&mode=dw&word=$wid\" class=\"button\">Delete
\ No newline at end of file diff --git a/test/take.php b/test/take.php index b743639..a9fcc3c 100644 --- a/test/take.php +++ b/test/take.php @@ -58,7 +58,7 @@ if ($_POST['submitted']=="true"){ $scores->score = $count; $scores->save(); - header("location: test.php?id={$test->id}&user={$current_user->id}"); + header("location: view.php?id={$test->id}&user={$current_user->id}"); die(""); }