You are here

function brb_admin_settings_submit in Browser Bouncer (brb) 7

Submit function

File

./brb.admin.inc, line 164
Administrative page callbacks for the BrB module.

Code

function brb_admin_settings_submit($form, &$form_state) {
  $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
  if ($op == t('Reset to defaults')) {
    brb_restore();
    drupal_set_message(t('The configuration options have been reset to their default values.'));
  }
  else {

    // Save IE conditional
    variable_set('brb_ie_conditional', $form_state['values']["brb_ie_conditional"]);

    // Save overlay
    variable_set('brb_overlay', $form_state['values']["brb_overlay"]);

    // Save browser list
    $browsers = variable_get('brb_browsers', array());
    foreach ($form_state['values'] as $key => $data) {

      //update url elements
      if (substr($key, 0, 3) == 'url') {

        //cunningly we have the DB id of the row in the element name
        $id = str_replace('url-', '', $key);
        $browsers[$id]->url = $data;
      }

      //update exclude elements
      if (substr($key, 0, 7) == 'exclude') {

        //cunningly we have the DB id of the row in the element name
        $id = str_replace('exclude-', '', $key);
        $browsers[$id]->exclude = $data;
      }

      //update weight elements
      if (substr($key, 0, 6) == 'weight') {

        //cunningly we have the DB id of the row in the element name
        $id = str_replace('weight-', '', $key);
        $browsers[$id]->weight = $data;
      }
    }
    variable_set('brb_browsers', $browsers);

    // Save title
    variable_set('brb_title', $form_state['values']["brb_title"]);

    // Save body
    variable_set('brb_body', $form_state['values']["brb_body"]);
    drupal_set_message(t('The configuration options have been saved.'));
  }

  //optionally set the redirect value in form_submit ...
}