Added copyright statement to all .pl and .pm files
[koha.git] / memberentry.pl
1 #!/usr/bin/perl
2
3 #script to set up screen for modification of borrower details
4 #written 20/12/99 by chris@katipo.co.nz
5
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 use strict;
25 use C4::Output;
26 use CGI;
27 use C4::Search;
28 use C4::Database;
29 use C4::Koha;
30
31 my $input = new CGI;
32 my $member=$input->param('bornum');
33 if ($member eq ''){
34   $member=NewBorrowerNumber();
35 }
36 my $type=$input->param('type');
37 my $modify=$input->param('modify.x'); 
38 my $delete=$input->param('delete.x');
39 if ($delete){
40   print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
41 } else {
42 print $input->header;
43 print startpage();
44 print startmenu('member');
45
46 if ($type ne 'Add'){
47   print mkheadr(1,'Update Member Details');
48 } else {
49   print mkheadr(1,'Add New Member');
50 }
51 my $data=borrdata('',$member);
52 print <<printend
53 <form action=/cgi-bin/koha/newmember.pl method=post>
54 <input type=hidden name=joining value="$data->{'dateenrolled'}">
55 <input type=hidden name=expiry value="$data->{'expiry'}">
56 <input type=hidden name=type value="borrowers">
57 <input type=hidden name=borrowernumber value="$member">
58 printend
59 ;
60 if ($type eq 'Add'){
61   print "<input type=hidden name=updtype value=I>";
62 } else {
63   print "<input type=hidden name=updtype value=M>";
64 }
65
66 my $cardnumber=$data->{'cardnumber'};
67 my %systemprefs=systemprefs();
68 # FIXME
69 # This logic should probably be moved out of the presentation code.
70 # Not tonight though.
71 #
72 if ($cardnumber eq '' && $systemprefs{'autoMemberNum'} eq '1') {
73   my $dbh=C4Connect;
74   my $query="select max(substring(borrowers.cardnumber,2,7)) from borrowers";
75   my $sth=$dbh->prepare($query);
76   $sth->execute;
77   my $data=$sth->fetchrow_hashref;
78   $cardnumber=$data->{'max(substring(borrowers.cardnumber,2,7))'};
79   $sth->finish;
80   $dbh->disconnect;
81   # purpose: generate checksum'd member numbers.
82   # We'll assume we just got the max value of digits 2-8 of member #'s from the database and our job is to
83   # increment that by one, determine the 1st and 9th digits and return the full string.
84   my @weightings = (8,4,6,3,5,2,1);
85   my $sum;
86   my $i = 0;
87   if (! $cardnumber) {                  # If DB has no values, start at 1000000
88     $cardnumber = 1000000;
89   } else {
90     $cardnumber = $cardnumber + 1;
91   }
92
93   while ($i <8) {                       # step from char 1 to 7.
94     my $temp1 = $weightings[$i];        # read weightings, left to right, 1 char at a time
95     my $temp2 = substr($cardnumber,$i,1);       # sequence left to right, 1 char at a time
96 #print "$temp2<br>";
97     $sum = $sum + ($temp1*$temp2);      # mult each char 1-7 by its corresponding weighting
98     $i++;                               # increment counter
99   }
100   my $rem = ($sum%11);                  # remainder of sum/11 (eg. 9999999/11, remainder=2)
101   if ($rem == 10) {                     # if remainder is 10, use X instead
102     $rem = "X";
103   }  
104   $cardnumber="V$cardnumber$rem";
105 } else {
106   $cardnumber=$data->{'cardnumber'};
107 }
108
109 print <<printend
110
111 <table border=0 cellspacing=0 cellpadding=5 >
112
113
114 <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'>
115 Member# $member,   Card Number* <input type=text name=cardnumber size=10 value="$cardnumber"><br>
116 </td></tr>
117
118
119 <tr valign=top  ><td  COLSPAN=3 background="/images/background-mem.gif">
120 <B>MEMBER PERSONAL DETAILS</b></td> <td  COLSPAN=2  ALIGN=RIGHT background="/images/background-mem.gif">
121 * <input type="radio" name="sex" value="F"
122 printend
123 ;
124 if ($data->{'sex'} eq 'F'){
125   print " checked";
126 }
127 print <<printend
128 >F  
129 <input type="radio" name="sex" value="M"
130 printend
131 ;
132 if ($data->{'sex'} eq 'M'){
133   print " checked";
134 }
135 print <<printend
136 >M
137 &nbsp; &nbsp;  <B>Date of Birth</B> (dd/mm/yy)
138 <input type=text name=dateofbirth size=10 value="$data->{'dateofbirth'}">
139 </td></tr>
140 <tr valign=top bgcolor=white>
141 <td><SELECT NAME="title" SIZE="1">
142 <OPTION value=" ">No Title
143 <OPTION value=Miss
144 printend
145 ;
146 if ($data->{'title'} eq 'Miss'){
147   print " Selected";
148 }
149 print ">Miss
150 <OPTION value=Mrs";
151 if ($data->{'title'} eq 'Mrs'){
152   print " Selected";
153 }
154 print ">Mrs
155 <OPTION value=Ms";
156 if ($data->{'title'} eq 'Ms'){
157   print " Selected";
158 }
159 print ">Ms
160 <OPTION value=Mr";
161 if ($data->{'title'} eq 'Mr'){
162   print " Selected";
163 }
164 print ">Mr
165 <OPTION value=Dr";
166 if ($data->{'title'} eq 'Dr'){
167   print " Selected";
168 }
169 print ">Dr
170 <OPTION value=Sir";
171 if ($data->{'title'} eq 'Sir'){
172   print " Selected";
173 }
174 print <<printend
175 >Sir
176 </SELECT>
177 </td>
178
179 <td><input type=text name=initials size=5 value="$data->{'initials'}"></td>
180 <td><input type=text name=firstname size=20 value="$data->{'firstname'}"></td>
181 <td><input type=text name=surname size=20 value="$data->{'surname'}"></td>
182 <td><input type=text name=othernames size=20 value="$data->{'othernames'}"></td></tr>
183 <tr valign=top bgcolor=white>
184 <td><FONT SIZE=2>Title</FONT></td>
185 <td><FONT SIZE=2>Initials</FONT></td>
186 <td><FONT SIZE=2>Given Names*</FONT></td>
187 <td><FONT SIZE=2>Surname*</FONT></td>
188 <td><FONT SIZE=2>Prefered Name</FONT></td>
189 </tr>
190
191 <tr><td>&nbsp; </TD></TR>
192 <tr valign=top bgcolor=white>
193 <td colspan=2>
194 printend
195 ;
196
197 my ($categories,$labels)=ethnicitycategories();
198 my $ethnicitycategoriescount=$#{$categories};
199 if ($ethnicitycategoriescount>=0) {
200         print $input->popup_menu(-name=>'ethnicity',
201                                 -values=>$categories,
202                                 -default=>$data->{'ethnicity'},
203                                 -labels=>$labels);
204 print <<printend
205 </td>
206 <td colspan=2><input type=text name=ethnicnotes size=40 ></td>
207 <td> 
208 printend
209 ;
210 } else {
211         print "</td><td colspan=2>&nbsp;</td><td>\n";
212 }
213 ($categories,$labels)=borrowercategories();
214 print $input->popup_menu(-name=>'categorycode',
215                                 -values=>$categories,
216                                 -default=>$data->{'categorycode'},
217                                 -labels=>$labels);
218
219
220
221 my $ethnicitylabels='';
222 if ($ethnicitycategoriescount>=0) {
223         $ethnicitylabels=qq|
224 <td colspan=2><FONT SIZE=2>Ethnicity</FONT></td>
225 <td colspan=2><FONT SIZE=2>Ethnicity Notes</FONT></td>
226 |;
227 } else {
228         $ethnicitylabels="<td colspan=2>&nbsp;</td><td colspan=2>&nbsp;</td>";
229 }
230 print <<printend
231
232 </td>
233 </tr>                                                                                                                                                                                                                                                                                                                                                                   
234 <tr valign=top bgcolor=white>
235 $ethnicitylabels
236 <td><FONT SIZE=2>Membership Category*</FONT></td>
237 </tr>
238 <tr><td>&nbsp; </TD></TR>
239
240 <tr valign=top bgcolor="99cc33" ><td  COLSPAN=5 background="/images/background-mem.gif">
241 <B>MEMBER ADDRESS</b></td></tr>
242 <tr valign=top bgcolor=white>
243 <td  COLSPAN=3><input type=text name=address size=40 value="$data->{'streetaddress'}">
244 <td><input type=text name=city size=20 value="$data->{'city'}"></td>
245 <td>
246 <SELECT NAME="area" SIZE="1">
247 printend
248 ;
249
250 print "
251 <OPTION value=L";
252 if ($data->{'area'} eq 'L'){
253   print " Selected";
254 }
255 print ">L - Levin
256 <OPTION value=F";
257 if ($data->{'area'} eq 'F'){
258   print " Selected";
259 }
260 print ">F - Foxton
261 <OPTION value=S";
262 if ($data->{'area'} eq 'S'){
263   print " Selected";
264 }
265 print ">S - Shannon
266 <OPTION value=H";
267 if ($data->{'area'} eq 'H'){
268   print " Selected";
269 }
270 print ">H - Horowhenua
271 <OPTION value=K";
272 if ($data->{'area'} eq 'K'){
273   print " Selected";
274 }
275 print ">K - Kapiti
276 <OPTION value=O";
277 if ($data->{'area'} eq 'O'){
278   print " Selected";
279 }
280 print ">O - Out of District
281 <OPTION value=X";
282 if ($data->{'area'} eq 'X'){
283   print " Selected";
284 }
285 print ">X - Temporary Visitor
286 <OPTION value=Z";
287 if ($data->{'area'} eq 'Z'){
288   print " Selected";
289 }
290 print ">Z - Interloan Libraries
291 <OPTION value=V";
292 if ($data->{'area'} eq 'V'){
293   print " Selected";
294 }
295 print ">V - Villlage";
296 print <<printend
297 </SELECT></td></tr>
298 <tr valign=top bgcolor=white>
299 <td  COLSPAN=3><FONT SIZE=2>Postal Address*</FONT></td>
300 <td><FONT SIZE=2>Town*</FONT></td>
301 <td><FONT SIZE=2>Area</FONT></td>
302 </tr>
303 <tr><td>&nbsp; </TD></TR>
304 <tr valign=top bgcolor=white>
305
306 <td  COLSPAN=3><input type=text name=streetaddress size=40 value="$data->{'physstreet'}"></td>
307 <td><input type=text name=streetcity size=20 value="$data->{'streetcity'}"></td>
308 </tr>
309 </tr>
310 <tr valign=top bgcolor=white>
311
312 <td  COLSPAN=3><FONT SIZE=2>Street Address if different</FONT></td>
313 <td><FONT SIZE=2>Town</FONT></td>
314 </tr>
315 <tr><td>&nbsp; </TD></TR>
316 <tr valign=top bgcolor="99cc33"  ><td  COLSPAN=5  background="/images/background-mem.gif">
317 <B>MEMBER CONTACT DETAILS</b></td></tr>
318
319
320 <tr valign=top bgcolor=white>
321 <td   COLSPAN=2 ><input type=text name=phone size=20 value="$data->{'phone'}"></td>
322 <td><input type=text name=phoneday size=20 value="$data->{'phoneday'}"></td>
323 <td><input type=text name=faxnumber size=20 value="$data->{'faxnumber'}"></td>
324 <td><input type=text name=emailaddress size=20 value="$data->{'emailaddress'}"></td></tr>
325
326 <tr valign=top bgcolor=white>
327 <td   COLSPAN=2 ><FONT SIZE=2>Phone (Home)</td>
328 <td><FONT SIZE=2>Phone (day)</td>
329 <td><FONT SIZE=2>Fax</td>
330 <td><FONT SIZE=2>Email</td></tr>
331 <tr><td>&nbsp; </TD></TR>
332 <tr valign=top bgcolor="99cc33"  ><td  COLSPAN=5  background="/images/background-mem.gif">
333 <B>ALTERNATE CONTACT DETAILS</b> </td></tr>
334
335 <tr valign=top bgcolor=white>
336 <td   COLSPAN=3 ><input type=text name=contactname size=40 value="$data->{'contactname'}"></td>
337 <td><input type=text name=altphone size=20 value="$data->{'altphone'}"></td>
338 <td><select name=altrelationship size=1>
339 <option value="workplace"
340 printend
341 ;
342 if ($data->{'altrelationship'} eq 'workplace'){
343   print " selected ";
344 }
345
346 print ">Workplace
347 <option value=\"relative\"";
348 if ($data->{'altrelationship'} eq 'relative'){
349   print " selected ";
350 }
351 print ">Relative
352 <option value=\"friend\"";
353 if ($data->{'altrelationship'} eq 'workplace'){
354   print " selected ";
355 }
356 print ">Friend
357 <option value=\"neighbour\"";
358 if ($data->{'altrelationship'} eq 'workplace'){
359   print " selected ";
360 }
361 print <<printend
362 >Neighbour
363 </select></td></tr>
364
365 <tr valign=top bgcolor=white>
366 <td   COLSPAN=3 ><FONT SIZE=2>Name*</td>
367 <td><FONT SIZE=2>Phone</td>
368 <td><FONT SIZE=2>Relationship*</td></tr>
369
370
371
372 <tr><td>&nbsp; </TD></TR>
373
374
375 <tr valign=top bgcolor=white>
376
377 <td><FONT SIZE=2>Notes</font></td>
378 <td  COLSPAN=4><textarea name=altnotes wrap=physical cols=70 rows=3>$data->{'altnotes'}</textarea></td></tr>
379 </tr>
380
381
382 <tr><td>&nbsp; </TD></TR>
383
384
385 <tr valign=top bgcolor="99cc33"  >
386
387 <td  COLSPAN=5  background="/images/background-mem.gif"><B>LIBRARY USE</B></td>
388 </tr>
389
390
391 <tr valign=top >
392
393 <td><FONT SIZE=2>Notes</font></td>
394 <td  COLSPAN=4><textarea name=borrowernotes wrap=physical cols=70 rows=3>$data->{'borrowernotes'}</textarea></td></tr>
395 <tr><td>&nbsp; </TD></TR>
396 <tr valign=top bgcolor=white><td  COLSPAN=5 align=right >
397 printend
398 ;
399 if ($modify){                                                                                                                                      
400   print <<printend                                                                                                                                 
401   <tr><td><Font size=2>FLAGS</font></td></tr>                                                                                                        
402   <tr><td>Gone No Address</td>                                                                                                                       
403   <td><input type=radio name=gna value=1                                                                                                             
404 printend
405 ;
406   if ($data->{'gonenoaddress'} eq '1'){                                                                                                            
407     print " checked";                                                                                                                              
408   }                                                                                                                                                
409   print ">Yes <input type=radio name=gna value=0";                                                                                                   
410   if ($data->{'gonenoaddress'} eq '0'){                                                                                                            
411     print " checked";                                                                                                                              
412   }                                                                                                                                                
413   print ">No</td></tr>\n";                                                                                                                         
414   print "<tr><td>Lost</td><td><input type=radio name=lost value=1";                                                                                
415   if ($data->{'lost'} eq '1'){                                                                                                                     
416     print " checked";                                                                                                                              
417   }                                                                                                                                                
418   print ">Yes<input type=radio name=lost value=0";                                                                                                 
419   if ($data->{'lost'} eq '0'){                                                                                                                     
420     print " checked";                                                                                                                              
421   }                                                                                                                                                
422   print ">No</td></tr>\n";                                                                                                                         
423   print "<tr><td>Debarred</td><td><input type=radio name=debarred value=1";                                                                        
424   if ($data->{'debarred'} eq '1'){                                                                                                                 
425     print " checked";                                                                                                                              
426   }                                                                                                                                                
427   print ">Yes<input type=radio name=debarred value=0";                                                                                             
428   if ($data->{'debarred'} eq '0'){                                                                                                                 
429     print " checked";                                                                                                                              
430   }                                                                                                                                                
431   print ">No</td></tr>\n";                                                                                                                         
432 }                 
433
434 if ($type ne 'modify'){
435   print <<printend
436 <tr><td></td><td><input type=image src="/images/save-changes.gif"  WIDTH=188  HEIGHT=44  ALT="Add New Member" border=0 ></td>
437 printend
438 ;
439 } else {
440 print <<printend
441 <td><td></td><td><input type=image src="/images/save-changes.gif"  WIDTH=188  HEIGHT=44  ALT="Add New Member" border=0 ></td>
442 printend
443 ;
444 }
445 print <<printend
446 </form>
447 </tr>
448 </TABLE>
449 </table>
450                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         </form>
451                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
452                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
453
454 printend
455 ;
456 print endmenu('member');
457 print endpage();
458 }