rel_3_0 moved to HEAD
[koha.git] / authorities / authorities-home.pl
index 17a424a..0405ac4 100755 (executable)
@@ -22,27 +22,23 @@ use strict;
 require Exporter;
 use CGI;
 use C4::Auth;
-use HTML::Template;
+
 use C4::Context;
-use C4::Search;
 use C4::Auth;
 use C4::Output;
 use C4::Interface::CGI::Output;
 use C4::AuthoritiesMarc;
-use C4::SearchMarc;
 use C4::Acquisition;
 use C4::Koha; # XXX subfield_is_koha_internal_p
+use C4::Biblio;
 
 my $query=new CGI;
 my $op = $query->param('op');
 my $authtypecode = $query->param('authtypecode');
 my $dbh = C4::Context->dbh;
 
-my $startfrom=$query->param('startfrom');
 my $authid=$query->param('authid');
-$startfrom=0 if(!defined $startfrom);
 my ($template, $loggedinuser, $cookie);
-my $resultsperpage;
 
 my $authtypes = getauthtypes;
 my @authtypesloop;
@@ -60,85 +56,93 @@ if ($op eq "do_search") {
        my @and_or = $query->param('and_or');
        my @excluding = $query->param('excluding');
        my @operator = $query->param('operator');
+       my $orderby = $query->param('orderby');
        my @value = $query->param('value');
 
-       $resultsperpage= $query->param('resultsperpage');
-       $resultsperpage = 19 if(!defined $resultsperpage);
-       my @tags;
-       my ($results,$total) = authoritysearch($dbh, \@marclist,\@and_or,
-                                                                               \@excluding, \@operator, \@value,
-                                                                               $startfrom*$resultsperpage, $resultsperpage,$authtypecode);
-       ($template, $loggedinuser, $cookie)
-               = get_template_and_user({template_name => "authorities/searchresultlist.tmpl",
-                               query => $query,
-                               type => 'intranet',
-                               authnotrequired => 0,
-                               flagsrequired => {borrowers => 1},
-                               flagsrequired => {catalogue => 1},
-                               debug => 1,
-                               });
+    my $startfrom = $query->param('startfrom') || 1;
+    my $resultsperpage = $query->param('resultsperpage') || 19;
+
+       my ($results,$total) = authoritysearch(
+        \@marclist,
+        \@and_or,
+        \@excluding,
+        \@operator,
+        \@value,
+        ($startfrom - 1)*$resultsperpage,
+        $resultsperpage,
+        $authtypecode,
+        $orderby
+    );
 
-       # multi page display gestion
-       my $displaynext=0;
-       my $displayprev=$startfrom;
-       if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){
-               $displaynext = 1;
-       }
+       ($template, $loggedinuser, $cookie)
+               = get_template_and_user({
+            template_name => "authorities/searchresultlist.tmpl",
+            query => $query,
+            type => 'intranet',
+            authnotrequired => 0,
+            flagsrequired => {catalogue => 1},
+            debug => 1,
+        });
 
        my @field_data = ();
 
-
+       # we must get parameters once again. Because if there is a mainentry, it
+       # has been replaced by something else during the search, thus the links
+       # next/previous would not work anymore
+       my @marclist_ini = $query->param('marclist');
        for(my $i = 0 ; $i <= $#marclist ; $i++)
        {
-               push @field_data, { term => "marclist", val=>$marclist[$i] };
-               push @field_data, { term => "and_or", val=>$and_or[$i] };
-               push @field_data, { term => "excluding", val=>$excluding[$i] };
-               push @field_data, { term => "operator", val=>$operator[$i] };
-               push @field_data, { term => "value", val=>$value[$i] };
-       }
-
-       my @numbers = ();
-
-       if ($total>$resultsperpage)
-       {
-               for (my $i=1; $i<$total/$resultsperpage+1; $i++)
-               {
-                       if ($i<16)
-                       {
-                       my $highlight=0;
-                       ($startfrom==($i-1)) && ($highlight=1);
-                       push @numbers, { number => $i,
-                                       highlight => $highlight ,
-                                       searchdata=> \@field_data,
-                                       startfrom => ($i-1)};
-                       }
-       }
+               push @field_data, { term => "marclist"  , val=>$marclist_ini[$i] };
+               push @field_data, { term => "and_or"    , val=>$and_or[$i] };
+               push @field_data, { term => "excluding" , val=>$excluding[$i] };
+               push @field_data, { term => "operator"  , val=>$operator[$i] };
+               push @field_data, { term => "value"     , val=>$value[$i] };
        }
 
-       my $from = $startfrom*$resultsperpage+1;
+    # construction of the url of each page
+    my $base_url =
+        'authorities-home.pl?'
+        .join(
+            '&amp;',
+            map { $_->{term}.'='.$_->{val} } @field_data
+        )
+        .'&amp;'
+        .join(
+            '&amp;',
+            map { $_->{term}.'='.$_->{val} } (
+                {term => 'resultsperpage', val => $resultsperpage},
+                {term => 'type'          , val => 'intranet'},
+                {term => 'op'            , val => 'do_search'},
+                {term => 'authtypecode'  , val => $authtypecode},
+                {term => 'orderby'       , val => $orderby},
+            )
+        )
+        ;
+
+       my $from = ($startfrom - 1) * $resultsperpage + 1;
        my $to;
 
-       if($total < (($startfrom+1)*$resultsperpage))
-       {
+       if ($total < $startfrom * $resultsperpage) {
                $to = $total;
-       } else {
-               $to = (($startfrom+1)*$resultsperpage);
        }
+    else {
+               $to = $startfrom * $resultsperpage;
+       }
+
        $template->param(result => $results) if $results;
+
        $template->param(
-                                                       startfrom=> $startfrom,
-                                                       displaynext=> $displaynext,
-                                                       displayprev=> $displayprev,
-                                                       resultsperpage => $resultsperpage,
-                                                       startfromnext => $startfrom+1,
-                                                       startfromprev => $startfrom-1,
-                                                       searchdata=>\@field_data,
-                                                       total=>$total,
-                                                       from=>$from,
-                                                       to=>$to,
-                                                       numbers=>\@numbers,
-                                                       authtypecode=>$authtypecode,
-                                                       );
+        pagination_bar => pagination_bar(
+            $base_url,
+            int($total/$resultsperpage)+1,
+            $startfrom,
+            'startfrom'
+            ),
+        total=>$total,
+        from=>$from,
+        to=>$to,
+        isEDITORS => $authtypecode eq 'EDITORS',
+    );
 
 } elsif ($op eq "delete") {
 
@@ -189,6 +193,7 @@ elsif ($op eq "AddStatement") {
                my $marclist = create_scrolling_list({name=>"marclist",
                                        values=> $marcarray,
                                        size=> 1,
+                                       -tabindex=>'',
                                        default=>$marcfields[$i],
                                        onChange => "sql_update()"}
                                        );
@@ -222,6 +227,7 @@ elsif ($op eq "AddStatement") {
        my $marclist = create_scrolling_list({name=>"marclist",
                                values=> $marcarray,
                                size=>1,
+                               -tabindex=>'',
                                onChange => "sql_update()"});
        push @statements, {"marclist" => $marclist };
 
@@ -241,7 +247,11 @@ else {
 
 }
 
-$template->param(authtypesloop => \@authtypesloop);
+$template->param(authtypesloop => \@authtypesloop,
+               intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
+               intranetstylesheet => C4::Context->preference("intranetstylesheet"),
+               IntranetNav => C4::Context->preference("IntranetNav"),
+               );
 
 # Print the page
 output_html_with_http_headers $query, $cookie, $template->output;