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>.
21 #use warnings; FIXME - Bug 2505
33 plugin_parameters : other parameters added when the plugin is called by the dopop function
38 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
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;
52 <script type=\"text/javascript\">
55 function Focus$function_name(subfield_managed) {
56 if ( document.getElementById(\"$field_number\").value ) {
59 document.getElementById(\"$field_number\").value='$dateentered' + 'b xxu||||| |||| 00| 0 $lang d';
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 = \"\";
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');
80 return ($function_name, $res);
84 my $lang = C4::Context->preference('DefaultLanguageField008' );
85 $lang = "eng" unless $lang;
86 $lang = pack("A3", $lang);
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 = {
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",
146 authnotrequired => 0,
147 flagsrequired => { editcatalogue => '*' },
152 $result = "$dateentered" . "b xxu||||| |||| 00| 0 $lang d" unless $result;
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');
161 $xmlschema->validate( $doc );
163 $errorXml = 'Can\'t validate the xml data from ' . $dir . 'marc21_field_008.xml' if ($@);
166 $errorXml = 'Can\'t read the xml file ' . $dir . 'marc21_field_008.xml';
168 $template->param(tagfield => '008',
171 errorXml => $errorXml,
172 material_configuration => $material_configuration,
174 output_html_with_http_headers $input, $cookie, $template->output;