Annotation of loncom/xml/lonxml.pm, revision 1.61

1.2       sakharuk    1: # The LearningOnline Network with CAPA
1.3       sakharuk    2: # XML Parser Module 
1.2       sakharuk    3: #
1.3       sakharuk    4: # last modified 06/26/00 by Alexander Sakharuk
1.33      www         5: # 11/6 Gerd Kortemeyer
1.45      www         6: # 6/1/1 Gerd Kortemeyer
1.56      albertel    7: # 2/21,3/13 Guy
1.2       sakharuk    8: 
1.4       albertel    9: package Apache::lonxml; 
1.33      www        10: use vars 
1.60      albertel   11: qw(@pwd @outputstack $redirection $import @extlinks $metamode);
1.1       sakharuk   12: use strict;
                     13: use HTML::TokeParser;
1.3       sakharuk   14: use Safe;
1.40      albertel   15: use Safe::Hole;
1.13      albertel   16: use Opcode;
1.46      www        17: use Apache::Constants qw(:common);
1.7       albertel   18: 
                     19: sub register {
                     20:   my $space;
                     21:   my @taglist;
                     22:   my $temptag;
                     23:   ($space,@taglist) = @_;
                     24:   foreach $temptag (@taglist) {
                     25:     $Apache::lonxml::alltags{$temptag}=$space;
                     26:   }
                     27: }
1.48      albertel   28: 
                     29: sub printalltags {
                     30:   my $temp;
                     31:   foreach $temp (sort keys %Apache::lonxml::alltags) {
                     32:     &Apache::lonxml::debug("$temp -- $Apache::lonxml::alltags{$temp}");
                     33:   }
                     34: }
1.4       albertel   35: use Apache::style;
1.3       sakharuk   36: use Apache::lontexconvert;
1.7       albertel   37: use Apache::run;
1.4       albertel   38: use Apache::londefdef;
1.7       albertel   39: use Apache::scripttag;
1.59      albertel   40: use Apache::edit;
1.3       sakharuk   41: #==================================================   Main subroutine: xmlparse  
1.33      www        42: @pwd=();
1.55      albertel   43: @outputstack = ();
                     44: $redirection = 0;
                     45: $import = 1;
