File:  [LON-CAPA] / loncom / interface / lonsupportreq.pm
Revision 1.66.6.2: download - view: text, annotated - select for diffs
Fri Feb 10 19:22:19 2012 UTC (12 years, 3 months ago) by raeburn
Branches: loncapaMITrelate_1
Diff to branchpoint 1.66: preferred, unified
- Customization for MITrelate
  - Remove unused item
  - Fix typo

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

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