Bug 2505 - Add commented use warnings where missing in the cataloguing/ directory
[koha.git] / cataloguing / value_builder / unimarc_field_100.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
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use C4::Auth;
24 use CGI;
25 use C4::Context;
26 use C4::Output;
27
28
29 =head1
30
31 plugin_parameters : other parameters added when the plugin is called by the dopop function
32
33 =cut
34
35 sub plugin_parameters {
36     my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
37     return "";
38 }
39
40 sub plugin_javascript {
41     my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
42     my $res           = "
43         <script type='text/javascript'>
44             function Focus$field_number() {
45                 return 1;
46             }
47             
48             function Blur$field_number() {
49                 return 1;
50             }
51             
52             function Clic$field_number(i) {
53                 var defaultvalue;
54                 try {
55                     defaultvalue = document.getElementById(i).value;
56                 } catch(e) {
57                     alert('error when getting '+i);
58                     return;
59                 }
60                 window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_100.pl&index=\"+i+\"&result=\"+defaultvalue,\"unimarc field 100\",'width=1000,height=600,toolbar=false,scrollbars=yes');
61             }
62         </script>
63 ";
64
65     return ( $field_number, $res );
66 }
67
68 sub plugin {
69     my ($input) = @_;
70     my $index  = $input->param('index');
71     my $result = $input->param('result');
72
73     my $dbh = C4::Context->dbh;
74
75     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
76         {
77             template_name => "cataloguing/value_builder/unimarc_field_100.tmpl",
78             query         => $input,
79             type          => "intranet",
80             authnotrequired => 0,
81             flagsrequired   => { editcatalogue => '*' },
82             debug           => 1,
83         }
84     );
85     $result = '        d        u  y0frey50      ba' unless $result;
86     my $f1 = substr( $result, 0, 8 );
87     if ( $f1 eq '        ' ) {
88         my @today = Date::Calc::Today();
89         $f1 = $today[0] . sprintf('%02s',$today[1]) . sprintf('%02s',$today[2]);
90     }
91     my $f2  = substr( $result, 8,  1 );
92     my $f3  = substr( $result, 9,  4 );
93     $f3='' if $f3 eq '    '; # empty publication year if only spaces, otherwise it's hard to fill the field
94     my $f4  = substr( $result, 13, 4 );
95     $f4='' if $f4 eq '    ';
96     my $f5  = substr( $result, 17, 1 );
97     my $f6  = substr( $result, 18, 1 );
98     my $f7  = substr( $result, 19, 1 );
99     my $f8  = substr( $result, 20, 1 );
100     my $f9  = substr( $result, 21, 1 );
101     my $f10 = substr( $result, 22, 3 );
102     my $f11 = substr( $result, 25, 1 );
103     my $f12 = substr( $result, 26, 2 );
104     my $f13 = substr( $result, 28, 2 );
105     my $f14 = substr( $result, 30, 4 );
106     my $f15 = substr( $result, 34, 2 );
107
108     $template->param(
109         index     => $index,
110         f1        => $f1,
111         f3        => $f3,
112         "f2$f2"   => 1,
113         f4        => $f4,
114         "f5$f5"   => 1,
115         "f6$f6"   => 1,
116         "f7$f7"   => 1,
117         "f8$f8"   => 1,
118         "f9$f9"   => 1,
119         "f10"     => $f10,
120         "f11$f11" => 1,
121         "f12$f12" => 1,
122         "f13$f13" => 1,
123         "f14"     => $f14,
124         "f15$f15" => 1
125     );
126     output_html_with_http_headers $input, $cookie, $template->output;
127 }
128
129 1;