File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.79.2.6: download - view: text, annotated - select for diffs
Mon Aug 12 18:11:42 2019 UTC (4 years, 9 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  Backport 1.80 (part), 1.97, 1.98, 1.99

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

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