fixme corrected, re-indent and adding the marc_breeding table (see commit of marcimpo...
[koha.git] / newmember.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 #script to print confirmation screen, then if accepted calls itself to insert data
6 # FIXME - Yes, but what does it _do_?
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 #
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA  02111-1307 USA
24
25 use strict;
26 use C4::Output;
27 use C4::Input;
28 use CGI;
29 use Date::Manip;
30
31 my %env;
32 my $input = new CGI;
33 #get varibale that tells us whether to show confirmation page
34 #or insert data
35 my $insert=$input->param('insert');
36
37 #get rest of data
38 my %data;
39 my @names=$input->param;
40 foreach my $key (@names){
41   $data{$key}=$input->param($key);
42 }
43 print $input->header;
44 print startpage();
45 print startmenu('member');
46 my $main="#99cc33";
47 my $image="/images/background-mem.gif";
48 if ($insert eq ''){
49   my $ok=0;
50   #check that all compulsary fields are entered
51   my $string="The following compulsary fields have been left blank. Please push the back button
52   and try again<p>";
53   if ($data{'cardnumber'} eq ''){
54
55      $string.=" Cardnumber<br>";
56     $ok=1;
57   } else {
58      #check cardnumber is valid
59      my $valid=checkdigit(\%env,$data{'cardnumber'});
60      if ($valid != 1){
61        $ok=1;
62        $string.=" Invalid Cardnumber<br>";
63      }
64   }
65   if ($data{'sex'} eq ''){
66     $string.=" Gender <br>";
67     $ok=1;
68   }
69   if ($data{'firstname'} eq ''){
70     $string.=" Given Names<br>";
71     $ok=1;
72   }
73   if ($data{'surname'} eq ''){
74     $string.=" Surname<br>";
75     $ok=1;
76   }
77   if ($data{'address'} eq ''){
78     $string.=" Postal Street Address<br>";
79     $ok=1;
80   }
81   if ($data{'city'} eq ''){
82     $string.=" Postal City<br>";
83     $ok=1;
84   }
85   if ($data{'contactname'} eq ''){
86     $string.=" Alternate Contact<br>";
87     $ok=1;
88   }
89   #we are printing confirmation page
90   print mkheadr(1,'Confirm Record');
91   if ($ok ==0){
92    print mktablehdr;
93    print mktablerow(2,$main,bold('NEW MEMBER'),"",$image);
94    my $name=$data{'title'}." ";
95    if ($data{'othernames'} ne ''){
96      $name.=$data{'othernames'}." ";
97    } else {
98      $name.=$data{'firstname'}." ";
99    }
100    $name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})";
101    print mktablerow(2,'white',bold('Name'),$name);
102    print mktablerow(2,$main,bold('MEMBERSHIP DETAILS'),"",$image);
103    print mktablerow(2,'white',bold('Membership Number'),$data{'borrowernumber'});
104    print mktablerow(2,'white',bold('Cardnumber'),$data{'cardnumber'});
105    print mktablerow(2,'white',bold('Membership Category'),$data{'categorycode'});
106    print mktablerow(2,'white',bold('Area'),$data{'area'});
107    print mktablerow(2,'white',bold('Fee'),$data{'fee'});
108    if ($data{'joining'} eq ''){
109      $data{'joining'}=ParseDate('today');
110      $data{'joining'}=&UnixDate($data{'joining'},'%Y-%m-%d');
111    }
112    print mktablerow(2,'white',bold('Joining Date'),$data{'joining'});
113    if ($data{'expiry'} eq ''){
114      $data{'expiry'}=ParseDate('in 1 year');
115      $data{'expiry'}=&UnixDate($data{'expiry'},'%Y-%m-%d');
116    }
117    print mktablerow(2,'white',bold('Expiry Date'),$data{'expiry'});
118    print mktablerow(2,'white',bold('Joining Branch'),$data{'joinbranch'});
119    print mktablerow(2,$main,bold('PERSONAL DETAILS'),"",$image);
120    my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'};
121    print mktablerow(2,'white',bold('Ethnicity'),$ethnic);
122    $data{'dateofbirth'}=ParseDate($data{'dateofbirth'});
123    $data{'dateofbirth'}=UnixDate($data{'dateofbirth'},'%Y-%m-%d');
124    print mktablerow(2,'white',bold('Date of Birth'),$data{'dateofbirth'});
125    my $sex;
126    if ($data{'sex'} eq 'M'){
127      $sex="Male";
128    } else {
129      $sex="Female";
130    }
131    print mktablerow(2,'white',bold('Sex'),$sex);
132    print mktablerow(2,$main,bold('MEMBER ADDRESS'),"",$image);
133    my $postal=$data{'address'}."<br>".$data{'city'};
134    my $home;
135    if ($data{'streetaddress'} ne ''){
136      $home=$data{'streetaddress'}."<br>".$data{'streetcity'};
137    } else {
138      $home=$postal;
139    }
140    print mktablerow(2,'white',bold('Postal Address'),$postal);
141    print mktablerow(2,'white',bold('Home Address'),$home);
142    print mktablerow(2,$main,bold('MEMBER CONTACT DETAILS'),"",$image);
143    print mktablerow(2,'white',bold('Phone (Home)'),$data{'phone'});
144    print mktablerow(2,'white',bold('Phone (Daytime)'),$data{'phoneday'});
145    print mktablerow(2,'white',bold('Fax'),$data{'faxnumber'});
146    print mktablerow(2,'white',bold('Email'),$data{'emailaddress'});
147    print mktablerow(2,$main,bold('ALTERNATIVE CONTACT DETAILS'),"",$image);
148    print mktablerow(2,'white',bold('Name'),$data{'contactname'});
149    print mktablerow(2,'white',bold('Phone'),$data{'altphone'});
150    print mktablerow(2,'white',bold('Relationship'),$data{'altrelationship'});
151    print mktablerow(2,'white',bold('Notes'),$data{'altnotes'});
152    print mktablerow(2,$main,bold('Notes'),"",$image);
153    print mktablerow(2,'white',bold('General Notes'),$data{'borrowernotes'});
154
155    print mktableft;
156    #set up form to post data thru for modification or insertion
157    my $i=0;
158    my @inputs;
159    while (my ($key, $value) = each %data) {
160      $value=~ s/\"/%22/g;
161      $inputs[$i]=["hidden","$key","$value"];
162      $i++;
163    }
164    $inputs[$i]=["submit","submit","submit"];
165    print mkformnotable("/cgi-bin/koha/insertdata.pl",@inputs);
166   } else {
167     print $string;
168   }
169 }
170 #print $input->dump;
171
172 print mktablehdr;
173
174 print mktableft;
175 print endmenu('member');
176 print endpage();