File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.79: download - view: text, annotated - select for diffs
Wed Jan 30 17:37:21 2002 UTC (22 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- checks if <problem> is embedded inside a webpage
- verifies only 1 problem per file

    1: # The LearningOnline Network with CAPA 
    2: # definition of tags that give a structure to a document
    3: #
    4: # $Id: structuretags.pm,v 1.79 2002/01/30 17:37:21 albertel 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: # 2/19 Guy
   29: # 6/26/2001 fixed extra web display at end of <web></web> tags
   30: # 8/17,8/18,8/20 Gerd Kortemeyer
   31: 
   32: package Apache::structuretags; 
   33: 
   34: use strict;
   35: use Apache::lonnet;
   36: 
   37: BEGIN {
   38:   &Apache::lonxml::register('Apache::structuretags',('block','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','startouttext','endouttext'));
   39: #  &Apache::lonxml::register_insert('problem','',('part','postanswerdate','preduedate'))
   40: }
   41: 
   42: sub start_web {
   43:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   44:   my $bodytext=&Apache::lonxml::get_all_text("/web",$$parser[$#$parser]);
   45:   if ($target eq 'web') {
   46:     return $bodytext;
   47:   } 
   48:   return '';
   49: }
   50: 
   51: sub end_web {
   52:     return '';
   53: }
   54: 
   55: sub start_tex {
   56:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   57:   my $bodytext=&Apache::lonxml::get_all_text("/tex",$$parser[$#$parser]);
   58:   if ($target eq 'tex') {
   59:     return $bodytext
   60:   }
   61:   return '';
   62: }
   63: 
   64: sub end_tex {
   65:     return '';
   66: }
   67: 
   68: sub page_start {
   69:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   70:   my %found;
   71:   foreach my $taginside ($tagstack) {
   72:     foreach my $taglookedfor ('html','body','form') {
   73:       if ($taginside =~ /^$taglookedfor$/i) { $found{$taglookedfor} = 1; }
   74:     }
   75:   }
   76: 
   77:   my $result;
   78:   my $head_tag_start;
   79:   if (!defined($found{'html'})) {
   80:     $result=&Apache::londefdef::start_html($target,$token,$tagstack,$parstack,
   81: 					   $parser,$safeeval);
   82:     $head_tag_start='<head>'.&Apache::lonxml::registerurl();
   83:   }
   84:   my $body_tag_start;
   85:   if (!defined($found{'body'})) {
   86:     my $body_tag_start='<body onLoad="'.&Apache::lonxml::loadevents().'" '.
   87:       'onUnload="'.&Apache::lonxml::unloadevents().'" ';
   88:     my $background=&Apache::lonxml::get_param('background',$parstack,$safeeval);
   89:     if ($background) {
   90:       $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
   91: 	$background;
   92:       $body_tag_start.='background="'.$background.'" ';
   93:     } else {
   94:       my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,$safeeval);
   95:       if ($bgcolor) {
   96: 	$body_tag_start.='bgcolor="'.$bgcolor.'" ';
   97:       } else {
   98: 	$body_tag_start.='bgcolor="#ffffff"';
   99:       }
  100:     }
  101:     $body_tag_start.='>';
  102:   }
  103:   return ($result,$head_tag_start,$body_tag_start);
  104: }
  105: 
  106: sub initialize_storage {
  107:   %Apache::lonhomework::results=();
  108:   my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
  109:   if ($ENV{'request.state'} eq 'construct') {
  110:     %Apache::lonhomework::history=
  111:       &Apache::lonnet::tmprestore($ENV{'request.uri'},'',$domain,$name);
  112:     my ($temp)=keys %Apache::lonhomework::history ;
  113:     &Apache::lonxml::debug("Return message of $temp");
  114:   } else {
  115:     %Apache::lonhomework::history=
  116:       &Apache::lonnet::restore($symb,$courseid,$domain,$name);
  117:   }
  118:   #ignore error conditions
  119:   my ($temp)=keys %Apache::lonhomework::history ;
  120:   if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
  121: }
  122: 
  123: # -------------------------------------------------------------finalize_storage
  124: # Stores away the result has to a student's environment
  125: # checks form.grade_ for specific values, other wises stores
  126: # to the running users environment
  127: sub finalize_storage {
  128:   my $result;
  129:   my ($temp) = keys %Apache::lonhomework::results;
  130:   if ( $temp ne '' ) {
  131:     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
  132:     if ($ENV{'request.state'} eq 'construct') {
  133:       $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,
  134: 				      $ENV{'request.uri'},'',$domain,$name);
  135:       &Apache::lonxml::debug('Construct Store return message:'.$result);
  136:     } else {
  137:       $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
  138: 				      $symb,$courseid,$domain,$name);
  139:       &Apache::lonxml::debug('Store return message:'.$result);
  140:     }
  141:   }
  142:   return $result;
  143: }
  144: 
  145: sub checkout_msg {
  146: return (<<ENDCHECKOUT);
  147: <h2>The resource needs to be checked out</h2>
  148: As a resource gets checked out, a unique timestamped ID is given to it, and a
  149: permanent record is left in the system.<p />
  150: <font color=red>
  151: Checking out resources is subject to course policies, and may exclude future
  152: credit even if done erroneously.<p />
  153: </font>  
  154: <form method=post>
  155: <input type=button name="doescheckout" 
  156: value="Check out Exam for Viewing" 
  157: onClick="if (confirm('Check out Exam?')) { this.form.submit(); }" />
  158: </form>
  159: ENDCHECKOUT
  160: }
  161: 
  162: sub start_problem {
  163:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  164: 
  165:   if ( $Apache::inputtags::part ne '' ) {
  166:     &Apache::lonxml::error('Only one problem allowed in a .problem file');
  167:     my $bodytext=&Apache::lonxml::get_all_text("/problem",$$parser[-1]);
  168:     return '';
  169:   }
  170: #intialize globals
  171:   $Apache::inputtags::part='0';
  172:   @Apache::inputtags::responselist = ();
  173:   @Apache::inputtags::previous=();
  174:   &initialize_storage();
  175:   if ($target eq 'web') {
  176:     &Apache::lonhomework::showhash(%Apache::lonhomework::history);
  177:   }
  178:   $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
  179:   &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
  180:   if ($Apache::lonhomework::type eq '') {
  181:     my $uri=$ENV{'request.uri'};
  182:     if ($uri=~/\.(\w+)$/) {
  183:       $Apache::lonhomework::type=$1;
  184:       &Apache::lonxml::debug("Using type of $1");
  185:     } else {
  186:       $Apache::lonhomework::type='problem';
  187:       &Apache::lonxml::debug("Using default type, problem, :$uri:");
  188:     }
  189:   }
  190: 
  191:   #added vars to the scripting enviroment
  192:   my $expression='$external::part='.$Apache::inputtags::part.';';
  193:   &Apache::run::run($expression,$safeeval);
  194:   my $status;
  195:   my $accessmsg;
  196: 
  197:   #should get back a <html> or the neccesary stuff to start XML/MathML
  198:   my ($result,$head_tag_start,$body_tag_start)=
  199:     &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
  200: 
  201: 
  202:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  203:     #handle exam checkout
  204:     if ($Apache::lonhomework::type eq 'exam') {
  205:       my $token=$Apache::lonhomework::history{"resource.0.outtoken"};
  206:       if (($ENV{'form.doescheckout'}) && (!$token)) {
  207: 	$token=&Apache::lonxml::maketoken();
  208: 	$Apache::lonhomework::history{"resource.0.outtoken"}=$token;
  209:       }
  210:       $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token);
  211:     }
  212: 
  213:     #handle rand seed in construction space
  214:     my $rndseed;
  215:     if ($ENV{'request.state'} eq "construct") {
  216:       $rndseed=$ENV{'form.rndseed'};
  217:       if (!$rndseed) {
  218: 	$rndseed=time;
  219: 	$ENV{'form.rndseed'}=$rndseed;
  220:       }
  221:       &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval);
  222:     }
  223:     ($status,$accessmsg) = &Apache::lonhomework::check_access('0');
  224:     push (@Apache::inputtags::status,$status);
  225:     my $expression='$external::datestatus="'.$status.'";';
  226:     $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
  227:     &Apache::run::run($expression,$safeeval);
  228:     if (( $status eq 'CLOSED' ) ||
  229:         ( $status eq 'UNCHECKEDOUT') ||
  230:         ( $status eq 'BANNED')) {
  231:       my $bodytext=&Apache::lonxml::get_all_text("/problem",$$parser[$#$parser]);
  232:       if ( $target eq "web" ) {
  233: 	$result.= $head_tag_start.'</head>';
  234:         my $msg=$body_tag_start.
  235: 	    '<h1>Not open to be viewed</h1>';
  236:         if ($status eq 'CLOSED') {
  237: 	    $msg.='The problem '.$accessmsg;
  238: 	} elsif ($status eq 'UNCHECKEDOUT') {
  239:             $msg.=&checkout_msg;
  240:         }
  241: 	$result.=$msg.'<br />';
  242:       }
  243:     } elsif ($target eq 'web') {
  244:       my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
  245:       if ($name eq '') { 
  246: 	$name=&Apache::lonnet::EXT('resource.title');
  247: 	if ($name eq 'con_lost') { $name = ''; }
  248:       }
  249:       $Apache::lonhomework::name=$name;
  250:       if ($status eq 'CAN_ANSWER') {
  251: 	# create a page header and exit
  252: 	$result.="$head_tag_start<title>$name</title></head>\n
  253:               $body_tag_start\n
  254:               <form name=\"lonhomework\" method=\"POST\" action=\"".$ENV{'request.uri'}."\">".
  255: 		'<input type="hidden" name="submitted" value="yes" />';
  256: 	if ($ENV{'request.state'} eq "construct") {
  257: 	  $result.=
  258: 	    '<input type="hidden" name="problemmode" value="View" />
  259:              <input type="submit" name="problemmode" value="Edit" />
  260:              <input type="submit" name="problemmode" value="EditXML" />
  261:              Random Seed:<input type="text" name="rndseed" width="10" value="'.
  262: 	       $rndseed.'" />
  263:              <input type="submit" name="changerandseed" value="Change" />
  264:              <input type="submit" name="resetdata" value="Reset Submissions" />
  265:              <hr />';
  266: 	}
  267: 	# if we are viewing someone else preserve that info
  268: 	if (defined $ENV{'form.grade_symb'}) {
  269: 	  foreach my $field ('symb','courseid','domain','username') {
  270: 	    $result .= '<input type="hidden" name="grade_'.$field.
  271: 	      '" value="'.$ENV{"form.grade_$field"}.'" />'."\n";
  272: 	  }
  273: 	}
  274:       } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER'
  275: 	       || $status eq 'CLOSED') {
  276: 	$result.=$head_tag_start.
  277: 	  "<title>$name</title></head>\n$body_tag_start\n";
  278:       }
  279:     }
  280:   } elsif ($target eq 'edit') {
  281:     $result.=$head_tag_start."</head>".$body_tag_start.
  282:       '<form name="lonhomework" method="POST" action="'.
  283: 	$ENV{'request.uri'}.'">
  284:        <input type="hidden" name="submitted" value="edit" />
  285:        <input type="hidden" name="problemmode" value="Edit" />
  286:        <input type="submit" name="problemmode" value="View" />
  287:        <input type="submit" name="problemmode" value="EditXML" />
  288:        <input type="submit" name="Undo" value="undo" /> <hr />
  289:        <input type="submit" name="submit" value="Submit Changes" /><br />
  290:       ';
  291:     my $temp=&Apache::edit::insertlist($target,$token);
  292:     $result.=$temp;
  293:   } elsif ($target eq 'modified') {
  294:     $result=$token->[4];
  295:     $result.=&Apache::edit::handle_insert();
  296:   } elsif ($target eq 'tex') {
  297:       $result .= '\begin{document}\noindent\textbf{Problem.}\newline';
  298:   } else {
  299:     # page_start returned a starting result, delete it if we don't need it
  300:     $result = '';
  301:   }
  302:   return $result;
  303: }
  304: 
  305: sub end_problem {
  306:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  307:   my $result='';
  308:   my $status=$Apache::inputtags::status['-1'];
  309:   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ) {
  310:     if ( $target eq 'grade' && $Apache::inputtags::part eq '0' &&
  311:        $status eq 'CAN_ANSWER') {
  312:       # if part is zero, no <part>s existed, so we need to the grading
  313:       &Apache::inputtags::grade;
  314:     } elsif ( $target eq 'web' && $Apache::inputtags::part eq '0') {
  315:       # if part is zero, no <part>s existed, so we need show the current 
  316:       # grading status
  317:       $result.= &Apache::inputtags::gradestatus($Apache::inputtags::part);
  318:     }
  319:     if (
  320: 	($target eq 'web' && ($ENV{'request.state'} ne 'construct')) ||
  321: 	($target eq 'answer')
  322:        ) {
  323:       if ($status eq 'CAN_ANSWER') {
  324: 	$result.="</form></body>\n"; 
  325:       } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {
  326: 	$result.="</body>\n";
  327:       }
  328:       $result.=&Apache::lonxml::xmlend();
  329:     }
  330:     if ($target eq 'grade') { 
  331:       &Apache::lonhomework::showhash(%Apache::lonhomework::results);
  332:       &finalize_storage();
  333:     }
  334:   } elsif ($target eq 'meta') {
  335:     if ($Apache::inputtags::part eq '0') {
  336:       $result=&Apache::response::mandatory_part_meta;
  337:     }
  338:   } elsif ($target eq 'edit') {
  339:     &Apache::lonxml::debug("in end_problem with $target, edit");
  340:     $result='<br /><input type="submit" name="submit" value="Submit Changes" />';
  341:   } elsif ($target eq 'tex') {
  342:       $result .= '\end{document}';
  343:   }
  344:   return $result;
  345: }
  346: 
  347: sub start_library {
  348:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  349:   my ($result,$head_tag_start,$body_tag_start)=
  350:     &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
  351:   if ($target eq 'edit') {
  352:     $result.=$head_tag_start."</head>".$body_tag_start.
  353:       '<form name="lonhomework" method="POST" action="'.$ENV{'request.uri'}.'">
  354:        <input type="hidden" name="submitted" value="edit" />
  355:        <input type="hidden" name="problemmode" value="Edit" />
  356:        <input type="submit" name="problemmode" value="View" />
  357:        <input type="submit" name="Undo" value="undo" /> <hr />
  358:       ';
  359:     my $temp=&Apache::edit::insertlist($target,$token);
  360:     $result.=$temp;
  361:     return $result;
  362:   }
  363:   if ($target eq 'modified') {
  364:     $result=$token->[4];
  365:     $result.=&Apache::edit::handle_insert();
  366:     return $result;
  367:   }
  368:   return '';
  369: }
  370: 
  371: sub end_library {
  372:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  373:   my $result='';
  374:   if ($target eq 'edit') {
  375:     $result='<br /><input type="submit" name="submit" value="Submit Changes" />';
  376:   }
  377:   return $result;
  378: }
  379: 
  380: sub start_block {
  381:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  382: 
  383:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  384:     my $code = @$parstack[$#$parstack];
  385:     $code =~ s/\"//g;
  386:     $code .=';return $condition;';
  387:     #  print "<br />$code<br />";
  388:     my $result = &Apache::run::run($code,$safeeval);
  389:     &Apache::lonxml::debug("block :$code: returned :$result:");
  390:     if ( ! $result ) { 
  391:       my $skip=&Apache::lonxml::get_all_text("/block",$$parser[$#$parser]);
  392:       &Apache::lonxml::debug("skipping ahead :$skip: $$parser[$#$parser]");
  393:     }
  394:   }
  395:   return "";
  396: }
  397: 
  398: sub end_block {
  399:   return '';
  400: }
  401: 
  402: sub start_while {
  403:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  404: 
  405:   my $code = @$parstack[$#$parstack];
  406:   $code =~ s/\"//g;
  407:   $code .=';return $condition;';
  408: 
  409:   push( @Apache::structuretags::whileconds, $code); 
  410:   my $result = &Apache::run::run($code,$safeeval);
  411:   my $bodytext=$$parser[$#$parser]->get_text("/while");
  412:   push( @Apache::structuretags::whilebody, $bodytext);
  413:   if ( $result ) { 
  414:     &Apache::lonxml::newparser($parser,\$bodytext);
  415:   }
  416:   return "";
  417: }
  418: 
  419: sub end_while {
  420:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  421:   my $code = pop @Apache::structuretags::whileconds;
  422:   my $bodytext = pop @Apache::structuretags::whilebody;
  423:   my $result = &Apache::run::run($code,$safeeval);
  424:   if ( $result ) { 
  425:     &Apache::lonxml::newparser($parser,\$bodytext);
  426:   } 
  427:   return "";
  428: }
  429: 
  430: # <randomlist> 
  431: #  <tag1>..</tag1>
  432: #  <tag2>..</tag2>
  433: #  <tag3>..</tag3>
  434: #  ... 
  435: # </randomlist>
  436: sub start_randomlist {
  437:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  438:   if ($target eq 'answer' || $target eq 'grade' || $target eq 'web') {
  439:     my $body= &Apache::lonxml::get_all_text("/randomlist",$$parser[$#$parser]);
  440:     my $b_parser= HTML::TokeParser->new(\$body);
  441:     my $b_tok;
  442:     my @randomlist;
  443:     my $list_item;
  444:     while($b_tok = $b_parser->get_token() ) {
  445:       if($b_tok->[0] eq 'S') { # start tag
  446: 	# get content of the tag until matching end tag
  447: 	# get all text upto the matching tag
  448: 	# and push the content into @randomlist
  449: 	$list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],$b_parser);
  450: 	$list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
  451: 	push(@randomlist,$list_item);
  452: 	#  print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4], $list_item</b>";
  453:       }
  454:       if($b_tok->[0] eq 'T') { # text
  455: 	# what to do with text in between tags?
  456: 	#  print "<b>TEXT $b_tok->[1]</b><br />";
  457:       }
  458:       # if($b_tok->[0] eq 'E') { # end tag, should not happen
  459:       #  print "<b>END-TAG $b_tok->[1]</b><br />";
  460:       # }
  461:     }
  462: 
  463:     my @idx_arr = (0 .. $#randomlist);
  464:     &Apache::structuretags::shuffle(\@idx_arr);
  465:     my $bodytext = '';
  466:     for(0 .. $#randomlist) {
  467:       $bodytext .= "$randomlist[ $idx_arr[$_] ]";
  468:     }
  469:     &Apache::lonxml::newparser($parser,\$bodytext);
  470:   }
  471:   return "";
  472: }
  473: 
  474: sub shuffle {
  475:     my $a=shift;
  476:     my $i;
  477:     if (defined(@$a)) {
  478:       &Apache::response::setrandomnumber();
  479:       for($i=@$a;--$i;) {
  480: 	my $j=int rand($i+1);
  481: 	next if $i == $j;
  482: 	@$a[$i,$j] = @$a[$j,$i];
  483:       }
  484:     }
  485: }
  486: 
  487: sub end_randomlist {
  488:   return '';
  489: }
  490: 
  491: sub start_part {
  492:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  493:   my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
  494:   if ($id eq '') { $id = $Apache::lonxml::curdepth; }
  495:   $Apache::inputtags::part=$id;
  496:   @Apache::inputtags::responselist = ();
  497:   @Apache::inputtags::previous=();
  498:   if ($target eq 'meta') {
  499:     return &Apache::response::mandatory_part_meta;
  500:   } elsif ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  501:     my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
  502:     push (@Apache::inputtags::status,$status);
  503:     my $expression='$external::datestatus="'.$status.'";';
  504:     $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
  505:     &Apache::run::run($expression,$safeeval);
  506:     if ( $status eq 'CLOSED' ) {
  507:       my $bodytext=&Apache::lonxml::get_all_text("/part",$$parser[$#$parser]);
  508:       if ( $target eq "web" ) {
  509: 	return "<br />Part is not open to be viewed. It $accessmsg<br />";
  510:       }
  511:     }
  512:   }
  513:   return '';
  514: }
  515: 
  516: sub end_part {
  517:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  518:   &Apache::lonxml::debug("in end_part $target ");
  519:   my $status=$Apache::inputtags::status['-1'];
  520:   pop @Apache::inputtags::status;
  521:   if ( $target eq 'meta' ) { return ''; }
  522:   if ( $target eq 'grade' && $status eq 'CAN_ANSWER') {
  523:     return &Apache::inputtags::grade;
  524:   }
  525:   if ($target eq 'web') {
  526:     return &Apache::inputtags::gradestatus($Apache::inputtags::part);
  527:   }
  528:   return '';
  529: }
  530: 
  531: sub start_preduedate {
  532:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  533:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  534:     if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
  535: 	$Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER' ) {
  536:       &Apache::lonxml::get_all_text("/preduedate",$$parser[$#$parser]);
  537:     }
  538:   }
  539:   return '';
  540: }
  541: 
  542: sub end_preduedate {
  543:   return '';
  544: }
  545: 
  546: sub start_postanswerdate {
  547:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  548:   if ($target eq 'web' || $target eq 'grade') {
  549:     if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
  550:       &Apache::lonxml::get_all_text("/postanswerdate",$$parser[$#$parser]);
  551:     }
  552:   }
  553:   return '';
  554: }
  555: 
  556: sub end_postanswerdate {
  557:   return '';
  558: }
  559: 
  560: sub start_notsolved {
  561:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  562:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  563:     my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
  564:     &Apache::lonxml::debug("not solved has :$gradestatus:");
  565:     if ($gradestatus =~ /^correct/) {
  566:       &Apache::lonxml::debug("skipping");
  567:       &Apache::lonxml::get_all_text("/notsolved",$$parser[$#$parser]);
  568:     }
  569:   }
  570:   return '';
  571: }
  572: 
  573: sub end_notsolved {
  574:   return '';
  575: }
  576: 
  577: sub start_solved {
  578:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  579:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  580:     my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
  581:     if ($gradestatus !~ /^correct/) {
  582:       &Apache::lonxml::get_all_text("/solved",$$parser[$#$parser]);
  583:     }
  584:   }
  585:   return '';
  586: }
  587: 
  588: sub end_solved {
  589:   return '';
  590: }
  591: 
  592: sub start_startouttext {
  593:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  594:   my @result=(''.'');
  595:   if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
  596:   return (@result);
  597: }
  598: sub end_startouttext {
  599:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  600:   my $result='';
  601:   my $text='';
  602: 
  603:   if ($target eq 'edit') {
  604:     $text=&Apache::lonxml::get_all_text("endouttext",$$parser[-1]);
  605:     $result.=&Apache::edit::start_table($token)."<tr><td>Text Block</td>
  606: <td>Delete:".
  607:   &Apache::edit::deletelist($target,$token)
  608:   ."</td>
  609: <td>".
  610:   &Apache::edit::insertlist($target,$token).
  611:     "</td>
  612: </tr><tr><td colspan=\"3\">\n".
  613: 	&Apache::edit::editfield($token->[1],$text,"",50,4);
  614:   }
  615:   if ($target eq 'modified') {
  616:     $text=&Apache::lonxml::get_all_text("endouttext",$$parser['-1']);
  617:     $result='<startouttext />'.&Apache::edit::modifiedfield();
  618:   }
  619:   return $result;
  620: }
  621: sub start_endouttext {
  622:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  623:   my $result='';
  624:   if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
  625:   if ($target eq "modified") { $result='<endouttext />'; }
  626:   return $result;
  627: }
  628: sub end_endouttext {
  629:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  630:   my @result=('','');
  631:   if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
  632:   return (@result);
  633: }
  634: sub delete_startouttext {
  635:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  636: #  my $text=&Apache::lonxml::get_all_text("endouttext",$$parser['-1']);
  637:   my $text=$$parser['-1']->get_text("/endouttext");
  638:   my $ntoken=$$parser['-1']->get_token();
  639:   &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
  640:   &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
  641:   # Deleting 2 parallel tag pairs, but we need the numbers later to look like 
  642:   # they did the last time round
  643:   &Apache::lonxml::increasedepth($ntoken);
  644:   &Apache::lonxml::decreasedepth($ntoken);
  645:   return 1;
  646: }
  647: 
  648: 1;
  649: __END__

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