[LON-CAPA-cvs] cvs: loncom /interface courseclassifier.pm domainprefs.pm loncommon.pm lonsupportreq.pm

raeburn raeburn at source.lon-capa.org
Wed Jan 18 16:24:41 EST 2017


raeburn		Wed Jan 18 21:24:41 2017 EDT

  Modified files:              
    /loncom/interface	courseclassifier.pm domainprefs.pm loncommon.pm 
                     	lonsupportreq.pm 
  Log:
  - Helpdesk web form
    - Domain configuration to specify which form fields besides E-mail address,
      Subject, and Description should be shown (some can be required fields).
    - Domain configuration to send submitted form to specified e-mail address(es)
      for user from other domains -- if no recipient set in user's domain for help).
    - Domain configuration to automatically include a specified string in the e-mail
      sent -- either prepended to the subject, or to the body.
    - If form is visited by a logged-in user with a role selected in an official 
      course, the user can change the course code in the linked select boxes, 
      in order to ask about a different course.
  
  
-------------- next part --------------
Index: loncom/interface/courseclassifier.pm
diff -u loncom/interface/courseclassifier.pm:1.25 loncom/interface/courseclassifier.pm:1.26
--- loncom/interface/courseclassifier.pm:1.25	Wed Jan 18 21:07:31 2017
+++ loncom/interface/courseclassifier.pm	Wed Jan 18 21:24:39 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utilities for classifying courses based on institutional code
 #
-# $Id: courseclassifier.pm,v 1.25 2017/01/18 21:07:31 raeburn Exp $
+# $Id: courseclassifier.pm,v 1.26 2017/01/18 21:24:39 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -260,7 +260,7 @@
 }
 
 sub javascript_code_selections {
-    my ($formname,$codetitlesref) = @_;
+    my ($formname,$codetitlesref,$knowncodes,$sectionlist) = @_;
     return unless (ref($codetitlesref) eq 'ARRAY');
     my @codetitles = @{$codetitlesref};
     my $numtitles = @codetitles;
@@ -357,15 +357,92 @@
    document.$formname.Number.selectedIndex = 0
  }
 }
+END_OF_BLOCK
+
+    if ((ref($knowncodes) eq 'HASH') && (keys(%{$knowncodes}) > 0)) {
+        my @standardnames = &Apache::loncommon::get_standard_codeitems();
+        my (%local_to_standard,$currstr);
+        for (my $i=0; $i<@codetitles; $i++) {
+            $local_to_standard{$codetitles[$i]} = $standardnames[$i];
+        }
+        $output .= <<"ENDJS";
+
+function initialize_codes() {
+ENDJS
+        for (my $i=0; $i<@codetitles-1; $i++) {
+            my $item = $local_to_standard{$codetitles[$i]};
+            $currstr .= $knowncodes->{$codetitles[$i]};
+            if ($knowncodes->{$codetitles[$i]} != -1) {
+                $output .= '
+    for (var j=0; j<document.'.$formname.'.'.$item.'.length; j++) {
+        if (document.'.$formname.'.'.$item.'[j].value == "'.$knowncodes->{$codetitles[$i]}.'") {
+            document.'.$formname.'.'.$item.'.selectedIndex = j;
+        }
+    }
+';
+            }
+            $output .= '   courseSet('."'$codetitles[$i]'".')'."\n";
+        }
+        my $lastcodetitle =  $local_to_standard{$codetitles[-1]};
+        $currstr .= $knowncodes->{$codetitles[-1]};
+        if ($knowncodes->{$codetitles[-1]} != -1) {
+            $output .= '
+    for (var j=0; j<document.'.$formname.'.'.$lastcodetitle.'.length; j++) {
+        if (document.'.$formname.'.'.$lastcodetitle.'[j].value == "'.$knowncodes->{$codetitles[-1]}.'") {
+            document.'.$formname.'.'.$lastcodetitle.'.selectedIndex = j;
+        }
+    }
+';
+        }
+        $output .= "    return;\n}\n";
+        if ($sectionlist) {
+            $output .= '
+function toggleSecVis() {
+    var currcode = "";
+    var crscode = '."'$currstr'".';
+';
+            for (my $i=0; $i<@codetitles-1; $i++) {
+                my $item = $local_to_standard{$codetitles[$i]};
+                $output .= 'currcode += document.'.$formname.'.'.$item.'.options[document.'.$formname.'.'.$item.'.selectedIndex].value;'."\n";
+            }
+            my $lastcodetitle =  $local_to_standard{$codetitles[-1]};
+            if ($lastcodetitle ne '') {
+                if ($knowncodes->{$codetitles[-1]} != -1) {
+                    $output .= 'currcode += document.'.$formname.'.'.$lastcodetitle.'.options[document.'.$formname.'.'.$lastcodetitle.'.selectedIndex].value;'."\n";
+                }
+            }
+            $output .= <<"ENDSEC";
+    var showlist = 'none';
+    var showbox = 'inline';
+    if ((crscode != '') && (currcode == crscode)) {
+        showlist = 'inline';
+        showbox = 'none';
+    }
+    alert("crscode is ||"+crscode+"|| and currcode is ||"+currcode+"|| and showlist is ||"+showlist+"|| and showbox is ||"+showbox+"||");
+    if (document.getElementById('LC_helpdesk_sectionlist')) {
+        document.getElementById('LC_helpdesk_sectionlist').style.display = showlist;
+    }
+    if (document.getElementById('LC_helpdesk_section')) {
+        document.getElementById('LC_helpdesk_section').style.display = showbox;
+    }
+    return;
+}
+
+ENDSEC
+
+        }
+    } else {
+        $output .= <<"END_OF_JS";
 
 function initialize_codes() {
     courseSet();
     return;
 }
-END_OF_BLOCK
+END_OF_JS
+    }
+    return $output;
 }
 
-
 sub javascript_definitions {
     my ($codetitles,$idlist,$idlist_titles,$idnums,$cat_titles) = @_;
     my $numtitles = @{$codetitles};
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.285 loncom/interface/domainprefs.pm:1.286
--- loncom/interface/domainprefs.pm:1.285	Mon Jan  2 19:44:06 2017
+++ loncom/interface/domainprefs.pm	Wed Jan 18 21:24:39 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.285 2017/01/02 19:44:06 raeburn Exp $
+# $Id: domainprefs.pm,v 1.286 2017/01/18 21:24:39 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -19,7 +19,8 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with LON-CAPA; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
 # /home/httpd/html/adm/gpl.txt
 #
 # http://www.lon-capa.org/
@@ -317,10 +318,14 @@
                     modify => \&modify_directorysrch,
                   },
         'contacts' =>
-                  { text => 'Contact Information',
+                  { text => 'E-mail addresses and helpform',
                     help => 'Domain_Configuration_Contact_Info',
-                    header => [{col1 => 'Setting',
-                                col2 => 'Value',}],
+                    header => [{col1 => 'Default e-mail addresses',
+                                col2 => 'Value',},
+                               {col1 => 'Recipient(s) for notifications',
+                                col2 => 'Value',},
+                               {col1 => 'Ask helpdesk form settings',
+                                col2 => 'Value',},],
                     print => \&print_contacts,
                     modify => \&modify_contacts,
                   },
@@ -576,6 +581,9 @@
 $coursebrowserjs
 END
         }
