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 $borrowernumber=$input->param('borrowernumber');
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');
61 my $destination=$input->param('destination');
64 # if a add or modify is requested => check validity of data.
65 if ($op eq 'add' or $op eq 'modify') {
67 my @names=$input->param;
68 foreach my $key (@names){
69 $data{$key}=$input->param($key);
70 $data{$key}=~ s/\'/\\\'/g;
71 $data{$key}=~ s/\"/\\\"/g;
74 if ($data{'cardnumber'} eq ''){
75 push @errors,"ERROR_cardnumber";
78 #check cardnumber is valid
85 my $valid=checkdigit('',$data{'cardnumber'}, $nounique);
88 push @errors, "ERROR_invalid_cardnumber";
92 if ($data{'sex'} eq '' && $categorycode ne "I"){
93 push @errors, "ERROR_gender";
96 if ($data{'firstname'} eq '' && $categorycode ne "I"){
97 push @errors,"ERROR_firstname";
100 if ($data{'surname'} eq ''){
101 push @errors,"ERROR_surname";
104 if ($data{'streetaddress'} eq ''){
105 push @errors, "ERROR_address";
108 if ($data{'city'} eq ''){
109 push @errors, "ERROR_city";
112 if (C4::Context->preference("IndependantBranches")) {
113 my $userenv = C4::Context->userenv;
114 if ($userenv->{flags} != 1){
115 unless ($userenv->{branch} eq $data{'branchcode'}){
116 push @errors, "ERROR_branch";
122 foreach my $error (@errors) {
123 $template->param( $error => 1);
125 $template->param(nok => 1);
127 my $query="Select * from borrowers where borrowernumber=?";
128 my $sth=$dbh->prepare($query);
129 $sth->execute($data{'borrowernumber'});
130 if (my $data2=$sth->fetchrow_hashref){
133 $borrowernumber = &newmember(%data);
136 if($destination eq "circ"){
137 print $input->redirect("/cgi-bin/koha/circ/circulation.pl?findborrower=$data{'cardnumber'}");
139 print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$borrowernumber");
144 print $input->redirect("/cgi-bin/koha/deletemem.pl?member=$borrowernumber");
145 } else { # this else goes down the whole script
146 if ($actionType eq 'Add'){
147 $template->param( addAction => 1);
149 $template->param( addAction =>0);
151 # retrieve previous values : either in DB or in CGI, in case of errors in values
154 my @names=$input->param;
155 foreach my $key (@names){
156 $data->{$key}=$input->param($key);
159 $data=borrdata('',$borrowernumber);
161 if (C4::Context->preference("IndependantBranches")) {
162 my $userenv = C4::Context->userenv;
163 if ($userenv->{flags} != 1 && $data->{branchcode}){
164 unless ($userenv->{branch} eq $data->{'branchcode'}){
165 print $input->redirect("/cgi-bin/koha/members/members-home.pl");
169 if ($actionType eq 'Add'){
170 $template->param( updtype => 'I');
172 $template->param( updtype => 'M');
174 my $cardnumber=$data->{'cardnumber'};
175 $cardnumber=fixup_cardnumber($data->{'cardnumber'}) if $actionType eq 'Add';
176 if ($data->{'sex'} eq 'F'){
177 $template->param(female => 1);
179 my ($categories,$labels)=ethnicitycategories();
180 my $ethnicitycategoriescount=$#{$categories};
182 if ($ethnicitycategoriescount>=0) {
183 $ethcatpopup = CGI::popup_menu(-name=>'ethnicity',
185 -values=>$categories,
186 -default=>$data->{'ethnicity'},
188 $template->param(ethcatpopup => $ethcatpopup); # bad style, has to be fixed
191 ($categories,$labels)=borrowercategories();
192 my $catcodepopup = CGI::popup_menu(-name=>'categorycode',
193 -id => 'categorycode',
194 -values=>$categories,
195 -default=>$data->{'categorycode'},
198 my @relationships = ('','workplace', 'relative','friend', 'neighbour');
200 while (@relationships) {
201 my $relship = shift @relationships;
202 my %row = ('relationship' => $relship);
203 if ($data->{'altrelationship'} eq $relship) {
204 $row{'selected'}=' selected';
208 push(@relshipdata, \%row);
211 # %flags: keys=$data-keys, datas=[formname, HTML-explanation]
212 my %flags = ('gonenoaddress' => ['gna', 'Gone no address'],
213 'lost' => ['lost', 'Lost'],
214 'debarred' => ['debarred', 'Debarred']);
217 foreach (keys(%flags)) {
219 my %row = ('key' => $key,
220 'name' => $flags{$key}[0],
221 'html' => $flags{$key}[1]);
223 $row{'yes'}=' checked';
227 $row{'no'}=' checked';
229 push(@flagdata, \%row);
233 $template->param( modify => 1 );
236 #Convert dateofbirth to correct format
237 $data->{'dateofbirth'} = format_date($data->{'dateofbirth'});
242 my $branches=getbranches();
244 foreach my $branch (keys %$branches) {
245 if ((not C4::Context->preference("IndependantBranches")) || (C4::Context->userenv->{'flags'} == 1)) {
246 push @select_branch, $branch;
247 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
248 $default = $data->{'branchcode'};
250 push @select_branch, $branch if ($branch eq C4::Context->userenv->{'branch'});
251 $select_branches{$branch} = $branches->{$branch}->{'branchname'} if ($branch eq C4::Context->userenv->{'branch'});
252 $default = C4::Context->userenv->{'branch'};
256 my $CGIbranch=CGI::scrolling_list( -name => 'branchcode',
258 -values => \@select_branch,
259 -default => $data->{'branchcode'},
260 -labels => \%select_branches,
264 my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data->{'sort1'});
266 $template->param(CGIsort1 => $CGIsort1);
268 $template->param( sort1 => $data->{'sort1'});
271 my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data->{'sort2'});
273 $template->param(CGIsort2 =>$CGIsort2);
275 $template->param( sort2 => $data->{'sort2'});
278 my $CGIsort1 = buildCGIsort("Bsort1","sort1",$data->{'sort1'});
280 $template->param(CGIsort1 => $CGIsort1);
282 $template->param( sort1 => $data->{'sort1'});
285 my $CGIsort2 = buildCGIsort("Bsort2","sort2",$data->{'sort2'});
287 $template->param(CGIsort2 =>$CGIsort2);
289 $template->param( sort2 => $data->{'sort2'});
292 $template->param( actionType => $actionType,
293 destination => $destination,
294 borrowernumber => $borrowernumber,
295 address => $data->{'streetaddress'},
296 firstname => $data->{'firstname'},
297 surname => $data->{'surname'},
298 othernames => $data->{'othernames'},
299 initials => $data->{'initials'},
300 ethcatpopup => $ethcatpopup,
301 catcodepopup => $catcodepopup,
302 streetaddress => $data->{'streetaddress'},
303 physstreet => $data->{'physstreet'},
304 zipcode => $data->{'zipcode'},
305 streetcity => $data->{'streetcity'},
306 homezipcode => $data->{'homezipcode'},
307 city => $data->{'city'},
308 phone => $data->{'phone'},
309 phoneday => $data->{'phoneday'},
310 faxnumber => $data->{'faxnumber'},
311 emailaddress => $data->{'emailaddress'},
312 textmessaging => $data->{'textmessaging'},
313 contactname => $data->{'contactname'},
314 altphone => $data->{'altphone'},
315 altnotes => $data->{'altnotes'},
316 borrowernotes => $data->{'borrowernotes'},
317 flagloop => \@flagdata,
318 relshiploop => \@relshipdata,
319 "title_".$data->{'title'} => " SELECTED ",
320 joining => format_date($data->{'dateenrolled'}),
321 expiry => format_date($data->{'expiry'}),
322 cardnumber => $cardnumber,
323 dateofbirth => $data->{'dateofbirth'},
324 dateformat => display_date_format(),
326 CGIbranch => $CGIbranch);
327 $template->param(Institution => 1) if ($categorycode eq "I");
328 output_html_with_http_headers $input, $cookie, $template->output;