You are here

function faq_ask_settings_form_submit in FAQ_Ask 7

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

Implements hook_form_submit().

It saves the expert roles that were selected, then rebuilds the expert/category table.

1 string reference to 'faq_ask_settings_form_submit'
faq_ask_settings_form in ./faq_ask.module
Implements hook_form().

File

./faq_ask.module, line 1665
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_category_field', $form_state['values']['faq_category_field']);
  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_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_asker_mailchimp_lid', $form_state['values']['faq_ask_notify_asker_mailchimp']);
  variable_set('faq_ask_notify_asker_mailchimp_confirm', $form_state['values']['faq_ask_notify_asker_mailchimp_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();
  $values[] = array(
    'uid' => $form_state['values']['faq_ask_default_expert'],
    'tid' => 0,
  );
  foreach ($form_state['values'] as $name => $value) {
    if (substr($name, 0, 7) == 'expert_') {
      if ($value) {
        list($junk, $uid, $tid) = explode('_', $name);
        $values[] = array(
          'uid' => $uid,
          'tid' => $tid,
        );
      }
    }
  }

  // Delete the current values and save the new ones.
  if (!empty($values)) {
    db_delete('faq_expert')
      ->execute();
    $db_query = db_insert('faq_expert')
      ->fields(array(
      'uid',
      'tid',
    ));
    foreach ($values as $pair) {
      $db_query
        ->values($pair);
    }
    $db_query
      ->execute();
  }
  drupal_set_message(t('Configuration has been updated.'), 'status');
}