Patch from Galen Charlton, removing $Id$ $Log$ and $Revision$ from files
[koha.git] / cataloguing / value_builder / unimarc_field_100.pl
1
2 #!/usr/bin/perl
3
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
28 =head1
29
30 plugin_parameters : other parameters added when the plugin is called by the dopop function
31
32 =cut
33
34 sub plugin_parameters {
35     my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
36     return "";
37 }
38
39 sub plugin_javascript {
40     my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
41     my $res           = "
42         <script type='text/javascript'>
43             function Focus$field_number() {
44                 return 1;
45             }
46             
47             function Blur$field_number() {
48                 return 1;
49             }
50             
51             function Clic$field_number(i) {
52                 var defaultvalue;
53                 try {
54                     defaultvalue = document.getElementById(i).value;
55                 } catch(e) {
56                     alert('error when getting '+i);
57                     return;
58                 }
59                 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');
60             }
61         </script>
62 ";
63
64     return ( $field_number, $res );
65 }
66
67 sub plugin {
68     my ($input) = @_;
69     my $index  = $input->param('index');
70     my $result = $input->param('result');
71
72     my $dbh = C4::Context->dbh;
73
74     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
75         {
76             template_name => "cataloguing/value_builder/unimarc_field_100.tmpl",
77             query         => $input,
78             type          => "intranet",
79             authnotrequired => 0,
80             flagsrequired   => { editcatalogue => 1 },
81             debug           => 1,
82         }
83     );
84     $result = '        d        u  y0frey50      ba' unless $result;
85     my $f1 = substr( $result, 0, 8 );
86     if ( $f1 eq '        ' ) {
87         my @today = Date::Calc::Today();
88         $f1 = $today[0] . sprintf('%02s',$today[1]) . sprintf('%02s',$today[2]);
89     }
90     my $f2  = substr( $result, 8,  1 );
91     my $f3  = substr( $result, 9,  4 );
92     $f3='' if $f3 eq '    '; # empty publication year if only spaces, otherwise it's hard to fill the field
93     my $f4  = substr( $result, 13, 4 );
94     $f4='' if $f4 eq '    ';
95     my $f5  = substr( $result, 17, 1 );
96     my $f6  = substr( $result, 18, 1 );
97     my $f7  = substr( $result, 19, 1 );
98     my $f8  = substr( $result, 20, 1 );
99     my $f9  = substr( $result, 21, 1 );
100     my $f10 = substr( $result, 22, 3 );
101     my $f11 = substr( $result, 25, 1 );
102     my $f12 = substr( $result, 26, 2 );
103     my $f13 = substr( $result, 28, 2 );
104     my $f14 = substr( $result, 30, 4 );
105     my $f15 = substr( $result, 34, 2 );
106
107     $template->param(
108         index     => $index,
109         f1        => $f1,
110         f3        => $f3,
111         "f2$f2"   => 1,
112         f4        => $f4,
113         "f5$f5"   => 1,
114         "f6$f6"   => 1,
115         "f7$f7"   => 1,
116         "f8$f8"   => 1,
117         "f9$f9"   => 1,
118         "f10"     => $f10,
119         "f11$f11" => 1,
120         "f12$f12" => 1,
121         "f13$f13" => 1,
122         "f14"     => $f14,
123         "f15$f15" => 1
124     );
125     print $input->header( -type => 'utf-8', -cookie => $cookie ), $template->output;
126 }
127
128 1;