]> git.mjollnir.org Git - moodle.git/commitdiff
Addition of Password option - version 2004090200
authorrkingdon <rkingdon>
Fri, 3 Sep 2004 09:26:17 +0000 (09:26 +0000)
committerrkingdon <rkingdon>
Fri, 3 Sep 2004 09:26:17 +0000 (09:26 +0000)
mod/exercise/db/mysql.php
mod/exercise/db/mysql.sql
mod/exercise/lib.php
mod/exercise/mod.html
mod/exercise/version.php
mod/exercise/view.php

index 2538b788f775a8948ce0691be94bdbafb426d9d7..03e75ffd5a89a44074dc4418e4eea7c40a13227e 100644 (file)
@@ -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;
 }
 
index 39fb61f7257e7d1ad73e6b2a26e21ef6b40ea366..def08688c42e0ae5d643e3bf8e532f4943fe2141 100644 (file)
@@ -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';
 # --------------------------------------------------------
index 32c3cb37ab420b1c9e185e76c87dc506f439814b..2068f4d586c7f23a7fa04fd5aa774110b52bdae9 100644 (file)
@@ -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);
index 52ab0987b02c2b7cb0e9c5c192a450d793ef81fc..4f0ed4640711981411fcfbf96a11c75052a0cb56 100644 (file)
@@ -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 @@
         <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>
index c64fc16831a421ec5ab84992ddf1ef94ab4fea55..bf291f84db2bb2008c1c78f31cf7575d5118f22a 100644 (file)
@@ -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;
 
index 4031b102d9b74b7e5d44233540b8d57c6eccfe61..b6718262d990c49375ebcf4438954d988b97d2f0 100644 (file)
     /****************** 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);