7 use C4::Output; # gettemplate
8 use C4::Auth; # checkauth, getborrowernumber.
10 use C4::Circulation::Circ2;
16 my ($loggedinuser, $cookie, $sessionID) = checkauth($query);
18 my $template = gettemplate("opac-reserve.tmpl", "opac");
20 # get borrower information ....
21 my $borrowernumber = getborrowernumber($loggedinuser);
22 my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
25 $template->param(BORROWER_INFO => \@bordat);
27 # get biblionumber.....
28 my $biblionumber = $query->param('bib');
29 $template->param(biblionumber => $biblionumber);
31 my $bibdata = bibdata($biblionumber);
32 $template->param($bibdata);
34 # get the rank number....
35 my ($rank,$reserves) = FindReserves($biblionumber);
36 foreach my $res (@$reserves) {
37 if ($res->{'found'} eq 'W') {
42 $template->param(rank => $rank);
46 # pass the pickup branch along....
47 my $branch = $query->param('branch');
48 $template->param(branch => $branch);
50 my $branches = getbranches();
51 $template->param(branchname => $branches->{$branch}->{'branchname'});
54 # make branch selection options...
55 my $branchoptions = '';
56 foreach my $br (keys %$branches) {
57 (next) unless $branches->{$br}->{'IS'};
60 $selected = "selected";
62 $branchoptions .= "<option value=$br $selected>$branches->{$br}->{'branchname'}</option>\n";
64 $template->param( branchoptions => $branchoptions);
67 #get the bibitem data....
68 my ($count,@data) = bibitems($biblionumber);
70 foreach my $bibitem (@data) {
71 my @barcodes = barcodes($bibitem->{'biblioitemnumber'});
72 my $barcodestext = "";
73 foreach my $num (@barcodes) {
74 my $message = $num->{'itemlost'} == 1 ? "(lost)" :
75 $num->{'itemlost'} == 2 ? "(long overdue)" : "($branches->{$num->{'holdingbranch'}}->{'branchname'})";
76 $barcodestext .= "$num->{'barcode'} $message <br>";
78 $barcodestext = substr($barcodestext, 0, -4);
79 $bibitem->{'copies'} = $barcodestext;
84 my @reqbibs = $query->param('reqbib');
85 if ($query->param('bibitemsselected')) {
86 $template->param(bibitemsselected => 1);
88 foreach my $bibitem (@data) {
89 foreach my $reqbib (@reqbibs){
90 push @tempdata, $bibitem if ($bibitem->{'biblioitemnumber'} == $reqbib) ;
94 } elsif ($query->param('placereserve')) {
95 # here we actually do the reserveration....
96 my $title = $bibdata->{'title'};
97 CreateReserve(undef,$branch,$borrowernumber,$biblionumber,'o',\@reqbibs,$rank,'',$title);
98 warn "reserve created\n";
99 print $query->redirect("/cgi-bin/koha/opac-user.pl");
101 $template->param(selectbibitems => 1);
103 # check that you can actually make the reserve.
107 $template->param(BIBLIOITEMS => \@data);
109 $template->param(loggedinuser => $loggedinuser);
110 print "Content-Type: text/html\n\n", $template->output;