From b6e62489d8dc749db077ccb86ea29f4ae7b91fa6 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 20 May 2009 11:35:55 -0500 Subject: [PATCH] bug 3222: moved messaging preference editing The display and editing of messaging preferences for a patron have been moved as follows: * the prefs for a patron are now displayed on the patron details tab, not the messaging tab. * the prefs are now modified by editing the patron record, not on the messaging tab. The messaging tab now contains only the list of messages that have been or will be sent to the patron. When creating a new patron record, changing the patron category via the category dropdown now also changes the default messaging preferences for that patron. If you start editing a new patron, change one of the messaging preferences, then change the patron category, the form will ask you if you want to keep the preferences or get the defaults belonging to the new patron category. Note that when you edit an existing patron record, changing the patron category will *not* cause the messaging preferences to be automatically changed. Programmer's note: this commit introduces a new web service, members/default_messagingprefs.pl, that uses Jesse Weaver's C4::Service module. Signed-off-by: Daniel Sweeney Signed-off-by: Galen Charlton --- C4/Form/MessagingPreferences.pm | 1 + .../en/includes/messaging-preference-form.inc | 57 +++++++++++++++-- .../en/modules/members/memberentrygen.tmpl | 59 ++++++++++++++++++ .../prog/en/modules/members/messaging.tmpl | 17 ----- .../prog/en/modules/members/moremember.tmpl | 16 ++++- members/default_messageprefs.pl | 35 +++++++++++ members/memberentry.pl | 62 ++++++++++++++----- members/messaging.pl | 16 +---- members/moremember.pl | 8 +++ 9 files changed, 217 insertions(+), 54 deletions(-) create mode 100755 members/default_messageprefs.pl diff --git a/C4/Form/MessagingPreferences.pm b/C4/Form/MessagingPreferences.pm index 264158e054..230b048d17 100755 --- a/C4/Form/MessagingPreferences.pm +++ b/C4/Form/MessagingPreferences.pm @@ -126,6 +126,7 @@ sub set_form_values { # make a hashref of the days, selecting one. if ( $option->{'takes_days'} ) { my $days_in_advance = $pref->{'days_in_advance'} ? $pref->{'days_in_advance'} : 0; + $option->{days_in_advance} = $days_in_advance; @{$option->{'select_days'}} = map {; { day => $_, selected => $_ == $days_in_advance ? 'selected="selected"' :'' } diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc index 59f7b32e2d..1655afcf7a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/messaging-preference-form.inc @@ -18,12 +18,23 @@ " /> - + + + + + + + - - - - - --> + +
Days in advanceSMSEmailDigests only?Do not notify
Days in advanceSMSEmailDigests only?Do not notify
+ + -DAYS"> + @@ -35,46 +46,80 @@ - + + " + name="" + value="sms" disabled="disabled" /> + + " name="" value="sms" onclick = "$('#none'+'').attr('checked','');" /> + - + + " + name="" + value="email" disabled="disabled" /> + + " name="" value="email" onclick = "$('#none'+'').attr('checked','');" /> + - + + " + value="" + name="digest" disabled="disabled" /> + + " value="" name="digest" onclick = "$('#none'+'').attr('checked','');" /> + - + + " + name="" + value="rss" disabled="disabled" /> + + " name="" value="rss" onclick = "$('#none'+'').attr('checked','');" /> + - " />
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl index fa2aeba4df..223e9ac92f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl @@ -929,6 +929,65 @@ + +
+ + + + + + Patron messaging preferences + + +

+ " /> +

+ +
+ +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/messaging.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/messaging.tmpl index 116e06ecd9..1b8b727f1f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/messaging.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/messaging.tmpl @@ -42,23 +42,6 @@ -
- -

Settings Updated

- The patron settings have been updated
- - -

Manage patron messaging settings

- - - -

" />

-
- Cancel -
- -
- diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl index 2b1d3beebf..e4b1135a0b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/moremember.tmpl @@ -279,6 +279,19 @@ if (nodename =="barcodes[]"){ + + +
+

Patron messaging preferences

+ + +
  1. SMS number: +
+ +
+ + +
@@ -443,7 +456,7 @@ if (nodename =="barcodes[]"){ - +
@@ -467,6 +480,7 @@ if (nodename =="barcodes[]"){

+
Message Queue
Totals:
diff --git a/members/default_messageprefs.pl b/members/default_messageprefs.pl new file mode 100755 index 0000000000..8b9e190968 --- /dev/null +++ b/members/default_messageprefs.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +# Copyright 2009 LibLime +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA +# + +use strict; +use warnings; +use C4::Service; +use C4::Form::MessagingPreferences; + +# Simple JSON service to get the default messaging preferences +# for a patron category - used by the patron editing form to +# update the prefs if operator is creating a new patron and has +# changed the patron category from its original value. + +my ($query, $response) = C4::Service->init(borrowers => 1); +my ($categorycode) = C4::Service->require_params('categorycode'); +C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode }, $response); +C4::Service->return_success( $response ); + diff --git a/members/memberentry.pl b/members/memberentry.pl index d5f04b8a36..2c97a570c0 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -38,6 +38,7 @@ use C4::Log; use C4::Letters; use C4::Branch; # GetBranches +use C4::Form::MessagingPreferences; use vars qw($debug); @@ -148,19 +149,30 @@ BEGIN # remove keys from %newdata that ModMember() doesn't like { - my @keys_to_delete = qw( - BorrowerMandatoryField - category_type - check_member - destination - nodouble - op - save - select_roadtype - updtype + my @keys_to_delete = ( + qr/^BorrowerMandatoryField$/, + qr/^category_type$/, + qr/^check_member$/, + qr/^destination$/, + qr/^nodouble$/, + qr/^op$/, + qr/^save$/, + qr/^select_roadtype$/, + qr/^updtype$/, + qr/^SMSnumber$/, + qr/^setting_extended_patron_attributes$/, + qr/^setting_messaging_prefs$/, + qr/^digest$/, + qr/^modify$/, + qr/^step$/, + qr/^\d+$/, + qr/^\d+-DAYS/, + qr/^patron_attr_/, ); - for (@keys_to_delete) { - delete($newdata{$_}); + for my $regexp (@keys_to_delete) { + for (keys %newdata) { + delete($newdata{$_}) if /$regexp/; + } } } @@ -267,6 +279,10 @@ BEGIN } } +if ( ( defined $input->param('SMSnumber') ) && ( $input->param('SMSnumber') ne $newdata{'mobile'} ) ) { + $newdata{smsalertnumber} = $input->param('SMSnumber'); +} + ### Error checks should happen before this line. $nok = $nok || scalar(@errors); if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ @@ -310,6 +326,9 @@ BEGIN if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes); } + if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) { + C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template); + } } elsif ($op eq 'save'){ if ($NoUpdateLogin) { delete $newdata{'password'}; @@ -319,6 +338,9 @@ BEGIN if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes); } + if (C4::Context->preference('EnhancedMessagingPreferences') and $input->param('setting_messaging_prefs')) { + C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template); + } } print scalar ($destination eq "circ") ? $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber") : @@ -337,7 +359,7 @@ BEGIN %data=%newdata; $template->param( updtype => ($op eq 'add' ?'I':'M')); # used to check for $op eq "insert"... but we just changed $op! unless ($step){ - $template->param( step_1 => 1,step_2 => 1,step_3 => 1, step_4 => 1); + $template->param( step_1 => 1,step_2 => 1,step_3 => 1, step_4 => 1, step_5 => 1); } } if (C4::Context->preference("IndependantBranches")) { @@ -352,11 +374,11 @@ BEGIN if ($op eq 'add'){ my $arg2 = $newdata{'dateenrolled'} || C4::Dates->today('iso'); $data{'dateexpiry'} = GetExpiryDate($newdata{'categorycode'},$arg2); - $template->param( updtype => 'I', step_1=>1, step_2=>1, step_3=>1, step_4=>1); + $template->param( updtype => 'I', step_1=>1, step_2=>1, step_3=>1, step_4=>1, step_5 => 1); } if ($op eq "modify") { $template->param( updtype => 'M',modify => 1 ); - $template->param( step_1=>1, step_2=>1, step_3=>1, step_4=>1) unless $step; + $template->param( step_1=>1, step_2=>1, step_3=>1, step_4=>1, step_5 => 1) unless $step; } # my $cardnumber=$data{'cardnumber'}; $data{'cardnumber'}=fixup_cardnumber($data{'cardnumber'}) if $op eq 'add'; @@ -573,6 +595,16 @@ BEGIN patron_attributes_form($template, $borrowernumber); } +if (C4::Context->preference('EnhancedMessagingPreferences')) { + if ($op eq 'add') { + C4::Form::MessagingPreferences::set_form_values({ categorycode => $categorycode }, $template); + } else { + C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowernumber }, $template); + } + $template->param(SMSSendDriver => C4::Context->preference("SMSSendDriver")); + $template->param(SMSnumber => defined $data{'smsalertnumber'} ? $data{'smsalertnumber'} : $data{'mobile'}); +} + $template->param( "showguarantor" => ($category_type=~/A|I|S|X/) ? 0 : 1); # associate with step to know where you are $debug and warn "memberentry step: $step"; $template->param(%data); diff --git a/members/messaging.pl b/members/messaging.pl index 90d154231c..1427973849 100755 --- a/members/messaging.pl +++ b/members/messaging.pl @@ -33,7 +33,6 @@ use C4::Biblio; use C4::Reserves; use C4::Branch; # GetBranchName -use C4::Form::MessagingPreferences; use Data::Dumper; @@ -65,18 +64,6 @@ BEGIN my $borrower = GetMemberDetails( $borrowernumber ); -if ( defined $query->param('modify') && $query->param('modify') eq 'yes' ) { - - # If they've modified the SMS number, record it. - if ( ( defined $query->param('SMSnumber') ) && ( $query->param('SMSnumber') ne $borrower->{'mobile'} ) ) { - ModMember( borrowernumber => $borrowernumber, - smsalertnumber => $query->param('SMSnumber') ); - $borrower = GetMemberDetails( $borrowernumber ); - } - C4::Form::MessagingPreferences::handle_form_action($query, { borrowernumber => $borrowernumber }, $template); -} - -C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowernumber }, $template); if ( $borrower->{'category_type'} eq 'C') { my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' ); @@ -100,7 +87,6 @@ BEGIN dateformat => C4::Context->preference("dateformat"), categoryname => $borrower->{'description'}, $borrower->{'categorycode'} => 1, - SMSSendDriver => C4::Context->preference("SMSSendDriver") ); #$messaging_preferences->{'SMSnumber'}{'value'} = defined $borrower->{'smsalertnumber'} @@ -109,6 +95,6 @@ BEGIN $template->param( BORROWER_INFO => [ $borrower ], messagingview => 1, is_child => ($borrower->{'category_type'} eq 'C'), - SMSnumber => defined $borrower->{'smsalertnumber'} ? $borrower->{'smsalertnumber'} : $borrower->{'mobile'} ); + ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/members/moremember.pl b/members/moremember.pl index 941272d8bd..610bceb4dd 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -47,6 +47,7 @@ =head1 moremember.pl use C4::Biblio; use C4::Reserves; use C4::Branch; # GetBranchName +use C4::Form::MessagingPreferences; #use Smart::Comments; #use Data::Dumper; @@ -350,6 +351,13 @@ BEGIN } } +if (C4::Context->preference('EnhancedMessagingPreferences')) { + C4::Form::MessagingPreferences::set_form_values({ borrowernumber => $borrowernumber }, $template); + $template->param(messaging_form_inactive => 1); + $template->param(SMSSendDriver => C4::Context->preference("SMSSendDriver")); + $template->param(SMSnumber => defined $data->{'smsalertnumber'} ? $data->{'smsalertnumber'} : $data->{'mobile'}); +} + $template->param( detailview => 1, AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),