File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.39: download - view: text, annotated - select for diffs
Wed Dec 6 22:22:37 2006 UTC (17 years, 6 months ago) by albertel
Branches: MAIN
CVS tags: version_2_2_99_0, HEAD
- more re fix ups

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

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