+        if (grep(/^contacts$/, at actions)) {
+            $js .= &contacts_javascript();
+        }
         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
     } else {
 # check if domconfig user exists for the domain.
@@ -766,7 +774,8 @@
         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
-            ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings')) {
+            ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
+            ($action eq 'contacts')) {
             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'coursecategories') {
             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
@@ -797,7 +806,7 @@
         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
             ($action eq 'usersessions') || ($action eq 'coursecategories') || 
-            ($action eq 'ssl') || ($action eq 'trust')) {
+            ($action eq 'ssl') || ($action eq 'trust') || ($action eq 'contacts')) {
             if ($action eq 'coursecategories') {
                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                 $colspan = ' colspan="2"';
@@ -1013,8 +1022,8 @@
         if ($action eq 'quotas') {
             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
-                 ($action eq 'contacts') || ($action eq 'serverstatuses') || 
-                 ($action eq 'loadbalancing') || ($action eq 'ltitools')) {
+                 ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
+                 ($action eq 'ltitools')) {
             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
         } elsif ($action eq 'scantron') {
             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
@@ -2944,104 +2953,252 @@
 }
 
 sub print_contacts {
-    my ($dom,$settings,$rowtotal) = @_;
+    my ($position,$dom,$settings,$rowtotal) = @_;
     my $datatable;
     my @contacts = ('adminemail','supportemail');
-    my (%checked,%to,%otheremails,%bccemails);
-    my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
-                    'requestsmail','updatesmail','idconflictsmail');
+    my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
+        $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions, at mailings);
     foreach my $type (@mailings) {
         $otheremails{$type} = '';
     }
-    $bccemails{'helpdeskmail'} = '';
-    if (ref($settings) eq 'HASH') {
-        foreach my $item (@contacts) {
-            if (exists($settings->{$item})) {
-                $to{$item} = $settings->{$item};
+    if ($position eq 'top') {
+        if (ref($settings) eq 'HASH') {
+            foreach my $item (@contacts) {
+                if (exists($settings->{$item})) {
+                    $to{$item} = $settings->{$item};
+                }
             }
         }
-        foreach my $type (@mailings) {
-            if (exists($settings->{$type})) {
-                if (ref($settings->{$type}) eq 'HASH') {
-                    foreach my $item (@contacts) {
-                        if ($settings->{$type}{$item}) {
-                            $checked{$type}{$item} = ' checked="checked" ';
+    } elsif ($position eq 'middle') {
+        @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
+                     'updatesmail','idconflictsmail');
+    } else {
+        @mailings = ('helpdeskmail','otherdomsmail');
+        $bccemails{'helpdeskmail'} = '';
+        $bccemails{'otherdomsmail'} = '';
+        $includestr{'helpdeskmail'} = '';
+        $includestr{'otherdomsmail'} = '';
+        ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
+    }
+    if (ref($settings) eq 'HASH') {
+        unless ($position eq 'top') {
+            foreach my $type (@mailings) {
+                if (exists($settings->{$type})) {
+                    if (ref($settings->{$type}) eq 'HASH') {
+                        foreach my $item (@contacts) {
+                            if ($settings->{$type}{$item}) {
+                                $checked{$type}{$item} = ' checked="checked" ';
+                            }
+                        }
+                        $otheremails{$type} = $settings->{$type}{'others'};
+                        if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
+                            $bccemails{$type} = $settings->{$type}{'bcc'};
+                            if ($settings->{$type}{'include'} ne '') {
+                                ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
+                                $includestr{$type} = &unescape($includestr{$type});
+                            }
                         }
                     }
-                    $otheremails{$type} = $settings->{$type}{'others'};
-                    if ($type eq 'helpdeskmail') {
-                        $bccemails{$type} = $settings->{$type}{'bcc'};
+                } elsif ($type eq 'lonstatusmail') {
+                    $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
+                }
+            }
+        }
+        if ($position eq 'bottom') {
+            foreach my $type (@mailings) {
+                $bccemails{$type} = $settings->{$type}{'bcc'};
+                if ($settings->{$type}{'include'} ne '') {
+                    ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
+                    $includestr{$type} = &unescape($includestr{$type});
+                }
+            }
+            if (ref($settings->{'helpform'}) eq 'HASH') {
+                if (ref($fields) eq 'ARRAY') {
+                    foreach my $field (@{$fields}) {
+                        $currfield{$field} = $settings->{'helpform'}{$field};
                     }
                 }
-            } elsif ($type eq 'lonstatusmail') {
-                $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
+                if (exists($settings->{'helpform'}{'maxsize'})) {
+                    $maxsize = $settings->{'helpform'}{'maxsize'};
+                } else {
+                    $maxsize = '1.0'; 
+                }
+            } else {
+                if (ref($fields) eq 'ARRAY') {
+                    foreach my $field (@{$fields}) {
+                        $currfield{$field} = 'yes';
+                    }
+                }
+                $maxsize = '1.0';
             }
         }
     } else {
-        $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
-        $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
-        $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
-        $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
-        $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
-        $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
-        $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
-        $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
-        $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
+        if ($position eq 'top') {
+            $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
+            $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
+            $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
+            $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
+            $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
+            $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
+            $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
+            $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
+        } elsif ($position eq 'bottom') {
+            $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
+            $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
+            if (ref($fields) eq 'ARRAY') {
+                foreach my $field (@{$fields}) {
+                    $currfield{$field} = 'yes';
+                }
+            }
+            $maxsize = '1.0';
+        }
     }
     my ($titles,$short_titles) = &contact_titles();
     my $rownum = 0;
     my $css_class;
-    foreach my $item (@contacts) {
-        $css_class = $rownum%2?' class="LC_odd_row"':'';
-        $datatable .= '<tr'.$css_class.'>'. 
-                  '<td><span class="LC_nobreak">'.$titles->{$item}.
-                  '</span></td><td class="LC_right_item">'.
-                  '<input type="text" name="'.$item.'" value="'.
-                  $to{$item}.'" /></td></tr>';
-        $rownum ++;
+    if ($position eq 'top') {
+        foreach my $item (@contacts) {
+            $css_class = $rownum%2?' class="LC_odd_row"':'';
+            $datatable .= '<tr'.$css_class.'>'. 
+                          '<td><span class="LC_nobreak">'.$titles->{$item}.
+                          '</span></td><td class="LC_right_item">'.
+                          '<input type="text" name="'.$item.'" value="'.
+                          $to{$item}.'" /></td></tr>';
+            $rownum ++;
+        }
+    } else {
+        foreach my $type (@mailings) {
+            $css_class = $rownum%2?' class="LC_odd_row"':'';
+            $datatable .= '<tr'.$css_class.'>'.
+                          '<td><span class="LC_nobreak">'.
+                          $titles->{$type}.': </span></td>'.
+                          '<td class="LC_left_item">';
+            if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
+                $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
+            }
+            $datatable .= '<span class="LC_nobreak">';
+            foreach my $item (@contacts) {
+                $datatable .= '<label>'.
+                              '<input type="checkbox" name="'.$type.'"'.
+                              $checked{$type}{$item}.
+                              ' value="'.$item.'" />'.$short_titles->{$item}.
+                              '</label> ';
+            }
+            $datatable .= '</span><br />'.&mt('Others').':  '.
+                          '<input type="text" name="'.$type.'_others" '.
+                          'value="'.$otheremails{$type}.'"  />';
+            my %locchecked;
+            if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
+                foreach my $loc ('s','b') {
+                    if ($includeloc{$type} eq $loc) {
+                        $locchecked{$loc} = ' checked="checked"';
+                        last;
+                    }
+                }
+                $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
+                              '<input type="text" name="'.$type.'_bcc" '.
+                              'value="'.$bccemails{$type}.'"  /></fieldset>'.
+                              '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
+                              &mt('Text automatically added to e-mail:').' '.
+                              '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
+                              '<span class="LC_nobreak">'.&mt('Location:').' '.
+                              '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
+                              (' 'x2).
+                              '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
+                              '</span></fieldset>';
+            }
+            $datatable .= '</td></tr>'."\n";
+            $rownum ++;
+        }
     }
-    foreach my $type (@mailings) {
+    if ($position eq 'middle') {
+        my %choices;
+        $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
+                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                    &mt('LON-CAPA core group - MSU'),600,500));
+        $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
+                                        &Apache::loncommon::modal_link('http://loncapa.org/core.html',
+                                        &mt('LON-CAPA core group - MSU'),600,500));
+        my @toggles = ('reporterrors','reportupdates');
+        my %defaultchecked = ('reporterrors'  => 'on',
+                              'reportupdates' => 'on');
+        (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
+                                                   \%choices,$rownum);
+        $datatable .= $reports;
+    } elsif ($position eq 'bottom') {
         $css_class = $rownum%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'>'.
-                      '<td><span class="LC_nobreak">'.
-                      $titles->{$type}.': </span></td>'.
-                      '<td class="LC_left_item">'.
-                      '<span class="LC_nobreak">';
-        foreach my $item (@contacts) {
-            $datatable .= '<label>'.
-                          '<input type="checkbox" name="'.$type.'"'.
-                          $checked{$type}{$item}.
-                          ' value="'.$item.'" />'.$short_titles->{$item}.
-                          '</label> ';
-        }
-        $datatable .= '</span><br />'.&mt('Others').':  '.
-                      '<input type="text" name="'.$type.'_others" '.
-                      'value="'.$otheremails{$type}.'"  />';
-        if ($type eq 'helpdeskmail') {
-            $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
-                          '<input type="text" name="'.$type.'_bcc" '.
-                          'value="'.$bccemails{$type}.'"  />';
+                      '<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 ++;
     }
-    my %choices;
-    $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
-                                   &Apache::loncommon::modal_link('http://loncapa.org/core.html',
-                                   &mt('LON-CAPA core group - MSU'),600,500));
-    $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
-                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
-                                    &mt('LON-CAPA core group - MSU'),600,500));
-    my @toggles = ('reporterrors','reportupdates');
-    my %defaultchecked = ('reporterrors'  => 'on',
-                          'reportupdates' => 'on');
-    (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
-                                               \%choices,$rownum);
-    $datatable .= $reports;
     $$rowtotal += $rownum;
     return $datatable;
 }
 
+sub contacts_javascript {
+    return <<"ENDSCRIPT";
+
+<script type="text/javascript">
+// <![CDATA[
+
+function screenshotSize(field) {
+    if (document.getElementById('help_screenshotsize')) {
+        if (field.value == 'no') {
+            document.getElementById('help_screenshotsize').style.display="none"; 
+        } else {
+            document.getElementById('help_screenshotsize').style.display="";
+        }
+    }
+    return;
+}
+
+// ]]>
+</script>
+
+ENDSCRIPT
+}
+
 sub print_helpsettings {
     my ($position,$dom,$settings,$rowtotal) = @_;
     my $confname = $dom.'-domainconfig';
@@ -5261,14 +5418,15 @@
 
 sub contact_titles {
     my %titles = &Apache::lonlocal::texthash (
-                   'supportemail' => 'Support E-mail address',
-                   '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 to be e-mailed to',
-                   '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',
+                   'supportemail'    => 'Support E-mail address',
+                   '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',  
+                   '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',
                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
                  );
     my %short_titles = &Apache::lonlocal::texthash (
@@ -5278,6 +5436,34 @@
     return (\%titles,\%short_titles);
 }
 
+sub helpform_fields {
+    my %titles =  &Apache::lonlocal::texthash (
+                       'username'   => 'Name',
+                       'user'       => 'Username/domain',
+                       'phone'      => 'Phone',
+                       'cc'         => 'Cc e-mail',
+                       'course'     => 'Course Details',
+                       'section'    => 'Sections',
+                       'screenshot' => 'File upload', 
+    );
+    my @fields = ('username','phone','user','course','section','cc','screenshot');
+    my %possoptions = (
+                        username     => ['yes','no','req'],
+                        phone        => ['yes','no','req'],   
+                        user         => ['yes','no'],
+                        cc           => ['yes','no'], 
+                        course       => ['yes','no'],
+                        section      => ['yes','no'],
+                        screenshot   => ['yes','no'],
+                      );
+    my %fieldoptions = &Apache::lonlocal::texthash (
+                         'yes'  => 'Optional',
+                         'req'  => 'Required',
+                         'no'   => "Not shown",
+    );
+    return (\@fields,\%titles,\%fieldoptions,\%possoptions);
+}
+
 sub tool_titles {
     my %titles = &Apache::lonlocal::texthash (
                      aboutme    => 'Personal web page',
@@ -10182,11 +10368,12 @@
             $currsetting{$key} = $domconfig{'contacts'}{$key};
         }
     }
-    my (%others,%to,%bcc);
+    my (%others,%to,%bcc,%includestr,%includeloc);
     my @contacts = ('supportemail','adminemail');
-    my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
-                    'requestsmail','updatesmail','idconflictsmail');
+    my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
+                    'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
     my @toggles = ('reporterrors','reportupdates');
+    my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
     foreach my $type (@mailings) {
         @{$newsetting{$type}} = 
             &Apache::loncommon::get_env_multiple('form.'.$type);
@@ -10199,9 +10386,14 @@
         }  
         $others{$type} = $env{'form.'.$type.'_others'};
         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
-        if ($type eq 'helpdeskmail') {
+        if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
             $bcc{$type} = $env{'form.'.$type.'_bcc'};
             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
+            if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
+                $includestr{$type} = $env{'form.'.$type.'_includestr'};
+                $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
+                $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
+            }
         }
     }
     foreach my $item (@contacts) {
@@ -10213,6 +10405,23 @@
             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
         }
     }
