functions that were in C4::Interface::CGI::Output are now in C4::Output.
[koha.git] / cataloguing / 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
27 use C4::Search;
28 use C4::Output;
29 use C4::Authorities;
30
31 sub plugin_javascript {
32 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
33 my $function_name= "100".(int(rand(100000))+1);
34 my $res="
35 <script>
36 function Focus$function_name(subfield_managed) {
37 return 1;
38 }
39
40 function Blur$function_name(subfield_managed) {
41         return 1;
42 }
43
44 function Clic$function_name(index) {
45         defaultvalue=document.f.field_value[index].value;
46         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');
47
48 }
49 </script>
50 ";
51
52 return ($function_name,$res);
53 }
54 sub plugin {
55         my ($input) = @_;
56         my $dbh = C4::Context->dbh;
57 #       my $input = new CGI;
58         my $index= $input->param('index');
59         my $result= $input->param('result');
60         my $search_string= $input->param('search_string');
61         my $op = $input->param('op');
62         my $id = $input->param('id');
63         my $insert = $input->param('insert');
64         my @freelib;
65         my %stdlib;
66         my $select_list;
67         my ($a,$b,$c,$f) ; # the 4 managed subfields.
68         if ($op eq "add") {
69                 newauthority($dbh,'NP',$insert,$insert,'',1,'');
70                 $search_string=$insert;
71         }
72         if ($op eq "select") {
73                 my $sti = $dbh->prepare("select stdlib from bibliothesaurus where id=?");
74                 $sti->execute($id);
75                 my ($freelib_text) = $sti->fetchrow_array;
76                 $result = $freelib_text;
77                 # fill the 4 managed subfields
78                 my @arr = split //,$result;
79                 my $where = 1;
80                 foreach my $x (@arr) {
81                         next if ($x eq ')');
82                         if ($x eq ',') {
83                                 $where=2;
84                                 next;
85                         }
86                         if ($x eq '(') {
87                                 if ($result =~ /.*;.*/) {
88                                         $where=3;
89                                 } else {
90                                         $where=4;
91                                 }
92                                 next;
93                         }
94                         if ($x eq ';') {
95                                 $where=4;
96                                 next;
97                         }
98                         if ($where eq 1) {
99                                 $a.=$x;
100                         }
101                         if ($where eq 2) {
102                                 $b.=$x;
103                         }
104                         if ($where eq 3) {
105                                 $c.=$x;
106                         }
107                         if ($where eq 4) {
108                                 $f.=$x;
109                         }
110                 }
111 # remove trailing blanks
112                 $a=~ s/^\s+//g;
113                 $b=~ s/^\s+//g;
114                 $c=~ s/^\s+//g;
115                 $f=~ s/^\s+//g;
116                 $a=~ s/\s+$//g;
117                 $b=~ s/\s+$//g;
118                 $c=~ s/\s+$//g;
119                 $f=~ s/^s+$//g;
120         }
121         if ($search_string) {
122         #       my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where freelib like '".$search_string."%' and category ='$category'");
123                 my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where match (category,freelib) AGAINST (?) and category ='NP'");
124                 $sti->execute($search_string);
125                 while (my $line=$sti->fetchrow_hashref) {
126                         $stdlib{$line->{'id'}} = "$line->{'freelib'}";
127                         push(@freelib,$line->{'id'});
128                 }
129                 $select_list= CGI::scrolling_list( -name=>'id',
130                                 -values=> \@freelib,
131                                 -default=> "",
132                                 -size=>1,
133                                 -multiple=>0,
134                                 -labels=> \%stdlib
135                                 );
136         }
137         my ($template, $loggedinuser, $cookie)
138         = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_700_701_702.tmpl",
139                                         query => $input,
140                                         type => "intranet",
141                                         authnotrequired => 0,
142                                         flagsrequired => { editcatalogue => 1},
143                                         debug => 1,
144                                         });
145 # builds collection list : search isbn and editor, in parent, then load collections from bibliothesaurus table
146         $template->param(index => $index,
147                                                         result =>$result,
148                                                         select_list => $select_list,
149                                                         search_string => $search_string?$search_string:$result,
150                                                         a => $a,
151                                                         b => $b,
152                                                         c => $c,
153                                                         f => $f,);
154         print $input->header(-cookie => $cookie),$template->output;
155 }
156
157 1;