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

(-)a/C4/Form/MessagingPreferences.pm (-4 / +60 lines)
Lines 77-87 sub handle_form_action { Link Here
77
    # 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
78
    my $prefs_set = 0;
78
    my $prefs_set = 0;
79
    OPTION: foreach my $option ( @$messaging_options ) {
79
    OPTION: foreach my $option ( @$messaging_options ) {
80
        my $updater = { %{ $target_params }, 
80
        my $updater = {
81
                        message_attribute_id    => $option->{'message_attribute_id'} };
81
            message_attribute_id  => $option->{'message_attribute_id'}
82
        
82
        };
83
84
        $updater->{borrowernumber} = $target_params->{borrowernumber};
85
        if ($target_params->{categorycode} && !$target_params->{borrowernumber}) {
86
            $updater->{categorycode} = $target_params->{categorycode};
87
            delete $updater->{borrowernumber};
88
        }
89
83
        # find the desired transports
90
        # find the desired transports
84
        @{$updater->{'message_transport_types'}} = $query->multi_param( $option->{'message_attribute_id'} );
91
        @{$updater->{'message_transport_types'}} =
92
            $query->multi_param( $option->{'message_attribute_id'} );
93
94
        my $email     = $query->param('email');
95
        my $phone     = $query->param('phone');
96
        my $smsnumber = $query->param('SMSnumber');
97
98
        # Messaging preference validation. Make sure there is a valid contact
99
        # information provided for every transport method. Otherwise remove
100
        # the transport method, because the message cannot be delivered!
101
        if (_no_contact_set($email, $target_params, 'email')) {
102
            my $id = _transport_set(
103
                'email', @{$updater->{'message_transport_types'}}
104
            );
105
            splice(@{$updater->{'message_transport_types'}}, $id, 1) if $id > -1;
106
        }
107
        if (_no_contact_set($phone, $target_params, 'phone')) {
108
            my $id = _transport_set(
109
                'phone',@{$updater->{'message_transport_types'}}
110
            );
111
            splice(@{$updater->{'message_transport_types'}}, $id, 1) if $id > -1;
112
        }
113
        if (_no_contact_set($smsnumber, $target_params, 'smsalertnumber')) {
114
            my $id = _transport_set(
115
                'sms',
116
                @{$updater->{'message_transport_types'}}
117
            );
118
            splice(@{$updater->{'message_transport_types'}}, $id, 1) if $id > -1;
119
        }
120
85
        next OPTION unless $updater->{'message_transport_types'};
121
        next OPTION unless $updater->{'message_transport_types'};
86
122
87
        if ( $option->{'has_digest'} ) {
123
        if ( $option->{'has_digest'} ) {
Lines 149-154 sub set_form_values { Link Here
149
    $template->param(messaging_preferences => $messaging_options);
185
    $template->param(messaging_preferences => $messaging_options);
150
}
186
}
151
187
188
sub _no_contact_set {
189
    my ($param, $target_params, $target_param_name) = @_;
190
191
    if (defined $param && !$param) {
192
        return 1;
193
    }
194
    elsif (!defined $param && exists $target_params->{$target_param_name}
195
                           && !$target_params->{$target_param_name}) {
196
        return 1;
197
    } else {
198
        return 0;
199
    }
200
}
201
202
sub _transport_set {
203
    my ($name, @transport_methods) = @_;
204
205
    return List::MoreUtils::firstidx { $_ eq $name } @transport_methods;
206
}
207
152
=head1 TODO
208
=head1 TODO
153
209
154
=over 4
210
=over 4
(-)a/C4/Members.pm (+16 lines)
Lines 396-401 sub ModMember { Link Here
396
            }
396
            }
397
        }
397
        }
398
398
399
        # Validate messaging preferences if any of the following field have
400
        # been removed
401
        if (!$data{email} || !$data{phone} || !$data{smsalertnumber}) {
402
            C4::Members::Messaging::DeleteAllMisconfiguredPreferences(
403
                $data{borrowernumber}
404
            );
405
        }
406
        # ...or if any of the given contact information is invalid
407
        elsif ($data{email} && !Koha::Validation::email($data{email}) ||
408
               $data{phone} && !Koha::Validation::phone($data{phone}) ||
409
               $data{smsalertnumber} && !Koha::Validation::phone($data{phone})) {
410
            C4::Members::Messaging::DeleteAllMisconfiguredPreferences(
411
                $data{borrowernumber}
412
            );
413
        }
414
399
        # If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
415
        # If NorwegianPatronDBEnable is enabled, we set syncstatus to something that a
400
        # cronjob will use for syncing with NL
416
        # cronjob will use for syncing with NL
401
        if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
417
        if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
(-)a/C4/Members/Messaging.pm (-1 / +137 lines)
Lines 21-27 use strict; Link Here
21
use warnings;
21
use warnings;
22
use C4::Context;
22
use C4::Context;
23
23
24
24
use Koha::Validation;
25
25
26
=head1 NAME
26
=head1 NAME
27
27
Lines 253-258 sub SetMessagingPreferencesFromDefaults { Link Here
253
        $default_pref->{borrowernumber}          = $params->{borrowernumber};
253
        $default_pref->{borrowernumber}          = $params->{borrowernumber};
254
        SetMessagingPreference( $default_pref );
254
        SetMessagingPreference( $default_pref );
255
    }
255
    }
