[LON-CAPA-cvs] cvs: loncom / lonsql /enrollment localenroll.pm /interface domainprefs.pm loncommon.pm lonconfigsettings.pm lonsupportreq.pm

raeburn raeburn at source.lon-capa.org
Fri Oct 13 16:37:47 EDT 2017


raeburn		Fri Oct 13 20:37:47 2017 EDT

  Modified files:              
    /loncom/interface	lonconfigsettings.pm domainprefs.pm 
                     	lonsupportreq.pm loncommon.pm 
    /loncom/enrollment	localenroll.pm 
    /loncom	lonsql 
  Log:
  - Domain configuration to override domain's helpdesk settings for e-mail
    recipients, and optionally added text, based on requester's affiliation	
    (e.g., faculty, staff or student).
  
  
-------------- next part --------------
Index: loncom/interface/lonconfigsettings.pm
diff -u loncom/interface/lonconfigsettings.pm:1.36 loncom/interface/lonconfigsettings.pm:1.37
--- loncom/interface/lonconfigsettings.pm:1.36	Thu Aug  3 16:22:09 2017
+++ loncom/interface/lonconfigsettings.pm	Fri Oct 13 20:37:34 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: lonconfigsettings.pm,v 1.36 2017/08/03 16:22:09 raeburn Exp $
+# $Id: lonconfigsettings.pm,v 1.37 2017/10/13 20:37:34 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -209,6 +209,11 @@
                     $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
                                                        "'cancreate_emaildomain','default');";
                 }
