You are here

function faq_ask_answer in FAQ_Ask 6.2

Same name and namespace in other branches
  1. 6 faq_ask.module \faq_ask_answer()
  2. 7 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.

1 string reference to 'faq_ask_answer'
faq_ask_menu in ./faq_ask.module
Implementation of hook_menu().

File

./faq_ask.module, line 1279
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;

  // 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 and the user id, if needed.
  $options = variable_get('node_options_faq', array(
    'status',
    'promote',
  ));
  if (in_array('status', $options) || isset($_REQUEST['forced']) && $_REQUEST['forced'] == TRUE) {
    db_query("UPDATE {node} SET status=1, uid=%d WHERE nid=%d", $node->uid, $node->nid);
    $node->status = 1;
  }
  if (!in_array('status', $options) && $node->status == '1') {

    // If this is default NOT published AND node published
    // Need to display published node.
    drupal_goto("node/{$node->nid}");
  }

  // Need to invoke node/##/edit.
  drupal_goto("node/{$node->nid}/edit");
}