You are here

function forena_data_settings_save in Forena Reports 7.3

Same name and namespace in other branches
  1. 8 forena_ui/forena.admin.inc \forena_data_settings_save()
  2. 6.2 forena.admin.inc \forena_data_settings_save()
  3. 7.5 forena.admin.inc \forena_data_settings_save()
  4. 7.2 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 1186

Code

function forena_data_settings_save($form, &$form_state) {
  $values = $form_state['values'];
  $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 = :name', array(
    ':name' => $name,
  ));
  if ($result) {
    drupal_set_message(t('Data connection settings saved'));
  }
  if ($repos = $result
    ->fetchObject()) {
    db_update('forena_repositories')
      ->fields(array(
      'title' => $values['title'],
      'enabled' => $values['enabled'],
      'config' => $config_str,
    ))
      ->condition('repository', $name, '=')
      ->execute();
  }
  else {
    $form_state['#redirect'] = 'admin/forena/content/data';
    db_insert('forena_repositories')
      ->fields(array(
      'repository' => $name,
      'title' => $values['title'],
      'enabled' => $values['enabled'],
      'config' => $config_str,
    ))
      ->execute();
  }
  $form_state['redirect'] = 'admin/config/content/forena/data';
}