You are here

function feeds_oai_pmh_set_ahah in Feeds OAI-PMH Fetcher and Parser 6

Callback function for AHAH setSpec element in form.

1 string reference to 'feeds_oai_pmh_set_ahah'
feeds_oai_pmh_menu in ./feeds_oai_pmh.module
Implementation of hook_menu().

File

./feeds_oai_pmh.module, line 66

Code

function feeds_oai_pmh_set_ahah() {
  if ($form = form_get_cache($_POST['form_build_id'], $form_state)) {

    // Validate the repository.
    $oai_source_url = $_POST['feeds']['FeedsOAIHTTPFetcher']['source'];
    require_once drupal_get_path('module', 'feeds_oai_pmh') . '/feeds_oai_pmh.inc';
    $result = feeds_oai_pmh_identify($oai_source_url);
    $set = '*';
    if ($result['status'] == 0) {

      // OAI-PMH Identify verb returned OK.
      // Change the form's set element.
      $form['feeds']['FeedsOAIHTTPFetcher']['set']['#options'] = feeds_oai_pmh_sets_options($result['repository']['sets']);
      $set = $_POST['feeds']['FeedsOAIHTTPFetcher']['set'];
      if ($set) {
        $form['feeds']['FeedsOAIHTTPFetcher']['set']['#default_value'] = $set;
      }
      if (isset($result['repository']['earliest_timestamp']) && $result['repository']['earliest_timestamp'] > 0) {
        $date = format_date($result['repository']['earliest_timestamp'], 'custom', 'M d, Y');
        $form['feeds']['FeedsOAIHTTPFetcher']['dates']['#description'] = t('Note: earliest record reported by repository is @date', array(
          '@date' => $date,
        ));
      }
    }
    else {

      // Empty sets.
      $form['feeds']['FeedsOAIHTTPFetcher']['set']['#options'] = feeds_oai_pmh_sets_options(array());
      $form['feeds']['FeedsOAIHTTPFetcher']['dates']['#description'] = '';
      drupal_set_message($result['output'], 'error');
    }

    // Cache the form.
    form_set_cache($_POST['form_build_id'], $form, $form_state);

    // Build and render the new select element, then return it in JSON format.
    $form_state = array();
    $form['#post'] = array();
    $form = form_builder($form['form_id']['#value'], $form, $form_state);

    // Update the status message
    $msg = feeds_oai_pmh_current_status_msg($oai_source_url, $set);
    if ($msg) {
      $msg = '<div class="messages status">' . $msg . '</div>';
    }
    $output = theme('status_messages') . drupal_render($form['feeds']['FeedsOAIHTTPFetcher']['set']) . $msg . drupal_render($form['feeds']['FeedsOAIHTTPFetcher']['use_dates']) . drupal_render($form['feeds']['FeedsOAIHTTPFetcher']['dates']);
    drupal_json(array(
      'status' => FALSE,
      'data' => $output,
    ));
  }
  exit;
}