+            } 
+            if (grep(/^contacts$/, at actions)) {
+                my $customclass = 'LC_helpdesk_override';
+                my $optionsprefix = 'LC_options_helpdesk_';
+                $onload = "toggleHelpdeskRow(document.display,'overrides','$customclass','$optionsprefix');";
             }
             if ($onload) {
                 my %loaditems = (
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.314 loncom/interface/domainprefs.pm:1.315
--- loncom/interface/domainprefs.pm:1.314	Sat Oct  7 00:50:47 2017
+++ loncom/interface/domainprefs.pm	Fri Oct 13 20:37:34 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.314 2017/10/07 00:50:47 raeburn Exp $
+# $Id: domainprefs.pm,v 1.315 2017/10/13 20:37:34 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3124,7 +3124,54 @@
                           $to{$item}.'" /></td></tr>';
             $rownum ++;
         }
-    } else {
+    } elsif ($position eq 'bottom') {
+        $css_class = $rownum%2?' class="LC_odd_row"':'';
+        $datatable .= '<tr'.$css_class.'>'.
+                      '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
+                      &mt('(e-mail, subject, and description always shown)').
+                      '</td><td class="LC_left_item">';
+        if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
+            (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
+            $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
+            foreach my $field (@{$fields}) {
+                $datatable .= '<tr><td>'.$fieldtitles->{$field};
+                if (($field eq 'screenshot') || ($field eq 'cc')) {
+                    $datatable .= ' '.&mt('(logged-in users)');
+                }
+                $datatable .='</td><td>';
+                my $clickaction;
+                if ($field eq 'screenshot') {
+                    $clickaction = ' onclick="screenshotSize(this);"';
+                }
+                if (ref($possoptions->{$field}) eq 'ARRAY') {
+                    foreach my $option (@{$possoptions->{$field}}) {
+                        my $checked;
+                        if ($currfield{$field} eq $option) {
+                            $checked = ' checked="checked"';
+                        }
+                        $datatable .= '<span class="LC_nobreak"><label>'.
+                                      '<input type="radio" name="helpform_'.$field.'" '.
+                                      'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
+                                      '</label></span>'.(' 'x2);
+                    }
+                }
+                if ($field eq 'screenshot') {
+                    my $display;
+                    if ($currfield{$field} eq 'no') {
+                        $display = ' style="display:none"';
+                    }
+                    $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
+                                  '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
+                                  '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
+                }
+                $datatable .= '</td></tr>';
+            }
+            $datatable .= '</table>';
+        }
+        $datatable .= '</td></tr>'."\n";
+        $rownum ++;
+    }
+    unless ($position eq 'top') {
         foreach my $type (@mailings) {
             $css_class = $rownum%2?' class="LC_odd_row"':'';
             $datatable .= '<tr'.$css_class.'>'.
@@ -3184,56 +3231,138 @@
                                                    \%choices,$rownum);
         $datatable .= $reports;
     } elsif ($position eq 'bottom') {
-        $css_class = $rownum%2?' class="LC_odd_row"':'';
-        $datatable .= '<tr'.$css_class.'>'.
-                      '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
-                      &mt('(e-mail, subject, and description always shown)').
-                      '</td><td class="LC_left_item">';
-        if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
-            (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
-            $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
-            foreach my $field (@{$fields}) {
-                $datatable .= '<tr><td>'.$fieldtitles->{$field};
-                if (($field eq 'screenshot') || ($field eq 'cc')) {
-                    $datatable .= ' '.&mt('(logged-in users)');
-                }
-                $datatable .='</td><td>';
-                my $clickaction;
-                if ($field eq 'screenshot') {
-                    $clickaction = ' onclick="screenshotSize(this);"';
-                }
-                if (ref($possoptions->{$field}) eq 'ARRAY') {
-                    foreach my $option (@{$possoptions->{$field}}) {
-                        my $checked;
-                        if ($currfield{$field} eq $option) {
-                            $checked = ' checked="checked"';
+        my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+        my (@posstypes,%usertypeshash);
+        if (ref($types) eq 'ARRAY') {
+            @posstypes = @{$types};
+        }
+        if (@posstypes) {
+            if (ref($usertypes) eq 'HASH') {
+                %usertypeshash = %{$usertypes};
+            }
+            my @overridden;
+            my $numinrow = 4;
+            if (ref($settings) eq 'HASH') {
+                if (ref($settings->{'overrides'}) eq 'HASH') {
+                    foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
+                        if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
+                            push(@overridden,$key);
+                            foreach my $item (@contacts) {
+                                if ($settings->{'overrides'}{$key}{$item}) {
+                                    $checked{'override_'.$key}{$item} = ' checked="checked" ';
+                                }
+                            }
+                            $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
+                            $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
+                            $includeloc{'override_'.$key} = '';
+                            $includestr{'override_'.$key} = '';
+                            if ($settings->{'overrides'}{$key}{'include'} ne '') {
+                                ($includeloc{'override_'.$key},$includestr{'override_'.$key}) = 
+                                    split(/:/,$settings->{'overrides'}{$key}{'include'},2);
+                                $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
+                            }
                         }
-                        $datatable .= '<span class="LC_nobreak"><label>'.
-                                      '<input type="radio" name="helpform_'.$field.'" '.
-                                      'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
-                                      '</label></span>'.(' 'x2);
                     }
                 }
-                if ($field eq 'screenshot') {
-                    my $display;
-                    if ($currfield{$field} eq 'no') {
-                        $display = ' style="display:none"';
-                    }
-                    $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
-                                  '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
-                                  '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
+            }
+            my $customclass = 'LC_helpdesk_override';
+            my $optionsprefix = 'LC_options_helpdesk_';
+
+            my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
+ 
+            $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
+                                         $numinrow,$othertitle,'overrides',
+                                         \$rownum,$onclicktypes,$customclass);
+            $rownum ++;
+            $usertypeshash{'default'} = $othertitle;
+            foreach my $status (@posstypes) {
+                my $css_class;
+                if ($rownum%2) {
+                    $css_class = 'LC_odd_row ';
+                }
+                $css_class .= $customclass;
+                my $rowid = $optionsprefix.$status;
+                my $hidden = 1;
+                my $currstyle = 'display:none';
+                if (grep(/^\Q$status\E$/, at overridden)) {
+                    $currstyle = 'display:table-row';
+                    $hidden = 0;
+                }
+                my $key = 'override_'.$status;
+                $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
+                                                  $includeloc{$key},$includestr{$key},$status,$rowid,
+                                                  $usertypeshash{$status},$css_class,$currstyle,
+                                                  \@contacts,$short_titles);
+                unless ($hidden) {
+                    $rownum ++;
                 }
-                $datatable .= '</td></tr>';
             }
-            $datatable .= '</table>';
         }
-        $datatable .= '</td></tr>'."\n";
-        $rownum ++;
     }
     $$rowtotal += $rownum;
     return $datatable;
 }
 
+sub overridden_helpdesk {
+    my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
+        $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
+    my $class = 'LC_left_item';
+    if ($css_class) {
+        $css_class = ' class="'.$css_class.'"';
+    }
+    if ($rowid) {
+        $rowid = ' id="'.$rowid.'"';
+    }
+    if ($rowstyle) {
+        $rowstyle = ' style="'.$rowstyle.'"';
+    }
+    my ($output,$description);
+    $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
+    $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
+              "<td>$description</td>\n".
+              '<td class="'.$class.'" colspan="2">'.
+              '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
+              '<span class="LC_nobreak">';
+    if (ref($contacts) eq 'ARRAY') {
+        foreach my $item (@{$contacts}) {
+            my $check;
+            if (ref($checked) eq 'HASH') {
+               $check = $checked->{$item};
+            }
+            my $title;
+            if (ref($short_titles) eq 'HASH') {
+                $title = $short_titles->{$item}; 
+            }
+            $output .= '<label>'.
+                       '<input type="checkbox" name="override_'.$type.'"'.$check.
+                       ' value="'.$item.'" />'.$title.'</label> ';
+        }
+    }
+    $output .= '</span><br />'.&mt('Others').':  '.
+               '<input type="text" name="override_'.$type.'_others" '.
+               'value="'.$otheremails.'"  />';
+    my %locchecked;
+    foreach my $loc ('s','b') {
+        if ($includeloc eq $loc) {
+            $locchecked{$loc} = ' checked="checked"';
+            last;
+        }
+    }
+    $output .= '<br />'.&mt('Bcc:').(' 'x6).
+               '<input type="text" name="override_'.$type.'_bcc" '.
+               'value="'.$bccemails.'"  /></fieldset>'.
+               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
+               &mt('Text automatically added to e-mail:').' '.
+               '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
+               '<span class="LC_nobreak">'.&mt('Location:').' '.
+               '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
+               (' 'x2).
+               '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
+               '</span></fieldset>'.
+               '</td></tr>'."\n";
+    return $output;
+}
+
 sub contacts_javascript {
     return <<"ENDSCRIPT";
 
@@ -3251,6 +3380,37 @@
     return;
 }
 
+function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
+    if (form.elements[checkbox].length != undefined) {
+        var count = 0;
+        if (docount) {
+            for (var i=0; i<form.elements[checkbox].length; i++) {
+                if (form.elements[checkbox][i].checked) {
+                    count ++;
+                }
+            }
+        }
+        for (var i=0; i<form.elements[checkbox].length; i++) {
+            var type = form.elements[checkbox][i].value;
+            if (document.getElementById(prefix+type)) {
+                if (form.elements[checkbox][i].checked) {
+                    document.getElementById(prefix+type).style.display = 'table-row';
+                    if (count % 2 == 1) {
+                        document.getElementById(prefix+type).className = target+' LC_odd_row';
+                    } else {
+                        document.getElementById(prefix+type).className = target;
+                    }
+                    count ++;
+                } else {
+                    document.getElementById(prefix+type).style.display = 'none';
+                }
+            }
+        }
+    }
+    return;
+}
+
+
 // ]]>
 </script>
 
