END; } # Hard-code values for Signet Mystery search. $signet = $_REQUEST['signet']; if ($signet) { if (!$form[search_key]) $form[search_key] = 'b.imprint_id'; if (!$form[search_value]) $form[search_value] = 3; if (!$form[sort]) $form[sort] = 'desc'; $logo =<< END; } # Get the book list. $book_list = get_search_results($form, $upcoming, $current, $berkley, $signet); # Hack to keep upcoming/current/Berkley/Signet search values from # showing up in the text field. $display_value = (preg_match("/\d{8}-\d{8}/", $form[search_value])) ? '' : $form[search_value]; if ($form[search_value] == 5) $display_value = ''; if ($form[search_value] == 3) $display_value = ''; print_header('Search', $user, '', $display_value, '', $logo); print '' . $book_list . ''; print_footer(); exit; ###################################################################### # Build the list of books. function get_search_results($form, $upcoming, $current, $berkley, $signet) { global $ENV; # Default order_by, sort, start and limit values. if (!$form[order_by]) $form[order_by] = 'b.publication_date'; if ($form[sort] != 'asc') $form[sort] = 'desc'; if ($form[start] < 1) $form[start] = 0; if (!$form[limit]) $form[limit] = 10; # Build the genre drop-down. Create a genre_names associative # array to use for display names while we're at it. The creation # of the genre_names hash is why we need to take care of this # stuff up here, before we add genre_names to the result set of # our search. $genre_records = sql_select_genre_parents(); $genres[] = array(0 => 'All'); foreach ($genre_records as $genre_record) { $genres[] = array($genre_record->id => $genre_record->name); } $genre_select = build_select(1, 'genre_id', $genres, $form[genre_id]); # Format pull-down for setting/place. $setting_places = set_or_enum_values('setting_place', 'book', 'primecrime'); array_unshift($setting_places, 'All'); $setting_place_select = build_select(1, 'setting_place', $setting_places, $form[setting_place]); # Format pull-down for setting/time. $setting_times = set_or_enum_values('setting_time', 'book', 'primecrime'); array_unshift($setting_times, 'All'); $setting_time_select = build_select(1, 'setting_time', $setting_times, $form[setting_time]); if ($form[search_key]) { # Search clause #1 (criteria). $int_keys = array('b.imprint_id'); $equal_keys = array('b.isbn'); $in_keys = array(); $like_keys = array('b.title', "concat(a.first_name, ' ', a.last_name)", 'bc.name', 'b.series'); $date_keys = array('b.publication_date'); $where_clause = build_search_clause($form[search_value], stripslashes(urldecode($form[search_key])), $int_keys, $equal_keys, $in_keys, $like_keys, $date_keys); $where_clause = ($where_clause) ? 'and ' . $where_clause : ''; # Search clause #2 (genres). if (str_is_int($form[genre_id], 1)) { $genre_clause = "and gm.book_id = b.id and ((gm.genre_id = $form[genre_id]) || ((g.parent_id = $form[genre_id]) and (g.id = gm.genre_id)))"; $extra_params = "&genre_id=$form[genre_id]"; } if ($form[setting_place] && $form[setting_place] != 'All') $where_clause .= " and b.setting_place = '$form[setting_place]' "; if ($form[setting_time] && $form[setting_time] != 'All') $where_clause .= " and b.setting_time = '$form[setting_time]' "; # Get all the matching books, derive a count, and then slice # off the records that will be displayed on this page. $books = sql_select_books_for_search($genre_clause, $where_clause, $form[order_by], $form[sort]); $count = count($books); if ($count > 0) $books = array_slice($books, $form[start], $form[limit]); # Redirect if only one match. if ($count == 1) { header("Location: $ENV[home]book" . $books[0]->id); exit; } # List navigation. $extra_params .= "&setting_place=$form[setting_place]&setting_time=$form[setting_time]&upcoming=$upcoming¤t=$current&berkley=$berkley&signet=$signet"; $list_nav = build_list_nav('search.php', $form, $count, $extra_params); } # HTML drop-downs. $list_headers = array(array('b.publication_date' => 'Publication Date'), array('b.title' => 'Title'), array('a.last_name' => 'Author'), array('bc.name' => 'Character'), array('b.series' => 'Series')); $search_select = build_select(1, 'search_key', array(array('all' => 'All Criteria'), array('b.publication_date' => 'Publication Date'), array('b.title' => 'Title'), array('b.isbn' => 'ISBN'), array("concat(a.first_name, ' ', a.last_name)" => 'Author'), array('bc.name' => 'Character'), array('b.series' => 'Series')), $form[search_key]); $order_by_select = build_select(1, 'order_by', $list_headers, $form[order_by]); # Extra drop-downs for personal shopper stuff. $extra_html =<<

Category:

$genre_select END; # Format list values. for ($i = 0; $i < count($books); $i++) { # Cover picture (medium-sized). $cover_pic = get_image_filename($books[$i]->isbn, 'books'); if ($cover_pic) $display_picture = ""; else $display_picture = ''; # Summary. $summary_snippet = ''; if ($books[$i]->summary) { preg_match("/(\W*\w+){0,30}/", $books[$i]->summary, $matches); $summary_snippet = '

' . $matches[0] . ' ' . id_link('book', $books[$i]->id, 'More...', 'none') . '

'; } $books[$i]->basic_info = '

' . build_basic_book_info($books[$i], array()) . '

' . $summary_snippet; $books[$i]->picture = $display_picture; } # Default order for sorts triggered by header links is asc. # Specify those header links that should override this. $link_sort['b.publication_date'] = 'desc'; # Build the HTML for the list itself. $hide_form = ($upcoming || $current || $berkley || $signet) ? 1 : 0; $list_values = array('basic_info', 'picture'); $book_list = build_list_html('search.php', '', $books, $count, $list_nav, $list_headers, $list_values, $search_select, $order_by_select, $form, $extra_html, $extra_params, $hide_form); return $book_list; } ###################################################################### # Add genre_names to the result set of our search. Re-sort the # result set according to genre_names while we're at it, as # necessary. function add_genre_names($books, $genre_names, $order_by) { global $ENV; $begin_genre_link = 'id); foreach ($book_genre_ids as $book_genre_id) { $books[$i]->genre_names .= $begin_genre_link . $book_genre_id . '>' . $genre_names[$book_genre_id] . ';
'; } $books[$i]->genre_names = preg_replace("/;
$/", '', $books[$i]->genre_names); } # If order_by is set to b.id, that's just a decoy -- we really # want to sort by these nifty genre_names we just created. if ($order_by == 'b.id') { function cmp_obj($a, $b) { $gn_a = strtolower($a->genre_names); $gn_b = strtolower($b->genre_names); if ($gn_a == $gn_b) return 0; return ($gn_a > $gn_b) ? +1 : -1; } uasort($books, "cmp_obj"); } return $books; } ?>