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

(-)a/C4/Form/MessagingPreferences.pm (-2 / +3 lines)
Lines 23-28 use warnings; Link Here
23
use CGI qw ( -utf8 );
23
use CGI qw ( -utf8 );
24
use C4::Context;
24
use C4::Context;
25
use C4::Members::Messaging;
25
use C4::Members::Messaging;
26
use Koha::Patron::MessagePreferences;
26
27
27
use constant MAX_DAYS_IN_ADVANCE => 30;
28
use constant MAX_DAYS_IN_ADVANCE => 30;
28
29
Lines 72-78 adds a settings_updated template variable. Link Here
72
73
73
sub handle_form_action {
74
sub handle_form_action {
74
    my ($query, $target_params, $template, $insert, $categorycode) = @_;
75
    my ($query, $target_params, $template, $insert, $categorycode) = @_;
75
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
76
    my $messaging_options = Koha::Patron::MessagePreferences->get_options;
76
    # TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box
77
    # TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box
77
    my $prefs_set = 0;
78
    my $prefs_set = 0;
78
    OPTION: foreach my $option ( @$messaging_options ) {
79
    OPTION: foreach my $option ( @$messaging_options ) {
Lines 127-133 C<$template> is the Template::Toolkit object for the response. Link Here
127
sub set_form_values {
128
sub set_form_values {
128
    my ($target_params, $template) = @_;
129
    my ($target_params, $template) = @_;
129
    # walk through the options and update them with these borrower_preferences
130
    # walk through the options and update them with these borrower_preferences
130
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
131
    my $messaging_options = Koha::Patron::MessagePreferences->get_options;
131
    PREF: foreach my $option ( @$messaging_options ) {
132
    PREF: foreach my $option ( @$messaging_options ) {
132
        my $pref = C4::Members::Messaging::GetMessagingPreferences( { %{ $target_params }, message_name => $option->{'message_name'} } );
133
        my $pref = C4::Members::Messaging::GetMessagingPreferences( { %{ $target_params }, message_name => $option->{'message_name'} } );
133
        $option->{ $option->{'message_name'} } = 1;
134
        $option->{ $option->{'message_name'} } = 1;
(-)a/C4/Members/Messaging.pm (-39 / +1 lines)
Lines 21-28 use strict; Link Here
21
use warnings;
21
use warnings;
22
use C4::Context;
22
use C4::Context;
23
23
24
25
26
=head1 NAME
24
=head1 NAME
27
25
28
C4::Members::Messaging - manage patron messaging preferences
26
C4::Members::Messaging - manage patron messaging preferences
Lines 185-226 END_SQL Link Here
185
    return;    
183
    return;    
186
}
184
}
187
185
188
=head2 GetMessagingOptions
189
190
  my $messaging_options = C4::Members::Messaging::GetMessagingOptions()
191
192
returns a hashref of messaging options available.
193
194
=cut
195
196
sub GetMessagingOptions {
197
198
    my $sql = <<'END_SQL';
199
select message_attributes.message_attribute_id, takes_days, message_name, message_transport_type, is_digest
200
  FROM message_attributes
201
  LEFT JOIN message_transports
202
    ON message_attributes.message_attribute_id = message_transports.message_attribute_id
203
END_SQL
204
205
    my $sth = C4::Context->dbh->prepare($sql);
206
    $sth->execute();
207
    my $choices;
208
    while ( my $row = $sth->fetchrow_hashref() ) {
209
        $choices->{ $row->{'message_name'} }->{'message_attribute_id'} = $row->{'message_attribute_id'};
210
        $choices->{ $row->{'message_name'} }->{'message_name'}         = $row->{'message_name'};
211
        $choices->{ $row->{'message_name'} }->{'takes_days'}           = $row->{'takes_days'};
212
        $choices->{ $row->{'message_name'} }->{'has_digest'}           = 1 if $row->{'is_digest'};
213
        $choices->{ $row->{'message_name'} }->{'transport_' . $row->{'message_transport_type'}} = ' ';
214
    }
215
216
    my @return = values %$choices;
217
218
    @return = sort { $a->{message_attribute_id} <=> $b->{message_attribute_id} } @return;
219
220
    # warn( Data::Dumper->Dump( [ \@return ], [ 'return' ] ) );
221
    return \@return;
222
}
223
224
=head2 SetMessagingPreferencesFromDefaults
186
=head2 SetMessagingPreferencesFromDefaults
225
187
226
  C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $borrower->{'borrowernumber'}
188
  C4::Members::Messaging::SetMessagingPreferencesFromDefaults( { borrowernumber => $borrower->{'borrowernumber'}
Lines 241-247 sub SetMessagingPreferencesFromDefaults { Link Here
241
        }
203
        }
242
    }
204
    }
243
205
244
    my $messaging_options = GetMessagingOptions();
206
    my $messaging_options = Koha::Patron::MessagePreferences->get_options;
245
    OPTION: foreach my $option ( @$messaging_options ) {
207
    OPTION: foreach my $option ( @$messaging_options ) {
246
        my $default_pref = GetMessagingPreferences( { categorycode => $params->{categorycode},
208
        my $default_pref = GetMessagingPreferences( { categorycode => $params->{categorycode},
247
                                                      message_name => $option->{'message_name'} } );
209
                                                      message_name => $option->{'message_name'} } );
(-)a/Koha/Patron/Category.pm (-1 / +2 lines)
Lines 23-28 use C4::Members::Messaging; Link Here
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Patron::MessagePreferences;
26
27
27
use base qw(Koha::Object Koha::Object::Limit::Library);
28
use base qw(Koha::Object Koha::Object::Limit::Library);
28
29
Lines 79-85 my $messaging = $category->default_messaging(); Link Here
79
80
80
sub default_messaging {
81
sub default_messaging {
81
    my ( $self ) = @_;
82
    my ( $self ) = @_;
82
    my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
83
    my $messaging_options = Koha::Patron::MessagePreferences->get_options;
83
    my @messaging;
84
    my @messaging;
84
    foreach my $option (@$messaging_options) {
85
    foreach my $option (@$messaging_options) {
85
        my $pref = C4::Members::Messaging::GetMessagingPreferences(
86
        my $pref = C4::Members::Messaging::GetMessagingPreferences(
(-)a/opac/opac-messaging.pl (-4 lines)
Lines 49-57 my ( $template, $borrowernumber, $cookie ) = get_template_and_user( Link Here
49
49
50
my $patron = Koha::Patrons->find( $borrowernumber ); # FIXME and if borrowernumber is invalid?
50
my $patron = Koha::Patrons->find( $borrowernumber ); # FIXME and if borrowernumber is invalid?
51
51
52
my $messaging_options;
53
$messaging_options = C4::Members::Messaging::GetMessagingOptions() if $opac_messaging;
54
55
if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
52
if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) {
56
    die "Wrong CSRF token" unless Koha::Token->new->check_csrf({
53
    die "Wrong CSRF token" unless Koha::Token->new->check_csrf({
57
        session_id => scalar $query->cookie('CGISESSID'),
54
        session_id => scalar $query->cookie('CGISESSID'),
58
- 

Return to bug 18595