YAB ! (Yet Another Bugfix) => related to biblio modif
[koha.git] / request.pl
index 1bd575a..fd2d644 100755 (executable)
@@ -1,5 +1,7 @@
 #!/usr/bin/perl
 
+# $Id$
+
 #script to place reserves/requests
 #writen 2/1/00 by chris@katipo.oc.nz
 
@@ -26,7 +28,7 @@ use strict;
 use C4::Search;
 use C4::Output;
 use C4::Reserves2;
-use C4::Acquisitions;
+use C4::Biblio;
 use C4::Koha;
 use C4::Circulation::Circ2;
 
@@ -39,6 +41,7 @@ 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--;
@@ -71,8 +74,8 @@ my ($count2,@data) = bibitems($bib);
 my $bibitemrows = "";
 
 
-for (my $i=0; $i<$count2; $i++) {
-    my @barcodes = barcodes($data[$i]->{'biblioitemnumber'});
+foreach my $dat (sort {$b->{'dateaccessioned'} cmp $a->{'dateaccessioned'}} @data) {
+    my @barcodes = barcodes($dat->{'biblioitemnumber'});
     my $barcodestext = "";
     foreach my $num (@barcodes) {
        my $message = $num->{'itemlost'} == 1 ? "(lost)" :
@@ -81,26 +84,26 @@ for (my $i=0; $i<$count2; $i++) {
     }
     $barcodestext = substr($barcodestext, 0, -4);
 
-    $data[$i]->{'dewey'}="" if ($data[$i]->{'dewey'} == 0);
+    $dat->{'dewey'}="" if ($dat->{'dewey'} == 0);
 
-    $data[$i]->{'volumeddesc'} = "&nbsp;" unless $data[$i]->{'volumeddesc'};
-    $data[$i]->{'dewey'}=~ s/\.0000$//;
-    $data[$i]->{'dewey'}=~ s/00$//;
-    my $class="$data[$i]->{'classification'}$data[$i]->{'dewey'}$data[$i]->{'subclass'}";
+    $dat->{'volumeddesc'} = "&nbsp;" unless $dat->{'volumeddesc'};
+    $dat->{'dewey'}=~ s/\.0000$//;
+    $dat->{'dewey'}=~ s/00$//;
+    my $class="$dat->{'classification'}$dat->{'dewey'}$dat->{'subclass'}";
     my $select;
-    if (($data[$i]->{'notforloan'}) 
-       || ($data[$i]->{'itemlost'} == 1))  {
+    if (($dat->{'notforloan'})
+       || ($dat->{'itemlost'} == 1))  {
        $select = "Cannot be reserved.";
     } else {
-       $select = " <input type=checkbox name=reqbib value=$data[$i]->{'biblioitemnumber'}><input type=hidden name=biblioitem value=$data[$i]->{'biblioitemnumber'}>";
+       $select = " <input type=checkbox name=reqbib value=$dat->{'biblioitemnumber'}><input type=hidden name=biblioitem value=$dat->{'biblioitemnumber'}>";
     }
     $bibitemrows .= <<"EOF";
 <tr VALIGN=TOP>
 <TD>$select</td>
-<TD>$data[$i]->{'description'}</td>
+<TD>$dat->{'description'}</td>
 <TD>$class</td>
-<td>$data[$i]->{'volumeddesc'}</td>
-<td>$data[$i]->{'publicationyear'}</td>
+<td>$dat->{'volumeddesc'}</td>
+<td>$dat->{'publicationyear'}</td>
 <td>$barcodestext</td>
 </tr>
 EOF
@@ -111,7 +114,7 @@ EOF
 
 my $existingreserves = "";
 foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
-    my $prioropt = priorityoptions($count, $res->{'priority'});
+    my $prioropt = priorityoptions($totalcount, $res->{'priority'});
     my $bropt = branchoptions($res->{'branchcode'});
     my $bor=$res->{'borrowernumber'};
     $date = slashifyDate($res->{'reservedate'});
@@ -126,32 +129,32 @@ foreach my $res (sort {$a->{'found'} cmp $b->{'found'}} @$reserves){
     my $notes = $res->{'reservenotes'}." ";
     my $rank;
     my $pickup;
-    my $change;
     if ($res->{'found'} eq 'W') {
        my %env;
        my $item = $res->{'itemnumber'};
        $item = getiteminformation(\%env,$item);
        $item = "<a href=/cgi-bin/koha/detail.pl?bib=$item->{'biblionumber'} &type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$item->{'barcode'}</a>";
-       my $wbra = $branches->{$res->{'branchcode'}}->{'branchname'};
-       $rank = "Item waiting";
+       my $wbrcd = $res->{'branchcode'};
+       my $wbra = $branches->{$wbrcd}->{'branchname'};
        $type = $item;
-       $pickup = "at <b>".$wbra."</b>";
-       $change = "<input type=checkbox name=rank-request value=del>delete";
+       $rank = "<select name=rank-request><option value=W selected>Waiting</option>$prioropt<option value=del>Del</option></select>";
+       $pickup = "Item waiting at <b>".$wbra."</b> <input type=hidden name=pickup value=$wbrcd>";
     } else {
-       $rank = "<select name=rank-request>$prioropt<option value=del>Del</select>";
+       $rank = "<select name=rank-request>$prioropt<option value=del>Del</option></select>";
        $pickup = "<select name=pickup>$bropt</select>";
     }
     $existingreserves .= <<"EOF";
+<tr VALIGN=TOP>
+<TD>
 <input type=hidden name=borrower value=$res->{'borrowernumber'}>
 <input type=hidden name=biblio value=$res->{'biblionumber'}>
-<tr VALIGN=TOP>
-<TD>$rank</td>
+$rank</td>
 <TD>
 <a href=/cgi-bin/koha/moremember.pl?bornum=$bor>$res->{'firstname'} $res->{'surname'}</a>
 </td>
 <td>$notes</td>
 <TD>$date</td>
-<TD>$pickup</td>
+<TD>OO $pickup</td>
 <TD>$type</td>
 </tr>
 EOF
@@ -167,7 +170,7 @@ sub priorityoptions {
        if ($sel == $i){
            $out .= " selected";
        }
-       $out .= ">$i\n";
+       $out .= ">$i</option>\n";
     }
     return $out;
 }
@@ -178,25 +181,31 @@ sub branchoptions {
     my $out = "";
     foreach my $br (keys %$branches) {
        (next) unless $branches->{$br}->{'IS'};
+                       # Only branches with the 'IS' branchrelation
+                       # can issue books
        my $selected = "";
        if ($br eq $selbr) {
            $selected = "selected";
        }
-       $out .= "<option value=$br $selected>$branches->{$br}->{'branchname'}\n";
+       $out .= "<option value=$br $selected>$branches->{$br}->{'branchname'}</option>\n";
     }
     return $out;
 }
 
 
+#get the time for the form name...
+my $time = time();
+
 
 # printout the page
 
 
-print $input->header;
+
+
+print $input->header(-expires=>'now');
 
 
 #setup colours
-print startpage();
 print startmenu('catalogue');
 
 
@@ -210,12 +219,12 @@ print <<printend
 <input type=hidden name=type value=str8>
 <input type=hidden name=title value="$dat->{'title'}">
 <FONT SIZE=6><em>Requesting: <br>
-<a href=/cgi-bin/koha/detail.pl?bib=$bib>$dat->{'title'}</a> 
+<a href=/cgi-bin/koha/detail.pl?bib=$bib>$dat->{'title'}</a>
 ($dat->{'author'})</em></FONT><P>
 <p>
 
 
-<!----------------BIBLIO RESERVE TABLE-------------->
+
 
 
 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
@@ -237,10 +246,10 @@ $priorityoptions
 <td><select name=pickup>
 $branchoptions
 </select></td>
-<td><input type=checkbox name=request value=any>Next Available, 
+<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 >
@@ -255,13 +264,15 @@ $branchoptions
 </TR>
 $bibitemrows
 </table>
-</p>
+
 </form>
 <p>&nbsp;</p>
 
 
 
-<!-----------MODIFY EXISTING REQUESTS----------------->
+
+
+<form name=T$time action=modrequest.pl method=post>
 
 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
 
@@ -269,7 +280,6 @@ $bibitemrows
 
 <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>