[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /interface lonsupportreq.pm

raeburn raeburn at source.lon-capa.org
Mon Jan 23 14:57:31 EST 2017


raeburn		Mon Jan 23 19:57:31 2017 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/interface	lonsupportreq.pm 
  Log:
  - For 2.11
    - Backport 1.81 (part), 1.88, 1.87, 1.88, 1.89, 1.90
  
  
-------------- next part --------------
Index: loncom/interface/lonsupportreq.pm
diff -u loncom/interface/lonsupportreq.pm:1.79.2.2 loncom/interface/lonsupportreq.pm:1.79.2.3
--- loncom/interface/lonsupportreq.pm:1.79.2.2	Mon Jan 23 01:56:26 2017
+++ loncom/interface/lonsupportreq.pm	Mon Jan 23 19:57:30 2017
@@ -1,5 +1,7 @@
+# The LearningOnline Network with CAPA
+# Helpdesk request form
 #
-# $Id: lonsupportreq.pm,v 1.79.2.2 2017/01/23 01:56:26 raeburn Exp $
+# $Id: lonsupportreq.pm,v 1.79.2.3 2017/01/23 19:57:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -85,7 +87,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'};
@@ -113,13 +115,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);
@@ -134,7 +229,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',
@@ -153,7 +248,7 @@
                   subj => 'Subject',
                   detd => 'Detailed Description',
                   opfi => 'Optional file upload',
-                  uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)',
+                  uplf => 'Upload a file (e.g., a screenshot) relevant to your help request',
                   fini => 'Finish',
                   clfm => 'Clear Form',
     );
@@ -173,21 +268,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'}) {
@@ -204,14 +290,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'} =~ /^[^\@]+\@[^\@]+$/) {
@@ -224,57 +302,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[
@@ -307,106 +339,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;
+        if ($homeserver) {
+            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) {
@@ -417,9 +460,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 = ();
@@ -448,7 +495,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";
@@ -456,7 +503,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";
                 }
@@ -465,40 +512,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></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 .= "</select>";
-    } 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>'
@@ -516,12 +566,21 @@
     $i = $num%2; 
     if ($knownuser) {
         if ($homeserver) {
-            $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i]).
+            unless ($helpform{'screenshot'} eq 'no') {
+                my $max = 1048576;
+                my $showmax = 1.00;
+                if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
+                    $max *= $helpform{'maxsize'};
+                    $showmax = $helpform{'maxsize'};
+                }
+                $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')';
+                $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i]).
                        ' <input type="file" name="screenshot" size="20" /><br />'.
-                       "\n".$html_lt{'uplf'}."\n".
+                       "\n".$html_lt{'uplf'}.$showmax."\n".
                        &Apache::lonhtmlcommon::row_closure();
-            $num ++;
-            $i = $num%2;
+                $num ++;
+                $i = $num%2;
+            }
         }
     } else {
         if ($captcha_form) {
@@ -568,8 +627,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 +662,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 +751,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 +798,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 +858,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 +866,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 .= 
@@ -846,15 +961,27 @@
     my $fname;
 
     my $attachmentpath = '';
-    my $attachmentsize = '';
+    my $showsize = '';
+
     if ((defined($env{'user.name'})) && (!$public)) {
         if ($homeserver && $env{'form.screenshot.filename'}) {
-            $attachmentsize = length($env{'form.screenshot'});
-            if ($attachmentsize > 131072) {
-                $displaymsg .= '<br /><span class="LC_warning">'.
-                               &mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.',$attachmentsize).'</span>';
-            } else {
-                $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
+            unless ($helpform{'screenshot'} eq 'no') {
+                my $attachmentsize = length($env{'form.screenshot'});
+                my $max = 1048576;
+                my $showmax = 1.00;
+                if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
+                    $max *= $helpform{'maxsize'};
+                    $showmax = $helpform{'maxsize'};
+                }
+                $showmax = '('.sprintf("%.2f",$showmax).' MB)';
+                $showsize = $attachmentsize/1048576;
+                $showsize = '('.sprintf("%.2f",$showsize).' MB)';
+                if ($attachmentsize > $max) {
+                    $displaymsg .= '<br /><span class="LC_warning">'.
+                                   &mt('The uploaded screenshot file [_1] included with your request exceeded the maximum allowed size [_2], and has therefore been discarded.',$showsize,$showmax).'</span>';
+                } else {
+                    $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
+                }
             }
         }
     }
@@ -868,9 +995,8 @@
     if ($attachmentpath =~ m-/([^/]+)$-) {
         $fname = $1;
         $displaymsg .= '<br />'
-                      .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
-                          ,'<span class="LC_filename">'.$fname.'</span>'
-                          ,$attachmentsize
+                      .&mt('An uploaded screenshot file [_1] was included in the request sent by [_2].'
+                          ,'<span class="LC_filename">'.$fname.'</span> '.$showsize,
                           ,$env{'user.name'}.':'.$env{'user.domain'}
                        );
         $supportmsg .= "\n";
@@ -884,7 +1010,40 @@
             $supportmsg .= "$var: $env{$var}\n";
         }
     }
- 
+
+    my $cc_string;
+    if ($homeserver) {
+        if (@ok_ccs > 0) {
+            $cc_string = join(', ', at ok_ccs);
+        }
+    }
+
+    my $attachment_text = '';
+    unless ($homeserver && $attachmentpath) {
+        foreach my $var (@cookievars) {
+            $attachment_text .= "$var: $cookies{$var}\n";
+        }
+        foreach my $var (@ENVvars) {
+            $attachment_text .= "$var: $ENV{$var}\n";
+        }
+        foreach my $var (@envvars) {
+            $attachment_text .= "$var: $env{$var}\n";
+        }
+        foreach my $var (@loncvars) {
+            $attachment_text .= "$var: $env{$var}\n";
+        }
+    }
+
+    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;
+        }
+    }
+
     my $msg = MIME::Lite->new(
                  From    => $from,
                  To      => $to,
@@ -911,22 +1070,9 @@
                      Filename => $fname
                      );
 
-    } else {
-        my $envdata = '';
-        foreach my $var (@cookievars) {
-            $envdata .= "$var: $cookies{$var}\n";
-        }
-        foreach my $var (@ENVvars) {
-            $envdata .= "$var: $ENV{$var}\n";
-        }
-        foreach my $var (@envvars) {
-            $envdata .= "$var: $env{$var}\n";
-        }
-        foreach my $var (@loncvars) {
-            $envdata .= "$var: $env{$var}\n";
-        }
+    } elsif ($attachment_text ne '') {
         $msg->attach(Type => 'TEXT',
-                     Data => $envdata);
+                     Data => $attachment_text);
     }
 
 ### Send it:
@@ -980,7 +1126,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