|
Lines 30-40
use C4::Branch qw(GetBranchesLoop);
Link Here
|
| 30 |
my $cgi = new CGI; |
30 |
my $cgi = new CGI; |
| 31 |
my $dbh = C4::Context->dbh; |
31 |
my $dbh = C4::Context->dbh; |
| 32 |
|
32 |
|
| 33 |
unless ( C4::Context->preference('PatronSelfRegistration') ) { |
|
|
| 34 |
print $cgi->redirect("/cgi-bin/koha/opac-main.pl"); |
| 35 |
exit; |
| 36 |
} |
| 37 |
|
| 38 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
33 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
| 39 |
{ |
34 |
{ |
| 40 |
template_name => "opac-memberentry.tmpl", |
35 |
template_name => "opac-memberentry.tmpl", |
|
Lines 44-64
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
Link Here
|
| 44 |
} |
39 |
} |
| 45 |
); |
40 |
); |
| 46 |
|
41 |
|
|
|
42 |
unless ( C4::Context->preference('PatronSelfRegistration') || $borrowernumber ) |
| 43 |
{ |
| 44 |
print $cgi->redirect("/cgi-bin/koha/opac-main.pl"); |
| 45 |
exit; |
| 46 |
} |
| 47 |
|
| 48 |
my $action = $cgi->param('action') || q{}; |
| 49 |
if ( $action eq q{} ) { |
| 50 |
if ($borrowernumber) { |
| 51 |
$action = 'edit'; |
| 52 |
} |
| 53 |
else { |
| 54 |
$action = 'new'; |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 47 |
$template->param( |
58 |
$template->param( |
| 48 |
hidden => GetHiddenFields(), |
59 |
action => $action, |
| 49 |
mandatory => GetMandatoryFields(), |
60 |
hidden => GetHiddenFields(), |
| 50 |
member_titles => GetTitles(), |
61 |
mandatory => GetMandatoryFields($action), |
| 51 |
branches => GetBranchesLoop() |
62 |
member_titles => GetTitles(), |
|
|
63 |
branches => GetBranchesLoop(), |
| 64 |
OPACPatronDetails => C4::Context->preference('OPACPatronDetails'), |
| 52 |
); |
65 |
); |
| 53 |
|
66 |
|
| 54 |
my $action = $cgi->param('action') || q{}; |
|
|
| 55 |
if ( $action eq 'create' ) { |
67 |
if ( $action eq 'create' ) { |
| 56 |
|
68 |
|
| 57 |
my %borrower = ParseCgiForBorrower($cgi); |
69 |
my %borrower = ParseCgiForBorrower($cgi); |
| 58 |
|
70 |
|
| 59 |
%borrower = DelEmptyFields(%borrower); |
71 |
%borrower = DelEmptyFields(%borrower); |
| 60 |
|
72 |
|
| 61 |
my @empty_mandatory_fields = CheckMandatoryFields( \%borrower ); |
73 |
my @empty_mandatory_fields = CheckMandatoryFields( \%borrower, $action ); |
| 62 |
|
74 |
|
| 63 |
if (@empty_mandatory_fields) { |
75 |
if (@empty_mandatory_fields) { |
| 64 |
$template->param( |
76 |
$template->param( |
|
Lines 144-173
if ( $action eq 'create' ) {
Link Here
|
| 144 |
} |
156 |
} |
| 145 |
} |
157 |
} |
| 146 |
elsif ( $action eq 'update' ) { |
158 |
elsif ( $action eq 'update' ) { |
| 147 |
( $template, $borrowernumber, $cookie ) = get_template_and_user( |
|
|
| 148 |
{ |
| 149 |
template_name => "opac-memberentry-update-submitted.tmpl", |
| 150 |
type => "opac", |
| 151 |
query => $cgi, |
| 152 |
authnotrequired => 1, |
| 153 |
} |
| 154 |
); |
| 155 |
|
159 |
|
| 156 |
my %borrower = ParseCgiForBorrower($cgi); |
160 |
my %borrower = ParseCgiForBorrower($cgi); |
| 157 |
|
161 |
|
| 158 |
%borrower = DelUnchangedFields( $borrowernumber, %borrower ); |
162 |
my %borrower_changes = DelEmptyFields(%borrower); |
|
|
163 |
my @empty_mandatory_fields = |
| 164 |
CheckMandatoryFields( \%borrower_changes, $action ); |
| 159 |
|
165 |
|
| 160 |
my $m = |
166 |
if (@empty_mandatory_fields) { |
| 161 |
Koha::Borrower::Modifications->new( borrowernumber => $borrowernumber ); |
167 |
$template->param( |
|
|
168 |
empty_mandatory_fields => \@empty_mandatory_fields, |
| 169 |
borrower => \%borrower |
| 170 |
); |
| 162 |
|
171 |
|
| 163 |
$m->DelModifications; |
172 |
$template->param( action => 'edit' ); |
| 164 |
$m->AddModifications(%borrower); |
173 |
} |
| 165 |
} |
174 |
else { |
| 166 |
elsif ($borrowernumber) { #Display logged in borrower's data |
175 |
( $template, $borrowernumber, $cookie ) = get_template_and_user( |
| 167 |
$action = 'edit'; |
176 |
{ |
|
|
177 |
template_name => "opac-memberentry-update-submitted.tmpl", |
| 178 |
type => "opac", |
| 179 |
query => $cgi, |
| 180 |
authnotrequired => 1, |
| 181 |
} |
| 182 |
); |
| 168 |
|
183 |
|
|
|
184 |
my %borrower_changes = DelUnchangedFields( $borrowernumber, %borrower ); |
| 185 |
|
| 186 |
my $m = |
| 187 |
Koha::Borrower::Modifications->new( |
| 188 |
borrowernumber => $borrowernumber ); |
| 189 |
|
| 190 |
$m->DelModifications; |
| 191 |
$m->AddModifications(%borrower_changes); |
| 192 |
} |
| 193 |
} |
| 194 |
elsif ( $action eq 'edit' ) { #Display logged in borrower's data |
| 169 |
$template->param( |
195 |
$template->param( |
| 170 |
borrower => GetMember( borrowernumber => $borrowernumber ) ); |
196 |
borrower => GetMember( borrowernumber => $borrowernumber ), ); |
| 171 |
} |
197 |
} |
| 172 |
|
198 |
|
| 173 |
my $captcha = random_string("CCCCC"); |
199 |
my $captcha = random_string("CCCCC"); |
|
Lines 177-184
$template->param(
Link Here
|
| 177 |
captcha_digest => md5_base64($captcha) |
203 |
captcha_digest => md5_base64($captcha) |
| 178 |
); |
204 |
); |
| 179 |
|
205 |
|
| 180 |
$template->param( action => $action ); |
|
|
| 181 |
|
| 182 |
output_html_with_http_headers $cgi, $cookie, $template->output; |
206 |
output_html_with_http_headers $cgi, $cookie, $template->output; |
| 183 |
|
207 |
|
| 184 |
sub GetHiddenFields { |
208 |
sub GetHiddenFields { |
|
Lines 197-202
sub GetHiddenFields {
Link Here
|
| 197 |
} |
221 |
} |
| 198 |
|
222 |
|
| 199 |
sub GetMandatoryFields { |
223 |
sub GetMandatoryFields { |
|
|
224 |
my ($action) = @_; |
| 225 |
|
| 200 |
my %mandatory_fields; |
226 |
my %mandatory_fields; |
| 201 |
|
227 |
|
| 202 |
my $BorrowerMandatoryField = |
228 |
my $BorrowerMandatoryField = |
|
Lines 208-225
sub GetMandatoryFields {
Link Here
|
| 208 |
$mandatory_fields{$_} = 1; |
234 |
$mandatory_fields{$_} = 1; |
| 209 |
} |
235 |
} |
| 210 |
|
236 |
|
| 211 |
$mandatory_fields{'email'} = 1 |
237 |
if ( $action eq 'create' || $action eq 'new' ) { |
| 212 |
if C4::Context->boolean_preference('PatronSelfRegistrationVerifyByEmail'); |
238 |
$mandatory_fields{'email'} = 1 |
|
|
239 |
if C4::Context->boolean_preference( |
| 240 |
'PatronSelfRegistrationVerifyByEmail'); |
| 241 |
} |
| 213 |
|
242 |
|
| 214 |
return \%mandatory_fields; |
243 |
return \%mandatory_fields; |
| 215 |
} |
244 |
} |
| 216 |
|
245 |
|
| 217 |
sub CheckMandatoryFields { |
246 |
sub CheckMandatoryFields { |
| 218 |
my ($borrower) = @_; |
247 |
my ( $borrower, $action ) = @_; |
| 219 |
|
248 |
|
| 220 |
my @empty_mandatory_fields; |
249 |
my @empty_mandatory_fields; |
| 221 |
|
250 |
|
| 222 |
my $mandatory_fields = GetMandatoryFields(); |
251 |
my $mandatory_fields = GetMandatoryFields($action); |
| 223 |
delete $mandatory_fields->{'cardnumber'}; |
252 |
delete $mandatory_fields->{'cardnumber'}; |
| 224 |
|
253 |
|
| 225 |
foreach my $key ( keys %$mandatory_fields ) { |
254 |
foreach my $key ( keys %$mandatory_fields ) { |
|
Lines 236-244
sub ParseCgiForBorrower {
Link Here
|
| 236 |
my %borrower; |
265 |
my %borrower; |
| 237 |
|
266 |
|
| 238 |
foreach ( $cgi->param ) { |
267 |
foreach ( $cgi->param ) { |
| 239 |
my ($key) = substr( $_, 9 ); |
268 |
if ( $_ =~ '^borrower_' ) { |
| 240 |
$borrower{$key} = $cgi->param($_) |
269 |
my ($key) = substr( $_, 9 ); |
| 241 |
if ( $_ =~ '^borrower_' ); |
270 |
$borrower{$key} = $cgi->param($_); |
|
|
271 |
} |
| 242 |
} |
272 |
} |
| 243 |
|
273 |
|
| 244 |
$borrower{'dateofbirth'} = |
274 |
$borrower{'dateofbirth'} = |