Index: quiz.install
===================================================================
RCS file: /xampp/htdocs/drupal/dev/quiz/quiz.install,v
retrieving revision 1.1
diff -u -r1.1 quiz.install
--- quiz.install	24 Jul 2008 16:34:07 -0000	1.1
+++ quiz.install	24 Jul 2008 20:58:12 -0000
@@ -33,8 +33,8 @@
         'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
         'number_of_random_questions' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
         'pass_rate' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE),
-        'summary_pass' => array('type' => 'text', 'size' => 'long'),
-        'summary_default' => array('type' => 'text', 'size' => 'long'),
+        'summary_pass' => array('type' => 'text', 'length' => 65535),
+        'summary_default' => array('type' => 'text', 'length' => 65535),
         'shuffle' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE),
         'backwards_navigation' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE),
         'feedback_time' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE),
@@ -45,10 +45,7 @@
         'quiz_always' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
         'tid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
       ),
-      'indexes' => array(
-        'vid' =>  array('vid', 'nid'),
-      ),
-      'primary key' => 'property_id',
+      'primary key' => array('property_id'),
     );
 
   /**
@@ -100,7 +97,7 @@
         'released' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0),
         'score' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
       ),
-      'primary key' => 'result_id',
+      'primary key' => array('result_id'),
     );
 
   /**
@@ -127,13 +124,15 @@
         'option_id' => array('type' => 'serial', 'size' => 'normal', 'unsigned' => TRUE, 'not null' => TRUE),
         'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
         'vid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
-        'option_name' => array('type' => 'varchar', 'not null' => TRUE),
-        'option_summary' => array('type' => 'text', 'size' => 'long'),
+        'option_name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE),
+        'option_summary' => array('type' => 'text', 'length' => 65535),
         'option_start' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0),
         'option_end' => array('type' => 'int', 'unsigned' => TRUE, 'default' => 0),
       ),
-      'primary key' => 'option_id'
+      'primary key' => array('option_id'),
     );
+	
+	return $schema;
 }
 
 /**
Index: quiz.module
===================================================================
RCS file: /xampp/htdocs/drupal/dev/quiz/quiz.module,v
retrieving revision 1.2
diff -u -r1.2 quiz.module
--- quiz.module	24 Jul 2008 16:49:10 -0000	1.2
+++ quiz.module	25 Jul 2008 02:08:57 -0000
@@ -60,8 +60,7 @@
 /**
  * Implementation of hook_access().
  */