@@ -5570,8 +5730,8 @@
                    'adminemail'      => 'Default Server Admin E-mail address',
                    'errormail'       => 'Error reports to be e-mailed to',
                    'packagesmail'    => 'Package update alerts to be e-mailed to',
-                   'helpdeskmail'    => "Helpdesk requests for this domain's users",
-                   'otherdomsmail'   => 'Helpdesk requests for other (unconfigured) domains',
+                   'helpdeskmail'    => "Helpdesk requests from all users in this domain",
+                   'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                    'requestsmail'    => 'E-mail from course requests requiring approval',
                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
@@ -7776,6 +7936,7 @@
                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
                       lockablenames => 'User preference to lock name',
                       selfassign    => 'Self-reportable affiliations',
+                      overrides     => "Override domain's helpdesk settings based on requester's affiliation",
              );
     my $showdom;
     if ($context eq 'cansearch') {
@@ -7822,6 +7983,10 @@
                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                             $check = ' checked="checked" ';
                         }
+                    } elsif (ref($settings->{$context}) eq 'HASH') {
+                        if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
+                            $check = ' checked="checked" ';
+                        }
                     } elsif ($context eq 'statustocreate') {
                         $check = ' checked="checked" ';
                     }
@@ -7836,29 +8001,38 @@
         $rem = @{$types}%($numinrow);
     }
     my $colsleft = $numinrow - $rem;