1.33      www        46: @extlinks=();
1.59      albertel   47: $metamode = 0;
1.31      sakharuk   48: 
1.3       sakharuk   49: sub xmlparse {
                     50: 
1.18      albertel   51:  my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
1.41      albertel   52:  if ($target eq 'meta') {
1.59      albertel   53:    # meta mode is a bit weird only some output is to be turned off
1.60      albertel   54:    #<output> tag turns metamode off (defined in londefdef.pm)
1.59      albertel   55:    $Apache::lonxml::redirection = 0;
                     56:    $Apache::lonxml::metamode = 1;
1.55      albertel   57:    $Apache::lonxml::import = 0;
1.47      albertel   58:  } elsif ($target eq 'grade') {
1.55      albertel   59:    &startredirection;
1.59      albertel   60:    $Apache::lonxml::metamode = 0;
1.55      albertel   61:    $Apache::lonxml::import = 1;
1.44      albertel   62:  } else {
1.59      albertel   63:    $Apache::lonxml::metamode = 0;
1.55      albertel   64:    $Apache::lonxml::redirection = 0;
                     65:    $Apache::lonxml::import = 1;
1.32      sakharuk   66:  }
1.48      albertel   67:  #&printalltags();
1.16      albertel   68:  my @pars = ();
1.23      albertel   69:  @Apache::lonxml::pwd=();
                     70:  my $pwd=$ENV{'request.filename'};
                     71:  $pwd =~ s:/[^/]*$::;
                     72:  &newparser(\@pars,\$content_file_string,$pwd);
1.3       sakharuk   73:  my $currentstring = '';
                     74:  my $finaloutput = ''; 
                     75:  my $newarg = '';
1.16      albertel   76:  my $result;
1.24      sakharuk   77: 
1.3       sakharuk   78:  my $safeeval = new Safe;
1.40      albertel   79:  my $safehole = new Safe::Hole;
1.6       albertel   80:  $safeeval->permit("entereval");
1.13      albertel   81:  $safeeval->permit(":base_math");
1.19      albertel   82:  $safeeval->deny(":base_io");
1.40      albertel   83:  $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
1.19      albertel   84: #need to inspect this class of ops
                     85: # $safeeval->deny(":base_orig");
1.21      albertel   86:  $safeinit .= ';$external::target='.$target.';';
1.26      albertel   87:  $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
1.21      albertel   88:  &Apache::run::run($safeinit,$safeeval);
1.3       sakharuk   89: #-------------------- Redefinition of the target in the case of compound target
                     90: 
                     91:  ($target, my @tenta) = split('&&',$target);
                     92: 
                     93:  my @stack = (); 
                     94:  my @parstack = ();
1.17      albertel   95:  &initdepth;
1.3       sakharuk   96:  my $token;
1.16      albertel   97:  while ( $#pars > -1 ) {
                     98:    while ($token = $pars[$#pars]->get_token) {
1.57      albertel   99:      if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
1.61    ! albertel  100:        if ($metamode<1) { $result=$token->[1]; }
1.57      albertel  101:      } elsif ($token->[0] eq 'PI') {
1.61    ! albertel  102:        if ($metamode<1) { $result=$token->[2]; }
1.16      albertel  103:      } elsif ($token->[0] eq 'S') {
                    104:        # add tag to stack 	    
                    105:        push (@stack,$token->[1]);
                    106:        # add parameters list to another stack
                    107:        push (@parstack,&parstring($token));
1.19      albertel  108:        &increasedepth($token);       
1.16      albertel  109:        if (exists $style_for_target{$token->[1]}) {
1.61    ! albertel  110: 	 if ($Apache::lonxml::redirection) {
1.55      albertel  111: 	   $Apache::lonxml::outputstack['-1'] .=  
                    112: 	     &recurse($style_for_target{$token->[1]},$target,$safeeval,
                    113: 		      \%style_for_target,@parstack);
1.41      albertel  114: 	 } else {
1.55      albertel  115: 	   $finaloutput .= &recurse($style_for_target{$token->[1]},$target,
                    116: 				    $safeeval,\%style_for_target,@parstack);
1.41      albertel  117: 	 }
1.16      albertel  118:        } else {
1.17      albertel  119: 	 $result = &callsub("start_$token->[1]", $target, $token,\@parstack,
1.41      albertel  120: 			    \@pars, $safeeval, \%style_for_target);
1.16      albertel  121:        }              
                    122:      } elsif ($token->[0] eq 'E')  {
                    123:        #clear out any tags that didn't end
1.55      albertel  124:        while ($token->[1] ne $stack[$#stack] && ($#stack > -1)) {
                    125: 	 &Apache::lonxml::warning("Unbalanced tags in resource $stack['-1']");
1.43      albertel  126: 	 pop @stack;pop @parstack;&decreasedepth($token);
                    127:        }
1.16      albertel  128:        
                    129:        if (exists $style_for_target{'/'."$token->[1]"}) {
1.61    ! albertel  130: 	 if ($Apache::lonxml::redirection) {
1.55      albertel  131: 	   $Apache::lonxml::outputstack['-1'] .=  
                    132: 	     &recurse($style_for_target{'/'."$token->[1]"},
                    133: 		      $target,$safeeval,\%style_for_target,@parstack);
                    134: 	 } else {
                    135: 	   $finaloutput .= &recurse($style_for_target{'/'."$token->[1]"},
                    136: 				    $target,$safeeval,\%style_for_target,
                    137: 				    @parstack);
                    138: 	 }
1.59      albertel  139: 
1.16      albertel  140:        } else {
1.17      albertel  141: 	 $result = &callsub("end_$token->[1]", $target, $token, \@parstack,
1.55      albertel  142: 			    \@pars,$safeeval, \%style_for_target);
1.13      albertel  143:        }
1.57      albertel  144:      } else {
                    145:        &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
1.16      albertel  146:      }
1.55      albertel  147:      #evaluate variable refs in result
1.25      sakharuk  148:      if ($result ne "") {
1.24      sakharuk  149:        if ( $#parstack > -1 ) {
1.55      albertel  150: 	 if ($Apache::lonxml::redirection) {
                    151: 	   $Apache::lonxml::outputstack['-1'] .= 
                    152: 	     &Apache::run::evaluate($result,$safeeval,$parstack[$#parstack]);
                    153: 	 } else {
                    154: 	   $finaloutput .= &Apache::run::evaluate($result,$safeeval,
                    155: 						  $parstack[$#parstack]);
                    156: 	 }
1.16      albertel  157:        } else {
                    158: 	 $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
1.13      albertel  159:        }
1.16      albertel  160:        $result = '';
1.55      albertel  161:      } 
                    162:      if ($token->[0] eq 'E') { 
                    163:        pop @stack;pop @parstack;&decreasedepth($token);
1.2       sakharuk  164:      }
1.5       albertel  165:    }
1.16      albertel  166:    pop @pars;
1.23      albertel  167:    pop @Apache::lonxml::pwd;
1.3       sakharuk  168:  }
1.24      sakharuk  169: 
1.59      albertel  170: # if ($target eq 'meta') {
                    171: #   $finaloutput.=&endredirection;
                    172: # }
1.3       sakharuk  173:  return $finaloutput;
1.15      albertel  174: }
                    175: 
                    176: sub recurse {
                    177:   
                    178:   my @innerstack = (); 
                    179:   my @innerparstack = ();
                    180:   my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
1.16      albertel  181:   my @pat = ();
1.23      albertel  182:   &newparser(\@pat,\$newarg);
1.15      albertel  183:   my $tokenpat;
                    184:   my $partstring = '';
                    185:   my $output='';
1.16      albertel  186:   my $decls='';
                    187:   while ( $#pat > -1 ) {
                    188:     while  ($tokenpat = $pat[$#pat]->get_token) {
1.57      albertel  189:       if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
1.61    ! albertel  190: 	if ($metamode<1) { $partstring=$tokenpat->[1]; }
1.57      albertel  191:       } elsif ($tokenpat->[0] eq 'PI') {
1.61    ! albertel  192: 	if ($metamode<1) { $partstring=$tokenpat->[2]; }
1.16      albertel  193:       } elsif ($tokenpat->[0] eq 'S') {
                    194: 	push (@innerstack,$tokenpat->[1]);
                    195: 	push (@innerparstack,&parstring($tokenpat));
1.19      albertel  196: 	&increasedepth($tokenpat);
1.16      albertel  197: 	$partstring = &callsub("start_$tokenpat->[1]", 
                    198: 			       $target, $tokenpat, \@innerparstack,
                    199: 			       \@pat, $safeeval, $style_for_target);
                    200:       } elsif ($tokenpat->[0] eq 'E') {
                    201: 	#clear out any tags that didn't end
                    202: 	while ($tokenpat->[1] ne $innerstack[$#innerstack] 
1.43      albertel  203: 	       && ($#innerstack > -1)) {
1.49      albertel  204: 	  &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
1.43      albertel  205: 	  pop @innerstack;pop @innerparstack;&decreasedepth($tokenpat);
                    206: 	}
1.16      albertel  207: 	$partstring = &callsub("end_$tokenpat->[1]",
                    208: 			       $target, $tokenpat, \@innerparstack,
                    209: 			       \@pat, $safeeval, $style_for_target);
1.57      albertel  210:       } else {
                    211: 	&Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
1.16      albertel  212:       }
                    213:       #pass both the variable to the style tag, and the tag we 
                    214:       #are processing inside the <definedtag>
                    215:       if ( $partstring ne "" ) {
                    216: 	if ( $#parstack > -1 ) { 
                    217: 	  if ( $#innerparstack > -1 ) { 
                    218: 	    $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
                    219: 	  } else {
                    220: 	    $decls= $parstack[$#parstack];
                    221: 	  }
                    222: 	} else {
                    223: 	  if ( $#innerparstack > -1 ) { 
                    224: 	    $decls=$innerparstack[$#innerparstack];
                    225: 	  } else {
                    226: 	    $decls='';
                    227: 	  }
                    228: 	}
                    229: 	$output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
                    230: 	$partstring = '';
                    231:       }
1.17      albertel  232:       if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
1.19      albertel  233: 				 &decreasedepth($tokenpat);}
1.15      albertel  234:     }
1.16      albertel  235:     pop @pat;
1.23      albertel  236:     pop @Apache::lonxml::pwd;
1.15      albertel  237:   }
                    238:   return $output;
1.7       albertel  239: }
                    240: 
                    241: sub callsub {
1.14      albertel  242:   my ($sub,$target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.7       albertel  243:   my $currentstring='';
                    244:   {
1.59      albertel  245:     my $sub1;
1.7       albertel  246:     no strict 'refs';
1.59      albertel  247:     if ($target eq 'edit' && $token->[0] eq 'S') {
                    248:       $currentstring = &Apache::edit::tag_start($target,$token,$parstack,$parser,
                    249: 						$safeeval,$style);
                    250:     }
1.7       albertel  251:     if (my $space=$Apache::lonxml::alltags{$token->[1]}) {
1.54      albertel  252:       #&Apache::lonxml::debug("Calling sub $sub in $space<br />\n");
1.24      sakharuk  253:       $sub1="$space\:\:$sub";
1.17      albertel  254:       $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
1.59      albertel  255:       $currentstring .= &$sub1($target,$token,$parstack,$parser,
1.16      albertel  256: 			     $safeeval,$style);
1.7       albertel  257:     } else {
1.54      albertel  258:       #&Apache::lonxml::debug("NOT Calling sub $sub in $space<br />\n");
1.61    ! albertel  259:       if (defined($token->[4]) && ($metamode < '1')) {
1.59      albertel  260: 	$currentstring .= $token->[4];
1.7       albertel  261:       } else {
1.59      albertel  262: 	$currentstring .= $token->[2];
1.7       albertel  263:       }
1.59      albertel  264:     }
                    265:     if ($target eq 'edit' && $token->[0] eq 'E') {
1.61    ! albertel  266:       $currentstring .= &Apache::edit::tag_end($target,$token,$parstack,$parser,
1.59      albertel  267: 						$safeeval,$style);
1.7       albertel  268:     }
                    269:     use strict 'refs';
                    270:   }
                    271:   return $currentstring;
1.17      albertel  272: }
                    273: 
1.55      albertel  274: sub startredirection {
                    275:   $Apache::lonxml::redirection++;
                    276:   push (@Apache::lonxml::outputstack, '');
                    277: }
                    278: 
                    279: sub endredirection {
                    280:   if (!$Apache::lonxml::redirection) {
                    281:     &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuggin information:".join ":",caller);
                    282:     return '';
                    283:   }
                    284:   $Apache::lonxml::redirection--;
                    285:   pop @Apache::lonxml::outputstack;
                    286: }
                    287: 
1.17      albertel  288: sub initdepth {
                    289:   @Apache::lonxml::depthcounter=();
                    290:   $Apache::lonxml::depth=-1;
                    291:   $Apache::lonxml::olddepth=-1;
                    292: }
                    293: 
                    294: sub increasedepth {
1.19      albertel  295:   my ($token) = @_;
1.17      albertel  296:   $Apache::lonxml::depth++;
                    297:   $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
                    298:   if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
                    299:     $Apache::lonxml::olddepth=$Apache::lonxml::depth;
                    300:   }
1.42      albertel  301:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
                    302:   &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
1.54      albertel  303: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17      albertel  304: }
                    305: 
                    306: sub decreasedepth {
1.19      albertel  307:   my ($token) = @_;
1.17      albertel  308:   $Apache::lonxml::depth--;
1.36      albertel  309:   if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
                    310:     $#Apache::lonxml::depthcounter--;
                    311:     $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
                    312:   }
1.43      albertel  313:   if (  $Apache::lonxml::depth < -1) {
1.49      albertel  314:     &Apache::lonxml::warning("Unbalanced tags in resource");   
1.43      albertel  315:     $Apache::lonxml::depth='-1';
                    316:   }
1.42      albertel  317:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
                    318:   &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
1.54      albertel  319: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1       sakharuk  320: }
1.19      albertel  321: 
                    322: sub get_all_text {
                    323: 
                    324:  my($tag,$pars)= @_;
                    325:  my $depth=0;
                    326:  my $token;
                    327:  my $result='';
1.57      albertel  328:  if ( $tag =~ m:^/: ) { 
                    329:    my $tag=substr($tag,1); 
                    330: #   &Apache::lonxml::debug("have:$tag:");
                    331:    while (($depth >=0) && ($token = $pars->get_token)) {
                    332: #     &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
                    333:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
                    334:        $result.=$token->[1];
                    335:      } elsif ($token->[0] eq 'PI') {
                    336:        $result.=$token->[2];
                    337:      } elsif ($token->[0] eq 'S') {
                    338:        if ($token->[1] eq $tag) { $depth++; }
                    339:        $result.=$token->[4];
                    340:      } elsif ($token->[0] eq 'E')  {
                    341:        if ( $token->[1] eq $tag) { $depth--; }
                    342:        #skip sending back the last end tag
                    343:        if ($depth > -1) { $result.=$token->[2]; } else {
                    344: 	 $pars->unget_token($token);
                    345:        }
                    346:      }
                    347:    }
                    348:  } else {
                    349:    while ($token = $pars->get_token) {
                    350: #     &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
                    351:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
                    352:        $result.=$token->[1];
                    353:      } elsif ($token->[0] eq 'PI') {
                    354:        $result.=$token->[2];
                    355:      } elsif ($token->[0] eq 'S') {
                    356:        if ( $token->[1] eq $tag) { 
                    357: 	 $pars->unget_token($token); last;
                    358:        } else {
                    359: 	 $result.=$token->[4];
                    360:        }
                    361:      } elsif ($token->[0] eq 'E')  {
                    362:        $result.=$token->[2];
1.36      albertel  363:      }
1.19      albertel  364:    }
                    365:  }
1.49      albertel  366: # &Apache::lonxml::debug("Exit:$result:");
1.19      albertel  367:  return $result
                    368: }
                    369: 
1.23      albertel  370: sub newparser {
                    371:   my ($parser,$contentref,$dir) = @_;
                    372:   push (@$parser,HTML::TokeParser->new($contentref));
1.56      albertel  373:   $$parser['-1']->xml_mode('1');
1.23      albertel  374:   if ( $dir eq '' ) {
                    375:     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
                    376:   } else {
                    377:     push (@Apache::lonxml::pwd, $dir);
                    378:   } 
                    379: #  &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
                    380: #  &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
                    381: }
1.1       sakharuk  382: 
1.8       albertel  383: sub parstring {
                    384:   my ($token) = @_;
                    385:   my $temp='';
1.20      albertel  386:   map {
1.35      www       387:     unless ($_=~/\W/) {
1.42      albertel  388:       my $val=$token->[2]->{$_};
1.53      albertel  389:       $val =~ s/([\%\@\\])/\\$1/g;
1.51      albertel  390:       #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.42      albertel  391:       $temp .= "my \$$_=\"$val\";"
1.20      albertel  392:     }
                    393:   } @{$token->[3]};
1.8       albertel  394:   return $temp;
                    395: }
1.22      albertel  396: 
1.34      www       397: sub writeallows {
                    398:     my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
                    399:     my $thisdir=$thisurl;
                    400:     $thisdir=~s/\/[^\/]+$//;
                    401:     my %httpref=();
                    402:     map {
                    403:        $httpref{'httpref.'.
                    404:  	        &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;              } @extlinks;
                    405:     &Apache::lonnet::appenv(%httpref);
                    406: }
                    407: 
1.24      sakharuk  408: sub handler {
                    409:   my $request=shift;
1.44      albertel  410:   
1.31      sakharuk  411:   my $target='web';
1.48      albertel  412:   $Apache::lonxml::debug=0;
1.25      sakharuk  413:   if ($ENV{'browser.mathml'}) {
1.27      albertel  414:     $request->content_type('text/xml');
                    415:   } else {
                    416:     $request->content_type('text/html');
1.25      sakharuk  417:   }
1.29      sakharuk  418: 
                    419: #  $request->print(<<ENDHEADER);
                    420: #<html>
                    421: #<head>
                    422: #<title>Just test</title>
                    423: #</head>
                    424: #<body bgcolor="#FFFFFF">
                    425: #ENDHEADER
                    426: #  &Apache::lonhomework::send_header($request);
1.27      albertel  427:   $request->send_http_header;
                    428: 
1.45      www       429:   return OK if $request->header_only;
1.27      albertel  430: 
                    431:   $request->print(&Apache::lontexconvert::header());
                    432: 
1.28      albertel  433:   $request->print('<body bgcolor="#FFFFFF">'."\n");
1.27      albertel  434: 
1.50      albertel  435:   my $file=&Apache::lonnet::filelocation("",$request->uri);
1.24      sakharuk  436:   my %mystyle;
1.50      albertel  437:   my $result = ''; 
                    438:   my $filecontents=&Apache::lonnet::getfile($file);
                    439:   if ($filecontents == -1) {
                    440:     &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
                    441:     $filecontents='';
                    442:   } else {
                    443:     $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
                    444:   }
1.24      sakharuk  445:   $request->print($result);
1.29      sakharuk  446: 
1.50      albertel  447: 
1.28      albertel  448:   $request->print('</body>');
                    449:   $request->print(&Apache::lontexconvert::footer());
1.34      www       450:   writeallows($request->uri);
1.45      www       451:   return OK;
1.24      sakharuk  452: }
                    453:  
1.22      albertel  454: $Apache::lonxml::debug=0;
                    455: sub debug {
                    456:   if ($Apache::lonxml::debug eq 1) {
1.54      albertel  457:     print "DEBUG:".$_[0]."<br />\n";
1.22      albertel  458:   }
                    459: }
1.49      albertel  460: 
1.22      albertel  461: sub error {
1.52      albertel  462:   if ($Apache::lonxml::debug eq 1) {
1.55      albertel  463:     print "<b>ERROR:</b>".$_[0]."<br />\n";
1.52      albertel  464:   } else {
                    465:     print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
                    466:     #notify author
                    467:     &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
                    468:     #notify course
                    469:     if ( $ENV{'request.course.id'} ) {
                    470:       my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
                    471:       foreach my $user (split /\,/, $users) {
                    472: 	($user,my $domain) = split /:/, $user;
1.54      albertel  473: 	&Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
1.52      albertel  474:       }
                    475:     }
                    476:     
                    477:     #FIXME probably shouldn't have me get everything forever.
1.54      albertel  478:     &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
                    479:     #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);   
1.52      albertel  480:   }
1.22      albertel  481: }
1.49      albertel  482: 
1.22      albertel  483: sub warning {
                    484:   if ($Apache::lonxml::debug eq 1) {
1.55      albertel  485:     print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
1.22      albertel  486:   }
                    487: }
                    488: 
1.1       sakharuk  489: 1;
                    490: __END__

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