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'), { clubs => 'enroll' } ); |
34 |
check_cookie_auth( $cgi->cookie('CGISESSID'), { clubs => 'enroll' } ); |
35 |
if ( $auth_status ne "ok" ) { |
35 |
if ( $auth_status ne "ok" ) { |
36 |
exit 0; |
36 |
exit 0; |
37 |
} |
37 |
} |
Lines 46-87
my $enrollment;
Link Here
|
46 |
|
46 |
|
47 |
my @club_enrollment_fields; |
47 |
my @club_enrollment_fields; |
48 |
|
48 |
|
49 |
if($enrollent_id){ |
49 |
if ($enrollent_id) { |
50 |
my @enrollment_fields = $club->club_template()->club_template_enrollment_fields()->as_list; |
50 |
my @enrollment_fields = $club->club_template()->club_template_enrollment_fields()->as_list; |
51 |
@club_enrollment_fields = Koha::Club::Enrollment::Fields->search({'club_enrollment_id'=> $enrollent_id})->as_list; |
51 |
@club_enrollment_fields = |
|
|
52 |
Koha::Club::Enrollment::Fields->search( { 'club_enrollment_id' => $enrollent_id } )->as_list; |
52 |
|
53 |
|
53 |
foreach my $club_enrollment_field (@club_enrollment_fields){ |
54 |
foreach my $club_enrollment_field (@club_enrollment_fields) { |
54 |
foreach my $e (@enrollment_fields){ |
55 |
foreach my $e (@enrollment_fields) { |
55 |
if($e->id()==$club_enrollment_field->club_template_enrollment_field_id){ |
56 |
if ( $e->id() == $club_enrollment_field->club_template_enrollment_field_id ) { |
56 |
my $value = $cgi->param( $e->id() ); |
57 |
my $value = $cgi->param( $e->id() ); |
57 |
$club_enrollment_field->value($value); |
58 |
$club_enrollment_field->value($value); |
58 |
$club_enrollment_field->update(); |
59 |
$club_enrollment_field->update(); |
59 |
} |
60 |
} |
60 |
} |
61 |
} |
61 |
} |
62 |
} |
62 |
} |
63 |
} elsif ($club) { |
63 |
elsif ($club) { |
64 |
my $already_enrolled = Koha::Club::Entrollments->search( |
64 |
$enrollment = Koha::Club::Enrollment->new( |
|
|
65 |
{ |
65 |
{ |
66 |
club_id => $club->id(), |
66 |
club_id => $club->id(), |
67 |
borrowernumber => $borrowernumber, |
67 |
borrowernumber => $borrowernumber, |
68 |
date_enrolled => \'NOW()', |
|
|
69 |
date_created => \'NOW()', |
70 |
branchcode => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, |
71 |
} |
68 |
} |
72 |
)->store(); |
69 |
)->count(); |
73 |
|
70 |
|
74 |
if ($enrollment) { |
71 |
my $wrong_branch = $club->branchcode && C4::Context->userenv && C4::Context->userenv->{branch} ne $club->branchcode; |
75 |
my @enrollment_fields = $club->club_template()->club_template_enrollment_fields->as_list; |
72 |
|
76 |
|
73 |
unless ( $already_enrolled || $wrong_branch ) { |
77 |
foreach my $e (@enrollment_fields) { |
74 |
$enrollment = Koha::Club::Enrollment->new( |
78 |
my $club_enrollment_field = Koha::Club::Enrollment::Field->new( |
75 |
{ |
79 |
{ |
76 |
club_id => $club->id(), |
80 |
club_enrollment_id => $enrollment->id(), |
77 |
borrowernumber => $borrowernumber, |
81 |
club_template_enrollment_field_id => $e->id(), |
78 |
date_enrolled => \'NOW()', |
82 |
value => scalar $cgi->param( $e->id() ), |
79 |
date_created => \'NOW()', |
83 |
} |
80 |
branchcode => C4::Context->userenv ? C4::Context->userenv->{branch} : undef, |
84 |
)->store(); |
81 |
} |
|
|
82 |
)->store(); |
83 |
|
84 |
if ($enrollment) { |
85 |
my @enrollment_fields = $club->club_template()->club_template_enrollment_fields->as_list; |
86 |
|
87 |
foreach my $e (@enrollment_fields) { |
88 |
my $club_enrollment_field = Koha::Club::Enrollment::Field->new( |
89 |
{ |
90 |
club_enrollment_id => $enrollment->id(), |
91 |
club_template_enrollment_field_id => $e->id(), |
92 |
value => scalar $cgi->param( $e->id() ), |
93 |
} |
94 |
)->store(); |
95 |
} |
85 |
} |
96 |
} |
86 |
} |
97 |
} |
87 |
} |
98 |
} |
Lines 89-97
elsif ($club) {
Link Here
|
89 |
binmode STDOUT, ':encoding(UTF-8)'; |
100 |
binmode STDOUT, ':encoding(UTF-8)'; |
90 |
print $cgi->header( -type => 'text/plain', -charset => 'UTF-8' ); |
101 |
print $cgi->header( -type => 'text/plain', -charset => 'UTF-8' ); |
91 |
|
102 |
|
92 |
if($enrollent_id){ |
103 |
if ($enrollent_id) { |
93 |
print to_json( { success => @club_enrollment_fields ? 1 : 0 } ); |
104 |
print to_json( { success => @club_enrollment_fields ? 1 : 0 } ); |
94 |
} |
105 |
} else { |
95 |
else{ |
|
|
96 |
print to_json( { success => $enrollment ? 1 : 0 } ); |
106 |
print to_json( { success => $enrollment ? 1 : 0 } ); |
97 |
} |
107 |
} |
98 |
- |
|
|