+    if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
+        foreach my $field (@{$fields}) {
+            if (ref($possoptions->{$field}) eq 'ARRAY') {
+                my $value = $env{'form.helpform_'.$field};
+                $value =~ s/^\s+|\s+$//g;
+                if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
+                    $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'};
+                        }
+                    }
+                }
+            }
+        }
+    }
     if (keys(%currsetting) > 0) {
         foreach my $item (@contacts) {
             if ($to{$item} ne $currsetting{$item}) {
@@ -10232,10 +10441,39 @@
             if ($others{$type} ne $currsetting{$type}{'others'}) {
                 push(@{$changes{$type}},'others');
             }
-            if ($type eq 'helpdeskmail') {   
+            if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {   
                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                     push(@{$changes{$type}},'bcc'); 
                 }
+                my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
+                if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
+                    push(@{$changes{$type}},'include');
+                }
+            }
+        }
+        if (ref($fields) eq 'ARRAY') {
+            if (ref($currsetting{'helpform'}) eq 'HASH') {
+                foreach my $field (@{$fields}) {
+                    if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
+                        push(@{$changes{'helpform'}},$field);
+                    }
+                    if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
+                        if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
+                            push(@{$changes{'helpform'}},'maxsize');
+                        }
+                    }
+                }
+            } else {
+                foreach my $field (@{$fields}) {
+                    if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
+                        push(@{$changes{'helpform'}},$field);
+                    }
+                    if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
+                        if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
+                            push(@{$changes{'helpform'}},'maxsize');
+                        }
+                    }
+                }
             }
         }
     } else {
@@ -10245,28 +10483,43 @@
         $default{'errormail'} = 'adminemail';
         $default{'packagesmail'} = 'adminemail';
         $default{'helpdeskmail'} = 'supportemail';
+        $default{'otherdomsmail'} = 'supportemail';
         $default{'lonstatusmail'} = 'adminemail';
         $default{'requestsmail'} = 'adminemail';
         $default{'updatesmail'} = 'adminemail';
         foreach my $item (@contacts) {
            if ($to{$item} ne $default{$item}) {
-              $changes{$item} = 1;
+               $changes{$item} = 1;
            }
         }
         foreach my $type (@mailings) {
             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
-               
                 push(@{$changes{$type}},@{$newsetting{$type}});
             }
             if ($others{$type} ne '') {
                 push(@{$changes{$type}},'others');
             }
-            if ($type eq 'helpdeskmail') {
+            if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                 if ($bcc{$type} ne '') {
                     push(@{$changes{$type}},'bcc');
                 }
+                if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
+                    push(@{$changes{$type}},'include');
+                }
             }
         }
+        if (ref($fields) eq 'ARRAY') {
+            foreach my $field (@{$fields}) {
+                if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
+                    push(@{$changes{'helpform'}},$field);
+                }
+                if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
+                    if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
+                        push(@{$changes{'helpform'}},'maxsize');
+                    }
+                }
+            }
+        }   
     }
     foreach my $item (@toggles) {
         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
@@ -10296,7 +10549,11 @@
             }
             foreach my $type (@mailings) {
                 if (ref($changes{$type}) eq 'ARRAY') {
-                    $resulttext .= '<li>'.$titles->{$type}.': ';
+                    if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
+                        $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': '; 
+                    } else {
+                        $resulttext .= '<li>'.$titles->{$type}.': ';
+                    }
                     my @text;
                     foreach my $item (@{$newsetting{$type}}) {
                         push(@text,$short_titles->{$item});
@@ -10304,12 +10561,31 @@
                     if ($others{$type} ne '') {
                         push(@text,$others{$type});
                     }
-                    $resulttext .= '<span class="LC_cusr_emph">'.
-                                   join(', ', at text).'</span>';
-                    if ($type eq 'helpdeskmail') {
+                    if (@text) {
+                        $resulttext .= '<span class="LC_cusr_emph">'.
+                                       join(', ', at text).'</span>';
+                    }
+                    if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                         if ($bcc{$type} ne '') {
-                            $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
+                            my $bcctext;
+                            if (@text) {
+                                $bcctext = ' '.&mt('with Bcc to'); 
+                            } else {
+                                $bcctext = '(Bcc)';
+                            }
+                            $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
+                        } elsif (!@text) {
+                            $resulttext .= &mt('No one');
+                        }   
+                        if ($includestr{$type} ne '') { 
+                            if ($includeloc{$type} eq 'b') {
+                                $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
+                            } elsif ($includeloc{$type} eq 's') {
+                                $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
+                            }
                         }
+                    } elsif (!@text) {
+                        $resulttext .= &mt('No recipients');
                     }
                     $resulttext .= '</li>';
                 }
@@ -10331,6 +10607,47 @@
                                         &mt('LON-CAPA core group - MSU'),600,500)).
                                 '</li>';
             }
+            if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
+                my (@optional, at required, at unused,$maxsizechg);
+                foreach my $field (@{$changes{'helpform'}}) {
+                    if ($field eq 'maxsize') {
+                        $maxsizechg = 1;
+                        next;
+                    }
+                    if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
+                        push(@optional,$field);    
+                    } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
+                        push(@unused,$field);
+                    } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
+                        push(@required,$field);   
+                    }
+                }
+                if (@optional) {
+                    $resulttext .= '<li>'.
+                                   &mt('Help form fields changed to "Optional": [_1].',
+                                       '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
+                                   '</li>';
+                }
+                if (@required) {
+                    $resulttext .= '<li>'.
+                                   &mt('Help form fields changed to "Required": [_1].',
+                                       '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
+                                   '</li>';
+                }
+                if (@unused) {
+                    $resulttext .= '<li>'.
+                                   &mt('Help form fields changed to "Not shown": [_1].',
+                                       '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
+                                   '</li>';
+                }
+                if ($maxsizechg) {
+                    $resulttext .= '<li>'.
+                                   &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>';
         } else {
             $resulttext = &mt('No changes made to contact information');
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1269 loncom/interface/loncommon.pm:1.1270
--- loncom/interface/loncommon.pm:1.1269	Mon Jan  2 19:44:06 2017
+++ loncom/interface/loncommon.pm	Wed Jan 18 21:24:40 2017
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1269 2017/01/02 19:44:06 raeburn Exp $
+# $Id: loncommon.pm,v 1.1270 2017/01/18 21:24:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -14517,9 +14517,9 @@
 sub build_recipient_list {
     my ($defmail,$mailing,$defdom,$origmail) = @_;
     my @recipients;
-    my $otheremails;
+    my ($otheremails,$lastresort,$allbcc,$addtext);
     my %domconfig =
-         &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
+        &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
     if (ref($domconfig{'contacts'}) eq 'HASH') {
         if (exists($domconfig{'contacts'}{$mailing})) {
             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
@@ -14531,14 +14531,96 @@
                             push(@recipients,$addr);
                         }
                     }
-                    $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
+                }
+                $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
+                if ($mailing eq 'helpdeskmail') {
+                    if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
+                        my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'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'}{$mailing}{'include'};
                 }
             }
         } elsif ($origmail ne '') {
-            push(@recipients,$origmail);
+            $lastresort = $origmail;
         }
     } elsif ($origmail ne '') {
-        push(@recipients,$origmail);
+        $lastresort = $origmail;
+    }
+
+    if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
+        unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
+            my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+            my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
+            my %what = (
+                          perlvar => 1,
+                       );
+            my $primary = &Apache::lonnet::domain($defdom,'primary');
+            if ($primary) {
+                my $gotaddr;
+                my ($result,$returnhash) =
+                    &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
+                if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
+                    if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
+                        $lastresort = $returnhash->{'lonSupportEMail'};
+                        $gotaddr = 1;
+                    }
+                }
+                unless ($gotaddr) {
+                    my $uintdom = &Apache::lonnet::internet_dom($primary);
+                    my $intdom = &Apache::lonnet::internet_dom($lonhost);
+                    unless ($uintdom eq $intdom) {
+                        my %domconfig =
+                            &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
+                        if (ref($domconfig{'contacts'}) eq 'HASH') {
+                            if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
+                                my @contacts = ('adminemail','supportemail');
+                                foreach my $item (@contacts) {
+                                    if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
+                                        my $addr = $domconfig{'contacts'}{$item};
+                                        if (!grep(/^\Q$addr\E$/, at recipients)) {
+                                            push(@recipients,$addr);
+                                        }
+                                    }
+                                }
+                                if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
+                                    $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
+                                }
+                                if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
+                                    my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'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'}{'otherdomsmail'}{'include'};
+                            }
+                        }
+                    }
+                }
+            }
+        }
     }
     if (defined($defmail)) {
         if ($defmail ne '') {
@@ -14558,8 +14640,21 @@
             }
         }
     }
+    if ($mailing eq 'helpdesk') {
+        if ((!@recipients) && ($lastresort ne '')) {
+            push(@recipients,$lastresort);
+        }
+    } elsif ($lastresort ne '') {
+        if (!grep(/^\Q$lastresort\E$/, at recipients)) {
+            push(@recipients,$lastresort);
+        }
+    }
     my $recipientlist = join(',', at recipients); 
-    return $recipientlist;
+    if (wantarray) {
+        return ($recipientlist,$allbcc,$addtext);
+    } else {
+        return $recipientlist;
+    }
 }
 
 ############################################################
Index: loncom/interface/lonsupportreq.pm
diff -u loncom/interface/lonsupportreq.pm:1.85 loncom/interface/lonsupportreq.pm:1.86
--- loncom/interface/lonsupportreq.pm:1.85	Wed Jan 18 21:07:31 2017
+++ loncom/interface/lonsupportreq.pm	Wed Jan 18 21:24:40 2017
@@ -1,5 +1,7 @@
+# The LearningOnline Network with CAPA
+# Helpdesk request form
 #
