Bug 25548: Remove Apache rewrite directives that trigger redirects
[koha.git] / cataloguing / value_builder / marc21_field_008.pl
blobb3c5d0c47f908edaa376b397a3bae5ecf8013c9e
1 #!/usr/bin/perl
3 # Converted to new plugin style (Bug 13437)
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Modern::Perl;
23 use C4::Auth;
24 use CGI qw ( -utf8 );
25 use C4::Context;
27 use C4::Search;
28 use C4::Output;
30 use XML::LibXML;
31 use Koha::Util::FrameworkPlugin qw|date_entered|;
33 my $builder = sub {
34 my ( $params ) = @_;
36 my $lang = C4::Context->preference('DefaultLanguageField008' );
37 $lang = "eng" unless $lang;
38 $lang = pack("A3", $lang);
39 my $country = C4::Context->preference('DefaultCountryField008') // "xxu";
40 $country = pack("A3", $country);
42 my $function_name = $params->{id};
43 my $dateentered = date_entered();
44 my $res = "
45 <script>
47 function Focus$function_name(event) {
48 if ( document.getElementById(event.data.id).value ) {
50 else {
51 document.getElementById(event.data.id).value='$dateentered' + 'b $country||||| |||| 00| 0 $lang d';
53 return 1;
56 function Click$function_name(event) {
57 defaultvalue=document.getElementById(event.data.id).value;
58 //Retrieve full leader string and pass it to the 008 tag editor
59 var leader_value = \$(\"input[id^='tag_000']\").val();
60 var leader_parameter = \"\";
61 if (leader_value){
62 //Only add the parameter to the URL if there is a value to add
63 leader_parameter = \"&leader=\"+leader_value;
65 newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=marc21_field_008.pl&index=\"+ event.data.id +\"&result=\"+encodeURIComponent(defaultvalue)+leader_parameter,\"tag_editor\",'width=1000,height=600,toolbar=false,scrollbars=yes');
68 </script>
71 return $res;
74 my $launcher = sub {
75 my ( $params ) = @_;
76 my $input = $params->{cgi};
77 my $lang = C4::Context->preference('DefaultLanguageField008' );
78 $lang = "eng" unless $lang;
79 $lang = pack("A3", $lang);
80 my $country = C4::Context->preference('DefaultCountryField008') // "xxu";
81 $country = pack("A3", $country);
83 my $index = $input->param('index');
84 my $result = $input->param('result');
85 my $leader = $input->param('leader');
87 my $material_configuration;
88 if ($leader && length($leader) == '24') {
89 #MARC 21 Material Type Configuration
90 #Field 008/18-34 Configuration
91 #If Leader/06 = a and Leader/07 = a, c, d, or m: Books
92 #If Leader/06 = a and Leader/07 = b, i, or s: Continuing Resources
93 #If Leader/06 = t: Books
94 #If Leader/06 = c, d, i, or j: Music
95 #If Leader/06 = e, or f: Maps
96 #If Leader/06 = g, k, o, or r: Visual Materials
97 #If Leader/06 = m: Computer Files
98 #If Leader/06 = p: Mixed Materials
99 #http://www.loc.gov/marc/bibliographic/bdleader.html
100 my $material_configuration_mapping = {
101 a => {
102 a => 'BKS',
103 c => 'BKS',
104 d => 'BKS',
105 m => 'BKS',
106 b => 'CR',
107 i => 'CR',
108 s => 'CR',
110 t => 'BKS',
111 c => 'MU',
112 d => 'MU',
113 i => 'MU',
114 j => 'MU',
115 e => 'MP',
116 f => 'MP',
117 g => 'VM',
118 k => 'VM',
119 o => 'VM',
120 r => 'VM',
121 m => 'CF',
122 p => 'MX',
124 my $leader06 = substr($leader, 6, 1);
125 my $leader07 = substr($leader, 7, 1);
126 #Retrieve material type using leader06
127 $material_configuration = $material_configuration_mapping->{$leader06};
128 #If the value returned is a ref (i.e. leader06 is 'a'), then use leader07 to get the actual material type
129 if ( ($material_configuration) && (ref($material_configuration) eq 'HASH') ){
130 $material_configuration = $material_configuration->{$leader07};
134 my $dbh = C4::Context->dbh;
136 my ($template, $loggedinuser, $cookie) = get_template_and_user(
137 { template_name => "cataloguing/value_builder/marc21_field_008.tt",
138 query => $input,
139 type => "intranet",
140 flagsrequired => { editcatalogue => '*' },
141 debug => 1,
145 my $dateentered = date_entered();
146 $result = "$dateentered" . "b $country||||| |||| 00| 0 $lang d" unless $result;
147 my $errorXml = '';
148 # Check if the xml, xsd exists and is validated
149 my $dir = C4::Context->config('intrahtdocs') . '/prog/' . $template->{lang} . '/data/';
150 if (-r $dir . 'marc21_field_008.xml') {
151 my $doc = XML::LibXML->new->parse_file($dir . 'marc21_field_008.xml');
152 if (-r $dir . 'marc21_field_CF.xsd') {
153 my $xmlschema = XML::LibXML::Schema->new(location => $dir . 'marc21_field_CF.xsd');
154 eval {
155 $xmlschema->validate( $doc );
157 $errorXml = 'Can\'t validate the xml data from ' . $dir . 'marc21_field_008.xml' if ($@);
159 } else {
160 $errorXml = 'Can\'t read the xml file ' . $dir . 'marc21_field_008.xml';
162 $template->param(tagfield => '008',
163 index => $index,
164 result => $result,
165 errorXml => $errorXml,
166 material_configuration => $material_configuration,
168 output_html_with_http_headers $input, $cookie, $template->output;
171 return { builder => $builder, launcher => $launcher };