Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Addition of Password option - version 2004090200

  • Loading branch information...
commit e10bb9b32795cfd990d9eaa8969ea6678e343252 1 parent a5e3c82
rkingdon authored
View
5 mod/exercise/db/mysql.php
@@ -25,6 +25,11 @@ function exercise_upgrade($oldversion) {
execute_sql("ALTER TABLE `{$CFG->prefix}exercise` DROP COLUMN `gradingweight`");
}
+ if ($oldversion < 2004090200) {
+ table_column("exercise", "", "usepassword", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL");
+ table_column("exercise", "", "password", "VARCHAR", "32", "", "", "NOT NULL");
+ }
+
return true;
}
View
2  mod/exercise/db/mysql.sql
@@ -18,6 +18,8 @@ CREATE TABLE `prefix_exercise` (
`grade` tinyint(3) NOT NULL default '0',
`gradinggrade` tinyint(3) NOT NULL default '0',
`showleaguetable` tinyint(3) unsigned NOT NULL default '0',
+ `usepassword` tinyint(3) unsigned NOT NULL default '0',
+ `password` varchar(32) NOT NULL default '',
PRIMARY KEY (`id`)
) COMMENT='Defines exercise';
# --------------------------------------------------------
View
14 mod/exercise/lib.php
@@ -60,6 +60,13 @@ function exercise_add_instance($exercise) {
$exercise->deadlinemonth, $exercise->deadlineday, $exercise->deadlinehour,
$exercise->deadlineminute);
+ // encode password if necessary
+ if (!empty($exercise->password)) {
+ $exercise->password = md5($exercise->password);
+ } else {
+ unset($exercise->password);
+ }
+
return insert_record("exercise", $exercise);
}
@@ -429,6 +436,13 @@ function exercise_update_instance($exercise) {
$exercise->deadlinemonth, $exercise->deadlineday, $exercise->deadlinehour,
$exercise->deadlineminute);
+ // encode password if necessary
+ if (!empty($exercise->password)) {
+ $exercise->password = md5($exercise->password);
+ } else {
+ unset($exercise->password);
+ }
+
$exercise->id = $exercise->instance;
return update_record("exercise", $exercise);
View
23 mod/exercise/mod.html
@@ -28,6 +28,9 @@
if (empty($form->deadline)) {
$form->deadline = "";
}
+ if (!isset($form->usepassword)) {
+ $form->usepassword = 0;
+ }
if (empty($form->showleaguetable)) {
$form->showleaguetable = "";
}
@@ -46,6 +49,7 @@
<input type="text" name="name" size=60 value="<?php p($form->name) ?>">
</td>
</tr>
+
<tr valign=top>
<td align=right><P><B><?php print_string("description", "exercise") ?>:</B></P></TD>
<td>
@@ -126,6 +130,25 @@
</td>
</tr>
+<tr>
+ <td align=right><p><b><?php print_string("usepassword", "exercise"); ?>:</b></p></td>
+ <td>
+ <?PHP
+ $options[0] = get_string("no"); $options[1] = get_string("yes");
+ choose_from_menu($options, "usepassword", $form->usepassword, "");
+ helpbutton("usepassword", get_string("usepassword", "exercise"), "exercise");
+ ?>
+ </td>
+</tr>
+
+<tr>
+ <td align=right><p><b><?php print_string("password"); ?>:</b></p></td>
+ <td>
+ <input type="text" name="password" size=10 value=""> <?php echo " (".get_string("leavetokeep").")"; ?>
+ <?php helpbutton("password", get_string("password"), "exercise"); ?>
+ </td>
+</tr>
+
<tr valign=top>
<td align=right><p><b><?php print_string("maximumsize", "exercise") ?>:</b></p></td>
<td>
View
2  mod/exercise/version.php
@@ -5,7 +5,7 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2004062300;
+$module->version = 2004090200;
$module->requires = 2004052505; // Requires this Moodle version
$module->cron = 60;
View
38 mod/exercise/view.php
@@ -236,7 +236,43 @@
/****************** student's view could be in 1 of 3 stages ***********************/
elseif ($action == 'studentsview') {
exercise_print_assignment_info($exercise);
- // in Stage 1 - the student must make an assessment (linked to the teacher's exercise/submission
+ // is a password needed?
+ if ($exercise->usepassword) {
+ $correctpass = false;
+ if (isset($_POST['userpassword'])) {
+ if ($exercise->password == md5(trim($_POST['userpassword']))) {
+ $USER->exerciseloggedin[$exercise->id] = true;
+ $correctpass = true;
+ }
+ } elseif (isset($USER->exerciseloggedin[$exercise->id])) {
+ $correctpass = true;
+ }
+
+ if (!$correctpass) {
+ print_simple_box_start("center");
+ echo "<form name=\"password\" method=\"post\" action=\"view.php\">\n";
+ echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+ echo "<table cellpadding=\"7px\">";
+ if (isset($_POST['userpassword'])) {
+ echo "<tr align=\"center\" style='color:#DF041E;'><td>".get_string("wrongpassword", "exercise").
+ "</td></tr>";
+ }
+ echo "<tr align=\"center\"><td>".get_string("passwordprotectedexercise", "exercise", $exercise->name).
+ "</td></tr>";
+ echo "<tr align=\"center\"><td>".get_string("enterpassword", "exercise").
+ " <input type=\"password\" name=\"userpassword\"></td></tr>";
+
+ echo "<tr align=\"center\"><td>";
+ echo "<input type=\"button\" value=\"".get_string("cancel").
+ "\" onclick=\"parent.location='../../course/view.php?id=$course->id';\"> ";
+ echo "<input type=\"button\" value=\"".get_string("continue").
+ "\" onclick=\"document.password.submit();\">";
+ echo "</td></tr></table>";
+ print_simple_box_end();
+ exit();
+ }
+ }
+ // in Stage 1 - the student must make an assessment (linked to the teacher's exercise/submission
if (!exercise_test_user_assessments($exercise, $USER)) {
print_heading(get_string("pleaseviewtheexercise", "exercise", $course->teacher));
exercise_list_teacher_submissions($exercise, $USER);
Please sign in to comment.
Something went wrong with that request. Please try again.