You are here

function domain_batch_form_submit in Domain Access 5

Same name and namespace in other branches
  1. 6.2 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

File

./domain_admin.inc, line 948
Administration functions for the domain module.

Code

function domain_batch_form_submit($form_id, $form_values) {

  # drupal_set_message(t('Form submitted'));
  $item = $form_values['batch_item'];
  $type = $form_values['data_type'];
  $variable = $form_values['variable'];
  $table = $form_values['table'];
  switch ($form_values['handler']) {
    case 'domain':
      foreach ($form_values['domain_batch'] as $key => $value) {
        if ($key > 0) {
          db_query("UPDATE {domain} SET %s = " . domain_batch_data_type($type) . "WHERE domain_id = %d", $item, $value, $key);
        }
        else {
          if (!empty($variable)) {
            variable_set($variable, $value);
          }
        }
      }
      break;
    case 'domain_conf':
      foreach ($form_values['domain_batch'] as $key => $value) {
        $settings = array();
        if ($key > 0 || empty($variable)) {
          $data = db_fetch_array(db_query("SELECT settings FROM {domain_conf} WHERE domain_id = %d", $key));
          if (isset($data['settings'])) {
            $settings = 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($variable)) {
            variable_set($variable, $value);
          }
        }
      }
      break;
    case 'domain_delete':
      foreach ($form_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 (function_exists($form_values['submit_handler'])) {
        $func = $form_values['submit_handler'];
        $func($form_values);
      }
      break;
  }

  // Clear the cache.
  cache_clear_all();
  drupal_set_message(t('Settings have been updated successfully.'));
}