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
30 use Koha::Util::FrameworkPlugin qw|date_entered|;
32 sub plugin_javascript {
33 my ($dbh, $record, $tagslib, $field_number, $tabloop) = @_;
35 my $lang = C4::Context->preference('DefaultLanguageField008' );
36 $lang = "eng" unless $lang;
37 $lang = pack("A3", $lang);
39 my $function_name = $field_number;
40 my $dateentered = date_entered();
42 <script type=\"text/javascript\">
45 function Focus$function_name(subfield_managed) {
46 if ( document.getElementById(\"$field_number\").value ) {
49 document.getElementById(\"$field_number\").value='$dateentered' + 'b xxu||||| |||| 00| 0 $lang d';
54 function Clic$function_name(i) {
55 defaultvalue=document.getElementById(\"$field_number\").value;
56 //Retrieve full leader string and pass it to the 008 tag editor
57 var leader_value = \$(\"input[id^='tag_000']\").val();
58 var leader_parameter = \"\";
60 //Only add the parameter to the URL if there is a value to add
61 leader_parameter = \"&leader=\"+leader_value;
63 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');
70 return ($function_name, $res);
75 my $lang = C4::Context->preference('DefaultLanguageField008' );
76 $lang = "eng" unless $lang;
77 $lang = pack("A3", $lang);
79 my $index = $input->param('index');
80 my $result = $input->param('result');
81 my $leader = $input->param('leader');
83 my $material_configuration;
84 if ($leader && length($leader) == '24') {
85 #MARC 21 Material Type Configuration
86 #Field 008/18-34 Configuration
87 #If Leader/06 = a and Leader/07 = a, c, d, or m: Books
88 #If Leader/06 = a and Leader/07 = b, i, or s: Continuing Resources
89 #If Leader/06 = t: Books
90 #If Leader/06 = c, d, i, or j: Music
91 #If Leader/06 = e, or f: Maps
92 #If Leader/06 = g, k, o, or r: Visual Materials
93 #If Leader/06 = m: Computer Files
94 #If Leader/06 = p: Mixed Materials
95 #http://www.loc.gov/marc/bibliographic/bdleader.html
96 my $material_configuration_mapping = {
120 my $leader06 = substr($leader, 6, 1);
121 my $leader07 = substr($leader, 7, 1);
122 #Retrieve material type using leader06
123 $material_configuration = $material_configuration_mapping->{$leader06};
124 #If the value returned is a ref (i.e. leader06 is 'a'), then use leader07 to get the actual material type
125 if ( ($material_configuration) && (ref($material_configuration) eq 'HASH') ){
126 $material_configuration = $material_configuration->{$leader07};
130 my $dbh = C4::Context->dbh;
132 my ($template, $loggedinuser, $cookie) = get_template_and_user(
133 { template_name => "cataloguing/value_builder/marc21_field_008.tt",
136 authnotrequired => 0,
137 flagsrequired => { editcatalogue => '*' },
142 my $dateentered = date_entered();
143 $result = "$dateentered" . "b xxu||||| |||| 00| 0 $lang d" unless $result;
145 # Check if the xml, xsd exists and is validated
146 my $dir = C4::Context->config('intrahtdocs') . '/prog/' . $template->{lang} . '/data/';
147 if (-r $dir . 'marc21_field_008.xml') {
148 my $doc = XML::LibXML->new->parse_file($dir . 'marc21_field_008.xml');
149 if (-r $dir . 'marc21_field_CF.xsd') {
150 my $xmlschema = XML::LibXML::Schema->new(location => $dir . 'marc21_field_CF.xsd');
152 $xmlschema->validate( $doc );
154 $errorXml = 'Can\'t validate the xml data from ' . $dir . 'marc21_field_008.xml' if ($@);
157 $errorXml = 'Can\'t read the xml file ' . $dir . 'marc21_field_008.xml';
159 $template->param(tagfield => '008',
162 errorXml => $errorXml,
163 material_configuration => $material_configuration,
165 output_html_with_http_headers $input, $cookie, $template->output;