256
    # Finally, delete all misconfigured preferences
257
    DeleteAllMisconfiguredPreferences($params->{borrowernumber});
258
}
259
260
=head2 DeleteAllMisconfiguredPreferences
261
262
  C4::Members::Messaging::DeleteAllMisconfiguredPreferences( [ $borrowernumber ] );
263
264
Deletes all misconfigured preferences for ALL borrowers that have invalid contact information for
265
the transport types. Given a borrowernumber, deletes misconfigured preferences only for this borrower.
266
267
return: returns array of arrayrefs to the deleted preferences (borrower_message_preference_id and message_transport_type)
268
269
=cut
270
271
sub DeleteAllMisconfiguredPreferences {
272
    my $borrowernumber = shift;
273
274
    my @deleted_prefs;
275
276
    push(@deleted_prefs, DeleteMisconfiguredPreference("email", "email", "email",
277
                                                       $borrowernumber));
278
    push(@deleted_prefs, DeleteMisconfiguredPreference("phone", "phone", "phone",
279
                                                       $borrowernumber));
280
    push(@deleted_prefs, DeleteMisconfiguredPreference("sms", "smsalertnumber",
281
                                                       "phone", $borrowernumber));
282
283
    return @deleted_prefs;
284
}
285
286
=head2 DeleteMisconfiguredPreference
287
288
  C4::Members::Messaging::DeleteMisconfiguredPreference(
289
    $type, $contact, $validator [, $borrowernumber ]
290
  );
