Corrected the missing brace syntax error (Bug 162)
[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 # 2003/01/20 acli@ada.dhs.org XXX it seems to do the following:
10 # * "insert" seems to do nothing; in 1.2.2 the script just returns a blank
11 #   page (with the headers etc.) if "insert" has anything in it
12 # * $ok has the opposite meaning of what one expects; $ok == 1 means "not ok"
13 # * if ($ok == 0) considers the "ok" case; it displays a confirmation page
14 #   for the user to "click to confirm that everything is entered correctly"
15 # * The "else" case for ($ok == 0) handles the "not ok" case; $string is the
16 #   error message to display
17
18 # FIXME - What is the correct value of "flagsrequired"?
19 # FIXME - untranslatable strings here
20
21 # Copyright 2000-2002 Katipo Communications
22 #
23 # This file is part of Koha.
24 #
25 # Koha is free software; you can redistribute it and/or modify it under the
26 # terms of the GNU General Public License as published by the Free Software
27 # Foundation; either version 2 of the License, or (at your option) any later
28 # version.
29 #
30 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
31 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
32 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
33 #
34 # You should have received a copy of the GNU General Public License along with
35 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
36 # Suite 330, Boston, MA  02111-1307 USA
37
38 use strict;
39 use C4::Auth;
40 use C4::Input;
41 use C4::Charset;
42 use CGI;
43 use Date::Manip;
44 use HTML::Template;
45
46 my %env;
47 my $input = new CGI;
48 #get varibale that tells us whether to show confirmation page
49 #or insert data
50 my $insert=$input->param('insert');
51
52 #get rest of data
53 my %data;
54 my @names=$input->param;
55 foreach my $key (@names){
56   $data{$key}=$input->param($key);
57 }
58
59 my ($template, $borrowernumber, $cookie)
60     = get_template_and_user({template_name => "newmember.tmpl",
61                              query => $input,
62                              type => "intranet",
63                              authnotrequired => 0,
64                              flagsrequired => {parameters => 1},
65                          });
66
67 # Check that all compulsary fields are entered
68 # If everything is ok, set $ok = 0
69 # Otherwise set $ok = 1 and $string to the error message to display.
70
71 my $ok=0;
72 my $string = "The following compulsary fields have been left blank. "
73         . "Please push the back button and try again<p>";
74
75 if ($data{'cardnumber'} eq ''){
76     $string.=" Cardnumber<br>";
77     $ok=1;
78 } else {
79     #check cardnumber is valid
80     my $valid=checkdigit(\%env,$data{'cardnumber'});
81     if ($valid != 1){
82         $ok=1;
83         $string.=" Invalid Cardnumber<br>";
84     }
85 }
86 if ($data{'sex'} eq ''){
87     $string.=" Gender <br>";
88     $ok=1;
89 }
90 if ($data{'firstname'} eq ''){
91     $string.=" Given Names<br>";
92     $ok=1;
93 }
94 if ($data{'surname'} eq ''){
95     $string.=" Surname<br>";
96     $ok=1;
97 }
98 if ($data{'address'} eq ''){
99     $string.=" Postal Street Address<br>";
100     $ok=1;
101 }
102 if ($data{'city'} eq ''){
103     $string.=" Postal City<br>";
104     $ok=1;
105 }
106 if ($data{'contactname'} eq ''){
107     $string.=" Alternate Contact<br>";
108     $ok=1;
109 }
110
111 # Pass the ok/not ok status and the error message to the template
112 $template->param(       OK=> ($ok==0),
113                         string=> $string);
114
115 # If things are ok, display the confirmation page
116 if ($ok == 0) {
117     my $name=$data{'title'}." ";
118     if ($data{'othernames'} ne ''){
119         $name.=$data{'othernames'}." ";
120     } else {
121         $name.=$data{'firstname'}." ";
122     }
123     $name.="$data{'surname'} ( $data{'firstname'}, $data{'initials'})";
124     my $sex;
125     if ($data{'sex'} eq 'M'){
126         $sex="Male";
127     } else {
128         $sex="Female";
129     }
130     if ($data{'joining'} eq ''){
131         $data{'joining'}=ParseDate('today');
132         $data{'joining'}=&UnixDate($data{'joining'},'%Y-%m-%d');
133     }
134     if ($data{'expiry'} eq ''){
135         $data{'expiry'}=ParseDate('in 1 year');
136         $data{'expiry'}=&UnixDate($data{'expiry'},'%Y-%m-%d');
137     }
138     my $ethnic=$data{'ethnicity'}." ".$data{'ethnicnotes'};
139     my $postal=$data{'address'}."<br>".$data{'city'};
140     my $home;
141     if ($data{'streetaddress'} ne ''){
142         $home=$data{'streetaddress'}."<br>".$data{'streetcity'};
143     } else {
144         $home=$postal;
145     }
146     my @inputsloop;
147     while (my ($key, $value) = each %data) {
148         $value=~ s/\"/%22/g;
149         my %line;
150         $line{'key'}=$key;
151         $line{'value'}=$value;
152         push(@inputsloop, \%line);
153     }
154
155     $template->param(name => $name,
156                      bornum => $data{'borrowernumber'},
157                      cardnum => $data{'cardnumber'},
158                      memcat => $data{'categorycode'},
159                      area => $data{'area'},
160                      fee => $data{'fee'},
161                      joindate => $data{'joining'},
162                      expdate => $data{'expiry'},
163                      joinbranch => $data{'joinbranch'},
164                      ethnic => $ethnic,
165                      dob => $data{'dateofbirth'},
166                      sex => $sex,
167                      postal => $postal,
168                      home => $home,
169                      phone => $data{'phone'},
170                      phoneday => $data{'phoneday'},
171                      faxnumber => $data{'faxnumber'},
172                      emailaddress => $data{'emailaddress'},
173                      contactname => $data{'contactname'},
174                      altphone => $data{'altphone'},
175                      altrelationship => $data{'altrelationship'},
176                      altnotes => $data{'altnotes'},
177                      bornotes => $data{'borrowernotes'},
178                      inputsloop => \@inputsloop);
179
180 # If things are not ok, display the error message
181 } else {
182     # Nothing to do; the "OK" and "string" variables have already been set
183     ;
184 }
185
186 print $input->header(
187     -type => guesstype($template->output),
188     -cookie => $cookie
189 ), $template->output;
190
191