/** * Prepares and returns the HTML for the SOPAC search page/hit list. * Uses the following templates: sopac_results.tpl.php, sopac_results_hitlist.tpl.php, sopac_results_nohits.tpl.php * * @return string SOPAC catalog search HTML */ function sopac_catalog_search() { global $pager_page_array, $pager_total, $locum_results_all, $locum_cfg; global $user; $account = user_load(array('uid' => $user->uid)); // Load Required JS libraries drupal_add_js(drupal_get_path('module', 'sopac') . '/js/jquery.treeview.js'); drupal_add_js(drupal_get_path('module', 'sopac') . '/js/jquery.rating.js'); drupal_add_js(drupal_get_path('module', 'sopac') . '/js/facet-browser.js'); require_once 'sopac_social.php'; $getvars = sopac_parse_get_vars(); $actions = sopac_parse_uri(); $locum = sopac_get_locum(); $locum_cfg = $locum->locum_config; $no_circ = $locum->csv_parser($locum_cfg['location_limits']['no_request']); $valid_search_types = array('title', 'author', 'keyword', 'subject', 'series', 'callnum', 'tags', 'reviews'); // TODO handle this more dynamically $output = $getvars['output']; $sort = $getvars['sort']; $format = $getvars['search_format']; $location = $getvars['location']; $limit_avail = $getvars['limit_avail']; $pager_page_array = explode(',', $getvars['page']); // temp for advanced page. should this be broken out if ($actions[1] == 'isn') { $actions[1] = 'keyword'; } $search_type = $actions[1]; if ($actions[3]) { $actions[2] = $actions[2] . "/" . $actions[3]; } $search_term = $actions[2]; // If there is a proper search query, we get that data here. if (in_array($actions[1], $valid_search_types)) { $valid_search = TRUE; // Save the search URL in a cookie $_SESSION['search_url'] = request_uri(); if ($getvars['perpage']) { $limit = $getvars['perpage']; } elseif ($account->profile_perpage) { $limit = $account->profile_perpage; } else { $limit = variable_get('sopac_results_per_page', 10); } if ($user->uid && $limit != $account->profile_perpage) { $field = db_fetch_object(db_query("SELECT * FROM profile_fields WHERE name = 'profile_perpage'")); db_query("INSERT INTO profile_values (fid, uid, value) VALUES (%d, %d, '%s') ON DUPLICATE KEY UPDATE value = '%s'", $field->fid, $user->uid, $limit, $limit); } //if ($addl_search_args['limit']) { // $limit = $addl_search_args['limit']; //} //else { // $limit = variable_get('sopac_results_per_page', 20); //} // Initialize the pager if need be if ($pager_page_array[0]) { $page = $pager_page_array[0] + 1; } else { $page = 1; } $page_offset = $limit * ($page - 1); // Grab the faceted search arguments from the URL $facet_args = array(); if (count($getvars['facet_series'])) { $facet_args['facet_series'] = $getvars['facet_series']; } if (count($getvars['facet_lang'])) { $facet_args['facet_lang'] = $getvars['facet_lang']; } if (count($getvars['facet_year'])) { $facet_args['facet_year'] = $getvars['facet_year']; } if (count($getvars['facet_decade'])) { $facet_args['facet_decade'] = $getvars['facet_decade']; } if (count($getvars['age'])) { $facet_args['age'] = $getvars['age']; } if (count($getvars['facet_subject'])) { $facet_args['facet_subject'] = $getvars['facet_subject']; } if (count($getvars['facet_lexile'])) { $facet_args['facet_lexile'] = $getvars['facet_lexile']; } // Hide suppressed records unless permission $show_inactive = user_access('show suppressed records'); // Get the search results from Locum $locum_results_all = $locum->search($search_type, $search_term, $limit, $page_offset, $sort, $format, $location, $facet_args, FALSE, $limit_avail, $show_inactive); $num_results = $locum_results_all['num_hits']; $result_info['limit'] = $limit; $result_info['num_results'] = $num_results; $result_info['hit_lowest'] = $page_offset + 1; if ($page_offset + $limit < $num_results) { $result_info['hit_highest'] = $page_offset + $limit; } else { $result_info['hit_highest'] = $num_results; } } // Construct the search form $search_form_cfg = variable_get('sopac_search_form_cfg', 'both'); $search_form = sopac_search_form($search_form_cfg); // If we get results back, we begin creating the hitlist if ($num_results > 0) { // We need to determine how many result pages there are. $pager_total[0] = ceil($num_results / $limit); $hitlist = ''; $hitnum = $page_offset + 1; // When limiting to available, sometimes the "Last" link takes the user beyond the number of // available items and errors out. This will step them back until they have at least 1 hit. if (!count($locum_results_all['results']) && $getvars['limit_avail']) { $uri_arr = explode('?', request_uri()); $uri = $uri_arr[0]; $getvars_tmp = $getvars; if ($getvars_tmp['page']) { if ($getvars_tmp['page'] == 1) { $getvars_tmp['page'] = ''; } else { $getvars_tmp['page']--; } $pvars_tmp = trim(sopac_make_pagevars(sopac_parse_get_vars($getvars_tmp))); $gvar_indicator = $pvars_tmp ? '?' : ''; $step_link = $uri . $gvar_indicator . $pvars_tmp; header('Location: ' . $step_link); } } // Loop through results. foreach ($locum_results_all['results'] as $locum_result) { // Grab Stdnum $stdnum = $locum_result['stdnum'][0]; // Get the cover image $cover_img_url = $locum_result['cover_img']; $locum_result['sort'] = $sort; // Grab Syndetics reviews, etc.. $review_links = $locum->get_syndetics($locum_result['stdnum'][0]); if (count($review_links)) { $locum_result['review_links'] = $review_links; } // Send it all off to the template if ($output == "rss") { $result_body .= theme('sopac_results_hitlist_rss', $hitnum, $cover_img_url, $locum_result, $locum_cfg, $no_circ); } else { if ($output == "xml") { $result_body .= theme('sopac_results_hitlist_xml', $hitnum, $cover_img_url, $locum_result, $locum_cfg, $no_circ); } else { $result_body .= theme('sopac_results_hitlist', $hitnum, $cover_img_url, $locum_result, $locum_cfg, $no_circ); } } $hitnum++; } $hitlist_pager = theme('pager', NULL, $limit, 0, NULL, 6); } else { if ($valid_search) { $result_body .= theme('sopac_results_nohits', $locum_results_all, $locum->locum_config); } } // Pull it all together into the search page template $result_page = $search_form . theme($output_template, $result_info, $hitlist_pager, $result_body, $locum_results_all, $locum->locum_config); // Check to see if we're doing RSS if ($output == "rss") { print theme('sopac_results_rss', $result_info, $search_term, $search_type, $result_body, $locum_results_all, $locum->locum_config); exit(0); } else { if ($output == "xml") { print theme('sopac_results_xml', $result_info, $hitlist_pager, $result_body, $locum_results_all, $locum->locum_config); exit(0); } else { $result_page = $search_form . theme('sopac_results', $result_info, $hitlist_pager, $result_body, $locum_results_all, $locum->locum_config); } } $search_feed_url = sopac_update_url(request_uri(), 'output', 'rss'); drupal_add_feed($search_feed_url, 'Search for "' . $search_term . '"'); return $result_page; }
/** * 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 = '<input type="checkbox" name="search_id[]" value="' . $search_arr['search_id'] . '">'; $parts = explode('?', $search_arr['search_url']); $search_desc = l($search_arr['search_desc'], $parts[0], array('query' => $parts[1])); // TODO: implement RSS feeds for saved searches. $search_feed_url = sopac_update_url($search_arr['search_url'], 'output', 'rss'); $search_feed = theme_feed_icon($search_feed_url, 'RSS Feed: ' . $search_arr['search_desc']); $rows[] = array($checkbox, $search_desc, $search_feed); } $submit_button = '<input type="submit" value="' . t('Remove Selected Searches') . '">'; $rows[] = array('data' => array(array('data' => $submit_button, 'colspan' => 3)), 'class' => 'profile_button'); $page_disp = '<form method="post">' . theme('pager', NULL, $limit, 0, NULL, 6) . theme('table', $header, $rows, array('id' => 'patroninfo', 'cellspacing' => '0')) . '</form>'; } else { $page_disp = '<div class="overview-nodata">' . t('You do not currently have any saved searches.') . '</div>'; } return $page_disp; }