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

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