7 use C4::Interface::CGI::Output;
8 use C4::Output; # contains gettemplate
14 my $op=$query->param("op");
15 my $dbh=C4::Context->dbh;
17 if ($op eq "export") {
18 print $query->header( -type => 'application/octet-stream',
19 -attachment=>'koha.mrc');
20 my $start_bib = $query->param("start_bib");
21 my $end_bib = $query->param("end_bib");
22 my $format = $query->param("format");
23 my $branch = $query->param("branch");
24 my $start_callnumber = $query->param("start_callnumber");
25 my $end_callnumber = $query->param("end_callnumber");
26 my $limit = $query->param("limit");
28 $strsth="select bibid from marc_biblio ";
29 if ($start_bib && $end_bib) {
30 $strsth.=" where biblionumber>=$start_bib and biblionumber<=$end_bib ";
32 if ($strsth=~/ where/){
33 $strsth=~s/ where (.*)/,biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\' and $1/;
35 $strsth.=",biblioitems where biblioitems.biblionumber=marc_biblio.biblionumber and biblioitems.itemtype=\'$format\'";
38 if ($strsth=~/ where/){
39 $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\' and $1/;
41 $strsth.=",items where items.biblionumber=marc_biblio.biblionumber and items.homebranch=\'$branch\'";
43 } elsif ($start_callnumber && $end_callnumber) {
44 $start_callnumber=~s/\*/\%/g;
45 $start_callnumber=~s/\?/\_/g;
46 $end_callnumber=~s/\*/\%/g;
47 $end_callnumber=~s/\?/\_/g;
48 if ($strsth=~/,items/){
49 $strsth.=" and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\'";
51 if ($strsth=~/ where/){
52 $strsth=~s/ where (.*)/,items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' and $1/;
54 $strsth=~",items where items.biblionumber=marc_biblio.biblionumber and items.itemcallnumber between \'$start_callnumber\' and \'$end_callnumber\' ";
58 $strsth.=" order by marc_biblio.biblionumber ";
59 $strsth.= "LIMIT 0,$limit " if ($limit);
60 warn "requĂȘte marc.pl : ".$strsth;
61 my $req=$dbh->prepare($strsth);
63 while (my ($bibid) = $req->fetchrow) {
64 my $record = MARCgetbiblio($dbh,$bibid);
66 print $record->as_usmarc();
69 my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description");
75 while (my ($value,$lib) = $sth->fetchrow_array) {
76 push @itemtype, $value;
77 $itemtypes{$value}=$lib;
80 my $CGIitemtype=CGI::scrolling_list( -name => 'format',
81 -values => \@itemtype,
83 -labels => \%itemtypes,
89 my $branches = getallbranches;
91 foreach my $thisbranch (keys %$branches) {
92 # my $selected = 1 if $thisbranch eq $branch;
93 my %row =(value => $thisbranch,
94 # selected => $selected,
95 branchname => $branches->{$thisbranch}->{'branchname'},
97 push @branchloop, \%row;
100 my ($template, $loggedinuser, $cookie)
101 = get_template_and_user({template_name => "export/marc.tmpl",
104 authnotrequired => 0,
105 flagsrequired => {parameters => 1, management => 1, tools => 1},
108 $template->param(branchloop=>\@branchloop,
109 CGIitemtype=>$CGIitemtype,
110 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
111 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
112 IntranetNav => C4::Context->preference("IntranetNav"),
114 output_html_with_http_headers $query, $cookie, $template->output;