Messaging Preferences for Intranet

- Added ability to modify per-user messaging preferences.

Signed-off-by: Daniel Sweeney <daniel.sweeney@liblime.com>
Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
John Beppu 2009-02-03 16:02:00 -06:00 committed by Galen Charlton
parent 65b0ca3923
commit a8accfb4c5
2 changed files with 135 additions and 2 deletions

View File

@ -865,6 +865,53 @@
</ol>
</fieldset>
<!-- /TMPL_UNLESS -->
<fieldset class="rows">
<legend>Items Borrowed Notifications</legend>
<ol class="radio">
<!-- TMPL_LOOP NAME="items_borrowed_loop" -->
<li>
<label class="radio" for="yes_<!-- TMPL_VAR name="name" -->"> <!-- TMPL_VAR name="label" -->: </label>
<label for="yes_<!-- TMPL_VAR NAME="name" -->">Yes </label>
<!-- TMPL_IF NAME="yes" -->
<input type="radio" id="yes_<!-- TMPL_VAR NAME="name" -->" name="<!-- TMPL_VAR NAME="name" -->" value="1" checked="checked" />
<!-- TMPL_ELSE -->
<input type="radio" id="yes_<!-- TMPL_VAR NAME="name" -->" name="<!-- TMPL_VAR NAME="name" -->" value="1" />
<!-- /TMPL_IF -->
<label for="no_<!-- TMPL_VAR NAME="name" -->">No </label>
<!-- TMPL_IF NAME="no" -->
<input type="radio" id="no_<!-- TMPL_VAR NAME="name" -->" name="<!-- TMPL_VAR NAME="name" -->" value="0" checked="checked"/>
<!-- TMPL_ELSE -->
<input type="radio" id="no_<!-- TMPL_VAR NAME="name" -->" name="<!-- TMPL_VAR NAME="name" -->" value="0" />
<!-- /TMPL_IF -->
</li>
<!-- /TMPL_LOOP -->
</ol>
</fieldset>
<fieldset class="rows">
<legend>Items Returned Notifications</legend>
<ol class="radio">
<!-- TMPL_LOOP NAME="items_returned_loop" -->
<li>
<label class="radio" for="yes_<!-- TMPL_VAR name="name" -->"> <!-- TMPL_VAR name="label" -->: </label>
<label for="yes_<!-- TMPL_VAR NAME="name" -->">Yes </label>
<!-- TMPL_IF NAME="yes" -->
<input type="radio" id="yes_<!-- TMPL_VAR NAME="name" -->" name="<!-- TMPL_VAR NAME="name" -->" value="1" checked="checked" />
<!-- TMPL_ELSE -->
<input type="radio" id="yes_<!-- TMPL_VAR NAME="name" -->" name="<!-- TMPL_VAR NAME="name" -->" value="1" />
<!-- /TMPL_IF -->
<label for="no_<!-- TMPL_VAR NAME="name" -->">No </label>
<!-- TMPL_IF NAME="no" -->
<input type="radio" id="no_<!-- TMPL_VAR NAME="name" -->" name="<!-- TMPL_VAR NAME="name" -->" value="0" checked="checked"/>
<!-- TMPL_ELSE -->
<input type="radio" id="no_<!-- TMPL_VAR NAME="name" -->" name="<!-- TMPL_VAR NAME="name" -->" value="0" />
<!-- /TMPL_IF -->
</li>
<!-- /TMPL_LOOP -->
</ol>
</fieldset>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="step_4" --><!-- TMPL_IF NAME="ExtendedPatronAttributes" --><!-- TMPL_UNLESS NAME="no_patron_attribute_types" -->

View File

@ -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: