View | Details | Raw Unified | Return to bug 35942
Collapse All | Expand All

(-)a/opac/svc/club/enroll (-20 / +31 lines)
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
}
(-)a/svc/club/enroll (-7 / +12 lines)
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 43-57 my $club = Koha::Clubs->find($id); Link Here
43
43
44
my $enrollment;
44
my $enrollment;
45
if ($club) {
45
if ($club) {
46
    my $already_enrolled = Koha::Club::Enrollments->search(
47
        {
48
            club_id        => $id,
49
            borrowernumber => $borrowernumber,
50
            date_canceled  => undef,
51
        }
52
    )->count();
53
46
    $enrollment = Koha::Club::Enrollment->new(
54
    $enrollment = Koha::Club::Enrollment->new(
47
        {
55
        {
48
            club_id        => $club->id(),
56
            club_id        => $club->id(),
49
            borrowernumber => $borrowernumber,
57
            borrowernumber => $borrowernumber,
50
            date_enrolled  => \'NOW()',
58
            date_canceled  => undef,
51
            date_created   => \'NOW()',
52
            branchcode     => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef,
53
        }
59
        }
54
    )->store();
60
    )->store() unless $already_enrolled;
55
61
56
    if ($enrollment) {
62
    if ($enrollment) {
57
        my @enrollment_fields = $club->club_template()->club_template_enrollment_fields->as_list;
63
        my @enrollment_fields = $club->club_template()->club_template_enrollment_fields->as_list;
58
- 

Return to bug 35942