*** empty log message ***
[koha.git] / thesaurus_popup.pl
index 1a01179..2873570 100755 (executable)
 # Suite 330, Boston, MA  02111-1307 USA
 
 use strict;
+use C4::Auth;
 use CGI;
 use C4::Context;
 use HTML::Template;
 use C4::Search;
-#use C4::Circulation::Circ2;
 use C4::Output;
-#use C4::Biblio;
-
+use C4::Authorities;
 # get all the data ....
 my %env;
 
@@ -40,6 +39,7 @@ my $op = $input->param('op');
 my $id = $input->param('id');
 my $category = $input->param('category');
 my $index= $input->param('index');
+my $insert = $input->param('insert');
 
 my $dbh = C4::Context->dbh;
 
@@ -55,15 +55,26 @@ if ($op eq "select") {
                $result = $freelib_text;
        }
 }
-
-my $template = gettemplate("thesaurus_popup.tmpl",0);
+if ($op eq "add") {
+       newauthority($dbh,$category,$insert,$insert,'',1,'');
+       $search_string=$insert;
+}
+my ($template, $loggedinuser, $cookie)
+    = get_template_and_user({template_name => "thesaurus_popup.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
 # /search thesaurus terms starting by search_string
 my @freelib;
 my %stdlib;
 my $select_list;
 if ($search_string) {
-       my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where freelib like '".$search_string."%' and category ='$category'");
-       $sti->execute;
+#      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 (?) and category ='$category'");
+       $sti->execute($search_string);
        while (my $line=$sti->fetchrow_hashref) {
                $stdlib{$line->{'id'}} = "$line->{'freelib'}";
                push(@freelib,$line->{'id'});
@@ -82,6 +93,6 @@ $template->param(select_list => $select_list,
                                                category => $category,
                                                index => $index
                                                );
-print "Content-Type: text/html\n\n", $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;