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                             => scalar $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 (-31 / +41 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 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
- 

Return to bug 35942