File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.55.6.2: download - view: text, annotated - select for diffs
Thu Dec 2 13:12:11 2010 UTC (13 years, 5 months ago) by raeburn
Branches: GCI_3
Diff to branchpoint 1.55: preferred, unified
- Backport 1.59.

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

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