File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.97: download - view: text, annotated - select for diffs
Wed Aug 7 16:08:04 2019 UTC (4 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Prepend LC_ to class name in client-side checking for uploaded file size,
  for purposes of namespacing.

    1: # The LearningOnline Network with CAPA
    2: # Helpdesk request form
    3: #
    4: # $Id: lonsupportreq.pm,v 1.97 2019/08/07 16:08:04 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonsupportreq;
   30: 
   31: use strict;
   32: use CGI::Cookie();
   33: use Apache::Constants qw(:common);
   34: use Apache::loncommon();
   35: use Apache::lonhtmlcommon;
   36: use Apache::lonnet;
   37: use Apache::lonlocal;
   38: use Apache::lonacc();
   39: use Apache::lonauth();
   40: use Apache::courseclassifier;
   41: use LONCAPA qw(:DEFAULT :match);
   42: use HTML::Entities;
   43: 
   44: sub handler {
   45:     my ($r) = @_;
   46:     &Apache::loncommon::content_type($r,'text/html');
   47:     $r->send_http_header;
   48: 
   49:     if ($r->header_only) {
   50:         return OK;
   51:     }
   52:     if ($r->uri eq '/adm/helpdesk') {
   53: 	&Apache::lonlocal::get_language_handle($r);
   54:     }
   55: 
   56:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
   57:     if ($r->uri eq '/adm/helpdesk') {
   58:         &Apache::lonacc::get_posted_cgi($r);
   59:     }
   60:     my $function;
   61:     if ($env{'form.function'}) {
   62:         if (($env{'form.function'} eq 'norole')  ||
   63:             ($env{'form.function'} eq 'student') ||
   64:             ($env{'form.function'} eq 'admin')   ||
   65:             ($env{'form.function'} eq 'author')) {
   66:             $function = $env{'form.function'};
   67:         }
   68:     }
   69:     my $origurl = $env{'form.origurl'};
   70:     if ($origurl =~ m{^https?://[^/]+(.*)$}) {
   71:         $origurl =~ $1;
   72:     }
   73:     $origurl =~ s/(`)//g;
   74:     $origurl =~ s/\$/\(\$\)/g;
   75:     my $command = $env{'form.command'};
   76: 
   77:     if ($command eq 'process') {
   78:         &print_request_receipt($r,$origurl,$function);
   79:     } else {
   80:         &print_request_form($r,$origurl,$function);
   81:     }
   82:     return OK;
   83: }
   84: 
   85: sub print_request_form {
   86:     my ($r,$origurl,$function) = @_;
   87:     my ($os,$browser,$bversion,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
   88:         $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
   89:         $formname,$public,$homeserver,$knownuser,$captcha_form,$captcha_error,
   90:         $captcha,$recaptcha_version,$extra_validations,%groupid);
   91:     $function = &Apache::loncommon::get_users_function() if (!$function);
   92:     $ccode = '';
   93:     $os = $env{'browser.os'};
   94:     $browser = $env{'browser.type'};
   95:     $bversion = $env{'browser.version'};
   96:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
   97:         $public = 1;
   98:     } else {
   99:         if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
  100:             $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
  101:                                                       $env{'user.domain'});
  102:             if ($homeserver eq 'no_host') {
  103:                 undef($homeserver); 
  104:             } else {
  105:                 $uname = $env{'user.name'};
  106:                 $udom = $env{'user.domain'};
  107:             }
  108:         }
  109:     }
  110:     if (($env{'user.name'} =~ /^$match_username$/) &&
  111:         ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
  112:         $knownuser = 1;
  113:     } else {
  114:         my $lonhost = $r->dir_config('lonHostID');
  115:         ($captcha_form,$captcha_error,$captcha,$recaptcha_version) =
  116:             &Apache::loncommon::captcha_display('login',$lonhost);
  117:     }
  118:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
  119:                                                  'useremail','useraccount']);
  120: 
  121:     if ($homeserver) {
  122:         $uhome = $env{'user.home'};
  123:         $urole = $env{'request.role'};
  124:         $usec = $env{'request.course.sec'};
  125:         $cid = $env{'request.course.id'};
  126:     }
  127:     if ($cid) {
  128:         $cdom = $env{'course.'.$cid.'.domain'};
  129:         $cnum = $env{'course.'.$cid.'.num'};
  130:     }
  131:     if ($cdom && $cnum) {
  132:         my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
  133:         $ctitle = $csettings{'description'};
  134:         $ccode = $csettings{'internal.coursecode'};
  135:         $sectionlist = $csettings{'internal.sectionnums'};
  136:         my @sections = split(/,/,$sectionlist);
  137:         foreach my $section (@sections) {
  138:            my ($sec,$grp) = split(/:/,$section);
  139:            $groupid{$sec} = $grp;
  140:         }
  141:     }
  142: 
  143:     $formname = 'logproblem';
  144:     my $codedom = &get_domain();
  145:     my %helpform;
  146:     my %domconfig =
  147:          &Apache::lonnet::get_dom('configuration',['contacts'],$codedom);
  148:     if (ref($domconfig{'contacts'}) eq 'HASH') {
  149:         if (ref($domconfig{'contacts'}{'helpform'}) eq 'HASH') {
  150:             %helpform = %{$domconfig{'contacts'}{'helpform'}};
  151:         }
  152:     }
  153: 
  154:     my %codes;
  155:     my @codetitles;
  156:     my %cat_titles;
  157:     my %cat_order;
  158:     my %idlist;
  159:     my %idnums;
  160:     my %idlist_titles;
  161:     my $totcodes = 0;
  162:     my $jscript = '';
  163:     my $loaditems = qq|
  164: function initialize_codes() {
  165:     return;
  166: }
  167:     |;
  168:     unless ($helpform{'course'} eq 'no') {
  169:         my $instcats = &Apache::lonnet::get_dom_instcats($codedom);
  170:         if (ref($instcats) eq 'HASH') {
  171:             if ((ref($instcats->{'codetitles'}) eq 'ARRAY') && (ref($instcats->{'codes'}) eq 'HASH') &&
  172:                 (ref($instcats->{'cat_titles'}) eq 'HASH') && (ref($instcats->{'cat_order'}) eq 'HASH')) {
  173:                 %codes = %{$instcats->{'codes'}};
  174:                 @codetitles = @{$instcats->{'codetitles'}};
  175:                 %cat_titles = %{$instcats->{'cat_titles'}};
  176:                 %cat_order = %{$instcats->{'cat_order'}};
  177:                 $totcodes = scalar(keys(%codes));
  178:             }
  179:             if ($totcodes > 0) {
  180:                 my $numtypes = @codetitles;
  181:                 &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
  182:                 my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
  183:                 my $longtitles_str = join('","',@{$longtitles});
  184:                 my $allidlist = $idlist{$codetitles[0]};
  185:                 my $knowncodes;
  186:                 if (($ccode ne '') && ($cnum ne '')) {
  187:                     my (%singlecodes,@singlecodetitles,%singlecat_titles,%singlecat_order);
  188:                     my $crscode_reply = &Apache::lonnet::auto_instcode_format($cnum,$codedom,{ $cnum => $ccode },\%singlecodes,
  189:                                                                               \@singlecodetitles,\%singlecat_titles,\%singlecat_order);
  190:                     if (ref($singlecodes{$cnum}) eq 'HASH') {
  191:                         $knowncodes = $singlecodes{$cnum};
  192:                     }
  193:                 }
  194:                 $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
  195:                 $jscript .= $scripttext;
  196:                 $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles,$knowncodes,$sectionlist);
  197:                 $loaditems = '';
  198:             }
  199:         }
  200:     }
  201:     my %missing = &Apache::lonlocal::texthash(
  202:                          username   => 'You must include a name.',
  203:                          phone      => 'You must include a phone.',
  204:     );
  205:     &js_escape(\%missing);
  206:     if (keys(%helpform)) {
  207:         foreach my $key (keys(%helpform)) {
  208:             if (($helpform{$key} eq 'req') && ($missing{$key} ne '')) {
  209:                 next if (($key eq 'username') && (($knownuser) ||
  210:                                                   (($env{'user.name'} =~ /^$match_username$/) && (!$public))));
  211:                 $extra_validations .= <<"END";
  212: 
  213:     if (document.$formname.$key.value == '') {
  214:         alert("$missing{$key}");
  215:         return;
  216:     }
  217: 
  218: END
  219:             }
  220:         }
  221:     }
  222:     my $machine = &Apache::lonnet::absolute_url();
  223:     my $sourceurl = $machine.$origurl;
  224:     $server = $machine.&Apache::loncommon::cleanup_html($origurl);
  225:     $server =~ s/\?.*$//;
  226:     my %js_lt = &Apache::lonlocal::texthash (
  227:                   email => 'The e-mail address you entered',
  228:                   notv => 'is not a valid e-mail address',
  229:                   rsub => 'You must include a subject',
  230:                   rdes => 'You must include a description',
  231:     );
  232:     my %html_lt = &Apache::lonlocal::texthash (
  233:                   name => 'Name',
  234:                   subm => 'Submit Request',
  235:                   emad => 'Your e-mail address',
  236:                   emac => 'Cc',
  237:                   unme => 'username',
  238:                   doma => 'domain',
  239:                   entu => 'Enter the username you use to log-in to LON-CAPA',
  240:                   chdo => 'Choose your LON-CAPA domain',
  241:                   entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
  242:                   urlp => 'URL of page',
  243:                   phon => 'Phone',
  244:                   crsd => 'Course Details',
  245:                   enin => 'Enter institutional course code',
  246:                   pick => 'Pick',
  247:                   enct => 'Enter course title',
  248:                   secn => 'Section Number',
  249:                   sele => 'Select',
  250:                   titl => 'Title',
  251:                   lsec => 'LON-CAPA sec',
  252:                   subj => 'Subject',
  253:                   detd => 'Detailed Description',
  254:                   opfi => 'Optional file upload',
  255:                   uplf => 'Upload a file (e.g., a screenshot) relevant to your help request',
  256:                   fini => 'Finish',
  257:                   clfm => 'Clear Form',
  258:     );
  259:     &js_escape(\%js_lt);
  260:     &html_escape(\%html_lt);
  261:     my $scripttag = (<<"END");
  262: function validate() {
  263:     if (validmail(document.logproblem.email) == false) {
  264:         alert("$js_lt{'email'}: "+document.logproblem.email.value+" $js_lt{'notv'}.");
  265:         return;
  266:     }
  267:     if (document.logproblem.subject.value == '') {
  268:         alert("$js_lt{'rsub'}.");
  269:         return;
  270:     }
  271:     if (document.logproblem.description.value == '') {
  272:         alert("$js_lt{'rdes'}.");
  273:         return;
  274:     }
  275:     $extra_validations
  276:     document.logproblem.submit();
  277: }
  278: 
  279: END
  280:     $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
  281: 
  282:     if ($homeserver) {
  283:         if ($env{'environment.permanentemail'}) {
  284:             $email = $env{'environment.permanentemail'};
  285:         } elsif ($env{'environment.critnotification'}) {
  286:             $email = $env{'environment.critnotification'};
  287:         } elsif ($env{'environment.notification'}) {
  288:             $email = $env{'environment.notification'};
  289:         }
  290:         if ($env{'environment.lastname'}) {
  291:             $lastname = $env{'environment.lastname'};
  292:         }
  293:         if ($env{'environment.firstname'}) {
  294:             $firstname = $env{'environment.firstname'};
  295:         }
  296:     }
  297:     if ($env{'form.origurl'} eq '/adm/createaccount') {
  298:         if ($email eq '') {
  299:             if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
  300:                 $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
  301:             }
  302:         }
  303:         if ($uname eq '') {
  304:             if ($env{'form.useraccount'} =~ /^$match_username$/) {
  305:                 $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
  306:             }
  307:         }
  308:     }
  309:     my $details_title;
  310:     if ($codedom) {
  311:         $details_title = '<br />('.$codedom.')';
  312:     }
  313: 
  314:     my $js = <<"ENDJS";
  315: <script type="text/javascript">
  316: // <![CDATA[
  317: $scripttag
  318: $jscript
  319: $loaditems
  320: // ]]>
  321: </script>
  322: <script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>
  323: ENDJS
  324:     if ($recaptcha_version >=2) {
  325:         $js.= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
  326:     }
  327:     my %add_entries = (
  328:                        style    => "margin-top:0px;margin-bottom:0px;",
  329:                        onload   => "initialize_codes();",
  330:                       );
  331: 
  332:     
  333:     $r->print(&Apache::loncommon::start_page('Support Request',$js,
  334: 				       { 'function'    => $function,
  335: 					 'add_entries' => \%add_entries,
  336: 					 'only_body'   => 1,}));
  337:     if ($r->uri eq '/adm/helpdesk') {
  338:         &print_header($r,$origurl);
  339:     }
  340:     my @css = ('LC_evenrow_value','LC_oddrow_value');
  341:     my $num = 1;
  342:     my $i = $num%2;
  343:     my $formtype;
  344:     if ($homeserver) {
  345:         $formtype = ' enctype="multipart/form-data"';
  346:     }
  347:     my $topsubmit = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$html_lt{'subm'}.'" onclick="validate()" />&nbsp;';
  348:     my $shownsubmit;
  349:     $r->print('<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
  350:     my $output = &Apache::lonhtmlcommon::start_pick_box().
  351:                  &Apache::lonhtmlcommon::row_headline().
  352:                  '<span class="LC_info">'.
  353:                  &mt('(All fields marked with * are required.)').
  354:                  '</span>'.
  355:                  &Apache::lonhtmlcommon::row_closure();
  356:     unless ($helpform{'username'} eq 'no') {
  357:         my ($reqd,$namefield,$fullname);
  358:         if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
  359:             $fullname = "$firstname $lastname";
  360:             $namefield = $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
  361:         } else {
  362:             if (defined($firstname) && $firstname ne '') {
  363:                 $fullname = $firstname;
  364:             } elsif (defined($lastname) && $lastname ne '') {
  365:                 $fullname = " $lastname";
  366:             }
  367:             $namefield = '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
  368:             if ($helpform{'username'} eq 'req') {
  369:                 $reqd = '<span class="LC_info">*</span>';
  370:             }
  371:         }
  372:         $output .= &Apache::lonhtmlcommon::row_title($html_lt{'name'}.$reqd,undef,$css[$num])."\n".$namefield.
  373:                    $topsubmit.
  374:                    &Apache::lonhtmlcommon::row_closure()."\n";
  375:         $shownsubmit = 1;
  376:         $num ++;
  377:         $i = $num%2;
  378:     }
  379:     $output .= &Apache::lonhtmlcommon::row_title(
  380:                    '<span title="'.&mt('required').'">'.
  381:                    $html_lt{'emad'}.' <span class="LC_info">*</span></span>'
  382:                   ,undef,$css[$i]).
  383:                '<input type="text" size="20" name="email" value="'.
  384:                &HTML::Entities::encode($email,'"<>&').'" />'."\n";
  385:     unless ($shownsubmit) {
  386:         $output .= $topsubmit;
  387:     }
  388:     $output .= &Apache::lonhtmlcommon::row_closure();
  389:     $num ++;
  390:     $i = $num%2;
  391:     if ($knownuser) {
  392:         if ($homeserver) {
  393:             unless ($helpform{'cc'} eq 'no') {
  394:                 $output .= &Apache::lonhtmlcommon::row_title($html_lt{'emac'},undef,$css[$i]).
  395:                            '<input type="text" size="50" name="cc" value="" /><br />'."\n".
  396:                            &Apache::lonhtmlcommon::row_closure();
  397:                 $num ++;
  398:                 $i = $num%2;
  399:             }
  400:         }
  401:     }
  402:     unless (($helpform{'user'} eq 'no') || ($env{'request.lti.login'})) {
  403:         $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]);
  404:         my $udom_input = '<input type="hidden" name="udom" value="'.
  405:                          &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
  406:         my $uname_input = '<input type="hidden" name="uname" value="'.
  407:                          &HTML::Entities::encode($uname,'"<>&').'" />'."\n";
  408:         if ($knownuser) {
  409:             $output .= '<i>'.$html_lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;<i>'.$html_lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input.$uname_input;
  410:         } else {
  411:             my $udomform = '';
  412:             my $unameform = '';
  413:             if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
  414:                 $output .= $html_lt{'entu'};
  415:             } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { 
  416:                 $output .= $html_lt{'chdo'};
  417:             } else {
  418:                 $output .= $html_lt{'entr'};
  419:             }
  420:             $output .= '<br />'."\n";
  421:             if (!$public) {
  422:                 if ($env{'user.domain'} =~ /^$match_domain$/) {
  423:                     $udomform = '<i>'.$html_lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input;
  424:                 } elsif ($env{'user.name'} =~ /^$match_username$/) {
  425:                     $unameform = '<i>'.$html_lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;'.$uname_input;
  426:                 }
  427:             }
  428:             if ($udomform eq '') {
  429:                 $udomform = '<i>'.$html_lt{'doma'}.'</i>:&nbsp;';
  430:                 $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n";
  431:             }
  432:             if ($unameform eq '') {
  433:                 $unameform= '<i>'.$html_lt{'unme'}.'</i>:&nbsp;<input type="text" size="20" name="uname" value="'.$uname.'" />&nbsp;&nbsp;';
  434:             }
  435:             $output .= $unameform.$udomform;
  436:         }
  437:         $output .= &Apache::lonhtmlcommon::row_closure();
  438:         $num ++;
  439:         $i = $num%2;
  440:     }
  441:     unless ($env{'request.lti.login'}) {
  442:         $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]).
  443:                    $server."\n".'<input type="hidden" name="sourceurl" value="'.
  444:                    &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
  445:                    &Apache::lonhtmlcommon::row_closure();
  446:     }
  447:     unless ($helpform{'phone'} eq 'no') {
  448:         my $reqd;
  449:         if ($helpform{'phone'} eq 'req') {
  450:             $reqd = '<span class="LC_info">*</span>';
  451:         }
  452:         $output .= &Apache::lonhtmlcommon::row_title($html_lt{'phon'}.$reqd,undef,'LC_evenrow_value').
  453:                    '<input type="text" size="15" name="phone" /><br />'."\n".
  454:                    &Apache::lonhtmlcommon::row_closure();
  455:         $num ++;
  456:         $i = $num%2;
  457:     }
  458:     unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) {
  459:         $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]);
  460:         if ($totcodes > 0) {
  461:             my $numtitles = @codetitles;
  462:             if ($numtitles == 0) {
  463:                 $output .= $html_lt{'enin'}.':&nbsp;
  464:                   <input type="text" name="coursecode" size="15" value="" />'."\n";
  465:             } else {
  466:                 my @standardnames = &Apache::loncommon::get_standard_codeitems();
  467:                 my $lasttitle = $numtitles;
  468:                 if ($numtitles > 4) {
  469:                     $lasttitle = 4;
  470:                 }
  471:                 my $onchange;
  472:                 if ($sectionlist) {
  473:                     $onchange = 'toggleSecVis()';
  474:                 }
  475:                 $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
  476:                       '<select name="'.$standardnames[0].'" onchange="courseSet('."'$codetitles[0]'".');'.$onchange.'">'."\n".
  477:                       ' <option value="-1">'.$html_lt{'sele'}."</option>\n";
  478:                 my @items = ();
  479:                 my @longitems = ();
  480:                 if ($idlist{$codetitles[0]} =~ /","/) {
  481:                     @items = split(/","/,$idlist{$codetitles[0]});
  482:                 } else {
  483:                     $items[0] = $idlist{$codetitles[0]};
  484:                 }
  485:                 if (defined($idlist_titles{$codetitles[0]})) {
  486:                     if ($idlist_titles{$codetitles[0]} =~ /","/) {
  487:                         @longitems = split(/","/,$idlist_titles{$codetitles[0]});
  488:                     } else {
  489:                         $longitems[0] = $idlist_titles{$codetitles[0]};
  490:                     }
  491:                     for (my $i=0; $i<@longitems; $i++) {
  492:                         if ($longitems[$i] eq '') {
  493:                             $longitems[$i] = $items[$i];
  494:                         }
  495:                     }
  496:                 } else {
  497:                     @longitems = @items;
  498:                 }
  499:                 for (my $i=0; $i<@items; $i++) {
  500:                     $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
  501:                 }
  502:                 $output .= '</select></td>';
  503:                 for (my $i=1; $i<$numtitles; $i++) {
  504:                     $output .= '<td>'.$codetitles[$i].'<br />'."\n".
  505:                      '<select name="'.$standardnames[$i].'" onchange="courseSet('."'$codetitles[$i]'".');'.$onchange.'">'."\n".
  506:                      '<option value="-1">&lt;-'.$html_lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
  507:                      '</select>'."\n".
  508:                      '</td>'."\n";
  509:                 }
  510:                 $output .= '</tr></table>';
  511:                 if ($numtitles > 4) {
  512:                     $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
  513:                           '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".');'.$onchange.'">'."\n".
  514:                           '<option value="-1">&lt;-'.$html_lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
  515:                           '</select>'."\n";
  516:                 }
  517:             }
  518:         } else {
  519:             $output .= $html_lt{'enin'}.':&nbsp;
  520:                   <input type="text" name="coursecode" size="15" value="" />'."\n";
  521:         }
  522:         my $reqd;
  523:         if ($helpform{'course'} eq 'req') {
  524:              $reqd = '<span class="LC_info">*</span>';
  525:         }
  526:         $output .= '<br />'.$html_lt{'enct'}.$reqd.':&nbsp;
  527:                    <input type="text" name="title" size="25" value="'.
  528:                    &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
  529:         $output .= &Apache::lonhtmlcommon::row_closure();
  530:         $num ++;
  531:         $i = $num%2;
  532:     }
  533:     unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) {
  534:         $output .= &Apache::lonhtmlcommon::row_title($html_lt{'secn'},undef,$css[$i]);
  535:         if ($sectionlist) {
  536:             $output .= "<div id=\"LC_helpdesk_sectionlist\"><select name=\"sectionsel\">\n".
  537:                        "  <option value=\"\" selected=\"selected\">$html_lt{'sele'}</option>\n";
  538:             foreach my $id (sort(keys(%groupid))) {
  539:                 if ($id eq $groupid{$id} || $groupid{$id} eq '') {
  540:                     $output .= "  <option value=".
  541:                                &HTML::Entities::encode($id,'"<>&').
  542:                                " >$id</option>\n";
  543:                 } else {
  544:                     $output .= "  <option value=".
  545:                                &HTML::Entities::encode($id,'"<>&').
  546:                                " >$id - ($html_lt{'lsec'}: $groupid{$id})</option>\n";
  547:                 }
  548:             }
  549:             $output .= '</select></div>'."\n".
  550:                        '<div id="LC_helpdesk_section" style="display:none">'.
  551:                        '<input type="text" name="sectiontxt" size="10" /></div>'."\n";
  552:         } else {
  553:             $output .= '<input type="text" name="section" size="10" />'."\n";
  554:         }
  555:         $output .= &Apache::lonhtmlcommon::row_closure();
  556:         $num ++;
  557:         $i = $num%2;
  558:     }
  559:     $output .= &Apache::lonhtmlcommon::row_title(
  560:                    '<span title="'.&mt('required').'">'.
  561:                    $html_lt{'subj'}.' <span class="LC_info">*</span></span>'
  562:                   ,undef,'LC_oddrow_value').
  563:                '<input type="text" size="40" name="subject" />'."\n".
  564:                &Apache::lonhtmlcommon::row_closure().
  565:                &Apache::lonhtmlcommon::row_title(
  566:                    '<span title="'.&mt('required').'">'.
  567:                    $html_lt{'detd'}.' <span class="LC_info">*</span></span>'
  568:                   ,undef,'LC_evenrow_value').
  569:                '<textarea rows="10" cols="45" name="description" style="word-wrap:normal;">'.
  570:                '</textarea>'."\n".
  571:                &Apache::lonhtmlcommon::row_closure();
  572:     $num ++;
  573:     $i = $num%2; 
  574:     if ($knownuser) {
  575:         if ($homeserver) {
  576:             unless ($helpform{'screenshot'} eq 'no') {
  577:                 my $max = 1048576;
  578:                 my $showmax = 1.00;
  579:                 if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
  580:                     $max *= $helpform{'maxsize'};
  581:                     $showmax = $helpform{'maxsize'};
  582:                 }
  583:                 $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')';
  584:                 $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])
  585:                     .' <input type="file" name="screenshot" class="LC_flUpload" size="20" />'
  586:                     .'<input type="hidden" id="free_space" value="'.$max.'" />'
  587:                     .'<br />'."\n".$html_lt{'uplf'}.$showmax."\n"
  588:                     .&Apache::lonhtmlcommon::row_closure();
  589:                 $num ++;
  590:                 $i = $num%2;
  591:             }
  592:         }
  593:     } else {
  594:         if ($captcha_form) {
  595:             $output .= &Apache::lonhtmlcommon::row_title(
  596:                            '<span title="'.&mt('required').'">'.
  597:                            &mt('Validation').
  598:                            ' <span class="LC_info">*</span></span>'
  599:                       ,undef,$css[$i]).
  600:                        $captcha_form."\n".
  601:                        &Apache::lonhtmlcommon::row_closure();
  602:             $num ++;
  603:             $i = $num%2;
  604:         }
  605:     }
  606:     $output .= &Apache::lonhtmlcommon::row_title($html_lt{'fini'},undef,$css[$i]);
  607:     $output .= <<END;
  608:              <table border="0" cellpadding="8" cellspacing="0">
  609:               <tr>
  610:                <td>
  611:                 <input type="hidden" name="command" value="process" />
  612:                 <input type="button" value="$html_lt{'subm'}" onclick="validate()" /> &nbsp;
  613:                </td>
  614:                <td>&nbsp;</td>
  615:                <td>
  616:                 <input type="reset" value="$html_lt{'clfm'}" />
  617:                </td>
  618:               </tr>
  619:              </table>
  620: END
  621:     $output .= &Apache::lonhtmlcommon::row_closure(1);
  622:     $output .= &Apache::lonhtmlcommon::end_pick_box();
  623:     $r->print(<<END);
  624: $output
  625: </form>
  626: <br />
  627: END
  628:     $r->print(&Apache::loncommon::end_page());
  629:     return;
  630: }
  631: 
  632: sub print_request_receipt {
  633:     my ($r,$url,$function) = @_;
  634:     my $public;
  635:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
  636:         $public = 1;
  637:     }
  638:     my $lonhost = $r->dir_config('lonHostID');
  639:     unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
  640:         my ($captcha_chk,$captcha_error) = 
  641:             &Apache::loncommon::captcha_response('login',$lonhost);
  642:         if ($captcha_chk != 1) {
  643:             $r->print(&Apache::loncommon::start_page('Support request failed',undef,
  644:                                        {'function'    => $function,
  645:                                         'add_entries' => {
  646:                                             topmargin    => "0",
  647:                                             marginheight => "0",
  648:                                         },
  649:                                         'only_body'   => 1,}));
  650:             if ($r->uri eq '/adm/helpdesk') {
  651:                 &print_header($r,$url,'process');
  652:             }
  653:             $r->print(
  654:                 '<h2>'.&mt('Support request failed').'</h2>'.
  655:                       &Apache::lonhtmlcommon::confirm_success(
  656:                         &mt('Validation of the code you entered failed.'),1).
  657:                 '<br /><br />'.
  658:                 &Apache::lonhtmlcommon::actionbox([
  659:                     &mt('[_1]Go back[_2] and try again',
  660:                         '<a href="javascript:history.go(-1)">','</a>')]).
  661:                       &Apache::loncommon::end_page());
  662:             return;
  663:         }
  664:     }
  665:     my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
  666:     my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
  667:     my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
  668:     my @cookievars;
  669:     if ($ENV{'SERVER_PORT'} == 443) {
  670:         @cookievars = ('lonLinkID');
  671:     } else {
  672:         @cookievars = ('lonID');
  673:     }
  674: 
  675:     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
  676:     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  677:     my $defdom = &get_domain();
  678:     my $from = $admin;
  679:     my %helpform;
  680:     my %domconfig =
  681:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
  682:     if (ref($domconfig{'contacts'}) eq 'HASH') {
  683:         if (ref($domconfig{'contacts'}{'helpform'}) eq 'HASH') {
  684:             %helpform = %{$domconfig{'contacts'}{'helpform'}};
  685:         }
  686:     }
  687:     my $reporttime = &Apache::lonlocal::locallocaltime(time);
  688:     my %formvars = (
  689:                      email       => 1,
  690:                      sourceurl   => 1,
  691:                      subject     => 1,
  692:                      description => 1,
  693:                    );
  694:     unless ($helpform{'username'} eq 'no') {
  695:         $formvars{'username'} = 1;
  696:     }
  697:     unless ($helpform{'user'} eq 'no') {
  698:         $formvars{'uname'} = 1;
  699:         $formvars{'udom'} = 1;
  700:     }
  701:     unless ($helpform{'phone'} eq 'no') {
  702:         $formvars{'phone'} = 1;
  703:     }
  704:     unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) {
  705:         $formvars{'section'} = 1;
  706:     }
  707:     unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) {
  708:         $formvars{'course'} = 1;
  709:     }
  710:     unless ($helpform{'cc'} eq 'no') {
  711:         $formvars{'cc'} = 1;
  712:     }
  713:     unless ($helpform{'screenshot'} eq 'no') {
  714:         $formvars{'screenshot'} = 1;
  715:     }
  716:     my ($coursecode,$sourceurl);
  717:     if ($formvars{'course'}) {
  718:         $coursecode = $env{'form.coursecode'};
  719:         if ($coursecode eq '') {
  720:             my $totcodes = 0;
  721:             my $instcats = &Apache::lonnet::get_dom_instcats($defdom);
  722:             if (ref($instcats) eq 'HASH') {
  723:                 if (ref($instcats->{'codes'}) eq 'HASH') {
  724:                     $totcodes = scalar(keys(%{$instcats->{'codes'}}));
  725:                 }
  726:             }
  727:             my @standardnames = &Apache::loncommon::get_standard_codeitems();
  728:             if ($totcodes > 0) {
  729:                 my $noregexps = 1;
  730:                 $coursecode = 
  731:                     &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
  732:             }
  733:             if ($coursecode eq '') {
  734:                 foreach my $item (@standardnames) {
  735:                     if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
  736:                         $coursecode .= $env{'form.'.$item};
  737:                     }
  738:                 }
  739:             }
  740:         }
  741:     }
  742:     my %lt = &Apache::lonlocal::texthash (
  743:                  username    => 'Name',
  744:                  email       => 'E-mail',
  745:                  cc          => 'Cc',
  746:                  user        => 'Username/domain',
  747:                  phone       => 'Phone',
  748:                  crsi        => 'Course Information',
  749:                  subject     => 'Subject',
  750:                  description => 'Description',
  751:                  sourceurl   => 'URL',
  752:                  date        => 'Date/Time',
  753:                  secn        => 'Section',
  754:                  warn        => 'Warning: Problem with support e-mail address',
  755:                  your        => 'Your support request contained the following information',
  756:                  sect        => 'section',
  757:                  info        => 'Information supplied',
  758:                  adin        => 'Additional information recorded',
  759:     );
  760: 
  761:     my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$homeserver);
  762:     unless ($public) {
  763:         if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
  764:             $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
  765:                                                       $env{'user.domain'});
  766:         }
  767:     }
  768:     my ($cid,$cdom,$cnum,$sectionlist,$ccode);
  769:     if ($homeserver) {
  770:         $cid = $env{'request.course.id'};
  771:     }
  772:     if ($cid) {
  773:         $cdom = $env{'course.'.$cid.'.domain'};
  774:         $cnum = $env{'course.'.$cid.'.num'};
  775:     }
  776:     if ($cdom && $cnum) {
  777:         my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
  778:         $ccode = $csettings{'internal.coursecode'};
  779:         $sectionlist = $csettings{'internal.sectionnums'};
  780:     }
  781:     if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
  782:         my @ccs;
  783:         if ($env{'form.cc'} =~ /,/) {
  784:             @ccs = split(/,/,$env{'form.cc'});
  785:         } else {
  786:             $env{'form.cc'} =~ s/^\s+//;
  787:             $env{'form.cc'} =~ s/\s+$//;
  788:             @ccs = $env{'form.cc'};
  789:         }
  790:         foreach my $cc (@ccs) {
  791:             $cc =~ s/^\s+//g;
  792:             $cc =~ s/\s+$//g;
  793:             if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
  794:                 if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
  795:                     push(@ok_ccs,$cc);
  796:                 }
  797:             } elsif ($cc ne '') {
  798:                 if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
  799:                     push(@bad_ccs,$cc);
  800:                 }
  801:             }
  802:         }
  803:         if (@ok_ccs > 0) {
  804:            $okcclist = join(', ',@ok_ccs); 
  805:         } 
  806:         if (@bad_ccs == 1) {
  807:             if ($bad_ccs[0] ne '') {
  808:                 $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').&Apache::loncommon::cleanup_html($bad_ccs[0]);
  809:             }
  810:         } elsif (@bad_ccs > 1) {
  811:             $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: '). &Apache::loncommon::cleanup_html(join(', ',@bad_ccs));
  812:         }
  813:     }
  814:     if ($env{'request.lti.login'}) {
  815:         if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
  816:             $env{'form.user'} = "'".$env{'user.name'}.':'.$env{'user.domain'}."'";
  817:         }
  818:         $sourceurl = &Apache::lonnet::absolute_url().$url;
  819:     } else {
  820:         $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
  821:         $sourceurl = $env{'form.sourceurl'};
  822:     }
  823:     if ($formvars{'course'}) {
  824:         $env{'form.crsi'} = $env{'form.title'};
  825:         if ($coursecode ne '') {
  826:             $env{'form.crsi'} .= ' - '.$coursecode;
  827:         }
  828:     }
  829:     if ($formvars{'section'}) {
  830:         my $section;
  831:         if ($sectionlist) {
  832:             if ($coursecode eq $ccode) {
  833:                 $section = $env{'form.sectionsel'}
  834:             } else {
  835:                 $section = $env{'form.sectiontxt'};
  836:             }
  837:         } else {
  838:             $section = $env{'form.section'};
  839:         }
  840:         $env{'form.crsi'} .= ' - '.$lt{'sect'}.': '.$section;
  841:     }
  842:     my $supportmsg;
  843:     if ($formvars{'username'}) {
  844:         $supportmsg .= "$lt{'username'}: $env{'form.username'}\n";
  845:     }
  846:     $supportmsg .= "$lt{'email'}: $env{'form.email'}\n";
  847:     if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
  848:         $supportmsg .= "$lt{'cc'}: $okcclist\n";
  849:     }
  850:     if ($formvars{'user'}) {
  851:         $supportmsg .= "$lt{'user'}: $env{'form.user'}\n";
  852:     }
  853:     if ($formvars{'phone'}) {
  854:         $supportmsg .= "$lt{'phone'}: $env{'form.phone'}\n";
  855:     }
  856:     if ($formvars{'course'}) {
  857:         $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n";
  858:     }
  859:     $supportmsg .= "$lt{'subject'}: $env{'form.subject'}
  860: $lt{'description'}: $env{'form.description'}
  861: $lt{'sourceurl'}: $sourceurl
  862: $lt{'date'}: $reporttime
  863: ";
  864: 
  865:     my $displaymsg;
  866:     foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
  867:         if ($env{'form.'.$item} ne '') {
  868:             if ($item eq 'description') {
  869:                 my $descrip = $env{'form.description'};
  870:                 $descrip =  &Apache::loncommon::cleanup_html($descrip);
  871:                 $descrip =~ s|[\n\r\f]|<br />|g;
  872:                 $displaymsg .= 
  873:                     '<span class="LC_helpform_receipt_cat">'.
  874:                     "$lt{$item}</span>: $descrip<br />\n";
  875:             } elsif ($item eq 'sourceurl') {
  876:                 my $showurl = $env{'form.sourceurl'};
  877:                 $showurl =~ s/\?.*$//;
  878:                 $showurl =  &Apache::loncommon::cleanup_html($showurl);
  879:                 $displaymsg .= 
  880:                     '<span class="LC_helpform_receipt_cat">'.
  881:                     "$lt{$item}</span>: $showurl<br />\n";
  882:             } elsif ($item eq 'cc') {
  883:                 next if ($helpform{'cc'} eq 'no');
  884:                 if ($okcclist) {
  885:                     my $showcclist = &Apache::loncommon::cleanup_html($okcclist);
  886:                     $displaymsg .=
  887:                         '<span class="LC_helpform_receipt_cat">'.
  888:                         "$lt{$item}</span>: $showcclist<br />\n";
  889:                 }
  890:             } else {
  891:                 if (($item eq 'username') || ($item eq 'user') || ($item eq 'phone')) {
  892:                     next if ($helpform{$item} eq 'no');
  893:                 }
  894:                 next if (($item eq 'crsi') && ($helpform{'course'} eq 'no'));
  895:                 next if (($item eq 'user') && ($env{'request.lti.login'}));
  896:                 my $showitem = $env{'form.'.$item};
  897:                 $showitem = &Apache::loncommon::cleanup_html($showitem);
  898:                 $displaymsg .= 
  899:                     '<span class="LC_helpform_receipt_cat">'.
  900:                     "$lt{$item}</span>: $showitem<br />\n";
  901:             }
  902:         }
  903:     }
  904: 
  905:     my ($requname,$requdom,$reqemail);
  906:     foreach my $field ('uname','udom','email') {
  907:         $env{'form.'.$field} =~ s/^\s+//;
  908:         $env{'form.'.$field} =~ s/\s+$//;
  909:     }
  910:     if ($env{'form.uname'} =~ /^$match_username$/) {
  911:         $requname = $env{'form.uname'};
  912:     }
  913:     if ($env{'form.udom'} =~ /^$match_domain$/) {
  914:         $requdom = $env{'form.udom'};
  915:     }
  916:     if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
  917:         $reqemail = $env{'form.email'};
  918:     }
  919: 
  920:     my $dom_in_effect;
  921:     unless ($env{'user.domain'} eq 'public') {
  922:         $dom_in_effect = $env{'user.domain'};
  923:     }
  924:     if ($dom_in_effect eq '') {
  925:         $dom_in_effect = $requdom;
  926:     }
  927:     if ($dom_in_effect eq '') {
  928:         $dom_in_effect = $defdom;
  929:     }
  930: 
  931:     $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
  932:                    $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
  933: 
  934:     my $start_page = 
  935: 	&Apache::loncommon::start_page('Support request recorded',undef,
  936: 				       {'function'    => $function,
  937: 					'add_entries' => {
  938: 					    topmargin    => "0",
  939: 					    marginheight => "0",
  940: 					},
  941: 					'only_body'   => 1,});
  942: 
  943:     $r->print(<<"END");
  944: $start_page
  945: <form name="logproblem" action="">
  946: <input type="hidden" name="command" value="result" />
  947: </form>
  948: END
  949:     if ($r->uri eq '/adm/helpdesk') {
  950:         &print_header($r,$url,'process');
  951:     }
  952:     my $bad_email = 0;
  953:     my ($to,$bcc,$addtext) =
  954:         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
  955:                                                  $dom_in_effect,$origmail,
  956:                                                  $requname,$requdom,
  957:                                                  $reqemail);
  958:     if ($to =~ /,/) {
  959:         my @ok_email; 
  960:         foreach my $email (split(/,/,$to)) {
  961:             if ($email =~ m/^[^\@]+\@[^\@]+$/) {
  962:                 if (!grep(/^\Q$email\E$/,@ok_email)) {
  963:                     push(@ok_email,$email);
  964:                 }
  965:             }
  966:         }
  967:         if (@ok_email > 0) {
  968:             $to = join(',',@ok_email);
  969:         } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
  970:             $to = $admin;
  971:         } else {
  972:             $bad_email = 1;
  973:         }
  974:     } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
  975:         if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
  976:             $to = $admin;
  977:         } else {
  978:             $bad_email = 1;
  979:         }
  980:     }
  981: 
  982:     my $message;
  983:     if (!$bad_email) {
  984:         $message = &Apache::lonhtmlcommon::confirm_success(
  985:             &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>'));
  986:     } else {
  987:         $message = &Apache::lonhtmlcommon::confirm_success(
  988:             $lt{'warn'}.'<br />'
  989:            .&mt('As the e-mail address provided for this LON-CAPA server ([_1]) does not appear to be a valid e-mail address, your support request has [_2]not[_3] been sent to the LON-CAPA support staff or administrator at your institution.','<tt>'.$to.'</tt>','<b>','</b>')
  990:            .' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.'),1); 
  991:         $to = 'helpdesk@lon-capa.org';
  992:     }
  993:     $r->print(&Apache::loncommon::confirmwrapper($message));
  994: 
  995:     if ($reqemail ne '') {
  996:         $from = $reqemail;
  997:     }
  998: 
  999:     if (defined($env{'form.cc'})) {
 1000:         if ($badccmsg) {
 1001:             $displaymsg .= $badccmsg;
 1002:         }
 1003:     }
 1004: 
 1005:     my $subject = $env{'form.subject'};
 1006:     $subject =~ s/(`)/'/g;
 1007:     $subject =~ s/\$/\(\$\)/g;
 1008:     $supportmsg =~ s/(`)/'/g;
 1009:     $supportmsg =~ s/\$/\(\$\)/g;
 1010:     $displaymsg =~ s/(`)/'/g;
 1011:     $displaymsg =~ s/\$/\(\$\)/g;
 1012:     my $fname;
 1013: 
 1014:     my $attachmentpath = '';
 1015:     my $showsize = '';
 1016: 
 1017:     if ((defined($env{'user.name'})) && (!$public)) {
 1018:         if ($homeserver && $env{'form.screenshot.filename'}) {
 1019:             unless ($helpform{'screenshot'} eq 'no') {
 1020:                 my $attachmentsize = length($env{'form.screenshot'});
 1021:                 my $max = 1048576;
 1022:                 my $showmax = 1.00;
 1023:                 if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
 1024:                     $max *= $helpform{'maxsize'};
 1025:                     $showmax = $helpform{'maxsize'};
 1026:                 }
 1027:                 $showmax = '('.sprintf("%.2f",$showmax).' MB)';
 1028:                 $showsize = $attachmentsize/1048576;
 1029:                 $showsize = '('.sprintf("%.2f",$showsize).' MB)';
 1030:                 if ($attachmentsize > $max) {
 1031:                     $displaymsg .= '<br /><span class="LC_warning">'.
 1032:                                    &mt('The uploaded screenshot file [_1] included with your request exceeded the maximum allowed size [_2], and has therefore been discarded.',$showsize,$showmax).'</span>';
 1033:                 } else {
 1034:                     $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
 1035:                 }
 1036:             }
 1037:         }
 1038:     }
 1039: 
 1040:     my %cookies;
 1041:     my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
 1042:     if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
 1043:         $cookies{'lonID'} = $1;
 1044:     }
 1045:     if ($$cookie{'lonLinkID'} =~ /lonLinkID=([a-f0-9]+_linked);/) {
 1046:         $cookies{'lonLinkID'} = $1;
 1047:     }
 1048:     my $lti_info;
 1049:     if (($env{'request.lti.login'}) && ($env{'request.course.id'})) {
 1050:         my $ltidom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1051:         if ($ltidom) {
 1052:             my %lti = &Apache::lonnet::get_domain_lti($ltidom,'provider');
 1053:             if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
 1054:                 if ($lti{$env{'request.lti.login'}}{'consumer'}) {
 1055:                     $lti_info = "LTI consumer: ".$lti{$env{'request.lti.login'}}{'consumer'}."\n";
 1056:                 }
 1057:             }
 1058:         }
 1059:     }
 1060:     if ($attachmentpath =~ m-/([^/]+)$-) {
 1061:         $fname = $1;
 1062:         $displaymsg .= '<br />'
 1063:                       .&mt('An uploaded screenshot file [_1] was included in the request sent by [_2].'
 1064:                           ,'<span class="LC_filename">'.$fname.'</span>&nbsp;'.$showsize,
 1065:                           ,$env{'user.name'}.':'.$env{'user.domain'}
 1066:                        );
 1067:         $supportmsg .= "\n";
 1068:         foreach my $var (@cookievars) {
 1069:             $supportmsg .= "$var: $cookies{$var}\n";
 1070:         }
 1071:         foreach my $var(@ENVvars) {
 1072:             $supportmsg .= "$var: $ENV{$var}\n";
 1073:         }
 1074:         foreach my $var (@envvars) {
 1075:             $supportmsg .= "$var: $env{$var}\n";
 1076:         }
 1077:         if ($lti_info) {
 1078:             $supportmsg .= $lti_info;
 1079:         }
 1080:     }
 1081: 
 1082:     my $cc_string;
 1083:     if ($homeserver) {
 1084:         if (@ok_ccs > 0) {
 1085:             $cc_string = join(', ',@ok_ccs);
 1086:         }
 1087:     }
 1088: 
 1089:     my $attachment_text = '';
 1090:     unless ($homeserver && $attachmentpath) {
 1091:         foreach my $var (@cookievars) {
 1092:             $attachment_text .= "$var: $cookies{$var}\n";
 1093:         }
 1094:         foreach my $var (@ENVvars) {
 1095:             $attachment_text .= "$var: $ENV{$var}\n";
 1096:         }
 1097:         foreach my $var (@envvars) {
 1098:             $attachment_text .= "$var: $env{$var}\n";
 1099:         }
 1100:         foreach my $var (@loncvars) {
 1101:             $attachment_text .= "$var: $env{$var}\n";
 1102:         }
 1103:         if ($lti_info) {
 1104:             $attachment_text .= $lti_info;
 1105:         }
 1106:     }
 1107: 
 1108:     if ($addtext) {
 1109:         my ($addloc,$addstr) = split(/:/,$addtext,2);
 1110:         $addstr = &unescape($addstr);
 1111:         if ($addloc eq 's') {
 1112:             $subject = $addstr.' '.$subject;
 1113:         } elsif ($addloc eq 'b') {
 1114:             $supportmsg = $addstr."\n".$supportmsg;
 1115:         }
 1116:     }
 1117: 
 1118:     # Compose and send a MIME email
 1119:     &Apache::loncommon::mime_email($from, $to, $subject, $supportmsg, $cc_string, $bcc, 
 1120:                                     $attachmentpath, $fname, $attachment_text);
 1121: 
 1122:     if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
 1123:         unlink($attachmentpath);
 1124:     }
 1125:     $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
 1126:     $r->print('<div style="width:620px;">'.
 1127:               &Apache::lonhtmlcommon::start_pick_box().
 1128:               &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
 1129:               &Apache::lonhtmlcommon::row_closure().
 1130:               &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
 1131:     my $envmsg;
 1132:     foreach my $var (@cookievars) {
 1133:         if ($cookies{$var} ne '') {
 1134:             $envmsg.= '<span class="LC_helpform_receipt_cat">'.
 1135:                       $var.'</span>:&nbsp;'.$cookies{$var}.', ';
 1136:         }
 1137:     }
 1138:     foreach my $var (@ENVvars) {
 1139:         if ($ENV{$var} ne '') {
 1140:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
 1141:                        $var.'</span>:&nbsp;'.$ENV{$var}.', ';
 1142:         }
 1143:     }
 1144:     foreach my $var (@envvars) {
 1145:         if ($env{$var} ne '') { 
 1146:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
 1147:                        $var.'</span>:&nbsp;'.$env{$var}.', ';
 1148:         }
 1149:     }
 1150:     $envmsg =~ s/, $//;
 1151:     $r->print($envmsg."\n".
 1152:               &Apache::lonhtmlcommon::row_closure(1)."\n".
 1153:               &Apache::lonhtmlcommon::end_pick_box().
 1154:               "</div>\n".
 1155:               &Apache::loncommon::end_page());
 1156: }
 1157: 
 1158: sub print_header {
 1159:     my ($r,$origurl,$command) = @_;
 1160:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
 1161:     my ($component_url);
 1162:     my $helpdesk_link = '<a href="javascript:validate()">';
 1163:     if ($command eq 'process') {
 1164:         $helpdesk_link = '<a href="/adm/helpdesk">';
 1165:     }
 1166:     my %lt = &Apache::lonlocal::texthash (
 1167:                                            login    => 'Log-in help',
 1168:                                            ask      => 'Ask helpdesk',
 1169:                                            getst    => 'Getting started guide',
 1170:                                            back     => 'Back to last location',
 1171:                                            headline => 'help/support',
 1172:                                            stud     => 'Students',
 1173:                                            ifyo     => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',
 1174:                                            cont     => 'Contact your instructor instead.',
 1175:                                          );
 1176:     my ($getstartlink,$reviewtext);
 1177:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
 1178:         $getstartlink = qq|<td align="center">&nbsp;<b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
 1179:         $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
 1180:     } else {
 1181:         $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
 1182:     }
 1183:     my $linkback;
 1184:     if ($origurl eq '') {
 1185:         $linkback = 'javascript:history.go(-1)';
 1186:     } else {
 1187:         $linkback = &HTML::Entities::encode($origurl,'"<>&');
 1188:     }
 1189:     my $loginhelp = &Apache::lonauth::loginhelpdisplay();
 1190:     if ($loginhelp eq '') {
 1191:         $loginhelp = '/adm/loginproblems.html';
 1192:     }
 1193:     $r->print(<<"END");
 1194: <table width="620" border="0" cellspacing="0" cellpadding="0" style="height: 55px;">
 1195:  <tr>
 1196:    <td width="5" height="50">&nbsp;</td>
 1197:    <td height="50">
 1198:     <fieldset>
 1199:       <legend>
 1200:         <img src="$location/lonIcons/minilogo.gif" height="20" width="29" alt="logo" style="vertical-align:bottom" />
 1201:         LON-CAPA $lt{'headline'}
 1202:       </legend>
 1203:  <table id="LC_helpmenu_links">
 1204:    <tr>
 1205:     <td align="center"><span class="LC_nobreak"><img src="$location/help/help.png" border="0" alt="($lt{'login'})" style="vertical-align:middle" />&nbsp;<b><a href="$loginhelp">$lt{'login'}</a></b>&nbsp;</span></td>
 1206:     <td align="center"><span class="LC_nobreak">&nbsp;<b>$helpdesk_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="($lt{'ask'})" style="vertical-align:middle" />&nbsp;$lt{'ask'}</a></b>&nbsp;</span></td>$getstartlink
 1207:     <td align="center"><span class="LC_nobreak">&nbsp;<b><a href="$linkback" target="_top"><img src="$location/lonIcons/move_up.gif" border="0" alt="($lt{'back'})" style="vertical-align:middle" />&nbsp;$lt{'back'}</a></b>&nbsp;</span></td>
 1208:    </tr>
 1209:  </table>
 1210: </fieldset>
 1211:   </td>
 1212:   <td width="5">&nbsp;</td>
 1213:  </tr>
 1214:  <tr>
 1215:   <td colspan="3" height="5">&nbsp;</td>
 1216:  </tr>
 1217: END
 1218:     if  ($command ne 'process') {
 1219:         my $stuwarn = &mt('Do [_1]not[_2] use this form to ask about course content.',
 1220:                           '<b>','</b>');
 1221:         $r->print(<<"END");
 1222:  <tr>
 1223:   <td colspan="3">$reviewtext 
 1224:   $lt{'ifyo'}
 1225: <p class="LC_info">
 1226: <b>$lt{'stud'}:</b> 
 1227: $stuwarn $lt{'cont'}
 1228: </p><br />
 1229:   </td>
 1230:  </tr>
 1231: END
 1232:     }
 1233:     $r->print('
 1234: </table>');
 1235:     return;
 1236: }
 1237: 
 1238: sub get_domain {
 1239:     my $codedom;
 1240:     if (exists($env{'form.codedom'})) {
 1241:         if (&Apache::lonnet::domain($env{'form.codedom'}) ne '') {
 1242:             return $env{'form.codedom'};
 1243:         }
 1244:     }
 1245:     if ($env{'request.course.id'}) {
 1246:         $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1247:     } elsif ($env{'request.role.domain'}) {
 1248:         $codedom = $env{'request.role.domain'};
 1249:     } else {
 1250:         $codedom = &Apache::lonnet::default_login_domain();
 1251:     }
 1252:     return $codedom;
 1253: }
 1254: 
 1255: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>