-function quiz_access($op, $node) {
-  global $user;
+function quiz_access($op, $node, $account) {
 
   if ($op == 'view') {
     return user_access('access quiz');
@@ -98,93 +97,71 @@
 /**
  * Implementation of hook_menu().
  */
-function quiz_menu($may_cache) {
-  $items = array();
-  if ($may_cache) {
-    $access = user_access(QUIZ_PERM_ADMIN_CONFIG);
-    $items[] = array(
-      'path' => 'admin/settings/quiz',
+function quiz_menu() {
+
+    drupal_add_css(drupal_get_path('module', 'quiz') .'/quiz.css', 'module', 'all');
+
+    $items['admin/settings/quiz'] = array(
       'title' => t('@quiz Configuration', array('@quiz' => QUIZ_NAME)),
       'description' => t('Configure @quiz options.', array('@quiz' => QUIZ_NAME)),
-      'callback' => 'drupal_get_form',
-      'callback arguments' => array('quiz_admin_settings'),
-      'access' => user_access(QUIZ_PERM_ADMIN_CONFIG),
+      'page callback' => 'drupal_get_form',
+      'page arguments' => array('quiz_admin_settings'),
+      'access arguments' => array(QUIZ_PERM_ADMIN_CONFIG),
       'type' => MENU_NORMAL_ITEM, // optional
     );
-
-    $items[] = array(
-      'path' => 'node/add/quiz',
-      'title' => t('@quiz', array('@quiz' => QUIZ_NAME)),
-      'access' => user_access('create quiz'),
-    );
-
-    $items[] = array(
-      'path' => 'admin/quiz/results',
+    $items['admin/quiz/results'] = array(
       'title' => t('@quiz Results', array('@quiz' => QUIZ_NAME)),
-      'callback' => 'quiz_admin',
-      'access' => user_access('administer quiz'),
+      'page callback' => 'quiz_admin',
+      'access arguments' => array('administer quiz'),
       'type' => MENU_NORMAL_ITEM,
     );
-  }
-  else {
-    drupal_add_css(drupal_get_path('module', 'quiz') .'/quiz.css', 'module', 'all');
-    if (arg(0) == 'node' && is_numeric(arg(1))) {
-      $node = node_load(arg(1));
-      if ($node->type == 'quiz') {
-        // Menu item for creating adding questions to quiz.
-        $items[] = array(
-          'path' => 'node/'. arg(1) .'/questions',
-          'title' => t('Manage questions'),
-          'callback' => 'quiz_questions',
-          'access' => user_access('create quiz'),
-          'type' => MENU_LOCAL_TASK,
-        );
-      if (user_access('administer quiz')) {
-          $items[] = array(
-            'path' => 'node/'. arg(1) .'/quiz/admin',
-            'title' => t('Quiz Admin', array('@quiz' => QUIZ_NAME)),
-            'callback' => 'theme_quiz_view',
-            'callback arguments' => array(node_load(arg(1))),
-            'access' => user_access('administer quiz'),
-            'type' => MENU_LOCAL_TASK,
-          );
-        }
-      }
-    }
-    else {
-      $items[] = array(
-        'path' => 'user/'. arg(1) .'/myresults',
-        'title' => t('My Results'),
-        'callback' => 'quiz_get_user_results',
-        'access' => user_access('user results'),
-        'type' => MENU_LOCAL_TASK,
-      );
-
-      $items[] = array(
-        'path' => 'user/quiz/'. arg(2) .'/userresults',
-        'title' => t('User Results'),
-        'callback' => 'quiz_user_results',
-        'access' => user_access('user results'),
-        'type' => MENU_CALLBACK,
-      );
+	
+	$node = node_load(arg(1));
+    if ($node->type == 'quiz') {
+
+    // Menu item for creating adding questions to quiz.
+    $items['node/%/questions'] = array(
+      'title' => t('Manage questions'),
+      'page callback' => 'quiz_questions',
+      'access arguments' => array('create quiz'),
+      'type' => MENU_LOCAL_TASK,
+    );
+    $items['node/%/admin'] = array(
+      'title' => t('Quiz Admin', array('@quiz' => QUIZ_NAME)),
+      'page callback' => 'theme_quiz_view',
+      'page arguments' => array(2),
+      'access arguments' => array('administer quiz'),
+      'type' => MENU_LOCAL_TASK,
+    );
+}
+    $items['user/%/myresults'] = array(
+      'title' => t('My Results'),
+      'page callback' => 'quiz_get_user_results',
+      'access arguments' => array('user results'),
+      'type' => MENU_LOCAL_TASK,
+    );
 
-      $items[] = array(
-        'path' => 'admin/quiz/'. arg(2) .'/view',
-        'title' => t('View @quiz', array('@quiz' => QUIZ_NAME)),
-        'callback' => 'quiz_admin_results',
-        'access' => user_access('administer quiz'),
-        'type' => MENU_CALLBACK,
-      );
-               
-      $items[] = array(
-        'path' => 'admin/quiz/'. arg(2) .'/delete',
-        'title' => t('Delete @quiz', array('@quiz' => QUIZ_NAME)),
-        'callback' => 'quiz_admin_result_delete',
-        'access' => user_access('administer quiz'),
-        'type' => MENU_CALLBACK,
-      );
-    }
-  }
+    $items['user/quiz/%/userresults'] = array(
+      'title' => t('User Results'),
+      'page callback' => 'quiz_user_results',
+      'access arguments' => array('user results'),
+      'type' => MENU_CALLBACK,
+    );
+	  
+    $items['admin/quiz/%/view'] = array(
+      'title' => t('View @quiz', array('@quiz' => QUIZ_NAME)),
+      'page callback' => 'quiz_admin_results',
+      'page arguments' => array(2),	  
+      'access arguments' => array('administer quiz'),
+      'type' => MENU_CALLBACK,
+    );
+	  
+    $items['admin/quiz/%/delete'] = array(
+      'title' => t('Delete @quiz', array('@quiz' => QUIZ_NAME)),
+      'page callback' => 'quiz_admin_result_delete',
+      'access arguments' => array('administer quiz'),
+      'type' => MENU_CALLBACK,
+    );
   return $items;
 }
 
@@ -560,10 +537,10 @@
  */
 function _quiz_insert_result_option($option) {
   if (empty($option['option_id'])) {
-    $option['option_id'] = db_next_id('{quiz_node_result_options}'.'_option_id');
-    $sql = "INSERT INTO {quiz_node_result_options} (nid, vid, option_id, option_name, option_summary, option_start, option_end)".
-           " VALUES(%d, %d, %d, '%s', '%s', %d, %d)";
-    $values = array($option['nid'],
+    $sql = "INSERT INTO {quiz_node_result_options} (nid, vid, option_name, option_summary, option_start, option_end)".
+           " VALUES(%d, %d, '%s', '%s', %d, %d)";
+   $option['option_id'] = db_last_insert_id('{quiz_node_result_options}','option_id');
+   $values = array($option['nid'],
                     $option['vid'],
                     $option['option_id'],
                     $option['option_name'],
@@ -718,8 +695,44 @@
   return $output;
 }
 
+function quiz_theme() {
+  return array(
+    'quiz_availability' => array(
+      'arguments' => array('node' => NULL),
+    ),
+	'quiz_view' => array(
+	  'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE),
+	),
+	'quiz_get_user_results' => array(
+      'arguments' => array('results' => NULL),
+	),
+	'quiz_question_table' => array(
+	  'arguments' => array('questions' => NULL, 'quiz_id' => NULL),
+	),
+	'quiz_take_question' => array(
+	  'arguments' => array('quiz' => NULL, 'question_node' => NULL),
+	),
+	'quiz_admin_summary' => array(
+	  'arguments' => array('quiz' =>NULL, 'questions' => NULL, 'score' =>NULL, 'summary' => NULL),
+	),
+	'quiz_user_summary' => array(
+	  'arguments' => array('quiz' =>NULL, 'questions' => NULL, 'score' =>NULL, 'summary' => NULL),
+	),
+	'quiz_feedback' => array(
+	  'arguments' => array('questions' => NULL, 'showpoints' =>TRUE, 'showfeedback' => FALSE),
+	),
+	'quiz_question_feedback' => array(
+	  'arguments' => array('quiz' => NULL, 'report' => NULL),
+	),
+	'quiz_questions' => array(
+      'arguments' => array('form' => NULL),
+	),	
+	'quiz_no_feedback' => array(),	
+  );
+}
+
 /**
- * Theme the node view for quizzes.
+ * Hook Theme the node view for quizzes.
  * 
  * @ingroup themeable
  */
@@ -774,7 +787,7 @@
   if (function_exists(taxonomy_node_get_terms)) {
     $output .= '<h3>'. t('Taxonomy selection') .'</h3>';
     $terms = array();
-    foreach (taxonomy_node_get_terms($node->nid) as $term) {
+    foreach (taxonomy_node_get_terms($node) as $term) {
       $terms[] = check_plain($term->name);
     }
     if (!empty($terms)) {
@@ -874,15 +887,15 @@
  *  HTML output for page.
  */
 function quiz_take_quiz() {
-  global $user;
-  if (arg(0) == 'node' && is_numeric(arg(1)) && user_access('access quiz')) {
-    if ($quiz = node_load(arg(1))) {
+  if (user_access('access quiz')) {
+    if ($quiz = menu_get_object()) {
+	
       // If anonymous user and no unique hash, refresh with a unique string to prevent caching.
-      if (!$user->uid && arg(4) == NULL) {
+      if (!$quiz->name && arg(4) == NULL) {
         drupal_goto('node/'. $quiz->nid .'/quiz/start/'. md5(mt_rand() . time()));
       }
       if ($user->uid && $quiz->takes != 0) {
-        $times = db_num_rows(db_query("SELECT result_id " .
+        $times = db_result(db_query("SELECT COUNT('result_id') " .
                                       "FROM {quiz_node_results} " .
                                       "WHERE nid = %d AND vid = %d AND uid = %d",
                                       $quiz->nid, $quiz->vid, $user->uid));
@@ -991,8 +1004,8 @@
  * Store a quiz question result.
  */
 function quiz_store_question_result($nid, $vid, $rid, $is_correct) {
-  $result = db_query("SELECT result_id FROM {quiz_node_results_answers} WHERE question_nid = %d AND question_vid = %d AND result_id = %d", $nid, $vid, $rid);
-  if (db_num_rows($result)) {
+  $result = db_query("SELECT COUNT('result_id') FROM {quiz_node_results_answers} WHERE question_nid = %d AND question_vid = %d AND result_id = %d", $nid, $vid, $rid);
+  if ($result) {
     db_query("UPDATE {quiz_node_results_answers} ".
             "SET is_correct = %d, points_awarded = %d, answer_timestamp = %d " . 
             "WHERE question_nid = %d AND question_vid = %d AND result_id = %d",
@@ -1189,11 +1202,12 @@
   }
 
   // Insert quiz_node_results record.
-  $rid = db_next_id('{quiz_node_results}_result_id');
   $result = db_query("INSERT INTO {quiz_node_results} " .
                      "(result_id, nid, vid, uid, time_start) " .
                      "VALUES (%d, %d, %d, %d, %d)", $rid, $quiz->nid, $quiz->vid, $user->uid, time());
-  if ($result) {
+  $rid = db_last_insert_id('{quiz_node_results}', 'result_id');
+
+ if ($result) {
     return $rid;
   }
   else {
@@ -1306,8 +1320,8 @@
 /**
  * Implementation of hook_help().
  */
-function quiz_help($section) {
-  switch ($section) {
+function quiz_help($path, $arg) {
+  switch ($path) {
     case 'admin/help#quiz':
       return t('
 <h3>Description</h3>
@@ -1413,10 +1427,10 @@
     </dl>
   </li>
   <li>Once the quiz has been created, click the <b>add questions</b> tab to assign questions to the quiz.</li>
-  <li>Select a radio button next to each question indicating if the question should appear (Randomly, Always, or Never), and click <strong>Submit questions</strong>.</li>
+  <li>Select a radio button next to each question indicating if the question should appear (Randomly, Always, or Never), and click <strong></strong>.</li>
   <li>Repeat process until satisfied with question selection.</li>
 </ol>
-    ', array('@quiz' => QUIZ_NAME, '@admin-access' => url('admin/user/access'), '@admin-modules' => url('admin/build/modules'), '@admin-taxonomy' => url('admin/content/taxonomy'), '@create-content' => url('node/add'), '@multichoice' => url('node/add/multichoice'), '@create-quiz' => url('node/add/quiz')));
+    ', array('@quiz' => QUIZ_NAME, '@admin-access' => url('admin/user/permissions'), '@admin-modules' => url('admin/build/modules'), '@admin-taxonomy' => url('admin/content/taxonomy'), '@create-content' => url('node/add'), '@multichoice' => url('node/add/multichoice'), '@create-quiz' => url('node/add/quiz')));
     case 'node/add#quiz':
       return t('A collection of questions designed to create interactive tests');
     default:
@@ -1646,13 +1660,13 @@
     '#description' => t('Allow question status changes to create a new revision of the quiz?'),
   );
 
+  $form['timestamp'] = array('#type' => 'hidden', '#value' => time());
+
   $form['submit'] = array(
     '#type' => 'submit',
     '#value' => t('Submit questions'),
   );
 
-  $form['timestamp'] = array('#type' => 'hidden', '#value' => time());
-
   return $form;
 }
 
@@ -1665,7 +1679,7 @@
  *  Array of questions objects.
  */
 function _quiz_get_unused_questions($quiz_vid = NULL, $nid_keys = FALSE) {
-  $quiz       = node_load( (int) arg(1) );
+  $quiz       = menu_get_object();
   $types      = _quiz_get_question_types();
   $where_sql  = '';
   $questions = array();
@@ -1716,40 +1730,39 @@
  * @param $values
  *  Array containing the form values.
  */
-function quiz_questions_form_submit($form_id, $values) {
-  // Load the node.
-  $quiz = node_load(arg(1));
+function quiz_questions_form_submit($form, &$form_state) {
+ 
   // Update quiz with selected question options.
-  if (!quiz_update_questions($values['question_status'], $values['new_revision'])) {
+  if (!quiz_update_questions($form_state['values']['question_status'], $form_state['values']['new_revision'])) {
     form_set_error('', t('Either no questions were selected, or there was a problem updating your @quiz. Please try again.', array('@quiz' => QUIZ_NAME)));
     return;
   }
 
   // Check if selecting random question from pool, and not via term.
-  if (empty($values['random_term_id'])) {
+  if (empty($form_state['values']['random_term_id'])) {
     $assigned_random =0;
-    if (is_array($values['question_status'])) {
-      foreach ($values['question_status'] as $id => $status) {
+    if (is_array($form_state['values']['question_status'])) {
+      foreach ($form_state['values']['question_status'] as $id => $status) {
         if (QUESTION_ALWAYS == $status) {
           $assigned_random++;
         }
       }
     }
 
-    if ($values['num_random_questions'] > $assigned_random) {
-      $values['num_random_questions'] = $assigned_random;
+    if ($form_state['values']['num_random_questions'] > $assigned_random) {
+      $form_state['values']['num_random_questions'] = $assigned_random;
       drupal_set_message(t('The number of random questions for this @quiz have been lowered to %anum to match the number of questions you assigned.', array('@quiz' => QUIZ_NAME, '%anum' => $assigned_random), 'status'));
     }
   }
   else {
     // Warn user if not enough questions available with this term_id.
-    $available_random = count(_quiz_get_random_questions($values['num_random_questions'], $values['random_term_id']));
-    if ($values['num_random_questions'] > $available_random) {
+    $available_random = count(_quiz_get_random_questions($form_state['values']['num_random_questions'], $form_state['values']['random_term_id']));
+    if ($form_state['values']['num_random_questions'] > $available_random) {
       drupal_set_message(t('There are currently not enough questions assigned to this term (@random). Please lower the number of random quetions or assign more questions to this taxonomy term before taking this @quiz.', array('@random' => $available_random, '@quiz' => QUIZ_NAME)), 'error');
     }
   }
 
-  $result = db_query("UPDATE {quiz_node_properties} SET number_of_random_questions = %d, tid = %d WHERE vid = %d AND nid = %d", $values['num_random_questions'], $values['random_term_id'], $quiz->vid, $quiz->nid);
+  $result = db_query("UPDATE {quiz_node_properties} SET number_of_random_questions = %d, tid = %d WHERE vid = %d AND nid = %d", $form_state['values']['num_random_questions'], $form_state['values']['random_term_id'], $quiz->vid, $quiz->nid);
   if (!$result) {
     drupal_set_message(t('There was an error updating the @quiz.', array('@quiz' => QUIZ_NAME)), 'error');
   }
@@ -1770,7 +1783,7 @@
  *  Number of questions that meet the criteria.
  */
 function quiz_get_num_questions($nid, $vid, $type) {
-  return db_num_rows(db_query("SELECT parent_vid FROM {quiz_node_relationship} WHERE parent_vid = %d AND parent_nid = %d AND question_status = %d", $vid, $nid, $type));
+  return db_result(db_query("SELECT COUNT('parent_vid') FROM {quiz_node_relationship} WHERE parent_vid = %d AND parent_nid = %d AND question_status = %d", $vid, $nid, $type));
 }
 
 /**
@@ -1826,7 +1839,8 @@
 
   // Create new revision of current quiz (if any question status has been changed).
   if (!empty($changes)) {
-    drupal_execute('node_form', array('revision' => '1'), $quiz);
+    $rev = array('revision' => '1');
+    drupal_execute('node_form', $rev, $quiz);
     drupal_set_message(t('A new revision of the @quiz has been created.', array('@quiz' => QUIZ_NAME)));
   }
 
@@ -1907,20 +1921,20 @@
 /**
  * Validation of the Form Settings form.
  */
-function quiz_settings_form_validate($form_id, $form_values) {
-  if (!is_numeric($form_values['num_random_questions']) || $form_values['num_random_questions'] <0 ) {
+function quiz_settings_form_validate($form, &$form_state) {
+  if (!is_numeric($form_state['values']['num_random_questions']) || $form_state['values']['num_random_questions'] <0 ) {
     form_set_error('num_random_questions', t('The number of random questions must be at least 0.'));
   }
-  if (!is_numeric($form_values['quiz_default_close']) || $form_values['quiz_default_close'] <= 0) {
+  if (!is_numeric($form_state['values']['quiz_default_close']) || $form_state['values']['quiz_default_close'] <= 0) {
     form_set_error('quiz_default_close', t('The default number of days before a quiz is closed must be a number greater than 0.'));
   }
-  if (!is_numeric($form_values['quiz_default_pass_rate'])) {
+  if (!is_numeric($form_state['values']['quiz_default_pass_rate'])) {
     form_set_error('quiz_default_pass_rate', t('The pass rate value must be a number between 0% and 100%.'));
   }
-  if ($form_values['quiz_default_pass_rate'] > 100) {
+  if ($form_state['values']['quiz_default_pass_rate'] > 100) {
     form_set_error('quiz_default_pass_rate', t('The pass rate value must not be more than 100%.'));
   }
-  if ($form_values['quiz_default_pass_rate'] < 0) {
+  if ($form_state['values']['quiz_default_pass_rate'] < 0) {
     form_set_error('quiz_default_pass_rate', t('The pass rate value must not be less than 0%.'));
   }
 }
@@ -2020,11 +2034,12 @@
                       t('Delete'),
                       t('Cancel'));
 }
-function quiz_admin_result_delete_form_submit($form_id, $form_values) {
-  db_query("DELETE FROM {quiz_node_results} WHERE result_id = %d", $form_values['del_rid']);
-  db_query("DELETE FROM {quiz_node_results_answers} WHERE result_id = %d", $form_values['del_rid']);
+function quiz_admin_result_delete_form_submit($form, &$form_state) {
+  db_query("DELETE FROM {quiz_node_results} WHERE result_id = %d", $form_state['values']['del_rid']);
+  db_query("DELETE FROM {quiz_node_results_answers} WHERE result_id = %d", $form_state['values']['del_rid']);
   drupal_set_message(t('Deleted result.'));
-  return "admin/quiz/results";
+  $form_state['redirect'] = 'admin/quiz/results';
+  $form_state['nid'] = $node->nid;  
 }
 
 function _quiz_get_answers($rid) {

