You are here

public static function Botcha::submitAdminForm in BOTCHA Spam Prevention 6.2

Same name and namespace in other branches
  1. 6.3 controller/application/botcha.application.controller.inc \Botcha::submitAdminForm()
  2. 7.2 controller/botcha.controller.inc \Botcha::submitAdminForm()
  3. 7.3 controller/application/botcha.application.controller.inc \Botcha::submitAdminForm()
2 calls to Botcha::submitAdminForm()
botcha_forms_form_submit in ./botcha.admin.inc
Submission handler for botcha_forms_form form.
botcha_form_form_submit in ./botcha.admin.inc
Submit handler for botcha_form_form.

File

controller/botcha.controller.inc, line 208
Contains Botcha class.

Class

Botcha
Singleton realization of botcha application.

Code

public static function submitAdminForm($form_name, $form, &$form_state) {
  switch ($form_name) {
    case 'form_edit':
      $form_id = $form_state['values']['botcha_form_id'];
      $enabled = $form_state['values']['botcha_enabled'];
      $rbid = $form_state['values']['botcha_form_recipebook'];
      $operation = $form_state['values']['botcha_operation'];
      $add = $operation == 'add';
      Botcha::getForm($form_id, $add)
        ->setEnabled($enabled)
        ->setRecipebook($rbid)
        ->save();
      switch ($operation) {
        case 'edit':

          // Check if the form was really modified.
          // @todo Refactor in a more general manner.
          $edited = $form['botcha_enabled']['#default_value'] != $form['botcha_enabled']['#value'] || $form['botcha_form_recipebook']['#default_value'] != $form['botcha_form_recipebook']['#value'];
          if ($edited) {
            drupal_set_message(t('Saved BOTCHA form settings for %form_id.', array(
              '%form_id' => $form_id,
            )), 'status');
          }
          break;
        case 'add':
        default:

          // Check if the form was really modified.
          // @todo Refactor in a more general manner.
          $added = $form['botcha_form_id']['#default_value'] != $form['botcha_form_id']['#value'] || $form['botcha_form_recipebook']['#default_value'] != $form['botcha_form_id']['#value'];
          if ($added) {
            drupal_set_message(t('Added BOTCHA form %form_id.', array(
              '%form_id' => $form_id,
            )), 'status');
          }
          break;
      }
      $form_state['redirect'] = Botcha::BOTCHA_ADMIN_PATH . '/form';
      break;
    case 'form_list':
      $forms = $form['botcha_form_protection']['botcha_form_id_overview']['botcha_forms'];
      $form_ids = element_children($forms);
      foreach ($form_ids as $form_id) {

        // @todo Replace this workaround with more beautiful solution.
        $fake_form_state['values'] = array(
          'botcha_form_id' => $form_state['values']['botcha_form_id_overview']['botcha_forms'][$form_id]['botcha_form_id'],
          'botcha_enabled' => $form_state['values']['botcha_form_id_overview']['botcha_forms'][$form_id]['botcha_enabled'],
          'botcha_form_recipebook' => $form_state['values']['botcha_form_id_overview']['botcha_forms'][$form_id]['botcha_form_recipebook'],
          'botcha_operation' => 'edit',
        );
        Botcha::submitAdminForm('form_edit', $forms[$form_id], $fake_form_state);
      }

      // Do what system_settings_form() would do with regular variable fields
      variable_set('botcha_on_captcha_forms', !empty($form_state['values']['botcha_on_captcha_forms']) ? $form_state['values']['botcha_on_captcha_forms'] : FALSE);
      variable_set('botcha_administration_mode', $form_state['values']['botcha_administration_mode']);
      variable_set('botcha_allow_on_admin_pages', $form_state['values']['botcha_allow_on_admin_pages']);
      drupal_set_message(t('The BOTCHA settings were saved.'), 'status');
      break;
  }
}