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

(-)a/C4/Form/MessagingPreferences.pm (-2 / +40 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 98-103 sub handle_form_action { Link Here
98
102
99
        C4::Members::Messaging::SetMessagingPreference( $updater );
103
        C4::Members::Messaging::SetMessagingPreference( $updater );
100
104
105
        _pushToActionLogBuffer($logEntries, $origPrefs, $updater, $option);
106
101
	if ($query->param( $option->{'message_attribute_id'})){
107
	if ($query->param( $option->{'message_attribute_id'})){
102
	    $prefs_set = 1;
108
	    $prefs_set = 1;
103
	}
109
	}
Lines 109-114 sub handle_form_action { Link Here
109
    }
115
    }
110
    # show the success message
116
    # show the success message
111
    $template->param( settings_updated => 1 );
117
    $template->param( settings_updated => 1 );
118
119
    _writeActionLogBuffer($logEntries, $borrowernumber);
112
}
120
}
113
121
114
=head2 set_form_values
122
=head2 set_form_values
Lines 149-154 sub set_form_values { Link Here
149
    $template->param(messaging_preferences => $messaging_options);
157
    $template->param(messaging_preferences => $messaging_options);
150
}
158
}
151
159
160
sub _pushToActionLogBuffer {
161
    return unless C4::Context->preference("BorrowersLog");
162
    my ($logEntries, $origPrefs, $updater, $option) = @_;
163
164
    if ($updater->{message_transport_types} && scalar(@{$updater->{message_transport_types}})) {
165
        my $entry = {};
166
        $entry->{cc}   = $updater->{categorycode}    if $updater->{categorycode};
167
        $entry->{dig}  = $updater->{wants_digest}    if $updater->{wants_digest};
168
        $entry->{da}   = $updater->{days_in_advance} if $updater->{days_in_advance};
169
        $entry->{mtt}  = $updater->{message_transport_types};
170
        $entry->{_name} = $option->{message_name};
171
        push(@$logEntries, $entry);
172
    }
173
}
174
175
sub _writeActionLogBuffer {
176
    return unless C4::Context->preference("BorrowersLog");
177
    my ($logEntries, $borrowernumber) = @_;
178
179
    if (scalar(@$logEntries)) {
180
        my $d = Data::Dumper->new([$logEntries]);
181
        $d->Indent(0);
182
        $d->Purity(0);
183
        $d->Terse(1);
184
        C4::Log::logaction('MEMBERS', 'MOD MTT', $borrowernumber, $d->Dump($logEntries));
185
    }
186
    else {
187
        C4::Log::logaction('MEMBERS', 'MOD MTT', $borrowernumber, 'All message_transports removed')
188
    }
189
}
190
152
=head1 TODO
191
=head1 TODO
153
192
154
=over 4
193
=over 4
155
- 

Return to bug 14806