-    if (($rem == 0) && (@{$types} > 0)) {
-        $output .= '<tr>';
-    }
-    if ($colsleft > 1) {
-        $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
+    if ($context eq 'overrides') {
+        if ($colsleft > 1) {
+            $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
+        } else {
+            $output .= '<td class="LC_left_item">';
+        }
+        $output .= ' ';  
     } else {
-        $output .= '<td class="LC_left_item">';
-    }
-    my $defcheck = ' ';
-    if (ref($settings) eq 'HASH') {  
-        if (ref($settings->{$context}) eq 'ARRAY') {
-            if (grep(/^default$/,@{$settings->{$context}})) {
+        if (($rem == 0) && (@{$types} > 0)) {
+            $output .= '<tr>';
+        }
+        if ($colsleft > 1) {
+            $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
+        } else {
+            $output .= '<td class="LC_left_item">';
+        }
+        my $defcheck = ' ';
+        if (ref($settings) eq 'HASH') {  
+            if (ref($settings->{$context}) eq 'ARRAY') {
+                if (grep(/^default$/,@{$settings->{$context}})) {
+                    $defcheck = ' checked="checked" ';
+                }
+            } elsif ($context eq 'statustocreate') {
                 $defcheck = ' checked="checked" ';
             }
-        } elsif ($context eq 'statustocreate') {
-            $defcheck = ' checked="checked" ';
         }
+        $output .= '<span class="LC_nobreak"><label>'.
+                   '<input type="checkbox" name="'.$context.'" '.
+                   'value="default"'.$defcheck.$onclick.' />'.
+                   $othertitle.'</label></span>';
     }
-    $output .= '<span class="LC_nobreak"><label>'.
-               '<input type="checkbox" name="'.$context.'" '.
-               'value="default"'.$defcheck.$onclick.' />'.
-               $othertitle.'</label></span></td>'.
-               '</tr></table></td></tr>';
+    $output .= '</td></tr></table></td></tr>';
     return $output;
 }
 
@@ -11074,17 +11248,57 @@
                 my $value = $env{'form.helpform_'.$field};
                 $value =~ s/^\s+|\s+$//g;
                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
-                    $contacts_hash{contacts}{'helpform'}{$field} = $value;
+                    $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
                     if ($field eq 'screenshot') {
                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
-                            $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
+                            $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
                         }
                     }
                 }
             }
         }
     }
+    my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
+    my (@statuses,%usertypeshash, at overrides);
+    if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
+        @statuses = @{$types};
+        if (ref($usertypes) eq 'HASH') {
+            %usertypeshash = %{$usertypes};
+        }
+    }
+    if (@statuses) {
+        my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
+        foreach my $type (@possoverrides) {
+            if (($type ne '') && (grep(/^\Q$type\E$/, at statuses))) {
+                push(@overrides,$type);
+            }
+        }
+        if (@overrides) {
+            foreach my $type (@overrides) {
+                my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
+                foreach my $item (@contacts) {
+                    if (grep(/^\Q$item\E$/, at standard)) {
+                        $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
+                        $newsetting{'override_'.$type}{$item} = 1;
+                    } else {
+                        $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
+                        $newsetting{'override_'.$type}{$item} = 0;
+                    }
+                }
+                $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
+                $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
+                $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
+                $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
+                if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
+                    $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
+                    $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
+                    $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
+                    $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
+                }
+            }     
+        }
+    }
     if (keys(%currsetting) > 0) {
         foreach my $item (@contacts) {
             if ($to{$item} ne $currsetting{$item}) {
@@ -11139,6 +11353,33 @@
                 }
             }
         }
+        if (@statuses) {
+            if (ref($currsetting{'overrides'}) eq 'HASH') { 
+                foreach my $key (keys(%{$currsetting{'overrides'}})) {
+                    if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
+                        if (ref($newsetting{'override_'.$key}) eq 'HASH') {
+                            foreach my $item (@contacts,'bcc','others','include') {
+                                if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) { 
+                                    push(@{$changes{'overrides'}},$key);
+                                    last;
+                                }
+                            }
+                        } else {
+                            push(@{$changes{'overrides'}},$key);
+                        }
+                    }
+                }
+                foreach my $key (@overrides) {
+                    unless (exists($currsetting{'overrides'}{$key})) {
+                        push(@{$changes{'overrides'}},$key);
+                    }
+                }
+            } else {
+                foreach my $key (@overrides) {
+                    push(@{$changes{'overrides'}},$key); 
+                }
+            }
+        }
     } else {
         my %default;
         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
@@ -11253,6 +11494,60 @@
                     $resulttext .= '</li>';
                 }
             }