-# $Id: lonsupportreq.pm,v 1.85 2017/01/18 21:07:31 raeburn Exp $
+# $Id: lonsupportreq.pm,v 1.86 2017/01/18 21:24:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -83,7 +85,7 @@
     my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
         $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
         $formname,$public,$homeserver,$knownuser,$captcha_form,$captcha_error,
-        $captcha,$recaptcha_version);
+        $captcha,$recaptcha_version,$extra_validations,%groupid);
     $function = &Apache::loncommon::get_users_function() if (!$function);
     $ccode = '';
     $os = $env{'browser.os'};
@@ -111,13 +113,106 @@
         ($captcha_form,$captcha_error,$captcha,$recaptcha_version) =
             &Apache::loncommon::captcha_display('login',$lonhost);
     }
+    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
+                                                 'useremail','useraccount']);
+
     if ($homeserver) {
         $uhome = $env{'user.home'};
         $urole = $env{'request.role'};
         $usec = $env{'request.course.sec'};
         $cid = $env{'request.course.id'};
     }
+    if ($cid) {
+        $cdom = $env{'course.'.$cid.'.domain'};
+        $cnum = $env{'course.'.$cid.'.num'};
+    }
+    if ($cdom && $cnum) {
+        my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
+        $ctitle = $csettings{'description'};
+        $ccode = $csettings{'internal.coursecode'};
+        $sectionlist = $csettings{'internal.sectionnums'};
+        my @sections = split(/,/,$sectionlist);
+        foreach my $section (@sections) {
+           my ($sec,$grp) = split(/:/,$section);
+           $groupid{$sec} = $grp;
+        }
+    }
+
     $formname = 'logproblem';
+    my $codedom = &get_domain();
+    my %helpform;
+    my %domconfig =
+         &Apache::lonnet::get_dom('configuration',['contacts'],$codedom);
+    if (ref($domconfig{'contacts'}) eq 'HASH') {
+        if (ref($domconfig{'contacts'}{'helpform'}) eq 'HASH') {
+            %helpform = %{$domconfig{'contacts'}{'helpform'}};
+        }
+    }
+
+    my %coursecodes;
+    my %codes;
+    my @codetitles;
+    my %cat_titles;
+    my %cat_order;
+    my %idlist;
+    my %idnums;
+    my %idlist_titles;
+    my $caller = 'global';
+    my $totcodes = 0;
+    my $format_reply;
+    my $jscript = '';
+    my $loaditems = qq|
+function initialize_codes() {
+    return;
+}
+    |;
+    unless ($helpform{'course'} eq 'no') {
+        $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom);
+        if ($totcodes > 0) {
+            $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
+            if ($format_reply eq 'ok') {
+                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);
+                my $longtitles_str = join('","',@{$longtitles});
+                my $allidlist = $idlist{$codetitles[0]};
+                my $knowncodes;
+                if (($ccode ne '') && ($cnum ne '')) {
+                    my (%singlecodes, at singlecodetitles,%singlecat_titles,%singlecat_order);
+                    my $crscode_reply = &Apache::lonnet::auto_instcode_format($cnum,$codedom,{ $cnum => $ccode },\%singlecodes,
+                                                                              \@singlecodetitles,\%singlecat_titles,\%singlecat_order);
+                    if (ref($singlecodes{$cnum}) eq 'HASH') {
+                        $knowncodes = $singlecodes{$cnum};
+                    }
+                }
+                $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
+                $jscript .= $scripttext;
+                $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles,$knowncodes,$sectionlist);
+                $loaditems = '';
+            }
+        }
+    }
+    my %missing = &Apache::lonlocal::texthash(
+                         username   => 'You must include a name.',
+                         phone      => 'You must include a phone.',
+    );
+    &js_escape(\%missing);
+    if (keys(%helpform)) {
+        foreach my $key (keys(%helpform)) {
+            if (($helpform{$key} eq 'req') && ($missing{$key} ne '')) {
+                next if (($key eq 'username') && (($knownuser) ||
+                                                  (($env{'user.name'} =~ /^$match_username$/) && (!$public))));
+                $extra_validations .= <<"END";
+
+    if (document.$formname.$key.value == '') {
+        alert("$missing{$key}");
+        return;
+    }
+
+END
+            }
+        }
+    }
     my $machine = &Apache::lonnet::absolute_url();
     my $sourceurl = $machine.$origurl;
     $server = $machine.&Apache::loncommon::cleanup_html($origurl);
@@ -132,7 +227,7 @@
                   name => 'Name',
                   subm => 'Submit Request',
                   emad => 'Your e-mail address',
-                  emac => 'Cc', 
+                  emac => 'Cc',
                   unme => 'username',
                   doma => 'domain',
                   entu => 'Enter the username you use to log-in to LON-CAPA',
@@ -171,21 +266,12 @@
         alert("$js_lt{'rdes'}.");
         return;
     }
+    $extra_validations
     document.logproblem.submit();
 }
 
 END
     $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
-    if ($cid) {
-        $cdom = $env{'course.'.$cid.'.domain'};
-        $cnum = $env{'course.'.$cid.'.num'};
-    }
-    if ($cdom && $cnum) {
-        my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
-        $ctitle = $csettings{'description'};
-        $ccode = $csettings{'internal.coursecode'};
-        $sectionlist = $csettings{'internal.sectionnums'};
-    }
 
     if ($homeserver) {
         if ($env{'environment.permanentemail'}) {
@@ -202,14 +288,6 @@
             $firstname = $env{'environment.firstname'};
         }
     }
-    my @sections = split(/,/,$sectionlist);
-    my %groupid;
-    foreach my $section (@sections) {
-        my ($sec,$grp) = split(/:/,$section);
-        $groupid{$sec} = $grp;
-    }
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
-                                                 'useremail','useraccount']);
     if ($env{'form.origurl'} eq '/adm/createaccount') {
         if ($email eq '') {
             if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
@@ -222,57 +300,11 @@
             }
         }
     }
-    my $codedom = &get_domain();
     my $details_title;
     if ($codedom) {
         $details_title = '<br />('.$codedom.')';
     }
-    my %coursecodes;
-    my %codes;
-    my @codetitles;
-    my %cat_titles;
-    my %cat_order;
-    my %idlist;
-    my %idnums;
-    my %idlist_titles;
-    my $caller = 'global';
-    my $totcodes = 0;
-    my $format_reply;
-    my $jscript = '';
-    my $loaditems = qq|
-function initialize_codes() {
-    return;
-}
-    |;
-    if ($cnum) {
-        $coursecodes{$cnum} = $ccode;
-        if ($ccode eq '') {
-            $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
-        } else {
-            $coursecodes{$cnum} = $ccode;
-            $caller = $cnum;
-            $totcodes ++;
-        }
-    } else { 
-        $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
-    }
-    if ($totcodes > 0) {
-        if ($ccode eq '') {
-            $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
-            if ($format_reply eq 'ok') {
-                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);
-                my $longtitles_str = join('","',@{$longtitles});
-                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);
-                $loaditems = '';
-            }
-        }
-    }
-	
+
     my $js = <<"ENDJS";
 <script type="text/javascript">
 // <![CDATA[
@@ -306,106 +338,117 @@
     if ($homeserver) {
         $formtype = ' enctype="multipart/form-data"';
     }
