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()', |
68 |
date_canceled => undef, |
69 |
date_created => \'NOW()', |
|
|
70 |
branchcode => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, |
71 |
} |
69 |
} |
72 |
)->store(); |
70 |
)->count(); |
73 |
|
71 |
|
74 |
if ($enrollment) { |
72 |
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; |
73 |
|
76 |
|
74 |
unless ( $already_enrolled || $wrong_branch ) { |
77 |
foreach my $e (@enrollment_fields) { |
75 |
$enrollment = Koha::Club::Enrollment->new( |
78 |
my $club_enrollment_field = Koha::Club::Enrollment::Field->new( |
76 |
{ |
79 |
{ |
77 |
club_id => $club->id(), |
80 |
club_enrollment_id => $enrollment->id(), |
78 |
borrowernumber => $borrowernumber, |
81 |
club_template_enrollment_field_id => $e->id(), |
79 |
date_enrolled => \'NOW()', |
82 |
value => scalar $cgi->param( $e->id() ), |
80 |
date_created => \'NOW()', |
83 |
} |
81 |
branchcode => C4::Context->userenv ? C4::Context->userenv->{branch} : undef, |
84 |
)->store(); |
82 |
} |
|
|
83 |
)->store(); |
84 |
|
85 |
if ($enrollment) { |
86 |
my @enrollment_fields = $club->club_template()->club_template_enrollment_fields->as_list; |
87 |
|
88 |
foreach my $e (@enrollment_fields) { |
89 |
my $club_enrollment_field = Koha::Club::Enrollment::Field->new( |
90 |
{ |
91 |
club_enrollment_id => $enrollment->id(), |
92 |
club_template_enrollment_field_id => $e->id(), |
93 |
value => scalar $cgi->param( $e->id() ), |
94 |
} |
95 |
)->store(); |
96 |
} |
85 |
} |
97 |
} |
86 |
} |
98 |
} |
87 |
} |
99 |
} |
Lines 89-97
elsif ($club) {
Link Here
|
89 |
binmode STDOUT, ':encoding(UTF-8)'; |
101 |
binmode STDOUT, ':encoding(UTF-8)'; |
90 |
print $cgi->header( -type => 'text/plain', -charset => 'UTF-8' ); |
102 |
print $cgi->header( -type => 'text/plain', -charset => 'UTF-8' ); |
91 |
|
103 |
|
92 |
if($enrollent_id){ |
104 |
if ($enrollent_id) { |
93 |
print to_json( { success => @club_enrollment_fields ? 1 : 0 } ); |
105 |
print to_json( { success => @club_enrollment_fields ? 1 : 0 } ); |
94 |
} |
106 |
} else { |
95 |
else{ |
|
|
96 |
print to_json( { success => $enrollment ? 1 : 0 } ); |
107 |
print to_json( { success => $enrollment ? 1 : 0 } ); |
97 |
} |
108 |
} |
98 |
- |
|
|