You are here

function domain_batch_form_submit in Domain Access 6.2

Same name and namespace in other branches
  1. 5 domain_admin.inc \domain_batch_form_submit()
  2. 7.3 domain.admin.inc \domain_batch_form_submit()
  3. 7.2 domain.admin.inc \domain_batch_form_submit()

FormsAPI for saving batch form actions.

1 call to domain_batch_form_submit()
domain_settings_batch_form_submit in domain_settings/domain_settings.module
Submit handler for batch domain settings.

File

./domain.admin.inc, line 973
Administration functions for the domain module.

Code

function domain_batch_form_submit($form, &$form_state) {
  if (!empty($form_state['values']['batch_override'])) {
    foreach ($form_state['values']['domain_batch'] as $domain_id => $value) {
      $options_all[$domain_id] = $form_state['values']['batch_all_setting'];
    }
    $form_state['values']['domain_batch'] = $options_all;
  }
  $item = $form_state['values']['batch_item'];
  switch ($form_state['values']['handler']) {
    case 'domain':
      foreach ($form_state['values']['domain_batch'] as $key => $value) {

        // Note that $type in the query below is a sanitzed value passed from domain_batch_data_type().
        db_query("UPDATE {domain} SET %s = " . domain_batch_data_type($form_state['values']['data_type']) . " WHERE domain_id = %d", $item, $value, $key);

        // Update the variable for the root domain
        if (!empty($form_state['values']['variable']) && $key == 0) {
          variable_set($form_state['values']['variable'], $value);
        }
      }
      break;
    case 'domain_conf':
      foreach ($form_state['values']['domain_batch'] as $key => $value) {
        $settings = array();
        if ($key > 0 || empty($form_state['values']['variable'])) {
          $data = db_fetch_array(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $key));
          if (isset($data['settings'])) {
            $settings = domain_unserialize($data['settings']);
            $settings[$item] = $value;
            db_query("UPDATE {domain_conf} SET settings = %b WHERE domain_id = %d", serialize($settings), $key);
          }
          else {
            $settings[$item] = $value;
            db_query("INSERT INTO {domain_conf} (domain_id, settings) VALUES (%d, %b)", $key, serialize($settings));
          }
        }
        else {
          if (!empty($form_state['values']['variable'])) {
            variable_set($form_state['values']['variable'], $value);
          }
        }
      }
      break;
    case 'domain_delete':
      $table = $form_state['values']['table'];
      foreach ($form_state['values']['domain_batch'] as $key => $value) {
        if ($value == 1) {
          if (is_array($table)) {
            foreach ($table as $current) {
              db_query("DELETE FROM {%s} WHERE domain_id = %d", $current, $key);
            }
          }
          else {
            db_query("DELETE FROM {%s} WHERE domain_id = %d", $table, $key);
          }
        }
      }
      break;
    case 'custom':
      if (isset($form_state['values']['submit_handler']) && function_exists($form_state['values']['submit_handler'])) {
        $func = $form_state['values']['submit_handler'];
        $func($form_state['values']);
      }
      break;
  }
  drupal_set_message(t('Settings have been updated successfully.'), 'status', FALSE);
}