+    my $topsubmit = '     <input type="button" value="'.$html_lt{'subm'}.'" onclick="validate()" /> ';
+    my $shownsubmit;
     $r->print('<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
     my $output = &Apache::lonhtmlcommon::start_pick_box().
                  &Apache::lonhtmlcommon::row_headline().
                  '<span class="LC_info">'.
                  &mt('(All fields marked with * are required.)').
                  '</span>'.
-                 &Apache::lonhtmlcommon::row_closure().
-                 &Apache::lonhtmlcommon::row_title($html_lt{'name'},undef,$css[$num])."\n";
-    my $fullname = '';
-    if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
-        $fullname = "$firstname $lastname"; 
-        $output .= $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
-    } else {
-        if (defined($firstname) && $firstname ne '') {
-            $fullname = $firstname;
-        } elsif (defined($lastname) && $lastname ne '') {
-            $fullname = " $lastname";
+                 &Apache::lonhtmlcommon::row_closure();
+    unless ($helpform{'username'} eq 'no') {
+        my ($reqd,$namefield,$fullname);
+        if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
+            $fullname = "$firstname $lastname"; 
+            $namefield = $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
+        } else {
+            if (defined($firstname) && $firstname ne '') {
+                $fullname = $firstname;
+            } elsif (defined($lastname) && $lastname ne '') {
+                $fullname = " $lastname";
+            }
+            $namefield = '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
+            if ($helpform{'username'} eq 'req') {
+                $reqd = '<span class="LC_info">*</span>';
+            }
         }
-        $output .= '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
+        $output .= &Apache::lonhtmlcommon::row_title($html_lt{'name'}.$reqd,undef,$css[$num])."\n".$namefield.
+                   $topsubmit.
+                   &Apache::lonhtmlcommon::row_closure()."\n";
+        $shownsubmit = 1;
+        $num ++;
+        $i = $num%2;
     }
-    $output .= '     <input type="button" value="'.$html_lt{'subm'}.'" onclick="validate()" /> '.
-                &Apache::lonhtmlcommon::row_closure()."\n";
-    $num ++;
-    $i = $num%2;
     $output .= &Apache::lonhtmlcommon::row_title(
                    '<span title="'.&mt('required').'">'.
                    $html_lt{'emad'}.' <span class="LC_info">*</span></span>'
                   ,undef,$css[$i]).
                '<input type="text" size="20" name="email" value="'.
-               &HTML::Entities::encode($email,'"<>&').'" /><br />'."\n".
-               &Apache::lonhtmlcommon::row_closure();
+               &HTML::Entities::encode($email,'"<>&').'" />'."\n";
+    unless ($shownsubmit) {
+        $output .= $topsubmit;
+    } 
+    $output .= &Apache::lonhtmlcommon::row_closure();
     $num ++;
     $i = $num%2;
     if ($knownuser) {
         if ($homeserver) {
-            $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).
-                       '<input type="text" size="50" name="cc" value="" /><br />'."\n".
-                       &Apache::lonhtmlcommon::row_closure();
-            $num ++;
-            $i = $num%2;
+            unless ($helpform{'cc'} eq 'no') {
+                $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).
+                           '<input type="text" size="50" name="cc" value="" /><br />'."\n".
+                           &Apache::lonhtmlcommon::row_closure();
+                $num ++;
+                $i = $num%2;
+            }
         }
     }
-    $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]);
-    my $udom_input = '<input type="hidden" name="udom" value="'.
-                     &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
-    my $uname_input = '<input type="hidden" name="uname" value="'.
-                      &HTML::Entities::encode($uname,'"<>&').'" />'."\n"; 
-    if ($knownuser) {
-        $output .= '<i>'.$html_lt{'unme'}.'</i>: '.$uname.'  <i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input.$uname_input;
-    } else {
-        my $udomform = '';
-        my $unameform = '';
-        if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
-            $output .= $html_lt{'entu'};
-        } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { 
-            $output .= $html_lt{'chdo'};
+    unless ($helpform{'user'} eq 'no') {
+        $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]);
+        my $udom_input = '<input type="hidden" name="udom" value="'.
+                         &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
+        my $uname_input = '<input type="hidden" name="uname" value="'.
+                         &HTML::Entities::encode($uname,'"<>&').'" />'."\n";
+        if ($knownuser) {
+            $output .= '<i>'.$html_lt{'unme'}.'</i>: '.$uname.'  <i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input.$uname_input;
         } else {
-            $output .= $html_lt{'entr'};
-        }
-        $output .= '<br />'."\n";
-        if (!$public) {
-            if ($env{'user.domain'} =~ /^$match_domain$/) {
-                $udomform = '<i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input;
-            } elsif ($env{'user.name'} =~ /^$match_username$/) {
-                $unameform = '<i>'.$html_lt{'unme'}.'</i>: '.$uname.'  '.$uname_input;
+            my $udomform = '';
+            my $unameform = '';
+            if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
+                $output .= $html_lt{'entu'};
+            } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { 
+                $output .= $html_lt{'chdo'};
+            } else {
+                $output .= $html_lt{'entr'};
             }
+            $output .= '<br />'."\n";
+            if (!$public) {
+                if ($env{'user.domain'} =~ /^$match_domain$/) {
+                    $udomform = '<i>'.$html_lt{'doma'}.'</i>: '.$udom.$udom_input;
+                } elsif ($env{'user.name'} =~ /^$match_username$/) {
+                    $unameform = '<i>'.$html_lt{'unme'}.'</i>: '.$uname.'  '.$uname_input;
+                }
+            }
+            if ($udomform eq '') {
+                $udomform = '<i>'.$html_lt{'doma'}.'</i>: ';
+                $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n";
+            }
+            if ($unameform eq '') {
+                $unameform= '<i>'.$html_lt{'unme'}.'</i>: <input type="text" size="20" name="uname" value="'.$uname.'" />  ';
+            }
+            $output .= $unameform.$udomform;
         }
-        if ($udomform eq '') {
-            $udomform = '<i>'.$html_lt{'doma'}.'</i>: ';
-            $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n";
-        }
-        if ($unameform eq '') {
-            $unameform= '<i>'.$html_lt{'unme'}.'</i>: <input type="text" size="20" name="uname" value="'.$uname.'" />  ';
-        }
-        $output .= $unameform.$udomform;
+        $output .= &Apache::lonhtmlcommon::row_closure();
+        $num ++;
     }
-    $output .= &Apache::lonhtmlcommon::row_closure();
-    $num ++;
     $i = $num%2;
     $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]).
                $server."\n".'<input type="hidden" name="sourceurl" value="'.
                &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
-               &Apache::lonhtmlcommon::row_closure().
-               &Apache::lonhtmlcommon::row_title("$html_lt{'phon'}",undef,'LC_evenrow_value').
-               '<input type="text" size="15" name="phone" /><br />'."\n".
                &Apache::lonhtmlcommon::row_closure();
