File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.86: download - view: text, annotated - select for diffs
Thu Mar 28 22:53:55 2002 UTC (22 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- cleaned up <rnadomlist> edit mode
- added arg show to <randomlist>, to optionally limit the number of internal tags it shows.

    1: # The LearningOnline Network with CAPA 
    2: # definition of tags that give a structure to a document
    3: #
    4: # $Id: structuretags.pm,v 1.86 2002/03/28 22:53:55 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(undef,$target);
   83:   }
   84:   my $body_tag_start;
   85:   if (!defined($found{'body'})) {
   86:     $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:   # meta is called from lonpublisher, which doesn't uses the normal
  166:   # lonhomework method of parsing the file which means that inputtags 
  167:   # won't get reset
  168:   if ( $Apache::inputtags::part ne '' && $target != 'meta' ) {
  169:     &Apache::lonxml::error('Only one problem allowed in a .problem file');
  170:     my $bodytext=&Apache::lonxml::get_all_text("/problem",$$parser[-1]);
  171:     return '';
  172:   }
  173: #intialize globals
  174:   $Apache::inputtags::part='0';
  175:   @Apache::inputtags::responselist = ();
  176:   @Apache::inputtags::previous=();
  177:   &initialize_storage();
  178:   if ($target eq 'web') {
  179:     &Apache::lonhomework::showhash(%Apache::lonhomework::history);
  180:   }
  181:   $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
  182:   &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
  183:   if ($Apache::lonhomework::type eq '') {
  184:     my $uri=$ENV{'request.uri'};
  185:     if ($uri=~/\.(\w+)$/) {
  186:       $Apache::lonhomework::type=$1;
  187:       &Apache::lonxml::debug("Using type of $1");
  188:     } else {
  189:       $Apache::lonhomework::type='problem';
  190:       &Apache::lonxml::debug("Using default type, problem, :$uri:");
  191:     }
  192:   }
  193: 
  194:   #added vars to the scripting enviroment
  195:   my $expression='$external::part='.$Apache::inputtags::part.';';
  196:   &Apache::run::run($expression,$safeeval);
  197:   my $status;
  198:   my $accessmsg;
  199: 
  200:   #should get back a <html> or the neccesary stuff to start XML/MathML
  201:   my ($result,$head_tag_start,$body_tag_start)=
  202:     &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
  203: 
  204: 
  205:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  206:     #handle exam checkout
  207:     if ($Apache::lonhomework::type eq 'exam') {
  208:       my $token=$Apache::lonhomework::history{"resource.0.outtoken"};
  209:       if (($ENV{'form.doescheckout'}) && (!$token)) {
  210: 	$token=&Apache::lonxml::maketoken();
  211: 	$Apache::lonhomework::history{"resource.0.outtoken"}=$token;
  212:       }
  213:       $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token);
  214:     }
  215: 
  216:     #handle rand seed in construction space
  217:     my $rndseed;
  218:     if ($ENV{'request.state'} eq "construct") {
  219:       $rndseed=$ENV{'form.rndseed'};
  220:       if (!$rndseed) {
  221: 	$rndseed=time;
  222: 	$ENV{'form.rndseed'}=$rndseed;
  223:       }
  224:       &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval);
  225:     }
  226:     ($status,$accessmsg) = &Apache::lonhomework::check_access('0');
  227:     push (@Apache::inputtags::status,$status);
  228:     my $expression='$external::datestatus="'.$status.'";';
  229:     $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
  230:     &Apache::run::run($expression,$safeeval);
  231:     if (( $status eq 'CLOSED' ) ||
  232:         ( $status eq 'UNCHECKEDOUT') ||
  233:         ( $status eq 'BANNED')) {
  234:       my $bodytext=&Apache::lonxml::get_all_text("/problem",$$parser[$#$parser]);
  235:       if ( $target eq "web" ) {
  236: 	$result.= $head_tag_start.'</head>';
  237:         my $msg=$body_tag_start.
  238: 	    '<h1>Not open to be viewed</h1>';
  239:         if ($status eq 'CLOSED') {
  240: 	    $msg.='The problem '.$accessmsg;
  241: 	} elsif ($status eq 'UNCHECKEDOUT') {
  242:             $msg.=&checkout_msg;
  243:         }
  244: 	$result.=$msg.'<br />';
  245:       }
  246:     } elsif ($target eq 'web') {
  247:       my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
  248:       if ($name eq '') { 
  249: 	$name=&Apache::lonnet::EXT('resource.title');
  250: 	if ($name eq 'con_lost') { $name = ''; }
  251:       }
  252:       $Apache::lonhomework::name=$name;
  253:       if ($status eq 'CAN_ANSWER') {
  254: 	# create a page header and exit
  255: 	$result.="$head_tag_start<title>$name</title></head>\n
  256:               $body_tag_start\n
  257:               <form name=\"lonhomework\" method=\"POST\" action=\"".$ENV{'request.uri'}."\">".
  258: 		'<input type="hidden" name="submitted" value="yes" />';
  259: 	if ($ENV{'request.state'} eq "construct") {
  260: 	  $result.=
  261: 	    '<input type="hidden" name="problemmode" value="View" />
  262:              <input type="submit" name="problemmode" value="Edit" />
  263:              <input type="submit" name="problemmode" value="EditXML" />
  264:              Random Seed:<input type="text" name="rndseed" width="10" value="'.
  265: 	       $rndseed.'" />
  266:              <input type="submit" name="changerandseed" value="Change" />
  267:              <input type="submit" name="resetdata" value="Reset Submissions" />
  268:              <hr />';
  269: 	}
  270: 	# if we are viewing someone else preserve that info
  271: 	if (defined $ENV{'form.grade_symb'}) {
  272: 	  foreach my $field ('symb','courseid','domain','username') {
  273: 	    $result .= '<input type="hidden" name="grade_'.$field.
  274: 	      '" value="'.$ENV{"form.grade_$field"}.'" />'."\n";
  275: 	  }
  276: 	}
  277:       } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER'
  278: 	       || $status eq 'CLOSED') {
  279: 	$result.=$head_tag_start.
  280: 	  "<title>$name</title></head>\n$body_tag_start\n";
  281:       }
  282:     }
  283:   } elsif ($target eq 'edit') {
  284:     $result.=$head_tag_start."</head>".$body_tag_start.
  285:       '<form name="lonhomework" method="POST" action="'.
  286: 	$ENV{'request.uri'}.'">
  287:        <input type="hidden" name="submitted" value="edit" />
  288:        <input type="hidden" name="problemmode" value="Edit" />
  289:        <input type="submit" name="problemmode" value="View" />
  290:        <input type="submit" name="problemmode" value="EditXML" />
  291:        <input type="submit" name="Undo" value="undo" /> <hr />
  292:        <input type="submit" name="submit" value="Submit Changes" /><br />
  293:       ';
  294:     my $temp=&Apache::edit::insertlist($target,$token);
  295:     $result.=$temp;
  296:   } elsif ($target eq 'modified') {
  297:     $result=$token->[4];
  298:     $result.=&Apache::edit::handle_insert();
  299:   } elsif ($target eq 'tex') {
  300:       $result .= '\begin{document} ';
  301:   } else {
  302:     # page_start returned a starting result, delete it if we don't need it
  303:     $result = '';
  304:   }
  305:   return $result;
  306: }
  307: 
  308: sub end_problem {
  309:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  310:   my $result='';
  311:   my $status=$Apache::inputtags::status['-1'];
  312:   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ) {
  313:     if ( $target eq 'grade' && $Apache::inputtags::part eq '0') {
  314:       # if part is zero, no <part>s existed, so we need to the grading
  315:       &Apache::inputtags::grade;
  316:     } elsif ( $target eq 'web' && $Apache::inputtags::part eq '0') {
  317:       # if part is zero, no <part>s existed, so we need show the current 
  318:       # grading status
  319:       $result.= &Apache::inputtags::gradestatus($Apache::inputtags::part);
  320:     }
  321:     if (
  322: 	($target eq 'web' && ($ENV{'request.state'} ne 'construct')) ||
  323: 	($target eq 'answer')
  324:        ) {
  325:       if ($status eq 'CAN_ANSWER') {
  326: 	$result.="</form></body>\n"; 
  327:       } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {
  328: 	$result.="</body>\n";
  329:       }
  330:       $result.=&Apache::lonxml::xmlend();
  331:     }
  332:     if ($target eq 'grade') { 
  333:       &Apache::lonhomework::showhash(%Apache::lonhomework::results);
  334:       &finalize_storage();
  335:     }
  336:   } elsif ($target eq 'meta') {
  337:     if ($Apache::inputtags::part eq '0') {
  338:       $result=&Apache::response::mandatory_part_meta;
  339:     }
  340:   } elsif ($target eq 'edit') {
  341:     &Apache::lonxml::debug("in end_problem with $target, edit");
  342:     $result='<br /><input type="submit" name="submit" value="Submit Changes" />';
  343:   } elsif ($target eq 'tex') {
  344:       $result .= '\noindent\makebox[9.0cm][b]{\hrulefill}\end{document}';
  345:   }
  346:   return $result;
  347: }
  348: 
  349: sub start_library {
  350:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  351:   my ($result,$head_tag_start,$body_tag_start)=
  352:     &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
  353:   if ($target eq 'edit') {
  354:     $result.=$head_tag_start."</head>".$body_tag_start.
  355:       '<form name="lonhomework" method="POST" action="'.$ENV{'request.uri'}.'">
  356:        <input type="hidden" name="submitted" value="edit" />
  357:        <input type="hidden" name="problemmode" value="Edit" />
  358:        <input type="submit" name="problemmode" value="View" />
  359:        <input type="submit" name="Undo" value="undo" /> <hr />
  360:       ';
  361:     my $temp=&Apache::edit::insertlist($target,$token);
  362:     $result.=$temp;
  363:     return $result;
  364:   }
  365:   if ($target eq 'modified') {
  366:     $result=$token->[4];
  367:     $result.=&Apache::edit::handle_insert();
  368:     return $result;
  369:   }
  370:   return '';
  371: }
  372: 
  373: sub end_library {
  374:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  375:   my $result='';
  376:   if ($target eq 'edit') {
  377:     $result='<br /><input type="submit" name="submit" value="Submit Changes" />';
  378:   }
  379:   return $result;
  380: }
  381: 
  382: sub start_block {
  383:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  384: 
  385:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  386:     my $code = @$parstack[$#$parstack];
  387:     $code =~ s/\"//g;
  388:     $code .=';return $condition;';
  389:     #  print "<br />$code<br />";
  390:     my $result = &Apache::run::run($code,$safeeval);
  391:     &Apache::lonxml::debug("block :$code: returned :$result:");
  392:     if ( ! $result ) { 
  393:       my $skip=&Apache::lonxml::get_all_text("/block",$$parser[$#$parser]);
  394:       &Apache::lonxml::debug("skipping ahead :$skip: $$parser[$#$parser]");
  395:     }
  396:   }
  397:   return "";
  398: }
  399: 
  400: sub end_block {
  401:   return '';
  402: }
  403: 
  404: sub start_while {
  405:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  406: 
  407:   my $code = @$parstack[$#$parstack];
  408:   $code =~ s/\"//g;
  409:   $code .=';return $condition;';
  410: 
  411:   push( @Apache::structuretags::whileconds, $code); 
  412:   my $result = &Apache::run::run($code,$safeeval);
  413:   my $bodytext=$$parser[$#$parser]->get_text("/while");
  414:   push( @Apache::structuretags::whilebody, $bodytext);
  415:   if ( $result ) { 
  416:     &Apache::lonxml::newparser($parser,\$bodytext);
  417:   }
  418:   return "";
  419: }
  420: 
  421: sub end_while {
  422:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  423:   my $code = pop @Apache::structuretags::whileconds;
  424:   my $bodytext = pop @Apache::structuretags::whilebody;
  425:   my $result = &Apache::run::run($code,$safeeval);
  426:   if ( $result ) { 
  427:     &Apache::lonxml::newparser($parser,\$bodytext);
  428:   } 
  429:   return "";
  430: }
  431: 
  432: # <randomlist> 
  433: #  <tag1>..</tag1>
  434: #  <tag2>..</tag2>
  435: #  <tag3>..</tag3>
  436: #  ... 
  437: # </randomlist>
  438: sub start_randomlist {
  439:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  440:   my $result;
  441:   if ($target eq 'answer' || $target eq 'grade' || $target eq 'web') {
  442:     my $body= &Apache::lonxml::get_all_text("/randomlist",$$parser[$#$parser]);
  443:     my $b_parser= HTML::TokeParser->new(\$body);
  444:     my $b_tok;
  445:     my @randomlist;
  446:     my $list_item;
  447:     while($b_tok = $b_parser->get_token() ) {
  448:       if($b_tok->[0] eq 'S') { # start tag
  449: 	# get content of the tag until matching end tag
  450: 	# get all text upto the matching tag
  451: 	# and push the content into @randomlist
  452: 	$list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],$b_parser);
  453: 	$list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
  454: 	push(@randomlist,$list_item);
  455: 	#  print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4], $list_item</b>";
  456:       }
  457:       if($b_tok->[0] eq 'T') { # text
  458: 	# what to do with text in between tags?
  459: 	#  print "<b>TEXT $b_tok->[1]</b><br />";
  460:       }
  461:       # if($b_tok->[0] eq 'E') { # end tag, should not happen
  462:       #  print "<b>END-TAG $b_tok->[1]</b><br />";
  463:       # }
  464:     }
  465:     my @idx_arr = (0 .. $#randomlist);
  466:     &Apache::structuretags::shuffle(\@idx_arr);
  467:     my $bodytext = '';
  468:     my $show=$#randomlist;
  469:     my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
  470:     $showarg--;
  471:     if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
  472:     for(0 .. $show) {
  473:       $bodytext .= "$randomlist[ $idx_arr[$_] ]";
  474:     }
  475:     &Apache::lonxml::newparser($parser,\$bodytext);
  476:   } elsif ($target eq 'edit' ) {
  477:     $result .= &Apache::edit::tag_start($target,$token);
  478:     $result .= &Apache::edit::text_arg('Maximum Tags to Show:','show',$token,5);
  479:     $result .= &Apache::edit::end_row().&Apache::edit::start_spanning_row();
  480:   } elsif ($target eq 'modified' ) {
  481:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
  482: 						 'show');
  483:     if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  484:   }
  485:   return $result;
  486: }
  487: 
  488: sub shuffle {
  489:     my $a=shift;
  490:     my $i;
  491:     if (defined(@$a)) {
  492:       &Apache::response::setrandomnumber();
  493:       for($i=@$a;--$i;) {
  494: 	my $j=int rand($i+1);
  495: 	next if $i == $j;
  496: 	@$a[$i,$j] = @$a[$j,$i];
  497:       }
  498:     }
  499: }
  500: 
  501: sub end_randomlist {
  502:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  503:   my $result;
  504:   if ($target eq 'edit' ) {
  505:     $result=&Apache::edit::tag_end($target,$token,'End Randomly Parsed Block');
  506:   }
  507:   return $result;
  508: }
  509: 
  510: sub start_part {
  511:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  512:   my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
  513:   if ($id eq '') { $id = $Apache::lonxml::curdepth; }
  514:   $Apache::inputtags::part=$id;
  515:   @Apache::inputtags::responselist = ();
  516:   @Apache::inputtags::previous=();
  517:   if ($target eq 'meta') {
  518:     return &Apache::response::mandatory_part_meta;
  519:   } elsif ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  520:     my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
  521:     push (@Apache::inputtags::status,$status);
  522:     my $expression='$external::datestatus="'.$status.'";';
  523:     $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
  524:     &Apache::run::run($expression,$safeeval);
  525:     if ( $status eq 'CLOSED' ) {
  526:       my $bodytext=&Apache::lonxml::get_all_text("/part",$$parser[$#$parser]);
  527:       if ( $target eq "web" ) {
  528: 	return "<br />Part is not open to be viewed. It $accessmsg<br />";
  529:       }
  530:     }
  531:   }
  532:   return '';
  533: }
  534: 
  535: sub end_part {
  536:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  537:   &Apache::lonxml::debug("in end_part $target ");
  538:   my $status=$Apache::inputtags::status['-1'];
  539:   pop @Apache::inputtags::status;
  540:   if ( $target eq 'meta' ) { return ''; }
  541:   if ( $target eq 'grade' && $status eq 'CAN_ANSWER') {
  542:     return &Apache::inputtags::grade;
  543:   }
  544:   if ($target eq 'web') {
  545:     return &Apache::inputtags::gradestatus($Apache::inputtags::part);
  546:   }
  547:   return '';
  548: }
  549: 
  550: sub start_preduedate {
  551:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  552:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  553:     if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
  554: 	$Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER' ) {
  555:       &Apache::lonxml::get_all_text("/preduedate",$$parser[$#$parser]);
  556:     }
  557:   }
  558:   return '';
  559: }
  560: 
  561: sub end_preduedate {
  562:   return '';
  563: }
  564: 
  565: sub start_postanswerdate {
  566:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  567:   if ($target eq 'web' || $target eq 'grade') {
  568:     if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
  569:       &Apache::lonxml::get_all_text("/postanswerdate",$$parser[$#$parser]);
  570:     }
  571:   }
  572:   return '';
  573: }
  574: 
  575: sub end_postanswerdate {
  576:   return '';
  577: }
  578: 
  579: sub start_notsolved {
  580:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  581:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  582:     my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
  583:     &Apache::lonxml::debug("not solved has :$gradestatus:");
  584:     if ($gradestatus =~ /^correct/) {
  585:       &Apache::lonxml::debug("skipping");
  586:       &Apache::lonxml::get_all_text("/notsolved",$$parser[$#$parser]);
  587:     }
  588:   }
  589:   return '';
  590: }
  591: 
  592: sub end_notsolved {
  593:   return '';
  594: }
  595: 
  596: sub start_solved {
  597:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  598:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
  599:     my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
  600:     if ($gradestatus !~ /^correct/) {
  601:       &Apache::lonxml::get_all_text("/solved",$$parser[$#$parser]);
  602:     }
  603:   }
  604:   return '';
  605: }
  606: 
  607: sub end_solved {
  608:   return '';
  609: }
  610: 
  611: sub start_startouttext {
  612:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  613:   my @result=(''.'');
  614:   if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
  615:   return (@result);
  616: }
  617: sub end_startouttext {
  618:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  619:   my $result='';
  620:   my $text='';
  621: 
  622:   if ($target eq 'edit') {
  623:     $text=&Apache::lonxml::get_all_text("endouttext",$$parser[-1]);
  624:     $result.=&Apache::edit::start_table($token)."<tr><td>Text Block</td>
  625: <td>Delete:".
  626:   &Apache::edit::deletelist($target,$token)
  627:     ."</td>
  628: <td>".
  629:   &Apache::edit::insertlist($target,$token).
  630:     &Apache::edit::end_row().&Apache::edit::start_spanning_row()."\n".
  631:       &Apache::edit::editfield($token->[1],$text,"",50,4);
  632:   }
  633:   if ($target eq 'modified') {
  634:     $text=&Apache::lonxml::get_all_text("endouttext",$$parser['-1']);
  635:     $result='<startouttext />'.&Apache::edit::modifiedfield();
  636:   }
  637:   if ($target eq 'tex') {
  638:       $result .= '\noindent ';
  639:   }
  640:   return $result;
  641: }
  642: sub start_endouttext {
  643:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  644:   my $result='';
  645:   if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
  646:   if ($target eq "modified") { $result='<endouttext />'; }
  647:   return $result;
  648: }
  649: sub end_endouttext {
  650:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  651:   my @result=('','');
  652:   if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
  653:   return (@result);
  654: }
  655: sub delete_startouttext {
  656:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  657: #  my $text=&Apache::lonxml::get_all_text("endouttext",$$parser['-1']);
  658:   my $text=$$parser['-1']->get_text("/endouttext");
  659:   my $ntoken=$$parser['-1']->get_token();
  660:   &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
  661:   &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
  662:   # Deleting 2 parallel tag pairs, but we need the numbers later to look like 
  663:   # they did the last time round
  664:   &Apache::lonxml::increasedepth($ntoken);
  665:   &Apache::lonxml::decreasedepth($ntoken);
  666:   return 1;
  667: }
  668: 
  669: 1;
  670: __END__

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