adding authentification with Auth.pm
[koha.git] / value_builder / unimarc_field_700_701_702.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use C4::Auth;
24 use CGI;
25 use C4::Context;
26 use HTML::Template;
27 use C4::Search;
28 use C4::Output;
29 use C4::Authorities;
30
31 sub plugin_parameters {
32 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
33 return "";
34 }
35 sub plugin_javascript {
36 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
37 my $function_name= "100".(int(rand(100000))+1);
38 my $res="
39 <script>
40 function Focus$function_name(subfield_managed) {
41 return 1;
42 }
43
44 function Blur$function_name(subfield_managed) {
45         return 1;
46 }
47
48 function Clic$function_name(index) {
49         defaultvalue=document.f.field_value[index].value;
50         newin=window.open(\"../plugin_launcher.pl?plugin_name=unimarc_field_700_701_702.pl&index=\"+index+\"&result=\"+defaultvalue,\"unimarc 700\",'width=700,height=300,toolbar=false,scrollbars=yes');
51
52 }
53 </script>
54 ";
55
56 return ($function_name,$res);
57 }
58 sub plugin {
59         my ($input) = @_;
60         my %env;
61         my $dbh = C4::Context->dbh;
62 #       my $input = new CGI;
63         my $index= $input->param('index');
64         my $result= $input->param('result');
65         my $search_string= $input->param('search_string');
66         my $op = $input->param('op');
67         my $id = $input->param('id');
68         my $insert = $input->param('insert');
69         my @freelib;
70         my %stdlib;
71         my $select_list;
72         my ($a,$b,$c,$f) ; # the 4 managed subfields.
73         if ($op eq "add") {
74                 newauthority($dbh,'NP',$insert,$insert,'',1,'');
75                 $search_string=$insert;
76         }
77         if ($op eq "select") {
78                 my $sti = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
79                 $sti->execute($id);
80                 my ($freelib_text) = $sti->fetchrow_array;
81                 $result = $freelib_text;
82                 # fill the 4 managed subfields
83                 my @arr = split //,$result;
84                 my $where = 1;
85                 foreach my $x (@arr) {
86                         next if ($x eq ')');
87                         if ($x eq ',') {
88                                 $where=2;
89                                 next;
90                         }
91                         if ($x eq '(') {
92                                 if ($result =~ /.*;.*/) {
93                                         $where=3;
94                                 } else {
95                                         $where=4;
96                                 }
97                                 next;
98                         }
99                         if ($x eq ';') {
100                                 $where=4;
101                                 next;
102                         }
103                         if ($where eq 1) {
104                                 $a.=$x;
105                         }
106                         if ($where eq 2) {
107                                 $b.=$x;
108                         }
109                         if ($where eq 3) {
110                                 $c.=$x;
111                         }
112                         if ($where eq 4) {
113                                 $f.=$x;
114                         }
115                 }
116 # remove trailing blanks
117                 $a=~ s/^\s+//g;
118                 $b=~ s/^\s+//g;
119                 $c=~ s/^\s+//g;
120                 $f=~ s/^\s+//g;
121                 $a=~ s/\s+$//g;
122                 $b=~ s/\s+$//g;
123                 $c=~ s/\s+$//g;
124                 $f=~ s/^s+$//g;
125         }
126         if ($search_string) {
127         #       my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where freelib like '".$search_string."%' and category ='$category'");
128                 my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where match (category,freelib) AGAINST ('$search_string') and category ='NP'");
129                 $sti->execute;
130                 while (my $line=$sti->fetchrow_hashref) {
131                         $stdlib{$line->{'id'}} = "$line->{'freelib'}";
132                         push(@freelib,$line->{'id'});
133                 }
134                 $select_list= CGI::scrolling_list( -name=>'id',
135                                 -values=> \@freelib,
136                                 -default=> "",
137                                 -size=>1,
138                                 -multiple=>0,
139                                 -labels=> \%stdlib
140                                 );
141         }
142         my ($template, $loggedinuser, $cookie)
143         = get_template_and_user({template_name => "value_builder/unimarc_field_700_701_702.tmpl",
144                                         query => $input,
145                                         type => "intranet",
146                                         authnotrequired => 0,
147                                         flagsrequired => {parameters => 1},
148                                         debug => 1,
149                                         });
150 # builds collection list : search isbn and editor, in parent, then load collections from bibliothesaurus table
151         $template->param(index => $index,
152                                                         result =>$result,
153                                                         select_list => $select_list,
154                                                         search_string => $search_string,
155                                                         a => $a,
156                                                         b => $b,
157                                                         c => $c,
158                                                         f => $f,);
159         print $input->header(-cookie => $cookie),$template->output;
160 }
161
162 1;