File:  [LON-CAPA] / loncom / interface / lontest.pm
Revision 1.11: download - view: text, annotated - select for diffs
Tue Apr 1 20:12:02 2003 UTC (21 years, 1 month ago) by www
Branches: MAIN
CVS tags: version_1_2_X, version_1_2_1, version_1_2_0, version_1_1_X, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, version_1_1_3, version_1_1_2, version_1_1_1, version_1_1_0, version_1_0_99_3, version_1_0_99_2, version_1_0_99_1, version_1_0_99, version_1_0_3, version_1_0_2, version_1_0_1, version_1_0_0, version_0_99_5, version_0_99_4, version_0_99_3, version_0_99_2, version_0_99_1, version_0_99_0, conference_2003, HEAD
List the user's condition state.

    1: # The LearningOnline Network with CAPA
    2: # A debugging harness.
    3: #
    4: # $Id: lontest.pm,v 1.11 2003/04/01 20:12:02 www 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: package Apache::lontest;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http);
   34: use GDBM_File;
   35: use Apache::loncommon;
   36: 
   37: # section takes one env var name as input, and returns
   38: # what section the given env var is in, which is the part
   39: # of the env var before the first period.
   40: # Returns the section, or blank string for 'no section',
   41: # which is normal for the standard ENV vars like REQUEST_URI.
   42: sub section
   43: {
   44:     my ($name) = @_;
   45:     return $1 if $name =~ m/\A([^.]*)\./;
   46:     return '';
   47: }
   48: 
   49:  sub handler {
   50:      my $r = shift;
   51:      $r->content_type('text/html');
   52:      $r->send_http_header;
   53:      return OK if $r->header_only;
   54: 
   55:      my $bodytag=&Apache::loncommon::bodytag("List Environment","admin");
   56:      $r->print('<html>'.$bodytag);
   57:      
   58:      my $envkey;
   59:  
   60:      $r->print("<hr><h1>Debugging</h1><hr>\n");
   61:      $r->print("<font face='Courier'>");
   62:      
   63:      my $i=0;
   64:      my $interval = 20; # change this to change how many keys/table
   65:      my $prevSection = ''; # keeps track of the section we're in.
   66:      foreach $envkey (sort keys %ENV) {
   67: 	 if (not ($i % $interval))
   68:          {
   69: 	     $r->print('</table>') unless $i eq 0;
   70: 	     $r->print('<table border="0">')
   71:          }
   72: 	 my $sec = section($envkey);
   73: 
   74: 	 if ($prevSection ne $sec) # new section, print header
   75: 	 {
   76: 	     $r->print('<tr><td colspan="2">');
   77: 	     $r->print("<br><br><h2 style='color: #008800'><u>$sec</u></h2>");
   78: 	     $r->print('</td></tr>');
   79: 	     $prevSection = $sec;
   80: 	 }
   81: 
   82: 	 my $envVal = $ENV{$envkey};
   83: 	 $envVal =~ s/(.{50})/$1\<wbr\>/g;
   84: 	 $envkey =~ s/(.{30})/$1\<wbr\>/g;
   85: 	 
   86: 	 $r->print("<tr><td valign='top'><b>$envkey</b></td>");
   87:          $r->print("<td valign='top'>$envVal</td></tr>\n");
   88: 	 $i++;
   89:      }
   90: 
   91:      $r->print('</table></font><h1>Total Number of Elements: '.$i.'</h1>');
   92: 
   93: # ------------------------------------------------ If in a course, print hashes
   94:    if ($ENV{'request.course.id'}) {
   95: 
   96:      my %parmhash;
   97:      my %symbhash;
   98:      my %hash;
   99: 
  100:      my $fn=$ENV{'request.course.fn'};
  101: 
  102:          if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) {
  103:              $r->print('<h2>Big Hash</h2>');
  104:              foreach (sort keys %hash) {
  105: 	         $r->print("\n<br>".$_.': '.$hash{$_});
  106:              }
  107:              untie %hash;
  108:          } else {
  109:              $r->print('<h2>Count not tie big hash</h2>');
  110:          }
  111:          if (tie(%parmhash,'GDBM_File',
  112: 		     $ENV{'request.course.fn'}.'_parms.db',
  113: 		     &GDBM_READER(),0640)) {
  114:              $r->print('<h2>Parm Hash</h2>');
  115:              foreach (sort keys %parmhash) {
  116: 	        $r->print("\n<br>".$_.': '.$parmhash{$_});
  117:              }
  118:              untie %parmhash;
  119:          } else {
  120:             $r->print('<h2>Could not tie parmhash</h2>');
  121: 	 }
  122:          if (tie(%symbhash,'GDBM_File',"$fn\_symb.db",&GDBM_READER(),0640)) {
  123:             $r->print('<h2>Symb Hash</h2>');
  124:             foreach (sort keys %symbhash) {
  125: 	       $r->print("\n<br>".$_.': '.$symbhash{$_});
  126:             }
  127:             untie %symbhash;
  128: 	 } else {
  129:             $r->print('<h2>Could not tie symbhash</h2>');
  130: 	 }
  131:          if (-e $fn.'.state') {
  132: 	     $r->print('<h2>State</h2>');
  133: 	     my @conditions=();
  134: 	     {
  135: 		 my $fh=Apache::File->new($fn.'.state');
  136: 		 @conditions=<$fh>;
  137: 	     }
  138: 	     foreach (@conditions) {
  139:                  $r->print('<tt>'.$_.'</tt><br />');
  140: 	     }
  141:        }
  142:  }
  143: 
  144:  
  145: # ------------------------------------------------------------------- End Debug
  146:      $r->print('</body></html>');        
  147:  }
  148: 
  149: 
  150: 1;
  151: __END__
  152: 
  153: 
  154: 
  155: 

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