File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.108: download - view: text, annotated - select for diffs
Tue Feb 25 05:35:26 2025 UTC (4 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- WCAG 2 compliance.

    1: # The LearningOnline Network with CAPA
    2: # Helpdesk request form
    3: #
    4: # $Id: lonsupportreq.pm,v 1.108 2025/02/25 05:35:26 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: ENDJS
  323:     if ($knownuser) {
  324:         $js .="\n".'<script type="text/javascript" src="/res/adm/includes/file_upload.js"></script>';
  325:     } elsif ($recaptcha_version >=2) {
  326:         $js.= "\n".'<script src="https://www.google.com/recaptcha/api.js"></script>'."\n";
  327:     }
  328:     my %add_entries = (
  329:                        style    => "margin-top:0px;margin-bottom:0px;",
  330:                        onload   => "initialize_codes();",
  331:                       );
  332: 
  333:     my $args = { 'function'    => $function,
  334:                  'add_entries' => \%add_entries,
  335:                  'only_body'   => 1,};
  336:     unless (($knownuser) || ($public)) {
  337:         (undef,undef,undef,my $clientmathml,my $clientunicode) =
  338:             &Apache::loncommon::decode_user_agent();
  339:         if ($clientunicode && !$clientmathml) {
  340:             $args->{'browser.unicode'} = 1;
  341:         }
  342:     }
  343:     $r->print(&Apache::loncommon::start_page('Support Request',$js,$args));
  344:     if ($r->uri eq '/adm/helpdesk') {
  345:         &print_header($r,$origurl);
  346:     }
  347:     my @css = ('LC_evenrow_value','LC_oddrow_value');
  348:     my $num = 1;
  349:     my $i = $num%2;
  350:     my $formtype;
  351:     if ($homeserver) {
  352:         $formtype = ' enctype="multipart/form-data"';
  353:     }
  354:     my $topsubmit = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$html_lt{'subm'}.'" onclick="validate()" />&nbsp;';
  355:     my $shownsubmit;
  356:     $r->print('<div class="LC_landmark" role="main">'."\n".
  357:               '<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
  358:     my $output = &Apache::lonhtmlcommon::start_pick_box().
  359:                  &Apache::lonhtmlcommon::row_headline().
  360:                  '<span class="LC_info">'.
  361:                  &mt('(All fields marked with [_1]*[_2] are required.)',
  362:                      '<span class="LC_parm_part">','</span>').
  363:                  '</span>'.
  364:                  &Apache::lonhtmlcommon::row_closure();
  365:     unless ($helpform{'username'} eq 'no') {
  366:         my ($reqd,$aria_reqd,$namefield,$fullname);
  367:         if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
  368:             $fullname = "$firstname $lastname";
  369:             $namefield = $fullname.'<input type="hidden" name="username" id="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
  370:         } else {
  371:             if (defined($firstname) && $firstname ne '') {
  372:                 $fullname = $firstname;
  373:             } elsif (defined($lastname) && $lastname ne '') {
  374:                 $fullname = " $lastname";
  375:             }
  376:             if ($helpform{'username'} eq 'req') {
  377:                 $reqd = '<span class="LC_parm_part">*</span>';
  378:                 $aria_reqd = 'aria-required="true" ';
  379:             }
  380:             $namefield = '<input type="text" size="20" name="username" id="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" '.$aria_reqd.'/>'."\n";
  381:         }
  382:         my $title = '<label for="username">'.$html_lt{'name'}.'</label>';
  383:         $output .= &Apache::lonhtmlcommon::row_title($title.$reqd,undef,$css[$num])."\n".$namefield.
  384:                    $topsubmit.
  385:                    &Apache::lonhtmlcommon::row_closure()."\n";
  386:         $shownsubmit = 1;
  387:         $num ++;
  388:         $i = $num%2;
  389:     }
  390:     $output .= &Apache::lonhtmlcommon::row_title(
  391:                    '<span title="'.&mt('required').'">'.
  392:                    '<label for="email">'.$html_lt{'emad'}.
  393:                    '</label><span class="LC_parm_part">*</span></span>'
  394:                   ,undef,$css[$i]).
  395:                '<input type="text" size="20" name="email" id="email" value="'.
  396:                &HTML::Entities::encode($email,'"<>&').'" aria-required="true" />'."\n";
  397:     unless ($shownsubmit) {
  398:         $output .= $topsubmit;
  399:     }
  400:     $output .= &Apache::lonhtmlcommon::row_closure();
  401:     $num ++;
  402:     $i = $num%2;
  403:     if ($knownuser) {
  404:         if ($homeserver) {
  405:             my $ip = &Apache::lonnet::get_requestor_ip($r);
  406:             my %setters;
  407:             my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
  408:                 &Apache::loncommon::blockcheck(\%setters,'com',$ip);
  409:             unless (($helpform{'cc'} eq 'no') || ($by_ip)) {
  410:                 $output .= &Apache::lonhtmlcommon::row_title('<label for="cc">'.$html_lt{'emac'}.'</label>',
  411:                                                              undef,$css[$i]).
  412:                            '<input type="text" size="50" name="cc" id="cc" value="" /><br />'."\n".
  413:                            &Apache::lonhtmlcommon::row_closure();
  414:                 $num ++;
  415:                 $i = $num%2;
  416:             }
  417:         }
  418:     }
  419:     unless (($helpform{'user'} eq 'no') || ($env{'request.lti.login'})) {
  420:         $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'unme'}/$html_lt{'doma'}",undef,$css[$i]);
  421:         my $udom_input = '<input type="hidden" name="udom" value="'.
  422:                          &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
  423:         my $uname_input = '<input type="hidden" name="uname" value="'.
  424:                          &HTML::Entities::encode($uname,'"<>&').'" />'."\n";
  425:         if ($knownuser) {
  426:             $output .= '<span class="LC_nobreak"><span class="LC_cusr_emph">'.$html_lt{'unme'}
  427:                       .'</span>:&nbsp;'.$uname.'&nbsp;&nbsp;<span class="LC_cusr_emph">'
  428:                       .$html_lt{'doma'}.'</span>:&nbsp;'.$udom.$udom_input.$uname_input.'</span>';
  429:         } else {
  430:             my $udomform = '';
  431:             my $unameform = '';
  432:             if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
  433:                 $output .= $html_lt{'entu'};
  434:             } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { 
  435:                 $output .= $html_lt{'chdo'};
  436:             } else {
  437:                 $output .= $html_lt{'entr'};
  438:             }
  439:             $output .= '<br />'."\n";
  440:             if (!$public) {
  441:                 if ($env{'user.domain'} =~ /^$match_domain$/) {
  442:                     $udomform = '<span class="LC_cusr_emph">'.$html_lt{'doma'}.'</span>:&nbsp;'.$udom.$udom_input;
  443:                 } elsif ($env{'user.name'} =~ /^$match_username$/) {
  444:                     $unameform = '<span class="LC_cusr_emph">'.$html_lt{'unme'}.'</span>:&nbsp;'.$uname.'&nbsp;&nbsp;'.$uname_input;
  445:                 }
  446:             }
  447:             if ($udomform eq '') {
  448:                 $udomform = '<span class="LC_nobreak"><span class="LC_cusr_emph"><label for="udom">'
  449:                            .$html_lt{'doma'}.'</label></span>:&nbsp;'
  450:                            .&Apache::loncommon::select_dom_form($codedom,'udom','','','','','','','udom')."</span>\n";
  451:             }
  452:             if ($unameform eq '') {
  453:                 $unameform= '<span class="LC_nobreak"><span class="LC_cusr_emph"><label for="uname">'
  454:                            .$html_lt{'unme'}.'</label></span>:&nbsp;'
  455:                            .'<input type="text" size="20" name="uname" id="uname" value="'.$uname.'" />'
  456:                            .'&nbsp;&nbsp;</span>';
  457:             }
  458:             $output .= $unameform.$udomform;
  459:         }
  460:         $output .= &Apache::lonhtmlcommon::row_closure();
  461:         $num ++;
  462:         $i = $num%2;
  463:     }
  464:     unless ($env{'request.lti.login'}) {
  465:         $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'urlp'}",undef,$css[$i]).
  466:                    $server."\n".'<input type="hidden" name="sourceurl" value="'.
  467:                    &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
  468:                    &Apache::lonhtmlcommon::row_closure();
  469:     }
  470:     unless ($helpform{'phone'} eq 'no') {
  471:         my ($reqd,$aria_reqd);
  472:         if ($helpform{'phone'} eq 'req') {
  473:             $reqd = '<span class="LC_parm_part">*</span>';
  474:             $aria_reqd = 'aria-required="true" ';
  475:         }
  476:         $output .= &Apache::lonhtmlcommon::row_title('<label for="phone">'.$html_lt{'phon'}.'</label>'.$reqd,undef,'LC_evenrow_value').
  477:                    '<input type="text" size="15" name="phone" id="phone" '.$aria_reqd.'/><br />'."\n".
  478:                    &Apache::lonhtmlcommon::row_closure();
  479:         $num ++;
  480:         $i = $num%2;
  481:     }
  482:     unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) {
  483:         $output .= &Apache::lonhtmlcommon::row_title("$html_lt{'crsd'}$details_title",undef,$css[$i]);
  484:         if ($totcodes > 0) {
  485:             my $numtitles = @codetitles;
  486:             if ($numtitles == 0) {
  487:                 $output .= '<label>'.$html_lt{'enin'}.':&nbsp;
  488:                   <input type="text" name="coursecode" size="15" value="'.&HTML::Entities::encode($ccode,'\'"&<>').'" /></label>'."\n";
  489:             } else {
  490:                 my @standardnames = &Apache::loncommon::get_standard_codeitems();
  491:                 my $lasttitle = $numtitles;
  492:                 if ($numtitles > 4) {
  493:                     $lasttitle = 4;
  494:                 }
  495:                 my $onchange;
  496:                 if ($sectionlist) {
  497:                     $onchange = 'toggleSecVis()';
  498:                 }
  499:                 $output .= '<table><tr>';
  500:                 for (my $i=0; $i<$lasttitle; $i++) {
  501:                     $output .= '<th><label for="'.$standardnames[$i].'_'.$i.'">'.$codetitles[0].'</label></th>';
  502:                 }
  503:                 $output .= '</tr>';
  504:                 $output .= '<tr><td>'.
  505:                       '<select name="'.$standardnames[0].'" id="'.$standardnames[0].'_0" onchange="courseSet('."'$codetitles[0]'".');'.$onchange.'">'."\n".
  506:                       ' <option value="-1">'.$html_lt{'sele'}."</option>\n";
  507:                 my @items = ();
  508:                 my @longitems = ();
  509:                 if ($idlist{$codetitles[0]} =~ /","/) {
  510:                     @items = split(/","/,$idlist{$codetitles[0]});
  511:                 } else {
  512:                     $items[0] = $idlist{$codetitles[0]};
  513:                 }
  514:                 if (defined($idlist_titles{$codetitles[0]})) {
  515:                     if ($idlist_titles{$codetitles[0]} =~ /","/) {
  516:                         @longitems = split(/","/,$idlist_titles{$codetitles[0]});
  517:                     } else {
  518:                         $longitems[0] = $idlist_titles{$codetitles[0]};
  519:                     }
  520:                     for (my $i=0; $i<@longitems; $i++) {
  521:                         if ($longitems[$i] eq '') {
  522:                             $longitems[$i] = $items[$i];
  523:                         }
  524:                     }
  525:                 } else {
  526:                     @longitems = @items;
  527:                 }
  528:                 for (my $i=0; $i<@items; $i++) {
  529:                     $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
  530:                 }
  531:                 $output .= '</select></td>';
  532:                 for (my $i=1; $i<$lasttitle; $i++) {
  533:                     $output .= '<td>'."\n".
  534:                      '<select name="'.$standardnames[$i].'" id="'.$standardnames[$i].'_'.$i.'" onchange="courseSet('."'$codetitles[$i]'".');'.$onchange.'">'."\n".
  535:                      '<option value="-1">&lt;-'.$html_lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
  536:                      '</select>'."\n".
  537:                      '</td>'."\n";
  538:                 }
  539:                 $output .= '</tr></table>';
  540:                 if ($numtitles > 4) {
  541:                     $output .= '<br /><br /><label>'.$codetitles[$numtitles].'<br />'."\n".
  542:                           '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".');'.$onchange.'">'."\n".
  543:                           '<option value="-1">&lt;-'.$html_lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
  544:                           '</select></label>'."\n";
  545:                 }
  546:             }
  547:         } else {
  548:             $output .= '<label>'.$html_lt{'enin'}.':&nbsp;
  549:                   <input type="text" name="coursecode" size="15" value="" /></label>'."\n";
  550:         }
  551:         my ($reqd,$aria_reqd);
  552:         if ($helpform{'course'} eq 'req') {
  553:              $reqd = '<span class="LC_parm_part">*</span>';
  554:              $aria_reqd = 'aria-required="true" ';
  555:         }
  556:         $output .= '<br /><div><label>'.$html_lt{'enct'}.$reqd.':&nbsp;
  557:                    <input type="text" name="title" size="25" value="'.
  558:                    &HTML::Entities::encode($ctitle,'"<>&').'" '.$aria_reqd.'/></label></div>'."\n";
  559:         $output .= &Apache::lonhtmlcommon::row_closure();
  560:         $num ++;
  561:         $i = $num%2;
  562:     }
  563:     unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) {
  564:         $output .= &Apache::lonhtmlcommon::row_title('<label for="section">'.$html_lt{'secn'}.'</label>',
  565:                                                      undef,$css[$i]);
  566:         if ($sectionlist) {
  567:             $output .= "<div id=\"LC_helpdesk_sectionlist\">\n".
  568:                        "<select name=\"sectionsel\" id=\"section\">\n".
  569:                        "  <option value=\"\" selected=\"selected\">$html_lt{'sele'}</option>\n";
  570:             foreach my $id (sort(keys(%groupid))) {
  571:                 if ($id eq $groupid{$id} || $groupid{$id} eq '') {
  572:                     $output .= "  <option value=".
  573:                                &HTML::Entities::encode($id,'"<>&').
  574:                                " >$id</option>\n";
  575:                 } else {
  576:                     $output .= "  <option value=".
  577:                                &HTML::Entities::encode($id,'"<>&').
  578:                                " >$id - ($html_lt{'lsec'}: $groupid{$id})</option>\n";
  579:                 }
  580:             }
  581:             $output .= '</select></div>'."\n".
  582:                        '<div id="LC_helpdesk_section" style="display:none">'.
  583:                        '<input type="text" name="sectiontxt" id="notinuse" size="10" /></div>'."\n";
  584:         } else {
  585:             $output .= '<input type="text" name="section" id="section" size="10" />'."\n";
  586:         }
  587:         $output .= &Apache::lonhtmlcommon::row_closure();
  588:         $num ++;
  589:         $i = $num%2;
  590:     }
  591:     $output .= &Apache::lonhtmlcommon::row_title(
  592:                    '<span title="'.&mt('required').'">'.
  593:                    '<label for="subject">'.$html_lt{'subj'}.'</label>'.
  594:                    '<span class="LC_parm_part">*</span></span>'
  595:                   ,undef,'LC_oddrow_value').
  596:                '<input type="text" size="40" name="subject" id="subject" aria-required="true" />'."\n".
  597:                &Apache::lonhtmlcommon::row_closure().
  598:                &Apache::lonhtmlcommon::row_title(
  599:                    '<span title="'.&mt('required').'">'.
  600:                    '<label for="description">'.$html_lt{'detd'}.'</label>'.
  601:                    '<span class="LC_parm_part">*</span></span>'
  602:                   ,undef,'LC_evenrow_value').
  603:                '<textarea rows="10" cols="45" name="description" id="description" style="word-wrap:normal;" aria-required="true">'.
  604:                '</textarea>'."\n".
  605:                &Apache::lonhtmlcommon::row_closure();
  606:     $num ++;
  607:     $i = $num%2; 
  608:     if ($knownuser) {
  609:         if ($homeserver) {
  610:             unless ($helpform{'screenshot'} eq 'no') {
  611:                 my $max = 1048576;
  612:                 my $showmax = 1.00;
  613:                 if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
  614:                     $max *= $helpform{'maxsize'};
  615:                     $showmax = $helpform{'maxsize'};
  616:                 }
  617:                 $showmax = ' ('.sprintf("%.2f",$showmax).' '.&mt('MB max.').')';
  618:                 $output .= &Apache::lonhtmlcommon::row_title($html_lt{'opfi'},undef,$css[$i])
  619:                     .'<input type="file" name="screenshot" id="screenshot" class="LC_flUpload" size="20" />'
  620:                     .'<input type="hidden" id="LC_free_space" value="'.$max.'" />'
  621:                     .'<br />'."\n".'<label for="screenshot">'.$html_lt{'uplf'}.'</label>'.$showmax."\n"
  622:                     .&Apache::lonhtmlcommon::row_closure();
  623:                 $num ++;
  624:                 $i = $num%2;
  625:             }
  626:         }
  627:     } else {
  628:         if ($captcha_form) {
  629:             $output .= &Apache::lonhtmlcommon::row_title(
  630:                            '<span title="'.&mt('required').'">'.
  631:                            &mt('Validation').
  632:                            '<span class="LC_parm_part">*</span></span>'
  633:                       ,undef,$css[$i]).
  634:                        $captcha_form."\n".
  635:                        &Apache::lonhtmlcommon::row_closure();
  636:             $num ++;
  637:             $i = $num%2;
  638:         }
  639:     }
  640:     $output .= &Apache::lonhtmlcommon::row_title($html_lt{'fini'},undef,$css[$i]);
  641:     $output .= <<END;
  642:              <div>
  643:                <div class="LC_floatleft" style="padding-top:0, padding-left:8px; padding-right:8px; padding-bottom:0; margin:0">
  644:                 <input type="hidden" name="command" value="process" />
  645:                 <input type="button" value="$html_lt{'subm'}" onclick="validate()" /> &nbsp;
  646:                </div>
  647:                <div class="LC_floatleft" style="padding-top:0, padding-left:8px; padding-right:8px; padding-bottom:0; margin:0">
  648:                 <input type="reset" value="$html_lt{'clfm'}" />
  649:                </div>
  650:              </div>
  651:              <div style="padding:0;clear:both;margin:0;border:0"></div>
  652: END
  653:     $output .= &Apache::lonhtmlcommon::row_closure(1);
  654:     $output .= &Apache::lonhtmlcommon::end_pick_box();
  655:     $r->print(<<END);
  656: $output
  657: </form>
  658: <br />
  659: </div>
  660: END
  661:     $r->print(&Apache::loncommon::end_page());
  662:     return;
  663: }
  664: 
  665: sub print_request_receipt {
  666:     my ($r,$url,$function) = @_;
  667:     my $public;
  668:     my $args;
  669:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
  670:         $public = 1;
  671:     }
  672:     my $lonhost = $r->dir_config('lonHostID');
  673:     unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
  674:         my ($captcha_chk,$captcha_error) = 
  675:             &Apache::loncommon::captcha_response('login',$lonhost);
  676:         if ($captcha_chk != 1) {
  677:             $args = {
  678:                      'function'    => $function,
  679:                      'add_entries' => {
  680:                                          topmargin    => "0",
  681:                                          marginheight => "0",
  682:                                       },
  683:                      'only_body'   => 1,};
  684:             (undef,undef,undef,my $clientmathml,my $clientunicode) =
  685:                 &Apache::loncommon::decode_user_agent();
  686:             if ($clientunicode && !$clientmathml) {
  687:                 $args->{'browser.unicode' => 1};
  688:             }
  689:             $r->print(&Apache::loncommon::start_page('Support request failed',undef,$args));
  690:             if ($r->uri eq '/adm/helpdesk') {
  691:                 &print_header($r,$url,'process');
  692:             }
  693:             $r->print(
  694:                 '<div class="LC_landmark" role="main">'.
  695:                 '<h2 class="LC_heading_2">'.&mt('Support request failed').'</h2>'.
  696:                       &Apache::lonhtmlcommon::confirm_success(
  697:                         &mt('Validation of the code you entered failed.'),1).
  698:                 '<br /><br />'.
  699:                 &Apache::lonhtmlcommon::actionbox([
  700:                     &mt('[_1]Go back[_2] and try again',
  701:                         '<a href="javascript:history.go(-1)">','</a>')]).
  702:                 '</div>'.
  703:                 &Apache::loncommon::end_page());
  704:             return;
  705:         }
  706:     }
  707:     my $ip = &Apache::lonnet::get_requestor_ip($r);
  708:     my %setters;
  709:     my ($startblock,$endblock,$triggerblock,$by_ip,$blockdom) =
  710:         &Apache::loncommon::blockcheck(\%setters,'com',$ip);
  711:     my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','SERVER_ADDR','SERVER_NAME');
  712:     my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
  713:     my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
  714:     my @cookievars;
  715:     if ($ENV{'SERVER_PORT'} == 443) {
  716:         @cookievars = ('lonLinkID');
  717:     } else {
  718:         @cookievars = ('lonID');
  719:     }
  720: 
  721:     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
  722:     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  723:     my $defdom = &get_domain();
  724:     my $from = $admin;
  725:     my %helpform;
  726:     my %domconfig =
  727:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
  728:     if (ref($domconfig{'contacts'}) eq 'HASH') {
  729:         if (ref($domconfig{'contacts'}{'helpform'}) eq 'HASH') {
  730:             %helpform = %{$domconfig{'contacts'}{'helpform'}};
  731:         }
  732:     }
  733:     my $reporttime = &Apache::lonlocal::locallocaltime(time);
  734:     my %formvars = (
  735:                      email       => 1,
  736:                      sourceurl   => 1,
  737:                      subject     => 1,
  738:                      description => 1,
  739:                    );
  740:     unless ($helpform{'username'} eq 'no') {
  741:         $formvars{'username'} = 1;
  742:     }
  743:     unless ($helpform{'user'} eq 'no') {
  744:         $formvars{'uname'} = 1;
  745:         $formvars{'udom'} = 1;
  746:     }
  747:     unless ($helpform{'phone'} eq 'no') {
  748:         $formvars{'phone'} = 1;
  749:     }
  750:     unless (($helpform{'section'} eq 'no') || ($env{'request.lti.login'})) {
  751:         $formvars{'section'} = 1;
  752:     }
  753:     unless (($helpform{'course'} eq 'no') || ($env{'request.lti.login'})) {
  754:         $formvars{'course'} = 1;
  755:     }
  756:     unless (($helpform{'cc'} eq 'no') || ($by_ip)) {
  757:         $formvars{'cc'} = 1;
  758:     }
  759:     unless ($helpform{'screenshot'} eq 'no') {
  760:         $formvars{'screenshot'} = 1;
  761:     }
  762:     my ($coursecode,$sourceurl);
  763:     if ($formvars{'course'}) {
  764:         $coursecode = $env{'form.coursecode'};
  765:         if ($coursecode eq '') {
  766:             my $totcodes = 0;
  767:             my $instcats = &Apache::lonnet::get_dom_instcats($defdom);
  768:             if (ref($instcats) eq 'HASH') {
  769:                 if (ref($instcats->{'codes'}) eq 'HASH') {
  770:                     $totcodes = scalar(keys(%{$instcats->{'codes'}}));
  771:                 }
  772:             }
  773:             my @standardnames = &Apache::loncommon::get_standard_codeitems();
  774:             if ($totcodes > 0) {
  775:                 my $noregexps = 1;
  776:                 $coursecode = 
  777:                     &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
  778:             }
  779:             if ($coursecode eq '') {
  780:                 foreach my $item (@standardnames) {
  781:                     if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
  782:                         $coursecode .= $env{'form.'.$item};
  783:                     }
  784:                 }
  785:             }
  786:         }
  787:     }
  788:     my %lt = &Apache::lonlocal::texthash (
  789:                  username    => 'Name',
  790:                  email       => 'E-mail',
  791:                  cc          => 'Cc',
  792:                  user        => 'Username/domain',
  793:                  phone       => 'Phone',
  794:                  crsi        => 'Course Information',
  795:                  subject     => 'Subject',
  796:                  description => 'Description',
  797:                  sourceurl   => 'URL',
  798:                  date        => 'Date/Time',
  799:                  secn        => 'Section',
  800:                  warn        => 'Warning: Problem with support e-mail address',
  801:                  your        => 'Your support request contained the following information',
  802:                  belo        => 'Below is your support request which could not be sent',
  803:                  ifyk        => 'If you know an IT support address for your institution, you could copy this information and send it to that email address.',
  804:                  sect        => 'section',
  805:                  info        => 'Information supplied',
  806:                  adin        => 'Additional information recorded',
  807:     );
  808: 
  809:     my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$homeserver);
  810:     unless ($public) {
  811:         if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
  812:             $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
  813:                                                       $env{'user.domain'});
  814:         }
  815:     }
  816:     my ($cid,$cdom,$cnum,$sectionlist,$ccode);
  817:     if ($homeserver) {
  818:         $cid = $env{'request.course.id'};
  819:     }
  820:     if ($cid) {
  821:         $cdom = $env{'course.'.$cid.'.domain'};
  822:         $cnum = $env{'course.'.$cid.'.num'};
  823:     }
  824:     if ($cdom && $cnum) {
  825:         my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
  826:         $ccode = $csettings{'internal.coursecode'};
  827:         $sectionlist = $csettings{'internal.sectionnums'};
  828:     }
  829:     if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
  830:         my @ccs;
  831:         if ($env{'form.cc'} =~ /,/) {
  832:             @ccs = split(/,/,$env{'form.cc'});
  833:         } else {
  834:             $env{'form.cc'} =~ s/^\s+//;
  835:             $env{'form.cc'} =~ s/\s+$//;
  836:             @ccs = $env{'form.cc'};
  837:         }
  838:         foreach my $cc (@ccs) {
  839:             $cc =~ s/^\s+//g;
  840:             $cc =~ s/\s+$//g;
  841:             if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
  842:                 if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
  843:                     push(@ok_ccs,$cc);
  844:                 }
  845:             } elsif ($cc ne '') {
  846:                 if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
  847:                     push(@bad_ccs,$cc);
  848:                 }
  849:             }
  850:         }
  851:         if (@ok_ccs > 0) {
  852:            $okcclist = join(', ',@ok_ccs); 
  853:         } 
  854:         if (@bad_ccs == 1) {
  855:             if ($bad_ccs[0] ne '') {
  856:                 $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').&Apache::loncommon::cleanup_html($bad_ccs[0]);
  857:             }
  858:         } elsif (@bad_ccs > 1) {
  859:             $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: '). &Apache::loncommon::cleanup_html(join(', ',@bad_ccs));
  860:         }
  861:     }
  862:     if ($env{'request.lti.login'}) {
  863:         if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
  864:             $env{'form.user'} = "'".$env{'user.name'}.':'.$env{'user.domain'}."'";
  865:         }
  866:         $sourceurl = &Apache::lonnet::absolute_url().$url;
  867:     } else {
  868:         $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
  869:         $sourceurl = $env{'form.sourceurl'};
  870:     }
  871:     if ($formvars{'course'}) {
  872:         $env{'form.crsi'} = $env{'form.title'};
  873:         if ($coursecode ne '') {
  874:             $env{'form.crsi'} .= ' - '.$coursecode;
  875:         }
  876:     }
  877:     if ($formvars{'section'}) {
  878:         my $section;
  879:         if ($sectionlist) {
  880:             if ($coursecode eq $ccode) {
  881:                 $section = $env{'form.sectionsel'}
  882:             } else {
  883:                 $section = $env{'form.sectiontxt'};
  884:             }
  885:         } else {
  886:             $section = $env{'form.section'};
  887:         }
  888:         $env{'form.crsi'} .= ' - '.$lt{'sect'}.': '.$section;
  889:     }
  890:     my $supportmsg;
  891:     if ($formvars{'username'}) {
  892:         $supportmsg .= "$lt{'username'}: $env{'form.username'}\n";
  893:     }
  894:     $supportmsg .= "$lt{'email'}: $env{'form.email'}\n";
  895:     if (($homeserver) && (defined($env{'form.cc'})) && ($formvars{'cc'})) {
  896:         $supportmsg .= "$lt{'cc'}: $okcclist\n";
  897:     }
  898:     if ($formvars{'user'}) {
  899:         $supportmsg .= "$lt{'user'}: $env{'form.user'}\n";
  900:     }
  901:     if ($formvars{'phone'}) {
  902:         $supportmsg .= "$lt{'phone'}: $env{'form.phone'}\n";
  903:     }
  904:     if ($formvars{'course'}) {
  905:         $supportmsg .= "$lt{'crsi'}: $env{'form.crsi'}\n";
  906:     }
  907:     $supportmsg .= "$lt{'subject'}: $env{'form.subject'}
  908: $lt{'description'}: $env{'form.description'}
  909: $lt{'sourceurl'}: $sourceurl
  910: $lt{'date'}: $reporttime
  911: ";
  912: 
  913:     my $displaymsg;
  914:     foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
  915:         if ($env{'form.'.$item} ne '') {
  916:             if ($item eq 'description') {
  917:                 my $descrip = $env{'form.description'};
  918:                 $descrip =  &Apache::loncommon::cleanup_html($descrip);
  919:                 $descrip =~ s|[\n\r\f]|<br />|g;
  920:                 $displaymsg .= 
  921:                     '<span class="LC_helpform_receipt_cat">'.
  922:                     "$lt{$item}</span>: $descrip<br />\n";
  923:             } elsif ($item eq 'sourceurl') {
  924:                 my $showurl = $env{'form.sourceurl'};
  925:                 $showurl =~ s/\?.*$//;
  926:                 $showurl =  &Apache::loncommon::cleanup_html($showurl);
  927:                 $displaymsg .= 
  928:                     '<span class="LC_helpform_receipt_cat">'.
  929:                     "$lt{$item}</span>: $showurl<br />\n";
  930:             } elsif ($item eq 'cc') {
  931:                 next if ($helpform{'cc'} eq 'no');
  932:                 if ($okcclist) {
  933:                     my $showcclist = &Apache::loncommon::cleanup_html($okcclist);
  934:                     $displaymsg .=
  935:                         '<span class="LC_helpform_receipt_cat">'.
  936:                         "$lt{$item}</span>: $showcclist<br />\n";
  937:                 }
  938:             } else {
  939:                 if (($item eq 'username') || ($item eq 'user') || ($item eq 'phone')) {
  940:                     next if ($helpform{$item} eq 'no');
  941:                 }
  942:                 next if (($item eq 'crsi') && ($helpform{'course'} eq 'no'));
  943:                 next if (($item eq 'user') && ($env{'request.lti.login'}));
  944:                 my $showitem = $env{'form.'.$item};
  945:                 $showitem = &Apache::loncommon::cleanup_html($showitem);
  946:                 $displaymsg .= 
  947:                     '<span class="LC_helpform_receipt_cat">'.
  948:                     "$lt{$item}</span>: $showitem<br />\n";
  949:             }
  950:         }
  951:     }
  952: 
  953:     my ($requname,$requdom,$reqemail);
  954:     foreach my $field ('uname','udom','email') {
  955:         $env{'form.'.$field} =~ s/^\s+//;
  956:         $env{'form.'.$field} =~ s/\s+$//;
  957:     }
  958:     if ($env{'form.uname'} =~ /^$match_username$/) {
  959:         $requname = $env{'form.uname'};
  960:     }
  961:     if ($env{'form.udom'} =~ /^$match_domain$/) {
  962:         $requdom = $env{'form.udom'};
  963:     }
  964:     if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
  965:         $reqemail = $env{'form.email'};
  966:     }
  967: 
  968:     my $dom_in_effect;
  969:     unless ($env{'user.domain'} eq 'public') {
  970:         $dom_in_effect = $env{'user.domain'};
  971:     }
  972:     if ($dom_in_effect eq '') {
  973:         $dom_in_effect = $requdom;
  974:     }
  975:     if ($dom_in_effect eq '') {
  976:         $dom_in_effect = $defdom;
  977:     }
  978: 
  979:     $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
  980:                    $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
  981:     my $args = {'function'    => $function,
  982:                 'add_entries' => {
  983:                                     topmargin    => "0",
  984:                                     marginheight => "0",
  985:                                  },
  986:                 'only_body'   => 1,};
  987:     (undef,undef,undef,my $clientmathml,my $clientunicode) =
  988:         &Apache::loncommon::decode_user_agent();
  989:     if ($clientunicode && !$clientmathml) {
  990:         $args->{'browser.unicode'} = 1;
  991:     }
  992:     $r->print(&Apache::loncommon::start_page('Support request recorded',undef,$args));
  993:     $r->print(<<"END");
  994: <form name="logproblem" action="">
  995: <input type="hidden" name="command" value="result" />
  996: </form>
  997: END
  998:     if ($r->uri eq '/adm/helpdesk') {
  999:         &print_header($r,$url,'process');
 1000:     }
 1001:     my $bad_email = 0;
 1002:     my ($to,$bcc,$addtext) =
 1003:         &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
 1004:                                                  $dom_in_effect,$origmail,
 1005:                                                  $requname,$requdom,
 1006:                                                  $reqemail);
 1007:     if ($to =~ /,/) {
 1008:         my @ok_email; 
 1009:         foreach my $email (split(/,/,$to)) {
 1010:             if ($email =~ m/^[^\@]+\@[^\@]+$/) {
 1011:                 if (!grep(/^\Q$email\E$/,@ok_email)) {
 1012:                     push(@ok_email,$email);
 1013:                 }
 1014:             }
 1015:         }
 1016:         if (@ok_email > 0) {
 1017:             $to = join(',',@ok_email);
 1018:         } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
 1019:             $to = $admin;
 1020:         } else {
 1021:             $bad_email = 1;
 1022:         }
 1023:     } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
 1024:         if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
 1025:             $to = $admin;
 1026:         } else {
 1027:             $bad_email = 1;
 1028:         }
 1029:     }
 1030: 
 1031:     my $message;
 1032:     if (!$bad_email) {
 1033:         $message = &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>');
 1034:     } else {
 1035:         $message = $lt{'warn'}.'<br />';
 1036:         if ($to eq '') {
 1037:             $message .= &mt('For this LON-CAPA server no e-mail address has been configured to receive support requests, so your support request has [_1]not[_2] been sent to the LON-CAPA support staff or administrator at your institution.','<b>','</b>');
 1038:         } else {
 1039:             $message .= &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>');
 1040:         }
 1041:     }
 1042:     $r->print('<div class="LC_landmark" role="main">');
 1043:     if ($bad_email) {
 1044:         $r->print(&Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($message,$bad_email)).'<br />');
 1045:     }
 1046:     if ($reqemail ne '') {
 1047:         $from = $reqemail;
 1048:     }
 1049: 
 1050:     if (defined($env{'form.cc'})) {
 1051:         if ($badccmsg) {
 1052:             $displaymsg .= $badccmsg;
 1053:         }
 1054:     }
 1055: 
 1056:     my $subject = $env{'form.subject'};
 1057:     $subject =~ s/(`)/'/g;
 1058:     $subject =~ s/\$/\(\$\)/g;
 1059:     $supportmsg =~ s/(`)/'/g;
 1060:     $supportmsg =~ s/\$/\(\$\)/g;
 1061:     $displaymsg =~ s/(`)/'/g;
 1062:     $displaymsg =~ s/\$/\(\$\)/g;
 1063:     my $fname;
 1064: 
 1065:     my $attachmentpath = '';
 1066:     my $showsize = '';
 1067: 
 1068:     if ((defined($env{'user.name'})) && (!$public)) {
 1069:         if ($homeserver && $env{'form.screenshot.filename'}) {
 1070:             unless ($helpform{'screenshot'} eq 'no') {
 1071:                 my $attachmentsize = length($env{'form.screenshot'});
 1072:                 my $max = 1048576;
 1073:                 my $showmax = 1.00;
 1074:                 if ($helpform{'maxsize'} =~ /^\d+\.\d*$/) {
 1075:                     $max *= $helpform{'maxsize'};
 1076:                     $showmax = $helpform{'maxsize'};
 1077:                 }
 1078:                 $showmax = '('.sprintf("%.2f",$showmax).' MB)';
 1079:                 $showsize = $attachmentsize/1048576;
 1080:                 $showsize = '('.sprintf("%.2f",$showsize).' MB)';
 1081:                 if ($attachmentsize > $max) {
 1082:                     $displaymsg .= '<br /><span class="LC_warning">'.
 1083:                                    &mt('The uploaded screenshot file [_1] included with your request exceeded the maximum allowed size [_2], and has therefore been discarded.',$showsize,$showmax).'</span>';
 1084:                 } else {
 1085:                     $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
 1086:                 }
 1087:             }
 1088:         }
 1089:     }
 1090: 
 1091:     my %cookies;
 1092:     my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
 1093:     if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
 1094:         $cookies{'lonID'} = $1;
 1095:     }
 1096:     if ($$cookie{'lonLinkID'} =~ /lonLinkID=([a-f0-9]+_linked);/) {
 1097:         $cookies{'lonLinkID'} = $1;
 1098:     }
 1099:     my $lti_info;
 1100:     if (($env{'request.lti.login'}) && ($env{'request.course.id'})) {
 1101:         my $ltidom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1102:         if ($ltidom) {
 1103:             my %lti = &Apache::lonnet::get_domain_lti($ltidom,'provider');
 1104:             if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
 1105:                 if ($lti{$env{'request.lti.login'}}{'consumer'}) {
 1106:                     $lti_info = "LTI consumer: ".$lti{$env{'request.lti.login'}}{'consumer'}."\n";
 1107:                 }
 1108:             }
 1109:         }
 1110:     }
 1111:     if ($attachmentpath =~ m-/([^/]+)$-) {
 1112:         $fname = $1;
 1113:         $displaymsg .= '<br />'
 1114:                       .&mt('An uploaded screenshot file [_1] was included in the request sent by [_2].'
 1115:                           ,'<span class="LC_filename">'.$fname.'</span>&nbsp;'.$showsize,
 1116:                           ,$env{'user.name'}.':'.$env{'user.domain'}
 1117:                        );
 1118:         $supportmsg .= "\n";
 1119:         foreach my $var (@cookievars) {
 1120:             $supportmsg .= "$var: $cookies{$var}\n";
 1121:         }
 1122:         foreach my $var(@ENVvars) {
 1123:             $supportmsg .= "$var: $ENV{$var}\n";
 1124:         }
 1125:         $supportmsg .= "REMOTE_ADDR: $ip\n";
 1126:         foreach my $var (@envvars) {
 1127:             $supportmsg .= "$var: $env{$var}\n";
 1128:         }
 1129:         if ($lti_info) {
 1130:             $supportmsg .= $lti_info;
 1131:         }
 1132:     }
 1133: 
 1134:     my $cc_string;
 1135:     if ($homeserver) {
 1136:         if (@ok_ccs > 0) {
 1137:             $cc_string = join(', ',@ok_ccs);
 1138:         }
 1139:     }
 1140: 
 1141:     my $attachment_text = '';
 1142:     unless ($homeserver && $attachmentpath) {
 1143:         foreach my $var (@cookievars) {
 1144:             $attachment_text .= "$var: $cookies{$var}\n";
 1145:         }
 1146:         foreach my $var (@ENVvars) {
 1147:             $attachment_text .= "$var: $ENV{$var}\n";
 1148:         }
 1149:         $attachment_text .= "REMOTE_ADDR: $ip\n";
 1150:         foreach my $var (@envvars) {
 1151:             $attachment_text .= "$var: $env{$var}\n";
 1152:         }
 1153:         foreach my $var (@loncvars) {
 1154:             $attachment_text .= "$var: $env{$var}\n";
 1155:         }
 1156:         if ($lti_info) {
 1157:             $attachment_text .= $lti_info;
 1158:         }
 1159:     }
 1160: 
 1161:     if ($addtext) {
 1162:         my ($addloc,$addstr) = split(/:/,$addtext,2);
 1163:         $addstr = &unescape($addstr);
 1164:         if ($addloc eq 's') {
 1165:             $subject = $addstr.' '.$subject;
 1166:         } elsif ($addloc eq 'b') {
 1167:             $supportmsg = $addstr."\n".$supportmsg;
 1168:         }
 1169:     }
 1170: 
 1171:     if ($bad_email) {
 1172:         $r->print('<b>'.$lt{'belo'}.'</b><br />'.
 1173:                   $lt{'ifyk'}."\n");
 1174:     } else {
 1175:         # Compose and send a MIME email
 1176:         &Apache::loncommon::mime_email($from,'',$to,$subject,$supportmsg,$cc_string,
 1177:                                        $bcc,$attachmentpath,$fname,$attachment_text);
 1178:         $r->print('<b>'.$lt{'your'}.'</b>:'."\n");
 1179:     }
 1180:     if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
 1181:         unlink($attachmentpath);
 1182:     }
 1183:     $r->print('<div style="width:620px;">'.
 1184:               &Apache::lonhtmlcommon::start_pick_box().
 1185:               &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
 1186:               &Apache::lonhtmlcommon::row_closure().
 1187:               &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
 1188:     my $envmsg;
 1189:     foreach my $var (@cookievars) {
 1190:         if ($cookies{$var} ne '') {
 1191:             $envmsg.= '<span class="LC_helpform_receipt_cat">'.
 1192:                       $var.'</span>:&nbsp;'.$cookies{$var}.', ';
 1193:         }
 1194:     }
 1195:     foreach my $var (@ENVvars) {
 1196:         if ($ENV{$var} ne '') {
 1197:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
 1198:                        $var.'</span>:&nbsp;'.$ENV{$var}.', ';
 1199:         }
 1200:     }
 1201:     if ($ip ne '') {
 1202:         $envmsg .= '<span class="LC_helpform_receipt_cat">'.
 1203:                    'REMOTE_ADDR</span>:&nbsp;'.$ip.', ';
 1204:     }
 1205:     foreach my $var (@envvars) {
 1206:         if ($env{$var} ne '') { 
 1207:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
 1208:                        $var.'</span>:&nbsp;'.$env{$var}.', ';
 1209:         }
 1210:     }
 1211:     $envmsg =~ s/, $//;
 1212:     $r->print($envmsg."\n".
 1213:               &Apache::lonhtmlcommon::row_closure(1)."\n".
 1214:               &Apache::lonhtmlcommon::end_pick_box().
 1215:               '</div>');
 1216:     unless ($bad_email) {
 1217:         $r->print('<p><br />'.&Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($message)).'</p>');
 1218:     }
 1219:     $r->print("</div>\n".
 1220:               &Apache::loncommon::end_page());
 1221: }
 1222: 
 1223: sub print_header {
 1224:     my ($r,$origurl,$command) = @_;
 1225:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
 1226:     my ($component_url);
 1227:     my $helpicon_link = '<a href="javascript:validate();" tabindex="-1">';
 1228:     if ($command eq 'process') {
 1229:         $helpicon_link = '<a href="/adm/helpdesk" tabindex="-1">';
 1230:     }
 1231:     my $helpdesk_link = '<a href="javascript:validate();">';
 1232:     if ($command eq 'process') {
 1233:         $helpdesk_link = '<a href="/adm/helpdesk">';
 1234:     }
 1235:     my %lt = &Apache::lonlocal::texthash (
 1236:                                            login    => 'Log-in help',
 1237:                                            ask      => 'Ask helpdesk',
 1238:                                            getst    => 'Getting started guide',
 1239:                                            back     => 'Back to last location',
 1240:                                            headline => 'help/support',
 1241:                                            stud     => 'Students',
 1242:                                            ifyo     => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',
 1243:                                            cont     => 'Contact your instructor instead.',
 1244:                                          );
 1245:     my ($getstartlink,$reviewtext);
 1246:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
 1247:         $getstartlink = qq|<div class="LC_helpdesk_links LC_nobreak"><div class="LC_helpdesk_img" aria-hidden="true">&nbsp;</div><div class="LC_helpdesk_text"><a href="/adm/gettingstarted.html">$lt{'getst'}</a>&nbsp;</div></div>|;
 1248:         $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
 1249:     } else {
 1250:         $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
 1251:     }
 1252:     my $linkback;
 1253:     if ($origurl eq '') {
 1254:         $linkback = 'javascript:history.go(-1)';
 1255:     } else {
 1256:         $linkback = &HTML::Entities::encode($origurl,'"<>&');
 1257:     }
 1258:     my $loginhelp = &Apache::lonauth::loginhelpdisplay();
 1259:     if ($loginhelp eq '') {
 1260:         $loginhelp = '/adm/loginproblems.html';
 1261:     }
 1262:     $r->print(<<"END");
 1263: <div class="LC_landmark" style="display: inline-block;" role="navigation">
 1264:   <div class="LC_helpdesk_headbox">
 1265:     <h1 class="LC_helpdesk_legend">
 1266:       <img src="$location/lonIcons/minilogo.gif" height="20" width="29" alt="LONCAPA logo" style="vertical-align: middle" />
 1267:       LON-CAPA $lt{'headline'}
 1268:     </h1>
 1269:     <div style="border:0; padding:0; margin: 1em 0 0.5em;">
 1270:       <div class="LC_helpdesk_links LC_nobreak"><div class="LC_helpdesk_img" aria-hidden="true">&nbsp;<a href="$loginhelp" tabindex="-1"><img src="$location/help/help.png" border="0" alt="($lt{'login'})" style="vertical-align:middle" />&nbsp;</a></div><div class="LC_helpdesk_text"><a href="$loginhelp">$lt{'login'}</a>&nbsp;</div></div>
 1271:       <div class="LC_helpdesk_links LC_nobreak"><div class="LC_helpdesk_img" aria-hidden="true">&nbsp;$helpicon_link<img src="$location/lonIcons/helpdesk.gif" border="0" alt="($lt{'ask'})" style="vertical-align:top" />&nbsp;</a></div><div class="LC_helpdesk_text">$helpdesk_link$lt{'ask'}</a>&nbsp;</div></div>$getstartlink
 1272:       <div class="LC_helpdesk_links LC_nobreak"><div class="LC_helpdesk_img" aria-hidden="true">&nbsp;<a href="$linkback" target="_top" tabindex="-1"><img src="$location/lonIcons/move_up.gif" border="0" alt="($lt{'back'})" style="vertical-align:middle" />&nbsp;</a></div><div class="LC_helpdesk_text"><a href="$linkback" target="_top">$lt{'back'}</a>&nbsp;</div></div>
 1273:     </div>
 1274:   </div>
 1275: </div>
 1276: END
 1277:     if  ($command ne 'process') {
 1278:         my $stuwarn = &mt('Do [_1]not[_2] use this form to ask about course content.',
 1279:                           '<b>','</b>');
 1280:         $r->print(<<"END");
 1281:  <div style="border:0; padding:0; margin: 0; max-width: 600px;" role="complementary">
 1282:   $reviewtext
 1283:   $lt{'ifyo'}
 1284:   <p class="LC_info">
 1285:     <b>$lt{'stud'}:</b> 
 1286:     $stuwarn $lt{'cont'}
 1287:   </p>
 1288:  </div>
 1289: END
 1290:     }
 1291:     return;
 1292: }
 1293: 
 1294: sub get_domain {
 1295:     my $codedom;
 1296:     if (exists($env{'form.codedom'})) {
 1297:         if (&Apache::lonnet::domain($env{'form.codedom'}) ne '') {
 1298:             return $env{'form.codedom'};
 1299:         }
 1300:     }
 1301:     if ($env{'request.course.id'}) {
 1302:         $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1303:     } elsif ($env{'request.role.domain'}) {
 1304:         $codedom = $env{'request.role.domain'};
 1305:     } else {
 1306:         $codedom = &Apache::lonnet::default_login_domain();
 1307:     }
 1308:     return $codedom;
 1309: }
 1310: 
 1311: 1;

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