synch'ing 2.2 and head
[koha.git] / value_builder / unimarc_field_700_701_702.pl
index ee30274..dd899d0 100644 (file)
@@ -20,6 +20,7 @@
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
+use C4::Auth;
 use CGI;
 use C4::Context;
 use HTML::Template;
@@ -27,12 +28,8 @@ use C4::Search;
 use C4::Output;
 use C4::Authorities;
 
-sub plugin_parameters {
-my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
-return "";
-}
 sub plugin_javascript {
-my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
+my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
 my $function_name= "100".(int(rand(100000))+1);
 my $res="
 <script>
@@ -124,8 +121,8 @@ sub plugin {
        }
        if ($search_string) {
        #       my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where freelib like '".$search_string."%' and category ='$category'");
-               my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where match (category,freelib) AGAINST ('$search_string') and category ='NP'");
-               $sti->execute;
+               my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where match (category,freelib) AGAINST (?) and category ='NP'");
+               $sti->execute($search_string);
                while (my $line=$sti->fetchrow_hashref) {
                        $stdlib{$line->{'id'}} = "$line->{'freelib'}";
                        push(@freelib,$line->{'id'});
@@ -138,17 +135,24 @@ sub plugin {
                                -labels=> \%stdlib
                                );
        }
-       my $template = gettemplate("value_builder/unimarc_field_700_701_702.tmpl",0);
+       my ($template, $loggedinuser, $cookie)
+       = get_template_and_user({template_name => "value_builder/unimarc_field_700_701_702.tmpl",
+                                       query => $input,
+                                       type => "intranet",
+                                       authnotrequired => 0,
+                                       flagsrequired => {parameters => 1},
+                                       debug => 1,
+                                       });
 # builds collection list : search isbn and editor, in parent, then load collections from bibliothesaurus table
        $template->param(index => $index,
                                                        result =>$result,
                                                        select_list => $select_list,
-                                                       search_string => $search_string,
+                                                       search_string => $search_string?$search_string:$result,
                                                        a => $a,
                                                        b => $b,
                                                        c => $c,
                                                        f => $f,);
-       print "Content-Type: text/html\n\n", $template->output;
+       print $input->header(-cookie => $cookie),$template->output;
 }
 
 1;