--- loncom/interface/lonnotify.pm	2010/07/09 14:40:20	1.37
+++ loncom/interface/lonnotify.pm	2019/07/23 13:58:53	1.43
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Sending messages
 #
-# $Id: lonnotify.pm,v 1.37 2010/07/09 14:40:20 raeburn Exp $
+# $Id: lonnotify.pm,v 1.43 2019/07/23 13:58:53 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -220,8 +220,8 @@ sub print_display_option_form {
     $output .= &Apache::lonhtmlcommon::row_title(&mt('Choose sender(s)'));
     my %personnel = &Apache::lonnet::get_domain_roles($cdom,\@roles);
     my @domcc = ();
-    foreach my $server (keys %personnel) {
-        foreach my $user (sort(keys %{$personnel{$server}})) {
+    foreach my $server (keys(%personnel)) {
+        foreach my $user (sort(keys(%{$personnel{$server}}))) {
             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
             unless (grep/^$uname:$udom$/,@domcc) {
                 my %userinfo = &Apache::lonnet::get('environment',['lastname','firstname'],$udom,$uname);
@@ -286,11 +286,11 @@ ENDSCRIPT
     $output .= &Apache::loncommon::start_data_table();
     if ($msgcount > 0) {
         $output .= &Apache::loncommon::start_data_table_header_row().
-	    '<th><a href="javascript:changeSort(\'date\')">Date</a></th>'.
-	    '<th><a href="javascript:changeSort(\'subject\')">Subject</a></th>'.
-	    '<th><a href="javascript:changeSort(\'sender\')">Sender</a></th>'.
-	    '<th><a href="javascript:changeSort(\'message\')">Message</a></th>'.
-	    '<th><a href="javascript:changeSort(\'recipients\')">Recipients</a></th>'.
+	    '<th><a href="javascript:changeSort(\'date\')">'.&mt('Date').'</a></th>'.
+	    '<th><a href="javascript:changeSort(\'subject\')">'.&mt('Subject').'</a></th>'.
+	    '<th><a href="javascript:changeSort(\'sender\')">'.&mt('Sender').'</a></th>'.
+	    '<th><a href="javascript:changeSort(\'message\')">'.&mt('Message').'</a></th>'.
+	    '<th><a href="javascript:changeSort(\'recipients\')">'.&mt('Recipients').'</a></th>'.
 	    &Apache::loncommon::end_data_table_header_row();
 
         if (($env{'form.sortby'} eq 'date') || ($env{'form.sortby'} eq '') || (!defined($env{'form.sortby'})) || (($env{'form.sortby'} eq 'sender') && (@senders <= 1))) {
@@ -357,7 +357,7 @@ ENDSCRIPT
         }
     } else {
         $output .= &Apache::loncommon::start_data_table_empty_row().
-	    '<td>No mail sent matching supplied criteria</td>'.
+	    '<td>'.&mt('No mail sent matching supplied criteria').'</td>'.
 	    &Apache::loncommon::end_data_table_empty_row();
     }
     $output .= &Apache::loncommon::end_data_table();
@@ -378,7 +378,6 @@ ENDSCRIPT
 
 sub print_selection_form {
     my ($r,$formname,$cdom) = @_;
-    my %coursecodes = ();
     my %codes = ();
     my @codetitles = ();
     my %cat_titles = ();
@@ -386,9 +385,7 @@ sub print_selection_form {
     my %idlist = ();
     my %idnums = ();
     my %idlist_titles = ();
-    my $caller = 'global';
     my $totcodes = 0;
-    my $format_reply;
     my $jscript = '';
     my %lt=&Apache::lonlocal::texthash(
                'buil' => 'Building valid e-mail address from username, if missing from preferences:',
@@ -399,10 +396,15 @@ sub print_selection_form {
     &Apache::lonhtmlcommon::add_breadcrumb
           ({text=>"Select Audience"});
 
-    $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$cdom,$totcodes);
-    if ($totcodes > 0) {
-        $format_reply = &Apache::lonnet::auto_instcode_format($caller,$cdom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
-        if ($format_reply eq 'ok') {
+    my $instcats = &Apache::lonnet::get_dom_instcats($cdom);
+    if (ref($instcats) eq 'HASH') {
+        if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
+            (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
+            %codes = %{$instcats->{'codes'}};
+            @codetitles = @{$instcats->{'codetitles'}};
+            %cat_titles = %{$instcats->{'cat_titles'}};
+            %cat_order = %{$instcats->{'cat_order'}};
+            $totcodes = scalar(keys(%codes));
             my $numtypes = @codetitles;
             &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
             my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
@@ -410,7 +412,7 @@ sub print_selection_form {
             my $allidlist = $idlist{$codetitles[0]};
             $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
             $jscript .= $scripttext;
-            $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
+            $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
         }
     }
     my @standardnames = &Apache::loncommon::get_standard_codeitems();
@@ -645,7 +647,7 @@ function goBack(target) {
         $output .= &Apache::loncommon::end_data_table();
         if (@unmatched) {
             $output .= '<br /><br />'.&mt('Could not determine e-mail addresses for the following users:').'<ul>';
-            foreach my $username (sort @unmatched) {
+            foreach my $username (sort(@unmatched)) {
                 $output .= '<li>'.$username.'</li>';
             }
             $output .= '</ul>';
@@ -705,7 +707,7 @@ ENDSCRIPT
 	    '<th>'.&mt('Status').'</th>'.
 	    '<th>'.&mt('Subject').'</th>'.
 	    '<th>'.&mt('Message').'</th>'.
-	    '<th>'.&mt('Recipents').'</th>'.
+	    '<th>'.&mt('Recipients').'</th>'.
 	    &Apache::loncommon::end_data_table_header_row();
 	$output .= &Apache::loncommon::start_data_table_row().
 	    '<td valign="middle">'.&mt('Sent').'</td>'.
@@ -720,7 +722,7 @@ ENDSCRIPT
 	    &Apache::loncommon::end_data_table_row().
 	    &Apache::loncommon::end_data_table();
     } else {
-        $output .= 'No mail sent - no recipients identified'; 
+        $output .= &mt('No mail sent - no recipients identified'); 
     }
     $output .= '<br /><a href="/adm/notify">'.&mt('Send another e-mail').'</a>'."\n";
     $output .= '<input type="hidden" name="command" />'."\n".
@@ -742,6 +744,7 @@ sub broadcast_email {
         $msg->to($to);
         $msg->subject($subject);
         $msg->add('From',"$from");
+        $msg->add('Content-type','text/plain; charset=UTF-8');
         if (my $fh = $msg->open()) {
             print $fh $message;
             $fh->close;