From: rkingdon Date: Fri, 3 Sep 2004 09:26:17 +0000 (+0000) Subject: Addition of Password option - version 2004090200 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=e10bb9b32795cfd990d9eaa8969ea6678e343252;p=moodle.git Addition of Password option - version 2004090200 --- diff --git a/mod/exercise/db/mysql.php b/mod/exercise/db/mysql.php index 2538b788f7..03e75ffd5a 100644 --- a/mod/exercise/db/mysql.php +++ b/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; } diff --git a/mod/exercise/db/mysql.sql b/mod/exercise/db/mysql.sql index 39fb61f725..def08688c4 100644 --- a/mod/exercise/db/mysql.sql +++ b/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'; # -------------------------------------------------------- diff --git a/mod/exercise/lib.php b/mod/exercise/lib.php index 32c3cb37ab..2068f4d586 100644 --- a/mod/exercise/lib.php +++ b/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); diff --git a/mod/exercise/mod.html b/mod/exercise/mod.html index 52ab0987b0..4f0ed46407 100644 --- a/mod/exercise/mod.html +++ b/mod/exercise/mod.html @@ -27,6 +27,9 @@ } if (empty($form->deadline)) { $form->deadline = ""; + } + if (!isset($form->usepassword)) { + $form->usepassword = 0; } if (empty($form->showleaguetable)) { $form->showleaguetable = ""; @@ -46,6 +49,7 @@ +

:

@@ -126,6 +130,25 @@ + +

:

+ + usepassword, ""); + helpbutton("usepassword", get_string("usepassword", "exercise"), "exercise"); + ?> + + + + +

:

+ + + + + +

:

diff --git a/mod/exercise/version.php b/mod/exercise/version.php index c64fc16831..bf291f84db 100644 --- a/mod/exercise/version.php +++ b/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; diff --git a/mod/exercise/view.php b/mod/exercise/view.php index 4031b102d9..b6718262d9 100644 --- a/mod/exercise/view.php +++ b/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 "
\n"; + echo "id\">\n"; + echo ""; + if (isset($_POST['userpassword'])) { + echo ""; + } + echo ""; + echo ""; + + echo "
".get_string("wrongpassword", "exercise"). + "
".get_string("passwordprotectedexercise", "exercise", $exercise->name). + "
".get_string("enterpassword", "exercise"). + "
"; + echo "id';\"> "; + echo ""; + echo "
"; + 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);