-    $num ++;
-    $i = $num%2; 
-    $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]);
-    if ($cnum) {
-        if ($coursecodes{$cnum}) {
-            foreach my $item (@codetitles) {
-                $output .= '<i>'.$item.'</i>: '.$codes{$cnum}{$item}.'; ';
-            }
-            $output .= ' <input type="hidden" name="coursecode" value="'.&HTML::Entities::encode($coursecodes{$cnum},'"<>&').'" />'."\n";
-        } else {
-            $output .= $html_lt{'enin'}.': 
-                  <input type="text" name="coursecode" size="15" value="" />'."\n";
-        }
-    } else {
+    unless ($helpform{'phone'} eq 'no') {
+        my $reqd;
+        if ($helpform{'phone'} eq 'req') {
+            $reqd = '<span class="LC_info">*</span>';
+        }
+        $output .= &Apache::lonhtmlcommon::row_title($html_lt{'phon'}.$reqd,undef,'LC_evenrow_value').
+                   '<input type="text" size="15" name="phone" /><br />'."\n".
+                   &Apache::lonhtmlcommon::row_closure();
+        $num ++;
+        $i = $num%2;
+    }
+    unless ($helpform{'course'} eq 'no') {
+        $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]);
         if ($totcodes > 0) {
             my $numtitles = @codetitles;
             if ($numtitles == 0) {
@@ -416,9 +459,13 @@
                 my $lasttitle = $numtitles;
                 if ($numtitles > 4) {
                     $lasttitle = 4;
-                } 
+                }
+                my $onchange;
+                if ($sectionlist) {
+                    $onchange = 'toggleSecVis()';
+                }
                 $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
-                      '<select name="'.$standardnames[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
+                      '<select name="'.$standardnames[0].'" onchange="courseSet('."'$codetitles[0]'".');'.$onchange.'">'."\n".
                       ' <option value="-1">'.$html_lt{'sele'}."</option>\n";
                 my @items = ();
                 my @longitems = ();
@@ -447,7 +494,7 @@
                 $output .= '</select></td>';
                 for (my $i=1; $i<$numtitles; $i++) {
                     $output .= '<td>'.$codetitles[$i].'<br />'."\n".
-                     '<select name="'.$standardnames[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
+                     '<select name="'.$standardnames[$i].'" onchange="courseSet('."'$codetitles[$i]'".');'.$onchange.'">'."\n".
                      '<option value="-1"><-'.$html_lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
                      '</select>'."\n".
                      '</td>'."\n";
@@ -455,7 +502,7 @@
                 $output .= '</tr></table>';
                 if ($numtitles > 4) {
                     $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
-                          '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
+                          '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".');'.$onchange.'">'."\n".
                           '<option value="-1"><-'.$html_lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
                           '</select>'."\n";
                 }
@@ -464,40 +511,43 @@
             $output .= $html_lt{'enin'}.': 
                   <input type="text" name="coursecode" size="15" value="" />'."\n";
         }
-    }
-    if ($ctitle) {
-        $output .= '<br /><i>'.$html_lt{'titl'}.'</i>: '.$ctitle.
-                   '<input type="hidden" name="title" value="'.
+        my $reqd;
+        if ($helpform{'course'} eq 'req') {
+             $reqd = '<span class="LC_info">*</span>';
+        }
+        $output .= '<br />'.$html_lt{'enct'}.$reqd.': 
+                   <input type="text" name="title" size="25" value="'.
                    &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
-    } else {
-        $output .= '<br />'.$html_lt{'enct'}.': 
-                 <input type="text" name="title" size="25" value="" />'."\n";
-    }
-    $output .= &Apache::lonhtmlcommon::row_closure();
-    $num ++;
-    $i = $num%2;
-    $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]);
-    if ($sectionlist) {
-        $output .= "<select name=\"section\"\n>".
-                   "  <option value=\"\" selected=\"selected\">$html_lt{'sele'}</option>\n";
-        foreach my $id (sort(keys(%groupid))) {
-            if ($id eq $groupid{$id} || $groupid{$id} eq '') {
-                $output .= "  <option value=".
-                           &HTML::Entities::encode($id,'"<>&').
-                           " >$id</option>\n";
-            } else {
-                $output .= "  <option value=".
-                           &HTML::Entities::encode($id,'"<>&').
-                           " >$id - ($html_lt{'lsec'}: $groupid{$id})</option>\n";
+        $output .= &Apache::lonhtmlcommon::row_closure();
+        $num ++;
+        $i = $num%2;
+    }
+    unless ($helpform{'section'} eq 'no') {
+        $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]);
+        if ($sectionlist) {
+            $output .= "<div id=\"LC_helpdesk_sectionlist\"><select name=\"sectionsel\">\n".
+                       "  <option value=\"\" selected=\"selected\">$html_lt{'sele'}</option>\n";
+            foreach my $id (sort(keys(%groupid))) {
+                if ($id eq $groupid{$id} || $groupid{$id} eq '') {
+                    $output .= "  <option value=".
+                               &HTML::Entities::encode($id,'"<>&').
+                               " >$id</option>\n";
+                } else {
+                    $output .= "  <option value=".
+                               &HTML::Entities::encode($id,'"<>&').
+                               " >$id - ($html_lt{'lsec'}: $groupid{$id})</option>\n";
+                }
             }
-        }
-        $output .= "</select>";
-    } else {
-        $output .= '<input type="text" name="section" size="10" />'."\n";
+            $output .= '</select></div>'."\n".
+                       '<div id="LC_helpdesk_section" style="display:none">'.
+                       '<input type="text" name="sectiontxt" size="10" /></div>'."\n";
+        } else { 
+            $output .= '<input type="text" name="section" size="10" />'."\n";
+        }
+        $output .= &Apache::lonhtmlcommon::row_closure();
+        $num ++;
+        $i = $num%2;
     }
-    $output .= &Apache::lonhtmlcommon::row_closure();
-    $num ++;
-    $i = $num%2; 
     $output .= &Apache::lonhtmlcommon::row_title(
                    '<span title="'.&mt('required').'">'.
                    $html_lt{'subj'}.' <span class="LC_info">*</span></span>'
@@ -515,13 +565,19 @@
     $i = $num%2; 
     if ($knownuser) {
         if ($homeserver) {
-            $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])
-                .' <input type="file" name="screenshot" class="flUpload" size="20" />'
-                .'<input type="hidden" id="free_space" value="1048576" />'
-                .'<br />'."\n".$html_lt{'uplf'}."\n"
-                .&Apache::lonhtmlcommon::row_closure();
-            $num ++;
-            $i = $num%2;
+            unless ($helpform{'screenshot'} eq 'no') {
+                my $max = 1048576;
+                if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
+                    $max *= $helpform{'maxsize'}; 
+                }
+                $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])
+                    .' <input type="file" name="screenshot" class="flUpload" size="20" />'
+                    .'<input type="hidden" id="free_space" value="'.$max.'" />'
+                    .'<br />'."\n".$html_lt{'uplf'}."\n"
+                    .&Apache::lonhtmlcommon::row_closure();
+                $num ++;
+                $i = $num%2;
+            }
         }
     } else {
         if ($captcha_form) {
@@ -568,8 +624,8 @@
     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
         $public = 1;
     }
+    my $lonhost = $r->dir_config('lonHostID'); 
     unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
-        my $lonhost = $r->dir_config('lonHostID');
         my ($captcha_chk,$captcha_error) = 
             &Apache::loncommon::captcha_response('login',$lonhost);
         if ($captcha_chk != 1) {
@@ -603,54 +659,65 @@
     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
     my $defdom = &get_domain();
-    my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
-                                                      $defdom,$origmail);
+    my ($to,$bcc,$addtext) =
+        &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
+                                                 $defdom,$origmail);
     my $from = $admin;
-    my $bcc;
+    my %helpform;
     my %domconfig =
          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
     if (ref($domconfig{'contacts'}) eq 'HASH') {
-        if (exists($domconfig{'contacts'}{'helpdeskmail'})) {
-            if (ref($domconfig{'contacts'}{'helpdeskmail'}) eq 'HASH') {
-                my $bccmail = $domconfig{'contacts'}{'helpdeskmail'}{'bcc'};
-                if ($bccmail ne '') {
-                    my @bccs = split(/,/,$bccmail);
-                    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) {
-                        $bcc = join(', ', at ok_bccs);
-                    }
-                }
-            }
+        if (ref($domconfig{'contacts'}{'helpform'}) eq 'HASH') {
+            %helpform = %{$domconfig{'contacts'}{'helpform'}};
         }
     }
     my $reporttime = &Apache::lonlocal::locallocaltime(time);
