File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.66.6.1: download - view: text, annotated - select for diffs
Wed Feb 8 17:49:01 2012 UTC (12 years, 4 months ago) by raeburn
Branches: loncapaMITrelate_1
Diff to branchpoint 1.66: preferred, unified
- Customization for MITrelate.
  - Course information not required.

    1: #
    2: # $Id: lonsupportreq.pm,v 1.66.6.1 2012/02/08 17:49:01 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 LONCAPA qw(:DEFAULT :match);
   40:  
   41: 
   42: sub handler {
   43:     my ($r) = @_;
   44:     &Apache::loncommon::content_type($r,'text/html');
   45:     $r->send_http_header;
   46: 
   47:     if ($r->header_only) {
   48:         return OK;
   49:     }
   50:     if ($r->uri eq '/adm/helpdesk') {
   51: 	&Apache::lonlocal::get_language_handle($r);
   52:     }
   53: 
   54:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['origurl','function']);
   55:     if ($r->uri eq '/adm/helpdesk') {
   56:         &Apache::lonacc::get_posted_cgi($r);
   57:     }
   58:     my $function = $env{'form.function'};
   59:     my $origurl = $env{'form.origurl'};
   60:     my $command = $env{'form.command'};
   61: 
   62:     if ($command eq 'process') {
   63:         &print_request_receipt($r,$origurl,$function);
   64:     } else {
   65:         &print_request_form($r,$origurl,$function);
   66:     }
   67:     return OK;
   68: }
   69:     
   70: sub print_request_form {
   71:     my ($r,$origurl,$function) = @_;
   72:     my ($os,$browser,$bversion,$uhost,$uname,$udom,$uhome,$email,
   73:         $lastname,$firstname,$server,$formname,$public);
   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:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
   81:         $public = 1;
   82:     } else {
   83:         $uname = $env{'user.name'};
   84:         $udom = $env{'user.domain'};
   85:     }
   86:     $uhome = $env{'user.home'};
   87:     $formname = 'logproblem';
   88:     my $machine = &Apache::lonnet::absolute_url();
   89:     if ($origurl =~ m-^https?://-) {
   90:         $server = $origurl;
   91:     } else {
   92:         $server = $machine.$origurl;
   93:     }
   94:     my $showserver = $server;
   95:     $showserver =~ s/\?.*$//;
   96:     my %lt = &Apache::lonlocal::texthash (
   97:                   email => 'The e-mail address you entered',
   98:                   notv => 'is not a valid e-mail address',
   99:                   rsub => 'You must include a subject',
  100:                   rdes => 'You must include a description',
  101:                   name => 'Name',
  102:                   subm => 'Submit Request',
  103:                   emad => 'Your e-mail address',
  104:                   emac => 'Cc', 
  105:                   unme => 'username',
  106:                   doma => 'domain',
  107:                   entu => 'Enter the username you use to log-in to LON-CAPA',
  108:                   chdo => 'Choose your LON-CAPA domain',
  109:                   entr => 'Enter the username you use to log-in to LON-CAPA, and your domain.',
  110:                   urlp => 'URL of page',
  111:                   phon => 'Phone',
  112:                   pick => 'Pick',
  113:                   subj => 'Subject',
  114:                   detd => 'Detailed Description',
  115:                   opfi => 'Optional file upload',
  116:                   uplf => 'Upload a file (e.g., a screenshot) relevant to your help request (128 KB max.)',
  117:                   fini => 'Finish',
  118:                   clfm => 'Clear Form',
  119:     );
  120:     my $scripttag = (<<"END");
  121: function validate() {
  122:     if (validmail(document.logproblem.email) == false) {
  123:         alert("$lt{'email'}: "+document.logproblem.email.value+" $lt{'notv'}.");
  124:         return;
  125:     }
  126:     if (document.logproblem.subject.value == '') {
  127:         alert("$lt{'rsub'}.");
  128:         return;
  129:     }
  130:     if (document.logproblem.description.value == '') {
  131:         alert("$lt{'rdes'}.");
  132:         return;
  133:     }
  134:     document.logproblem.submit();
  135: }
  136: 
  137: END
  138:     $scripttag .= &Apache::lonhtmlcommon::javascript_valid_email();
  139: 
  140:     if ($env{'environment.permanentemail'}) {
  141:         $email = $env{'environment.permanentemail'};
  142:     } elsif ($env{'environment.critnotification'}) {
  143:         $email = $env{'environment.critnotification'};
  144:     } elsif ($env{'environment.notification'}) {
  145:         $email = $env{'environment.notification'};
  146:     }
  147:     if ($env{'environment.lastname'}) {
  148:         $lastname = $env{'environment.lastname'};
  149:     }
  150:     if ($env{'environment.firstname'}) {
  151:         $firstname = $env{'environment.firstname'};
  152:     }
  153: 
  154:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['codedom',
  155:                                                  'useremail','useraccount']);
  156:     if ($env{'form.origurl'} eq '/adm/createaccount') {
  157:         if ($email eq '') {
  158:             if ($env{'form.useremail'} =~ /^[^\@]+\@[^\@]+$/) {
  159:                 $email = &HTML::Entities::encode($env{'form.useremail'},'"<>&');
  160:             }
  161:         }
  162:         if ($uname eq '') {
  163:             if ($env{'form.useraccount'} =~ /^$match_username$/) {
  164:                 $uname = &HTML::Entities::encode($env{'form.useraccount'},'"<>&');
  165:             }
  166:         }
  167:     }
  168:     my $codedom = &get_domain();
  169:     my $caller = 'global';
  170:     my $format_reply;
  171:     my $jscript = '';
  172:     my $js = '<script type="text/javascript">'."\n$scripttag\n$jscript\n".
  173: 	     '</script>';
  174:     my %add_entries = (topmargin    => "0",
  175: 		       marginheight => "0",
  176: 		      );
  177:     
  178:     $r->print(&Apache::loncommon::start_page('Support Request',$js,
  179: 				       { 'function'    => $function,
  180: 					 'add_entries' => \%add_entries,
  181: 					 'only_body'   => 1,}));
  182:     if ($r->uri eq '/adm/helpdesk') {
  183:         &print_header($r,$origurl);
  184:     }
  185:     my @css = ('LC_evenrow_value','LC_oddrow_value');
  186:     my $num = 1;
  187:     my $i = $num%2;
  188:     $r->print('<form method="post" name="logproblem" enctype="multipart/form-data">'."\n");
  189:     my $output = &Apache::lonhtmlcommon::start_pick_box().
  190:                  &Apache::lonhtmlcommon::row_title($lt{'name'},undef,$css[$num])."\n";
  191:     my $fullname = '';
  192:     if ((defined($lastname) && $lastname ne '') && (defined($firstname) && $firstname ne '')) {
  193:         $fullname = "$firstname $lastname"; 
  194:         $output .= $fullname.'<input type="hidden" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />';
  195:     } else {
  196:         if (defined($firstname) && $firstname ne '') {
  197:             $fullname = $firstname;
  198:         } elsif (defined($lastname) && $lastname ne '') {
  199:             $fullname = " $lastname";
  200:         }
  201:         $output .= '<input type="text" size="20" name="username" value="'.&HTML::Entities::encode($fullname,'"<>&').'" />';
  202:     }
  203:     $output .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$lt{'subm'}.'" onclick="validate()" />&nbsp;'.
  204:                 &Apache::lonhtmlcommon::row_closure()."\n";
  205:     $num ++;
  206:     $i = $num%2;
  207:     $output .= &Apache::lonhtmlcommon::row_title($lt{'emad'},undef,$css[$i]).
  208:                '<input type="text" size="20" name="email" value="'.
  209:                &HTML::Entities::encode($email,'"<>&').'" /><br />'."\n".
  210:                &Apache::lonhtmlcommon::row_closure();
  211:     $num ++;
  212:     $i = $num%2;
  213:     if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
  214:         $output .= &Apache::lonhtmlcommon::row_title($lt{'emac'},undef,$css[$i]).
  215:                    '<input type="text" size="50" name="cc" value="" /><br />'."\n".
  216:                    &Apache::lonhtmlcommon::row_closure();
  217:         $num ++;
  218:         $i = $num%2;
  219:     }
  220:     $output .= &Apache::lonhtmlcommon::row_title("$lt{'unme'}/$lt{'doma'}",undef,$css[$i]);
  221:     my $udom_input = '<input type="hidden" name="udom" value="'.
  222:                      &HTML::Entities::encode($udom,'"<>&').'" />';
  223:     my $uname_input = '<input type="hidden" name="uname" value="'.
  224:                       &HTML::Entities::encode($uname,'"<>&').'" />'; 
  225:     if (($env{'user.name'} =~ /^$match_username$/) && 
  226:         ($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
  227:         $output .= '<i>'.$lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;<i>'.$lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input.$uname_input;
  228:     } else {
  229:         my $udomform = '';
  230:         my $unameform = '';
  231:         if (($env{'user.domain'} =~ /^$match_domain$/) && (!$public)) {
  232:             $output .= $lt{'entu'};
  233:         } elsif (($env{'user.name'} =~ /^$match_username$/) && (!$public)) { 
  234:             $output .= $lt{'chdo'};
  235:         } else {
  236:             $output .= $lt{'entr'};
  237:         }
  238:         $output .= '<br />';
  239:         if (!$public) {
  240:             if ($env{'user.domain'} =~ /^$match_domain$/) {
  241:                 $udomform = '<i>'.$lt{'doma'}.'</i>:&nbsp;'.$udom.$udom_input;
  242:             } elsif ($env{'user.name'} =~ /^$match_username$/) {
  243:                 $unameform = '<i>'.$lt{'unme'}.'</i>:&nbsp;'.$uname.'&nbsp;&nbsp;'.$uname_input;
  244:             }
  245:         }
  246:         if ($udomform eq '') {
  247:             $udomform = '<i>'.$lt{'doma'}.'</i>:&nbsp;';
  248:             $udomform .= &Apache::loncommon::select_dom_form($codedom,'udom');
  249:         }
  250:         if ($unameform eq '') {
  251:             $unameform= '<i>'.$lt{'unme'}.'</i>:&nbsp;<input type="text" size="20" name="uname" value="'.$uname.'" />&nbsp;&nbsp;';
  252:         }
  253:         $output .= $unameform.$udomform;
  254:     }
  255:     $output .= &Apache::lonhtmlcommon::row_closure();
  256:     $num ++;
  257:     $i = $num%2;
  258:     $output .= &Apache::lonhtmlcommon::row_title("$lt{'urlp'}",undef,$css[$i]).
  259:                $showserver.'<input type="hidden" name="sourceurl" value="'.
  260:                &HTML::Entities::encode($server,'"<>&').'" />'.
  261:                &Apache::lonhtmlcommon::row_closure().
  262:     $num ++;
  263:     $i = $num%2;
  264:     $output .= &Apache::lonhtmlcommon::row_title("$lt{'phon'}",undef,
  265:                                                  'LC_evenrow_value').
  266:                '<input type="text" size="15" name="phone" /><br />'.
  267:                &Apache::lonhtmlcommon::row_closure();
  268:     $num ++;
  269:     $i = $num%2;
  270:     $output .= &Apache::lonhtmlcommon::row_title($lt{'subj'},undef,'LC_oddrow_value').
  271:                '  <input type="text" size="40" name="subject" />'."\n".
  272:                &Apache::lonhtmlcommon::row_closure().
  273:                &Apache::lonhtmlcommon::row_title($lt{'detd'},undef,'LC_evenrow_value').
  274:                '  <textarea rows="10" cols="45" name="description" wrap="virtual"></textarea>'.
  275:                &Apache::lonhtmlcommon::row_closure();
  276:     $num ++;
  277:     $i = $num%2; 
  278:     if (($env{'user.name'} =~ /^$match_username$/) && (!$public)) {
  279:         $output .= &Apache::lonhtmlcommon::row_title($lt{'opfi'},undef,$css[$i]).
  280:                    ' <input type="file" name="screenshot" size="20" /><br />'.$lt{'uplf'}."\n".
  281:         &Apache::lonhtmlcommon::row_closure();
  282:         $num ++;
  283:         $i = $num%2; 
  284:     }
  285:     $output .= &Apache::lonhtmlcommon::row_title($lt{'fini'},undef,$css[$i]);
  286:     $output .= <<END;
  287:              <table border="0" cellpadding="8" cellspacing="0">
  288:               <tr>
  289:                <td>
  290:                 <input type="hidden" name="command" value="process" />
  291:                 <input type="button" value="$lt{'subm'}" onclick="validate()" /> &nbsp;
  292:                </td>
  293:                <td>&nbsp;</td>
  294:                <td>
  295:                 <input type="reset" value="$lt{'clfm'}" />
  296:                </td>
  297:               </tr>
  298:              </table>
  299: END
  300:     $output .= &Apache::lonhtmlcommon::row_closure(1);
  301:     $output .= &Apache::lonhtmlcommon::end_pick_box();
  302:     $r->print(<<END);
  303: $output
  304: </form>
  305: <br />
  306: END
  307:     $r->print(&Apache::loncommon::end_page());
  308:     return;
  309: }
  310: 
  311: sub print_request_receipt {
  312:     my ($r,$url,$function) = @_;
  313:     my @ENVvars = ('HTTP_HOST','HTTP_USER_AGENT','REMOTE_ADDR','SERVER_ADDR','SERVER_NAME');
  314:     my @envvars = ('browser.os','browser.type','browser.version','user.home','request.role');
  315:     my @loncvars = ('user.name','user.domain','request.course.sec','request.course.id');
  316:     my @cookievars = ('lonID');
  317: 
  318:     my $admin = $Apache::lonnet::perlvar{'lonAdminMail'};
  319:     my $origmail = $Apache::lonnet::perlvar{'lonSupportEMail'};
  320:     my $defdom = &get_domain();
  321:     my $to = &Apache::loncommon::build_recipient_list(undef,'helpdeskmail',
  322:                                                       $defdom,$origmail);
  323:     my $from = $admin;
  324:     my $bcc;
  325:     my %domconfig =
  326:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
  327:     if (ref($domconfig{'contacts'}) eq 'HASH') {
  328:         if (exists($domconfig{'contacts'}{'helpdeskmail'})) {
  329:             if (ref($domconfig{'contacts'}{'helpdeskmail'}) eq 'HASH') {
  330:                 my $bccmail = $domconfig{'contacts'}{'helpdeskmail'}{'bcc'};
  331:                 if ($bccmail ne '') {
  332:                     my @bccs = split(/,/,$bccmail);
  333:                     my @ok_bccs;
  334:                     foreach my $bcc (@bccs) {
  335:                         $bcc =~ s/^\s+//g;
  336:                         $bcc =~ s/\s+$//g;
  337:                         if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
  338:                             if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
  339:                                 push(@ok_bccs,$bcc);
  340:                             }
  341:                         }
  342:                     }
  343:                     if (@ok_bccs > 0) {
  344:                         $bcc = join(', ',@ok_bccs);
  345:                     }
  346:                 }
  347:             }
  348:         }
  349:     }
  350:     my $reporttime = &Apache::lonlocal::locallocaltime(time);
  351:     my @formvars = ('username','email','uname','udom','sourceurl','phone',
  352:                     'subject','description','screenshot');
  353:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},\@formvars);
  354:     my %lt = &Apache::lonlocal::texthash (
  355:                  username    => 'Name',
  356:                  email       => 'E-mail',
  357:                  cc          => 'Cc',
  358:                  user        => 'Username/domain',
  359:                  phone       => 'Phone',
  360:                  subject     => 'Subject',
  361:                  description => 'Description',
  362:                  sourceurl   => 'URL',
  363:                  date        => 'Date/Time',
  364:                  warn        => 'Warning: Problem with support e-mail address',
  365:                  your        => 'Your support request contained the following information',
  366:                  info        => 'Information supplied',
  367:                  adin        => 'Additional information recorded',
  368:     );
  369: 
  370:     my (@ok_ccs,@bad_ccs,$badccmsg,$okcclist);
  371:     if ((defined($env{'user.name'})) && (defined($env{'form.cc'}))) {
  372:         my @ccs;
  373:         if ($env{'form.cc'} =~ /,/) {
  374:             @ccs = split(/,/,$env{'form.cc'});
  375:         } else {
  376:             $env{'form.cc'} =~ s/^\s+//;
  377:             $env{'form.cc'} =~ s/\s+$//;
  378:             @ccs = $env{'form.cc'};
  379:         }
  380:         foreach my $cc (@ccs) {
  381:             $cc =~ s/^\s+//g;
  382:             $cc =~ s/\s+$//g;
  383:             if ($cc =~ m/^[^\@]+\@[^\@]+$/) {
  384:                 if (!(grep(/^\Q$cc\E$/,@ok_ccs))) {
  385:                     push(@ok_ccs,$cc);
  386:                 }
  387:             } elsif ($cc ne '') {
  388:                 if (!(grep(/^\Q$cc\E$/,@bad_ccs))) {
  389:                     push(@bad_ccs,$cc);
  390:                 }
  391:             }
  392:         }
  393:         if (@ok_ccs > 0) {
  394:            $okcclist = join(', ',@ok_ccs); 
  395:         } 
  396:         if (@bad_ccs == 1) {
  397:             $badccmsg .= '<br />'.&mt('The following Cc e-mail address is invalid: ').$bad_ccs[0];
  398:         } elsif (@bad_ccs > 1) {
  399:             my $bad_cc_string = join(', ',@bad_ccs);
  400:             $badccmsg .= '<br />'.&mt('The following Cc e-mail addresses are invalid: ').$bad_cc_string;
  401:         }
  402:     }
  403:     $env{'form.user'} = "'".$env{'form.uname'}.':'.$env{'form.udom'}."'";
  404:     my $supportmsg = <<END;
  405: $lt{'username'}: $env{'form.username'}
  406: $lt{'email'}: $env{'form.email'}
  407: $lt{'cc'}: $okcclist
  408: $lt{'user'}: $env{'form.user'}
  409: $lt{'phone'}: $env{'form.phone'}
  410: $lt{'subject'}: $env{'form.subject'}
  411: $lt{'description'}: $env{'form.description'}
  412: $lt{'sourceurl'}: $env{'form.sourceurl'}
  413: $lt{'date'}: $reporttime
  414: 
  415: END
  416:     my $displaymsg;
  417:     foreach my $item ('username','email','cc','user','phone','subject',
  418:                       'description','sourceurl') {
  419:         if ($env{'form.'.$item} ne '') {
  420:             if ($item eq 'description') {
  421:                 my $descrip = $env{'form.description'};
  422:                 $descrip =  &cleanup_html($descrip);
  423:                 $descrip =~ s|[\n\r\f]|<br />|g;
  424:                 $displaymsg .= 
  425:                     '<span class="LC_helpform_receipt_cat">'.
  426:                     "$lt{$item}</span>: $descrip<br />\n";
  427:             } elsif ($item eq 'sourceurl') {
  428:                 my $showurl = $env{'form.sourceurl'};
  429:                 $showurl =~ s/\?.*$//;
  430:                 $showurl =  &cleanup_html($showurl);
  431:                 $displaymsg .= 
  432:                     '<span class="LC_helpform_receipt_cat">'.
  433:                     "$lt{$item}</span>: $showurl<br />\n";
  434:             } elsif ($item eq 'cc') {
  435:                 $displaymsg .=
  436:                     '<span class="LC_helpform_receipt_cat">'.
  437:                     "$lt{$item}</span>: $okcclist<br />\n";
  438:             } else {
  439:                 my $showitem = $env{'form.'.$item};
  440:                 $showitem = &cleanup_html($showitem);
  441:                 $displaymsg .= 
  442:                     '<span class="LC_helpform_receipt_cat">'.
  443:                     "$lt{$item}</span>: $showitem<br />\n";
  444:             }
  445:         }
  446:     }
  447:     $displaymsg .= '<span class="LC_helpform_receipt_cat">'.
  448:                    $lt{'date'}.'</span>: '.$reporttime.'<br />'."\n";
  449: 
  450:     my $start_page = 
  451: 	&Apache::loncommon::start_page('Support request recorded',undef,
  452: 				       {'function'    => $function,
  453: 					'add_entries' => {
  454: 					    topmargin    => "0",
  455: 					    marginheight => "0",
  456: 					},
  457: 					'only_body'   => 1,});
  458: 
  459:     $r->print(<<"END");
  460: $start_page
  461: <form name="logproblem">
  462: <input type="hidden" name="command" value="result" />
  463: </form>
  464: END
  465:     if ($r->uri eq '/adm/helpdesk') {
  466:         &print_header($r,$url,'process');
  467:     }
  468:     my $bad_email = 0;
  469:     if ($to =~ /,/) {
  470:         my @ok_email; 
  471:         foreach my $email (split(/,/,$to)) {
  472:             if ($email =~ m/^[^\@]+\@[^\@]+$/) {
  473:                 if (!grep(/^\Q$email\E$/,@ok_email)) {
  474:                     push(@ok_email,$email);
  475:                 }
  476:             }
  477:         }
  478:         if (@ok_email > 0) {
  479:             $to = join(',',@ok_email);
  480:         } elsif ($admin =~ m/^[^\@]+\@[^\@]+$/) {
  481:             $to = $admin;
  482:         } else {
  483:             $bad_email = 1;
  484:         }
  485:     } elsif ($to !~ m/^[^\@]+\@[^\@]+$/) {
  486:         if ($admin =~ m/^[^\@]+\@[^\@]+$/) {
  487:             $to = $admin;
  488:         } else {
  489:             $bad_email = 1;
  490:         }
  491:     }
  492: 
  493:     my $message;
  494:     if (!$bad_email) {
  495:         $message = &Apache::lonhtmlcommon::confirm_success(
  496:             &mt('A support request has been sent to [_1]','<tt>'.$to.'</tt>'));
  497:     } else {
  498:         $message = &Apache::lonhtmlcommon::confirm_success(
  499:             $lt{'warn'}.'<br />'
  500:            .&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 [_2]not[_3] been sent to the LON-CAPA support staff or administrator at your institution.','<tt>'.$to.'</tt>','<b>','</b>')
  501:            .' '.&mt('Instead a copy has been sent to the LON-CAPA support team at Michigan State University.'),1); 
  502:         $to = 'helpdesk@lon-capa.org';
  503:     }
  504:     $r->print(&Apache::loncommon::confirmwrapper($message));
  505: 
  506:     if (defined($env{'form.email'})) {
  507:         $env{'form.email'} =~ s/^\s+//;
  508:         $env{'form.email'} =~ s/\s+$//;
  509:         if ($env{'form.email'} =~ m/^[^\@]+\@[^\@]+$/) {
  510:             $from = $env{'form.email'};
  511:         }
  512:     }
  513: 
  514:     if (defined($env{'form.cc'})) {
  515:         if ($badccmsg) {
  516:             $displaymsg .= $badccmsg;
  517:         }
  518:     }
  519: 
  520:     my $subject = $env{'form.subject'};
  521:     $subject =~ s/(`)/'/g;
  522:     $subject =~ s/\$/\(\$\)/g;
  523:     $supportmsg =~ s/(`)/'/g;
  524:     $supportmsg =~ s/\$/\(\$\)/g;
  525:     $displaymsg =~ s/(`)/'/g;
  526:     $displaymsg =~ s/\$/\(\$\)/g;
  527:     my $fname;
  528: 
  529:     my $attachmentpath = '';
  530:     my $attachmentsize = '';
  531:     if ((defined($env{'user.name'})) && ($env{'user.name'} ne 'public')
  532:         && ($env{'user.domain'} ne 'public')) {
  533:         if ($env{'form.screenshot.filename'}) {
  534:             $attachmentsize = length($env{'form.screenshot'});
  535:             if ($attachmentsize > 131072) {
  536:                 $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);
  537:             } else {
  538:                 $attachmentpath=&Apache::lonnet::userfileupload('screenshot',undef,'helprequests');
  539:             }
  540:         }
  541:     }
  542: 
  543:     my %cookies;
  544:     my $cookie=CGI::Cookie->parse($r->header_in('Cookie'));
  545:     if ($$cookie{'lonID'} =~ /lonID=($LONCAPA::handle_re);/) {
  546:         $cookies{'lonID'} = $1;
  547:     }
  548: 
  549:     if ($attachmentpath =~ m-/([^/]+)$-) {
  550:         $fname = $1;
  551:         $displaymsg .= '<br />'
  552:                       .&mt('An uploaded screenshot file [_1] ([_2] bytes) was included in the request sent by [_3].'
  553:                           ,'<span class="LC_filename">'.$fname.'</span>'
  554:                           ,$attachmentsize
  555:                           ,$env{'user.name'}.':'.$env{'user.domain'}
  556:                        );
  557:         $supportmsg .= "\n";
  558:         foreach my $var (@cookievars) {
  559:             $supportmsg .= "$var: $cookies{$var}\n";
  560:         }
  561:         foreach my $var(@ENVvars) {
  562:             $supportmsg .= "$var: $ENV{$var}\n";
  563:         }
  564:         foreach my $var (@envvars) {
  565:             $supportmsg .= "$var: $env{$var}\n";
  566:         }
  567:     }
  568:  
  569:     my $msg = MIME::Lite->new(
  570:                  From    => $from,
  571:                  To      => $to,
  572:                  Subject => $subject,
  573:                  Type    =>'TEXT',
  574:                  Data    => $supportmsg,
  575:                  );
  576:     if (@ok_ccs > 0) {
  577:         my $cc_string = join(', ',@ok_ccs);
  578:         $msg->add("Cc" => $cc_string);
  579:     }
  580:     if ($bcc ne '') {
  581:         $msg->add("Bcc" => $bcc);
  582:     }
  583:     $msg->attr("content-type"         => "text/plain");
  584:     $msg->attr("content-type.charset" => "UTF-8");
  585: 
  586:     if ($attachmentpath) {
  587:         my ($type, $encoding) = MIME::Types::by_suffix($attachmentpath);
  588:         $msg->attach(Type     => $type,
  589:                      Path     => $attachmentpath,
  590:                      Filename => $fname
  591:                      );
  592: 
  593:     } else {
  594:         my $envdata = '';
  595:         foreach my $var (@cookievars) {
  596:             $envdata .= "$var: $cookies{$var}\n";
  597:         }
  598:         foreach my $var (@ENVvars) {
  599:             $envdata .= "$var: $ENV{$var}\n";
  600:         }
  601:         foreach my $var (@envvars) {
  602:             $envdata .= "$var: $env{$var}\n";
  603:         }
  604:         foreach my $var (@loncvars) {
  605:             $envdata .= "$var: $env{$var}\n";
  606:         }
  607:         $msg->attach(Type => 'TEXT',
  608:                      Data => $envdata);
  609:     }
  610: 
  611: ### Send it:
  612:     $msg->send('sendmail');
  613: 
  614:     if ($attachmentpath =~ m|$Apache::lonnet::perlvar{'lonDaemons'}/tmp/helprequests/(\d+)/[^/]+|) {
  615:         unlink($attachmentpath);
  616:     }
  617:     $r->print('<b>'.$lt{'your'}.'</b>:<br /><br />'."\n");
  618:     $r->print('<div style="width:620px;">'.
  619:               &Apache::lonhtmlcommon::start_pick_box().
  620:               &Apache::lonhtmlcommon::row_title($lt{'info'},undef,'LC_oddrow_value')."\n".$displaymsg."\n".
  621:               &Apache::lonhtmlcommon::row_closure().
  622:               &Apache::lonhtmlcommon::row_title($lt{'adin'},undef,'LC_evenrow_value'));
  623:     my $envmsg;
  624:     foreach my $var (@cookievars) {
  625:         if ($cookies{$var} ne '') {
  626:             $envmsg.= '<span class="LC_helpform_receipt_cat">'.
  627:                       $var.'</span>:&nbsp;'.$cookies{$var}.', ';
  628:         }
  629:     }
  630:     foreach my $var (@ENVvars) {
  631:         if ($ENV{$var} ne '') {
  632:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
  633:                        $var.'</span>:&nbsp;'.$ENV{$var}.', ';
  634:         }
  635:     }
  636:     foreach my $var (@envvars) {
  637:         if ($env{$var} ne '') { 
  638:             $envmsg .= '<span class="LC_helpform_receipt_cat">'.
  639:                        $var.'</span>:&nbsp;'.$env{$var}.', ';
  640:         }
  641:     }
  642:     $envmsg =~ s/, $//;
  643:     $r->print($envmsg."\n".
  644:               &Apache::lonhtmlcommon::row_closure(1)."\n".
  645:               &Apache::lonhtmlcommon::end_pick_box().
  646:               "</div>\n".
  647:               &Apache::loncommon::end_page());
  648: }
  649: 
  650: sub print_header {
  651:     my ($r,$origurl,$command) = @_;
  652:     my $location=&Apache::loncommon::lonhttpdurl("/adm");
  653:     my ($component_url);
  654:     my $helpdesk_link = '<a href="javascript:validate()">';
  655:     if ($command eq 'process') {
  656:         $helpdesk_link = '<a href="/adm/helpdesk">';
  657:     }
  658:     my %lt = &Apache::lonlocal::texthash (
  659:                                            login => 'Log-in help',
  660:                                            ask   => 'Ask helpdesk',
  661:                                            getst => 'Getting started guide',
  662:                                            back =>  'Back to last location',
  663:                                            headline => 'help/support',
  664:                                          );
  665:     my ($getstartlink,$reviewtext);
  666:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/gettingstarted.html') {
  667:         $getstartlink = qq|<td align="center">&nbsp;<b><a href="/adm/gettingstarted.html">$lt{'getst'}</a></td>|;
  668:         $reviewtext = &mt('Please review the information in "Log-in help" and the "Getting started" guide if you are unable to log-in.');
  669:     } else {
  670:         $reviewtext = &mt('Please review the information in "Log-in help" if you are unable to log-in.');
  671:     }
  672:     if ($origurl eq '') {
  673:         $origurl = 'javascript:history.go(-1)';
  674:     }
  675:     $r->print(<<END);
  676: <table width="620" border="0" cellspacing="0" cellpadding="0" height="55">   <tr height="50">    <td width='5'>&nbsp;</td>
  677:    <td>
  678:     <fieldset>
  679:       <legend>
  680:         <img src="$location/lonIcons/minilogo.gif" height="20" width="29" valign="bottom" />
  681:         LON-CAPA $lt{'headline'}
  682:       </legend>
  683:  <table id="LC_helpmenu_links">
  684:    <tr>
  685:     <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>
  686:     <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
  687:     <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>
  688:    </tr>
  689:  </table>
  690: </fieldset>
  691:   </td>
  692:   <td width='5'>&nbsp;</td>
  693:  </tr>
  694:  <tr height='5'>
  695:   <td colspan='3' height='5'>&nbsp;</td>
  696:  </tr>
  697: END
  698:     if  ($command ne 'process') {
  699:         $r->print('
  700:  <tr>
  701:   <td colspan="3">'.$reviewtext.' '
  702: .&mt('If your problem is still unresolved, the form below can be used to send a question to the LON-CAPA helpdesk.').'<br />'
  703: .'<font size="-1"><b>'.&mt('Students').'</b>: '.&mt('Do <b>not</b> use this form to ask questions about course content.').' '
  704: .&mt('Contact your instructor instead.')
  705: .'</font><br /><br />
  706:   </td>
  707:  </tr>');
  708:     }
  709:     $r->print('
  710: </table>');
  711:     return;
  712: }
  713: 
  714: sub get_domain {
  715:     my $codedom;
  716:     if (exists($env{'form.codedom'})) {
  717:         $codedom = $env{'form.codedom'};
  718:     } elsif ($env{'request.course.id'}) {
  719:         $codedom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  720:     } elsif ($env{'request.role.domain'}) {
  721:         $codedom = $env{'request.role.domain'};
  722:     } else {
  723:         $codedom = &Apache::lonnet::default_login_domain();
  724:     }
  725:     return $codedom;
  726: }
  727: 
  728: sub cleanup_html {
  729:     my ($incoming) = @_;
  730:     my $outgoing;
  731:     if ($incoming ne '') {
  732:         $outgoing = $incoming;
  733:         $outgoing =~ s/\#/&#035;/g;
  734:         $outgoing =~ s/\&/&#038;/g;
  735:         $outgoing =~ s/</&#060;/g;
  736:         $outgoing =~ s/>/&#062;/g;
  737:         $outgoing =~ s/\(/&#040/g;
  738:         $outgoing =~ s/\)/&#041;/g;
  739:         $outgoing =~ s/"/&#034;/g;
  740:         $outgoing =~ s/'/&#039;/g;
  741:         $outgoing =~ s/\$/&#036;/g;
  742:     }
  743:     return $outgoing;
  744: }
  745: 
  746: 1;

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