You are here

function quiz_results_mr_browser_ahah in Quiz 7

Same name and namespace in other branches
  1. 6.4 quiz.admin.inc \quiz_results_mr_browser_ahah()

AHAH handler for the results browser

2 string references to 'quiz_results_mr_browser_ahah'
quiz_menu in ./quiz.module
Implements hook_menu().
_quiz_results_mr_add_filter_fields in ./quiz.admin.inc
Adds form items for the filters to the browser form.

File

./quiz.admin.inc, line 402
Administrator interface for Quiz module.

Code

function quiz_results_mr_browser_ahah($form, &$form_state) {

  // Prepare to get the form from cache

  //$form_state = array('storage' => NULL, 'submitted' => FALSE);
  $form_id = $form['#form_id'];

  // Make sure the form exists

  //if (!($form = form_get_cache($form_id, $form_state))) {

  //  form_set_error('form_token', t("Validation error, please try again. If this error persists, please contact the site administrator."));
  //   $output = theme('status_messages');
  //   print drupal_json_encode(array('status' => TRUE, 'data' => $output));
  //   exit();

  //}

  // If filter or pager has been used

  //$replace_all = drupal_strlen($_POST['table']['add_to_get']) > 0;

  // Prepare to submit the form

  //$args = $form['#parameters'];

  //$form_id = array_shift($args);

  // We will run some of the submit handlers so we need to disable redirecting.

  //$form_state['#redirect'] = FALSE;

  // We need to process the form, prepare for that by setting a few internal variables.

  //$form['#post'] = $_POST;

  ///$form['#programmed'] = FALSE;

  //$form_state['post'] = $_POST;

  // $_REQUEST is used by drupal core. We need to remove data recieved from ajax.

  //foreach ($_POST as $key => $value) {

  //  unset($_REQUEST[$key]);
  // }

  //$_POST = array();

  // We don't want any validation errors to show up. This isn't a real submit.
  _quiz_skip_validation($form);
  _quiz_results_mr_store_filters($form_state['values']['table']['filters']);

  // Build, validate and submit the form.

  //drupal_process_form($form_id, $form, $form_state);

  //Remove any status messages the processing resulted in...
  theme('status_messages');

  // Get the form the ajax call resulted in
  $form = drupal_rebuild_form($form_id, $form_state);
  return $form['table'];

  //print_r($form);exit;

  // We store a copy of the browser part of the form, and remove it from the main form.
  // This way we can render the form without the browser, and render the browser separatly
  $b_form = $form['table'];
  unset($form['table']);

  /*
   * $output is the string we will send to ajax, and that will be added to the page.
   * We are doing this in a special way so we have to call javascript functions to
   * update the DOM.
   */
  $output = '<script>var quizNewBuildId = ' . drupal_json_encode($form['#build_id']) . ';';

  // We replace the entire browser. This is done when the browser is sorted
  if ($replace_all) {

    // Make sure the description and test is removed
    unset($b_form['#type']);
    unset($b_form['#value']);
    $rendered_browser = drupal_render($b_form);
    $output .= ' var renderedBrowser = ' . drupal_json_encode(theme('status_messages') . $rendered_browser) . ';';

    // Have js(jQuery) replace the browser and change the form build id in the DOM
    $output .= ' Quiz.replaceBrowser(renderedBrowser, quizNewBuildId); </script>';
  }
  else {

    // Send status messages, new build id for the form and the new question row to the javascript:
    $b_rows = _quiz_get_browser_content(drupal_render($b_form), 'quiz-results-browser-row');
    $b_pager = drupal_render($b_form['pager']);
    $output .= ' var quizBrowserRows = ' . drupal_json_encode($b_rows) . ';';
    $output .= ' var quizBrowserPager = ' . drupal_json_encode($b_pager) . ';';
    $output .= ' Quiz.addBrowserRows(quizBrowserRows, quizNewBuildId, quizBrowserPager);';
    $output .= ' </script>';
    $output .= ' ' . theme('status_messages');
  }
  return $output;
}