File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.70: download - view: text, annotated - select for diffs
Fri Jan 4 16:57:38 2013 UTC (11 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Sanity checking.
- Additional entity conversions to proof against XSS.

    1: #
    2: # $Id: lonsupportreq.pm,v 1.70 2013/01/04 16:57:38 raeburn Exp $
    3: #
    4: # Copyright Michigan State University Board of Trustees
    5: #
    6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    7: #
    8: # LON-CAPA is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: #
   13: # LON-CAPA is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: #
   18: # You should have received a copy of the GNU General Public License
   19: # along with LON-CAPA; if not, write to the Free Software
   20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   21: #
   22: # /home/httpd/html/adm/gpl.txt
   23: #
   24: # http://www.lon-capa.org/
   25: #
   26: 
   27: package Apache::lonsupportreq;
   28: 
   29: use strict;
   30: use MIME::Types;
   31: use MIME::Lite;
   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:     $origurl =~ s{^https?://}{};
   71:     $origurl =~ s/(`)//g;
   72:     $origurl =~ s/\$/\(\$\)/g;
   73:     my $command = $env{'form.command'};
   74: 
   75:     if ($command eq 'process') {
   76:         &print_request_receipt($r,$origurl,$function);
   77:     } else {
   78:         &print_request_form($r,$origurl,$function);
   79:     }
   80:     return OK;
   81: }
   82:     
   83: sub print_request_form {
   84:     my ($r,$origurl,$function) = @_;
   85:     my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$urole,$usec,$email,$cid,
   86:         $cdom,$cnum,$ctitle,$ccode,$sectionlist,$lastname,$firstname,$server,
   87:         $formname,$public,$homeserver);
   88:     $function = &Apache::loncommon::get_users_function() if (!$function);
   89:     $ccode = '';
   90:     $os = $env{'browser.os'};
   91:     $browser = $env{'browser.type'};
   92:     $bversion = $env{'browser.version'};
   93:     $uhost = $env{'request.host'};
   94:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
   95:         $public = 1;
   96:     } else {
   97:         if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
   98:             $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
   99:                                                       $env{'user.domain'});
  100:             if ($homeserver eq 'no_host') {
  101:                 undef($homeserver); 
  102:             } else {
  103:                 $uname = $env{'user.name'};
  104:                 $udom = $env{'user.domain'};
  105:             }
  106:         }
  107:     }
  108:     if ($homeserver) {
  109:         $uhome = $env{'user.home'};
  110:         $urole = $env{'request.role'};
  111:         $usec = $env{'request.course.sec'};
  112:         $cid = $env{'request.course.id'};
  113:     }
  114:     $formname = 'logproblem';
  115:     my $machine = &Apache::lonnet::absolute_url();
  116:     my $sourceurl = $machine.$origurl;
  117:     $server = $machine.&cleanup_html($origurl);
  118:     $server =~ s/\?.*$//;
  119:     my %lt = &Apache::lonlocal::texthash (
  120:                   email => 'The e-mail address you entered',
  121:                   notv => 'is not a valid e-mail address',
  122:                   rsub => 'You must include a subject',
  123:                   rdes => 'You must include a description',
  124:                   name => 'Name',
  125:                   subm => 'Submit Request',
  126:                   emad => 'Your e-mail address',
  127:                   emac => 'Cc', 
  128:                   unme => 'username',
  129:                   doma => 'domain',
  130:                   entu => 'Enter the username you use to log-in to LON-CAPA',
  131:                   chdo => 'Choose your LON-CAPA domain',
  132:                   entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
  133:                   urlp => 'URL of page',
  134:                   phon => 'Phone',
  135:                   crsd => 'Course Details',
  136:                   enin => 'Enter institutional course code',
  137:                   pick => 'Pick',
  138:                   enct => 'Enter course title',
  139:                   secn => 'Section Number',
  140:                   sele => 'Select',
  141:                   titl => 'Title',
  142:                   lsec => 'LON-CAPA sec',
  143:                   subj => 'Subject',
  144:                   detd => 'Detailed Description',
  145:                   opfi => 'Optional file upload',
  146:                   uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)',
  147:                   fini => 'Finish',
  148:                   clfm => 'Clear Form',
  149:     );
  150:     my $scripttag = (<<"END");
  151: function validate() {
  152:     if (validmail(document.logproblem.email) == false) {
  153:         alert("$lt{'email'}: "+document.logproblem.email.value+" $lt{'notv'}.");
  154:         return;
  155:     }
  156:     if (document.logproblem.subject.value == '') {
  157:         alert("$lt{'rsub'}.");
  158:         return;
  159:     }
  160:     if (document.logproblem.description.value == '') {
  161:         alert("$lt{'rdes'}.");
  162:         return;
  163:     }
  164:     document.logproblem.submit();
  165: }
  166: 
  167: END
  168:     $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
  169:     if ($cid) {
  170:         $cdom = $env{'course.'.$cid.'.domain'};
  171:         $cnum = $env{'course.'.$cid.'.num'};
  172:     }
  173:     if ($cdom && $cnum) {
  174:         my %csettings = &Apache::lonnet::get('environment',['description','internal.coursecode','internal.sectionnums'],$cdom,$cnum);
  175:         $ctitle = $csettings{'description'};
  176:         $ccode = $csettings{'internal.coursecode'};
  177:         $sectionlist = $csettings{'internal.sectionnums'};
  178:     }
  179: 
  180:     if ($homeserver) {
  181:         if ($env{'environment.permanentemail'}) {
  182:             $email = $env{'environment.permanentemail'};
  183:         } elsif ($env{'environment.critnotification'}) {
  184:             $email = $env{'environment.critnotification'};
  185:         } elsif ($env{'environment.notification'}) {
  186:             $email = $env{'environment.notification'};
  187:         }
  188:         if ($env{'environment.lastname'}) {
  189:             $lastname = $env{'environment.lastname'};
  190:         }
  191:         if ($env{'environment.firstname'}) {
  192:             $firstname = $env{'environment.firstname'};
  193:         }
  194:     }
  195:     my @sections = split(/,/,$sectionlist);
  196:     my %groupid;
  197:     foreach my $section (@sections) {
  198:         my ($sec,$grp) = split(/:/,$section);
  199:         $groupid{$sec} = $grp;
  200:     }
  201:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
  202:                                                  'useremail','useraccount']);
  203:     if ($env{'form.origurl'} eq '/adm/createaccount') {
  204:         if ($email eq '') {
  205:             if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
  206:                 $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
  207:             }
  208:         }
  209:         if ($uname eq '') {
  210:             if ($env{'form.useraccount'} =~ /^$match_username$/) {
  211:                 $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
  212:             }
  213:         }
  214:     }
  215:     my $codedom = &get_domain();
  216:     my $details_title;
  217:     if ($codedom) {
  218:         $details_title = '<br />('.$codedom.')';
  219:     }
  220:     my %coursecodes;
  221:     my %codes;
  222:     my @codetitles;
  223:     my %cat_titles;
  224:     my %cat_order;
  225:     my %idlist;
  226:     my %idnums;
  227:     my %idlist_titles;
  228:     my $caller = 'global';
  229:     my $totcodes = 0;
  230:     my $format_reply;
  231:     my $jscript = '';
  232:     my $loaditems = qq|
  233: function initialize_codes() {
  234:     return;
  235: }
  236:     |;
  237:     if ($cnum) {
  238:         $coursecodes{$cnum} = $ccode;
  239:         if ($ccode eq '') {
  240:             $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
  241:         } else {
  242:             $coursecodes{$cnum} = $ccode;
  243:             $caller = $cnum;
  244:             $totcodes ++;
  245:         }
  246:     } else { 
  247:         $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$codedom,$totcodes);
  248:     }
  249:     if ($totcodes > 0) {
  250:         if ($ccode eq '') {
  251:             $format_reply = &Apache::lonnet::auto_instcode_format($caller,$codedom,\%coursecodes,\%codes,\@codetitles,\%cat_titles,\%cat_order);
  252:             if ($format_reply eq 'ok') {
  253:                 my $numtypes = @codetitles;
  254:                 &Apache::courseclassifier::build_code_selections(\%codes,\@codetitles,\%cat_titles,\%cat_order,\%idlist,\%idnums,\%idlist_titles);
  255:                 my ($scripttext,$longtitles) = &Apache::courseclassifier::javascript_definitions(\@codetitles,\%idlist,\%idlist_titles,\%idnums,\%cat_titles);
  256:                 my $longtitles_str = join('","',@{$longtitles});
  257:                 my $allidlist = $idlist{$codetitles[0]};
  258:                 $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
  259:                 $jscript .= $scripttext;
  260:                 $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);
  261:                 $loaditems = '';
  262:             }
  263:         }
  264:     }
  265: 	
  266:     my $js = <<"ENDJS";
  267: <script type="text/javascript">
  268: // <![CDATA[
  269: $scripttag
  270: $jscript
  271: $loaditems
  272: // ]]>
  273: </script>
  274: ENDJS
  275:     my %add_entries = (
  276:                        style    => "margin-top:0px;margin-bottom:0px;",
  277:                        onload   => "initialize_codes();",
  278:                       );
  279: 
  280:     
  281:     $r->print(&Apache::loncommon::start_page('Support Request',$js,
  282: 				       { 'function'    => $function,
  283: 					 'add_entries' => \%add_entries,
  284: 					 'only_body'   => 1,}));
  285:     if ($r->uri eq '/adm/helpdesk') {
  286:         &print_header($r,$origurl);
  287:     }
  288:     my @css = ('LC_evenrow_value','LC_oddrow_value');
  289:     my $num = 1;
  290:     my $i = $num%2;
  291:     my $formtype;
  292:     if ($homeserver) {
  293:         $formtype = ' enctype="multipart/form-data"';
  294:     }
  295:     $r->print('<form method="post" action="" name="logproblem"'.$formtype.'>'."\n");
  296:     my $output = &Apache::lonhtmlcommon::start_pick_box().
  297:                  &Apache::lonhtmlcommon::row_title($lt{'name'},undef,$css[$num])."\n";
  298:     my $fullname = '';
  299:     if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
  300:         $fullname = "$firstname $lastname"; 
  301:         $output .= $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
  302:     } else {
  303:         if (defined($firstname) && $firstname ne '') {
  304:             $fullname = $firstname;
  305:         } elsif (defined($lastname) && $lastname ne '') {
  306:             $fullname = " $lastname";
  307:         }
  308:         $output .= '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />'."\n";
  309:     }
  310:     $output .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$lt{'subm'}.'" onclick="validate()" />&nbsp;'.
  311:                 &Apache::lonhtmlcommon::row_closure()."\n";
  312:     $num ++;
  313:     $i = $num%2;
  314:     $output .= &Apache::lonhtmlcommon::row_title($lt{'emad'},undef,$css[$i]).
  315:                '<input type="text" size="20" name="email" value="'.
  316:                &HTML::Entities::encode($email,'"<>&').'" /><br />'."\n".
  317:                &Apache::lonhtmlcommon::row_closure();
  318:     $num ++;
  319:     $i = $num%2;
  320:     if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
  321:         if ($homeserver) { 
  322:             $output .= &Apache::lonhtmlcommon::row_title($lt{'emac'},undef,$css[$i]).
  323:                        '<input type="text" size="50" name="cc" value="" /><br />'."\n".
  324:                        &Apache::lonhtmlcommon::row_closure();
  325:             $num ++;
  326:             $i = $num%2;
  327:         }
  328:     }
  329:     $output .= &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,$css[$i]);
  330:     my $udom_input = '<input type="hidden" name="udom" value="'.
  331:                      &HTML::Entities::encode($udom,'"<>&').'" />'."\n";
  332:     my $uname_input = '<input type="hidden" name="uname" value="'.
  333:                       &HTML::Entities::encode($uname,'"<>&').'" />'."\n"; 
  334:     if (($env{'user.name'} =~ /^$match_username$/) && 
  335:         ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
  336:         $output .= '<i>'.$lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;<i>'.$lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input.$uname_input;
  337:     } else {
  338:         my $udomform = '';
  339:         my $unameform = '';
  340:         if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
  341:             $output .= $lt{'entu'};
  342:         } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { 
  343:             $output .= $lt{'chdo'};
  344:         } else {
  345:             $output .= $lt{'entr'};
  346:         }
  347:         $output .= '<br />'."\n";
  348:         if (!$public) {
  349:             if ($env{'user.domain'} =~ /^$match_domain$/) {
  350:                 $udomform = '<i>'.$lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input;
  351:             } elsif ($env{'user.name'} =~ /^$match_username$/) {
  352:                 $unameform = '<i>'.$lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;'.$uname_input;
  353:             }
  354:         }
  355:         if ($udomform eq '') {
  356:             $udomform = '<i>'.$lt{'doma'}.'</i>:&nbsp;';
  357:             $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom')."\n";
  358:         }
  359:         if ($unameform eq '') {
  360:             $unameform= '<i>'.$lt{'unme'}.'</i>:&nbsp;<input type="text" size="20" name="uname" value="'.$uname.'" />&nbsp;&nbsp;';
  361:         }
  362:         $output .= $unameform.$udomform;
  363:     }
  364:     $output .= &Apache::lonhtmlcommon::row_closure();
  365:     $num ++;
  366:     $i = $num%2;
  367:     $output .= &Apache::lonhtmlcommon::row_title("$lt{'urlp'}",undef,$css[$i]).
  368:                $server."\n".'<input type="hidden" name="sourceurl" value="'.
  369:                &HTML::Entities::encode($sourceurl,'"<>&').'" />'."\n".
  370:                &Apache::lonhtmlcommon::row_closure().
  371:                &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,'LC_evenrow_value').
  372:                '<input type="text" size="15" name="phone" /><br />'."\n".
  373:                &Apache::lonhtmlcommon::row_closure();
  374:     $num ++;
  375:     $i = $num%2; 
  376:     $output .= &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,$css[$i]);
  377:     if ($cnum) {
  378:         if ($coursecodes{$cnum}) {
  379:             foreach my $item (@codetitles) {
  380:                 $output .= '<i>'.$item.'</i>:&nbsp;'.$codes{$cnum}{$item}.';&nbsp;';
  381:             }
  382:             $output .= '&nbsp;<input type="hidden" name="coursecode" value="'.&HTML::Entities::encode($coursecodes{$cnum},'"<>&').'" />'."\n";
  383:         } else {
  384:             $output .= $lt{'enin'}.':&nbsp;
  385:                   <input type="text" name="coursecode" size="15" value="" />'."\n";
  386:         }
  387:     } else {
  388:         if ($totcodes > 0) {
  389:             my $numtitles = @codetitles;
  390:             if ($numtitles == 0) {
  391:                 $output .= $lt{'enin'}.':&nbsp;
  392:                   <input type="text" name="coursecode" size="15" value="" />'."\n";
  393:             } else {
  394:                 my @standardnames = &Apache::loncommon::get_standard_codeitems();
  395:                 my $lasttitle = $numtitles;
  396:                 if ($numtitles > 4) {
  397:                     $lasttitle = 4;
  398:                 } 
  399:                 $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
  400:                       '<select name="'.$standardnames[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
  401:                       ' <option value="-1">'.$lt{'sele'}."</option>\n";
  402:                 my @items = ();
  403:                 my @longitems = ();
  404:                 if ($idlist{$codetitles[0]} =~ /","/) {
  405:                     @items = split(/","/,$idlist{$codetitles[0]});
  406:                 } else {
  407:                     $items[0] = $idlist{$codetitles[0]};
  408:                 }
  409:                 if (defined($idlist_titles{$codetitles[0]})) {
  410:                     if ($idlist_titles{$codetitles[0]} =~ /","/) {
  411:                         @longitems = split(/","/,$idlist_titles{$codetitles[0]});
  412:                     } else {
  413:                         $longitems[0] = $idlist_titles{$codetitles[0]};
  414:                     }
  415:                     for (my $i=0; $i<@longitems; $i++) {
  416:                         if ($longitems[$i] eq '') {
  417:                             $longitems[$i] = $items[$i];
  418:                         }
  419:                     }
  420:                 } else {
  421:                     @longitems = @items;
  422:                 }
  423:                 for (my $i=0; $i<@items; $i++) {
  424:                     $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
  425:                 }
  426:                 $output .= '</select></td>';
  427:                 for (my $i=1; $i<$numtitles; $i++) {
  428:                     $output .= '<td>'.$codetitles[$i].'<br />'."\n".
  429:                      '<select name="'.$standardnames[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
  430:                      '<option value="-1">&lt;-'.$lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
  431:                      '</select>'."\n".
  432:                      '</td>'."\n";
  433:                 }
  434:                 $output .= '</tr></table>';
  435:                 if ($numtitles > 4) {
  436:                     $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
  437:                           '<select name="'.$standardnames[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
  438:                           '<option value="-1">&lt;-'.$lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
  439:                           '</select>'."\n";
  440:                 }
  441:             }
  442:         } else {
  443:             $output .= $lt{'enin'}.':&nbsp;
  444:                   <input type="text" name="coursecode" size="15" value="" />'."\n";
  445:         }
  446:     }
  447:     if ($ctitle) {
  448:         $output .= '<br /><i>'.$lt{'titl'}.'</i>:&nbsp;'.$ctitle.
  449:                    '<input type="hidden" name="title" value="'.
  450:                    &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
  451:     } else {
  452:         $output .= '<br />'.$lt{'enct'}.':&nbsp;
  453:                  <input type="text" name="title" size="25" value="" />'."\n";
  454:     }
  455:     $output .= &Apache::lonhtmlcommon::row_closure();
  456:     $num ++;
  457:     $i = $num%2;
  458:     $output .= &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,$css[$i]);
  459:     if ($sectionlist) {
  460:         $output .= "<select name=\"section\"\n>".
  461:                    "  <option value=\"\" selected=\"selected\">$lt{'sele'}</option>\n";
  462:         foreach my $id (sort(keys(%groupid))) {
  463:             if ($id eq $groupid{$id} || $groupid{$id} eq '') {
  464:                 $output .= "  <option value=".
  465:                            &HTML::Entities::encode($id,'"<>&').
  466:                            " >$id</option>\n";
  467:             } else {
  468:                 $output .= "  <option value=".
  469:                            &HTML::Entities::encode($id,'"<>&').
  470:                            " >$id - ($lt{'lsec'}: $groupid{$id})</option>\n";
  471:             }
  472:         }
  473:         $output .= "</select>";
  474:     } else {
  475:         $output .= '<input type="text" name="section" size="10" />'."\n";
  476:     }
  477:     $output .= &Apache::lonhtmlcommon::row_closure();
  478:     $num ++;
  479:     $i = $num%2; 
  480:     $output .= &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value').
  481:                '  <input type="text" size="40" name="subject" />'."\n".
  482:                &Apache::lonhtmlcommon::row_closure().
  483:                &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_evenrow_value').
  484:                '  <textarea rows="10" cols="45" name="description" style="word-wrap:normal;">'.
  485:                '</textarea>'."\n".
  486:                &Apache::lonhtmlcommon::row_closure();
  487:     $num ++;
  488:     $i = $num%2; 
  489:     if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
  490:         if ($homeserver) {
  491:             $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]).
  492:                        ' <input type="file" name="screenshot" size="20" /><br />'.
  493:                        "\n".$lt{'uplf'}."\n".
  494:                        &Apache::lonhtmlcommon::row_closure();
  495:             $num ++;
  496:             $i = $num%2;
  497:         }
  498:     } else {
  499:         my $lonhost = $r->dir_config('lonHostID');
  500:         my ($captchaform,$error) = 
  501:             &Apache::loncommon::captcha_display('login',$lonhost);
  502:         if ($captchaform) {
  503:             $output .= &Apache::lonhtmlcommon::row_title(&mt('Validation'),undef,
  504:                                                          $css[$i])."\n".
  505:                        $captchaform."\n".
  506:                        &Apache::lonhtmlcommon::row_closure();
  507:             $num ++;
  508:             $i = $num%2;
  509:         }
  510:     }
  511:     $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]);
  512:     $output .= <<END;
  513:              <table border="0" cellpadding="8" cellspacing="0">
  514:               <tr>
  515:                <td>
  516:                 <input type="hidden" name="command" value="process" />
  517:                 <input type="button" value="$lt{'subm'}" onclick="validate()" /> &nbsp;
  518:                </td>
  519:                <td>&nbsp;</td>
  520:                <td>
  521:                 <input type="reset" value="$lt{'clfm'}" />
  522:                </td>
  523:               </tr>
  524:              </table>
  525: END
  526:     $output .= &Apache::lonhtmlcommon::row_closure(1);
  527:     $output .= &Apache::lonhtmlcommon::end_pick_box();
  528:     $r->print(<<END);
  529: $output
  530: </form>
  531: <br />
  532: END
  533:     $r->print(&Apache::loncommon::end_page());
  534:     return;
  535: }
  536: 
  537: sub print_request_receipt {
  538:     my ($r,$url,$function) = @_;
  539:     my $public;
  540:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
  541:         $public = 1;
  542:     }
  543:     unless (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
  544:         my $lonhost = $r->dir_config('lonHostID');
  545:         my ($captcha_chk,$captcha_error) = 
  546:             &Apache::loncommon::captcha_response('login',$lonhost);
  547:         if ($captcha_chk != 1) {
  548:             $r->print(&Apache::loncommon::start_page('Support request failed',undef,
  549:                                        {'function'    => $function,
  550:                                         'add_entries' => {
  551:                                             topmargin    => "0",
  552:                                             marginheight => "0",
  553:                                         },
  554:                                         'only_body'   => 1,}));
  555:             if ($r->uri eq '/adm/helpdesk') {
  556:                 &print_header($r,$url,'process');
  557:             }
  558:             $r->print('<h3>'.&mt('Support request failed').'</h3>'.
  559:                       '<span class="LC_error">'.
  560:                       &mt('Validation of the code you entered failed.').
  561:                       &Apache::loncommon::end_page());
  562:             return;
  563:         }
  564:     }
  565:     my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
  566:     my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
  567:     my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
  568:     my @cookievars = ('lonID');
  569: 
  570:     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
  571:     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  572:     my $defdom = &get_domain();
  573:     my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
  574:                                                       $defdom,$origmail);
  575:     my $from = $admin;
  576:     my $bcc;
  577:     my %domconfig =
  578:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
  579:     if (ref($domconfig{'contacts'}) eq 'HASH') {
  580:         if (exists($domconfig{'contacts'}{'helpdeskmail'})) {
  581:             if (ref($domconfig{'contacts'}{'helpdeskmail'}) eq 'HASH') {
  582:                 my $bccmail = $domconfig{'contacts'}{'helpdeskmail'}{'bcc'};
  583:                 if ($bccmail ne '') {
  584:                     my @bccs = split(/,/,$bccmail);
  585:                     my @ok_bccs;
  586:                     foreach my $bcc (@bccs) {
  587:                         $bcc =~ s/^\s+//g;
  588:                         $bcc =~ s/\s+$//g;
  589:                         if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
  590:                             if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
  591:                                 push(@ok_bccs,$bcc);
  592:                             }
  593:                         }
  594:                     }
  595:                     if (@ok_bccs > 0) {
  596:                         $bcc = join(', ',@ok_bccs);
  597:                     }
  598:                 }
  599:             }
  600:         }
  601:     }
  602:     my $reporttime = &Apache::lonlocal::locallocaltime(time);
  603:     my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
  604: 
  605:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
  606:     my $coursecode = $env{'form.coursecode'};
  607:     if ($coursecode eq '') {
  608:         my $totcodes = 0;
  609:         my %coursecodes;
  610:         $totcodes = &Apache::courseclassifier::retrieve_instcodes(\%coursecodes,$defdom,$totcodes);
  611:         my @standardnames = &Apache::loncommon::get_standard_codeitems();
  612:         if ($totcodes > 0) {
  613:             my $noregexps = 1;
  614:             $coursecode = 
  615:                 &Apache::courseclassifier::instcode_from_selectors($defdom,$noregexps);
  616:         } 
  617:         if ($coursecode eq '') {
  618:             foreach my $item (@standardnames) {
  619:                 if ((defined($env{'form.'.$item})) && ($env{'form.'.$item} ne '-1')) {
  620:                     $coursecode .= $env{'form.'.$item};
  621:                 }
  622:             }
  623:         }
  624:     }
  625:     my %lt = &Apache::lonlocal::texthash (
  626:                  username    => 'Name',
  627:                  email       => 'E-mail',
  628:                  cc          => 'Cc',
  629:                  user        => 'Username/domain',
  630:                  phone       => 'Phone',
  631:                  crsi        => 'Course Information',
  632:                  subject     => 'Subject',
  633:                  description => 'Description',
  634:                  sourceurl   => 'URL',
  635:                  date        => 'Date/Time',
  636:                  secn        => 'Section',
  637:                  warn        => 'Warning: Problem with support e-mail address',
  638:                  your        => 'Your support request contained the following information',
  639:                  sect        => 'section',
  640:                  info        => 'Information supplied',
  641:                  adin        => 'Additional information recorded',
  642:     );
  643: 
  644:     my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist,$public,$homeserver);
  645:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
  646:         $public = 1;
  647:     } else {
  648:         if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
  649:             $homeserver = &Apache::lonnet::homeserver($env{'user.name'},
  650:                                                       $env{'user.domain'});
  651:         }
  652:     }
  653: 
  654:     if (($homeserver) && (defined($env{'form.cc'}))) {
  655:         my @ccs;
  656:         if ($env{'form.cc'} =~ /,/) {
  657:             @ccs = split(/,/,$env{'form.cc'});
  658:         } else {
  659:             $env{'form.cc'} =~ s/^\s+//;
  660:             $env{'form.cc'} =~ s/\s+$//;
  661:             @ccs = $env{'form.cc'};
  662:         }
  663:         foreach my $cc (@ccs) {
  664:             $cc =~ s/^\s+//g;
  665:             $cc =~ s/\s+$//g;
  666:             if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
  667:                 if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
  668:                     push(@ok_ccs,$cc);
  669:                 }
  670:             } elsif ($cc ne '') {
  671:                 if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
  672:                     push(@bad_ccs,$cc);
  673:                 }
  674:             }
  675:         }
  676:         if (@ok_ccs > 0) {
  677:            $okcclist = join(', ',@ok_ccs); 
  678:         } 
  679:         if (@bad_ccs == 1) {
  680:             $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').$bad_ccs[0];
  681:         } elsif (@bad_ccs > 1) {
  682:             my $bad_cc_string = join(', ',@bad_ccs);
  683:             $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: ').$bad_cc_string;
  684:         }
  685:     }
  686:     $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
  687:     $env{'form.crsi'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
  688:     my $supportmsg = <<END;
  689: $lt{'username'}: $env{'form.username'}
  690: $lt{'email'}: $env{'form.email'}
  691: $lt{'cc'}: $okcclist
  692: $lt{'user'}: $env{'form.user'}
  693: $lt{'phone'}: $env{'form.phone'}
  694: $lt{'crsi'}: $env{'form.crsi'}
  695: $lt{'subject'}: $env{'form.subject'}
  696: $lt{'description'}: $env{'form.description'}
  697: $lt{'sourceurl'}: $env{'form.sourceurl'}
  698: $lt{'date'}: $reporttime
  699: 
  700: END
  701:     my $displaymsg;
  702:     foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
  703:         if ($env{'form.'.$item} ne '') {
  704:             if ($item eq 'description') {
  705:                 my $descrip = $env{'form.description'};
  706:                 $descrip =  &cleanup_html($descrip);
  707:                 $descrip =~ s|[\n\r\f]|<br />|g;
  708:                 $displaymsg .= 
  709:                     '<span class="LC_helpform_receipt_cat">'.
  710:                     "$lt{$item}</span>: $descrip<br />\n";
  711:             } elsif ($item eq 'sourceurl') {
  712:                 my $showurl = $env{'form.sourceurl'};
  713:                 $showurl =~ s/\?.*$//;
  714:                 $showurl =  &cleanup_html($showurl);
  715:                 $displaymsg .= 
  716:                     '<span class="LC_helpform_receipt_cat">'.
  717:                     "$lt{$item}</span>: $showurl<br />\n";
  718:             } elsif ($item eq 'cc') {
  719:                 $displaymsg .=
  720:                     '<span class="LC_helpform_receipt_cat">'.
  721:                     "$lt{$item}</span>: $okcclist<br />\n";
  722:             } else {
  723:                 my $showitem = $env{'form.'.$item};
  724:                 $showitem = &cleanup_html($showitem);
  725:                 $displaymsg .= 
  726:                     '<span class="LC_helpform_receipt_cat">'.
  727:                     "$lt{$item}</span>: $showitem<br />\n";
  728:             }
  729:         }
  730:     }
  731:     $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
  732:                    $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
  733: 
  734:     my $start_page = 
  735: 	&Apache::loncommon::start_page('Support request recorded',undef,
  736: 				       {'function'    => $function,
  737: 					'add_entries' => {
  738: 					    topmargin    => "0",
  739: 					    marginheight => "0",
  740: 					},
  741: 					'only_body'   => 1,});
  742: 
  743:     $r->print(<<"END");
  744: $start_page
  745: <form name="logproblem">
  746: <input type="hidden" name="command" value="result" />
  747: </form>
  748: END
  749:     if ($r->uri eq '/adm/helpdesk') {
  750:         &print_header($r,$url,'process');
  751:     }
  752:     my $bad_email = 0;
  753:     if ($to =~ /,/) {
  754:         my @ok_email; 
  755:         foreach my $email (split(/,/,$to)) {
  756:             if ($email =~ m/^[^\@]+\@[^\@]+$/) {
  757:                 if (!grep(/^\Q$email\E$/,@ok_email)) {
  758:                     push(@ok_email,$email);
  759:                 }
  760:             }
  761:         }
  762:         if (@ok_email > 0) {
  763:             $to = join(',',@ok_email);
  764:         } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
  765:             $to = $admin;
  766:         } else {
  767:             $bad_email = 1;
  768:         }
  769:     } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
  770:         if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
  771:             $to = $admin;
  772:         } else {
  773:             $bad_email = 1;
  774:         }
  775:     }
  776: 
  777:     my $message;
  778:     if (!$bad_email) {
  779:         $message = &Apache::lonhtmlcommon::confirm_success(
  780:             &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>'));
  781:     } else {
  782:         $message = &Apache::lonhtmlcommon::confirm_success(
  783:             $lt{'warn'}.'<br />'
  784:            .&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>')
  785:            .' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.'),1); 
  786:         $to = 'helpdesk@lon-capa.org';
  787:     }
  788:     $r->print(&Apache::loncommon::confirmwrapper($message));
  789: 
  790:     if (defined($env{'form.email'})) {
  791:         $env{'form.email'} =~ s/^\s+//;
  792:         $env{'form.email'} =~ s/\s+$//;
  793:         if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
  794:             $from = $env{'form.email'};
  795:         }
  796:     }
  797: 
  798:     if (defined($env{'form.cc'})) {
  799:         if ($badccmsg) {
  800:             $displaymsg .= $badccmsg;
  801:         }
  802:     }
  803: 
  804:     my $subject = $env{'form.subject'};
  805:     $subject =~ s/(`)/'/g;
  806:     $subject =~ s/\$/\(\$\)/g;
  807:     $supportmsg =~ s/(`)/'/g;
  808:     $supportmsg =~ s/\$/\(\$\)/g;
  809:     $displaymsg =~ s/(`)/'/g;
  810:     $displaymsg =~ s/\$/\(\$\)/g;
  811:     my $fname;
  812: 
  813:     my $attachmentpath = '';
  814:     my $attachmentsize = '';
  815:     if ((defined($env{'user.name'})) && ($env{'user.name'} ne 'public')
  816:         && ($env{'user.domain'} ne 'public')) {
  817:         if ($homeserver && $env{'form.screenshot.filename'}) {
  818:             $attachmentsize = length($env{'form.screenshot'});
  819:             if ($attachmentsize > 131072) {
  820:                 $displaymsg .= '<br />'.&mt('The uploaded screenshot file ([_1] bytes) included with your request exceeded the maximum allowed size - 128 KB, and has therefore been discarded.',$attachmentsize);
  821:             } else {
  822:                 $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
  823:             }
  824:         }
  825:     }
  826: 
  827:     my %cookies;
  828:     my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
  829:     if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
  830:         $cookies{'lonID'} = $1;
  831:     }
  832: 
  833:     if ($attachmentpath =~ m-/([^/]+)$-) {
  834:         $fname = $1;
  835:         $displaymsg .= '<br />'
  836:                       .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
  837:                           ,'<span class="LC_filename">'.$fname.'</span>'
  838:                           ,$attachmentsize
  839:                           ,$env{'user.name'}.':'.$env{'user.domain'}
  840:                        );
  841:         $supportmsg .= "\n";
  842:         foreach my $var (@cookievars) {
  843:             $supportmsg .= "$var: $cookies{$var}\n";
  844:         }
  845:         foreach my $var(@ENVvars) {
  846:             $supportmsg .= "$var: $ENV{$var}\n";
  847:         }
  848:         foreach my $var (@envvars) {
  849:             $supportmsg .= "$var: $env{$var}\n";
  850:         }
  851:     }
  852:  
  853:     my $msg = MIME::Lite->new(
  854:                  From    => $from,
  855:                  To      => $to,
  856:                  Subject => $subject,
  857:                  Type    =>'TEXT',
  858:                  Data    => $supportmsg,
  859:                  );
  860:     if ($homeserver) {
  861:         if (@ok_ccs > 0) {
  862:             my $cc_string = join(', ',@ok_ccs);
  863:             $msg->add("Cc" => $cc_string);
  864:         }
  865:     }
  866:     if ($bcc ne '') {
  867:         $msg->add("Bcc" => $bcc);
  868:     }
  869:     $msg->attr("content-type"         => "text/plain");
  870:     $msg->attr("content-type.charset" => "UTF-8");
  871: 
  872:     if ($homeserver && $attachmentpath) {
  873:         my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
  874:         $msg->attach(Type     => $type,
  875:                      Path     => $attachmentpath,
  876:                      Filename => $fname
  877:                      );
  878: 
  879:     } else {
  880:         my $envdata = '';
  881:         foreach my $var (@cookievars) {
  882:             $envdata .= "$var: $cookies{$var}\n";
  883:         }
  884:         foreach my $var (@ENVvars) {
  885:             $envdata .= "$var: $ENV{$var}\n";
  886:         }
  887:         foreach my $var (@envvars) {
  888:             $envdata .= "$var: $env{$var}\n";
  889:         }
  890:         foreach my $var (@loncvars) {
  891:             $envdata .= "$var: $env{$var}\n";
  892:         }
  893:         $msg->attach(Type => 'TEXT',
  894:                      Data => $envdata);
  895:     }
  896: 
  897: ### Send it:
  898:     $msg->send('sendmail');
  899: 
  900:     if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
  901:         unlink($attachmentpath);
  902:     }
  903:     $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
  904:     $r->print('<div style="width:620px;">'.
  905:               &Apache::lonhtmlcommon::start_pick_box().
  906:               &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
  907:               &Apache::lonhtmlcommon::row_closure().
  908:               &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
  909:     my $envmsg;
  910:     foreach my $var (@cookievars) {
  911:         if ($cookies{$var} ne '') {
  912:             $envmsg.= '<span class="LC_helpform_receipt_cat">'.
  913:                       $var.'</span>:&nbsp;'.$cookies{$var}.', ';
  914:         }
  915:     }
  916:     foreach my $var (@ENVvars) {
  917:         if ($ENV{$var} ne '') {
  918:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
  919:                        $var.'</span>:&nbsp;'.$ENV{$var}.', ';
  920:         }
  921:     }
  922:     foreach my $var (@envvars) {
  923:         if ($env{$var} ne '') { 
  924:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
  925:                        $var.'</span>:&nbsp;'.$env{$var}.', ';
  926:         }
  927:     }
  928:     $envmsg =~ s/, $//;
  929:     $r->print($envmsg."\n".
  930:               &Apache::lonhtmlcommon::row_closure(1)."\n".
  931:               &Apache::lonhtmlcommon::end_pick_box().
  932:               "</div>\n".
  933:               &Apache::loncommon::end_page());
  934: }
  935: 
  936: sub print_header {
  937:     my ($r,$origurl,$command) = @_;
  938:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
  939:     my ($component_url);
  940:     my $helpdesk_link = '<a href="javascript:validate()">';
  941:     if ($command eq 'process') {
  942:         $helpdesk_link = '<a href="/adm/helpdesk">';
  943:     }
  944:     my %lt = &Apache::lonlocal::texthash (
  945:                                            login    => 'Log-in help',
  946:                                            ask      => 'Ask helpdesk',
  947:                                            getst    => 'Getting started guide',
  948:                                            back     =>  'Back to last location',
  949:                                            headline => 'help/support',
  950:                                            stud     => 'Students',
  951:                                            ifyo     => 'If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.',
  952:                                            cont     => 'Contact your instructor instead.',
  953:                                          );
  954:     my ($getstartlink,$reviewtext);
  955:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
  956:         $getstartlink = qq|<td align="center">&nbsp;<b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
  957:         $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
  958:     } else {
  959:         $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
  960:     }
  961:     my $linkback;
  962:     if ($origurl eq '') {
  963:         $linkback = 'javascript:history.go(-1)';
  964:     } else {
  965:         $linkback = &HTML::Entities::encode($origurl,'"<>&');
  966:     }
  967:     my $loginhelp = &Apache::lonauth::loginhelpdisplay();
  968:     if ($loginhelp eq '') {
  969:         $loginhelp = '/adm/loginproblems.html';
  970:     }
  971:     $r->print(<<"END");
  972: <table width="620" border="0" cellspacing="0" cellpadding="0" style="height: 55px;">
  973:  <tr>
  974:    <td width="5" height="50">&nbsp;</td>
  975:    <td height="50">
  976:     <fieldset>
  977:       <legend>
  978:         <img src="$location/lonIcons/minilogo.gif" height="20" width="29" alt="logo" style="vertical-align:bottom" />
  979:         LON-CAPA $lt{'headline'}
  980:       </legend>
  981:  <table id="LC_helpmenu_links">
  982:    <tr>
  983:     <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>
  984:     <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
  985:     <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>
  986:    </tr>
  987:  </table>
  988: </fieldset>
  989:   </td>
  990:   <td width="5">&nbsp;</td>
  991:  </tr>
  992:  <tr>
  993:   <td colspan="3" height="5">&nbsp;</td>
  994:  </tr>
  995: END
  996:     if  ($command ne 'process') {
  997:         my $stuwarn = &mt('Do [_1]not[_2] use this form to ask about course content.',
  998:                           '<b>','</b>');
  999:         $r->print(<<"END");
 1000:  <tr>
 1001:   <td colspan="3">$reviewtext 
 1002:   $lt{'ifyo'}<br />
 1003: <span style="font-size:90%;"><b>$lt{'stud'}</b>: 
 1004: $stuwarn $lt{'cont'}</span>
 1005: <br /><br />
 1006:   </td>
 1007:  </tr>
 1008: END
 1009:     }
 1010:     $r->print('
 1011: </table>');
 1012:     return;
 1013: }
 1014: 
 1015: sub get_domain {
 1016:     my $codedom;
 1017:     if (exists($env{'form.codedom'})) {
 1018:         if (&Apache::lonnet::domain($env{'form.codedom'}) ne '') {
 1019:             return $env{'form.codedom'};
 1020:         }
 1021:     }
 1022:     if ($env{'request.course.id'}) {
 1023:         $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1024:     } elsif ($env{'request.role.domain'}) {
 1025:         $codedom = $env{'request.role.domain'};
 1026:     } else {
 1027:         $codedom = &Apache::lonnet::default_login_domain();
 1028:     }
 1029:     return $codedom;
 1030: }
 1031: 
 1032: sub cleanup_html {
 1033:     my ($incoming) = @_;
 1034:     my $outgoing;
 1035:     if ($incoming ne '') {
 1036:         $outgoing = $incoming;
 1037:         $outgoing =~ s/;/&#059;/g;
 1038:         $outgoing =~ s/\#/&#035;/g;
 1039:         $outgoing =~ s/\&/&#038;/g;
 1040:         $outgoing =~ s/</&#060;/g;
 1041:         $outgoing =~ s/>/&#062;/g;
 1042:         $outgoing =~ s/\(/&#040/g;
 1043:         $outgoing =~ s/\)/&#041;/g;
 1044:         $outgoing =~ s/"/&#034;/g;
 1045:         $outgoing =~ s/'/&#039;/g;
 1046:         $outgoing =~ s/\$/&#036;/g;
 1047:         $outgoing =~ s{/}{&#047;}g;
 1048:         $outgoing =~ s/=/&#061;/g;
 1049:         $outgoing =~ s/\\/&#092;/g
 1050:     }
 1051:     return $outgoing;
 1052: }
 1053: 
 1054: 1;

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