Bug 24183: Add before_send_messages hook
[koha.git] / cataloguing / value_builder / unimarc_field_100_authorities.pl
blobac5d50611284986147f6668ab2a600958166e97d
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright (C) 2013 Vitor Fernandes
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use Koha::Util::FrameworkPlugin qw(wrapper);
23 use C4::Auth;
24 use CGI qw ( -utf8 );
25 use C4::Context;
26 use C4::Output;
29 sub plugin_javascript {
30 my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
31 my $res = "
32 <script type='text/javascript'>
33 function Clic$field_number(i) {
34 var defaultvalue;
35 try {
36 defaultvalue = document.getElementById(i).value;
37 } catch(e) {
38 alert('error when getting '+i);
39 return;
41 window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_100_authorities.pl&index=\"+i+\"&result=\"+defaultvalue,\"unimarc_field_100\",'width=1000,height=600,toolbar=false,scrollbars=yes');
43 </script>
46 return ( $field_number, $res );
50 sub plugin {
51 my ($input) = @_;
52 my $index = $input->param('index');
53 my $result = $input->param('result');
55 my $dbh = C4::Context->dbh;
57 my $defaultlanguage = C4::Context->preference("UNIMARCField100Language");
58 $defaultlanguage = "fre" if (!$defaultlanguage || length($defaultlanguage) != 3);
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => "cataloguing/value_builder/unimarc_field_100_authorities.tt",
63 query => $input,
64 type => "intranet",
65 authnotrequired => 0,
66 flagsrequired => { editcatalogue => '*' },
67 debug => 1,
70 $result = " a".$defaultlanguage."y50 ba0" unless $result;
71 my $f1 = substr( $result, 0, 8 );
72 if ( $f1 eq ' ' ) {
73 my @today = Date::Calc::Today();
74 $f1 = $today[0] . sprintf('%02s',$today[1]) . sprintf('%02s',$today[2]);
77 my $f2 = substr( $result, 8, 1 ); $f2 = wrapper( $f2 ) if $f2;
78 my $f3 = substr( $result, 9, 3 );
79 my $f4 = substr( $result, 12, 1 ); $f4 = wrapper( $f4 ) if $f4;
80 my $f5 = substr( $result, 13, 2 ); $f5 = wrapper( $f5 ) if $f5;
81 my $f6 = substr( $result, 15, 2 ); $f6 = wrapper( $f6 ) if $f6;
82 my $f7 = substr( $result, 17, 4 ); $f7 = wrapper( $f7 ) if $f7;
83 my $f8 = substr( $result, 21, 2 ); $f8 = wrapper( $f8 ) if $f8;
84 my $f9 = substr( $result, 23, 1 ); $f9 = wrapper( $f9 ) if $f9;
86 $template->param(
87 index => $index,
88 f1 => $f1,
89 "f2$f2" => 1,
90 f3 => $f3,
91 "f4$f4" => 1,
92 "f5$f5" => 1,
93 "f6$f6" => 1,
94 f7 => $f7,
95 "f8$f8" => 1,
96 "f9$f9" => 1,
98 output_html_with_http_headers $input, $cookie, $template->output;