http://atutor.ca/atutor/mantis/view.php?id=3093
authorjoel kronenberg <joel.kronenberg@utoronto.ca>
Mon, 9 Jul 2007 20:37:55 +0000 (20:37 -0000)
committerjoel kronenberg <joel.kronenberg@utoronto.ca>
Mon, 9 Jul 2007 20:37:55 +0000 (20:37 -0000)
docs/include/lib/test_result_functions.inc.php
docs/tools/tests/edit_test.php

index 7389ea5..e39759b 100644 (file)
 if (!defined('AT_INCLUDE_PATH')) { exit; }
 
 // $num_questions must be greater than or equal to $row_required['cnt'] + $row_optional['cnt']
-function get_total_weight($tid, $num_questions) {
+function get_total_weight($tid, $num_questions = null) {
        global $db;
        $sql = "SELECT SUM(weight) AS weight, required, COUNT(*) AS cnt FROM ".TABLE_PREFIX."tests_questions_assoc WHERE test_id=$tid GROUP BY required ORDER BY required DESC";
        $result = mysql_query($sql, $db);
        $row_required = mysql_fetch_assoc($result);
        $row_optional = mysql_fetch_assoc($result);
 
-       $total_weight = $row_required['weight'] + ($row_optional['weight'] / $row_optional['cnt']) * min($num_questions - $row_required['cnt'], $row_optional['cnt']);
+       if ($num_questions == null) {
+               $total_weight = $row_required['weight'] + $row_optional['weight'];
+       } else {
+               $total_weight = $row_required['weight'] + ($row_optional['weight'] / $row_optional['cnt']) * min($num_questions - $row_required['cnt'], $row_optional['cnt']);
+       }
 
        return $total_weight;
 }
index 0c140d9..881f08d 100644 (file)
@@ -15,6 +15,7 @@
 $page = 'tests';
 define('AT_INCLUDE_PATH', '../../include/');
 require(AT_INCLUDE_PATH.'vitals.inc.php');
+require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
 
 authenticate(AT_PRIV_TESTS);
 
@@ -32,7 +33,7 @@ if (isset($_POST['cancel'])) {
        $_POST['num_questions']         = intval($_POST['num_questions']);
        $_POST['num_takes']                     = intval($_POST['num_takes']);
        $_POST['anonymous']                     = intval($_POST['anonymous']);
-       $_POST['allow_guests'] = $_POST['allow_guests'] ? 1 : 0;
+       $_POST['allow_guests']      = $_POST['allow_guests'] ? 1 : 0;
        $_POST['instructions']      = $addslashes($_POST['instructions']);
 
        /* this doesn't actually get used: */
@@ -121,7 +122,13 @@ if (isset($_POST['cancel'])) {
                $result = mysql_query($sql, $db);
 
                if ($row = mysql_fetch_assoc($result)) {
-                       $sql = "UPDATE ".TABLE_PREFIX."tests SET title='$_POST[title]', format=$_POST[format], start_date='$start_date', end_date='$end_date', randomize_order=$_POST[randomize_order], num_questions=$_POST[num_questions], instructions='$_POST[instructions]', content_id=$_POST[content_id],  result_release=$_POST[result_release], random=$_POST[random], difficulty=$_POST[difficulty], num_takes=$_POST[num_takes], anonymous=$_POST[anonymous], guests=$_POST[allow_guests] WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
+                       if ($_POST['random']) {
+                               $total_weight = get_total_weight($tid, $_POST['num_questions']);
+                       } else {
+                               $total_weight = get_total_weight($tid);
+                       }
+
+                       $sql = "UPDATE ".TABLE_PREFIX."tests SET title='$_POST[title]', format=$_POST[format], start_date='$start_date', end_date='$end_date', randomize_order=$_POST[randomize_order], num_questions=$_POST[num_questions], instructions='$_POST[instructions]', content_id=$_POST[content_id],  result_release=$_POST[result_release], random=$_POST[random], difficulty=$_POST[difficulty], num_takes=$_POST[num_takes], anonymous=$_POST[anonymous], guests=$_POST[allow_guests], out_of=$total_weight WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
                        $result = mysql_query($sql, $db);
 
                        $sql = "DELETE FROM ".TABLE_PREFIX."tests_groups WHERE test_id=$tid";