File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.74: download - view: text, annotated - select for diffs
Tue Dec 4 15:17:56 2001 UTC (22 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- GPL headers

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

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