File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.38: download - view: text, annotated - select for diffs
Thu Oct 12 22:47:31 2006 UTC (17 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Moving routines used by lonsupportreq.pm, lonnotify.pm and coursecatalog.pm to courseclassifier.pm

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

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