The libraries interlibrary loan form module
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

526 lines
17 KiB

8 years ago
<?php
/**
* @file
* Contains the ILL forms.
*/
/**
* A form to wrap the different steps of our multi step form.
*
* @param array $form
* An array representing a Drupal form.
* @param array $form_state
* An array containing the Drupal form state.
*
* @return array
* An array representing the bibliographic form.
*/
function upei_roblib_ill_form($form, &$form_state) {
if (!isset($form_state['values'])) {
$form_name = 'upei_roblib_ill_request_form';
}
else {
$form_name = 'upei_roblib_ill_auth_form';
}
$form_state['step'] = $form_name;
return $form_name === 'upei_roblib_ill_request_form' ? upei_roblib_ill_request_form($form, $form_state) :
upei_roblib_ill_auth_form($form, $form_state);
}
/**
* Validation for the upei_roblib_ill_form form.
*
* @param array $form
* An array representing a Drupal form.
* @param array $form_state
* An array containing the Drupal form state.
*/
function upei_roblib_ill_form_validate($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/relais');
if ($form_state['step'] == 'upei_roblib_ill_auth_form') {
if (!valid_email_address($form_state['values']['DeliveryAddress'])) {
form_set_error('DeliveryAddress', t('Your email address appears to be invalid.'));
}
if (!$form_state['values']['certify']) {
form_set_error('certify', t('Please certify that this is item is being sought for a fair dealing purpose'));
}
$form_state['values']['campus_id'] = upei_roblib_ill_form_message_id($form_state['values']['campus_id']);
$aid = upei_roblib_ill_authenticate($form_state['values']['campus_id'], $form_state['values']['Surname']);
if (is_array($aid) && isset($aid['Problem']['Message'])) {
form_set_error('Surname', $aid['Problem']['Message']);
form_set_error('campus_id', '');
// Log invalid requests, we need to build the full array here to log it, even though we won't send it yet as auth has failed.
$form_state['storage']['upei_roblib_ill_auth_form'] = $form_state['values'];
module_load_include('inc', 'upei_roblib_ill', 'includes/db');
$arr = upei_roblib_ill_build_relais_arr($form_state);
upei_roblib_ill_log_request($arr, $aid);
}
else {
$form_state['storage']['aid'] = $aid;
}
}
if ($form_state['step'] == 'upei_roblib_ill_request_form' && $form_state['triggering_element']['#value'] !== 'Lookup DOI' && empty($form_state['values']['Title'])) {
form_set_error('Title', t('Journal/Book Title is required.'));
8 years ago
}
}
/**
* @param string $id
* The users campus id
*
* @return mixed
* the campus id with leading zeros and leading/trailing whitespace removed.
*/
function upei_roblib_ill_form_message_id($id) {
$id = ltrim($id, '0');
return trim($id);
}
8 years ago
/**
* Submit handler for the upei_roblib_ill_form form.
*
* @param array $form
* An array representing a Drupal form.
* @param array $form_state
* An array containing the Drupal form state.
*/
function upei_roblib_ill_form_submit($form, &$form_state) {
8 years ago
$form_state['storage'][$form_state['step']] = $form_state['values'];
switch ($form_state['step']) {
case 'upei_roblib_ill_request_form':
if ($form_state['clicked_button']['#value'] != 'Lookup DOI') {
8 years ago
$form_state['step'] = 'upei_roblib_ill_auth_form';
$form_state['rebuild'] = TRUE;
}
break;
case 'upei_roblib_ill_auth_form':
//process the form
$response = upei_roblib_ill_add_request($form_state, $form_state['storage']['aid']);
$error = isset($response['RequestNumber']) ? 'FALSE' : 'TRUE';
$form_state['redirect'] = [
'/upei/roblib/ill/finished',
[
'query' => [
'message' => $response['ConfirmMessage'],
'email' => $form_state['values']['DeliveryAddress'],
'error' => $error,
],
],
];
8 years ago
}
}
/**
* 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() {
$contact_email = variable_get('upei_roblib_ill_contact_email', 'ill@upei.ca');
$contact_phone_number = variable_get('upei_roblib_ill_contact_phone', '902-566-0445');
$librarian_link = l(t('subject-specific'), 'http://library.upei.ca/librarians', ['html' => TRUE]);
$help_message = t("We can help! Please contact your !librarian_link librarian if you'd like help finding more resources relating to your topic.",
['!librarian_link' => $librarian_link]);
$standard_message = t("To contact the department about this request, you can send a message to @email or
call @phone.", ['@phone' => $contact_phone_number, '@email' => $contact_email]);
if (isset($_GET['error']) && $_GET['error'] === 'FALSE') {
$standard_message = t("A message including the Request ID has been sent to @email.", [
'@email' => $_GET['email'],
]) . $standard_message;
}
$output = [
'#prefix' => '<div upei-roblib-ill-content>',
'#suffix' => '</div>',
'dynamic_message' => [
'#type' => 'markup',
'#markup' => $_GET['message'],
'#prefix' => '<div class="upei-roblib-ill-message">',
'#suffix' => '</div>',
],
'standard_message' => [
'#type' => 'markup',
'#markup' => $standard_message,
'#prefix' => '<div class="upei-roblib-ill-email">',
'#suffix' => '</div>',
],
'help_message' => [
'#type' => 'markup',
'#markup' => $help_message,
'#allowed_tags' => ['a', 'source'],
'#prefix' => '<div class="upei-roblib-ill-help">',
'#suffix' => '</div>',
],
];
return drupal_render($output);
}
8 years ago
/**
* The patron portion of the ILL form.
*
* The campus_id and email portion are also used in a request for an Relais aid.
*
* @param array $form
* An array representing a Drupal form.
* @param array $form_state
* An array containing the Drupal form state.
*
* @return array
* An array representing the bibliographic form.
*/
function upei_roblib_ill_auth_form($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$form['#prefix'] = upei_roblib_format_biblio_info($form_state);
$form['#suffix'] = '<div class="roblib-required">* = Required Field</div>
<div class="roblib-FOIPP"><strong>Protection of Privacy</strong> - The personal information requested
on this form is collected under the authority of Section 31(c) of the PEI
Freedom of Information and Protection of Privacy Act and will be protected
under Part 2 of that Act. It will be used for the purpose of administering
and providing library service. Direct any questions about this collection to
Health Sciences and Scholarly Communications Librarian at ill@upei.ca, 550
University Ave, Charlottetown PE , 902-566-0453.</div>';
$form['FirstName'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Your First Name'),
'#size' => 50,
'#required' => TRUE,
];
$form['Surname'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Your Last Name'),
'#size' => 50,
'#required' => TRUE,
];
$form['campus_id'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Your Campus ID'),
'#size' => 50,
'#required' => TRUE,
];
$patron_types = [
'Faculty/Staff' => t('Faculty/Staff'),
'Undergraduate Student' => t('Undergraduate Student'),
'Masters Student' => t('Masters Student'),
'Doctoral Student' => t('Doctoral Student'),
'Alumni Premiere Subscriber' => t('Alumni Premiere Subscriber'),
'Alumni/Public' => t('Alumni/Public'),
'Other' => 'Other',
];
$departments = [
'Actuarial Science' => t('Actuarial Science'),
'Analytics' => t('Analytics'),
'Applied Communication, Leadership, and Culture' => t('Applied Communication, Leadership, and Culture'),
'Applied Health Services Research' => t('Applied Health Services Research'),
8 years ago
'Applied Human Sciences' => t('Applied Human Sciences'),
'Arts (General)' => t('Arts (General)'),
8 years ago
'Biology' => t('Biology'),
'Business' => t('Business'),
'Canadian Studies' => t('Canadian Studies'),
8 years ago
'Chemistry' => t('Chemistry'),
'Climate Change and Adaptation' => t('Climate Change and Adaptation'),
'Computer Science' => t('Computer Science'),
8 years ago
'Diversity and Social Justice Studies' => t('Diversity and Social Justice Studies'),
'Economics' => t('Economics'),
'Education' => t('Education'),
'English' => t('English'),
'Environmental Studies/Sciences' => t('Environmental Studies/Sciences'),
'Financial Mathematics' => t('Financial Mathematics'),
'Foods and Nutrition' => t('Foods and Nutrition'),
'French' => t('French'),
'Global Affairs' => t('Global Affairs'),
8 years ago
'History' => t('History'),
'Integrated Studies' => t('Integrated Studies'),
8 years ago
'Island Studies' => t('Island Studies'),
'Journalism' => t('Journalism'),
'Kinesiology' => t('Kinesiology'),
'Library, Robertson' => t('Library, Robertson'),
'Nursing' => t('Nursing'),
'Mathematics' => t('Mathematics'),
8 years ago
'Modern Languages' => t('Modern Languages'),
'Music' => t('Music'),
'Paramedicine' => t('Paramedicine'),
8 years ago
'Philosophy' => t('Philosophy'),
'Physics' => t('Physics'),
'Political Science' => t('Political Science'),
'Psychology' => t('Psychology'),
'Radiography' => t('Radiography'),
8 years ago
'Religious Studies' => t('Religious Studies'),
'Science (General)' => t('Science (General)'),
8 years ago
'Sociology/Anthropology' => t('Sociology/Anthropology'),
'Spanish' => t('Spanish'),
'Statistics' => t('Statistics'),
'Sustainable Design Engineering' => t('Sustainable Design Engineering'),
'Wildlife Conservation' => t('Wildlife Conservation'),
'Veterinary Medicine' => t('Veterinary Medicine'),
'Other' => ('Other (please add to the notes field)'),
];
$form['patron_type'] = [
8 years ago
'#type' => 'select',
'#title' => t('Your Patron Type'),
'#options' => $patron_types,
'#required' => TRUE,
];
$form['Department'] = [
8 years ago
'#type' => 'select',
'#title' => t('Your Department'),
'#options' => $departments,
'#required' => TRUE,
];
$form['DeliveryAddress'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Your Email (If using an email address other than @upei.ca, enter that address in the Notes field as well.)'),
8 years ago
'#size' => 50,
'#required' => TRUE,
];
$form['InstitutionName'] = [
'#type' => 'hidden',
8 years ago
'#title' => t('Name of Institution'),
'#size' => 50,
'#default_value' => 'University of Prince Edward Island',
'#required' => TRUE,
];
$form['LibraryName'] = [
'#type' => 'hidden',
'#title' => t('Name of Library'),
8 years ago
'#size' => 50,
'#default_value' => 'Robertson Library',
'#required' => TRUE,
];
$form['notes'] = [
8 years ago
'#type' => 'textarea',
'#title' => t('Notes'),
'#size' => 50,
'#required' => FALSE,
];
$form['certify'] = [
'#title' => t('I certify'),
8 years ago
'#type' => 'checkbox',
'#description' => 'I hereby certify that this item is being sought for a fair dealing purpose and any copying will be in accordance with the Copyright Act. ',
'#size' => 50,
'#required' => TRUE,
];
$form['submit'] = [
8 years ago
'#type' => 'submit',
'#value' => 'Submit',
];
8 years ago
return $form;
}
/**
* The bibliographic portion of the ILL form.
*
* @param array $form
* An array representing a Drupal form.
* @param array $form_state
* An array containing the Drupal form state.
*
* @return array
* An array representing the bibliographic form.
*/
function upei_roblib_ill_request_form($form, &$form_state) {
module_load_include('inc', 'upei_roblib_ill', 'includes/utilities');
$emergency_message = '<div class="messages messages--error closure-notice">Most libraries
are unable to provide access to physical resources at this time, so books, microfilm,
etc. are not available and requests for those will be automatically rejected.
You may request chapters from books, or journal articles. If they are not
currently accessible, you will be notified. </div>';
$form['#prefix'] = $emergency_message . '<div id="upei-roblib-ill-request-form">';
$form['#suffix'] = '<div class="roblib-required">* = Required Field</div></div>';
$type = upei_roblib_ill_get_request_variable('genre');
$genre = empty($type) ? 'article' : $type;
$form['Genre'] = [
8 years ago
'#type' => 'select',
'#title' => t('Item Type'),
'#options' => [
8 years ago
'book' => t('Book'),
'chapter' => t('Book Chapter'),
'article' => t('Journal Article'),
],
8 years ago
'#required' => TRUE,
];
if(!empty($type)) {
$form['Genre']['#default_value'] = $type;
}
$form['doi'] = [
8 years ago
'#type' => 'textfield',
'#title' => t("DOI (ex: 10.1016/j.ypmed.2019.01.018) <a href='https://library.upei.ca/doi'>more info</a>"),
'#default_value' => upei_roblib_ill_get_doi_from_request(),
//'#description' => 'DOI, if you provide a DOI we will attempt to lookup the record for you',
8 years ago
'#size' => 50,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
8 years ago
'#required' => FALSE,
];
$form['doi_button'] = [
8 years ago
'#type' => 'submit',
'#value' => 'Lookup DOI',
'#ajax' => [
8 years ago
'callback' => 'upei_roblib_ill_doi_callback',
'method' => 'replace',
'wrapper' => 'upei-roblib-ill-request-form',
'effect' => 'fade',
],
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
8 years ago
'#required' => FALSE,
];
$form['Title'] = [
'#type' => 'textarea',
'#rows' => 2,
'#title' => t('Journal/Book Title *'),
8 years ago
'#default_value' => upei_roblib_ill_get_request_variable('title'),
//'#description' => 'Journal or Book Title (Required)',
8 years ago
'#size' => 50,
'#required' => FALSE,
];
$form['ArticleTitle'] = [
'#type' => 'textarea',
'#rows' => 2,
'#title' => t('Article/Chapter Title'),
8 years ago
'#default_value' => upei_roblib_ill_get_request_variable('atitle'),
//'#description' => 'Article or Chapter Title',
8 years ago
'#size' => 50,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
8 years ago
'#required' => FALSE,
];
8 years ago
$form['ISSN'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('ISSN (ex: 1234-567X)'),
8 years ago
'#default_value' => upei_roblib_ill_get_request_variable('issn'),
'#size' => 50,
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
8 years ago
'#required' => FALSE,
];
$article_author = ($genre == 'book') ? '' : upei_roblib_ill_get_request_variable('author');
$form['ArticleAuthor'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Article/Chapter Author'),
'#default_value' => $article_author,
8 years ago
'#size' => 50,
'#required' => FALSE,
//'#description' => 'Article or Chapter Author',
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
];
$author = ($genre == 'book') ? upei_roblib_ill_get_request_variable('author') : '';
$form['Author'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Book Author'),
'#default_value' => $author,
8 years ago
'#size' => 50,
'#required' => FALSE,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => t('article')],
],
],
];
$form['ISBN'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('ISBN (ex: 9780323554459)'),
8 years ago
'#default_value' => upei_roblib_ill_get_request_variable('isbn'),
'#size' => 50,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
8 years ago
'#required' => FALSE,
];
$form['SubTitle'] = [
8 years ago
'#type' => 'hidden',
'#title' => t('Sub Title'),
'#default_value' => upei_roblib_ill_get_request_variable('ubtitle'),
'#size' => 50,
'#required' => FALSE,
];
$form['SeriesTitle'] = [
8 years ago
'#type' => 'hidden',
'#title' => t('Series Title'),
'#default_value' => upei_roblib_ill_get_request_variable('stitle'),
'#size' => 50,
'#required' => FALSE,
];
8 years ago
$form['Volume'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Volume'),
'#default_value' => upei_roblib_ill_get_request_variable('volume'),
'#size' => 50,
'#required' => FALSE,
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
];
$form['Issue'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Issue'),
'#default_value' => upei_roblib_ill_get_request_variable('issue'),
'#size' => 50,
'#required' => FALSE,
'#states' => [
'visible' => [
':input[name="Genre"]' => ['value' => 'article'],
],
],
];
$form['PagesRequested'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Pages (startpage-endpage)'),
'#default_value' => upei_roblib_ill_get_request_variable('pages'),
//'#description' => 'Pages requested (startpage-endpage)',
8 years ago
'#size' => 50,
'#required' => FALSE,
'#states' => [
'invisible' => [
':input[name="Genre"]' => ['value' => 'book'],
],
],
];
$form['Date'] = [
8 years ago
'#type' => 'textfield',
'#title' => t('Publication Date'),
8 years ago
'#default_value' => upei_roblib_ill_get_request_variable('date'),
'#size' => 50,
'#required' => FALSE,
];
$form['next'] = [
8 years ago
'#type' => 'submit',
'#value' => t('Next'),
];
8 years ago
return $form;
}