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 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
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.
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
22 use C4::Branch; # GetBranches
27 use C4::Interface::CGI::Output;
28 use C4::Output; # contains gettemplate
34 my $op=$query->param("op");
35 my $dbh=C4::Context->dbh;
37 if ($op eq "export") {
38 print $query->header( -type => 'application/octet-stream',
39 -attachment=>'koha.mrc');
40 my $StartingBiblionumber = $query->param("StartingBiblionumber");
41 my $EndingBiblionumber = $query->param("EndingBiblionumber");
42 my $format = $query->param("format");
43 my $branch = $query->param("branch");
44 my $start_callnumber = $query->param("start_callnumber");
45 my $end_callnumber = $query->param("end_callnumber");
46 my $limit = $query->param("limit");
48 $strsth="select bibid from marc_biblio ";
49 if ($StartingBiblionumber && $EndingBiblionumber) {
50 $strsth.=" where biblionumber>=$StartingBiblionumber and biblionumber<=$EndingBiblionumber ";
52 if ($strsth=~/ where/){
53 $strsth=~s/ where (.*)/,biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\' and $1/;
55 $strsth.=",biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\'";
58 if ($strsth=~/ where/){
59 $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\' and $1/;
61 $strsth.=",items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\'";
63 } elsif ($start_callnumber && $end_callnumber) {
64 $start_callnumber=~s/\*/\%/g;
65 $start_callnumber=~s/\?/\_/g;
66 $end_callnumber=~s/\*/\%/g;
67 $end_callnumber=~s/\?/\_/g;
68 if ($strsth=~/,items/){
69 $strsth.=" and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\'";
71 if ($strsth=~/ where/){
72 $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' and $1/;
74 $strsth=~",items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' ";
78 $strsth.=" order by marc_biblio.biblionumber ";
79 $strsth.= "LIMIT 0,$limit " if ($limit);
80 warn "requete marc.pl : ".$strsth;
81 my $req=$dbh->prepare($strsth);
83 while (my ($bibid) = $req->fetchrow) {
84 my $record = GetMarcBiblio($bibid);
86 print $record->as_usmarc();
89 my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
95 while (my ($value,$lib) = $sth->fetchrow_array) {
96 push @itemtype, $value;
97 $itemtypes{$value}=$lib;
100 my $CGIitemtype=CGI::scrolling_list( -name => 'format',
101 -values => \@itemtype,
103 -labels => \%itemtypes,
109 my $branches = GetBranches;
111 foreach my $thisbranch (keys %$branches) {
112 # my $selected = 1 if $thisbranch eq $branch;
113 my %row =(value => $thisbranch,
114 # selected => $selected,
115 branchname => $branches->{$thisbranch}->{'branchname'},
117 push @branchloop, \%row;
120 my ($template, $loggedinuser, $cookie)
121 = get_template_and_user({template_name => "export/marc.tmpl",
124 authnotrequired => 0,
125 flagsrequired => {tools => 1},
128 $template->param(branchloop=>\@branchloop,
129 CGIitemtype=>$CGIitemtype,
130 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
131 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
132 IntranetNav => C4::Context->preference("IntranetNav"),
134 output_html_with_http_headers $query, $cookie, $template->output;