Index: faq_ask.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/faq_ask/faq_ask.info,v retrieving revision 1.2 diff -u -r1.2 faq_ask.info --- faq_ask.info 5 Jan 2008 03:18:53 -0000 1.2 +++ faq_ask.info 21 Jan 2008 18:04:33 -0000 @@ -2,3 +2,4 @@ name = Faq_Ask description = "Allows an unanswered question 'queue' for the FAQ module." dependencies = faq +core = 6.x Index: faq_ask.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/faq_ask/faq_ask.install,v retrieving revision 1.4 diff -u -r1.4 faq_ask.install --- faq_ask.install 17 Jan 2008 14:36:52 -0000 1.4 +++ faq_ask.install 21 Jan 2008 18:35:11 -0000 @@ -33,29 +33,9 @@ * Implementation of hook_install(). **/ function faq_ask_install() { - // Note: I did not specify defaults here because an insert should fail if a value is not supplied. - switch ($GLOBALS['db_type']) { - case 'mysql': - case 'mysqli': - $result = db_query("CREATE TABLE IF NOT EXISTS {faq_expert} ( - uid INT(10) UNSIGNED NOT NULL, - tid INT(10) UNSIGNED NOT NULL, - PRIMARY KEY (uid, tid), - INDEX tid (tid, uid) - ) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); - break; + $result = drupal_install_schema('faq_ask'); - case 'pgsql': - $result = db_query("CREATE TABLE {faq_expert} ( - uid integer NOT NULL, - tid integer NOT NULL, - PRIMARY KEY (uid, tid) - )"); - db_query("CREATE INDEX {faq_expert}_tid ON {faq_expert} (tid, uid)"); - break; - } - - if ($result) { drupal_set_message(t('faq_ask module installed.')); } + if (count($result) > 0) { drupal_set_message(t('faq_ask module installed.')); } else { drupal_set_message(t('faq_ask table creation failed. Please "uninstall" the module and retry.')); } } @@ -63,7 +43,7 @@ * Implementation of hook_uninstall(). **/ function faq_ask_uninstall() { - db_query('DROP TABLE {faq_expert}'); + drupal_uninstall_schema('faq_ask'); variable_del('faq_expert_role'); variable_del('faq_ask_vocabularies'); Index: faq_ask.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/faq_ask/faq_ask.module,v retrieving revision 1.17 diff -u -r1.17 faq_ask.module --- faq_ask.module 10 Jan 2008 18:15:38 -0000 1.17 +++ faq_ask.module 21 Jan 2008 19:50:31 -0000 @@ -53,55 +53,59 @@ } /** + * Determines whether the current user has one of the given permissions. + */ +function faq_ask_user_access_or($string1, $string2) { + return user_access($string1) || user_access($string2); +} + +/** * Implementation of hook_menu() */ -function faq_ask_menu($may_cache) { +function faq_ask_menu() { $items = array(); - if ($may_cache) { - $items[] = array( - 'path' => 'admin/settings/faq/ask', - 'title' => t('Experts'), - 'callback' => 'drupal_get_form', - 'callback arguments' => array('faq_ask_settings_form'), - 'access' => user_access('administer faq'), - 'description' => t('Allows the user to configure the Ask_FAQ module.'), - 'type' => MENU_LOCAL_TASK, - 'weight' => -2, - ); + $items['admin/settings/faq/ask'] = array( + 'title' => t('Experts'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('faq_ask_settings_form'), + 'access arguments' => array('administer faq'), + 'description' => t('Allows the user to configure the Ask_FAQ module.'), + 'type' => MENU_LOCAL_TASK, + 'weight' => -2, + ); - $items[] = array( - 'path' => 'faq_ask', - 'title' => t('Ask a question'), - 'callback' => 'faq_ask_page', - 'access' => user_access('ask question'), - ); - } - else { - $items[] = array( - 'path' => 'faq_ask/answer', - 'title' => t('Answer a question'), - 'callback' => 'faq_ask_answer', - 'access' => user_access('answer question'), - 'type' => MENU_CALLBACK, - ); - - $items[] = array( - 'path' => 'faq_ask/edit', - 'title' => t('Edit a question'), - 'callback' => 'faq_ask_edit', - 'access' => user_access('answer question'), - 'type' => MENU_CALLBACK, - ); - - $items[] = array( - 'path' => 'faq_ask/more', - 'title' => t('List more unanswered questions'), - 'callback' => 'faq_ask_list_more', - 'access' => user_access('answer question') || user_access('ask question'), - 'type' => MENU_CALLBACK, - ); - } + $items['faq_ask'] = array( + 'title' => t('Ask a question'), + 'page callback' => 'faq_ask_page', + 'access callback' => 'user_access', + 'access arguments ' => array('ask question'), + 'weight' => 1, + ); + + $items['faq_ask/answer/%node'] = array( + 'title' => t('Answer a question'), + 'page callback' => 'faq_ask_answer', + 'page arguments' => array(2), + 'access arguments' => array('answer question'), + 'type' => MENU_CALLBACK, + ); + + $items['faq_ask/edit/%node'] = array( + 'title' => t('Edit a question'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('faq_ask_form', null, 2), + 'access arguments' => array('answer question'), + 'type' => MENU_CALLBACK, + ); + + $items['faq_ask/more'] = array( + 'title' => t('List more unanswered questions'), + 'page callback' => 'faq_ask_list_more', + 'access callback' => 'faq_ask_user_access_or', + 'access arguments' => array('answer question', 'ask question'), + 'type' => MENU_CALLBACK, + ); return $items; } @@ -125,25 +129,17 @@ } /** - * Get the edit question form. - */ -function faq_ask_edit($nid = null) { - $form = drupal_get_form('faq_ask_form', null, $nid); - return $form; -} - -/** * Implementation of hook_form() * This is the "ask question" form. */ -function faq_ask_form($tid, $nid, $form_values = null) { +function faq_ask_form($tid, $node, $form_values = null) { $form = array(); - + // We will allow term suggestions only if the setting is chosen // AND there is a vocabulary named "FAQ." $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE name='FAQ' LIMIT 1")); $suggest = variable_get('faq_ask_suggest', false) && $vid; - + if ($suggest) { $cat_list[0] = t(''); $form['#multistep'] = true; @@ -172,13 +168,14 @@ } // If a nid exists, then get the existing values. - if ($nid) { - $node = node_load($nid); + if ($node) { + $nid = $node->nid; $title = $node->title; $taxo = array_keys($node->taxonomy); $default_tid = $taxo[0]; } else { + $nid = null; $default_tid = $tid; $title = null; } @@ -240,9 +237,10 @@ * Implementation of hook_form_submit. * This function gets the entered question and category and creates an unpublished FAQ node. */ -function faq_ask_form_submit($form_id, $form_values) { +function faq_ask_form_submit($form, &$form_state) { global $user; - + $form_values = $form_state['values']; + $category = $form_values['category']; if ($category == 0 && empty($form_values['new_cat'])) { // Can only be 0 if allowing category suggestion. @@ -271,11 +269,12 @@ 'taxonomy' => array($category => $term), 'created' => time(), 'uid' => $user->uid, + 'name' => $user->name, 'status' => 0, /* Unpublished. */ 'format' => 1, /* Default filter (filtered HTML) */ 'comment' => variable_get('comment_faq', 0), ); - + $node_options = variable_get('node_options_'. $node['type'], array('status', 'promote')); foreach (array('promote', 'sticky', 'revision') as $key) { $node[$key] = in_array($key, $node_options) ? 1 : 0; @@ -286,7 +285,7 @@ // Okay, let's get it done. Node_submit will prepare it and make it an object. $node = node_submit($node); node_save($node); - + // Are we notifying the expert(s)? if (variable_get('faq_ask_notify', false)) { // Find out who the experts are. @@ -311,7 +310,7 @@ // The URLs in the following are contructed as absolute addresses. $body .= '

'. t('In order to answer it you will first need to login to the site.', array('!url' => url('user', null, null, true))); $body .= '
'. t('Once logged in, you may proceed directly to the question to answer it.', array('!url' => url('faq_ask/answer/'. $node->nid, null, null, true))); - + $mail_sent = drupal_mail('expert-notify', $to, 'You have a question waiting', $body, $from, $header); if ($mail_sent) { watchdog('FAQ_Ask', t('Expert notification email sent.') .' '. $to, WATCHDOG_NOTICE); @@ -354,7 +353,7 @@ } else { $msg = null; } drupal_set_message(t('Your question has been submitted.') .' '. $msg, 'notice'); - + drupal_goto('faq/'. $category); } } @@ -363,7 +362,7 @@ * Implementation of hook_form. * This form allows the users to select the expert roles and to which categories the users in those roles are assigned. * Note, the expert/category table attempts to use the least horizontal space, - * so it can "flip" based on whether there are more categories or experts. + * so it can "flip" based on whether there are more categories or experts. */ function faq_ask_settings_form($op = null, $aid = null) { $form = array(); @@ -402,6 +401,7 @@ if (count($vocabs) == 1) { // Single vocabulary, don't bother with a selection box, just set it. $vid = key($vocabs); + $def_vid = $vid; variable_set('faq_ask_vocabularies', array($vid => $vid)); $vobj = $vocabs[$vid]; $free = $vobj->tags; @@ -484,7 +484,7 @@ // Put them in alphabetical order. asort($faq_expert_names); } - + if (!empty($role_list)) { $form['faq_expert_role'] = array( '#type' => 'select', @@ -501,7 +501,7 @@ // If there is only one eligible expert, we might as well preset all categories. $expert_msg = null; $only_one_expert = (count($faq_expert_names) == 1); - + $count = 0; if ($more_experts_than_terms) { // Experts go down the left; terms go across the top. @@ -526,11 +526,11 @@ '#suffix' => '', ); $top = null; - $left = null; + $left = null; } - $form[$box_name]['#suffix'] .= ''; + $form[$box_name]['#suffix'] .= ''; } - $form[$box_name]['#suffix'] .= ''; + $form[$box_name]['#suffix'] .= ''; } else { // Experts go across the top; terms go down the left. @@ -552,11 +552,11 @@ '#suffix' => '', ); $top = null; - $left = null; + $left = null; } - $form[$box_name]['#suffix'] .= ''; + $form[$box_name]['#suffix'] .= ''; } - $form[$box_name]['#suffix'] .= ''; + $form[$box_name]['#suffix'] .= ''; } $result = db_query("SELECT * FROM {faq_expert}"); while ($expert = db_fetch_array($result)) { @@ -583,7 +583,7 @@ '#description' => t('The selected user will be assigned as the expert for all terms that are added to the selected vocabularies until you return to this page and update it.'), '#default_value' => variable_get('faq_ask_default_expert', 1), ); - } + } $form['save']['update'] = array( '#type' => 'submit', @@ -598,10 +598,15 @@ * Implementation of hook_form_submit. * It saves the expert roles that were selected, then rebuilds the expert/category table. */ -function faq_ask_settings_form_submit($form_id, $form_values) { +function faq_ask_settings_form_submit($form, &$form_state) { + $form_values = $form_state['values']; // Save the simple stuff. - variable_set('faq_expert_role', $form_values['faq_expert_role']); - variable_set('faq_ask_vocabularies', $form_values['faq_ask_vocabularies']); + if (isset($form_values['faq_expert_role'])) { + variable_set('faq_expert_role', $form_values['faq_expert_role']); + } + if (isset($form_values['faq_ask_vocabularies'])) { + variable_set('faq_ask_vocabularies', $form_values['faq_ask_vocabularies']); + } variable_set('faq_ask_title_len', $form_values['faq_ask_title_len']); variable_set('faq_ask_suggest', $form_values['faq_ask_suggest']); variable_set('faq_ask_notify', $form_values['faq_ask_notify']); @@ -632,12 +637,12 @@ * This function is called when an expert selects a question to answer. * It changes the status option to "published" then goes to the regular FAQ edit function. */ -function faq_ask_answer($nid) { +function faq_ask_answer($node) { // Change the status to published. - db_query("UPDATE {node} SET status=1 WHERE nid=%d", $nid); - + db_query("UPDATE {node} SET status=1 WHERE nid=%d", $node->nid); + // Need to invoke node/##/edit. - drupal_goto('node/'. $nid .'/edit'); + drupal_goto('node/'. $node->nid .'/edit'); } /** @@ -670,14 +675,14 @@ } } break; - + case 'vocabulary': // New vocabulary created. It will not show on the ask page until the user // goes to the settings page, so we don't need to do anything. break; } // End insert switch type. break; - + case 'delete': switch ($type) { case 'term': @@ -686,7 +691,7 @@ _faq_ask_delete_expert($array['tid'], $array['name']); } break; - + case 'vocabulary': // Each term gets deleted first, so all we have to do is remove it from our vocab list. if ($our_vocab) { @@ -695,7 +700,7 @@ break; } // End delete switch type. break; - + case 'update': // Two cases for vocabulary: // 1) FAQ is added to the vocab. -- see insert comment. @@ -705,7 +710,7 @@ case 'term': // Term update: nothing to do. break; - + case 'vocabulary': if (in_array('faq', $array['nodes'])) { // If it's there now, we're done. @@ -728,7 +733,7 @@ default: drupal_set_message(t('Faq_ask_taxonomy: Unknown op (@op) encountered', array('@op' => $op)), 'warning'); - + } // End switch $op } @@ -775,7 +780,7 @@ * * @param: none. * - * @return: + * @return: * vocabulary object from taxonomy module, or a boolean false if no faq nodes were found. */ function faq_ask_get_vocabulary() { @@ -844,12 +849,12 @@ global $user; // Bounce anonymous users. if ($user->uid == 0) { return null; } - + // What permissions does this user have? $can_edit = user_access('administer faq') || user_access('administer nodes'); $is_expert = user_access('answer question'); $only_own = user_access('edit own faq'); - + $mode = 'edit'; $extra_msg = null; @@ -878,11 +883,11 @@ $result = db_query("SELECT title, nid FROM {node} n $join WHERE n.type='faq' AND n.status=0 AND n.uid=%d ORDER BY n.created ASC", $user->uid); } } - + // Get unpublished nodes that are type='faq'. Stop at the limit given. $items = array(); $i = 0; - + while ($node = db_fetch_array($result)) { ++$i; if ($i > $limit) { @@ -912,14 +917,14 @@ } else { $output = null; } $output .= '
'; - + // What permissions does this user have? $can_edit = user_access('administer faq') || user_access('administer nodes'); $is_expert = user_access('answer question'); $only_own = user_access('edit own faq'); - + $mode = 'edit'; - + if ($can_edit) { $result = db_query("SELECT n.title, n.nid, tn.tid FROM {node} n JOIN {term_node} tn USING (nid) WHERE n.type='faq' AND n.status=0 ORDER BY tn.tid ASC, created ASC", $terms); } @@ -931,7 +936,7 @@ while ($expert = db_fetch_array($result)) { $terms[] = $expert['tid']; } - + // Check if this expert has any categories. if (count($terms) == 0) { return '

'. t("For some strange reason, I couldn't find any categories for you.") .'

'; @@ -944,11 +949,11 @@ $result = db_query("SELECT n.title, n.nid, tn.tid FROM {node} n JOIN {term_node} tn USING (nid) WHERE n.type='faq' AND n.status=0 AND n.uid=%d ORDER BY tn.tid ASC, created ASC", $user->uid); } } - + // Get unpublished nodes that are type='faq'. $items = array(); $prev_cat = -1; - + while ($node = db_fetch_array($result)) { $tid = $node['tid']; if ($prev_cat == $tid) {