291
292
Takes a messaging preference type and the primary contact method for it, and
293
a string to define the Koha::Validation that should be used to determine whether
294
the preference is misconfigured.
295
296
A messaging preference is misconfigured when it is linked with invalid contact
297
information. E.g. messaging type email expects the user to have a valid e-mail
298
address in order to work.
299
300
Deletes misconfigured preferences for ALL borrowers that have invalid contact
301
information for that transport type. Given a borrowernumber, deletes misconfigured
302
preferences only for this borrower.
303
304
return: returns array of arrayrefs to the deleted preferences
305
(borrower_message_preference_id and message_transport_type)
306
307
=cut
308
309
sub DeleteMisconfiguredPreference {
310
    my ($type, $contact, $validator, $borrowernumber) = @_;
311
312
    if (not defined $type or not defined $contact or not defined $validator) {
313
        return 0;
314
    }
315
316
    my @misconfigured_prefs;
317
318
    # Get all messaging preferences and borrower's contact information
319
    my $dbh = C4::Context->dbh();
320
    my $query = "
321
322
        SELECT
323
                    borrower_message_preferences.borrower_message_preference_id,
324
                    borrower_message_transport_preferences.message_transport_type,
325
                    borrowers.$contact
326
327
        FROM
328
                    borrower_message_preferences,
329
                    borrower_message_transport_preferences,
330
                    borrowers
331
332
        WHERE
333
                    borrower_message_preferences.borrower_message_preference_id
334
                    =
335
                    borrower_message_transport_preferences.borrower_message_preference_id
336
337
        AND
338
                    borrowers.borrowernumber = borrower_message_preferences.borrowernumber
339
340
        AND
341
                    borrower_message_transport_preferences.message_transport_type = ?
342
    ";
343
344
    $query .= " AND borrowers.borrowernumber = ?" if defined $borrowernumber;
345
346
    my $sth = $dbh->prepare($query);
347
348
    if (defined $borrowernumber){
349
        $sth->execute($type, $borrowernumber);
350
    } else {
351
        $sth->execute($type);
352
    }
353
354
    while (my $ref = $sth->fetchrow_arrayref) {
355
        if ($$ref[1] eq $type) {
356
            if (not defined $$ref[2] or defined $$ref[2] and $$ref[2] eq "") {
357
                my $valid_contact = 0; # delete prefs if empty contact
358
                unless ($valid_contact && $$ref[2]) {
359
                    # push the misconfigured preferences into an array
360
                    push(@misconfigured_prefs, $$ref[0]);
361
                }
362
            }
363
            else {
364
                my ($valid_contact, $err, $err_msg) =
365
                Koha::Validation->$validator($$ref[2]);
366
                unless ($valid_contact && $$ref[2]) {
367
                    # push the misconfigured preferences into an array
368
                    push(@misconfigured_prefs, $$ref[0]);
369
                }
370
            }
371
        }
372
    }
373
374
    $sth = $dbh->prepare("
375
376
    DELETE FROM
377
                    borrower_message_transport_preferences
378
379
    WHERE
380
                    borrower_message_preference_id = ? AND message_transport_type = ?
381
    ");
382
383
    my @deleted_prefs;
384
    foreach my $id (@misconfigured_prefs){
385
        # delete the misconfigured pref
386
        $sth->execute($id, $type);
387
        # push it into array that we will return
388
        push (@deleted_prefs, [$id,$type]);
389
    }
390
391
    return @deleted_prefs;
256
}
392
}
257
393
258
=head1 TABLES
394
=head1 TABLES
(-)a/Koha/Patron/Modification.pm (+17 lines)
Lines 140-145 sub approve { Link Here
140
                            && $attr->{value} == 0
140
                            && $attr->{value} == 0
141
                          );
141
                          );
142
                }
142
                }
143
144
                # Validate messaging preferences if any of the following field
145
                # have been removed
146
                if (!$data->{email} || !$data->{phone} ||
147
                    !$data->{smsalertnumber}) {
148
                    C4::Members::Messaging::DeleteAllMisconfiguredPreferences(
149
                        $self->borrowernumber
150
                    );
151
                }
152
                # ...or if any of the given contact information is invalid
153
                elsif (!Koha::Validation::email($data->{email}) ||
154
                       !Koha::Validation::phone($data->{phone}) ||
155
                       !Koha::Validation::phone($data->{phone})) {
156
                    C4::Members::Messaging::DeleteAllMisconfiguredPreferences(
157
                        $self->borrowernumber
158
                    );
159
                }
143
            }
160
            }
