turned of the branchtransfer when an item is set to "waiting".
[koha.git] / memberentry.pl
index 0080839..815643e 100755 (executable)
@@ -3,11 +3,30 @@
 #script to set up screen for modification of borrower details
 #written 20/12/99 by chris@katipo.co.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 C4::Output;
 use CGI;
 use C4::Search;
-
+use C4::Database;
+use C4::Koha;
 
 my $input = new CGI;
 my $member=$input->param('bornum');
@@ -15,7 +34,11 @@ if ($member eq ''){
   $member=NewBorrowerNumber();
 }
 my $type=$input->param('type');
-
+my $modify=$input->param('modify.x'); 
+my $delete=$input->param('delete.x');
+if ($delete){
+  print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
+} else {
 print $input->header;
 print startpage();
 print startmenu('member');
@@ -39,13 +62,57 @@ if ($type eq 'Add'){
 } else {
   print "<input type=hidden name=updtype value=M>";
 }
+
+my $cardnumber=$data->{'cardnumber'};
+my %systemprefs=systemprefs();
+# FIXME
+# This logic should probably be moved out of the presentation code.
+# Not tonight though.
+#
+if ($cardnumber eq '' && $systemprefs{'autoMemberNum'} eq '1') {
+  my $dbh=C4Connect;
+  my $query="select max(substring(borrowers.cardnumber,2,7)) from borrowers";
+  my $sth=$dbh->prepare($query);
+  $sth->execute;
+  my $data=$sth->fetchrow_hashref;
+  $cardnumber=$data->{'max(substring(borrowers.cardnumber,2,7))'};
+  $sth->finish;
+  $dbh->disconnect;
+  # purpose: generate checksum'd member numbers.
+  # We'll assume we just got the max value of digits 2-8 of member #'s from the database and our job is to
+  # increment that by one, determine the 1st and 9th digits and return the full string.
+  my @weightings = (8,4,6,3,5,2,1);
+  my $sum;
+  my $i = 0;
+  if (! $cardnumber) {                         # If DB has no values, start at 1000000
+    $cardnumber = 1000000;
+  } else {
+    $cardnumber = $cardnumber + 1;
+  }
+
+  while ($i <8) {                      # step from char 1 to 7.
+    my $temp1 = $weightings[$i];       # read weightings, left to right, 1 char at a time
+    my $temp2 = substr($cardnumber,$i,1);      # sequence left to right, 1 char at a time
+#print "$temp2<br>";
+    $sum = $sum + ($temp1*$temp2);     # mult each char 1-7 by its corresponding weighting
+    $i++;                              # increment counter
+  }
+  my $rem = ($sum%11);                 # remainder of sum/11 (eg. 9999999/11, remainder=2)
+  if ($rem == 10) {                    # if remainder is 10, use X instead
+    $rem = "X";
+  }  
+  $cardnumber="V$cardnumber$rem";
+} else {
+  $cardnumber=$data->{'cardnumber'};
+}
+
 print <<printend
 
 <table border=0 cellspacing=0 cellpadding=5 >
 
 
 <tr valign=top><td  COLSPAN=2><input type=reset value="Clear all Fields"></td><td  COLSPAN=3   ALIGN=RIGHT ><font size=4 face='arial,helvetica'>
-Member# $member,   Card Number* <input type=text name=cardnumber size=10 value="$data->{'cardnumber'}"><br>
+Member# $member,   Card Number* <input type=text name=cardnumber size=10 value="$cardnumber"><br>
 </td></tr>
 
 
@@ -123,96 +190,49 @@ print <<printend
 
 <tr><td>&nbsp; </TD></TR>
 <tr valign=top bgcolor=white>
-<td colspan=2><SELECT NAME="ethnicity" SIZE="1">
+<td colspan=2>
 printend
 ;
-print "<OPTION value=\" \">
-<OPTION value=european";
-if ($data->{'ethnicity'} eq 'european'){
-  print " selected";
-}
-print "
->European/Pakeha
-<OPTION value=maori";
-if ($data->{'ethnicity'} eq 'maori'){
-  print " selected";
-}
-print ">Maori
-<OPTION value=asian";
-if ($data->{'ethnicity'} eq 'asian'){
-  print " selected";
-}
-print ">Asian
-<OPTION value=pi";
-if ($data->{'ethnicity'} eq 'pi'){
-  print " selected";
-}
-print ">Pacific Island
-<OPTION value=other";
-if ($data->{'ethnicity'} eq 'other'){
-  print " selected";
-}
 
+my ($categories,$labels)=ethnicitycategories();
+my $ethnicitycategoriescount=$#{$categories};
+if ($ethnicitycategoriescount>=0) {
+       print $input->popup_menu(-name=>'ethnicity',
+                               -values=>$categories,
+                               -default=>$data->{'ethnicity'},
+                               -labels=>$labels);
 print <<printend
->Other - please specify-->
-</SELECT>
 </td>
 <td colspan=2><input type=text name=ethnicnotes size=40 ></td>
-<td> <select name=categorycode>
-<option value="A"
+<td> 
 printend
 ;
-if ($data->{'categorycode'} eq 'A'){
-  print " Selected";
-}
-print ">Adult
-<option value=B";
-if ($data->{'categorycode'} eq 'B'){
-  print " Selected";
-}
-print ">Homebound
-<option value=P";
-if ($data->{'categorycode'} eq 'P'){
-  print " Selected";
-}
-print ">Privileged
-<option value=E";
-if ($data->{'categorycode'} eq 'E'){
-  print " Selected";
-}
-print ">Senior Citizen
-<option value=W";
-if ($data->{'categorycode'} eq 'W'){
-  print " Selected";
-}
-print ">Staff
-<option value=I";
-if ($data->{'categorycode'} eq 'I'){
-  print " Selected";
-}
-print ">Institution
-<option value=C";
-if ($data->{'categorycode'} eq 'C'){
-  print " Selected";
-}
-print ">Child
-<option value=L";
-if ($data->{'categorycode'} eq 'L'){
-  print " Selected";
+} else {
+       print "</td><td colspan=2>&nbsp;</td><td>\n";
 }
-print ">Library
-<option value=F";
-if ($data->{'categorycode'} eq 'F'){
-  print " Selected";
+($categories,$labels)=borrowercategories();
+print $input->popup_menu(-name=>'categorycode',
+                               -values=>$categories,
+                               -default=>$data->{'categorycode'},
+                               -labels=>$labels);
+
+
+
+my $ethnicitylabels='';
+if ($ethnicitycategoriescount>=0) {
+       $ethnicitylabels=qq|
+<td colspan=2><FONT SIZE=2>Ethnicity</FONT></td>
+<td colspan=2><FONT SIZE=2>Ethnicity Notes</FONT></td>
+|;
+} else {
+       $ethnicitylabels="<td colspan=2>&nbsp;</td><td colspan=2>&nbsp;</td>";
 }
-print ">Family";
 print <<printend
-</select>
+
 </td>
 </tr>                                                                                                                                                                                                                                                                                                                                                                  
 <tr valign=top bgcolor=white>
-<td colspan=2><FONT SIZE=2>Ethnicity</FONT></td>
-<td colspan=2><FONT SIZE=2>Ethnicity Notes</FONT></td>
+$ethnicitylabels
 <td><FONT SIZE=2>Membership Category*</FONT></td>
 </tr>
 <tr><td>&nbsp; </TD></TR>
@@ -224,9 +244,11 @@ print <<printend
 <td><input type=text name=city size=20 value="$data->{'city'}"></td>
 <td>
 <SELECT NAME="area" SIZE="1">
-<OPTION value=L
 printend
 ;
+
+print "
+<OPTION value=L";
 if ($data->{'area'} eq 'L'){
   print " Selected";
 }
@@ -374,18 +396,54 @@ print <<printend
 <tr valign=top bgcolor=white><td  COLSPAN=5 align=right >
 printend
 ;
+if ($modify){                                                                                                                                      
+  print <<printend                                                                                                                                 
+  <tr><td><Font size=2>FLAGS</font></td></tr>                                                                                                        
+  <tr><td>Gone No Address</td>                                                                                                                       
+  <td><input type=radio name=gna value=1                                                                                                             
+printend
+;
+  if ($data->{'gonenoaddress'} eq '1'){                                                                                                            
+    print " checked";                                                                                                                              
+  }                                                                                                                                                
+  print ">Yes <input type=radio name=gna value=0";                                                                                                   
+  if ($data->{'gonenoaddress'} eq '0'){                                                                                                            
+    print " checked";                                                                                                                              
+  }                                                                                                                                                
+  print ">No</td></tr>\n";                                                                                                                         
+  print "<tr><td>Lost</td><td><input type=radio name=lost value=1";                                                                                
+  if ($data->{'lost'} eq '1'){                                                                                                                     
+    print " checked";                                                                                                                              
+  }                                                                                                                                                
+  print ">Yes<input type=radio name=lost value=0";                                                                                                 
+  if ($data->{'lost'} eq '0'){                                                                                                                     
+    print " checked";                                                                                                                              
+  }                                                                                                                                                
+  print ">No</td></tr>\n";                                                                                                                         
+  print "<tr><td>Debarred</td><td><input type=radio name=debarred value=1";                                                                        
+  if ($data->{'debarred'} eq '1'){                                                                                                                 
+    print " checked";                                                                                                                              
+  }                                                                                                                                                
+  print ">Yes<input type=radio name=debarred value=0";                                                                                             
+  if ($data->{'debarred'} eq '0'){                                                                                                                 
+    print " checked";                                                                                                                              
+  }                                                                                                                                                
+  print ">No</td></tr>\n";                                                                                                                         
+}                 
+
 if ($type ne 'modify'){
   print <<printend
-<input type=image src="/images/save-changes.gif"  WIDTH=188  HEIGHT=44  ALT="Add New Member" border=0 ></td>
+<tr><td></td><td><input type=image src="/images/save-changes.gif"  WIDTH=188  HEIGHT=44  ALT="Add New Member" border=0 ></td>
 printend
 ;
 } else {
 print <<printend
-<input type=image src="/images/save-changes.gif"  WIDTH=188  HEIGHT=44  ALT="Add New Member" border=0 ></td>
+<td><td></td><td><input type=image src="/images/save-changes.gif"  WIDTH=188  HEIGHT=44  ALT="Add New Member" border=0 ></td>
 printend
 ;
 }
 print <<printend
+</form>
 </tr>
 </TABLE>
 </table>
@@ -397,3 +455,4 @@ printend
 ;
 print endmenu('member');
 print endpage();
+}