2 # NOTE: This file uses standard 8-space tabs
3 # DO NOT SET TAB SIZE TO 4
7 #script to set up screen for modification of borrower details
8 #written 20/12/99 by chris@katipo.co.nz
11 # Copyright 2000-2002 Katipo Communications
13 # This file is part of Koha.
15 # Koha is free software; you can redistribute it and/or modify it under the
16 # terms of the GNU General Public License as published by the Free Software
17 # Foundation; either version 2 of the License, or (at your option) any later
20 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
21 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
22 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License along with
25 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
26 # Suite 330, Boston, MA 02111-1307 USA
32 use C4::Interface::CGI::Output;
44 my $dbh = C4::Context->dbh;
46 my ($template, $loggedinuser, $cookie)
47 = get_template_and_user({template_name => "members/memberentry.tmpl",
51 flagsrequired => {borrowers => 1},
55 my $member=$input->param('bornum');
56 my $actionType=$input->param('actionType') || '';
57 my $modify=$input->param('modify');
58 my $delete=$input->param('delete');
59 my $op=$input->param('op');
60 my $categorycode=$input->param('categorycode');
63 # if a add or modify is requested => check validity of data.
64 if ($op eq 'add' or $op eq 'modify') {
66 my @names=$input->param;
67 foreach my $key (@names){
68 $data{$key}=$input->param($key);
69 $data{$key}=~ s/\'/\\\'/g;
70 $data{$key}=~ s/\"/\\\"/g;
73 if ($data{'cardnumber'} eq ''){
74 push @errors,"ERROR_cardnumber";
77 #check cardnumber is valid
79 if ( $data{'actionType'} eq "Add" ) {
84 my $valid=checkdigit('',$data{'cardnumber'}, $nounique);
87 push @errors, "ERROR_invalid_cardnumber";
90 if ($data{'sex'} eq '' && $categorycode ne "I"){
91 push @errors, "ERROR_gender";
94 if ($data{'firstname'} eq '' && $categorycode ne "I"){
95 push @errors,"ERROR_firstname";
98 if ($data{'surname'} eq ''){
99 push @errors,"ERROR_surname";
102 if ($data{'address'} eq ''){
103 push @errors, "ERROR_address";
106 if ($data{'city'} eq ''){
107 push @errors, "ERROR_city";
111 foreach my $error (@errors) {
112 $template->param( $error => 1);
114 $template->param(nok => 1);
116 my $query="Select * from borrowers where borrowernumber=?";
117 my $sth=$dbh->prepare($query);
118 $sth->execute($data{'borrowernumber'});
119 if (my $data2=$sth->fetchrow_hashref){
122 $data{borrowernumber} = &newmember(%data);
124 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$data{'borrowernumber'}");
128 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$member");
129 } else { # this else goes down the whole script
130 if ($actionType eq 'Add'){
131 $template->param( addAction => 1);
133 $template->param( addAction =>0);
135 # retrieve previous values : either in DB or in CGI, in case of errors in values
138 my @names=$input->param;
139 foreach my $key (@names){
140 $data->{$key}=$input->param($key);
143 $data=borrdata('',$member);
145 if ($actionType eq 'Add'){
146 $template->param( updtype => 'I');
148 $template->param( updtype => 'M');
150 my $cardnumber=C4::Members::fixup_cardnumber($data->{'cardnumber'});
151 if ($data->{'sex'} eq 'F'){
152 $template->param(female => 1);
154 my ($categories,$labels)=ethnicitycategories();
155 my $ethnicitycategoriescount=$#{$categories};
157 if ($ethnicitycategoriescount>=0) {
158 $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
160 -values=>$categories,
161 -default=>$data->{'ethnicity'},
163 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
166 ($categories,$labels)=borrowercategories();
167 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
168 -id => 'categorycode',
169 -values=>$categories,
170 -default=>$data->{'categorycode'},
173 my @relationships = ('workplace', 'relative','friend', 'neighbour');
175 while (@relationships) {
176 my $relship = shift @relationships;
177 my %row = ('relationship' => $relship);
178 if ($data->{'altrelationship'} eq $relship) {
179 $row{'selected'}=' selected';
183 push(@relshipdata, \%row);
186 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
187 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
188 'lost' => ['lost', 'Lost'],
189 'debarred' => ['debarred', 'Debarred']);
192 foreach (keys(%flags)) {
194 my %row = ('key' => $key,
195 'name' => $flags{$key}[0],
196 'html' => $flags{$key}[1]);
198 $row{'yes'}=' checked';
202 $row{'no'}=' checked';
204 push(@flagdata, \%row);
208 $template->param( modify => 1 );
211 #Convert dateofbirth to correct format
212 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
217 my $branches=getbranches();
218 foreach my $branch (keys %$branches) {
219 push @select_branch, $branch;
220 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
222 my $CGIbranch=CGI::scrolling_list( -name => 'branchcode',
224 -values => \@select_branch,
225 -default => $data->{'branchcode'},
226 -labels => \%select_branches,
230 $template->param( actionType => $actionType,
232 address => $data->{'streetaddress'},
233 firstname => $data->{'firstname'},
234 surname => $data->{'surname'},
235 othernames => $data->{'othernames'},
236 initials => $data->{'initials'},
237 ethcatpopup => $ethcatpopup,
238 catcodepopup => $catcodepopup,
239 streetaddress => $data->{'physstreet'},
240 zipcode => $data->{'zipcode'},
241 streetcity => $data->{'streetcity'},
242 homezipcode => $data->{'homezipcode'},
243 city => $data->{'city'},
244 phone => $data->{'phone'},
245 phoneday => $data->{'phoneday'},
246 faxnumber => $data->{'faxnumber'},
247 emailaddress => $data->{'emailaddress'},
248 textmessaging => $data->{'textmessaging'},
249 contactname => $data->{'contactname'},
250 altphone => $data->{'altphone'},
251 altnotes => $data->{'altnotes'},
252 borrowernotes => $data->{'borrowernotes'},
253 flagloop => \@flagdata,
254 relshiploop => \@relshipdata,
255 "title_".$data->{'title'} => " SELECTED ",
256 dateenrolled => $data->{'dateenrolled'},
257 expiry => $data->{'expiry'},
258 cardnumber => $cardnumber,
259 dateofbirth => $data->{'dateofbirth'},
260 sort1 => $data->{'sort1'},
261 sort2 => $data->{'sort2'},
262 dateformat => display_date_format(),
264 CGIbranch => $CGIbranch);
265 $template->param(Institution => 1) if ($categorycode eq "I");
266 output_html_with_http_headers $input, $cookie, $template->output;