From b181fb53743abd320191f89e098fbb1998cea2f9 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Thu, 4 May 2017 14:49:15 -0300 Subject: [PATCH] on form submission patrons are now redirected to a landing page --- includes/form.inc | 27 ++++++++++++++++++++++++--- includes/relais.inc | 16 +++++----------- upei_roblib_ill.module | 8 ++++++++ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/includes/form.inc b/includes/form.inc index bb6b2c1..543fd22 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -65,14 +65,35 @@ function upei_roblib_ill_form_submit($form, &$form_state) { break; case 'upei_roblib_ill_auth_form': //process the form - drupal_set_message('completed form'); $aid = upei_roblib_ill_authenticate($form_state['values']['campus_id']); - upei_roblib_ill_add_request($form_state, $aid); - break; + $response = upei_roblib_ill_add_request($form_state, $aid); + $form_state['redirect'] = array( + 'upei/roblib/ill/finished', + array( + 'query' => array( + 'message' => $response['ConfirmMessage'], + ), + ), + ); } } +/** + * After submitting an ILL request patrons will be redirected to the content returned from this function. + * @return string + * a string of HTML to display including the results of the ILL request and some boilerplate text. + */ +function upei_roblib_ill_form_redirect() { + //TODO turn this into a drupal render array + //TODO phone number, email etc. could be variables read from the database. + $std_message = "
To contact the department about this request, you can send a message to ill@upei.ca or +call 902-566-0445
"; + return "
" . $_GET['message'] . '
'. $std_message; +} + + + /** * The patron portion of the ILL form. diff --git a/includes/relais.inc b/includes/relais.inc index 6d53aef..e6f6ab2 100644 --- a/includes/relais.inc +++ b/includes/relais.inc @@ -45,23 +45,17 @@ function upei_roblib_ill_add_request($form_state, $aid) { if(!isset($aid) || is_array($aid)) { upei_roblib_ill_log_request($relais_arr, $aid); drupal_set_message(t('Error retrieving authentication token, @message', array('@message' => $aid['Problem']['Message'])), 'error'); - return; + return array('ConfirmMessage' => $aid['Problem']['Message'] . ' You may have entered an incorrect Campus ID'); } $result = drupal_http_request($url . '?aid=' . $aid, $options); module_load_include('inc', 'upei_roblib_ill', 'includes/db'); + if(!isset($result->data)) { + return array('ConfirmMessage' => 'Error Communicating with Relais, no data returned.'); + } $response_json = $result->data; $response_arr = json_decode($response_json, TRUE); - if ($result->code == '200') { - //TODO remove or improve the line below after testing - drupal_set_message('submitted request to relais' . $response_json); - } - else { - drupal_set_message(t('Error submitting request to relais, @code, @message', array( - '@code' => $result->code, - '@message' => $result->message - )), 'error'); - } upei_roblib_ill_log_request($relais_arr, $response_arr); + return $response_arr; } /** diff --git a/upei_roblib_ill.module b/upei_roblib_ill.module index 1176c55..d44a8f0 100644 --- a/upei_roblib_ill.module +++ b/upei_roblib_ill.module @@ -25,6 +25,14 @@ function upei_roblib_ill_menu() { 'file' => 'includes/form.inc', 'type' => MENU_NORMAL_ITEM, ); + $items['upei/roblib/ill/finished'] = array( + 'title' => 'UPEI ILL Request', + 'description' => 'Redirect to this page after form is submitted', + 'page callback' => 'upei_roblib_ill_form_redirect', + 'access arguments' => array('access content'), + 'file' => 'includes/form.inc', + 'type' => MENU_NORMAL_ITEM, + ); return $items; }