Added variables available to template: streetaddress, city, phone, cardnumber. Added...
[srvgit] / circ / circulation.pl
index 65240f5..9f34ce5 100755 (executable)
@@ -83,7 +83,7 @@ my $borrowerslist;
 # if there is a list of find borrowers....
 my $findborrower = $query->param('findborrower');
 if ($findborrower) {
-       my ($borrowers, $flags) = findborrower(\%env, $findborrower);
+       my ($count,$borrowers)=BornameSearch(\%env,$findborrower,'web');
        my @borrowers=@$borrowers;
        if ($#borrowers == -1) {
                $query->param('findborrower', '');
@@ -138,7 +138,6 @@ my $day=$query->param('day');
 if ($barcode) {
        $barcode = cuecatbarcodedecode($barcode);
        my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
-
        unless ($invalidduedate) {
                $env{'datedue'}=$datedue;
                my @time=localtime(time);
@@ -156,9 +155,13 @@ if ($borrowernumber) {
 ##################################################################################
 # HTML code....
 
-my $responsesform = '';
+my %responseform;
+my @responsearray;
 foreach (keys %responses) {
-    $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
+#    $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
+    $responseform{'name'}=$_;
+    $responseform{'value'}=$responses{$_};
+    push @responsearray,\%responseform;
 }
 my $questionform;
 my $stickyduedate;
@@ -168,6 +171,10 @@ if ($question) {
 
 
 # Barcode entry box, with hidden inputs attached....
+
+# FIXME - How can we move this HTML into the template?  Can we create
+# arrays of the months, dates, etc and use <TMPL_LOOP> in the template to 
+# output the data that's getting built here?
 my $counter = 1;
 my $dayoptions = '';
 my $monthoptions = '';
@@ -201,7 +208,13 @@ my $selected='';
 # make the issued books table.....
 my $todaysissues='';
 my $previssues='';
+my @realtodayissues;
+my @realprevissues;
+my $allowborrow;
+my $hash;
 if ($borrower) {
+    ($borrower, $flags,$hash) = getpatroninformation(\%env,$borrowernumber,0);
+    $allowborrow= $hash->{'borrow'};
     my @todaysissues;
     my @previousissues;
     my $issueslist = getissues($borrower);
@@ -214,64 +227,57 @@ if ($borrower) {
            push @previousissues, $issueslist->{$it};
        }
     }
-    my $tcolor = '';
-    my $pcolor = '';
-    foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
-       my $dd = $book->{'date_due'};
-       my $datedue = $book->{'date_due'};
-       $dd=format_date($dd);
-       $datedue=~s/-//g;
-       if ($datedue < $todaysdate) {
-           $dd="<font color=red>$dd</font>\n";
+       my $tcolor = '';
+       my $pcolor = '';
+       foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
+               my $dd = $book->{'date_due'};
+               my $datedue = $book->{'date_due'};
+               $dd=format_date($dd);
+               $datedue=~s/-//g;
+# FIXME - Instead of declaring the font color here, can we set a variable 
+# that says 'overdue'?  Then the template can check for it: <TMPL_IF
+# NAME="overdue"><font color="red"></TMPL_IF>
+               if ($datedue < $todaysdate) {
+                       $dd="<font color=red>$dd</font>\n";
+               }
+               ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
+               $book->{'dd'}=$dd;
+               $book->{'tcolor'}=$tcolor;
+               if ($book->{'author'} eq ''){
+                   $book->{'author'}=' ';
+               }    
+               push @realtodayissues,$book;
        }
-       ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
-       $todaysissues .=<< "EOF";
-<tr><td bgcolor=$tcolor align=center>$dd</td>
-<td bgcolor=$tcolor align=center>
-<a href=/cgi-bin/koha/detail.pl?bib=$book->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$book->{'barcode'}</a></td>
-<td bgcolor=$tcolor>$book->{'title'}</td>
-<td bgcolor=$tcolor>$book->{'author'}</td>
-<td bgcolor=$tcolor align=center>$book->{'dewey'} $book->{'subclass'}</td></tr>
-EOF
-    }
+    
+
     # FIXME - For small and private libraries, it'd be nice if this
     # table included a "Return" link next to each book, so that you
     # don't have to remember the book's bar code and type it in on the
     # "Returns" page.
+
+    # This is in the template now, so its possible for a small library to make that link in their
+    # template
+
     foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
        my $dd = $book->{'date_due'};
        my $datedue = $book->{'date_due'};
        $dd=format_date($dd);
+       my $pcolor = '';
        $datedue=~s/-//g;
        if ($datedue < $todaysdate) {
+# FIXME - See line 233 above regarding overdues
            $dd="<font color=red>$dd</font>\n";
        }
-       ($pcolor eq $linecolor1) ? ($pcolor=$linecolor2) : ($pcolor=$linecolor1);
-       $previssues .= << "EOF";
-<tr><td bgcolor=$pcolor align=center>$dd</td>
-<td bgcolor=$pcolor align=center>
-<a href=/cgi-bin/koha/detail.pl?bib=$book->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$book->{'barcode'}</a></td>
-<td bgcolor=$pcolor>$book->{'title'}</td>
-<td bgcolor=$pcolor>$book->{'author'}</td>
-<td bgcolor=$pcolor align=center>$book->{'dewey'} $book->{'subclass'}</td></tr>
-EOF
-    }
+       ($pcolor eq $linecolor1) ? ($pcolor=$linecolor2) : ($pcolor=$linecolor1); 
+       $book->{'dd'}=$dd; 
+       $book->{'tcolor'}=$pcolor;
+       if ($book->{'author'} eq ''){
+           $book->{'author'}=' ';
+       }    
+       push @realprevissues,$book
+   }
 }
 
-# actually print the page!
-#if ($branchcookie && $printercookie) {
-#    print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie,$sessioncookie]);
-#} else {
-#    print $query->header(-cookie=>[$sessioncookie]);
-#}
-
-#if ($query->param('barcode') eq '' && $query->param('charges') eq 'yes'){
-#    my $count=@inp;
-#     for (my $i=0;$i<$count;$i++){
-#       $inp[$i]=~ s/onLoad=focusinput\(\)/onLoad=focusinput\(\)\;messenger\(\"\/cgi-bin\/koha\/pay.pl?bornum=$bornum\",700,600\)\;window1.focus\(\)/;
-#     }
-#}
-
 my @values;
 my %labels;
 my $CGIselectborrower;
@@ -300,13 +306,18 @@ $template->param(
                printer => $printer,
                branchname => $branches->{$branch}->{'branchname'},
                printername => $printers->{$printer}->{'printername'},
-
+               allowborrow =>$allowborrow,
                #question form
                question => $question,
                title => $iteminformation->{'title'},
                author => $iteminformation->{'author'},
                firstname => $borrower->{'firstname'},
                surname => $borrower->{'surname'},
+               categorycode => $borrower->{'categorycode'},
+               streetaddress => $borrower->{'streetaddress'},
+               city => $borrower->{'city'},
+               phone => $borrower->{'phone'},
+               cardnumber => $borrower->{'cardnumber'},
                question => $question,
                barcode => $barcode,
                questionnumber => $questionnumber,
@@ -314,17 +325,17 @@ $template->param(
                monthoptions => $monthoptions,
                yearoptions => $yearoptions,
                stickyduedate => $stickyduedate,
-               responseform => $responsesform,
                rejected => $rejected,
                message => $message,
                CGIselectborrower => $CGIselectborrower,
-
-               patrontable => $patrontable,
-               flaginfotable => $flaginfotable,
-               CHARGES => $flags->{'CHARGES'},
                amountold => $amountold,
-               todayissues => $todaysissues,
-               previssues => $previssues,
+               todayissues => \@realtodayissues,
+               previssues => \@realprevissues,
+               responseloop => \@responsearray,
+                month=>$month,
+                day=>$day,
+                year=>$year
+                
        );
 
 if ($branchcookie) {
@@ -355,6 +366,13 @@ sub fixdate {
     if (($year eq 0) && ($month eq 0) && ($year eq 0)) {
        $env{'datedue'}='';
     } else {
+       
+# FIXME - Can we set two flags here, one that says 'invalidduedate', so that 
+# the template can check for it, and then one for a particular message?
+# Ex: <TMPL_IF NAME="invalidduedate">  <TMPL_IF NAME="daysinFeb">
+# Invalid Due Date Specified. Book was not issued.  Never that many days
+# in February! </TMPL_IF> </TMPL_IF>
+
        if (($year eq 0) || ($month eq 0) || ($year eq 0)) {
            $invalidduedate="Invalid Due Date Specified. Book was not issued.<p>\n";
        } else {
@@ -365,7 +383,7 @@ sub fixdate {
            } elsif (($month == 2) && ($day > 28) && (($year%4) && ((!($year%100) || ($year%400))))) {
                $invalidduedate="Invalid Due Date Specified. Book was not issued.  $year is not a leap year.<p>\n";
            } else {
-               $date=format_date("$year-$month-$day");
+               $date="$year-$month-$day";
            }
        }
     }
@@ -377,61 +395,76 @@ sub patrontable {
     my ($borrower) = @_;
     my $flags = $borrower->{'flags'};
     my $flaginfotable='';
-    my $flaginfotext='';
+    my $flaginfotext;
+    #my $flaginfotext='';
     my $flag;
     my $color='';
     foreach $flag (sort keys %$flags) {
+       warn $flag;
+#      my @itemswaiting='';
        ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
        $flags->{$flag}->{'message'}=~s/\n/<br>/g;
        if ($flags->{$flag}->{'noissues'}) {
-           if ($flag eq 'CHARGES') {
-               $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color><b>$flags->{$flag}->{'message'}</b> <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>\n";
-           } else {
-               $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>\n";
-           }
+               $template->param(
+                       noissues => 'true',
+                       color => $color,
+                        );
+               if ($flag eq 'CHARGES') {
+                       $template->param(
+                               charges => 'true',
+                               chargesmsg => $flags->{'CHARGES'}->{'message'}
+                                );
+               }
        } else {
-           if ($flag eq 'CHARGES') {
-               $flaginfotext.="<tr><td valign=top>$flag</td><td> $flags->{$flag}->{'message'} <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>\n";
-           } elsif ($flag eq 'WAITING') {
-               my $itemswaiting='';
-               my $items=$flags->{$flag}->{'itemlist'};
-               foreach my $item (@$items) {
-                   my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
-                   $itemswaiting.="<a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$iteminformation->{'barcode'}</a> $iteminformation->{'title'} ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>\n";
+                if ($flag eq 'CHARGES') {
+                       $template->param(
+                               charges => 'true',
+                               chargesmsg => $flags->{'CHARGES'}->{'message'}
+                        );
                }
-               $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
-           } elsif ($flag eq 'ODUES') {
-               my $items=$flags->{$flag}->{'itemlist'};
-               my $itemswaiting="<table border=1 cellspacing=0 cellpadding=2>\n";
-               my $currentcolor=$color;
-               {
-                   my $color=$currentcolor;
-                   foreach my $item (@$items) {
-                       ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
+               if ($flag eq 'WAITING') {
+                       my $items=$flags->{$flag}->{'itemlist'};
+                       my @itemswaiting;
+                       foreach my $item (@$items) {
                        my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
-                       $itemswaiting.="<tr><td><font color=red>$iteminformation->{'date_due'}</font></td><td bgcolor=$color><a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$iteminformation->{'barcode'}</a></td><td>$iteminformation->{'title'}</td></tr>\n";
-                   }
+                       $iteminformation->{'branchname'} = $branches->{$iteminformation->{'holdingbranch'}}->{'branchname'};
+                       push @itemswaiting, $iteminformation;
+                       }
+                       $template->param(
+                               waiting => 'true',
+                               waitingmsg => $flags->{'WAITING'}->{'message'},
+                               itemswaiting => \@itemswaiting,
+                                );
                }
-               $itemswaiting.="</table>\n";
-               if ($query->param('module') ne 'returns'){
-                 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}, See below</td></tr>\n";
-               } else {
-                 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
+               if ($flag eq 'ODUES') {
+                       $template->param(
+                               odues => 'true',
+                               oduesmsg => $flags->{'ODUES'}->{'message'}
+                                );
+
+                       my $items=$flags->{$flag}->{'itemlist'};
+                       my $currentcolor=$color;
+                       {
+                       my $color=$currentcolor;
+                           my @itemswaiting;
+                       foreach my $item (@$items) {
+                               ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
+                               my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
+                               push @itemswaiting, $iteminformation;
+                       }
+                       }
+                       if ($query->param('module') ne 'returns'){
+                               $template->param( nonreturns => 'true' );
+                       }
+               }
+               if ($flag eq 'NOTES') {
+                       $template->param(
+                               notes => 'true',
+                               notesmsg => $flags->{'NOTES'}->{'message'}
+                                );
                }
-           } else {
-               $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
-           }
        }
     }
-    ($flaginfotext) && ($flaginfotext="<tr><td  colspan=2><b>Flags</b></td></tr>$flaginfotext\n");
-    $flaginfotext.="</table>";
-    my $patrontable= << "EOF";
-<br><p>
-    <table border=1 cellpadding=5 cellspacing=0 align=right>
-    <tr><td colspan=2><font color=black><b>Patron Information</b></font></td></tr>
-    <tr><td colspan=2>
-    <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'} onClick="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a> $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>$borrower->{'streetaddress'} $borrower->{'city'} Cat: $borrower->{'categorycode'} </td></tr>
-EOF
     return($patrontable, $flaginfotext);
 }