File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.89: download - view: text, annotated - select for diffs
Wed Apr 10 19:58:19 2002 UTC (22 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- now alwyas generates at least the package metadata for part 0

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

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