File:  [LON-CAPA] / loncom / interface / lonerrorhandler.pm
Revision 1.23: download - view: text, annotated - select for diffs
Thu Feb 12 21:15:47 2009 UTC (15 years, 2 months ago) by schafran
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_99_1, version_2_8_99_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, bz5969, bz2851, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, GCI_2, BZ5971-printing-apage, BZ5434-fox, BZ4492-merge, BZ4492-feature_horizontal_radioresponse
consistent wording, email -> e-mail, catalog information -> metadata, e-mail vs. message

    1: # The LearningOnline Network
    2: # Internal Server Error Handler
    3: #
    4: # $Id: lonerrorhandler.pm,v 1.23 2009/02/12 21:15:47 schafran Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: 
   30: 
   31: package Apache::lonerrorhandler;
   32: 
   33: use strict;
   34: use Apache::Constants qw(:common);
   35: use Apache::loncommon();
   36: use Apache::lonnet;
   37: use Apache::lonmsg();
   38: use Apache::lonacc();
   39: use Apache::lonlocal;
   40: 
   41: sub handler {
   42:     my $r = shift;
   43:     &Apache::loncommon::content_type($r,'text/html');
   44:     $r->send_http_header;
   45:     return OK if $r->header_only;
   46: 
   47:     &Apache::lonacc::get_posted_cgi($r);
   48:     if (!$Apache::lonlocal::lh) {
   49:         &Apache::lonlocal::get_language_handle($r);
   50:     }
   51:     my $title = $env{'form.sendinfo'} ? 'Sending Error Report'
   52:                                       : 'Could Not Process Request';
   53:     $r->print(&Apache::loncommon::start_page($title));
   54: 
   55:     if ($env{'form.sendinfo'}) {
   56: 	my $repro='no';
   57: # ------------------------------------------------------------------ Mail stuff
   58: 	if ($env{'form.reproducible'}) {
   59: 	    $repro='yes';
   60: 	}
   61:         my %lt = &Apache::lonlocal::texthash (
   62:                      msg => 'LON-CAPA Error Message',
   63:                      rep => 'Reproducible',
   64:                      ver => 'Version',
   65:                      syl => 'Syllabus',
   66:                      pri => 'Prior Action',
   67:                      gue => 'Guesses',
   68:                      env => 'Environment',
   69:                  );
   70: 	my $message=(<<ENDMESSAGE);
   71: $lt{'msg'}
   72: $lt{'rep'}: $repro
   73: $lt{'ver'}: $env{'form.version'}
   74: $lt{'syl'}:
   75: $env{'form.syllabus'}
   76: 
   77: $lt{'pri'}:
   78: $env{'form.prioraction'}
   79: 
   80: $lt{'gue'}:
   81: $env{'form.guesses'}
   82: 
   83: $lt{'env'}:
   84: $env{'form.environment'}
   85: ENDMESSAGE
   86:         my $sysmail = $r->dir_config('lonSysEMail');
   87:         my $defdom = $r->dir_config('lonDefDomain');
   88:         my $origmail = $r->dir_config('lonAdmEMail');
   89:         my $recipients = &Apache::loncommon::build_recipient_list($sysmail,
   90:                                              'errormail',$defdom,$origmail);
   91:         if ($recipients ne '') {
   92:             &Apache::lonmsg::sendemail($recipients,'ERROR REPORT',$message);
   93: 	    $r->print('<h2>'.&mt('Report submitted').'</h2>'.&mt('Thank you!'));
   94:         } else {
   95:             $r->print('<h2>'.&mt('Warning: Report not submitted').'</h2>'.
   96:                       '<span class="LC_error">'
   97:                      .&mt('The administrators of the domain [_1] have not set'
   98:                          .' any e-mail addresses for receipt of your error report.'
   99:                          ,'<tt>'.$defdom.'</tt>')
  100:                      .'</span>');
  101:         }
  102:     } else {
  103: # ------------------------------------------------------------- Get environment
  104: 	my $envkey;
  105: 	my $env='';
  106: 	my $syllabus='';
  107: 
  108: 	foreach $envkey (keys(%env)) {
  109:             if ($envkey =~ /^form\.(.+)\.filename$/) {
  110:                 my $item = $1;
  111:                 if (exists($env{'form.'.$item.'.mimetype'})) {
  112:                     if (exists($env{'form.'.$item})) {
  113:                         my $size = (length($env{'form.'.$item}))/(1024.0 * 1024.0);
  114:                         $env{'form.'.$item} = &mt('File (contents not shown) - size was [_1] MB.',sprintf("%.4f",$size));
  115:                     }
  116:                 }
  117:             }
  118:         }
  119: 
  120: 	foreach $envkey (sort(keys(%env))) {
  121: 	    $env.="$envkey: $env{$envkey}\n";
  122: 	}
  123: 	foreach $envkey (sort(keys(%ENV))) {
  124: 	    $env.="$envkey: $ENV{$envkey}\n";
  125: 	    if ($envkey=~/REDIRECT\_(REQUEST_URI|SCRIPT|ERROR)/) {
  126: 		$syllabus.="\n$1:\n$ENV{$envkey}";
  127: 	    }
  128: 	}
  129: 
  130: 	$env=~s/\"/\'\'/g;
  131: 
  132: 	my $version=$r->dir_config('lonVersion');
  133: 
  134: # ----------------------------------------------------------- Print error form
  135: 	$r->print('<h2 class="LC_error">'
  136: .&mt('Somewhere something went wrong')
  137: .'</h2>'
  138: .'<p>'.&mt('Please help us to find out what.').'</p>'
  139: .'<p>'.&mt('Please take a moment to fill out the form below.').' '
  140: .&mt('Your information, together with internal debugging information, '
  141:     .'will be e-mailed to the system and server administrators.')
  142: .'</p>
  143: <form action="/adm/errorhandler" method="post">
  144: <h3>'.&mt('Please describe what you did just before this screen came up').'</h3>
  145: <textarea name="prioraction" cols="50" rows="5">
  146: </textarea>
  147: <h3>'.&mt('Is this problem reproducible?').'</h3>
  148: <label>
  149: <input type="checkbox" name="reproducible" value="yes" /> '.&mt('Yes!').'
  150: </label>
  151: <h3>'.&mt('Do you have any guesses why this might have happened?').'</h3>
  152: <textarea name="guesses" cols="50" rows="5">
  153: </textarea>
  154: <input type="hidden" name="version" value="'.$version.'" />
  155: <input type="hidden" name="environment" value="'.$env.'" />
  156: <input type="hidden" name="syllabus" value="'.$syllabus.'" />
  157: <input type="hidden" name="sendinfo" value="1" />
  158: <p>
  159: <input type="submit" title="'.&mt('Send Information').'" value="'.&mt('Send').'" />
  160: </p>
  161: </form>
  162: <h1>'.&mt('Thank you for your help!').'</h1>
  163: <div><font size="-1">
  164: '.&mt('Internal info:').
  165: '<pre>'.
  166: $syllabus.'
  167: </pre>
  168: </font></div>
  169: ');
  170: # -------------------------- Better terminate this in case something was sticky
  171: 
  172:         $r->child_terminate();
  173:     }
  174:     $r->print(&Apache::loncommon::end_page());
  175:     return OK;
  176: }
  177: 
  178: 1;
  179: __END__
  180: 
  181: 
  182: =pod
  183: 
  184: =head1 NAME
  185: 
  186: Apache::lonerrorhandler.pm
  187: 
  188: =head1 SYNOPSIS
  189: 
  190: Handles errors.
  191: 
  192: This is part of the LearningOnline Network with CAPA project
  193: described at http://www.lon-capa.org.
  194: 
  195: =head1 OVERVIEW
  196: 
  197: None
  198: 
  199: =cut

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