From a8accfb4c5034bf7883d7b35cbabab9c6acef092 Mon Sep 17 00:00:00 2001 From: John Beppu Date: Tue, 3 Feb 2009 16:02:00 -0600 Subject: [PATCH] Messaging Preferences for Intranet - Added ability to modify per-user messaging preferences. Signed-off-by: Daniel Sweeney Signed-off-by: Galen Charlton --- .../en/modules/members/memberentrygen.tmpl | 47 ++++++++++ members/memberentry.pl | 90 ++++++++++++++++++- 2 files changed, 135 insertions(+), 2 deletions(-) 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 698f37bde9..19732eb7bf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tmpl @@ -865,6 +865,53 @@ + +
+ Items Borrowed Notifications +
    + +
  1. + + + + " name="" value="1" checked="checked" /> + + " name="" value="1" /> + + + + " name="" value="0" checked="checked"/> + + " name="" value="0" /> + +
  2. + +
+
+ +
+ Items Returned Notifications +
    + +
  1. + + + + " name="" value="1" checked="checked" /> + + " name="" value="1" /> + + + + " name="" value="0" checked="checked"/> + + " name="" value="0" /> + +
  2. + +
+
+ diff --git a/members/memberentry.pl b/members/memberentry.pl index 0466a8b0e7..3c0656cb49 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -115,6 +115,7 @@ $category_type="A" unless $category_type; # FIXME we should display a error mess # if a add or modify is requested => check validity of data. %data = %$borrower_data if ($borrower_data); +# initialize %newdata my %newdata; # comes from $input->param() if ($op eq 'insert' || $op eq 'modify' || $op eq 'save') { my @names= ($borrower_data && $op ne 'save') ? keys %$borrower_data : $input->param(); @@ -145,6 +146,26 @@ if ($op eq 'insert' || $op eq 'modify' || $op eq 'save') { } } +# remove keys from %newdata that ModMember() doesn't like +{ + my @keys_to_delete = + map { ("items_borrowed_$_", "items_returned_$_") } qw(email sms feed); + push @keys_to_delete, qw( + BorrowerMandatoryField + category_type + check_member + destination + nodouble + op + save + select_roadtype + updtype + ); + for (@keys_to_delete) { + delete($newdata{$_}); + } +} + #############test for member being unique ############# if (($op eq 'insert') and !$nodouble){ my $category_type_send=$category_type if ($category_type eq 'I'); @@ -290,7 +311,8 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ delete $newdata{'password'}; delete $newdata{'userid'}; } - &ModMember(%newdata); + &ModMember(%newdata); + save_messaging_preferences($input); if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes); } @@ -454,6 +476,35 @@ foreach (keys(%flags)) { push @flagdata,\%row; } +## Mesaging Preferences +##____________________________________________________________________________ +sub yes_or_no { + my ($transport, $config) = @_; + if (grep { $_ eq $transport } @{$config->{transports}}) { + return (yes => 1); + } else { + return (no => 1); + } +} +my $checkin_prefs = C4::Members::Messaging::GetMessagingPreferences({ + borrowernumber => $borrowernumber, + message_name => 'Item Checkout' +}); +my @items_borrowed_loop = ( + { name => 'items_borrowed_email', label => 'Email', yes_or_no('email', $checkin_prefs) }, + { name => 'items_borrowed_sms', label => 'Text Message', yes_or_no('sms', $checkin_prefs) }, + { name => 'items_borrowed_feed', label => 'XML Syndication Feed', yes_or_no('feed', $checkin_prefs) }, +); +my $checkout_prefs = C4::Members::Messaging::GetMessagingPreferences({ + borrowernumber => $borrowernumber, + message_name => 'Item Check-in' +}); +my @items_returned_loop = ( + { name => 'items_returned_email', label => 'Email', yes_or_no('email', $checkout_prefs) }, + { name => 'items_returned_sms', label => 'Text Message', yes_or_no('sms', $checkout_prefs) }, + { name => 'items_returned_feed', label => 'XML Syndication Feed', yes_or_no('feed', $checkout_prefs) }, +); + #get Branches my @branches; my @select_branch; @@ -496,7 +547,7 @@ if (C4::Context->preference("memberofinstitution")){ $org_labels{$organisation}=$organisations->{$organisation}->{'surname'}; } $member_of_institution=1; - + $CGIorganisations = CGI::scrolling_list( -id => 'organisations', -name => 'organisations', -labels => \%org_labels, @@ -576,6 +627,8 @@ $template->param( borrotitlepopup => $borrotitlepopup, guarantorinfo => $guarantorinfo, flagloop => \@flagdata, + items_borrowed_loop => \@items_borrowed_loop, + items_returned_loop => \@items_returned_loop, dateformat => C4::Dates->new()->visual(), C4::Context->preference('dateformat') => 1, check_categorytype =>$check_categorytype,#to recover the category type with checkcategorytype function @@ -674,6 +727,39 @@ sub patron_attributes_form { } +sub save_messaging_preferences { + my $input = shift; + my %options = map { $_->{message_name} => $_ } + @{C4::Members::Messaging::GetMessagingOptions()}; + my @checkin_transports; + my @checkout_transports; + for (qw(email sms feed)) { + push @checkin_transports, $_ if ($input->param("items_returned_$_")); + push @checkout_transports, $_ if ($input->param("items_borrowed_$_")); + } + #use Data::Dump 'pp'; + #warn pp({ checkin => \@checkin_transports, checkout => \@checkout_transports }); + + # Check-in Notifications + C4::Members::Messaging::SetMessagingPreference({ + borrowernumber => $borrowernumber, + wants_digest => 1, + message_attribute_id => $options{'Item Check-in'}{message_attribute_id}, + message_transport_types => \@checkin_transports, + }); + # Checkout Notifications + C4::Members::Messaging::SetMessagingPreference({ + borrowernumber => $borrowernumber, + wants_digest => 1, + message_attribute_id => $options{'Item Checkout'}{message_attribute_id}, + message_transport_types => \@checkout_transports, + }); + return { + checkin => \@checkin_transports, + checkout => \@checkout_transports, + }; +} + # Local Variables: # tab-width: 8 # End: -- 2.39.5