don t display the 1 in location column if there is only 1 item : it's useless & confu...
[koha.git] / cataloguing / value_builder / unimarc_field_100.pl
1
2 #!/usr/bin/perl
3
4 # $Id$
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 use C4::Auth;
25 use CGI;
26 use C4::Context;
27
28 use C4::Search;
29 use C4::Output;
30
31 =head1
32
33 plugin_parameters : other parameters added when the plugin is called by the dopop function
34
35 =cut
36
37 sub plugin_parameters {
38     my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_;
39     return "";
40 }
41
42 sub plugin_javascript {
43     my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
44     my $function_name = "100" . ( int( rand(100000) ) + 1 );
45     my $res           = "
46 <script>
47 function Focus$function_name(subfield_managed) {
48 return 1;
49 }
50
51 function Blur$function_name(subfield_managed) {
52     return 1;
53 }
54
55 function Clic$function_name(i) {
56     defaultvalue=document.forms['f'].field_value[i].value;
57     newin=window.open(\"../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');
58
59 }
60 </script>
61 ";
62
63     return ( $function_name, $res );
64 }
65
66 sub plugin {
67     my ($input) = @_;
68     my $index  = $input->param('index');
69     my $result = $input->param('result');
70
71     my $dbh = C4::Context->dbh;
72
73     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
74         {
75             template_name => "cataloguing/value_builder/unimarc_field_100.tmpl",
76             query         => $input,
77             type          => "intranet",
78             authnotrequired => 0,
79             flagsrequired   => { editcatalogue => 1 },
80             debug           => 1,
81         }
82     );
83     $result = '        d        u  y0frey50      ba' unless $result;
84     my $f1 = substr( $result, 0, 8 );
85     if ( $f1 eq '        ' ) {
86         my @today = Date::Calc::Today();
87         $f1 = $today[0] . sprintf('%02s',$today[1]) . sprintf('%02s',$today[2]);
88     }
89     my $f2  = substr( $result, 8,  1 );
90     my $f3  = substr( $result, 9,  4 );
91     $f3='' if $f3 eq '    '; # empty publication year if only spaces, otherwise it's hard to fill the field
92     my $f4  = substr( $result, 13, 4 );
93     $f4='' if $f4 eq '    ';
94     my $f5  = substr( $result, 17, 1 );
95     my $f6  = substr( $result, 18, 1 );
96     my $f7  = substr( $result, 19, 1 );
97     my $f8  = substr( $result, 20, 1 );
98     my $f9  = substr( $result, 21, 1 );
99     my $f10 = substr( $result, 22, 3 );
100     my $f11 = substr( $result, 25, 1 );
101     my $f12 = substr( $result, 26, 2 );
102     my $f13 = substr( $result, 28, 2 );
103     my $f14 = substr( $result, 30, 4 );
104     my $f15 = substr( $result, 34, 2 );
105
106     $template->param(
107         index     => $index,
108         f1        => $f1,
109         f3        => $f3,
110         "f2$f2"   => 1,
111         f4        => $f4,
112         "f5$f5"   => 1,
113         "f6$f6"   => 1,
114         "f7$f7"   => 1,
115         "f8$f8"   => 1,
116         "f9$f9"   => 1,
117         "f10"     => $f10,
118         "f11$f11" => 1,
119         "f12$f12" => 1,
120         "f13$f13" => 1,
121         "f14"     => $f14,
122         "f15$f15" => 1
123     );
124     print $input->header( -type => 'utf-8', -cookie => $cookie ), $template->output;
125 }
126
127 1;