### Eclipse Workspace Patch 1.0 #P vanilla Index: drupal/modules/contrib/quiz/quiz.module =================================================================== RCS file: /cvs/drupal/contributions/modules/quiz/quiz.module,v retrieving revision 1.67 diff -u -r1.67 quiz.module --- drupal/modules/contrib/quiz/quiz.module 11 Oct 2006 15:21:53 -0000 1.67 +++ drupal/modules/contrib/quiz/quiz.module 12 Oct 2006 21:01:41 -0000 @@ -66,6 +66,13 @@ 'path' => 'node/add/quiz', 'title' => t('quiz'), 'access' => user_access('create quizzes')); + + $items[] = array( + 'path' => 'admin/quiz', + 'title' => t('quizzes'), + 'callback' => 'quiz_admin', + 'access' => user_access('administer quizzes'), + 'type' => MENU_NORMAL_ITEM); } else { if (arg(0) == 'node' && is_numeric(arg(1))) { @@ -118,12 +125,7 @@ 'access' => user_access('administer quizzes'), 'type' => MENU_CALLBACK); - $items[] = array( - 'path' => 'admin/quiz', - 'title' => t('quizzes'), - 'callback' => 'quiz_admin', - 'access' => user_access('administer quizzes'), - 'type' => MENU_NORMAL_ITEM); + } } @@ -291,9 +293,34 @@ if (empty($node->body)) { form_set_error('body', t('Description is required.')); } + + // validate the number of questions against the actual questions assigned to this quiz if ($node->number_of_questions < 1) { form_set_error('number_of_questions', t('Number of questions is required and must be a positive number.')); } + else if($node->nid){ + // get the number of each kind of question + $anum_random = quiz_get_num_questions($node->nid, QUESTION_RANDOM); + $anum_always = quiz_get_num_questions($node->nid, QUESTION_ALWAYS); + $anum_total = $anum_always + $anum_random; + if($anum_random > 0){ $anum_always++; } + // format the valid range + if($anum_always != $anum_total){ + $range = theme('placeholder', t('between %low and %high', array('%low' => $anum_always, '%high' => $anum_total))); + } + else { + $range = theme('placeholder', $anum_total); + } + // If there are not enough questions to support this number. + if ($anum_total < $node->number_of_questions) { + form_set_error('number_of_questions', t('You don\'t currently have enough questions assigned to this quiz to support that many questions. Either change the number of questions to %range or %action to this quiz.', array('%range' => $range, '%action' => l(t('add more questions'), 'node/'.$node->nid.'/questions')))); + } + // If there are too many questions for this number. + else if($anum_always > $node->number_of_questions){ + form_set_error('number_of_questions', t('There are too many questions assigned to this quiz to support that low of a number. Either change the number of questions to %range or %link from this quiz.', array('%range' => $range, '%action' => l(t('remove some questions'), 'node/'.$node->nid.'/questions')))); + } + } + if (mktime(0,0,0, $node->open['month'], $node->open['day'], $node->open['year']) > mktime(0,0,0, $node->close['month'], $node->close['day'], $node->close['year'])) { form_set_error('close', t('Close date before open date')); form_set_error('open', t('Open date after close date')); @@ -897,14 +924,6 @@ //BE CAREFUL OF THE $_POST['edit'] ARRAY AS THIS VALUE IS LIABLE TO CHANGE WHEN VOCABS ARE ADDED AND DELETED...IF YOU HAVE MORE THAN ONE VOCAB, MAY GOD HELP YOU!! $_SESSION['quiz_filter'] = $_POST['edit'][4]; } - else if ($_POST['op'] =='Submit questions') { - if (quiz_update_questions($_POST['edit']['question_status'])) { - drupal_set_message("Question sucessfully updated"); - } - else { - drupal_set_message("There was a problem updating the questions...", 'error'); - } - } } if (isset($_SESSION['quiz_filter'])) { @@ -918,6 +937,14 @@ // Set page title drupal_set_title(check_plain($quiz->title)); + + // show the number of questions that this quiz currently has + $form['numberofquestions'] = array( + '#prefix' => '