Getting web links going
[koha.git] / request.pl
index a36063b..dd49478 100755 (executable)
 #!/usr/bin/perl
 
+# $Id$
+
 #script to place reserves/requests
 #writen 2/1/00 by chris@katipo.oc.nz
 
+
+# Copyright 2000-2002 Katipo Communications
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA  02111-1307 USA
+
 use strict;
-#use DBI;
 use C4::Search;
-use CGI;
 use C4::Output;
+use C4::Auth;
 use C4::Reserves2;
-use C4::Acquisitions;
+use C4::Biblio;
+use C4::Koha;
+use C4::Circulation::Circ2;
+use HTML::Template;
+use C4::Catalogue;
+use CGI;
+use C4::Date;
+
 my $input = new CGI;
-print $input->header;
 
+# get biblio information....
+my $bib = $input->param('bib');
+my $dat = bibdata($bib);
+
+# get existing reserves .....
+my ($count,$reserves) = FindReserves($bib);
+my $totalcount = $count;
+foreach my $res (@$reserves) {
+    if ($res->{'found'} eq 'W') {
+       $count--;
+    }
+}
 
-#setup colours
-print startpage();
-print startmenu();
-my $blah;
-my $bib=$input->param('bib');
-my $dat=bibdata($bib);
-my ($count,$reserves)=FindReserves($bib);
-#print $count;
-#print $input->dump;
-
-
-print <<printend
-<form action="placerequest.pl" method=post>
-<INPUT TYPE="image" name="submit"  VALUE="request" height=42  WIDTH=187 BORDER=0 src="/images/place-request.gif" align=right >
-<input type=hidden name=biblio value=$bib>
-<input type=hidden name=type value=str8>
-<input type=hidden name=title value="$dat->{'title'}">
-<FONT SIZE=6><em>Requesting: <a href=/cgi-bin/koha/detail.pl?bib=$bib>$dat->{'title'}</a> ($dat->{'author'})</em></FONT><P>
-<p>
-
-<TABLE  CELLSPACING=0  CELLPADDING=5 border=1 align=left >
-
-<!----------------BIBLIO RESERVE TABLE-------------->
-
-
-
-<TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
-<TR VALIGN=TOP>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Rank</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Member Number</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Notes</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Date</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Pickup</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Request</b></TD>
-</TR>
-<tr VALIGN=TOP  >
-<TD><select name=rank-request>
-printend
-;
-$count++;
-my $i;
-for ($i=1;$i<$count;$i++){
-  print "<option value=$i>$i\n";
+# make priorities options
+my $num = $count + 1;
+
+#priorityoptions building
+my @optionloop;
+for (my $i=1; $i<=$num; $i++){
+       my %option;
+       $option{num}=$i;
+       $option{selected}=($i==$num);
+       push(@optionloop, \%option);
 }
-print "<option value=$i selected>$i\n";
+
+# todays date
 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime(time);
 $year=$year+1900;
 $mon++;
-my $date="$mday/$mon/$year";
-print <<printend
-</select>
-</td>
-<TD><input type=text size=10 name=member></td>
-<TD><input type=text size=20 name=notes></td>
-<TD>$date</td>
-<TD><select name=pickup>
-printend
-;
-my ($count2,@branches)=branches;                                                                         
-for (my $i=0;$i<$count2;$i++){                                                                           
-  print "<option value=$branches[$i]->{'branchcode'}";                                                   
-  print ">$branches[$i]->{'branchname'}";                                                                
-}   
-print <<printend
-</select>
-</td>
-<td><input type=checkbox name=request value=any>Next Available, <br>(or choose from list below)</td>
-</tr>
-
-
-</table>
-</p>
-
-
-<TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
-<TR VALIGN=TOP>
-
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Request</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Item Type</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Classification</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Volume</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>ISBN</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Copyright</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Pubdate</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Copies</b></TD>
-</TR>
-printend
-;
-my $blah;
-my ($count2,@data)=bibitems($bib);
-for ($i=0;$i<$count2;$i++){
-  my @barcodes=barcodes($data[$i]->{'biblioitemnumber'});
-  if ($data[$i]->{'dewey'} == 0){
-    $data[$i]->{'dewey'}="";
-  }
-  $data[$i]->{'dewey'}=~ s/\.0000$//;
-  $data[$i]->{'dewey'}=~ s/00$//;
-  my $class="$data[$i]->{'classification'}$data[$i]->{'dewey'}$data[$i]->{'subclass'}";
-  print "<tr VALIGN=TOP  >
-  <TD><input type=checkbox name=reqbib value=$data[$i]->{'biblioitemnumber'}>
-  <input type=hidden name=biblioitem value=$data[$i]->{'biblioitemnumber'}>
-  </td>
-  <TD>$data[$i]->{'description'}</td>
-  <TD>$class</td>                                                                                                                                                                                              
-  <td>$data[$i]->{'volumeddesc'}</td>
-  <td>$data[$i]->{'isbn'}</td>
-  <td>$dat->{'copyrightdate'}</td>
-  <td>$data[$i]->{'publicationyear'}</td>
-  <td>@barcodes</td>
-  </tr>";
-}
-print <<printend
-</table>
-</p>
-</form>
-<p>&nbsp; </p>
-<!-----------MODIFY EXISTING REQUESTS----------------->
-
-<TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
-
-<TR VALIGN=TOP>
-
-<td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=7><B>MODIFY EXISTING REQUESTS </b></TD>
-</TR>
-<form action=modrequest.pl method=post>
-<TR VALIGN=TOP>
-
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Rank</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Member</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Notes</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Date</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Pickup</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Request</b></TD>
-<td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Change To</b></TD>
-</TR>
-printend
-;
-$count--;
-
-for ($i=0;$i<$count;$i++){
-print "<input type=hidden name=borrower value=$reserves->[$i]{'borrowernumber'}>";
-print "<input type=hidden name=biblio value=$reserves->[$i]{'biblionumber'}>";
-#my $bor=$reserves->[$i]{'firstname'}."%20".$reserves->[$i]{'surname'};
-#$bor=~ s/ /%20/g;
-my $bor=$reserves->[$i]{'borrowernumber'};
-my @temp=split('-',$reserves->[$i]{'reservedate'});
-$date="$temp[2]/$temp[1]/$temp[0]";
-my $type=$reserves->[$i]{'constrainttype'};
-#print "test";
-if ($type eq 'a'){
-  $type='Next Available';
-} elsif ($type eq 'o'){
-# print "test";
-  my $res=getreservetitle($reserves->[$i]{'biblionumber'},$reserves->[$i]{'borrowernumber'},$reserves->[$i]{'reservedate'},$reserves->[$i]{'timestamp'});
-  $type="This type only $res->{'volumeddesc'} $res->{'itemtype'}";
-#  my @data=ItemInfo(\$blah,$reserves->[$i]{'borrowernumber'});
-  
-}
-print "<tr VALIGN=TOP  >
-<TD><select name=rank-request>
-";
-for (my $i2=1;$i2<=$count;$i2++){
-  print "<option value=$i2";
-  if ($reserves->[$i]{'priority'} eq $i2){
-    print " selected";
-  }
-  print">$i2";
+my $date=format_date("$year-$mon-$mday");
+
+
+# get biblioitem information and build rows for form
+my ($count2,@data) = bibitems($bib);
+
+my @bibitemloop;
+foreach my $dat (sort {$b->{'dateaccessioned'} cmp $a->{'dateaccessioned'}} @data) {
+    $dat->{'dewey'}="" if ($dat->{'dewey'} == 0);
+    $dat->{'volumeddesc'} = "&nbsp;" unless $dat->{'volumeddesc'};
+    $dat->{'dewey'}=~ s/\.0000$//;
+    $dat->{'dewey'}=~ s/00$//;
+
+       my %abibitem;
+       my @barcodeloop;
+    my @barcodes = barcodes($dat->{'biblioitemnumber'});
+    foreach my $num (@barcodes) {
+               my %barcode;
+               $barcode{'barcode'}=$num->{'barcode'};
+               $barcode{'message'}=$num->{'itemlost'} == 1 ? "(lost)" :
+           $num->{'itemlost'} == 2 ? "(long overdue)" : "";
+               push(@barcodeloop, \%barcode);
+    }
+       $abibitem{'barcodeloop'}=\@barcodeloop;
+    $abibitem{'class'}="$dat->{'classification'}$dat->{'dewey'}$dat->{'subclass'}";
+    my $select;
+    $abibitem{'itemlost'}=(($dat->{'notforloan'})|| ($dat->{'itemlost'} == 1)) ;
+       $abibitem{'biblioitemnumber'}=$dat->{'biblioitemnumber'};
+       $abibitem{'description'}=$dat->{'description'};
+       $abibitem{'volumeddesc'}=$dat->{'volumeddesc'};
+       $abibitem{'publicationyear'}=$dat->{'publicationyear'};
+       push(@bibitemloop,\%abibitem);
 }
-print "<option value=del>Del";
-print "</select>
-</td>
-<TD><a href=/cgi-bin/koha/moremember.pl?bornum=$bor>$reserves->[$i]{'firstname'} $reserves->[$i]{'surname'}</a></td>
-<td>$reserves->[$i]{'reservenotes'}</td>
-<TD>$date</td>
-<TD><select name=pickup>
-";
-my ($count2,@branches)=branches;                                                                         
-for (my $i2=0;$i2<$count2;$i2++){                                                                           
-  print "<option value=$branches[$i2]->{'branchcode'}";                                                   
-  if ($reserves->[$i]{'branchcode'} eq $branches[$i2]->{'branchcode'}){                                           
-    print " Selected";                                                                                   
-  }
-  print ">$branches[$i2]->{'branchname'}\n";                                                                
-}   
-print "
-</select>
-</td>
-<TD>$type</td>
-<TD><select name=itemtype>
-<option value=next>Next Available
-<option value=change>Change Selection
-<option value=nc >No Change
-</select>
-</td>
-</tr>
-";
-}
-print <<printend
-
-
-<tr VALIGN=TOP  >
-
-<TD colspan=6 align=right>
-Delete a request by selecting "del" from the rank list.
-
-<INPUT TYPE="image" name="submit"  VALUE="request" height=42  WIDTH=64 BORDER=0 src="/images/ok.gif"></td>
-
 
-</tr>
-
-
-</table>
-<P>
-
-<br>
 
 
+#existingreserves building
+my @reserveloop;
+my $branches = getbranches();
+foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
+       my %reserve;
+#    my $prioropt = priorityoptions($totalcount, $res->{'priority'});
+       my @optionloop;
+       for (my $i=1; $i<=$totalcount; $i++){
+               my %option;
+               $option{num}=$i;
+               $option{selected}=($i==$res->{'priority'});
+               push(@optionloop, \%option);
+       }
+       my @branchloop;
+       foreach my $br (keys %$branches) {
+#              (next) unless $branches->{$br}->{'IS'};
+                               # Only branches with the 'IS' branchrelation
+                               # can issue books
+               my %abranch;
+               $abranch{'selected'}=($br eq $res->{'branchcode'});
+               $abranch{'branch'}=$br;
+               $abranch{'branchname'}=$branches->{$br}->{'branchname'};
+               push(@branchloop,\%abranch);
+       }
+
+    if ($res->{'found'} eq 'W') {
+               my %env;
+               my $item = $res->{'itemnumber'};
+               $item = getiteminformation(\%env,$item);
+               $reserve{'barcode'}=$item->{'barcode'};
+               $reserve{'biblionumber'}=$item->{'biblionumber'};
+               $reserve{'wbrcode'} = $res->{'branchcode'};
+               $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
+    }
+    $reserve{'date'} = format_date($res->{'reservedate'});
+       $reserve{'borrowernumber'}=$res->{'borrowernumber'};
+       $reserve{'biblionumber'}=$res->{'biblionumber'};
+       $reserve{'bornum'}=$res->{'borrowernumber'};
+       $reserve{'firstname'}=$res->{'firstname'};
+       $reserve{'bornum'}=$res->{'borrowernumber'};
+       $reserve{'notes'}=$res->{'reservenotes'};
+       $reserve{'wait'}=($res->{'found'} eq 'W');
+       $reserve{'constrainttypea'}=($res->{'constrainttype'} eq 'a');
+       $reserve{'constrainttypeo'}=($res->{'constrainttype'} eq 'o');
+       $reserve{'voldesc'}=$res->{'volumeddesc'};
+       $reserve{'itemtype'}=$res->{'itemtype'};
+       $reserve{'branchloop'}=\@branchloop;
+       $reserve{'optionloop'}=\@optionloop;
+       push(@reserveloop,\%reserve);
+}
 
+my @branches;
+my @select_branch;
+my %select_branches;
+my ($count2,@branches)=branches();
+for (my $i=0;$i<$count2;$i++){
+       push @select_branch, $branches[$i]->{'branchcode'};#
+       $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
+}
+my $CGIbranch=CGI::scrolling_list( -name     => 'pickup',
+                       -values   => \@select_branch,
+                       -labels   => \%select_branches,
+                       -size     => 1,
+                       -multiple => 0 );
 
-</form>
-printend
-;
+#get the time for the form name...
+my $time = time();
 
-print endmenu();
-print endpage();
+#setup colours
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "request.tmpl",
+                                                       query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                         });
+$template->param(      optionloop =>\@optionloop,
+                                                               CGIbranch => $CGIbranch,
+                                                               reserveloop => \@reserveloop,
+                                                               'time' => $time,
+                                                               bibitemloop => \@bibitemloop,
+                                                               date => $date,
+                                                               bib => $bib,
+                                                               title =>$dat->{title});
+# printout the page
+print $input->header(-expires=>'now'), $template->output;