144
            catch {
161
            catch {
145
                if ( $_->isa('DBIx::Class::Exception') ) {
162
                if ( $_->isa('DBIx::Class::Exception') ) {
(-)a/Koha/Validation.pm (+4 lines)
Lines 39-44 This module lets you validate given inputs. Link Here
39
=head3 email
39
=head3 email
40
40
41
Koha::Validation::email("email@address.com");
41
Koha::Validation::email("email@address.com");
42
Koha::Validation->email("email@address.com");
42
43
43
Validates given email.
44
Validates given email.
44
45
Lines 48-53 returns: 1 if the given email is valid (or empty), 0 otherwise. Link Here
48
49
49
sub email {
50
sub email {
50
    my $address = shift;
51
    my $address = shift;
52
    $address = shift if $address eq __PACKAGE__;
51
53
52
    return 1 unless $address;
54
    return 1 unless $address;
53
    return 0 if $address =~ /(^(\s))|((\s)$)/;
55
    return 0 if $address =~ /(^(\s))|((\s)$)/;
Lines 58-63 sub email { Link Here
58
=head3 phone
60
=head3 phone
59
61
60
Koha::Validation::validate_phonenumber(123456789);
62
Koha::Validation::validate_phonenumber(123456789);
63
Koha::Validation->validate_phonenumber(123456789);
61
64
62
Validates given phone number.
65
Validates given phone number.
63
66
Lines 67-72 returns: 1 if the given phone number is valid (or empty), 0 otherwise. Link Here
67
70
68
sub phone {
71
sub phone {
69
    my $phonenumber = shift;
72
    my $phonenumber = shift;
73
    $phonenumber = shift if $phonenumber eq __PACKAGE__;
70
74
71
    return 1 unless $phonenumber;
75
    return 1 unless $phonenumber;
72
    return 0 if $phonenumber =~ /(^(\s))|((\s)$)/;
76
    return 0 if $phonenumber =~ /(^(\s))|((\s)$)/;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt (+10 lines)
Lines 64-69 $(document).ready(function() { Link Here
64
        $(".toggler").toggle();
64
        $(".toggler").toggle();
65
    });
65
    });
66
66
67
    [% IF email %]
68
    patron_email = "[% email %]";
69
    [% END %]
70
    [% IF phone %]
71
    patron_phone = "[% phone %]";
72
    [% END %]
73
    [% IF smsalertnumber %]
74
    patron_sms = "[% smsalertnumber %]";
75
    [% END %]
67
76
68
    var MSG_INCORRECT_PHONE = _("Please enter a valid phone number.");
77
    var MSG_INCORRECT_PHONE = _("Please enter a valid phone number.");
69
    $.validator.addMethod('phone', function(value) {
78
    $.validator.addMethod('phone', function(value) {
Lines 114-119 $(document).ready(function() { Link Here
114
//]]>
123
//]]>
115
</script>
124
</script>
116
<script type="text/javascript" src="[% interface %]/[% theme %]/js/members.js"></script>
125
<script type="text/javascript" src="[% interface %]/[% theme %]/js/members.js"></script>
126
<script type="text/javascript" src="[% interface %]/[% theme %]/js/messaging-preference.js"></script>
117
</head>
127
</head>
118
<body id="pat_memberentrygen" class="pat">
128
<body id="pat_memberentrygen" class="pat">
119
[% INCLUDE 'header.inc' %]
129
[% INCLUDE 'header.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/members.js (+12 lines)
Lines 372-377 $(document).ready(function(){ Link Here
372
    $("#phone, #phonepro, #B_phone, #SMSnumber").each(function(){
372
    $("#phone, #phonepro, #B_phone, #SMSnumber").each(function(){
373
        $(this).val($.trim($(this).val()));
373
        $(this).val($.trim($(this).val()));
374
    });
374
    });
375
    disableCheckboxesWithInvalidPreferences($("#email"), "email");
376
    disableCheckboxesWithInvalidPreferences($("#phone"), "phone");
377
    disableCheckboxesWithInvalidPreferences($("#SMSnumber"), "sms");
378
    $("#email").on("input change", function() {
379
        disableCheckboxesWithInvalidPreferences($("#email"), "email");
380
    });
381
    $("#phone").on("input change", function() {
382
        disableCheckboxesWithInvalidPreferences($("#phone"), "phone");
383
    });
384
    $("#SMSnumber").on("input change", function() {
385
        disableCheckboxesWithInvalidPreferences($("#SMSnumber"), "sms");
386
    });
375
387
376
    var mrform = $("#manual_restriction_form");
388
    var mrform = $("#manual_restriction_form");
377
    var mrlink = $("#add_manual_restriction");
389
    var mrlink = $("#add_manual_restriction");
(-)a/koha-tmpl/intranet-tmpl/prog/js/messaging-preference.js (+93 lines)
Line 0 Link Here
1
/**
2
 *
3
 * Used in: koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt
4
 *
5
 * This component is also used in OPAC: koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt
6
 * For modifications, edit also OPAC version in: koha-tmpl/opac-tmpl/bootstrap/en/js/messaging-preference.js
7
 *
8
 * Disables and clears checkboxes from messaging preferences
9
 * if there is either invalid or nonexistent contact information
10
 * for the message transfer type.
11
 *
12
 * @param {HTMLInputElement} elem
13
 *  The contact field
14
 * @param {string} id_attr
15
 *  Checkboxes' id attribute so that we can recognize them
16
 */
17
// Settings for messaging-preference.js
18
var patron_messaging_checkbox_preferences = {
19
    email: {
20
        checked_checkboxes: null,
21
        is_enabled: true,
22
        disabled_checkboxes: null
23
    },
24
    sms: {
25
        checked_checkboxes: null,
26
        is_enabled: true,
27
        disabled_checkboxes: null
28
    },
29
    phone: {
30
        checked_checkboxes: null,
31
        is_enabled: true,
32
        disabled_checkboxes: null
33
    }
34
};
35
36
function disableCheckboxesWithInvalidPreferences(elem, id_attr) {
37
    if (!$(elem).length && typeof window["patron_" + id_attr] !== "undefined") {
38
        return;
39
    }
40
    // Get checkbox preferences for the element
41
    var checkbox_prefs = eval("patron_messaging_checkbox_preferences." + id_attr);
42
    // Check if element is empty or not valid
43
    if (!$(elem).length || $(elem).val().length == 0 || !$(elem).valid()) {
44
45
        if (checkbox_prefs.is_enabled) {
46
            // Save the state of checked checkboxes
47
            checkbox_prefs.checked_checkboxes = $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]:checked");
48
49
            // Save the state of automatically disabled checkboxes
50
            // (We don't want to enable them once the e-mail is valid!)
51
            checkbox_prefs.disabled_checkboxes = $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]:disabled");
52
53
            // Clear patron messaging preferences checkboxes
54
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").removeAttr("checked");
55
56
            // Then disable checkboxes from patron messaging perferences
57
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").attr("disabled", "disabled");
58
59
            // Color table cell's background emphasize the disabled state of the checkbox
60
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", "#E8F0F8");
61
62
            // Show notice about missing contact in messaging preferences box
63
            $("#required-" + id_attr).css("display", "block");
64
65
            checkbox_prefs.is_enabled = false;
66
        }
67
    } else {
68
69
        if (!checkbox_prefs.is_enabled) {
70
            // Enable patron messaging preferences checkboxes
71
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").removeAttr("disabled");
72
73
            // Disable the checkboxes that were disabled by default
74
            checkbox_prefs.disabled_checkboxes.each(function() {
75
                $(this).attr("disabled", "disabled");
76
                $(this).removeAttr("checked");
77
            });
78
79
            // Restore the state of checkboxes
80
            checkbox_prefs.checked_checkboxes.each(function() {
81
                $(this).attr("checked", "checked");
82
            });
83
84
            // Remove the background color from table cell
85
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", "#FFF");
86
87
            // Remove notice about missing contact from messaging preferences box
88
            $("#required-" + id_attr).css("display", "none");
89
90
            checkbox_prefs.is_enabled = true;
91
        }
92
    }
93
}
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt (-1 / +21 lines)
Lines 25-30 Link Here
25
                [% IF Koha.Preference( 'EnhancedMessagingPreferencesOPAC' )  %]
25
                [% IF Koha.Preference( 'EnhancedMessagingPreferencesOPAC' )  %]
26
                <div id="usermessaging">
26
                <div id="usermessaging">
27
                    <h3>Your messaging settings</h3>
27
                    <h3>Your messaging settings</h3>
28
                    <div id="required-email" class="alert" style="[% IF BORROWER_INFO.email %]display:none;[% END %]"><h4>Primary email</h4> is required in order to set Email preferences.</div>
29
                    [% IF ( TalkingTechItivaPhone AND ValidatePhoneNumber ) %]<div id="required-phone" class="alert" style="[% IF BORROWER_INFO.phone %]display:none;[% END %]"><h4>Primary phone</h4> is required in order to set Phone preferences.</div>[% END %]
30
                    [% IF ( SMSSendDriver AND ValidatePhoneNumber ) %]<div id="required-sms" class="alert" style="[% IF SMSnumber %]display:none;[% END %]"><h4>SMS number</h4> is required in order to set SMS preferences.</div>[% END %]
28
                    [% IF ( settings_updated ) %]
31
                    [% IF ( settings_updated ) %]
29
                        <div class="alert alert-success"><h4>Settings updated</h4></div>
32
                        <div class="alert alert-success"><h4>Settings updated</h4></div>
30
                    [% END %]
33
                    [% END %]
Lines 214-224 Link Here
214
            error.width("auto");
217
            error.width("auto");
215
        }
218
        }
216
    });
219
    });
217
    $("#SMSnumber").on("change", function(){
220
    [% IF BORROWER_INFO.email %]
221
    patron_email = "[% BORROWER_INFO.email %]";
222
    [% END %]
223
    [% IF BORROWER_INFO.phone %]
224
    patron_phone = "[% BORROWER_INFO.phone %]";
225
    [% END %]
226
    [% IF smsalertnumber %]
227
    patron_sms = "[% BORROWER_INFO.smsalertnumber %]";
228
    [% END %]
229
    disableCheckboxesWithInvalidPreferences(undefined, "email");
230
    disableCheckboxesWithInvalidPreferences(undefined, "phone");
231
    [% IF SMSSendDriver %]
232
    $("#SMSnumber").on("input change", function(){
218
        $(this).val($.trim($(this).val()));
233
        $(this).val($.trim($(this).val()));
234
        [% IF ( ValidatePhoneNumber ) %]
235
        disableCheckboxesWithInvalidPreferences($("#SMSnumber"), "sms");
236
        [% END %]
219
    });
237
    });
238
    [% END %]
220
  });
239
  });
221
//]]>
240
//]]>
222
</script>
241
</script>
223
<script type="text/javascript" src="/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.validate.min.js"></script>
242
<script type="text/javascript" src="/opac-tmpl/bootstrap/lib/jquery/plugins/jquery.validate.min.js"></script>
243
<script type="text/javascript" src="[% interface %]/[% theme %]/js/messaging-preference.js"></script>
224
[% END %]
244
[% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/messaging-preference.js (+94 lines)
Line 0 Link Here
1
/**
2
 *
3
 * Used in: koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-messaging.tt
4
 *
5
 * This component is also used in Staff client: koha-tmpl/intranet-tmpl/prog/en/modules/memberentrygen.tt
6
 * For modifications, edit also Staff client version in: koha-tmpl/intranet-tmpl/prog/en/js/messaging-preference.js
7
 *
8
 * Disables and clears checkboxes from messaging preferences
9
 * if there is either invalid or nonexistent contact information
10
 * for the message transfer type.
11
 *
12
 * @param {HTMLInputElement} elem
13
 *  The contact field
14
 * @param {string} id_attr
15
 *  Checkboxes' id attribute so that we can recognize them
16
 */
17
// Settings for messaging-preference.js
18
var patron_messaging_checkbox_preferences = {
19
    email: {
20
        checked_checkboxes: null,
21
        is_enabled: true,
22
        disabled_checkboxes: null
23
    },
24
    sms: {
25
        checked_checkboxes: null,
26
        is_enabled: true,
27
        disabled_checkboxes: null
28
    },
29
    phone: {
30
        checked_checkboxes: null,
31
        is_enabled: true,
32
        disabled_checkboxes: null
33
    }
34
};
35
36
function disableCheckboxesWithInvalidPreferences(elem, id_attr) {
37
    if (!$(elem).length && typeof window["patron_" + id_attr] !== "undefined") {
38
        return;
39
    }
40
    // Get checkbox preferences for the element
41
    var checkbox_prefs = eval("patron_messaging_checkbox_preferences." + id_attr);
42
    // Check if element is empty or not valid
43
44
    if (!$(elem).length || $(elem).val().length == 0 || !$(elem).valid()) {
45
46
        if (checkbox_prefs.is_enabled) {
47
            // Save the state of checked checkboxes
48
            checkbox_prefs.checked_checkboxes = $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]:checked");
49
50
            // Save the state of automatically disabled checkboxes
51
            // (We don't want to enable them once the e-mail is valid!)
52
            checkbox_prefs.disabled_checkboxes = $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]:disabled");
53
54
            // Clear patron messaging preferences checkboxes
55
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").removeAttr("checked");
56
57
            // Then disable checkboxes from patron messaging perferences
58
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").attr("disabled", "disabled");
59
60
            // Color table cell's background emphasize the disabled state of the checkbox
61
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", "#E8F0F8");
62
63
            // Show notice about missing contact in messaging preferences box
64
            $("#required-" + id_attr).css("display", "block");
65
66
            checkbox_prefs.is_enabled = false;
67
        }
68
    } else {
69
70
        if (!checkbox_prefs.is_enabled) {
71
            // Enable patron messaging preferences checkboxes
72
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").removeAttr("disabled");
73
74
            // Disable the checkboxes that were disabled by default
75
            checkbox_prefs.disabled_checkboxes.each(function() {
76
                $(this).attr("disabled", "disabled");
77
                $(this).removeAttr("checked");
78
            });
79
80
            // Restore the state of checkboxes
81
            checkbox_prefs.checked_checkboxes.each(function() {
82
                $(this).attr("checked", "checked");
83
            });
84
85
            // Remove the background color from table cell
86
            $("input[type='checkbox'][id^=" + id_attr + "][value=" + id_attr + "]").parent().css("background-color", "#FFF");
87
88
            // Remove notice about missing contact from messaging preferences box
89
            $("#required-" + id_attr).css("display", "none");
90
91
            checkbox_prefs.is_enabled = true;
92
        }
93
    }
94
}
(-)a/members/memberentry.pl (-2 / +2 lines)
Lines 438-444 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
438
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
438
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
439
        }
439
        }
440
        if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
440
        if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
441
            C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'});
441
            C4::Form::MessagingPreferences::handle_form_action($input, \%newdata, $template, 1, $newdata{'categorycode'});
442
        }
