View | Details | Raw Unified | Return to bug 13437
Collapse All | Expand All

(-)a/Koha/Util/FrameworkPlugin.pm (-1 / +15 lines)
Lines 27-33 BEGIN { Link Here
27
    require Exporter;
27
    require Exporter;
28
    @ISA = qw( Exporter );
28
    @ISA = qw( Exporter );
29
    @EXPORT = qw( );
29
    @EXPORT = qw( );
30
    @EXPORT_OK = qw( wrapper );
30
    @EXPORT_OK = qw( wrapper date_entered );
31
}
31
}
32
32
33
=head1 NAME
33
=head1 NAME
Lines 52-55 sub wrapper { Link Here
52
    return $str;
52
    return $str;
53
}
53
}
54
54
55
=head2 date_entered
56
57
    date_entered returns date in yymmdd format as needed by MARC21 field 008
58
59
=cut
60
61
sub date_entered {
62
    # find today's date
63
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
64
    $year +=1900;
65
    $mon +=1;
66
    return substr($year,2,2).sprintf ("%0.2d", $mon).sprintf ("%0.2d",$mday);
67
}
68
55
1;
69
1;
(-)a/cataloguing/value_builder/marc21_field_008.pl (-7 / +3 lines)
Lines 27-32 use C4::Search; Link Here
27
use C4::Output;
27
use C4::Output;
28
28
29
use XML::LibXML;
29
use XML::LibXML;
30
use Koha::Util::FrameworkPlugin qw|date_entered|;
30
31
31
=head1 DESCRIPTION
32
=head1 DESCRIPTION
32
33
Lines 34-46 plugin_parameters : other parameters added when the plugin is called by the dopo Link Here
34
35
35
=cut
36
=cut
36
37
37
# find today's date
38
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
39
40
$year += 1900;
41
$mon  += 1;
42
my $dateentered = substr($year, 2, 2) . sprintf("%0.2d", $mon) . sprintf("%0.2d", $mday);
43
44
sub plugin_javascript {
38
sub plugin_javascript {
45
    my $lang = C4::Context->preference('DefaultLanguageField008' );
39
    my $lang = C4::Context->preference('DefaultLanguageField008' );
46
    $lang = "eng" unless $lang;
40
    $lang = "eng" unless $lang;
Lines 48-53 sub plugin_javascript { Link Here
48
42
49
    my ($dbh, $record, $tagslib, $field_number, $tabloop) = @_;
43
    my ($dbh, $record, $tagslib, $field_number, $tabloop) = @_;
50
    my $function_name = $field_number;
44
    my $function_name = $field_number;
45
    my $dateentered = date_entered();
51
    my $res           = "
46
    my $res           = "
52
<script type=\"text/javascript\">
47
<script type=\"text/javascript\">
53
//<![CDATA[
48
//<![CDATA[
Lines 149-154 sub plugin { Link Here
149
        }
144
        }
150
    );
145
    );
151
146
147
    my $dateentered = date_entered();
152
    $result = "$dateentered" . "b        xxu||||| |||| 00| 0 $lang d" unless $result;
148
    $result = "$dateentered" . "b        xxu||||| |||| 00| 0 $lang d" unless $result;
153
    my $errorXml = '';
149
    my $errorXml = '';
154
    # Check if the xml, xsd exists and is validated
150
    # Check if the xml, xsd exists and is validated
