Bug 13200 - Followup of Bug 12246 - noisy C4/Auth.pm
[koha.git] / cataloguing / value_builder / unimarc_field_100.pl
blob6a660d39458e853d8a8805a9fcf6f29bf3e493e0
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 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.
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.
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.
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use C4::Auth;
24 use CGI;
25 use C4::Context;
26 use C4::Output;
29 =head1 FUNCTIONS
31 =head2 plugin_parameters
33 Other parameters added when the plugin is called by the dopop function
35 =cut
37 sub plugin_parameters {
38 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
39 return "";
42 sub plugin_javascript {
43 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
44 my $res = "
45 <script type='text/javascript'>
46 function Focus$field_number() {
47 return 1;
50 function Blur$field_number() {
51 return 1;
54 function Clic$field_number(i) {
55 var defaultvalue;
56 try {
57 defaultvalue = document.getElementById(i).value;
58 } catch(e) {
59 alert('error when getting '+i);
60 return;
62 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');
64 </script>
67 return ( $field_number, $res );
70 sub wrapper {
71 my ($char) = @_;
72 return "space" if $char eq " ";
73 return "dblspace" if $char eq " ";
74 return "pipe" if $char eq "|";
75 return $char;
78 sub plugin {
79 my ($input) = @_;
80 my $index = $input->param('index');
81 my $result = $input->param('result');
83 my $dbh = C4::Context->dbh;
85 my $defaultlanguage = C4::Context->preference("UNIMARCField100Language");
86 $defaultlanguage = "fre" if (!$defaultlanguage || length($defaultlanguage) != 3);
88 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
90 template_name => "cataloguing/value_builder/unimarc_field_100.tt",
91 query => $input,
92 type => "intranet",
93 authnotrequired => 0,
94 flagsrequired => { editcatalogue => '*' },
95 debug => 1,
98 $result = " d u y0".$defaultlanguage."y50 ba" unless $result;
99 my $f1 = substr( $result, 0, 8 );
100 if ( $f1 eq ' ' ) {
101 my @today = Date::Calc::Today();
102 $f1 = $today[0] . sprintf('%02s',$today[1]) . sprintf('%02s',$today[2]);
104 my $f2 = substr( $result, 8, 1 ); $f2 = wrapper( $f2 ) if $f2;
105 my $f3 = substr( $result, 9, 4 );
106 $f3='' if $f3 eq ' '; # empty publication year if only spaces, otherwise it's hard to fill the field
107 my $f4 = substr( $result, 13, 4 );
108 $f4='' if $f4 eq ' ';
109 my $f5 = substr( $result, 17, 1 ); $f5 = wrapper( $f5 ) if $f5;
110 my $f6 = substr( $result, 18, 1 ); $f6 = wrapper( $f6 ) if $f6;
111 my $f7 = substr( $result, 19, 1 ); $f7 = wrapper( $f7 ) if $f7;
112 my $f8 = substr( $result, 20, 1 );
113 my $f9 = substr( $result, 21, 1 );
114 my $f10 = substr( $result, 22, 3 );
115 my $f11 = substr( $result, 25, 1 );
116 my $f12 = substr( $result, 26, 2 );
117 my $f13 = substr( $result, 28, 2 );
118 my $f14 = substr( $result, 30, 4 );
119 my $f15 = substr( $result, 34, 2 ); $f15 = wrapper( $f15 ) if $f15;
121 $template->param(
122 index => $index,
123 f1 => $f1,
124 f3 => $f3,
125 "f2$f2" => 1,
126 f4 => $f4,
127 "f5$f5" => 1,
128 "f6$f6" => 1,
129 "f7$f7" => 1,
130 "f8$f8" => 1,
131 "f9$f9" => 1,
132 "f10" => $f10,
133 "f11$f11" => 1,
134 "f12$f12" => 1,
135 "f13$f13" => 1,
136 "f14" => $f14,
137 "f15$f15" => 1
139 output_html_with_http_headers $input, $cookie, $template->output;