function faq_ask_answer in FAQ_Ask 7
Same name and namespace in other branches
- 6.2 faq_ask.module \faq_ask_answer()
 - 6 faq_ask.module \faq_ask_answer()
 
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.
Parameters
object $node: FAQ node to answer
1 string reference to 'faq_ask_answer'
- faq_ask_menu in ./
faq_ask.module  - Implements hook_menu().
 
File
- ./
faq_ask.module, line 1727  - This module is an add-on to the FAQ module that allows users with the 'ask question' permission to create a question which will be queued for an 'expert' to answer.
 
Code
function faq_ask_answer($node) {
  global $user;
  if ($user->uid == '0') {
    // If user is not logged in
    drupal_goto('user', array(
      'query' => drupal_get_destination(),
    ));
    // Log in first
  }
  // Validate the request.
  if (!isset($_REQUEST['token']) || !_faq_ask_valid_token($_REQUEST['token'], "faq_ask/answer/{$node->nid}")) {
    watchdog('Faq_Ask', 'Received an invalid answer request (@query_string) from @user_ip.', array(
      '@query_string' => $_SERVER['QUERY_STRING'],
      '@user_ip' => $_SERVER['REMOTE_ADDR'],
    ), WATCHDOG_ALERT);
    drupal_access_denied();
    return;
  }
  $reassign_opt = variable_get('faq_ask_expert_own', 0);
  // Check if we need to reassign to the expert.
  switch ($reassign_opt) {
    case 0:
      // Do not reassign.
      break;
    case 1:
      // Reassign if anonymous.
      if ($node->uid == 0) {
        faq_ask_reassign($node);
      }
      break;
    case 2:
      // Always reassign.
      faq_ask_reassign($node);
      break;
  }
  // Change the status to published
  $node = node_load($node->nid);
  $node->status = NODE_PUBLISHED;
  node_save($node);
  // Need to invoke node/##/edit.
  drupal_goto("node/{$node->nid}/edit");
}