locum_pass = substr($account->pass, 0, 7);
// Patron information table (top of the page)
$patron_details_table = sopac_user_info_table($account, $locum);
if (variable_get('sopac_summary_enable', 1)) {
$result[patroninfo]['#title'] = 'Account Summary';
$result[patroninfo]['#weight'] = 1;
$result[patroninfo]['#type'] = 'user_profile_category';
$result[patroninfo][details]['#value'] = $patron_details_table;
}
// Patron checkouts (middle of the page)
if ($account->valid_card && $account->bcode_verify) {
$co_table = sopac_user_chkout_table($account, $locum);
if ($co_table) {
$result[patronco]['#title'] = 'Checked-out Items';
$result[patronco]['#weight'] = 2;
$result[patronco]['#type'] = 'user_profile_category';
$result[patronco][details]['#value'] = $co_table;
}
}
// Patron holds (bottom of the page)
if ($account->valid_card && $account->bcode_verify) {
$holds_table = sopac_user_holds_table($account, $locum);
if ($holds_table) {
$result[patronholds]['#title'] = 'Requested Items';
$result[patronholds]['#weight'] = 3;
$result[patronholds]['#type'] = 'user_profile_category';
$result[patronholds][details]['#value'] = $holds_table;
}
}
// Commit the page content
$account->content[] = $result;
// The Summary is not really needed.
if (variable_get('sopac_history_hide', 1)) { unset($account->content[summary]); }
unset($account->content[Preferences]);
}
/**
* Returns a Drupal themed table of patron information for the "My Account" page.
*
* @param object $account Drupal user object for account being viewed
* @param object $locum Instansiated Locum object
* @return string Drupal themed table
*/
function sopac_user_info_table(&$account, &$locum) {
$rows = array();
if ($account->profile_pref_cardnum) {
$cardnum = $account->profile_pref_cardnum;
$cardnum_link = '' . $cardnum . '';
$userinfo = $locum->get_patron_info($cardnum);
$bcode_verify = sopac_bcode_isverified($account);
if ($bcode_verify) { $account->bcode_verify = TRUE; } else { $account->bcode_verify = FALSE; }
if ($userinfo[pnum]) { $account->valid_card = TRUE; } else { $account->valid_card = FALSE; }
// Construct the user details table based on what is configured in the admin interface
if ($account->valid_card && $bcode_verify) {
if (variable_get('sopac_pname_enable', 1)) {
$rows[] = array(array('data' => 'Patron Name', 'class' => 'attr_name'), $userinfo[name]);
}
if (variable_get('sopac_lcard_enable', 1)) {
$rows[] = array(array('data' => 'Library Card Number', 'class' => 'attr_name'), $cardnum_link);
}
if (variable_get('sopac_numco_enable', 1)) {
$rows[] = array(array('data' => 'Items Checked Out', 'class' => 'attr_name'), $userinfo[checkouts]);
}
if (variable_get('sopac_fines_enable', 1)) {
$amount_link = '$' . number_format($userinfo[balance], 2, '.', '') . '';
$rows[] = array(array('data' => 'Fine Balance', 'class' => 'attr_name'), $amount_link);
}
if (variable_get('sopac_cardexp_enable', 1)) {
$rows[] = array(array('data' => 'Card Expiration Date', 'class' => 'attr_name'), date('m-d-Y', $userinfo[expires]));
}
if (variable_get('sopac_tel_enable', 1)) {
$rows[] = array(array('data' => 'Telephone', 'class' => 'attr_name'), $userinfo[tel1]);
}
} else {
$rows[] = array(array('data' => 'Library Card Number', 'class' => 'attr_name'), $cardnum_link);
}
} else {
$cardnum_link = 'Click to add your library card';
$rows[] = array(array('data' => 'Library Card Number', 'class' => 'attr_name'), $cardnum_link);
}
if ($account->mail && variable_get('sopac_email_enable', 1)) {
$rows[] = array(array('data' => 'Email', 'class' => 'attr_name'), $account->mail);
}
// Begin creating the user information display content
$user_info_disp = theme('table', NULL, $rows, array('id' => 'patroninfo-summary', 'cellspacing' => '0'));
if ($account->valid_card && !$bcode_verify) {
$user_info_disp .= '
' . variable_get('sopac_uv_cardnum', 'The card number you have provided has not yet been verified by you. In order to make sure that you are the rightful owner of this library card number, we need to ask you some simple questions.') . '
',
);
$form['sopac_payment_cc_info']['ccseccode'] = array(
'#type' => 'textfield',
'#title' => t('Security Code'),
'#size' => 5,
'#maxlength' => 5,
'#required' => TRUE,
);
foreach ($hidden_vars_arr as $hkey => $hvar) {
$form['sopac_payment_form']['fine_summary[' . $hkey . '][amount]'] = array('#type' => 'hidden', '#value' => $hvar[amount]);
$form['sopac_payment_form']['fine_summary[' . $hkey . '][desc]'] = array('#type' => 'hidden', '#value' => $hvar[desc]);
}
$form['sopac_payment_form']['varname'] = array('#type' => 'hidden', '#value' => implode('|', $varname));
$form['sopac_payment_form']['total'] = array('#type' => 'hidden', '#value' => $fine_total);
$form['sopac_savesearch_form']['submit'] = array('#type' => 'submit', '#value' => t('Make Payment'));
return $form;
}
function sopac_fine_payment_form_submit($form, &$form_state) {
global $user;
$locum = new locum_client;
profile_load_profile(&$user);
$locum_pass = substr($user->pass, 0, 7);
if ($user->profile_pref_cardnum && sopac_bcode_isverified(&$user)) {
$fines = $locum->get_patron_fines($cardnum, $locum_pass);
$payment_details[name] = $form_state[values][name];
$payment_details[address1] = $form_state[values][address1];
$payment_details[city] = $form_state[values][city];
$payment_details[state] = $form_state[values][state];
$payment_details[zip] = $form_state[values][zip];
$payment_details[email] = $form_state[values][email];
$payment_details[ccnum] = $form_state[values][ccnum];
$payment_details[ccexpmonth] = $form_state[values][ccexpmonth];
$payment_details[ccexpyear] = $form_state[values][ccexpyear];
$payment_details[ccseccode] = $form_state[values][ccseccode];
$payment_details[total] = $form_state[values][total];
$payment_details[varnames] = explode('|', $form_state[values][varname]);
$payment_result = $locum->pay_patron_fines($user->profile_pref_cardnum, $locum_pass, $payment_details);
if (!$payment_result[approved]) {
if ($payment_result[reason]) {
$error = 'Your payment was not processed: ' . $payment_result[reason];
} else {
$error = 'We were unable to process your payment.';
}
drupal_set_message(t('' . $error . ''));
if ($payment_result[error]) {
drupal_set_message(t('' . $payment_result[error] . ''));
}
} else {
foreach ($_POST[fine_summary] as $fine_var => $fine_var_arr) {
$fine_desc = db_escape_string($fine_var_arr[desc]);
$sql = 'INSERT INTO {sopac_fines_paid} (payment_id, uid, amount, fine_desc) VALUES (0, ' . $user->uid . ', ' . $fine_var_arr[amount] . ', "' . $fine_desc . '")';
db_query($sql);
}
$amount = '$' . number_format($form_state[values][total], 2);
drupal_set_message(t('Your payment of ' . $amount . ' was successful. Thank-you!'));
}
}
}
/**
* A dedicated page for showing and managing saved searches from the catalog.
*/
function sopac_saved_searches_page() {
global $user;
$limit = 20; // TODO Make this configurable
if (count($_POST[search_id])) {
foreach ($_POST[search_id] as $sid) {
db_query('DELETE FROM {sopac_saved_searches} WHERE search_id = ' . $sid . ' AND uid = ' . $user->uid);
}
}
if (db_result(db_query('SELECT COUNT(*) FROM {sopac_saved_searches} WHERE uid = ' . $user->uid))) {
$header = array('','Search Description','');
$dbq = pager_query('SELECT * FROM {sopac_saved_searches} WHERE uid = ' . $user->uid . ' ORDER BY savedate DESC', $limit);
while ($search_arr = db_fetch_array($dbq)) {
$checkbox = '';
$search_desc = '' . $search_arr[search_desc]. '';
$search_feed = theme_feed_icon('/feed' . $search_arr[search_url], 'RSS Feed: ' . $search_arr[search_desc]);
$rows[] = array($checkbox, $search_desc, $search_feed);
}
$submit_button = '';
$rows[] = array( 'data' => array(array('data' => $submit_button, 'colspan' => 3)), 'class' => 'profile_button' );
$page_disp = '';
} else {
$page_disp = '
You do not currently have any saved searches.
';
}
return $page_disp;
}
/**
* Returns the form array for saving searches
*
* @return array Drupal form array.
*/
function sopac_savesearch_form() {
global $user;
$search_args = '/' . variable_get('sopac_url_prefix', 'cat/seek') . '/search' . substr($_SERVER[REQUEST_URI], 12 + strlen(variable_get('sopac_url_prefix', 'cat/seek')));
$uri_arr = sopac_parse_uri();
$term_arr = explode('?', $uri_arr[2]);
$form_desc = 'How would you like to label your ' . $uri_arr[1] . ' search for "'. $term_arr[0] . '" ?';
$form['#redirect'] = 'user/library/searches';
$form['sopac_savesearch_form'] = array(
'#type' => 'fieldset',
'#title' => t($form_desc),
'#collapsible' => FALSE,
);
$form['sopac_savesearch_form']['searchname'] = array(
'#type' => 'textfield',
'#title' => t('Search Label'),
'#size' => 48,
'#maxlength' => 128,
'#required' => TRUE,
'#default_value' => 'My custom ' . $uri_arr[1] . ' search for "' . $term_arr[0] . '"',
);
$form['sopac_savesearch_form']['uri'] = array('#type' => 'hidden', '#value' => $search_args);
$form['sopac_savesearch_form']['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
function sopac_savesearch_form_submit($form, &$form_state) {
global $user;
$desc = db_escape_string($form_state[values][searchname]);
db_query('INSERT INTO {sopac_saved_searches} VALUES (0, ' . $user->uid . ', NOW(), "' . $desc . '", "' . $form_state[values][uri] . '")');
$submsg = '» You have saved this search. »Return to your search
';
drupal_set_message($submsg);
}
function sopac_update_locum_acct($op, &$edit, &$account) {
$locum = new locum_client;
// Make sure we're all legit on this account
$cardnum = $account->profile_pref_cardnum;
if (!$cardnum) { return 0; }
$userinfo = $locum->get_patron_info($cardnum);
$bcode_verify = sopac_bcode_isverified($account);
if ($bcode_verify) { $account->bcode_verify = TRUE; } else { $account->bcode_verify = FALSE; }
if ($userinfo[pnum]) { $account->valid_card = TRUE; } else { $account->valid_card = FALSE; }
if (!$account->valid_card || !$bcode_verify) { return 0; }
if ($edit[mail] && $pnum) {
// TODO update email. etc.
}
}
/**
* Creates and returns the barcode/patron card number verification form. It also does the neccesary processing
* If this function has just successfully processed a form result, then it will instead return a message indicating thus.
*
* @param string $cardnum Library patron barcode/card number
* @return string Either the verification form or a confirmation of success.
*/
function sopac_bcode_verify_form() {
$args = func_get_args();
if (variable_get('sopac_require_cfg', 'one') == 'one') {
$req_flds = FALSE;
$form_desc = 'Please correctly answer one of the following questions:';
} else {
$req_flds = TRUE;
$form_desc = 'Please correctly answer all of the following questions:';
}
$form['sopac_card_verify'] = array(
'#type' => 'fieldset',
'#title' => t('Verify your Library Card Number'),
'#description' => t($form_desc),
'#collapsible' => FALSE,
'#validate' => 'sopac_bcode_verify_form_validate',
);
if (variable_get('sopac_require_name', 1)) {
$form['sopac_card_verify']['last_name'] = array(
'#type' => 'textfield',
'#title' => t('What is your last name?'),
'#size' => 32,
'#maxlength' => 128,
'#required' => $req_flds,
'#value' => $_POST[last_name],
);
}
if (variable_get('sopac_require_streetname', 1)) {
$form['sopac_card_verify']['streetname'] = array(
'#type' => 'textfield',
'#title' => t('What is the name of the street you live on?'),
'#size' => 24,
'#maxlength' => 32,
'#required' => $req_flds,
'#value' => $_POST[streetname],
);
}
if (variable_get('sopac_require_tel', 1)) {
$form['sopac_card_verify']['telephone'] = array(
'#type' => 'textfield',
'#title' => t('What is your telephone number?'),
'#description' => t("Please provide your area code as well as your phone number, eg: 203-555-1234."),
'#size' => 18,
'#maxlength' => 24,
'#required' => $req_flds,
'#value' => $_POST[telephone],
);
}
$form['sopac_card_verify']['vfy_post'] = array('#type' => 'hidden', '#value' => '1');
$form['sopac_card_verify']['uid'] = array('#type' => 'hidden', '#value' => $args[1]);
$form['sopac_card_verify']['cardnum'] = array('#type' => 'hidden', '#value' => $args[2]);
$form['sopac_card_verify']['vfy_submit'] = array('#type' => 'submit', '#value' => t('Verify!'));
return $form;
}
function sopac_bcode_verify_form_validate($form, $form_state) {
global $account;
$locum = new locum_client;
$cardnum = $form_state[values][cardnum];
$uid = $form_state[values][uid];
$userinfo = $locum->get_patron_info($cardnum);
$numreq = 0;
$correct = 0;
$validated = FALSE;
$req_cfg = variable_get('sopac_require_cfg', 'one');
// Match the name given
if (variable_get('sopac_require_name', 1)) {
if (trim($form_state[values][last_name])) {
$locum_name = ereg_replace("[^A-Za-z0-9 ]", "", trim(strtolower($userinfo[name])));
$sub_name = ereg_replace("[^A-Za-z0-9 ]", "", trim(strtolower($form_state[values][last_name])));
if (preg_match('/\b' . $sub_name . '\b/i', $locum_name)) {
$correct++;
} else {
$error[] = 'The last name you entered does not appear to match what we have on file.';
}
} else {
$error[] = 'You did not provide a last name.';
}
$numreq++;
}
if (variable_get('sopac_require_streetname', 1)) {
if (trim($form_state[values][streetname])) {
$locum_addr = ereg_replace("[^A-Za-z ]", "", trim(strtolower($userinfo[address])));
$sub_addr = ereg_replace("[^A-Za-z ]", "", trim(strtolower($form_state[values][streetname])));
$sub_addr_arr = explode(' ', $sub_addr);
if (strlen($sub_addr_arr[0]) == 1 || $sub_addr_arr[0] == 'north' || $sub_addr_arr[0] == 'east' || $sub_addr_arr[0] == 'south' || $sub_addr_arr[0] == 'west') {
$sub_addr = $sub_addr_arr[1];
} else {
$sub_addr = $sub_addr_arr[0];
}
if (preg_match('/\b' . $sub_addr . '\b/i', $locum_addr)) {
$correct++;
} else {
$error[] = 'The street name you entered does not appear to match what we have on file.';
}
} else {
$error[] = 'You did not provide a street name.';
}
$numreq++;
}
if (variable_get('sopac_require_tel', 1)) {
if (trim($form_state[values][telephone])) {
$locum_tel = ereg_replace("[^A-Za-z0-9 ]", "", trim(strtolower($userinfo[tel1] . ' ' . $userinfo[tel2])));
$sub_tel = ereg_replace("[^A-Za-z0-9 ]", "", trim(strtolower($form_state[values][telephone])));
if (preg_match('/\b' . $sub_tel . '\b/i', $locum_tel)) {
$correct++;
} else {
$error[] = 'The telephone number you entered does not appear to match what we have on file.';
}
} else {
$error[] = 'You did not provide a telephone number.';
}
$numreq++;
}
if ($req_cfg == 'one') {
if ($correct > 0) { $validated = TRUE; }
} else {
if ($correct == $numreq) { $validated = TRUE; }
}
if (count($error) && !$validated) {
foreach ($error as $errkey => $errmsg) {
form_set_error($errkey, t($errmsg));
}
}
if ($validated) {
db_query("INSERT INTO {sopac_card_verify} VALUES ($uid, '$cardnum', 1, NOW())");
}
}