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