Finished Edit test, now need to make add test and test assignment

master
rubenwardy 2014-03-08 15:08:56 +00:00
parent 2c8e9a8039
commit 25d5d6e346
7 changed files with 182 additions and 12 deletions

1
.htaccess Normal file
View File

@ -0,0 +1 @@
ErrorDocument 404 /index.php?404=1

View File

@ -1,4 +1,11 @@
<?php
// The root url
$root_url = "http://spell.rubenwardy.kd.io/";
function burl($page){
return $root_url.$page;
}
// Shows the web page to the user, with a title
function showHeader($title){
include("template/header.php");

View File

@ -65,9 +65,9 @@ class Test {
}
// Update each field using the function above
update($this->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);
}
}

View File

@ -4,6 +4,14 @@ require "common/common.php";
auth(AUTH_PUPIL);
showHeader("Dashboard");
if ($_GET['404']==1){
?>
<div style="background:red;color:white;padding:1em;margin:0.5em;margin-bottom:1em;border-radius:2px;">
That's a 404; We could not find that page :/
</div>
<?php
}
?>
<h2>Dashboard</h2>
@ -13,7 +21,7 @@ if ($current_user->isPupil()){
$ass = $current_user->tests();
foreach ($ass as $a){
echo "<tr><td>".$a->test()->title."</td><td class=\"take\"><a href=\"test/take.php?id=".$a->test()->id."\">Take</a></td></tr>";
echo "<tr><td>".$a->test()->title."</td><td class=\"take\"><a href=\"".burl("test/take.php?id=".$a->test()->id)."\">Take</a></td></tr>";
}
}else if ($current_user->isStaff()){
?>
@ -23,10 +31,10 @@ if ($current_user->isPupil()){
</div>
<div class="dashbox_content">
<ul>
<li><a href="users.php?rank=1">Pupils</a></li>
<li><a href="test/?user=<?php echo $current_user->id;?>">My Tests</a></li>
<li><a href="<?php echo burl("users.php?rank=1");?>">Pupils</a></li>
<li><a href="<?php echo burl("test/?user=".$current_user->id);?>">My Tests</a></li>
<?php
echo "\t\t\t<li><a href=\"admin.php\">Admin Tools</a></li>";
echo "\t\t\t<li><a href=\"".burl("admin.php")."\">Admin Tools</a></li>";
?>
</ul>

View File

@ -26,4 +26,9 @@ showHeader("Log in");
Username: <input type="test" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Log in">
<p>
<b>Admin account:</b> aw / pass<br>
<b>Pupil account:</b> to / pass
</p>
</form>

View File

@ -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 "<h1>{$test->title}</h1>\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 :/<br>".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}";
}
?>
<a href="edit.php?id=<?php echo $test->id;?>">Back</a><br>
<fieldset>
<legend>Edit Word</legend>
<form action="edit.php?id=<?php echo $test->id;?>&mode=ew&submit=1&word=<?php echo $word->id;?>" method="POST">
Word: <input type="text" value="<?php echo $word->word;?>" name="word" /><br>
Definition: <input type="text" value="<?php echo $word->def;?>" name="def" /><br>
Nearwords: <input type="text" size="70" value="<?php echo $nw;?>" name="nearword" />
<br /><br />
<input type="submit" value="Save">
</form>
</fieldset>
<?php
}
}else if ($_GET['mode']=="dw" && $_GET['word'] && is_numeric($_GET['word'])){
$word = Word::get($_GET['word']);
if ($word){
if ($_GET['submit']==1){
$handle->query("DELETE FROM word WHERE wordID = ".$word->id) or die("Error deleting words from mysql database :/<br>".mysqli_error($handle));
$handle->query("DELETE FROM nearword WHERE wordID = ".$word->id) or die("Error deleting near words from mysql database :/<br>".mysqli_error($handle));
$handle->query("DELETE FROM wrongword WHERE wordID = ".$word->id) or die("Error deleting wrong word records from mysql database :/<br>".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}";
}
?>
<a href="edit.php?id=<?php echo $test->id;?>">Back</a><br>
<fieldset>
<legend>Delete Word</legend>
<form action="edit.php?id=<?php echo $test->id;?>&mode=dw&submit=1&word=<?php echo $word->id;?>" method="POST">
Are you sure?<br><br>
Word: <?php echo $word->word;?><br>
Definition: <?php echo $word->def;?><br>
Nearwords: <?php echo $nw;?>
<br /><br />
<input type="submit" value="Delete">
</form>
</fieldset>
<?php
}
}else{
?>
<fieldset>
<legend>Test Properties</legend>
Title: <input type="text" value="<?php echo $test->title;?>" />
<form action="edit.php?id=<?php echo $test->id;?>&mode=prop" method="POST">
Title: <input type="text" value="<?php echo $test->title;?>" name="title" />
<br /><br />
<input type="submit" value="Save">
</form>
</fieldset>
<fieldset>
<legend>Add Word</legend>
<form action="edit.php?id=<?php echo $test->id;?>&mode=nw" method="POST">
Word: <input type="text" name="word" /><br>
Definition: <input type="text" name="def" /><br>
Nearwords: <input type="text" size="60" name="nearword" /><br>
<i style="font-size:75%;">(^ Words that get 1/2 marks. Separate using commas)</i>
<br /><br />
<input type="submit" value="Save">
</form>
</fieldset>
<?php
}
?>
<table style="margin-top: 30px;">
<tr><th>Answer</th><th>Definition</th><th>Near words</th><th></th></tr>
<!--<tr><td>Potato</td><td>Not a vegetable</td><td>Potatoe</td><td><a href="edit.php?id=<?php echo $test->id;?>&w=1" class="button">Edit</a> <a class="button">Delete</a></td></tr>-->
<?php
// Output row
function orow($word,$def,$near,$wid){
global $test;
echo "<tr><td style=\"width: 10%;\">$word</td><td style=\"width: 40%;\">$def</td><td style=\"width: 30%;\">$near</td><td><a style=\"width: 20%;\" href=\"edit.php?id={$test->id}&w=$wid\" class=\"button\">Edit</a> <a href=\"edit.php?id={$test->id}&delete_word=$wid\" class=\"button\">Delete</a></td></tr>\n";
echo "<tr><td style=\"width: 10%;\">$word</td><td style=\"width: 40%;\">$def</td><td style=\"width: 30%;\">$near</td><td><a style=\"width: 20%;\" href=\"edit.php?id={$test->id}&mode=ew&word=$wid\" class=\"button\">Edit</a> <a href=\"edit.php?id={$test->id}&mode=dw&word=$wid\" class=\"button\">Delete</a></td></tr>\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);
}
?>
</table>

View File

@ -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("");
}