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;
}
`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';
# --------------------------------------------------------
$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);
}
$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);
}
if (empty($form->deadline)) {
$form->deadline = "";
+ }
+ if (!isset($form->usepassword)) {
+ $form->usepassword = 0;
}
if (empty($form->showleaguetable)) {
$form->showleaguetable = "";
<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>
</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>
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2004062300;
+$module->version = 2004090200;
$module->requires = 2004052505; // Requires this Moodle version
$module->cron = 60;
/****************** 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);