Bug 14585: Fixing up online help on main page
[koha.git] / cataloguing / value_builder / unimarc_field_100.pl
blobdc5fdd11ba83c38c3c139f382f1d12f9922e6f2e
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use strict;
22 #use warnings; FIXME - Bug 2505
24 use Koha::Util::FrameworkPlugin qw(wrapper);
25 use C4::Auth;
26 use CGI;
27 use C4::Context;
28 use C4::Output;
31 =head1 FUNCTIONS
33 =head2 plugin_parameters
35 Other parameters added when the plugin is called by the dopop function
37 =cut
39 sub plugin_parameters {
40 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
41 return "";
44 sub plugin_javascript {
45 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
46 my $res = "
47 <script type='text/javascript'>
48 function Focus$field_number() {
49 return 1;
52 function Blur$field_number() {
53 return 1;
56 function Clic$field_number(i) {
57 var defaultvalue;
58 try {
59 defaultvalue = document.getElementById(i).value;
60 } catch(e) {
61 alert('error when getting '+i);
62 return;
64 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');
66 </script>
69 return ( $field_number, $res );
73 sub plugin {
74 my ($input) = @_;
75 my $index = $input->param('index');
76 my $result = $input->param('result');
78 my $dbh = C4::Context->dbh;
80 my $defaultlanguage = C4::Context->preference("UNIMARCField100Language");
81 $defaultlanguage = "fre" if (!$defaultlanguage || length($defaultlanguage) != 3);
83 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
85 template_name => "cataloguing/value_builder/unimarc_field_100.tt",
86 query => $input,
87 type => "intranet",
88 authnotrequired => 0,
89 flagsrequired => { editcatalogue => '*' },
90 debug => 1,
93 $result = " d u y0".$defaultlanguage."y50 ba" unless $result;
94 my $f1 = substr( $result, 0, 8 );
95 if ( $f1 eq ' ' ) {
96 my @today = Date::Calc::Today();
97 $f1 = $today[0] . sprintf('%02s',$today[1]) . sprintf('%02s',$today[2]);
99 my $f2 = substr( $result, 8, 1 ); $f2 = wrapper( $f2 ) if $f2;
100 my $f3 = substr( $result, 9, 4 );
101 $f3='' if $f3 eq ' '; # empty publication year if only spaces, otherwise it's hard to fill the field
102 my $f4 = substr( $result, 13, 4 );
103 $f4='' if $f4 eq ' ';
104 my $f5 = substr( $result, 17, 1 ); $f5 = wrapper( $f5 ) if $f5;
105 my $f6 = substr( $result, 18, 1 ); $f6 = wrapper( $f6 ) if $f6;
106 my $f7 = substr( $result, 19, 1 ); $f7 = wrapper( $f7 ) if $f7;
107 my $f8 = substr( $result, 20, 1 );
108 my $f9 = substr( $result, 21, 1 );
109 my $f10 = substr( $result, 22, 3 );
110 my $f11 = substr( $result, 25, 1 );
111 my $f12 = substr( $result, 26, 2 );
112 my $f13 = substr( $result, 28, 2 );
113 my $f14 = substr( $result, 30, 4 );
114 my $f15 = substr( $result, 34, 2 ); $f15 = wrapper( $f15 ) if $f15;
116 $template->param(
117 index => $index,
118 f1 => $f1,
119 f3 => $f3,
120 "f2$f2" => 1,
121 f4 => $f4,
122 "f5$f5" => 1,
123 "f6$f6" => 1,
124 "f7$f7" => 1,
125 "f8$f8" => 1,
126 "f9$f9" => 1,
127 "f10" => $f10,
128 "f11$f11" => 1,
129 "f12$f12" => 1,
130 "f13$f13" => 1,
131 "f14" => $f14,
132 "f15$f15" => 1
134 output_html_with_http_headers $input, $cookie, $template->output;