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::Output; # contains gettemplate
33 my $op=$query->param("op");
34 my $dbh=C4::Context->dbh;
36 if ($op eq "export") {
37 print $query->header( -type => 'application/octet-stream',
38 -attachment=>'koha.mrc');
39 my $StartingBiblionumber = $query->param("StartingBiblionumber");
40 my $EndingBiblionumber = $query->param("EndingBiblionumber");
41 my $format = $query->param("format");
42 my $branch = $query->param("branch");
43 my $start_callnumber = $query->param("start_callnumber");
44 my $end_callnumber = $query->param("end_callnumber");
45 my $limit = $query->param("limit");
47 $strsth="select bibid from marc_biblio ";
48 if ($StartingBiblionumber && $EndingBiblionumber) {
49 $strsth.=" where biblionumber>=$StartingBiblionumber and biblionumber<=$EndingBiblionumber ";
51 if ($strsth=~/ where/){
52 $strsth=~s/ where (.*)/,biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\' and $1/;
54 $strsth.=",biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\'";
57 if ($strsth=~/ where/){
58 $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\' and $1/;
60 $strsth.=",items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\'";
62 } elsif ($start_callnumber && $end_callnumber) {
63 $start_callnumber=~s/\*/\%/g;
64 $start_callnumber=~s/\?/\_/g;
65 $end_callnumber=~s/\*/\%/g;
66 $end_callnumber=~s/\?/\_/g;
67 if ($strsth=~/,items/){
68 $strsth.=" and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\'";
70 if ($strsth=~/ where/){
71 $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' and $1/;
73 $strsth=~",items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' ";
77 $strsth.=" order by marc_biblio.biblionumber ";
78 $strsth.= "LIMIT 0,$limit " if ($limit);
79 warn "requete marc.pl : ".$strsth;
80 my $req=$dbh->prepare($strsth);
82 while (my ($bibid) = $req->fetchrow) {
83 my $record = GetMarcBiblio($bibid);
85 print $record->as_usmarc();
88 my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
94 while (my ($value,$lib) = $sth->fetchrow_array) {
95 push @itemtype, $value;
96 $itemtypes{$value}=$lib;
99 my $CGIitemtype=CGI::scrolling_list( -name => 'format',
100 -values => \@itemtype,
102 -labels => \%itemtypes,
108 my $branches = GetBranches;
110 foreach my $thisbranch (keys %$branches) {
111 # my $selected = 1 if $thisbranch eq $branch;
112 my %row =(value => $thisbranch,
113 # selected => $selected,
114 branchname => $branches->{$thisbranch}->{'branchname'},
116 push @branchloop, \%row;
119 my ($template, $loggedinuser, $cookie)
120 = get_template_and_user({template_name => "export/marc.tmpl",
123 authnotrequired => 0,
124 flagsrequired => {tools => 1},
127 $template->param(branchloop=>\@branchloop,
128 CGIitemtype=>$CGIitemtype,
129 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
130 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
131 IntranetNav => C4::Context->preference("IntranetNav"),
133 output_html_with_http_headers $query, $cookie, $template->output;