+            if (ref($changes{'overrides'}) eq 'ARRAY') {
+                my @deletions;
+                foreach my $type (@{$changes{'overrides'}}) {
+                    if ($usertypeshash{$type}) {
+                        if (grep(/^\Q$type\E/, at overrides)) {
+                            $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
+                                                      $usertypeshash{$type}).'<ul><li>';
+                            if (ref($newsetting{'override_'.$type}) eq 'HASH') {
+                                my @text;
+                                foreach my $item (@contacts) {
+                                    if ($newsetting{'override_'.$type}{$item}) { 
+                                        push(@text,$short_titles->{$item});
+                                    }
+                                }
+                                if ($newsetting{'override_'.$type}{'others'} ne '') {
+                                    push(@text,$newsetting{'override_'.$type}{'others'});
+                                }
+  
+                                if (@text) {
+                                    $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
+                                                       '<span class="LC_cusr_emph">'.join(', ', at text).'</span>');
+                                }
+                                if ($newsetting{'override_'.$type}{'bcc'} ne '') {
+                                    my $bcctext;
+                                    if (@text) {
+                                        $bcctext = ' '.&mt('with Bcc to');
+                                    } else {
+                                        $bcctext = '(Bcc)';
+                                    }
+                                    $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
+                                } elsif (!@text) {
+                                     $resulttext .= &mt('Helpdesk e-mail sent to no one');
+                                }
+                                $resulttext .= '</li>';
+                                if ($newsetting{'override_'.$type}{'include'} ne '') {
+                                    my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
+                                    if ($loc eq 'b') {
+                                        $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
+                                    } elsif ($loc eq 's') {
+                                        $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
+                                    }
+                                }
+                            }
+                            $resulttext .= '</li></ul></li>';
+                        } else {
+                            push(@deletions,$usertypeshash{$type});
+                        }
+                    }
+                }
+                if (@deletions) {
+                    $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
+                                              join(', ', at deletions)).'</li>';
+                }
+            }
             my @offon = ('off','on');
             if ($changes{'reporterrors'}) {
                 $resulttext .= '<li>'.
@@ -11308,7 +11603,6 @@
                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                                    '</li>';
-
                 }
             }
             $resulttext .= '</ul>';
Index: loncom/interface/lonsupportreq.pm
diff -u loncom/interface/lonsupportreq.pm:1.92 loncom/interface/lonsupportreq.pm:1.93
--- loncom/interface/lonsupportreq.pm:1.92	Fri Oct 13 19:59:11 2017
+++ loncom/interface/lonsupportreq.pm	Fri Oct 13 20:37:35 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Helpdesk request form
 #
-# $Id: lonsupportreq.pm,v 1.92 2017/10/13 19:59:11 raeburn Exp $
+# $Id: lonsupportreq.pm,v 1.93 2017/10/13 20:37:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -667,9 +667,6 @@
     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
     my $defdom = &get_domain();
-    my ($to,$bcc,$addtext) =
-        &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
-                                                 $defdom,$origmail);
     my $from = $admin;
     my %helpform;
     my %domconfig =
@@ -883,6 +880,33 @@
             }
         }
     }
+
+    my ($requname,$requdom,$reqemail);
+    foreach my $field ('uname','udom','email') {
+        $env{'form.'.$field} =~ s/^\s+//;
+        $env{'form.'.$field} =~ s/\s+$//;
+    }
+    if ($env{'form.uname'} =~ /^$match_username$/) {
+        $requdom = $env{'form.udom'};
+    }
+    if ($env{'form.udom'} =~ /^$match_domain$/) {
+        $requdom = $env{'form.udom'};
+    }
+    if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
+        $reqemail = $env{'form.email'};
+    }
+
+    my $dom_in_effect;
+    unless ($env{'user.domain'} eq 'public') {
+        $dom_in_effect = $env{'user.domain'};
+    }
+    if ($dom_in_effect eq '') {
+        $dom_in_effect = $requdom;
+    }
+    if ($dom_in_effect eq '') {
+        $dom_in_effect = $defdom;
+    }
+
     $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
                    $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
 
