"Fossies" - the Fresh Open Source Software Archive

Member "koha-19.11.15/opac/opac-authorities-home.pl" (23 Feb 2021, 6268 Bytes) of package /linux/misc/koha-19.11.15.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "opac-authorities-home.pl" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 20.05.06_vs_20.11.00.

    1 #!/usr/bin/perl
    2 # WARNING: 4-character tab stops here
    3 
    4 # Copyright 2000-2002 Katipo Communications
    5 #
    6 # This file is part of Koha.
    7 #
    8 # Koha is free software; you can redistribute it and/or modify it
    9 # under the terms of the GNU General Public License as published by
   10 # the Free Software Foundation; either version 3 of the License, or
   11 # (at your option) any later version.
   12 #
   13 # Koha is distributed in the hope that it will be useful, but
   14 # WITHOUT ANY WARRANTY; without even the implied warranty of
   15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   16 # GNU General Public License for more details.
   17 #
   18 # You should have received a copy of the GNU General Public License
   19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
   20 
   21 use Modern::Perl;
   22 
   23 use CGI qw ( -utf8 );
   24 use URI::Escape;
   25 use C4::Auth;
   26 
   27 use C4::Context;
   28 use C4::Auth;
   29 use C4::Output;
   30 use C4::AuthoritiesMarc;
   31 use C4::Koha;
   32 use C4::Search::History;
   33 
   34 use Koha::Authority::Types;
   35 use Koha::SearchEngine::Search;
   36 use Koha::SearchEngine::QueryBuilder;
   37 
   38 my $query        = new CGI;
   39 my $op           = $query->param('op') || '';
   40 my $authtypecode = $query->param('authtypecode') || '';
   41 my $dbh          = C4::Context->dbh;
   42 
   43 my $startfrom = $query->param('startfrom') || 1;
   44 my $resultsperpage = $query->param('resultsperpage') || 20;
   45 my $authid    = $query->param('authid');
   46 my ( $template, $loggedinuser, $cookie );
   47 
   48 my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']});
   49 
   50 if ( $op eq "do_search" ) {
   51     my @marclist = $query->multi_param('marclist');
   52     my @and_or = $query->multi_param('and_or');
   53     my @excluding = $query->multi_param('excluding');
   54     my @operator = $query->multi_param('operator');
   55     my $orderby = $query->param('orderby');
   56     my @value = $query->multi_param('value');
   57     $value[0] ||= q||;
   58 
   59     my @tags;
   60     my $builder = Koha::SearchEngine::QueryBuilder->new(
   61         { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
   62     my $searcher = Koha::SearchEngine::Search->new(
   63         { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
   64     my $search_query = $builder->build_authorities_query_compat( \@marclist, \@and_or,
   65         \@excluding, \@operator, \@value, $authtypecode, $orderby );
   66     my $offset = ( $startfrom - 1 ) * $resultsperpage + 1;
   67     my ( $results, $total ) =
   68       $searcher->search_auth_compat( $search_query, $offset, $resultsperpage );
   69     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
   70         {
   71             template_name   => "opac-authoritiessearchresultlist.tt",
   72             query           => $query,
   73             type            => 'opac',
   74             authnotrequired => 1,
   75             debug           => 1,
   76         }
   77     );
   78     $template->param( search_query => $search_query ) if C4::Context->preference('DumpSearchQueryTemplate');
   79 
   80     # multi page display gestion
   81     my $value_url = uri_escape_utf8($value[0]);
   82     my $base_url = "opac-authorities-home.pl?"
   83       ."marclist=$marclist[0]"
   84       ."&amp;and_or=$and_or[0]"
   85       ."&amp;excluding=$excluding[0]"
   86       ."&amp;operator=$operator[0]"
   87       ."&amp;value=$value_url"
   88       ."&amp;resultsperpage=$resultsperpage"
   89       ."&amp;type=opac"
   90       ."&amp;op=do_search"
   91       ."&amp;authtypecode=$authtypecode"
   92       ."&amp;orderby=$orderby";
   93 
   94     my $from = ( $startfrom - 1 ) * $resultsperpage + 1;
   95     my $to;
   96     if ( !defined $total ) {
   97         $total = 0;
   98     }
   99 
  100     if ( $total < $startfrom * $resultsperpage ) {
  101         $to = $total;
  102     }
  103     else {
  104         $to = $startfrom * $resultsperpage;
  105     }
  106 
  107     $template->param( result => $results ) if $results;
  108 
  109     $template->param(
  110         pagination_bar => pagination_bar(
  111             $base_url,  int( $total / $resultsperpage ) + 1,
  112             $startfrom, 'startfrom'
  113         ),
  114         total     => $total,
  115         from      => $from,
  116         to        => $to,
  117     );
  118 
  119     unless (C4::Context->preference('OPACShowUnusedAuthorities')) {
  120 #        TODO implement usage counts
  121 #        my @usedauths = grep { $_->{used} > 0 } @$results;
  122 #        $results = \@usedauths;
  123     }
  124 
  125     # Opac search history
  126     if (C4::Context->preference('EnableOpacSearchHistory')) {
  127         if ( $startfrom == 1) {
  128             my $path_info = $query->url(-path_info=>1);
  129             my $query_cgi_history = $query->url(-query=>1);
  130             $query_cgi_history =~ s/^$path_info\?//;
  131             $query_cgi_history =~ s/;/&/g;
  132 
  133             unless ( $loggedinuser ) {
  134                 my $new_search = C4::Search::History::add_to_session({
  135                         cgi => $query,
  136                         query_desc => $value[0],
  137                         query_cgi => $query_cgi_history,
  138                         total => $total,
  139                         type => "authority",
  140                 });
  141             } else {
  142                 # To the session (the user is logged in)
  143                 C4::Search::History::add({
  144                     userid => $loggedinuser,
  145                     sessionid => $query->cookie("CGISESSID"),
  146                     query_desc => $value[0],
  147                     query_cgi => $query_cgi_history,
  148                     total => $total,
  149                     type => "authority",
  150                 });
  151             }
  152         }
  153     }
  154 
  155     $template->param( orderby => $orderby );
  156     $template->param(
  157         startfrom      => $startfrom,
  158         resultsperpage => $resultsperpage,
  159         countfuzzy     => !(C4::Context->preference('OPACShowUnusedAuthorities')),
  160         resultcount    => scalar @$results,
  161         authtypecode   => $authtypecode,
  162         authtypetext   => $authority_types->find($authtypecode)->authtypetext,
  163         isEDITORS      => $authtypecode eq 'EDITORS',
  164     );
  165 
  166 }
  167 else {
  168     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
  169         {
  170             template_name   => "opac-authorities-home.tt",
  171             query           => $query,
  172             type            => 'opac',
  173             authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
  174             debug           => 1,
  175         }
  176     );
  177 
  178 }
  179 
  180 $template->param(
  181     authority_types => $authority_types,
  182     authtypecode    => $authtypecode,
  183 );
  184 
  185 # Print the page
  186 output_html_with_http_headers $query, $cookie, $template->output;
  187 
  188 # Local Variables:
  189 # tab-width: 4
  190 # End: