File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.73: download - view: text, annotated - select for diffs
Tue Dec 4 14:53:59 2001 UTC (22 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- added support for EditXML

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

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