File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.69: download - view: text, annotated - select for diffs
Mon Aug 27 06:28:06 2012 UTC (11 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- "Contact Helpdesk" form (as used by users who are not logged in), can require
   CAPTCHA validation.  Default is not to require CAPTCHA.

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

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