File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.55: download - view: text, annotated - select for diffs
Thu Oct 22 13:41:41 2009 UTC (14 years, 7 months ago) by bisitz
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, bz6209-base, bz6209, HEAD, GCI_3
Replaced special styles for helpdesk request pages by standard pick_box styles.
Actual difference was only a limited width which moved directly to lonsupportreq.pm.

    1: #
    2: # $Id: lonsupportreq.pm,v 1.55 2009/10/22 13:41:41 bisitz 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="12" 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:                &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,'LC_evenrow_value').
  316:                '<input type="text" size="15" name="phone" /><br />'.
  317:                &Apache::lonhtmlcommon::row_closure();
  318:     $num ++;
  319:     $i = $num%2; 
  320:     $output .= &Apache::lonhtmlcommon::row_title("$lt{'crsd'}$details_title",undef,$css[$i]);
  321:     if ($cnum) {
  322:         if ($coursecodes{$cnum}) {
  323:             foreach my $item (@codetitles) {
  324:                 $output .= '<i>'.$item.'</i>:&nbsp;'.$codes{$cnum}{$item}.';&nbsp;';
  325:             }
  326:             $output .= '&nbsp;<input type="hidden" name="coursecode" value="'.&HTML::Entities::encode($coursecodes{$cnum},'"<>&').'" />';
  327:         } else {
  328:             $output .= $lt{'enin'}.':&nbsp;
  329:                   <input type="text" name="coursecode" size="15" value="" />';
  330:         }
  331:     } else {
  332:         if ($totcodes > 0) {
  333:             my $numtitles = @codetitles;
  334:             if ($numtitles == 0) {
  335:                 $output .= $lt{'enin'}.':&nbsp;
  336:                   <input type="text" name="coursecode" size="15" value="" />';
  337:             } else {
  338:                 my $lasttitle = $numtitles;
  339:                 if ($numtitles > 4) {
  340:                     $lasttitle = 4;
  341:                 } 
  342:                 $output .= '<table><tr><td>'.$codetitles[0].'<br />'."\n".
  343:                       '<select name="'.$codetitles[0].'" onchange="courseSet('."'$codetitles[0]'".')">'."\n".
  344:                       ' <option value="-1" />'.$lt{'sele'}."\n";
  345:                 my @items = ();
  346:                 my @longitems = ();
  347:                 if ($idlist{$codetitles[0]} =~ /","/) {
  348:                     @items = split(/","/,$idlist{$codetitles[0]});
  349:                 } else {
  350:                     $items[0] = $idlist{$codetitles[0]};
  351:                 }
  352:                 if (defined($idlist_titles{$codetitles[0]})) {
  353:                     if ($idlist_titles{$codetitles[0]} =~ /","/) {
  354:                         @longitems = split(/","/,$idlist_titles{$codetitles[0]});
  355:                     } else {
  356:                         $longitems[0] = $idlist_titles{$codetitles[0]};
  357:                     }
  358:                     for (my $i=0; $i<@longitems; $i++) {
  359:                         if ($longitems[$i] eq '') {
  360:                             $longitems[$i] = $items[$i];
  361:                         }
  362:                     }
  363:                 } else {
  364:                     @longitems = @items;
  365:                 }
  366:                 for (my $i=0; $i<@items; $i++) {
  367:                     $output .= ' <option value="'.$items[$i].'">'.$longitems[$i].'</option>'."\n";
  368:                 }
  369:                 $output .= '</select></td>';
  370:                 for (my $i=1; $i<$numtitles; $i++) {
  371:                     $output .= '<td>'.$codetitles[$i].'<br />'."\n".
  372:                      '<select name="'.$codetitles[$i].'" onchange="courseSet('."'$codetitles[$i]'".')">'."\n".
  373:                      '<option value="-1">&lt;-'.$lt{'pick'}.' '.$codetitles[$i-1].'</option>'."\n".
  374:                      '</select>'."\n".
  375:                      '</td>'."\n";
  376:                 }
  377:                 $output .= '</tr></table>';
  378:                 if ($numtitles > 4) {
  379:                     $output .= '<br /><br />'.$codetitles[$numtitles].'<br />'."\n".
  380:                           '<select name="'.$codetitles[$numtitles].'" onchange="courseSet('."'$codetitles[$numtitles]'".')">'."\n".
  381:                           '<option value="-1">&lt;-'.$lt{'pick'}.' '.$codetitles[$numtitles-1].'</option>'."\n".
  382:                           '</select>'."\n";
  383:                 }
  384:             }
  385:         } else {
  386:             $output .= $lt{'enin'}.':&nbsp;
  387:                   <input type="text" name="coursecode" size="15" value="" />';
  388:         }
  389:     }
  390:     if ($ctitle) {
  391:         $output .= '<br /><i>'.$lt{'titl'}.'</i>:&nbsp;'.$ctitle.
  392:                    '<input type="hidden" name="title" value="'.
  393:                    &HTML::Entities::encode($ctitle,'"<>&').'" />'."\n";
  394:     } else {
  395:         $output .= '<br />'.$lt{'enct'}.':&nbsp;
  396:                  <input type="text" name="title" size="25" value="" />'."\n";
  397:     }
  398:     $output .= &Apache::lonhtmlcommon::row_closure();
  399:     $num ++;
  400:     $i = $num%2;
  401:     $output .= &Apache::lonhtmlcommon::row_title($lt{'secn'},undef,$css[$i]);
  402:     if ($sectionlist) {
  403:         $output .= "<select name=\"section\"\n>".
  404:                    "  <option value=\"\" selected=\"selected\">$lt{'sele'}</option>\n";
  405:         foreach my $id (sort(keys(%groupid))) {
  406:             if ($id eq $groupid{$id} || $groupid{$id} eq '') {
  407:                 $output .= "  <option value=".
  408:                            &HTML::Entities::encode($id,'"<>&').
  409:                            " >$id</option>\n";
  410:             } else {
  411:                 $output .= "  <option value=".
  412:                            &HTML::Entities::encode($id,'"<>&').
  413:                            " >$id - ($lt{'lsec'}: $groupid{$id})</option>\n";
  414:             }
  415:         }
  416:         $output .= "</select>";
  417:     } else {
  418:         $output .= '<input type="text" name="section" size="10" />';
  419:     }
  420:     $output .= &Apache::lonhtmlcommon::row_closure();
  421:     $num ++;
  422:     $i = $num%2; 
  423:     $output .= &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value').
  424:                '  <input type="text" size="40" name="subject" />'."\n".
  425:                &Apache::lonhtmlcommon::row_closure().
  426:                &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_evenrow_value').
  427:                '  <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>'.
  428:                &Apache::lonhtmlcommon::row_closure();
  429:     $num ++;
  430:     $i = $num%2; 
  431:     if (defined($env{'user.name'})) {
  432:         $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]).
  433:                    ' <input type="file" name="screenshot" size="20" /><br />'.$lt{'uplf'}."\n".
  434:         &Apache::lonhtmlcommon::row_closure();
  435:         $num ++;
  436:         $i = $num%2; 
  437:     }
  438:     $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]);
  439:     $output .= <<END;
  440:              <table border="0" cellpadding="8" cellspacing="0">
  441:               <tr>
  442:                <td>
  443:                 <input type="hidden" name="command" value="process" />
  444:                 <input type="button" value="$lt{'subm'}" onclick="validate()" /> &nbsp;
  445:                </td>
  446:                <td>&nbsp;</td>
  447:                <td>
  448:                 <input type="reset" value="$lt{'clfm'}" />
  449:                </td>
  450:               </tr>
  451:              </table>
  452: END
  453:     $output .= &Apache::lonhtmlcommon::row_closure(1);
  454:     $output .= &Apache::lonhtmlcommon::end_pick_box();
  455:     $r->print(<<END);
  456: $output
  457: </form>
  458: <br />
  459: END
  460:     $r->print(&Apache::loncommon::end_page());
  461:     return;
  462: }
  463: 
  464: sub print_request_receipt {
  465:     my ($r,$url,$function) = @_;
  466:     my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
  467:     my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
  468:     my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
  469:     my @cookievars = ('lonID');
  470: 
  471:     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
  472:     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  473:     my $defdom = &get_domain();
  474:     my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
  475:                                                       $defdom,$origmail);
  476:     my $from = $admin;
  477:     my $reporttime = &Apache::lonlocal::locallocaltime(time);
  478:     my @formvars = ('username','email','uname','udom','sourceurl','phone','section','coursecode','title','subject','description','screenshot');
  479: 
  480:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
  481:     my $coursecode = $env{'form.coursecode'};
  482:     if ($coursecode eq '') {
  483:         if (defined($env{'form.Year'})) {
  484:             $coursecode .= $env{'form.Year'};
  485:         }
  486:         if (defined($env{'form.Semester'})) {
  487:             $coursecode .= $env{'form.Semester'};
  488:         }
  489:         if (defined($env{'form.Department'})) {
  490:             $coursecode .= $env{'form.Department'};
  491:         }
  492:         if (defined($env{'form.Number'})) {
  493:             $coursecode .= $env{'form.Number'};
  494:         }
  495:     }
  496:     my %lt = &Apache::lonlocal::texthash (
  497:                  username    => 'Name',
  498:                  email       => 'E-mail',
  499:                  cc          => 'Cc',
  500:                  user        => 'Username/domain',
  501:                  phone       => 'Phone',
  502:                  crsi        => 'Course Information',
  503:                  subject     => 'Subject',
  504:                  description => 'Description',
  505:                  sourceurl   => 'URL',
  506:                  date        => 'Date/Time',
  507:                  secn        => 'Section',
  508:                  asup        => 'A support request has been sent to',
  509:                  warn        => 'Warning: Problem with support e-mail address',
  510:                  your        => 'Your support request contained the following information',
  511:                  sect        => 'section',
  512:                  info        => 'Information supplied',
  513:                  adin        => 'Additional information recorded',
  514:     );
  515: 
  516:     my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist);
  517:     if ((defined($env{'user.name'})) && (defined($env{'form.cc'}))) {
  518:         my @ccs;
  519:         if ($env{'form.cc'} =~ /,/) {
  520:             @ccs = split(/,/,$env{'form.cc'});
  521:         } else {
  522:             $env{'form.cc'} =~ s/^\s+//;
  523:             $env{'form.cc'} =~ s/\s+$//;
  524:             @ccs = $env{'form.cc'};
  525:         }
  526:         foreach my $cc (@ccs) {
  527:             $cc =~ s/^\s+//g;
  528:             $cc =~ s/\s+$//g;
  529:             if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
  530:                 if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
  531:                     push(@ok_ccs,$cc);
  532:                 }
  533:             } else {
  534:                 if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
  535:                     push(@bad_ccs,$cc);
  536:                 }
  537:             }
  538:         }
  539:         if (@ok_ccs > 0) {
  540:            $okcclist = join(', ',@ok_ccs); 
  541:         } 
  542:         if (@bad_ccs == 1) {
  543:             $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').$bad_ccs[0];
  544:         } elsif (@bad_ccs > 1) {
  545:             my $bad_cc_string = join(', ',@bad_ccs);
  546:             $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: ').$bad_cc_string;
  547:         }
  548:     }
  549:     $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
  550:     $env{'form.csri'} = $env{'form.title'}.' - '.$coursecode.' - '.$lt{'sect'}.': '.$env{'form.section'};
  551:     my $supportmsg = <<END;
  552: $lt{'username'}: $env{'form.username'}
  553: $lt{'email'}: $env{'form.email'}
  554: $lt{'cc'}: $okcclist
  555: $lt{'user'}: $env{'form.user'}
  556: $lt{'phone'}: $env{'form.phone'}
  557: $lt{'crsi'}: $env{'form.csri'}
  558: $lt{'subject'}: $env{'form.subject'}
  559: $lt{'description'}: $env{'form.description'}
  560: $lt{'sourceurl'}: $env{'form.sourceurl'}
  561: $lt{'date'}: $reporttime
  562: 
  563: END
  564:     my $displaymsg;
  565:     foreach my $item ('username','email','cc','user','phone','crsi','subject','description','sourceurl') {
  566:         if ($env{'form.'.$item} ne '') {
  567:             if ($item eq 'description') {
  568:                 my $descrip = $env{'form.description'};
  569:                 $descrip =  &cleanup_html($descrip);
  570:                 $descrip =~ s|[\n\r\f]|<br />|g;
  571:                 $displaymsg .= 
  572:                     '<span class="LC_helpform_receipt_cat">'.
  573:                     "$lt{$item}</span>: $descrip<br />\n";
  574:             } elsif ($item eq 'sourceurl') {
  575:                 my $showurl = $env{'form.sourceurl'};
  576:                 $showurl =~ s/\?.*$//;
  577:                 $showurl =  &cleanup_html($showurl);
  578:                 $displaymsg .= 
  579:                     '<span class="LC_helpform_receipt_cat">'.
  580:                     "$lt{$item}</span>: $showurl<br />\n";
  581:             } elsif ($item eq 'cc') {
  582:                 $displaymsg .=
  583:                     '<span class="LC_helpform_receipt_cat">'.
  584:                     "$lt{$item}</span>: $okcclist<br />\n";
  585:             } else {
  586:                 my $showitem = $env{'form.'.$item};
  587:                 $showitem = &cleanup_html($showitem);
  588:                 $displaymsg .= 
  589:                     '<span class="LC_helpform_receipt_cat">'.
  590:                     "$lt{$item}</span>: $showitem<br />\n";
  591:             }
  592:         }
  593:     }
  594:     $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
  595:                    $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
  596: 
  597:     my $start_page = 
  598: 	&Apache::loncommon::start_page('Support request recorded',undef,
  599: 				       {'function'    => $function,
  600: 					'add_entries' => {
  601: 					    topmargin    => "0",
  602: 					    marginheight => "0",
  603: 					},
  604: 					'only_body'   => 1,});
  605: 
  606:     $r->print(<<"END");
  607: $start_page
  608: <form name="logproblem">
  609: <input type="hidden" name="command" value="result" />
  610: </form>
  611: END
  612:     if ($r->uri eq '/adm/helpdesk') {
  613:         &print_header($r,$url,'process');
  614:     }
  615:     my $bad_email = 0;
  616:     if ($to =~ /,/) {
  617:         my @ok_email; 
  618:         foreach my $email (split(/,/,$to)) {
  619:             if ($email =~ m/^[^\@]+\@[^\@]+$/) {
  620:                 if (!grep(/^\Q$email\E$/,@ok_email)) {
  621:                     push(@ok_email,$email);
  622:                 }
  623:             }
  624:         }
  625:         if (@ok_email > 0) {
  626:             $to = join(',',@ok_email);
  627:         } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
  628:             $to = $admin;
  629:         } else {
  630:             $bad_email = 1;
  631:         }
  632:     } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
  633:         if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
  634:             $to = $admin;
  635:         } else {
  636:             $bad_email = 1;
  637:         }
  638:     }
  639:     if ($bad_email) {
  640:         $r->print('
  641:  <h3>'.$lt{'warn'}.'</h3>'.
  642: &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.')); 
  643:             $to = 'helpdesk@lon-capa.org';
  644:     } else {
  645:         $r->print('<h3>'.$lt{'asup'}.' '.$to.'</h3>');
  646:     }
  647:     if (defined($env{'form.email'})) {
  648:         $env{'form.email'} =~ s/^\s+//;
  649:         $env{'form.email'} =~ s/\s+$//;
  650:         if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
  651:             $from = $env{'form.email'};
  652:         }
  653:     }
  654: 
  655:     if (defined($env{'form.cc'})) {
  656:         if ($badccmsg) {
  657:             $displaymsg .= $badccmsg;
  658:         }
  659:     }
  660: 
  661:     my $subject = $env{'form.subject'};
  662:     $subject =~ s/(`)/'/g;
  663:     $subject =~ s/\$/\(\$\)/g;
  664:     $supportmsg =~ s/(`)/'/g;
  665:     $supportmsg =~ s/\$/\(\$\)/g;
  666:     $displaymsg =~ s/(`)/'/g;
  667:     $displaymsg =~ s/\$/\(\$\)/g;
  668:     my $fname;
  669: 
  670:     my $attachmentpath = '';
  671:     my $attachmentsize = '';
  672:     if (defined($env{'user.name'})) {
  673:         if ($env{'form.screenshot.filename'}) {
  674:             $attachmentsize = length($env{'form.screenshot'});
  675:             if ($attachmentsize > 131072) {
  676:                 $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);
  677:             } else {
  678:                 $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
  679:             }
  680:         }
  681:     }
  682: 
  683:     my %cookies;
  684:     my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
  685:     if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
  686:         $cookies{'lonID'} = $1;
  687:     }
  688: 
  689:     if ($attachmentpath =~ m-/([^/]+)$-) {
  690:         $fname = $1;
  691:         $displaymsg .= '<br />'
  692:                       .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
  693:                           ,'<span class="LC_filename">'.$fname.'<span>'
  694:                           ,$attachmentsize
  695:                           ,$env{'user.name'}.':'.$env{'user.domain'}
  696:                        );
  697:         $supportmsg .= "\n";
  698:         foreach my $var (@cookievars) {
  699:             $supportmsg .= "$var: $cookies{$var}\n";
  700:         }
  701:         foreach my $var(@ENVvars) {
  702:             $supportmsg .= "$var: $ENV{$var}\n";
  703:         }
  704:         foreach my $var (@envvars) {
  705:             $supportmsg .= "$var: $env{$var}\n";
  706:         }
  707:     }
  708:  
  709:     my $msg = MIME::Lite->new(
  710:                  From    => $from,
  711:                  To      => $to,
  712:                  Subject => $subject,
  713:                  Type    =>'TEXT',
  714:                  Data    => $supportmsg,
  715:                  );
  716:     if (@ok_ccs > 0) {
  717:         my $cc_string = join(', ',@ok_ccs);
  718:         $msg->add("Cc" => $cc_string);
  719:     }
  720: 
  721:     if ($attachmentpath) {
  722:         my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
  723:         $msg->attach(Type     => $type,
  724:                      Path     => $attachmentpath,
  725:                      Filename => $fname
  726:                      );
  727: 
  728:     } else {
  729:         my $envdata = '';
  730:         foreach my $var (@cookievars) {
  731:             $envdata .= "$var: $cookies{$var}\n";
  732:         }
  733:         foreach my $var (@ENVvars) {
  734:             $envdata .= "$var: $ENV{$var}\n";
  735:         }
  736:         foreach my $var (@envvars) {
  737:             $envdata .= "$var: $env{$var}\n";
  738:         }
  739:         foreach my $var (@loncvars) {
  740:             $envdata .= "$var: $env{$var}\n";
  741:         }
  742:         $msg->attach(Type => 'TEXT',
  743:                      Data => $envdata);
  744:     }
  745: 
  746: ### Send it:
  747:     $msg->send('sendmail');
  748: 
  749:     if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
  750:         unlink($attachmentpath);
  751:     }
  752:     $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
  753:     $r->print('<div style="width:620px;">'.
  754:               &Apache::lonhtmlcommon::start_pick_box().
  755:               &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
  756:               &Apache::lonhtmlcommon::row_closure().
  757:               &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
  758:     my $envmsg;
  759:     foreach my $var (@cookievars) {
  760:         if ($cookies{$var} ne '') {
  761:             $envmsg.= '<span class="LC_helpform_receipt_cat">'.
  762:                       $var.'</span>:&nbsp;'.$cookies{$var}.', ';
  763:         }
  764:     }
  765:     foreach my $var (@ENVvars) {
  766:         if ($ENV{$var} ne '') {
  767:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
  768:                        $var.'</span>:&nbsp;'.$ENV{$var}.', ';
  769:         }
  770:     }
  771:     foreach my $var (@envvars) {
  772:         if ($env{$var} ne '') { 
  773:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
  774:                        $var.'</span>:&nbsp;'.$env{$var}.', ';
  775:         }
  776:     }
  777:     $envmsg =~ s/, $//;
  778:     $r->print($envmsg."\n".
  779:               &Apache::lonhtmlcommon::row_closure(1)."\n".
  780:               &Apache::lonhtmlcommon::end_pick_box().
  781:               "</div>\n".
  782:               &Apache::loncommon::end_page());
  783: }
  784: 
  785: sub print_header {
  786:     my ($r,$origurl,$command) = @_;
  787:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
  788:     my ($component_url);
  789:     my $helpdesk_link = '<a href="javascript:validate()">';
  790:     if ($command eq 'process') {
  791:         $helpdesk_link = '<a href="/adm/helpdesk">';
  792:     }
  793:     my %lt = &Apache::lonlocal::texthash (
  794:                                            login => 'Log-in help',
  795:                                            ask   => 'Ask helpdesk',
  796:                                            getst => 'Getting started guide',
  797:                                            back =>  'Back to last location',
  798:                                            headline => 'help/support',
  799:                                          );
  800:     my ($getstartlink,$reviewtext);
  801:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
  802:         $getstartlink = qq|<td align="center">&nbsp;<b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
  803:         $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
  804:     } else {
  805:         $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
  806:     }
  807:     $r->print(<<END);
  808: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55">   <tr height="50">    <td width='5'>&nbsp;</td>
  809:    <td>
  810:     <fieldset>
  811:       <legend>
  812:         <img src="$location/lonIcons/minilogo.gif" height="20" width="29" valign="bottom" />
  813:         LON-CAPA $lt{'headline'}
  814:       </legend>
  815:  <table id="LC_helpmenu_links">
  816:    <tr>
  817:     <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>
  818:     <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
  819:     <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>
  820:    </tr>
  821:  </table>
  822: </fieldset>
  823:   </td>
  824:   <td width='5'>&nbsp;</td>
  825:  </tr>
  826:  <tr height='5'>
  827:   <td colspan='3' height='5'>&nbsp;</td>
  828:  </tr>
  829: END
  830:     if  ($command ne 'process') {
  831:         $r->print('
  832:  <tr>
  833:   <td colspan="3">'.$reviewtext.' '
  834: .&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.').'<br />'
  835: .'<font size="-1"><b>'.&mt('Students').'</b>: '.&mt('Do <b>not</b> use this form to ask questions about course content.').' '
  836: .&mt('Contact your instructor instead.')
  837: .'</font><br /><br />
  838:   </td>
  839:  </tr>');
  840:     }
  841:     $r->print('
  842: </table>');
  843:     return;
  844: }
  845: 
  846: sub get_domain {
  847:     my $codedom;
  848:     if (exists($env{'form.codedom'})) {
  849:         $codedom = $env{'form.codedom'};
  850:     } elsif ($env{'request.course.id'}) {
  851:         $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  852:     } elsif ($env{'request.role.domain'}) {
  853:         $codedom = $env{'request.role.domain'};
  854:     } else {
  855:         $codedom = &Apache::lonnet::default_login_domain();
  856:     }
  857:     return $codedom;
  858: }
  859: 
  860: sub cleanup_html {
  861:     my ($incoming) = @_;
  862:     my $outgoing;
  863:     if ($incoming ne '') {
  864:         $outgoing = $incoming;
  865:         $outgoing =~ s/\#/&#035;/g;
  866:         $outgoing =~ s/\&/&#038;/g;
  867:         $outgoing =~ s/</&#060;/g;
  868:         $outgoing =~ s/>/&#062;/g;
  869:         $outgoing =~ s/\(/&#040/g;
  870:         $outgoing =~ s/\)/&#041;/g;
  871:         $outgoing =~ s/"/&#034;/g;
  872:         $outgoing =~ s/'/&#039;/g;
  873:         $outgoing =~ s/\$/&#036;/g;
  874:     }
  875:     return $outgoing;
  876: }
  877: 
  878: 1;

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