File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.41: download - view: text, annotated - select for diffs
Thu Dec 21 18:32:54 2006 UTC (17 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_2_99_1, HEAD
Lost a $ somehow.

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

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