File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.56: download - view: text, annotated - select for diffs
Wed Apr 14 03:09:35 2010 UTC (14 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD
- User: public:public does not count as a logged in user.
- Domain Configuration can include one or Bcc recipients of helpdesk email.

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

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