|
Lines 30-37
use Koha::Clubs;
Link Here
|
| 30 |
|
30 |
|
| 31 |
my $cgi = CGI->new; |
31 |
my $cgi = CGI->new; |
| 32 |
|
32 |
|
| 33 |
my ( $auth_status ) = |
33 |
my ($auth_status) = |
| 34 |
check_cookie_auth( $cgi->cookie('CGISESSID') ); |
34 |
check_cookie_auth( $cgi->cookie('CGISESSID') ); |
| 35 |
if ( $auth_status ne "ok" ) { |
35 |
if ( $auth_status ne "ok" ) { |
| 36 |
exit 0; |
36 |
exit 0; |
| 37 |
} |
37 |
} |
|
Lines 42-72
my $id = $cgi->param('id');
Link Here
|
| 42 |
|
42 |
|
| 43 |
my $enrollment; |
43 |
my $enrollment; |
| 44 |
if ( $borrowernumber && $id ) { |
44 |
if ( $borrowernumber && $id ) { |
|
|
45 |
my $already_enrolled = Koha::Club::Enrollments->search( |
| 46 |
{ |
| 47 |
club_id => $id, |
| 48 |
borrowernumber => $borrowernumber, |
| 49 |
date_canceled => undef, |
| 50 |
} |
| 51 |
)->count(); |
| 52 |
|
| 45 |
my $club = Koha::Clubs->find($id); |
53 |
my $club = Koha::Clubs->find($id); |
| 46 |
|
54 |
|
| 47 |
if ( $club->club_template()->is_enrollable_from_opac() ) { |
55 |
my $wrong_branch = $club->branchcode && C4::Context->userenv && C4::Context->userenv->{branch} ne $club->branchcode; |
| 48 |
$enrollment = Koha::Club::Enrollment->new()->set( |
|
|
| 49 |
{ |
| 50 |
club_id => $club->id(), |
| 51 |
borrowernumber => $borrowernumber, |
| 52 |
date_enrolled => \'NOW()', |
| 53 |
date_created => \'NOW()', |
| 54 |
branchcode => C4::Context->userenv |
| 55 |
? C4::Context->userenv->{'branch'} |
| 56 |
: undef, |
| 57 |
} |
| 58 |
)->store(); |
| 59 |
|
56 |
|
| 60 |
my @enrollment_fields = $club->club_template()->club_template_enrollment_fields->as_list; |
57 |
unless ( $already_enrolled || $wrong_branch ) { |
| 61 |
|
58 |
|
| 62 |
foreach my $e (@enrollment_fields) { |
59 |
if ( $club->club_template()->is_enrollable_from_opac() ) { |
| 63 |
Koha::Club::Enrollment::Field->new()->set( |
60 |
$enrollment = Koha::Club::Enrollment->new( |
| 64 |
{ |
61 |
{ |
| 65 |
club_enrollment_id => $enrollment->id(), |
62 |
club_id => $club->id(), |
| 66 |
club_template_enrollment_field_id => $e->id(), |
63 |
borrowernumber => $borrowernumber, |
| 67 |
value => $cgi->param( $e->id() ), |
64 |
date_enrolled => \'NOW()', |
|
|
65 |
date_created => \'NOW()', |
| 66 |
branchcode => C4::Context->userenv ? C4::Context->userenv->{branch} : undef, |
| 68 |
} |
67 |
} |
| 69 |
)->store(); |
68 |
)->store(); |
|
|
69 |
|
| 70 |
my @enrollment_fields = $club->club_template()->club_template_enrollment_fields->as_list; |
| 71 |
|
| 72 |
foreach my $e (@enrollment_fields) { |
| 73 |
Koha::Club::Enrollment::Field->new()->set( |
| 74 |
{ |
| 75 |
club_enrollment_id => $enrollment->id(), |
| 76 |
club_template_enrollment_field_id => $e->id(), |
| 77 |
value => scalar $cgi->param( $e->id() ), |
| 78 |
} |
| 79 |
)->store(); |
| 80 |
} |
| 70 |
} |
81 |
} |
| 71 |
} |
82 |
} |
| 72 |
} |
83 |
} |