-    my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
-
-    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
-    my $coursecode = $env{'form.coursecode'};
-    if ($coursecode eq '') {
-        my $totcodes = 0;
-        my %coursecodes;
-        $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom,$totcodes);
-        my @standardnames = &Apache::loncommon::get_standard_codeitems();
-        if ($totcodes > 0) {
-            my $noregexps = 1;
-            $coursecode = 
-                &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
-        } 
+    my %formvars = (
+                     email       => 1,
+                     sourceurl   => 1,
+                     subject     => 1,
+                     description => 1,
+                   );
+    unless ($helpform{'username'} eq 'no') {
+        $formvars{'username'} = 1;
+    }
+    unless ($helpform{'user'} eq 'no') {
+        $formvars{'uname'} = 1;
+        $formvars{'udom'} = 1;
+    }
+    unless ($helpform{'phone'} eq 'no') {
+        $formvars{'phone'} = 1;
+    }
+    unless ($helpform{'section'} eq 'no') {
+        $formvars{'section'} = 1;
+    }
+    unless ($helpform{'course'} eq 'no') {
+        $formvars{'course'} = 1;
+    }
+    unless ($helpform{'cc'} eq 'no') {
+        $formvars{'cc'} = 1;
+    }
+    unless ($helpform{'screenshot'} eq 'no') {
+        $formvars{'screenshot'} = 1;
+    }
+    my $coursecode;
+    if ($formvars{'course'}) {
+        $coursecode = $env{'form.coursecode'};
         if ($coursecode eq '') {
-            foreach my $item (@standardnames) {
-                if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
-                    $coursecode .= $env{'form.'.$item};
+            my $totcodes = 0;
+            my %coursecodes;
+            $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom);
+            my @standardnames = &Apache::loncommon::get_standard_codeitems();
+            if ($totcodes > 0) {
+                my $noregexps = 1;
+                $coursecode = 
+                    &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
+            }
+            if ($coursecode eq '') {
+                foreach my $item (@standardnames) {
+                    if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
+                        $coursecode .= $env{'form.'.$item};
+                    }
                 }
             }
         }
@@ -681,8 +748,20 @@
                                                       $env{'user.domain'});
         }
     }
-
-    if (($homeserver) && (defined($env{'form.cc'}))) {
+    my ($cid,$cdom,$cnum,$sectionlist,$ccode);
+    if ($homeserver) {
+        $cid = $env{'request.course.id'};
+    }
+    if ($cid) {
+        $cdom = $env{'course.'.$cid.'.domain'};
+        $cnum = $env{'course.'.$cid.'.num'};
+    }
+    if ($cdom && $cnum) {
+        my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
+        $ccode = $csettings{'internal.coursecode'};
+        $sectionlist = $csettings{'internal.sectionnums'};
+    }
+    if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
         my @ccs;
         if ($env{'form.cc'} =~ /,/) {
             @ccs = split(/,/,$env{'form.cc'});
@@ -716,20 +795,48 @@
         }
     }
     $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
-    $env{'form.crsi'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
-    my $supportmsg = <<END;
-$lt{'username'}: $env{'form.username'}
-$lt{'email'}: $env{'form.email'}
-$lt{'cc'}: $okcclist
-$lt{'user'}: $env{'form.user'}
-$lt{'phone'}: $env{'form.phone'}
-$lt{'crsi'}: $env{'form.crsi'}
-$lt{'subject'}: $env{'form.subject'}
+    if ($formvars{'course'}) {
+        $env{'form.crsi'} = $env{'form.title'};
+        if ($coursecode ne '') {
+            $env{'form.crsi'} .= ' - '.$coursecode;
+        }
+    }
+    if ($formvars{'section'}) {
+        my $section;
+        if ($sectionlist) {
+            if ($coursecode eq $ccode) {
+                $section = $env{'form.sectionsel'}
+            } else {
+                $section = $env{'form.sectiontxt'};
+            }
+        } else {
+            $section = $env{'form.section'};
+        }
+        $env{'form.crsi'} .= ' - '.$lt{'sect'}.': '.$section;
+    }
+    my $supportmsg;
+    if ($formvars{'username'}) {
+        $supportmsg .= "$lt{'username'}: $env{'form.username'}\n";
+    }
+    $supportmsg .= "$lt{'email'}: $env{'form.email'}\n";
+    if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
+        $supportmsg .= "$lt{'cc'}: $okcclist\n";
+    }
+    if ($formvars{'user'}) {
+        $supportmsg .= "$lt{'user'}: $env{'form.user'}\n";
+    }
+    if ($formvars{'phone'}) {
+        $supportmsg .= "$lt{'phone'}: $env{'form.phone'}\n";
+    }
+    if ($formvars{'course'}) {
+        $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n";
+    } 
+    $supportmsg .= "$lt{'subject'}: $env{'form.subject'}
 $lt{'description'}: $env{'form.description'}
 $lt{'sourceurl'}: $env{'form.sourceurl'}
 $lt{'date'}: $reporttime
+";
 
-END
     my $displaymsg;
     foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
         if ($env{'form.'.$item} ne '') {
@@ -748,6 +855,7 @@
                     '<span class="LC_helpform_receipt_cat">'.
                     "$lt{$item}</span>: $showurl<br />\n";
             } elsif ($item eq 'cc') {
+                next if ($helpform{'cc'} eq 'no');
                 if ($okcclist) {
                     my $showcclist = &Apache::loncommon::cleanup_html($okcclist);
                     $displaymsg .=
@@ -755,6 +863,10 @@
                         "$lt{$item}</span>: $showcclist<br />\n";
                 }
             } else {
+                if (($item eq 'username') || ($item eq 'user') || ($item eq 'phone')) {
+                    next if ($helpform{$item} eq 'no');
+                }
+                next if (($item eq 'crsi') && ($helpform{'course'} eq 'no'));
                 my $showitem = $env{'form.'.$item};
                 $showitem = &Apache::loncommon::cleanup_html($showitem);
                 $displaymsg .= 
@@ -849,12 +961,18 @@
     my $attachmentsize = '';
     if ((defined($env{'user.name'})) && (!$public)) {
         if ($homeserver && $env{'form.screenshot.filename'}) {
-            $attachmentsize = length($env{'form.screenshot'});
-            if ($attachmentsize > 1048576) {
-                $displaymsg .= '<br /><span class="LC_warning">'.
-                               &mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 1 MB, and has therefore been discarded.',$attachmentsize).'</span>';
-            } else {
-                $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
+            unless ($helpform{'screenshot'} eq 'no') {
+                $attachmentsize = length($env{'form.screenshot'});
+                my $max = 1048576;
+                if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
+                    $max *= $helpform{'maxsize'};
+                }
+                if ($attachmentsize > $max) {
+                    $displaymsg .= '<br /><span class="LC_warning">'.
+                                   &mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 1 MB, and has therefore been discarded.',$attachmentsize).'</span>';
+                } else {
+                    $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
+                }
             }
         }
     }
@@ -909,7 +1027,17 @@
         }
         $attachment_text = $envdata;
     }
-    
+
+    if ($addtext) {
+        my ($addloc,$addstr) = split(/:/,$addtext,2);
+        $addstr = &unescape($addstr);
+        if ($addloc eq 's') {
+            $subject = $addstr.' '.$subject;
+        } elsif ($addloc eq 'b') {
+            $supportmsg = $addstr."\n".$supportmsg;
+        }
+    }
+
     # Compose and send a MIME email
     &Apache::loncommon::mime_email($from, $to, $subject, $supportmsg, $cc_string, $bcc, 
                                     $attachmentpath, $fname, $attachment_text);
@@ -962,7 +1090,7 @@
                                            login    => 'Log-in help',
                                            ask      => 'Ask helpdesk',
                                            getst    => 'Getting started guide',
-                                           back     =>  'Back to last location',
+                                           back     => 'Back to last location',
                                            headline => 'help/support',
                                            stud     => 'Students',
                                            ifyo     => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',


More information about the LON-CAPA-cvs mailing list