@@ -905,6 +929,11 @@
         &print_header($r,$url,'process');
     }
     my $bad_email = 0;
+    my ($to,$bcc,$addtext) =
+        &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
+                                                 $dom_in_effect,$origmail,
+                                                 $requname,$requdom,
+                                                 $reqemail);
     if ($to =~ /,/) {
         my @ok_email; 
         foreach my $email (split(/,/,$to)) {
@@ -942,12 +971,8 @@
     }
     $r->print(&Apache::loncommon::confirmwrapper($message));
 
-    if (defined($env{'form.email'})) {
-        $env{'form.email'} =~ s/^\s+//;
-        $env{'form.email'} =~ s/\s+$//;
-        if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
-            $from = $env{'form.email'};
-        }
+    if ($reqemail ne '') {
+        $from = $reqemail;
     }
 
     if (defined($env{'form.cc'})) {
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1296 loncom/interface/loncommon.pm:1.1297
--- loncom/interface/loncommon.pm:1.1296	Fri Sep 29 01:43:06 2017
+++ loncom/interface/loncommon.pm	Fri Oct 13 20:37:35 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1296 2017/09/29 01:43:06 raeburn Exp $
+# $Id: loncommon.pm,v 1.1297 2017/10/13 20:37:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -14632,7 +14632,14 @@
 defdom (domain for which to retrieve configuration settings),
 
 origmail (scalar - email address of recipient from loncapa.conf, 
-i.e., predates configuration by DC via domainprefs.pm 
+i.e., predates configuration by DC via domainprefs.pm
+
+$requname username of requester (if mailing type is helpdeskmail)
+
+$requdom domain of requester (if mailing type is helpdeskmail)
+
+$reqemail e-mail address of requester (if mailing type is helpdeskmail)
+
 
 Returns: comma separated list of addresses to which to send e-mail.
 
@@ -14643,7 +14650,7 @@
 ############################################################
 ############################################################
 sub build_recipient_list {
-    my ($defmail,$mailing,$defdom,$origmail) = @_;
+    my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
     my @recipients;
     my ($otheremails,$lastresort,$allbcc,$addtext);
     my %domconfig =
@@ -14684,11 +14691,98 @@
         } elsif ($origmail ne '') {
             $lastresort = $origmail;
         }
+        if ($mailing eq 'helpdeskmail') {
+            if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
+                (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
+                my ($inststatus,$inststatus_checked);
+                if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
+                    ($env{'user.domain'} ne 'public')) {
+                    $inststatus_checked = 1;
+                    $inststatus = $env{'environment.inststatus'};
+                }
+                unless ($inststatus_checked) {
+                    if (($requname ne '') && ($requdom ne '')) {
+                        if (($requname =~ /^$match_username$/) &&
+                            ($requdom =~ /^$match_domain$/) &&
+                            (&Apache::lonnet::domain($requdom))) {
+                            my $requhome = &Apache::lonnet::homeserver($requname,
+                                                                      $requdom);
+                            unless ($requhome eq 'no_host') {
+                                my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
+                                $inststatus = $userenv{'inststatus'};
+                                $inststatus_checked = 1;
+                            }
+                        }
+                    }
+                }
+                unless ($inststatus_checked) {
+                    if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
+                        my %srch = (srchby     => 'email',
+                                    srchdomain => $defdom,
+                                    srchterm   => $reqemail,
+                                    srchtype   => 'exact');
+                        my %srch_results = &Apache::lonnet::usersearch(\%srch);
+                        foreach my $uname (keys(%srch_results)) {
+                            if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
+                                $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
+                                $inststatus_checked = 1;
+                                last;
+                            }
+                        }
+                        unless ($inststatus_checked) {
+                            my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
+                            if ($dirsrchres eq 'ok') {
+                                foreach my $uname (keys(%srch_results)) {
+                                    if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
+                                        $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
+                                        $inststatus_checked = 1;
+                                        last;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+                if ($inststatus ne '') {
+                    foreach my $status (split(/\:/,$inststatus)) {
+                        if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
+                            my @contacts = ('adminemail','supportemail');
+                            foreach my $item (@contacts) {
+                                if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
+                                    my $addr = $domconfig{'contacts'}{'overrides'}{$status};
+                                    if (!grep(/^\Q$addr\E$/, at recipients)) {
+                                        push(@recipients,$addr);
+                                    }
+                                }
+                            }
+                            $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
+                            if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
+                                my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
+                                my @ok_bccs;
+                                foreach my $bcc (@bccs) {
+                                    $bcc =~ s/^\s+//g;
+                                    $bcc =~ s/\s+$//g;
+                                    if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
+                                        if (!(grep(/^\Q$bcc\E$/, at ok_bccs))) {
+                                            push(@ok_bccs,$bcc);
+                                        }
+                                    }
+                                }
+                                if (@ok_bccs > 0) {
+                                    $allbcc = join(', ', at ok_bccs);
+                                }
+                            }
+                            $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
+                            last;
+                        }
+                    }
+                }
+            }
+        }
     } elsif ($origmail ne '') {
         $lastresort = $origmail;
     }
