You are here

function faq_ask_settings_form_submit in FAQ_Ask 6

Same name and namespace in other branches
  1. 6.2 faq_ask.module \faq_ask_settings_form_submit()
  2. 7 faq_ask.module \faq_ask_settings_form_submit()

Implementation of hook_form_submit(). It saves the expert roles that were selected, then rebuilds the expert/category table.

File

./faq_ask.module, line 780
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_settings_form_submit($form, &$form_state) {
  $form_values = $form_state['values'];

  // Save the simple stuff.
  if (isset($form_state['values']['faq_expert_role'])) {
    variable_set('faq_expert_role', $form_state['values']['faq_expert_role']);
  }
  if (isset($form_state['values']['faq_ask_vocabularies'])) {
    variable_set('faq_ask_vocabularies', $form_state['values']['faq_ask_vocabularies']);
  }
  variable_set('faq_ask_title_len', $form_state['values']['faq_ask_title_len']);
  variable_set('faq_ask_categorize', $form_state['values']['faq_ask_categorize']);
  variable_set('faq_ask_expert_own', $form_state['values']['faq_ask_expert_own']);
  variable_set('faq_ask_suggest', $form_state['values']['faq_ask_suggest']);
  variable_set('faq_ask_notify', $form_state['values']['faq_ask_notify']);
  variable_set('faq_ask_default_expert', $form_state['values']['faq_ask_default_expert']);
  variable_set('faq_ask_expert_advice', $form_state['values']['faq_ask_expert_advice']);
  variable_set('faq_ask_help_text', $form_state['values']['faq_ask_help_text']);
  variable_set('faq_ask_admin_advice', $form_state['values']['faq_ask_admin_advice']);
  variable_set('faq_ask_asker_advice', $form_state['values']['faq_ask_asker_advice']);

  // Get all the selected expert/category options.
  // First, we'll include the default expert for tid=0.
  $values = array(
    '(' . $form_state['values']['faq_ask_default_expert'] . ', 0)',
  );
  foreach ($form_values as $name => $value) {
    if (substr($name, 0, 7) == 'expert_') {
      list($junk, $uid, $tid) = explode('_', $name);
      if ($value) {
        $values[] = '(' . $uid . ', ' . $tid . ')';
      }
    }
  }
  $vals = implode(', ', $values);

  // Delete the current values and save the new ones.
  if (!empty($values)) {
    db_query('TRUNCATE {faq_expert}');
    db_query("INSERT INTO {faq_expert} (uid, tid) VALUES %s", $vals);
  }
  drupal_set_message(t('Configuration has been updated.'), 'status');
}