MT 2050, Follow-up, Fast Cataloging
[koha.git] / cataloguing / value_builder / unimarc_field_4XX.pl
index b97f27b..58a82bf 100755 (executable)
@@ -31,6 +31,7 @@ use C4::Biblio;
 use C4::Koha;
 use MARC::Record;
 use C4::Branch;    # GetBranches
+use C4::ItemType;
 
 sub plugin_parameters {
     my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
@@ -52,7 +53,7 @@ sub plugin_javascript {
 
         function Clic$function_name(i) {
             defaultvalue=document.getElementById(\"$field_number\").value;
-            window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_4XX.pl&index=$field_number&result=\"+defaultvalue,\"unimarc field 4\"+i+\"\",'width=900,height=700,toolbar=false,scrollbars=yes');
+            window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_4XX.pl&index=\" + i + \"&result=\"+defaultvalue,\"unimarc field 4\"+i+\"\",'width=900,height=700,toolbar=false,scrollbars=yes');
 
         }
     </script>
@@ -94,7 +95,7 @@ sub plugin {
                 query           => $query,
                 type            => "intranet",
                 authnotrequired => 0,
-                flagsrequired   => { editcatalogue => 1 },
+                flagsrequired   => { editcatalogue => '*' },
                 debug           => 1,
             }
         );
@@ -327,10 +328,12 @@ sub plugin {
     }
     elsif ( $op eq "do_search" ) {
         my $search         = $query->param('search');
+        my $itype          = $query->param('itype');
         my $startfrom      = $query->param('startfrom');
         my $resultsperpage = $query->param('resultsperpage') || 20;
         my $orderby;
-        my ( $errors, $results, $total_hits ) = SimpleSearch($search, $startfrom, $resultsperpage );
+        $search = 'kw,wrdl='.$search.' and mc-itemtype='.$itype if $itype;
+        my ( $errors, $results, $total_hits ) = SimpleSearch($search, $startfrom * $resultsperpage, $resultsperpage );
         my $total = scalar(@$results);
 
         #        warn " biblio count : ".$total;
@@ -349,17 +352,15 @@ sub plugin {
         # multi page display gestion
         my $displaynext = 0;
         my $displayprev = $startfrom;
-        if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
+
+        if( ( $total_hits - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
             $displaynext = 1;
         }
         my @arrayresults;
         my @field_data = ($search);
          for (
-             my $i = $startfrom * $resultsperpage ;
-             $i < (( $startfrom * $resultsperpage + $resultsperpage  < scalar(@$results))
-                 ? $startfrom * $resultsperpage + $resultsperpage
-                 : scalar(@$results)
-             ) ;
+             my $i = 0 ;
+             $i < $resultsperpage ;
              $i++
            )
          {
@@ -414,11 +415,10 @@ sub plugin {
         my $from = $startfrom * $resultsperpage + 1;
         my $to;
 
-        if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
-            $to = $total;
-        }
-        else {
-            $to = ( ( $startfrom + 1 ) * $resultsperpage );
+        if ( $total_hits < $from + $resultsperpage ) {
+            $to = $total_hits;
+        }else{
+            $to = $from + $resultsperpage ;
         }
         my $defaultview =
           'BiblioDefaultView' . C4::Context->preference('BiblioDefaultView');
@@ -445,7 +445,7 @@ sub plugin {
             startfromnext  => $startfrom + 1,
             startfromprev  => $startfrom - 1,
             searchdata     => \@field_data,
-            total          => $total,
+            total          => $total_hits,
             from           => $from,
             to             => $to,
             numbers        => \@numbers,
@@ -533,10 +533,13 @@ sub plugin {
 #         }
 #         $sth->finish;
 
+        my @itemtypes = C4::ItemType->all;
+
         $template->param(    #classlist => $classlist,
             CGIitemtype  => $CGIitemtype,
             CGIbranch    => $CGIbranch,
             CGIPublisher => $CGIpublisher,
+            itypeloop    => \@itemtypes,
             index        => $query->param('index'),
             Search       => 1,
         );