You are here

function elysia_cron_settings_form_submit in Elysia Cron 7

Same name and namespace in other branches
  1. 5.2 elysia_cron.admin.inc \elysia_cron_settings_form_submit()
  2. 5 elysia_cron.admin.inc \elysia_cron_settings_form_submit()
  3. 6.2 elysia_cron.admin.inc \elysia_cron_settings_form_submit()
  4. 6 elysia_cron.admin.inc \elysia_cron_settings_form_submit()
  5. 7.2 elysia_cron.admin.inc \elysia_cron_settings_form_submit()

File

./elysia_cron.admin.inc, line 563

Code

function elysia_cron_settings_form_submit($_dco_form, &$_dco_form_state) {
  extract(_dcf_form_validate($_dco_form, $_dco_form_state));
  $form_values = $form_state['values'];
  $op = isset($form_values['op']) ? $form_values['op'] : '';

  // Exclude unnecessary elements.
  unset($form_values['submit'], $form_values['reset'], $form_values['form_id'], $form_values['op'], $form_values['form_token']);
  $elysia_cron_default_rules = array();
  $rules = explode("\n", $form_values['elysia_cron_default_rules']);
  foreach ($rules as $r) {
    if (trim($r)) {
      $rr = explode("=", $r);
      $elysia_cron_default_rules[trim($rr[1])] = trim($rr[0]);
    }
  }
  variable_set('elysia_cron_default_rules', $elysia_cron_default_rules);
  foreach ($form_values as $key => $value) {
    $value = trim($value);
    if (!preg_match('/^_elysia_cron_([^_]+_[^_]+)_(.*)$/', $key, $r)) {
      if ($op == t('Reset to defaults') || $key != 'cron_safe_threshold' && !$value) {
        variable_del($key);
      }
      elseif ($key != 'elysia_cron_default_rules') {
        if (is_array($value) && isset($form_values['array_filter'])) {
          $value = array_keys(array_filter($value));
        }
        variable_set($key, $value);
      }
    }
    else {
      $nullvalue = $r[1] != 'job_weight' ? !$value : !$value && $value !== '0';

      //dprint($r[1].' '.$r[1].' '.$r[2]);
      if ($op == t('Reset to defaults') || $nullvalue) {
        switch ($r[1]) {
          case 'job_channel':
            elysia_cron_reset_job_channel($r[2]);
            break;
          case 'job_rule':
            elysia_cron_reset_job_rule($r[2]);
            break;
          case 'job_weight':
            elysia_cron_reset_job_weight($r[2]);
            break;
          case 'job_disabled':
            elysia_cron_reset_job_disabled($r[2]);
            break;
          case 'ch_disabled':
            elysia_cron_reset_channel_disabled($r[2]);
            break;
          case 'ch_rule':
            elysia_cron_reset_channel_rule($r[2]);
            break;
        }
      }
      else {
        switch ($r[1]) {
          case 'job_channel':
            elysia_cron_set_job_channel($r[2], $value);
            break;
          case 'job_rule':
            if ($form_values['_elysia_cron_seljob_rule_' . $r[2]] == 'custom') {
              elysia_cron_set_job_rule($r[2], $value);
            }
            break;
          case 'seljob_rule':
            if ($value != 'custom') {
              if ($value == 'default') {
                elysia_cron_reset_job_rule($r[2]);
              }
              else {
                elysia_cron_set_job_rule($r[2], $value);
              }
            }
            break;
          case 'job_weight':
            elysia_cron_set_job_weight($r[2], $value);
            break;
          case 'job_disabled':
            elysia_cron_set_job_disabled($r[2], $value);
            break;
          case 'ch_disabled':
            elysia_cron_set_channel_disabled($r[2], $value);
            break;
          case 'ch_rule':
            elysia_cron_set_channel_rule($r[2], $value);
            break;
        }
      }
    }
  }
  if ($op == t('Reset to defaults')) {
    drupal_set_message(t('The configuration options have been reset to their default values.'));
  }
  else {
    drupal_set_message(t('The configuration options have been saved.'));
  }
}