Bug 14194: Restore the HH:MM to 23:59 for onsite-checkouts
[koha.git] / cataloguing / value_builder / marc21_field_008.pl
blobcc2d28d2f53243a6a925a4d61576d4092fb53517
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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 strict;
21 #use warnings; FIXME - Bug 2505
22 use C4::Auth;
23 use CGI qw ( -utf8 );
24 use C4::Context;
26 use C4::Search;
27 use C4::Output;
29 use XML::LibXML;
31 =head1 DESCRIPTION
33 plugin_parameters : other parameters added when the plugin is called by the dopop function
35 =cut
37 # find today's date
38 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
40 $year += 1900;
41 $mon += 1;
42 my $dateentered = substr($year, 2, 2) . sprintf("%0.2d", $mon) . sprintf("%0.2d", $mday);
44 sub plugin_javascript {
45 my $lang = C4::Context->preference('DefaultLanguageField008' );
46 $lang = "eng" unless $lang;
47 $lang = pack("A3", $lang);
49 my ($dbh, $record, $tagslib, $field_number, $tabloop) = @_;
50 my $function_name = $field_number;
51 my $res = "
52 <script type=\"text/javascript\">
53 //<![CDATA[
55 function Focus$function_name(subfield_managed) {
56 if ( document.getElementById(\"$field_number\").value ) {
58 else {
59 document.getElementById(\"$field_number\").value='$dateentered' + 'b xxu||||| |||| 00| 0 $lang d';
61 return 1;
64 function Clic$function_name(i) {
65 defaultvalue=document.getElementById(\"$field_number\").value;
66 //Retrieve full leader string and pass it to the 008 tag editor
67 var leader_value = \$(\"input[id^='tag_000']\").val();
68 var leader_parameter = \"\";
69 if (leader_value){
70 //Only add the parameter to the URL if there is a value to add
71 leader_parameter = \"&leader=\"+leader_value;
73 newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=marc21_field_008.pl&index=$field_number&result=\"+defaultvalue+leader_parameter,\"tag_editor\",'width=1000,height=600,toolbar=false,scrollbars=yes');
76 //]]>
77 </script>
80 return ($function_name, $res);
83 sub plugin {
84 my $lang = C4::Context->preference('DefaultLanguageField008' );
85 $lang = "eng" unless $lang;
86 $lang = pack("A3", $lang);
88 my ($input) = @_;
89 my $index = $input->param('index');
90 my $result = $input->param('result');
91 my $leader = $input->param('leader');
93 my $material_configuration;
94 if ($leader && length($leader) == '24') {
95 #MARC 21 Material Type Configuration
96 #Field 008/18-34 Configuration
97 #If Leader/06 = a and Leader/07 = a, c, d, or m: Books
98 #If Leader/06 = a and Leader/07 = b, i, or s: Continuing Resources
99 #If Leader/06 = t: Books
100 #If Leader/06 = c, d, i, or j: Music
101 #If Leader/06 = e, or f: Maps
102 #If Leader/06 = g, k, o, or r: Visual Materials
103 #If Leader/06 = m: Computer Files
104 #If Leader/06 = p: Mixed Materials
105 #http://www.loc.gov/marc/bibliographic/bdleader.html
106 my $material_configuration_mapping = {
107 a => {
108 a => 'BKS',
109 c => 'BKS',
110 d => 'BKS',
111 m => 'BKS',
112 b => 'CR',
113 i => 'CR',
114 s => 'CR',
116 t => 'BKS',
117 c => 'MU',
118 d => 'MU',
119 i => 'MU',
120 j => 'MU',
121 e => 'MP',
122 f => 'MP',
123 g => 'VM',
124 k => 'VM',
125 o => 'VM',
126 r => 'VM',
127 m => 'CF',
128 p => 'MX',
130 my $leader06 = substr($leader, 6, 1);
131 my $leader07 = substr($leader, 7, 1);
132 #Retrieve material type using leader06
133 $material_configuration = $material_configuration_mapping->{$leader06};
134 #If the value returned is a ref (i.e. leader06 is 'a'), then use leader07 to get the actual material type
135 if ( ($material_configuration) && (ref($material_configuration) eq 'HASH') ){
136 $material_configuration = $material_configuration->{$leader07};
140 my $dbh = C4::Context->dbh;
142 my ($template, $loggedinuser, $cookie) = get_template_and_user(
143 { template_name => "cataloguing/value_builder/marc21_field_008.tt",
144 query => $input,
145 type => "intranet",
146 authnotrequired => 0,
147 flagsrequired => { editcatalogue => '*' },
148 debug => 1,
152 $result = "$dateentered" . "b xxu||||| |||| 00| 0 $lang d" unless $result;
153 my $errorXml = '';
154 # Check if the xml, xsd exists and is validated
155 my $dir = C4::Context->config('intrahtdocs') . '/prog/' . $template->{lang} . '/data/';
156 if (-r $dir . 'marc21_field_008.xml') {
157 my $doc = XML::LibXML->new->parse_file($dir . 'marc21_field_008.xml');
158 if (-r $dir . 'marc21_field_CF.xsd') {
159 my $xmlschema = XML::LibXML::Schema->new(location => $dir . 'marc21_field_CF.xsd');
160 eval {
161 $xmlschema->validate( $doc );
163 $errorXml = 'Can\'t validate the xml data from ' . $dir . 'marc21_field_008.xml' if ($@);
165 } else {
166 $errorXml = 'Can\'t read the xml file ' . $dir . 'marc21_field_008.xml';
168 $template->param(tagfield => '008',
169 index => $index,
170 result => $result,
171 errorXml => $errorXml,
172 material_configuration => $material_configuration,
174 output_html_with_http_headers $input, $cookie, $template->output;