You are here

function faq_ask_settings_form_submit in FAQ_Ask 6.2

Same name and namespace in other branches
  1. 6 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 1227
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) {

  // 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_categorize', $form_state['values']['faq_ask_categorize']);
  variable_set('faq_ask_compact_limit', $form_state['values']['faq_ask_compact_limit']);
  variable_set('faq_ask_expert_own', $form_state['values']['faq_ask_expert_own']);
  variable_set('faq_ask_notify', $form_state['values']['faq_ask_notify']);
  variable_set('faq_ask_notify_asker', $form_state['values']['faq_ask_asker_notify']);
  variable_set('faq_ask_asker_notify_indication', $form_state['values']['faq_ask_asker_notify_indication']);
  variable_set('faq_ask_notify_asker_simplenews_tid', $form_state['values']['faq_ask_notify_asker_simplenews']);
  variable_set('faq_ask_notify_asker_simplenews_confirm', $form_state['values']['faq_ask_notify_asker_simplenews_confirm']);
  variable_set('faq_ask_notify_by_cron', $form_state['values']['faq_ask_asker_notify_cron']);
  variable_set('faq_ask_unanswered', $form_state['values']['faq_ask_unanswered']);
  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_state['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}');

    // Issue #1559240 by stenjo: Saving experts on multi-lingual sites
    // Issue #1828148 by Andriy Podranetskyy (apodran): Wrong use of db_rewrite_sql in the code
    db_query("INSERT INTO {faq_expert} (uid, tid) VALUES " . $vals, 'fe', 'uid');
  }
  drupal_set_message(t('Configuration has been updated.'), 'status');
}