-
-    if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
+    if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
         unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
             my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
             my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
Index: loncom/enrollment/localenroll.pm
diff -u loncom/enrollment/localenroll.pm:1.56 loncom/enrollment/localenroll.pm:1.57
--- loncom/enrollment/localenroll.pm:1.56	Thu Aug 25 18:01:34 2016
+++ loncom/enrollment/localenroll.pm	Fri Oct 13 20:37:40 2017
@@ -1,6 +1,6 @@
 # functions to glue school database system into Lon-CAPA for 
 # automated enrollment
-# $Id: localenroll.pm,v 1.56 2016/08/25 18:01:34 raeburn Exp $
+# $Id: localenroll.pm,v 1.57 2017/10/13 20:37:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -955,8 +955,8 @@
               institutional types to check.
  (g) $srchby - optional if $uname or $id defined, otherwise required.
                Allowed values include: 1. lastfirst, 2. last, 3. uname
-               corresponding to searches by 1. lastname,firstname;
-               2. lastname; 3. username
+               4. email, corresponding to searches by 1. lastname,firstname;
+               2. lastname; 3. username; 4. e-mail address
  (h) $srchterm - optional if $uname or $id defined, otherwise required
                 String to search for.
  (i) $srchtype - optional. Allowed values: contains, begins (defaults
Index: loncom/lonsql
diff -u loncom/lonsql:1.95 loncom/lonsql:1.96
--- loncom/lonsql:1.95	Sun Aug  9 21:43:11 2015
+++ loncom/lonsql	Fri Oct 13 20:37:46 2017
@@ -3,7 +3,7 @@
 # The LearningOnline Network
 # lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
 #
-# $Id: lonsql,v 1.95 2015/08/09 21:43:11 raeburn Exp $
+# $Id: lonsql,v 1.96 2017/10/13 20:37:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -490,6 +490,7 @@
                 $userdata{'domain'} = $udom;
                 $result = &allusers_table_update($query,$uname,$udom,\%userdata);
             } else {
+                # Sanity checking of $query needed.
                 # Do an sql query
                 $result = &do_sql_query($query,$arg1,$arg2,$arg3,$searchdomain);
             }
@@ -541,13 +542,20 @@
         my %srchfield = (
                           uname    => 'username',
                           lastname => 'lastname',
+                          email    => 'permanentemail',
                         );
-        if ($srchtype eq 'exact') {
-            $query .= $srchfield{$srchby}.' = '.$dbh->quote($srchterm);
-        } elsif ($srchtype eq 'begins') {
-             $query .= $srchfield{$srchby}.' LIKE '.$dbh->quote($srchterm.'%');
+        if (exists($srchfield{$srchby})) {
+            if ($srchtype eq 'exact') {
+                $query .= $srchfield{$srchby}.' = '.$dbh->quote($srchterm);
+            } elsif ($srchtype eq 'begins') {
+                $query .= $srchfield{$srchby}.' LIKE '.$dbh->quote($srchterm.'%');
+            } else {
+                $query .= $srchfield{$srchby}.' LIKE '.$dbh->quote('%'.$srchterm.'%');
+            }
         } else {
-             $query .= $srchfield{$srchby}.' LIKE '.$dbh->quote('%'.$srchterm.'%');
+            &logthis('<font color="blue">'.
+                     'WARNING: Invalid srchby: '.$srchby.'</font>');  
+            return $result;
         }
     }
     $query .= ") ORDER BY username ";


More information about the LON-CAPA-cvs mailing list