=head2 handle_form_action
- C4::Form::MessagingPreferences::handle_form_action($input, { categorycode => 'CPL' }, $template);
+ C4::Form::MessagingPreferences::handle_form_action($input, { categorycode => 'CPL' }, $template, $insert);
Processes CGI parameters and updates the target patron or patron category's
preferences.
C<$target_params> is a hashref containing either a C<categorycode> key or a C<borrowernumber> key
identifying the patron or patron category whose messaging preferences are to be updated.
-C<$template> is the HTML::Template::Pro object for the response; this routine
+C<$template> is the Template::Toolkit object for the response; this routine
adds a settings_updated template variable.
=cut
sub handle_form_action {
- my ($query, $target_params, $template) = @_;
+ my ($query, $target_params, $template, $insert, $categorycode) = @_;
my $messaging_options = C4::Members::Messaging::GetMessagingOptions();
-
# TODO: If a "NONE" box and another are checked somehow (javascript failed), we should pay attention to the "NONE" box
-
+ my $prefs_set = 0;
OPTION: foreach my $option ( @$messaging_options ) {
my $updater = { %{ $target_params },
message_attribute_id => $option->{'message_attribute_id'} };
}
C4::Members::Messaging::SetMessagingPreference( $updater );
- }
+ if ($query->param( $option->{'message_attribute_id'})){
+ $prefs_set = 1;
+ }
+ }
+ if (! $prefs_set && $insert){
+ # this is new borrower, and we have no preferences set, use the defaults
+ $target_params->{categorycode} = $categorycode;
+ C4::Members::Messaging::SetMessagingPreferencesFromDefaults( $target_params );
+ }
# show the success message
$template->param( settings_updated => 1 );
}
C<$target_params> is a hashref containing either a C<categorycode> key or a C<borrowernumber> key
identifying the patron or patron category.
-C<$template> is the HTML::Template::Pro object for the response.
+C<$template> is the Template::Toolkit object for the response.
=cut
$template->param( "checked" => 1 ) if ( defined($nodouble) && $nodouble eq 1 );
( $borrower_data = GetMember( 'borrowernumber' => $borrowernumber ) ) if ( $op eq 'modify' or $op eq 'save' or $op eq 'duplicate' );
my $categorycode = $input->param('categorycode') || $borrower_data->{'categorycode'};
-my $category_type = $input->param('category_type');
+my $category_type = $input->param('category_type') || '';
+if ($category_type){
+ $template->{VARS}->{'type_only'} = 1;
+}
my $new_c_type = $category_type; #if we have input param, then we've already chosen the cat_type.
unless ($category_type or !($categorycode)){
my $borrowercategory = GetBorrowercategory($categorycode);
$category_type = $borrowercategory->{'category_type'};
my $category_name = $borrowercategory->{'description'};
$template->param("categoryname"=>$category_name);
-}
+ }
$category_type="A" unless $category_type; # FIXME we should display a error message instead of a 500 error !
# if a add or modify is requested => check validity of data.
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);
+ C4::Form::MessagingPreferences::handle_form_action($input, { borrowernumber => $borrowernumber }, $template, 1, $newdata{'categorycode'});
}
} elsif ($op eq 'save'){
if ($NoUpdateLogin) {