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

(-)a/C4/Form/MessagingPreferences.pm (-2 / +44 lines)
Lines 20-25 package C4::Form::MessagingPreferences; Link Here
20
use strict;
20
use strict;
21
use warnings;
21
use warnings;
22
22
23
use Data::Dumper;
23
use CGI qw ( -utf8 );
24
use CGI qw ( -utf8 );
24
use C4::Context;
25
use C4::Context;
25
use C4::Members::Messaging;
26
use C4::Members::Messaging;
Lines 76-88 sub handle_form_action { Link Here
76
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
77
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
77
    # TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box
78
    # TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box
78
    my $prefs_set = 0;
79
    my $prefs_set = 0;
80
    my $borrowernumber;
81
    my $logEntries = [];
79
    OPTION: foreach my $option ( @$messaging_options ) {
82
    OPTION: foreach my $option ( @$messaging_options ) {
80
        my $updater = { %{ $target_params }, 
83
        my $updater = { %{ $target_params }, 
81
                        message_attribute_id    => $option->{'message_attribute_id'} };
84
                        message_attribute_id    => $option->{'message_attribute_id'} };
85
        $borrowernumber = $option->{borrowernumber} unless $borrowernumber;
82
        
86
        
83
        # find the desired transports
87
        # find the desired transports
84
        @{$updater->{'message_transport_types'}} = $query->param( $option->{'message_attribute_id'} );
88
        @{$updater->{'message_transport_types'}} = $query->param( $option->{'message_attribute_id'} );
85
        next OPTION unless $updater->{'message_transport_types'};
89
        next OPTION unless $updater->{'message_transport_types'}; #Shouldn't this be "unless scalar(@{$updater->{'message_transport_types'}});" however this would never let existing message_preferences to be deleted :)
86
90
87
        if ( $option->{'has_digest'} ) {
91
        if ( $option->{'has_digest'} ) {
88
            if ( List::Util::first { $_ == $option->{'message_attribute_id'} } $query->param( 'digest' ) ) {
92
            if ( List::Util::first { $_ == $option->{'message_attribute_id'} } $query->param( 'digest' ) ) {
Lines 96-103 sub handle_form_action { Link Here
96
            }
100
            }
97
        }
101
        }
98
102
103
        my $origPrefs = C4::Members::Messaging::GetMessagingPreferences({borrowernumber => $updater->{borrowernumber},
104
                                                         message_name   => $option->{message_name},
105
                                                        }) if C4::Context->preference("BorrowersLog");
106
99
        C4::Members::Messaging::SetMessagingPreference( $updater );
107
        C4::Members::Messaging::SetMessagingPreference( $updater );
100
108
109
        _pushToActionLogBuffer($logEntries, $origPrefs, $updater, $option);
110
101
	if ($query->param( $option->{'message_attribute_id'})){
111
	if ($query->param( $option->{'message_attribute_id'})){
102
	    $prefs_set = 1;
112
	    $prefs_set = 1;
103
	}
113
	}
Lines 109-114 sub handle_form_action { Link Here
109
    }
119
    }
110
    # show the success message
120
    # show the success message
111
    $template->param( settings_updated => 1 );
121
    $template->param( settings_updated => 1 );
122
123
    _writeActionLogBuffer($logEntries, $borrowernumber);
112
}
124
}
113
125
114
=head2 set_form_values
126
=head2 set_form_values
Lines 149-154 sub set_form_values { Link Here
149
    $template->param(messaging_preferences => $messaging_options);
161
    $template->param(messaging_preferences => $messaging_options);
150
}
162
}
151
163
164
sub _pushToActionLogBuffer {
165
    return unless C4::Context->preference("BorrowersLog");
166
    my ($logEntries, $origPrefs, $updater, $option) = @_;
167
168
    if ($updater->{message_transport_types} && scalar(@{$updater->{message_transport_types}})) {
169
        my $entry = {};
170
        $entry->{cc}   = $updater->{categorycode}    if $updater->{categorycode};
171
        $entry->{dig}  = $updater->{wants_digest}    if $updater->{wants_digest};
172
        $entry->{da}   = $updater->{days_in_advance} if $updater->{days_in_advance};
173
        $entry->{mtt}  = $updater->{message_transport_types};
174
        $entry->{_name} = $option->{message_name};
175
        push(@$logEntries, $entry);
176
    }
177
}
178
179
sub _writeActionLogBuffer {
180
    return unless C4::Context->preference("BorrowersLog");
181
    my ($logEntries, $borrowernumber) = @_;
182
183
    if (scalar(@$logEntries)) {
184
        my $d = Data::Dumper->new([$logEntries]);
185
        $d->Indent(0);
186
        $d->Purity(0);
187
        $d->Terse(1);
188
        C4::Log::logaction('MEMBERS', 'MOD MTT', $borrowernumber, $d->Dump($logEntries));
189
    }
190
    else {
191
        C4::Log::logaction('MEMBERS', 'MOD MTT', $borrowernumber, 'All message_transports removed')
192
    }
193
}
194
152
=head1 TODO
195
=head1 TODO
153
196
154
=over 4
197
=over 4
155
- 

Return to bug 14806