442
        }
443
        # Try to do the live sync with the Norwegian national patron database, if it is enabled
443
        # Try to do the live sync with the Norwegian national patron database, if it is enabled
444
        if ( exists $data{'borrowernumber'} && C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
444
        if ( exists $data{'borrowernumber'} && C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) {
Lines 499-505 if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ Link Here
499
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
499
            C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes);
500
        }
500
        }
501
        if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
501
        if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) {
502
            C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template);
502
            C4::Form::MessagingPreferences::handle_form_action($input, \%data, $template);
503
        }
503
        }
504
	}
504
	}
505
	print scalar ($destination eq "circ") ? 
505
	print scalar ($destination eq "circ") ? 
(-)a/opac/opac-messaging.pl (-2 / +1 lines)
Lines 77-83 if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) { Link Here
77
        $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
77
        $borrower = C4::Members::GetMember( borrowernumber => $borrowernumber );
78
    }
78
    }
79
79
80
    C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $borrowernumber }, $template);
80
    C4::Form::MessagingPreferences::handle_form_action($query, $borrower, $template);
81
}
81
}
82
82
83
C4::Form::MessagingPreferences::set_form_values({ borrowernumber     => $borrower->{'borrowernumber'} }, $template);
83
C4::Form::MessagingPreferences::set_form_values({ borrowernumber     => $borrower->{'borrowernumber'} }, $template);
84
- 

Return to bug 14590