(-)a/cataloguing/value_builder/marc21_field_008_authorities.pl (-20 / +6 lines)
Lines 1-6 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
4
# Copyright 2000-2002 Katipo Communications
3
# Copyright 2000-2002 Katipo Communications
5
#
4
#
6
# This file is part of Koha.
5
# This file is part of Koha.
Lines 26-31 use C4::Context; Link Here
26
25
27
use C4::Search;
26
use C4::Search;
28
use C4::Output;
27
use C4::Output;
28
use Koha::Util::FrameworkPlugin qw|date_entered|;
29
29
30
use constant FIXLEN_DATA_ELTS => '|| aca||aabn           | a|a     d';
30
use constant FIXLEN_DATA_ELTS => '|| aca||aabn           | a|a     d';
31
use constant PREF_008 => 'MARCAuthorityControlField008';
31
use constant PREF_008 => 'MARCAuthorityControlField008';
Lines 36-51 plugin_parameters : other parameters added when the plugin is called by the dopo Link Here
36
36
37
=cut
37
=cut
38
38
39
# find today's date
40
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
41
42
$year +=1900; $mon +=1;
43
my $dateentered = substr($year,2,2).sprintf ("%0.2d", $mon).sprintf ("%0.2d",$mday);
44
my $defaultval = Field008();
45
46
sub plugin_javascript {
39
sub plugin_javascript {
47
    my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
40
    my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
48
    my $function_name= $field_number;
41
    my $function_name= $field_number;
42
    my $dateentered = date_entered();
43
    my $defaultval = substr( C4::Context->preference(PREF_008) || FIXLEN_DATA_ELTS, 0, 34 );
49
    my $res="
44
    my $res="
50
<script type=\"text/javascript\">
45
<script type=\"text/javascript\">
51
//<![CDATA[
46
//<![CDATA[
Lines 79-84 sub plugin { Link Here
79
    my $index= $input->param('index');
74
    my $index= $input->param('index');
80
    my $result= $input->param('result');
75
    my $result= $input->param('result');
81
    my $authtype= $input->param('authtypecode')||'';
76
    my $authtype= $input->param('authtypecode')||'';
77
78
    my $defaultval = substr( C4::Context->preference(PREF_008) || FIXLEN_DATA_ELTS, 0, 34 );
82
    substr($defaultval,14-6,1)='b' if $authtype=~ /TOPIC_TERM|GENRE.FORM|CHRON_TERM/;
79
    substr($defaultval,14-6,1)='b' if $authtype=~ /TOPIC_TERM|GENRE.FORM|CHRON_TERM/;
83
80
84
    my $dbh = C4::Context->dbh;
81
    my $dbh = C4::Context->dbh;
Lines 91-96 sub plugin { Link Here
91
                 flagsrequired => {editcatalogue => '*'},
88
                 flagsrequired => {editcatalogue => '*'},
92
                 debug => 1,
89
                 debug => 1,
93
                 });
90
                 });
91
    my $dateentered = date_entered();
94
    $result = "$dateentered$defaultval" unless $result;
92
    $result = "$dateentered$defaultval" unless $result;
95
    my @f;
93
    my @f;
96
    for(0,6..17,28,29,31..33,38,39) {
94
    for(0,6..17,28,29,31..33,38,39) {
Lines 109-123 sub plugin { Link Here
109
    }
107
    }
110
    output_html_with_http_headers $input, $cookie, $template->output;
108
    output_html_with_http_headers $input, $cookie, $template->output;
111
}
109
}
112
113
sub Field008 {
114
  my $pref= C4::Context->preference(PREF_008);
115
  if(!$pref) {
116
    return FIXLEN_DATA_ELTS;
117
  }
118
  elsif(length($pref)<34) {
119
    warn "marc21_field_008_authorities.pl: Syspref ".PREF_008." should be 34 characters long ";
120
    return FIXLEN_DATA_ELTS;
121
  }
122
  return substr($pref,0,34);  #ignore remainder
123
}
(-)a/t/Koha_Util_FrameworkPlugin.t (-3 / +5 lines)
Lines 1-9 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use Test::More tests => 6;
4
use Test::More tests => 7;
5
5
6
use_ok( 'Koha::Util::FrameworkPlugin', qw(wrapper) );
6
use_ok( 'Koha::Util::FrameworkPlugin', qw(wrapper date_entered) );
7
7
8
my $char;
8
my $char;
9
is($char=wrapper(' '),'space',"Return space");
9
is($char=wrapper(' '),'space',"Return space");
Lines 11-13 is($char=wrapper(' '),'dblspace',"Return dblspace"); Link Here
11
is($char=wrapper('|'),'pipe',"Return pipe");
11
is($char=wrapper('|'),'pipe',"Return pipe");
12
is($char=wrapper('||'),'dblpipe',"Return dblpipe");
12
is($char=wrapper('||'),'dblpipe',"Return dblpipe");
13
is($char=wrapper('somethingelse'),'somethingelse',"Return somethingelse");
13
is($char=wrapper('somethingelse'),'somethingelse',"Return somethingelse");
14
- 
14
15
my $f008= date_entered();
16
is( $f008 =~ /^\d{6}$/, 1, 'date_entered gives six digits' );

Return to bug 13437