Bug 13969: Replace calls to $sth->fetchrow* with a call to $dbh->selectrow* and Clean...
[koha.git] / cataloguing / value_builder / marc21_linking_section.pl
index f317f8b..8407ace 100644 (file)
@@ -4,23 +4,23 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use strict;
 use warnings;
 
-use CGI;
+use CGI qw ( -utf8 );
 use C4::Output;
 use C4::Context;
 use C4::Search;
@@ -33,24 +33,11 @@ use MARC::Record;
 use C4::Branch;
 use C4::ItemType;
 
-sub plugin_parameters {
- my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
-     return "";
-}
-
 sub plugin_javascript {
   my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
   my $function_name = $field_number;
      my $res           = "
   <script type='text/javascript'>
-                function Focus$function_name(subfield_managed) {
-                       return 1;
-              }
-
-             function Blur$function_name(subfield_managed) {
-                        return 1;
-              }
-
              function Clic$function_name(i) {
                        defaultvalue=document.getElementById(\"$field_number\").value;
                  window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=marc21_linking_section.pl&index=\" + i + \"&result=\"+defaultvalue,\"marc21_field_7\"+i+\"\",'width=900,height=700,toolbar=false,scrollbars=yes');
@@ -190,7 +177,15 @@ sub plugin {
            my $startfrom      = $query->param('startfrom');
                my $resultsperpage = $query->param('resultsperpage') || 20;
             my $orderby;
-           $search = 'kw,wrdl=' . $search . ' and mc-itemtype=' . $itype if $itype;
+            my $QParser;
+            $QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
+            my $op;
+            if ($QParser) {
+                $op = '&&';
+            } else {
+                $op = 'and';
+            }
+           $search = 'kw:' . $search . " $op mc-itemtype:" . $itype if $itype;
                my ( $errors, $results, $total_hits ) =
                   SimpleSearch( $search, $startfrom * $resultsperpage,
                  $resultsperpage );
@@ -223,7 +218,7 @@ sub plugin {
               my @arrayresults;
               my @field_data = ($search);
             for ( my $i = 0 ; $i < $resultsperpage ; $i++ ) {
-                      my $record = MARC::Record::new_from_usmarc( $results->[$i] );
+                  my $record = C4::Search::new_record_from_zebra( 'biblioserver', $results->[$i] );
                   my $rechash = TransformMarcToKoha( $dbh, $record );
                     my $pos;
                        my $countitems = $rechash->{itembumber} ? 1 : 0;
@@ -327,83 +322,13 @@ sub plugin {
                   }
               );
 
-            my $sth = $dbh->prepare(
-                       "Select itemtype,description from itemtypes order by description");
-            $sth->execute;
-         my @itemtype;
-          my %itemtypes;
-         push @itemtype, "";
-            $itemtypes{''} = "";
-           while ( my ( $value, $lib ) = $sth->fetchrow_array ) {
-                 push @itemtype, $value;
-                        $itemtypes{$value} = $lib;
-             }
+            my @itemtypes = C4::ItemType->all;
 
-             my $CGIitemtype = CGI::scrolling_list(
-                 -name     => 'value',
-                  -values   => \@itemtype,
-                       -labels   => \%itemtypes,
-                      -size     => 1,
-                        -multiple => 0
-         );
-             $sth->finish;
-
-         my @branchloop;
-                my @select_branch;
-             my %select_branches;
-           my $branches = GetBranches;
-            push @select_branch, "";
-               $select_branches{''} = "";
-             foreach my $thisbranch ( keys %$branches ) {
-                   push @select_branch, $branches->{$thisbranch}->{'branchcode'};
-                 $select_branches{ $branches->{$thisbranch}->{'branchcode'} } =
-                   $branches->{$thisbranch}->{'branchname'};
-            }
-              my $CGIbranch = CGI::scrolling_list(
-                   -name     => 'value',
-                  -values   => \@select_branch,
-                  -labels   => \%select_branches,
-                        -size     => 1,
-                        -multiple => 0
-         );
-             $sth->finish;
-
-         my $req = $dbh->prepare(
-"select distinctrow left(publishercode,45) from biblioitems order by publishercode"
-           );
-             $req->execute;
-         my @select;
-            push @select, "";
-              while ( my ($value) = $req->fetchrow ) {
-                       push @select, $value;
-          }
-              my $CGIpublisher = CGI::scrolling_list(
-                        -name     => 'value',
-                  -id       => 'publisher',
-                      -values   => \@select,
-                 -size     => 1,
-                        -multiple => 0
-         );
-
-#         my $sth=$dbh->prepare("select description,itemtype from itemtypes order by description");
-#         $sth->execute;
-#         while (my ($description,$itemtype) = $sth->fetchrow) {
-#             $classlist.="<option value=\"$itemtype\">$description</option>\n";
-#         }
-#         $sth->finish;
-
-                my @itemtypes = C4::ItemType->all;
-
-            $template->param(    #classlist => $classlist,
-                 CGIitemtype  => $CGIitemtype,
-                  CGIbranch    => $CGIbranch,
-                    CGIPublisher => $CGIpublisher,
-                 itypeloop    => \@itemtypes,
-                   index        => $query->param('index'),
+            $template->param(
+                        itypeloop    => \@itemtypes,
+                        index        => $query->param('index'),
                         Search       => 1,
-             );
+            );
      }
       output_html_with_http_headers $query, $cookie, $template->output;
 }
-
-1;