Bug 5502 - Patron card category search field should be menu
[koha.git] / cataloguing / value_builder / unimarc_field_100_authorities.pl
blobd929e885a9e6cc4a6b0e5145a19bbc9962a4ca72
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;
21 use C4::Auth;
22 use CGI;
23 use C4::Context;
24 use C4::Output;
27 =head1 FUNCTIONS
29 =head2 plugin_parameters
31 Other parameters added when the plugin is called by the dopop function
33 =cut
35 sub plugin_parameters {
36 my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
37 return "";
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;
48 function Blur$field_number() {
49 return 1;
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;
60 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');
62 </script>
65 return ( $field_number, $res );
68 sub wrapper {
69 my ($char) = @_;
70 return "space" if $char eq " ";
71 return "dblspace" if $char eq " ";
72 return "pipe" if $char eq "|";
73 return $char;
76 sub plugin {
77 my ($input) = @_;
78 my $index = $input->param('index');
79 my $result = $input->param('result');
81 my $dbh = C4::Context->dbh;
83 my $defaultlanguage = C4::Context->preference("UNIMARCField100Language");
84 $defaultlanguage = "fre" if (!$defaultlanguage || length($defaultlanguage) != 3);
86 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
88 template_name => "cataloguing/value_builder/unimarc_field_100_authorities.tt",
89 query => $input,
90 type => "intranet",
91 authnotrequired => 0,
92 flagsrequired => { editcatalogue => '*' },
93 debug => 1,
96 $result = " a".$defaultlanguage."y50 ba0" unless $result;
97 my $f1 = substr( $result, 0, 8 );
98 if ( $f1 eq ' ' ) {
99 my @today = Date::Calc::Today();
100 $f1 = $today[0] . sprintf('%02s',$today[1]) . sprintf('%02s',$today[2]);
103 my $f2 = substr( $result, 8, 1 ); $f2 = wrapper( $f2 ) if $f2;
104 my $f3 = substr( $result, 9, 3 );
105 my $f4 = substr( $result, 12, 1 ); $f4 = wrapper( $f4 ) if $f4;
106 my $f5 = substr( $result, 13, 2 ); $f5 = wrapper( $f5 ) if $f5;
107 my $f6 = substr( $result, 15, 2 ); $f6 = wrapper( $f6 ) if $f6;
108 my $f7 = substr( $result, 17, 4 ); $f7 = wrapper( $f7 ) if $f7;
109 my $f8 = substr( $result, 21, 2 ); $f8 = wrapper( $f8 ) if $f8;
110 my $f9 = substr( $result, 23, 1 ); $f9 = wrapper( $f9 ) if $f9;
112 $template->param(
113 index => $index,
114 f1 => $f1,
115 "f2$f2" => 1,
116 f3 => $f3,
117 "f4$f4" => 1,
118 "f5$f5" => 1,
119 "f6$f6" => 1,
120 f7 => $f7,
121 "f8$f8" => 1,
122 "f9$f9" => 1,
124 output_html_with_http_headers $input, $cookie, $template->output;