Index: quiz.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quiz/quiz.module,v
retrieving revision 1.110
diff -u -r1.110 quiz.module
--- quiz.module	2 Dec 2007 09:20:31 -0000	1.110
+++ quiz.module	2 Dec 2007 20:48:01 -0000
@@ -238,33 +238,63 @@
     '#options' => _quiz_get_feedback_options(),
     '#description' => t('Indicates at what point feedback for each question will be given to the user'),
   );
-
-  // Set up the availability options.
-  $form['quiz_availability'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Availability options'),
-    '#collapsed' => FALSE,
-    '#collapsible' => TRUE,
-  );
-  $form['quiz_availability']['quiz_always'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Always Available'),
-    '#default_value' => $node->quiz_always,
-    '#description' => t('Click this option to ignore the open and close dates.'),
-  );
-  $form['quiz_availability']['quiz_open'] = array(
-    '#type' => 'date',
-    '#title' => t('Open Date'),
-    '#default_value' => _quiz_form_prepare_date($node->quiz_open),
-    '#description' => t('The date this @quiz will become available.', array('@quiz' => QUIZ_NAME)),
-  );
-  $form['quiz_availability']['quiz_close'] = array(
-    '#type' => 'date',
-    '#title' => t('Close Date'),
-    '#default_value' => _quiz_form_prepare_date($node->quiz_close, variable_get('quiz_default_close', 30)),
-    '#description' => t('The date this @quiz will cease to be available.', array('@quiz' => QUIZ_NAME)),
-  );
-
+  $quiz_disable_vuln = variable_get('quiz_disable_availablity', 'no');
+  if ( $quiz_disable_vuln == 'timeavail') {
+    $form['quiz_availability']['quiz_always'] = array(
+      '#type' => 'hidden',
+      '#value' => 1,
+    );
+    $date_prepare =_quiz_form_prepare_date();
+    $date = $date_prepare['day'] . $date_prepare['month'] . $date_prepare['year'];
+    $form['quiz_availability']['quiz_open'] = array(
+      '#type' => 'hidden',
+      '#value' => $date,
+    );
+    $form['quiz_availability']['quiz_close'] = array(
+      '#type' => 'hidden',
+      '#value' => $date,
+    );
+  }
+  else {
+    // Set up the availability options
+    $form['quiz_availability'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Availability options'),
+      '#collapsed' => FALSE,
+      '#collapsible' => TRUE,
+    );
+    // If always available is disabled
+    if ( $quiz_disable_vuln == 'alwaysavail') {
+      $form['quiz_availability']['quiz_always'] = array(
+        '#type' => 'hidden',
+        '#value' => 0,
+      );
+      $req_open_close = TRUE; //require quiz->open/close true if always available disabled
+    }
+    else {
+      $form['quiz_availability']['quiz_always'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Always Available'),
+        '#default_value' => (isset($node->quiz_always) ? $node->quiz_always : variable_get('quiz_default_always_available', 0)),
+        '#description' => t('Click this option to ignore the open and close dates.'),
+      );
+      $req_open_close = FALSE;
+    }
+    $form['quiz_availability']['quiz_open'] = array(
+      '#type' => 'date',
+      '#title' => t('Open Date'),
+      '#default_value' => _quiz_form_prepare_date($node->quiz_open),
+      '#description' => t('The date this @quiz will become available.', array('@quiz' => QUIZ_NAME)),
+      '#required' => $req_open_close,
+    );
+    $form['quiz_availability']['quiz_close'] = array(
+      '#type' => 'date',
+      '#title' => t('Close Date'),
+      '#default_value' => _quiz_form_prepare_date($node->quiz_close, variable_get('quiz_default_close', 30)),
+      '#description' => t('The date this @quiz will cease to be available.', array('@quiz' => QUIZ_NAME)),
+      '#required' => $req_open_close,
+    );
+  }
   $options = array(t('Unlimited'));
   for ($i = 1; $i < 10; $i++) {
     $options[$i] = $i;
@@ -1865,31 +1895,83 @@
  */
 function quiz_admin_settings() {
   $form = array();
-  // Option to globally turn off pass/fail form elements.
-  $form['quiz_default_close'] = array(
+  $form['quiz_name'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Assessment name'),
+    '#default_value' => QUIZ_NAME,
+    '#size' => 15,
+    '#description' => t('How do you want to refer to quizzes across the site (for example: Quiz, Test, Assessment).  This will affect display text but will not affect menu paths.'), 
+    '#required' => TRUE,
+  );
+  $form['quiz_availability'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('@quiz Availability Options', array('@quiz' => QUIZ_NAME)),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  $form['quiz_availability']['quiz_disable_availablity'] = array(
+    '#type' => 'select',
+    '#title' => t('Disable @quiz availability options.', array('@quiz' => QUIZ_NAME)),
+    '#default_value' => variable_get('quiz_disable_availablity', 'no'),
+    '#description' => t('Disables associated elements on the @quiz. If closing and starting times are disabled, always available defaults to true. This will not effect already created quizzes until they are edited.', array('@quiz' => QUIZ_NAME)),
+    '#options' => array(
+      'no' => t('Don\'t Disable Anything'),
+      'alwaysavail' => t('Disable Always Available'),
+      'timeavail' => t('Disable starting and closing times.'),
+    ), 
+  );
+  // extra code for disabling availability options
+  switch (variable_get('quiz_disable_availablity', 'no')) {
+    case 'timeavail':
+      $default_value = 1;
+      $disable_aa = TRUE;
+      $disable_dc = TRUE;
+      break;
+    case 'alwaysavail':
+      $default_value = 0;
+      break;
+    default:
+      $disable_aa = FALSE;
+      $disable_dc = FALSE;
+      $default_value = variable_get('quiz_default_always_available', 0);
+  }
+ 
+  $form['quiz_availability']['quiz_default_always_available'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Default new @quiz to always available.', array('@quiz' => QUIZ_NAME)),
+    '#default_value' => $default_value,
+    '#disabled' => $disable_aa,
+    '#description' => t('Check this to default new quizzes to always available instead of only available for a period of time.'), 
+  );
+  $form['quiz_availability']['quiz_default_close'] = array(
     '#type' => 'textfield',
     '#title' => t('Default number of days before a @quiz is closed', array('@quiz' => QUIZ_NAME)),
     '#default_value' => variable_get('quiz_default_close', 30),
+    '#disabled' => $disable_dc,
+    '#size' => 5,
     '#description' => t('Supply a number of days to calculate the default close date for new quizzes.'),
   );
-  $form['quiz_use_passfail'] = array(
+  $form['quiz_passfail_options'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('@quiz Pass/Fail Options', array('@quiz' => QUIZ_NAME)),
+    '#collapsible' => TRUE,
+    '#collapsed' => FALSE,
+  );
+  // option to globally turn off pass / fail form elements
+  $form['quiz_passfail_options']['quiz_use_passfail'] = array(
     '#type' => 'checkbox',
     '#title' => t('Display pass/fail options in the @quiz form', array('@quiz' => QUIZ_NAME)),
     '#default_value' => variable_get('quiz_use_passfail', 1),
     '#description' => t('Check this to display the pass/fail options in the @quiz form. If you want to prohibit other quiz creators from changing the default pass/fail percentage set below, uncheck this option.', array('@quiz' => QUIZ_NAME)),
   );
-  $form['quiz_default_pass_rate'] = array(
+  $form['quiz_passfail_options']['quiz_default_pass_rate'] = array(
     '#type' => 'textfield',
     '#title' => t('Default percentage needed to pass a @quiz', array('@quiz' => QUIZ_NAME)),
     '#default_value' => variable_get('quiz_default_pass_rate', 75),
     '#description' => t('Supply a number between 1 and 100 to set as the default percentage correct needed to pass a quiz. Set to 0 if you want to ignore pass/fail summary information by default.'),
-  );
-  $form['quiz_name'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Assessment name'),
-    '#default_value' => QUIZ_NAME,
-    '#description' => t('How do you want to refer to quizzes across the site (for example: quiz, test, assessment).  This will affect display text but will not affect menu paths.'),
-    '#required' => TRUE,
+    '#size' => 3,
+    '#field_suffix' => t('%'),
+    '#description' => t('Supply a number between 1 and 100 to set as the default percentage correct needed to pass a @quiz. Set to 0 if you want to ignore pass/fail summary information by default.', array('@quiz' => QUIZ_NAME)),
   );
   return system_settings_form($form);
 }
