File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.42: download - view: text, annotated - select for diffs
Fri Dec 22 20:51:27 2006 UTC (17 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: version_2_3_X, version_2_3_2, version_2_3_1, version_2_3_0, HEAD
- need to initalize the language handle

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

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