You are here

function forena_data_settings_save in Forena Reports 6.2

Same name and namespace in other branches
  1. 8 forena_ui/forena.admin.inc \forena_data_settings_save()
  2. 7.5 forena.admin.inc \forena_data_settings_save()
  3. 7.2 forena.admin.inc \forena_data_settings_save()
  4. 7.3 forena.admin.inc \forena_data_settings_save()
  5. 7.4 forena.admin.inc \forena_data_settings_save()

Submit handler to cause save events to happen. Enter description here ...

1 string reference to 'forena_data_settings_save'
forena_data_settings_edit in ./forena.admin.inc

File

./forena.admin.inc, line 1338

Code

function forena_data_settings_save($form, &$form_state) {
  $values = $form_state['values'];
  foreach ($form['connection'] as $key => $element) {
    if ($element['#disabled']) {
      $values['connection'][$key] = $element['#default_value'];
    }
  }
  foreach ($form as $key => $element) {
    if ($element['#disabled']) {
      $values[$key] = $element['#default_value'];
    }
  }
  $name = $values['name'];
  $config = $form_state['storage']['config'];
  $config['path'] = @$values['path'];
  $config['data provider'] = $values['data_provider'];
  $config['user callback'] = $values['user_callback'];
  $config['debug'] = $values['debug'];
  if (@$values['connection']['new_password']) {
    $values['connection']['password'] = $values['connection']['new_password'];
  }
  if (isset($values['connection']['new_password'])) {
    unset($values['connection']['new_password']);
  }
  if (is_array(@$values['connection'])) {
    $config = array_merge($config, @$values['connection']);
  }
  if ($values['access_method'] == 'callback') {
    $config['access callback'] = empty($values['access_callback']) ? 'user_access' : $values['access_callback'];
    if (isset($config['access block'])) {
      unset($config['access block']);
    }
  }
  else {
    $config['access block'] = $values['access_block'];
  }
  $config_str = serialize($config);
  $result = db_query("SELECT * FROM {forena_repositories} WHERE repository = '%s'", $name);
  if ($result) {
    drupal_set_message(t('Data connection settings saved'));
  }
  if ($row = db_fetch_object($result)) {
    db_query("UPDATE {forena_repositories} SET title='%s', enabled=%d, config='%s'\n      WHERE repository='%s'", $values['title'], $values['enabled'], $config_str, $name);
  }
  else {
    $form_state['#redirect'] = 'admin/forena/content/data';
    db_query("INSERT INTO {forena_repositories} (repository, title, enabled, config)\n      VALUES ('%s', '%s', %d, '%s')", $name, $values['title'], $values['enabled'], $config_str);
  }
  unset($form_state['storage']);
  $form_state['redirect'] = array(
    'admin/settings/forena/data',
  );
}