bugfixes + language selection during install
[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 # 2002/12/18 hdl@ifrance.com templating
8
9 # Copyright 2000-2002 Katipo Communications
10 #
11 # This file is part of Koha.
12 #
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
16 # version.
17 #
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License along with
23 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
24 # Suite 330, Boston, MA  02111-1307 USA
25
26 use strict;
27 use C4::Output;
28 use C4::Input;
29 use CGI;
30 use Date::Manip;
31 use HTML::Template;
32
33 my %env;
34 my $input = new CGI;
35 #get varibale that tells us whether to show confirmation page
36 #or insert data
37 my $insert=$input->param('insert');
38
39 #get rest of data
40 my %data;
41 my @names=$input->param;
42 foreach my $key (@names){
43   $data{$key}=$input->param($key);
44 }
45
46 my $template = gettemplate("newmember.tmpl");
47 #print $input->header;
48 #print startpage();
49 #print startmenu('member');
50 my $main="#99cc33";
51 my $image="/images/background-mem.gif";
52 if ($insert eq ''){
53   my $ok=0;
54   #check that all compulsary fields are entered
55   my $string="The following compulsary fields have been left blank. Please push the back button
56   and try again<p>";
57   if ($data{'cardnumber'} eq ''){
58
59      $string.=" Cardnumber<br>";
60     $ok=1;
61   } else {
62      #check cardnumber is valid
63      my $valid=checkdigit(\%env,$data{'cardnumber'});
64      if ($valid != 1){
65        $ok=1;
66        $string.=" Invalid Cardnumber<br>";
67      }
68   }
69   if ($data{'sex'} eq ''){
70     $string.=" Gender <br>";
71     $ok=1;
72   }
73   if ($data{'firstname'} eq ''){
74     $string.=" Given Names<br>";
75     $ok=1;
76   }
77   if ($data{'surname'} eq ''){
78     $string.=" Surname<br>";
79     $ok=1;
80   }
81   if ($data{'address'} eq ''){
82     $string.=" Postal Street Address<br>";
83     $ok=1;
84   }
85   if ($data{'city'} eq ''){
86     $string.=" Postal City<br>";
87     $ok=1;
88   }
89   if ($data{'contactname'} eq ''){
90     $string.=" Alternate Contact<br>";
91     $ok=1;
92   }
93   #we are printing confirmation page
94 $template->param(       OK=> ($ok==0),
95                                                                 string=> $string);
96   if ($ok ==0){
97    my $name=$data{'title'}." ";
98    if ($data{'othernames'} ne ''){
99      $name.=$data{'othernames'}." ";
100    } else {
101      $name.=$data{'firstname'}." ";
102    }
103    $name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})";
104    my $sex;
105    if ($data{'sex'} eq 'M'){
106      $sex="Male";
107    } else {
108      $sex="Female";
109    }
110    if ($data{'joining'} eq ''){
111      $data{'joining'}=ParseDate('today');
112      $data{'joining'}=&UnixDate($data{'joining'},'%Y-%m-%d');
113    }
114    if ($data{'expiry'} eq ''){
115      $data{'expiry'}=ParseDate('in 1 year');
116      $data{'expiry'}=&UnixDate($data{'expiry'},'%Y-%m-%d');
117    }
118    my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'};
119    my $postal=$data{'address'}."<br>".$data{'city'};
120    my $home;
121    if ($data{'streetaddress'} ne ''){
122      $home=$data{'streetaddress'}."<br>".$data{'streetcity'};
123    } else {
124      $home=$postal;
125    }
126    my @inputsloop;
127    while (my ($key, $value) = each %data) {
128      $value=~ s/\"/%22/g;
129                         my %line;
130                         $line{'key'}=$key;
131                         $line{'value'}=$value;
132                         push(@inputsloop, \%line);
133   }
134
135    $template->param(name => $name,
136                                                                         bornum => $data{'borrowernumber'},
137                                                                         cardnum => $data{'cardnumber'},
138                                                                         memcat => $data{'categorycode'},
139                                                                         area => $data{'area'},
140                                                                         fee => $data{'fee'},
141                                                                         joindate => $data{'joining'},
142                                                                         expdate => $data{'expiry'},
143                                                                         joinbranch => $data{'joinbranch'},
144                                                                         ethnic => $ethnic,
145                                                                         dob => $data{'dateofbirth'},
146                                                                         sex => $sex,
147                                                                         postal => $postal,
148                                                                         home => $home,
149                                                                         phone => $data{'phone'},
150                                                                         phoneday => $data{'phoneday'},
151                                                                         faxnumber => $data{'faxnumber'},
152                                                                         emailaddress => $data{'emailaddress'},
153                                                                         contactname => $data{'contactname'},
154                                                                         altphone => $data{'altphone'},
155                                                                         altrelationship => $data{'altrelationship'},
156                                                                         altnotes => $data{'altnotes'},
157                                                                         bornotes => $data{'borrowernotes'},
158                                                                         inputsloop => \@inputsloop);
159   }
160 print "Content-Type: text/html\n\n", $template->output;
161
162