some modifs in zebra unimarc config files
[koha.git] / ISBDdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 =head1 NAME
21
22 ISBDdetail.pl : script to show a biblio in ISBD format
23
24 =head1 SYNOPSIS
25
26
27 =head1 DESCRIPTION
28
29 This script needs a biblionumber in bib parameter (bibnumber
30 from koha style DB.  Automaticaly maps to marc biblionumber).
31
32 =head1 FUNCTIONS
33
34 =over 2
35
36 =cut
37
38
39 use strict;
40 require Exporter;
41 use C4::Auth;
42 use C4::Context;
43 use C4::Output;
44 use C4::Interface::CGI::Output;
45 use CGI;
46 use C4::Search;
47 use MARC::Record;
48 use C4::Biblio;
49 use C4::Acquisition;
50 use HTML::Template;
51
52 my $query=new CGI;
53
54 my $dbh=C4::Context->dbh;
55
56 my $biblionumber=$query->param('biblionumber');
57 my $itemtype = &MARCfind_frameworkcode($dbh,$biblionumber);
58 my $tagslib = &MARCgettagslib($dbh,1,$itemtype);
59
60 my $record =MARCgetbiblio($dbh,$biblionumber);
61 # open template
62 my ($template, $loggedinuser, $cookie)
63                 = get_template_and_user({template_name => "catalogue/ISBDdetail.tmpl",
64                              query => $query,
65                              type => "intranet",
66                              authnotrequired => 1,
67                              debug => 1,
68                              });
69
70 my $ISBD = C4::Context->preference('ISBD');
71 # my @blocs = split /\@/,$ISBD;
72 # my @fields = $record->fields();
73 my $res;
74 # foreach my $bloc (@blocs) {
75 #       $bloc =~ s/\n//g;
76         my $bloc = $ISBD;
77         my $blocres;
78         foreach my $isbdfield (split /#/,$bloc) {
79 #               $isbdfield= /(.?.?.?)/;
80                 $isbdfield =~ /(\d\d\d)\|(.*)\|(.*)\|(.*)/;
81                 my $fieldvalue=$1;
82                 my $textbefore=$2;
83                 my $analysestring=$3;
84                 my $textafter=$4;
85 #               warn "==> $1 / $2 / $3 / $4";
86 #               my $fieldvalue=substr($isbdfield,0,3);
87                 if ($fieldvalue>0) {
88         #               warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
89 #                       warn "FV : $fieldvalue";
90                         my $hasputtextbefore=0;
91                         foreach my $field ($record->field($fieldvalue)) {
92                                 my $calculated = $analysestring;
93                                 my $tag = $field->tag();
94                                 if ($tag<10) {
95                                 } else {
96                                         my @subf = $field->subfields;
97                                         for my $i (0..$#subf) {
98                                                 my $subfieldcode = $subf[$i][0];
99                                                 my $subfieldvalue = get_authorised_value_desc($tag, $subf[$i][0], $subf[$i][1], '', $dbh);;
100                                                 my $tagsubf = $tag.$subfieldcode;
101                                                 $calculated =~ s/\{(.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue\{$1$tagsubf$2\}$2/g;
102                                         }
103                                         # field builded, store the result
104                                         if ($calculated && !$hasputtextbefore) { # put textbefore if not done
105                                                 $blocres .=$textbefore;
106                                                 $hasputtextbefore=1
107                                         }
108                                         # remove punctuation at start
109                                         $calculated =~ s/^( |;|:|\.|-)*//g;
110                                         $blocres.=$calculated;
111                                 }
112                         }
113                         $blocres .=$textafter if $hasputtextbefore;
114                 } else {
115                         $blocres.=$isbdfield;
116                 }
117         }
118         $res.=$blocres;
119 # }
120 $res =~ s/\{(.*?)\}//g;
121 $res =~ s/\\n/\n/g;
122 $res =~ s/\n/<br\/>/g;
123 # remove empty ()
124 $res =~ s/\(\)//g;
125 $template->param(ISBD => $res,
126                                 biblionumber => $biblionumber);
127
128 output_html_with_http_headers $query, $cookie, $template->output;
129
130 sub get_authorised_value_desc ($$$$$) {
131    my($tag, $subfield, $value, $framework, $dbh) = @_;
132
133    #---- branch
134     if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
135        return getbranchdetail($value)->{branchname};
136     }
137
138    #---- itemtypes
139    if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
140                 my $itemtypedef = getitemtypeinfo($itemtype);
141        return $itemtypedef->{description};
142     }
143
144    #---- "true" authorized value
145    my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
146
147    if ($category ne "") {
148        my $sth = $dbh->prepare("select lib from authorised_values where category = ? and authorised_value = ?");
149        $sth->execute($category, $value);
150        my $data = $sth->fetchrow_hashref;
151        return $data->{'lib'};
152    } else {
153        return $value; # if nothing is found return the original value
154    }
155 }