You are here

function forena_data_settings_edit in Forena Reports 6.2

Same name and namespace in other branches
  1. 8 forena_ui/forena.admin.inc \forena_data_settings_edit()
  2. 7.5 forena.admin.inc \forena_data_settings_edit()
  3. 7.2 forena.admin.inc \forena_data_settings_edit()
  4. 7.3 forena.admin.inc \forena_data_settings_edit()
  5. 7.4 forena.admin.inc \forena_data_settings_edit()
1 string reference to 'forena_data_settings_edit'
forena_menu in ./forena.module
Implementation of hook_menu.

File

./forena.admin.inc, line 1049

Code

function forena_data_settings_edit(&$form_state, $source = -1) {
  $adding = $source === -1;
  if (!@$form_state['storage']) {
    if ($adding) {
      $form_state['storage'] = array(
        'name' => '',
        'title' => '',
        'path' => '',
        'config' => array(
          'source' => 'user',
          'data provider' => 'FrxDrupal',
          'access callback' => 'user_access',
          'user callback' => 'forena_current_user_id',
        ),
      );
    }
    else {
      $repos = FrxReportGenerator::instance()->app
        ->repositories();
      $r = $repos[$source];
      $load = FrxReportGenerator::instance()
        ->repository($source);

      // Remove teh object from the data.
      unset($load['data']);
      $form_state['storage'] = array(
        'name' => $source,
        'title' => $r['title'],
        'path' => @$r['path'],
        'config' => $load,
      );
    }
  }
  $data = $form_state['storage'];
  $config = $data['config'];
  $locked = !($adding || @$config['source'] == 'user');
  $values = @$form_state['values'];
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('Machine readable name.  Used in referencing all data used by this source. must should not contain any special characters or spaces.'),
    '#disabled' => !$adding,
    '#default_value' => $data['name'],
    '#required' => $adding,
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#required' => TRUE,
    '#description' => t('Human readable name that describes the data source.  This primarily occurs in error messages where the data source cannot be accessed.'),
    '#default_value' => $data['title'],
  );
  $form['enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enabled'),
    '#description' => t('Disabling will cause all queries to return no data.'),
    '#default_value' => @$data['enabled'] !== 0,
  );
  $form['debug'] = array(
    '#type' => 'checkbox',
    '#title' => t('Debug'),
    '#description' => t('Write information to the screen and logs for each query executed.'),
    '#default_value' => @$config['debug'],
  );
  $form['path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path'),
    '#required' => !$locked,
    '#disabled' => $locked,
    '#description' => t('Directory containing data block files.'),
    '#default_value' => @$data['path'],
  );
  $user_options = array(
    '' => 'None',
    'forena_current_user_id' => 'UID',
    'forena_current_user_name' => 'User name',
  );
  $form['user_callback'] = array(
    '#type' => 'select',
    '#title' => 'Current user',
    '#disabled' => $locked,
    '#description' => t('Can be refererenced as :current_user in each data block.'),
    '#options' => $user_options,
    '#default_value' => @$config['user callback'],
    '#disabled' => $locked,
  );

  // Access method list
  $access = array(
    'callback' => t('Use drupal permissions'),
    'block' => t('Match values provided by a data block. '),
  );
  $form['access_method'] = array(
    '#type' => 'select',
    '#options' => $access,
    '#disabled' => $locked,
    '#title' => t('Data security method'),
    '#default_value' => empty($config['access block']) ? 'callback' : 'block',
    '#description' => t('Specify how the ACCESS defined for a data block is to be interpreted. '),
    '#ahah' => array(
      'path' => 'admin/settings/forena/js/access_details',
      'event' => 'change',
      'method' => 'replace',
      'wrapper' => 'access-details',
    ),
  );
  $form['access_details'] = array(
    '#type' => 'fieldset',
    '#prefix' => '<div id="access-details">',
    '#suffix' => '</div>',
    '#title' => t('Details'),
  );
  switch (!empty($values['access_method']) ? $values['access_method'] : $form['access_method']['#default_value']) {
    case 'block':
      $form['access_details']['access_block'] = array(
        '#type' => 'textfield',
        '#title' => 'Data block providing permissions list',
        '#disabled' => $locked,
        //       '#autocomplete_path' => 'forena/data_block/autocomplete',
        '#description' => t('The datablock to be used to interpret permissions.  This should return a single column of permissions based on the current user.   May be provided by another repository.'),
        '#default_value' => @$config['access block'],
      );
      break;
    default:
      $form['access_details']['access_callback'] = array(
        '#type' => 'item',
        '#title' => 'Access callback',
        '#disabled' => $locked,
        '#value' => @$config['access callback'],
      );
  }

  // Driver list
  $drivers = array(
    'FrxDrupal' => t('Drupal'),
    'FrxOracle' => t('Oracle Database'),
    'FrxPDO' => t('PDO other than Drupal '),
    'FrxPostgres' => t('Postgres Database'),
    'FrxMSSQL' => t('MSSQL Database'),
    'FrxFiles' => t('XML Files'),
  );
  $form['data_provider'] = array(
    '#type' => 'select',
    '#title' => t('Driver'),
    '#description' => t('Forena data connection type'),
    '#options' => $drivers,
    '#disabled' => $locked,
    '#default_value' => $config['data provider'],
    '#ahah' => array(
      'path' => 'admin/settings/forena/js/connection_info',
      'event' => 'change',
      'method' => 'replace',
      'wrapper' => 'conn-div',
    ),
  );
  $form['connection'] = array(
    '#type' => 'fieldset',
    '#tree' => TRUE,
    '#title' => 'Connection info',
    '#prefix' => '<div id="conn-div">',
    '#suffix' => '</div>',
  );
  $data_provider = !empty($form_state['values']['data_provider']) ? $form_state['values']['data_provider'] : $config['data provider'];

  // Common controls used in mulitple providers.
  $uri = array(
    '#type' => 'textfield',
    '#title' => t('uri'),
    '#descripton' => t('Connection string: see appropriate php documentation for more details.'),
    '#default_value' => @$config['uri'],
    '#required' => !$locked,
    '#disabled' => $locked,
  );
  $user = array(
    '#type' => 'textfield',
    '#title' => t('User'),
    '#default_value' => @$config['user'],
  );
  $password = array(
    '#type' => 'password',
    '#title' => t('Password'),
    '#default_value' => @$config['password'],
  );
  switch ($data_provider) {
    case 'FrxDrupal':
      $form['connection']['uri'] = array(
        '#type' => 'item',
        '#title' => t('URI'),
        '#disabled' => $locked,
        '#value' => 'Determined by Drupal settings.php file',
      );
      break;
    case 'FrxMSSQL':
      $form['connection']['uri'] = $uri;
      $form['connection']['user'] = $user;
      $form['connection']['new_password'] = $password;
      $form['connection']['database'] = array(
        '#type' => 'textfield',
        '#disabled' => $locked,
        '#title' => t('Database'),
        '#default_value' => $config['database'],
        '#required' => TRUE,
      );
      $form['connection']['mssql_xml'] = array(
        '#type' => 'checkbox',
        '#disabled' => $locked,
        '#title' => t('Microsoft SQL native XML'),
        '#description' => t('Use for XML auto queries to generate XML.'),
        '#default_value' => $config['mssql_xml'],
      );
      break;
    case 'FrxOracle':
      $form['connection']['uri'] = $uri;
      $form['connection']['user'] = $user;
      $form['connection']['new_password'] = $password;
      $form['connection']['character_set'] = array(
        '#type' => 'textfield',
        '#title' => t('Character Set'),
        '#disabled' => $locked,
        '#description' => t('Leave blank for default character set'),
        '#default_value' => @$config['character_set'],
      );
      $form['connection']['oracle_xml'] = array(
        '#type' => 'checkbox',
        '#title' => t('Oracle native XML'),
        '#disabled' => $locked,
        '#description' => t('Use the function provided with Forena to generate XML.  Requires installing a function into the database'),
        '#default_value' => $config['oracle_xml'],
      );
      break;
    case 'FrxPDO':
      $form['connection']['uri'] = $uri;
      $form['connection']['user'] = $user;
      $form['connection']['new_password'] = $password;
      break;
    case 'FrxPostgres':
      $form['connection']['uri'] = $uri;
      $form['connection']['new_password'] = $password;
      $form['connection']['postgres_xml'] = array(
        '#type' => 'checkbox',
        '#title' => t('Postgres native XML'),
        '#disabled' => $locked,
        '#default_value' => @$config['postgres_xml'],
        '#description' => t('Use Postgres native XML support.  Requires Posgres 8.3 or better'),
      );
    default:
      $form['connection']['uri'] = $uri;
  }
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
    '#submit' => array(
      'forena_data_settings_save',
    ),
  );
  $form['delete'] = array(
    "#type" => 'submit',
    '#value' => t('Delete'),
    '#submit' => array(
      'forena_data_settings_delete',
    ),
  );
  return $form;
}