-my $advanced_search_types = C4::Context->preference('AdvancedSearchTypes');
-
-my $whereclause = '';
-$whereclause .= ' AND items.homebranch='.$dbh->quote($branch) if ($branch);
-$whereclause .= ' AND TO_DAYS(NOW()) - TO_DAYS(biblio.datecreated) <= '.($timeLimit*30) if $timeLimit < 999;
-$whereclause =~ s/ AND $// if $whereclause;
-my $query;
-
-if($advanced_search_types eq 'ccode'){
- $whereclause .= ' AND authorised_values.authorised_value='.$dbh->quote($itemtype) if $itemtype;
- $query = "SELECT datecreated, biblio.biblionumber, title,
- author, sum( items.issues ) AS tot, biblioitems.itemtype,
- biblioitems.publishercode,biblioitems.publicationyear,
- authorised_values.lib as description
- FROM biblio
- LEFT JOIN items USING (biblionumber)
- LEFT JOIN biblioitems USING (biblionumber)
- LEFT JOIN authorised_values ON items.ccode = authorised_values.authorised_value
- WHERE 1
- $whereclause
- AND authorised_values.category = 'ccode'
- GROUP BY biblio.biblionumber
- HAVING tot >0
- ORDER BY tot DESC
- LIMIT $limit
- ";
- $template->param(ccodesearch => 1);
-}else{
- $whereclause .= ' AND biblioitems.itemtype='.$dbh->quote($itemtype) if $itemtype;
- $query = "SELECT datecreated, biblio.biblionumber, title,
- author, sum( items.issues ) AS tot, biblioitems.itemtype,
- biblioitems.publishercode,biblioitems.publicationyear,
- itemtypes.description
- FROM biblio
- LEFT JOIN items USING (biblionumber)
- LEFT JOIN biblioitems USING (biblionumber)
- LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
- WHERE 1
- $whereclause
- GROUP BY biblio.biblionumber
- HAVING tot >0
- ORDER BY tot DESC
- LIMIT $limit
- ";
- $template->param(itemtypesearch => 1);
+my $advanced_search_types = C4::Context->preference('OpacAdvancedSearchTypes');
+my @advanced_search_types = split /\|/, $advanced_search_types;
+
+my $params = {
+ count => $limit,
+ branch => $branch,
+ newness => $timeLimit < 999 ? $timeLimit * 30 : undef,
+};
+
+@advanced_search_types = grep /^(ccode|itemtypes)$/, @advanced_search_types;
+foreach my $type (@advanced_search_types) {
+ if ($type eq 'itemtypes') {
+ $type = 'itemtype';
+ }
+ $params->{$type} = $input->param($type);
+ $template->param('selected_' . $type => scalar $input->param($type));