File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.182: download - view: text, annotated - select for diffs
Thu Jun 12 22:19:33 2003 UTC (20 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- <web> and <tex> should run for all other targets too
- process the contents of <web>/<tex> so more markup can occur inside of it.
- BUG#1723

    1: # The LearningOnline Network with CAPA 
    2: # definition of tags that give a structure to a document
    3: #
    4: # $Id: structuretags.pm,v 1.182 2003/06/12 22:19:33 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: 
   33: package Apache::structuretags; 
   34: 
   35: use strict;
   36: use Apache::lonnet;
   37: use Apache::File();
   38: use Apache::lonmenu;
   39: 
   40: BEGIN {
   41:     &Apache::lonxml::register('Apache::structuretags',('block','languageblock','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','startouttext','endouttext'));
   42: }
   43: 
   44: sub start_web {
   45:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   46:     if (!($target eq 'web' || $target eq 'edit' || $target eq 'modified' ||
   47: 	  $target eq 'answer' || $target eq 'grade' || $target eq 'meta' )) {
   48: 	my $bodytext=&Apache::lonxml::get_all_text("/web",$parser);
   49:     }
   50:     return '';
   51: }
   52: 
   53: sub end_web {
   54:     return '';
   55: }
   56: 
   57: sub start_tex {
   58:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   59:     if (!($target eq 'tex' || $target eq 'edit' || $target eq 'modified' ||
   60: 	  $target eq 'answer' || $target eq 'grade' || $target eq 'meta' )) {
   61: 	&Apache::lonxml::debug("tex 1");
   62: 	my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser);
   63:     }
   64:     return '';
   65: }
   66: 
   67: sub end_tex {
   68:     return '';
   69: }
   70: 
   71: sub page_start {
   72:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
   73:     my %found;
   74:     foreach my $taginside ($tagstack) {
   75: 	foreach my $taglookedfor ('html','body','form') {
   76: 	    if ($taginside =~ /^$taglookedfor$/i) {$found{$taglookedfor} = 1;}
   77: 	}
   78:     }
   79: 
   80:     my $result;
   81:     my $head_tag_start;
   82:     if (!defined($found{'html'})) {
   83: 	$result=&Apache::londefdef::start_html($target,$token,$tagstack,
   84: 					       $parstack,$parser,$safeeval);
   85: 	$head_tag_start='<head>'.&Apache::lonmenu::registerurl(undef,$target);
   86:     }
   87:     my $body_tag_start;
   88:     if (!defined($found{'body'})) {
   89: 	$body_tag_start='<body onLoad="'.&Apache::lonmenu::loadevents().'" '.
   90: 	    'onUnload="'.&Apache::lonmenu::unloadevents().'" ';
   91: 	my $background=&Apache::lonxml::get_param('background',$parstack,
   92: 						  $safeeval);
   93: 	if ($background) {
   94: 	    $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
   95: 		$background;
   96: 	    $body_tag_start.='background="'.$background.'" ';
   97: 	} else {
   98: 	    my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,
   99: 						   $safeeval);
  100: 	    if ($bgcolor) {
  101: 		$body_tag_start.='bgcolor="'.$bgcolor.'" ';
  102: 	    } else {
  103: 		$body_tag_start.='bgcolor="#ffffff"';
  104: 	    }
  105: 	}
  106: 	$body_tag_start.='>'.&Apache::lonmenu::menubuttons(undef,$target,1);
  107: 	if ($target eq 'web' && $ENV{'request.state'} ne 'construct') {
  108: 	    my ($symb,undef,undef,undef,$publicuser)=
  109: 		&Apache::lonxml::whichuser();
  110: 	    if ($symb eq '' && !$publicuser) {
  111: 		my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference");
  112: 		$help="Browsing resource, all submissions are temporary.<br />";
  113: 		$body_tag_start.=$help;
  114: 	    }
  115: 	}
  116:     }
  117:     my $form_tag_start;
  118:     if (!defined($found{'form'})) {
  119: 	$form_tag_start='<form name="lonhomework" method="POST" action="'.
  120: 	    $ENV{'request.uri'}.'">';
  121:     }
  122:     return ($result,$head_tag_start,$body_tag_start,$form_tag_start);
  123: }
  124: 
  125: #use Time::HiRes();
  126: sub get_resource_name {
  127:     my ($parstack,$safeeval)=@_;
  128:     my $name=&Apache::lonnet::gettitle();
  129:     if ($name eq '') {
  130: 	$name=&Apache::lonnet::EXT('resource.title');
  131: 	if ($name eq 'con_lost') { $name = ''; }
  132:     }
  133:     $Apache::lonhomework::name=$name;
  134:     return $name;
  135: }
  136: 
  137: sub setup_rndseed {
  138:     my ($safeeval)=@_;
  139:     my $rndseed;
  140:     my ($symb)=&Apache::lonxml::whichuser();
  141:     if ($ENV{'request.state'} eq "construct" || $symb eq '') {
  142: 	$rndseed=$ENV{'form.rndseed'};
  143: 	if (!$rndseed) {
  144: 	    $rndseed=$Apache::lonhomework::history{'rndseed'};
  145: 	    if (!$rndseed) {
  146: 		$rndseed=time;
  147: 		$ENV{'form.rndseed'}=$rndseed;
  148: 	    }
  149: 	}
  150: 	if ($ENV{'form.resetdata'} eq 'New Problem Variation' ||
  151: 	    $ENV{'form.newrandomization'} eq 'New Randomization') {
  152: 	    $rndseed=time;
  153: 	    if ($rndseed eq $ENV{'form.rndseed'}) {
  154: 		srand($rndseed);
  155: 		$rndseed=int(rand(1000000000));
  156: 	    }
  157: 	    $ENV{'form.rndseed'}=$rndseed;
  158: 	    delete($ENV{'form.resetdata'});
  159: 	    delete($ENV{'form.newrandomization'});
  160: 	}
  161: 	&Apache::lonxml::debug("Setting rndseed to $rndseed");
  162: 	&Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval);
  163:     }
  164:     return $rndseed;
  165: }
  166: 
  167: sub problem_edit_header {
  168:     return '<input type="hidden" name="submitted" value="edit" />
  169:        <input type="hidden" name="problemmode" value="Edit" />
  170:        <input type="submit" name="problemmode" value="Discard Edits and View" />
  171:        <input type="submit" name="problemmode" value="EditXML" />
  172:        <input type="submit" name="Undo" value="undo" /> <hr />
  173:        <input type="submit" name="submit" value="Submit Changes and Edit" />
  174:        <input type="submit" name="submit" value="Submit Changes and View" /><br /><p>&nbsp;</p><table border="0"><tr><td bgcolor="#DDDDDD">
  175:       ';
  176: }
  177: 
  178: sub problem_edit_footer {
  179:     return '</td></tr></table><br /><input type="submit" name="submit" value="Submit Changes and Edit" />
  180:     <input type="submit" name="submit" value="Submit Changes and View" />';
  181: }
  182: 
  183: sub problem_web_to_edit_header {
  184:     my ($rndseed)=@_;
  185:     my $result.='<input type="hidden" name="problemmode" value="View" />
  186:              <input type="submit" name="problemmode" value="Edit" />
  187:              <input type="submit" name="problemmode" value="EditXML" />
  188:              <input type="submit" name="newrandomization" value="New Randomization" />
  189:              <input type="submit" name="resetdata" value="Reset Submissions" />
  190:              <nobr><input type="submit" name="changerandseed" value="Change Random Seed To:" />
  191:               <input type="text" name="rndseed" width="10" value="'.
  192: 	       $rndseed.'"
  193:            onChange="javascript:document.lonhomework.changerandseed.click()" /></nobr>
  194:              <input type="checkbox" name="showallfoils" ';
  195:     if (defined($ENV{'form.showallfoils'})) { $result.='checked="on"'; }
  196:     $result.= ' />&nbsp;Show&nbsp;All&nbsp;Foils
  197:              <hr />';
  198:     my $numtoanalyze=$ENV{'form.numtoanalyze'};
  199:     if (!$numtoanalyze) { $numtoanalyze=20; }
  200:     $result.= '<input type="submit" name="problemmode" value="Calculate answers" /> for
  201:              <input type="text" name="numtoanalyze" value="'.
  202: 		 $numtoanalyze.'" size="5" /> versions of this problem.'.
  203: 		     &Apache::loncommon::help_open_topic("Analyze_Problem",
  204: 						     '',undef,undef,300).
  205: 		     '<hr />';
  206:     return $result;
  207: }
  208: 
  209: sub initialize_storage {
  210:     %Apache::lonhomework::results=();
  211:     %Apache::lonhomework::history=();
  212:     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
  213:     if ($ENV{'request.state'} eq 'construct' || $symb eq '') {
  214: 	%Apache::lonhomework::history=
  215: 	    &Apache::lonnet::tmprestore($ENV{'request.uri'},'',$domain,$name);
  216: 	my ($temp)=keys %Apache::lonhomework::history ;
  217: 	&Apache::lonxml::debug("Return message of $temp");
  218:     } else {
  219: 	%Apache::lonhomework::history=
  220: 	    &Apache::lonnet::restore($symb,$courseid,$domain,$name);
  221:     }
  222:     #ignore error conditions
  223:     my ($temp)=keys %Apache::lonhomework::history ;
  224:     if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
  225: }
  226: 
  227: # -------------------------------------------------------------finalize_storage
  228: # Stores away the result has to a student's environment
  229: # checks form.grade_ for specific values, other wises stores
  230: # to the running users environment
  231: sub finalize_storage {
  232:     my $result;
  233:     my ($temp) = keys %Apache::lonhomework::results;
  234:     if ( $temp ne '' ) {
  235: 	my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
  236: 	if ($ENV{'request.state'} eq 'construct' || $symb eq '') {
  237: 	    $Apache::lonhomework::results{'rndseed'}=$ENV{'form.rndseed'};
  238: 	    $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,
  239: 					$ENV{'request.uri'},'',$domain,$name);
  240: 	    &Apache::lonxml::debug('Construct Store return message:'.$result);
  241: 	} else {
  242: 	    $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
  243: 					    $symb,$courseid,$domain,$name);
  244: 	    &Apache::lonxml::debug('Store return message:'.$result);
  245: 	}
  246:     }
  247:     return $result;
  248: }
  249: 
  250: sub checkout_msg {
  251:     return (<<ENDCHECKOUT);
  252: <h2>The resource needs to be checked out</h2>
  253: As a resource gets checked out, a unique timestamped ID is given to it, and a
  254: permanent record is left in the system.<p />
  255: <font color=red>
  256: Checking out resources is subject to course policies, and may exclude future
  257: credit even if done erroneously.<p />
  258: </font>
  259: <form name="checkout" method="POST" action="$ENV{'request.uri'}">
  260: <input type="hidden" name="doescheckout" value="yes" />
  261: <input type="button" name="checkoutbutton" value="Check out Exam for Viewing" onClick="javascript:if (confirm('Check out Exam?')) { document.checkout.submit(); }" />
  262: </form>
  263: ENDCHECKOUT
  264: }
  265: 
  266: sub start_problem {
  267:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  268: 
  269:     $Apache::lonhomework::parsing_a_problem=1;
  270:     # meta is called from lonpublisher, which doesn't uses the normal
  271:     # lonhomework method of parsing the file which means that inputtags 
  272:     # won't get reset
  273:     if ( $Apache::inputtags::part ne '' && $target != 'meta' ) {
  274: 	&Apache::lonxml::error('Only one problem allowed in a .problem file');
  275: 	my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
  276: 	return '';
  277:     }
  278: #initialize globals
  279:     $Apache::inputtags::part='0';
  280:     @Apache::inputtags::partlist=('0');
  281:     @Apache::inputtags::responselist = ();
  282:     @Apache::inputtags::importlist = ();
  283:     @Apache::inputtags::previous=();
  284:     @Apache::inputtags::previous_version=();
  285:     $Apache::structuretags::printanswer='No';
  286:     @Apache::structuretags::whileconds=();
  287:     @Apache::structuretags::whilebody=();
  288:     @Apache::structuretags::whileline=();
  289:     $Apache::lonhomework::scantronmode=0;
  290:     $Apache::lonhomework::problemstatus=
  291: 	&Apache::lonnet::EXT('resource.0.problemstatus');
  292: 
  293:     if (defined($ENV{'scantron.maxquest'})) {
  294: 	$Apache::lonhomework::scantronmode=1;
  295:     }
  296: 
  297:     if ($target ne 'analyze') {
  298: 	&initialize_storage();
  299: 	if ($target eq 'web') {
  300: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
  301: 	}
  302: 	$Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
  303: 	&Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
  304:     }
  305:     if ($Apache::lonhomework::type eq '' ) {
  306: 	my $uri=$ENV{'request.uri'};
  307: 	if ($uri=~/\.(\w+)$/) {
  308: 	    $Apache::lonhomework::type=$1;
  309: 	    &Apache::lonxml::debug("Using type of $1");
  310: 	} else {
  311: 	    $Apache::lonhomework::type='problem';
  312: 	    &Apache::lonxml::debug("Using default type, problem, :$uri:");
  313: 	}
  314:     }
  315: 
  316:     #added vars to the scripting enviroment
  317:     my $expression='$external::part='.$Apache::inputtags::part.';';
  318:     &Apache::run::run($expression,$safeeval);
  319:     my $status;
  320:     my $accessmsg;
  321: 
  322:     #should get back a <html> or the neccesary stuff to start XML/MathML
  323:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
  324: 	&page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
  325:     if ($target eq 'tex' and $ENV{'request.symb'} =~ m/\.page_/) {$result='';}
  326: 
  327:     if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval); }
  328:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  329: 	$target eq 'tex') {
  330: 	#handle exam checkout
  331: 	if ($Apache::lonhomework::type eq 'exam') {
  332: 	    my $token=
  333: 		$Apache::lonhomework::history{"resource.0.outtoken"};
  334: 	    if (($ENV{'form.doescheckout'}) && (!$token)) {
  335: 		$token=&Apache::lonxml::maketoken();
  336: 		$Apache::lonhomework::history{"resource.0.outtoken"}=
  337: 		    $token;
  338: 	    }
  339: 	    $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token);
  340: 	}
  341: 
  342: 	#handle rand seed in construction space
  343: 	my $rndseed=&setup_rndseed($safeeval);
  344: 	my ($symb)=&Apache::lonxml::whichuser();
  345: 	if ($ENV{'request.state'} ne "construct" && $symb eq '') {
  346: 	    $form_tag_start.='<input type="hidden" name="rndseed" value="'.
  347: 		$rndseed.'" />'.
  348: 		    '<input type="submit" name="resetdata"
  349:                              value="New Problem Variation" />'.
  350: 		    '<input type="hidden" name="username"
  351:                              value="'.$ENV{'form.username'}.'" />';
  352: 	}
  353: 	($status,$accessmsg) = &Apache::lonhomework::check_access('0');
  354: 	push (@Apache::inputtags::status,$status);
  355: 	my $expression='$external::datestatus="'.$status.'";';
  356: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
  357: 	&Apache::run::run($expression,$safeeval);
  358: 	&Apache::lonxml::debug("Got $status");
  359: 	if (( $status eq 'CLOSED' ) ||
  360: 	    ( $status eq 'UNCHECKEDOUT') ||
  361: 	    ( $status eq 'BANNED') ||
  362: 	    ( $status eq 'UNAVAILABLE')) {
  363: 	    my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
  364: 	    if ( $target eq "web" ) {
  365: 		$result.= $head_tag_start.'</head>';
  366: 		my $msg=$body_tag_start;
  367: 		if ($status eq 'UNAVAILABLE') {
  368: 		    $result.='<h1>Unable to determine if this resource is open due to network problems. Please try again later.</h1>';
  369: 		} else {
  370: 		    $result.='<h1>Not open to be viewed</h1>';
  371: 		}
  372: 		if ($status eq 'CLOSED') {
  373: 		    $msg.='The problem '.$accessmsg;
  374: 		} elsif ($status eq 'UNCHECKEDOUT') {
  375: 		    $msg.=&checkout_msg;
  376: 		}
  377: 		$result.=$msg.'<br />';
  378: 	    } elsif ($target eq 'tex') {
  379: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
  380: 		if ($status eq 'UNAVAILABLE') {
  381: 		    $result.='Unable to determine if this resource is open due to network problems. Please try again later.\vskip 0 mm ';
  382: 		} else {
  383: 		    $result.="Problem is not open to be viewed. It $accessmsg \\vskip 0 mm ";
  384: 		}
  385: 	    }
  386: 	} elsif ($target eq 'web') {
  387: 	    my $name= &get_resource_name($parstack,$safeeval);
  388: 	    if ($status eq 'CAN_ANSWER') {
  389: 		# create a page header and exit
  390: 		$result.="$head_tag_start<title>$name</title></head>
  391:               $body_tag_start \n $form_tag_start".	
  392: 		  '<input type="hidden" name="submitted" value="yes" />';
  393: 		if ($ENV{'request.state'} eq "construct") {
  394: 		    $result.= &problem_web_to_edit_header($rndseed);
  395: 		}
  396: 		# if we are viewing someone else preserve that info
  397: 		if (defined $ENV{'form.grade_symb'}) {
  398: 		    foreach my $field ('symb','courseid','domain','username') {
  399: 			$result .= '<input type="hidden" name="grade_'.$field.
  400: 			    '" value="'.$ENV{"form.grade_$field"}.'" />'."\n";
  401: 		    }
  402: 		}
  403: 	    } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER'
  404: 		     || $status eq 'CLOSED' || $status eq 'UNAVALAILABLE') {
  405: 		$result.=$head_tag_start.
  406: 		    "<title>$name</title></head>\n$body_tag_start\n";
  407: 	    }
  408: 	} elsif ($target eq 'tex') {
  409: 	    my $startminipage = '';
  410: 	    if ($ENV{'form.problem_split'} ne 'yes') {
  411: 		$startminipage = '\begin{minipage}{\textwidth}';
  412: 	    }
  413: 	    my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
  414: 	    if ($name eq '') {
  415: 		$name=&Apache::lonnet::EXT('resource.title');
  416: 		if ($name eq 'con_lost') { $name = ''; }
  417: 	    }
  418: 	    $Apache::lonhomework::name=$name;
  419: 	    my $id = $Apache::inputtags::part;
  420: 	    my $weight = &Apache::lonnet::EXT("resource.$id.weight");
  421: 	    my $allkeys=&Apache::lonnet::metadata($ENV{'request.uri'},'keys');
  422: 	    my @allkeys = split /,/,$allkeys;
  423: 	    my $allow_print_points = 0;
  424: 	    foreach my $partial_key (@allkeys) {
  425: 		if ($partial_key=~m/weight/) {
  426: 		    $allow_print_points++;
  427: 		}
  428: 	    }
  429: 	    my $duedate = &Apache::lonnet::EXT("resource.$id.duedate"); 
  430: 	    $duedate = POSIX::strftime("%c",localtime($duedate));
  431: 	    my $temp_file;
  432: 	    my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.due";
  433: 	    if (-e $filename) {
  434: 		$temp_file = Apache::File->new($filename);
  435: 	    } else {
  436: 		$temp_file = Apache::File->new('>>'.$filename);
  437: 	    }
  438: 	    my @due_file_content = <$temp_file>;
  439: 	    my $due_file_content = $due_file_content[$#due_file_content];
  440: 	    chomp $due_file_content;
  441: 	    my $name_of_resourse= &get_resource_name($parstack,$safeeval);
  442: 	    if ($due_file_content ne $duedate) {
  443: 		$temp_file = Apache::File->new('>'.$filename);
  444: 		print $temp_file "$duedate\n";
  445: 		if (not $ENV{'request.symb'} =~ m/\.page_/) {
  446: 		    if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') {
  447: 			$result .= '\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource <h2>"'.$name_of_resourse.'"</h2> located in <br /><small><b>'.$ENV{'request.uri'}.'</b></small><br /> STAMPOFPASSEDRESOURCEEND} \noindent\textit{Due date: '.$duedate.'} \vskip 1 mm\noindent '.$startminipage;	
  448: 		    } else {
  449: 			$result .= '\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource <h2>"'.$name_of_resourse.'"</h2> located in <br /><small><b>'.$ENV{'request.uri'}.'</b></small><br /> STAMPOFPASSEDRESOURCEEND} \noindent \vskip 1 mm \noindent'.$startminipage;
  450: 			if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
  451: 		    }
  452: 		} else {
  453: 		    $result .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\';
  454: 		}
  455: 	    } else {
  456: 		if (not $ENV{'request.symb'} =~ m/\.page_/) {
  457: 		    $result .= '\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource <h2>"'.$name_of_resourse.'"</h2> located in <br /><small><b>'.$ENV{'request.uri'}.'</b></small><br /> STAMPOFPASSEDRESOURCEEND} \noindent \vskip 1 mm\noindent'.$startminipage;	
  458: 		    if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
  459: 		} else {
  460: 		    $result .= '\vskip 1mm \\\\\\\\';
  461: 		}
  462: 	    }
  463: 	}
  464:     } elsif ($target eq 'edit') {
  465: 	$result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
  466: 	    &problem_edit_header();
  467: 	my $temp=&Apache::edit::insertlist($target,$token);
  468: 	$result.=$temp;
  469:     } elsif ($target eq 'modified') {
  470: 	$result=$token->[4];
  471: 	$result.=&Apache::edit::handle_insert();
  472:     } else {
  473: 	# page_start returned a starting result, delete it if we don't need it
  474: 	$result = '';
  475:     }
  476:     return $result;
  477: }
  478: 
  479: sub end_problem {
  480:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  481:     my $result='';
  482:     my $status=$Apache::inputtags::status['-1'];
  483:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
  484: 	$target eq 'tex') {
  485: 	if ( $target eq 'grade' && $Apache::inputtags::part eq '0' &&
  486: 	     $status eq 'CAN_ANSWER' ) {
  487: 	    # if part is zero, no <part>s existed, so we need to the grading
  488: 	    &Apache::inputtags::grade;
  489: 	} elsif ( ($target eq 'web' || $target eq 'tex') &&
  490: 		  $Apache::inputtags::part eq '0' &&
  491: 		  $status ne 'UNCHECKEDOUT') {
  492: 	    # if part is zero, no <part>s existed, so we need show the current
  493: 	    # grading status
  494: 	    my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
  495: 	    $result.= $gradestatus;
  496: 	}
  497: 	if (
  498: 	    (($target eq 'web') && ($ENV{'request.state'} ne 'construct')) ||
  499: 	    ($target eq 'answer') || ($target eq 'tex')
  500: 	   ) {
  501: 	    if ($status eq 'CAN_ANSWER') {
  502: 		if ($target ne 'tex' &&
  503: 		    $ENV{'form.answer_output_mode'} ne 'tex') {
  504: 		    $result.="</form></body>\n";
  505: 		}
  506: 	    } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER' ||
  507: 		     $status eq 'UNCHECKEDOUT' ) {
  508: 		if ($target ne 'tex') {
  509: 		    $result.="</body>\n";
  510: 		}
  511: 	    }
  512: 	    if ($target eq 'web') {
  513: 		$result.=&Apache::lonxml::xmlend();
  514: 	    } elsif ($target eq 'tex') {
  515: 		my $endminipage = '';
  516: 		if ($ENV{'form.problem_split'} ne 'yes') {
  517: 		    $endminipage = '\end{minipage}';
  518: 		}
  519: 		$result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
  520: 		if (not $ENV{'request.symb'} =~ m/\.page_/) {
  521: 		    $result .= $endminipage.'\end{document} ';
  522: 		} else {
  523: 		    $result .= '';
  524: 		}
  525: 	    }
  526: 	}
  527: 	if ($target eq 'grade') {
  528: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
  529: 	    &finalize_storage();
  530: 	}
  531: 	if ($target eq 'answer' && ($ENV{'request.state'} eq 'construct')
  532: 	    && $ENV{'form.answer_output_mode'} ne 'tex') {
  533: 	    $result.='</html>'; # normally we get it from xmlend, but in CSTR
  534: 	                        # we always show answer mode too.
  535: 	}
  536:     } elsif ($target eq 'meta') {
  537: 	if ($Apache::inputtags::part eq '0') {
  538: 	    @Apache::inputtags::response=();
  539: 	    $result=&Apache::response::mandatory_part_meta;
  540: 	}
  541:     } elsif ($target eq 'edit') {
  542: 	&Apache::lonxml::debug("in end_problem with $target, edit");
  543: 	$result = &problem_edit_footer();
  544:     }
  545: 
  546:     if ($ENV{'request.state'} eq 'construct' && $target eq 'web') {
  547: 	&Apache::inputtags::check_for_duplicate_ids();
  548:     }
  549:     undef(%Apache::lonhomework::history);
  550:     undef(%Apache::lonhomework::results);
  551:     undef($Apache::inputtags::part);
  552:     undef($Apache::lonhomework::parsing_a_problem);
  553: 
  554:     return $result;
  555: }
  556: 
  557: 
  558: sub start_library {
  559:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  560:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start);
  561: 
  562:     if ($target eq 'edit') {
  563: 	($result,$head_tag_start,$body_tag_start,$form_tag_start)=
  564: 	    &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
  565: 	$result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
  566: 	    &problem_edit_header();
  567: 	my $temp=&Apache::edit::insertlist($target,$token);
  568: 	$result.=$temp;
  569:     } elsif ($target eq 'modified') {
  570: 	$result=$token->[4];
  571: 	$result.=&Apache::edit::handle_insert();
  572:     } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
  573: 	     $ENV{'request.state'} eq "construct" ) {
  574: 	($result,$head_tag_start,$body_tag_start,$form_tag_start)=
  575: 	    &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
  576: 	my $name=&get_resource_name($parstack,$safeeval);
  577: 	my $rndseed=&setup_rndseed($safeeval);
  578: 	$result.="$head_tag_start<title>$name</title></head>
  579:               $body_tag_start \n $form_tag_start".	
  580: 		  '<input type="hidden" name="submitted" value="yes" />';
  581: 	$result.=&problem_web_to_edit_header($rndseed);
  582:     }
  583:     return $result;
  584: }
  585: 
  586: sub end_library {
  587:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  588:     my $result='';
  589:     if ($target eq 'edit') {
  590: 	$result=&problem_edit_footer();
  591:     } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
  592: 	     $ENV{'request.state'} eq "construct") {
  593: 	$result.='</form></body>'.&Apache::lonxml::xmlend();
  594:     }
  595:     return $result;
  596: }
  597: 
  598: sub start_block {
  599:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  600: 
  601:     my $result;
  602: 
  603:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  604: 	$target eq 'tex' || $target eq 'analyze') {
  605: 	my $code = $token->[2]->{'condition'};
  606: 	if ($code) {
  607: 	    if (!$Apache::lonxml::default_homework_loaded) {
  608: 		&Apache::lonxml::default_homework_load($safeeval);
  609: 	    }
  610: 	    $result = &Apache::run::run($code,$safeeval);
  611: 	    &Apache::lonxml::debug("block :$code: returned :$result:");
  612: 	} else {
  613: 	    $result='1';
  614: 	}
  615: 	if ( ! $result ) {
  616: 	    my $skip=&Apache::lonxml::get_all_text("/block",$parser);
  617: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
  618: 	}
  619: 	$result='';
  620:     } elsif ($target eq 'edit') {
  621: 	$result .=&Apache::edit::tag_start($target,$token);
  622: 	$result .=&Apache::edit::text_arg('Test Condition:','condition',
  623: 					  $token,40);
  624: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  625:     } elsif ($target eq 'modified') {
  626: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  627: 						     $safeeval,'condition');
  628: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  629:     }
  630:     return $result;
  631: }
  632: 
  633: sub end_block {
  634:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  635:     my $result;
  636:     if ($target eq "edit") {
  637: 	$result.= &Apache::edit::tag_end($target,$token,'');
  638:     }
  639:     return $result;
  640: }
  641: 
  642: sub start_languageblock {
  643:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  644: 
  645:     my $result;
  646: 
  647:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  648: 	$target eq 'tex' || $target eq 'analyze') {
  649: 	my $include = $token->[2]->{'include'};
  650: 	my $exclude = $token->[2]->{'exclude'};
  651:         my %languages=&Apache::loncommon::display_languages();
  652:         $result='1';
  653: 	if ($include) {
  654:             $result='';
  655:             foreach (split(/\,/,$include)) {
  656:                 if ($languages{$_}) { $result='1'; }
  657:             }
  658: 	}
  659:         if ($exclude) {
  660:             foreach (split(/\,/,$exclude)) {
  661:                 if ($languages{$_}) { $result='0'; }
  662:             }
  663: 	}
  664: 	if ( ! $result ) {
  665: 	    my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser);
  666: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
  667: 	}
  668: 	$result='';
  669:     } elsif ($target eq 'edit') {
  670: 	$result .=&Apache::edit::tag_start($target,$token);
  671: 	$result .=&Apache::edit::text_arg('Include Language:','include',
  672: 					  $token,40);
  673: 	$result .=&Apache::edit::text_arg('Exclude Language:','exclude',
  674: 					  $token,40);
  675: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  676:     } elsif ($target eq 'modified') {
  677: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  678: 						     $safeeval,'include',
  679: 						     'exclude');
  680: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  681:     }
  682:     return $result;
  683: }
  684: 
  685: sub end_languageblock {
  686:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  687:     my $result;
  688:     if ($target eq "edit") {
  689: 	$result.= &Apache::edit::tag_end($target,$token,'');
  690:     }
  691:     return $result;
  692: }
  693: 
  694: sub start_instructorcomment {
  695:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  696: 
  697:     my $result;
  698: 
  699:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  700: 	$target eq 'tex' || $target eq 'analyze') {
  701:         $result=($ENV{'request.role'}=~/^(in|cc|au|ca|li)/);
  702: 	if ( ! $result ) {
  703: 	    my $skip=&Apache::lonxml::get_all_text("/instructorcomment",$parser);
  704: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
  705: 	}
  706: 	$result='';
  707:     } elsif ($target eq 'edit') {
  708: 	$result .=&Apache::edit::tag_start($target,$token);
  709: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  710:     }
  711:     return $result;
  712: }
  713: 
  714: sub end_instructorcomment {
  715:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  716:     my $result;
  717:     if ($target eq "edit") {
  718: 	$result.= &Apache::edit::tag_end($target,$token,'');
  719:     }
  720:     return $result;
  721: }
  722: 
  723: sub start_while {
  724:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  725: 
  726:     my $result;
  727:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  728: 	$target eq 'tex' || $target eq 'analyze') {
  729: 	my $code = $token->[2]->{'condition'};
  730: 
  731: 	push( @Apache::structuretags::whileconds, $code);
  732: 	if (!$Apache::lonxml::default_homework_loaded) {
  733: 	    &Apache::lonxml::default_homework_load($safeeval);
  734: 	}
  735: 	my $result = &Apache::run::run($code,$safeeval);
  736: 	my $bodytext=&Apache::lonxml::get_all_text("/while",$parser);
  737: 	push( @Apache::structuretags::whilebody, $bodytext);
  738: 	push( @Apache::structuretags::whileline, $token->[5]);
  739: 	&Apache::lonxml::debug("s code $code got -$result-");
  740: 	if ( $result ) {
  741: 	    &Apache::lonxml::newparser($parser,\$bodytext);
  742: 	}
  743:     } elsif ($target eq 'edit') {
  744: 	$result .=&Apache::edit::tag_start($target,$token);
  745: 	$result .=&Apache::edit::text_arg('Test Condition:','condition',
  746: 					  $token,40);
  747: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  748:     } elsif ($target eq 'modified') {
  749: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  750: 						     $safeeval,'condition');
  751: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  752:     }
  753:     return $result;
  754: }
  755: 
  756: sub end_while {
  757:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  758:     my $result;
  759: 
  760:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  761: 	$target eq 'tex' || $target eq 'analyze') {
  762: 	my $code = pop(@Apache::structuretags::whileconds);
  763: 	my $bodytext = pop(@Apache::structuretags::whilebody);
  764: 	my $line = pop(@Apache::structuretags::whileline);
  765: 	my $return = &Apache::run::run($code,$safeeval);
  766: 	my $starttime=time;
  767: 	my $error=0;
  768: 	while ($return) {
  769: 	    if (time-$starttime >
  770: 		$Apache::lonnet::perlvar{'lonScriptTimeout'}) {
  771: 		$return = 0; $error=1; next;
  772: 	    }
  773: 	    $result.=&Apache::scripttag::xmlparse($bodytext);
  774: 	    $return = &Apache::run::run($code,$safeeval);
  775: 	}
  776: 	if ($error) {
  777: 	    &Apache::lonxml::error('<pre>Code ran too long. It ran for more than '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' seconds occured while running &lt;while$gt; on line '.$line.'</pre>');
  778: 	}
  779:     } elsif ($target eq "edit") {
  780: 	$result.= &Apache::edit::tag_end($target,$token,'');
  781:     }
  782:     return $result;
  783: }
  784: 
  785: # <randomlist show="1">
  786: #  <tag1>..</tag1>
  787: #  <tag2>..</tag2>
  788: #  <tag3>..</tag3>
  789: #  ...
  790: # </randomlist>
  791: sub start_randomlist {
  792:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  793:     my $result;
  794:     if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' ||
  795: 	$target eq 'tex' || $target eq 'analyze') {
  796: 	my $body= &Apache::lonxml::get_all_text("/randomlist",$parser);
  797: 	my $b_parser= HTML::TokeParser->new(\$body);
  798: 	my $b_tok;
  799: 	my @randomlist;
  800: 	my $list_item;
  801: 	while($b_tok = $b_parser->get_token() ) {
  802: 	    if($b_tok->[0] eq 'S') { # start tag
  803: 		# get content of the tag until matching end tag
  804: 		# get all text upto the matching tag
  805: 		# and push the content into @randomlist
  806: 		$list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],
  807: 							   $b_parser);
  808: 		$list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
  809: 		push(@randomlist,$list_item);
  810: 		#  print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4],
  811:                 #         $list_item</b>";
  812: 	    }
  813: 	    if($b_tok->[0] eq 'T') { # text
  814: 		# what to do with text in between tags?
  815: 		#  print "<b>TEXT $b_tok->[1]</b><br />";
  816: 	    }
  817: 	    # if($b_tok->[0] eq 'E') { # end tag, should not happen
  818: 	    #  print "<b>END-TAG $b_tok->[1]</b><br />";
  819: 	    # }
  820: 	}
  821: 	my @idx_arr = (0 .. $#randomlist);
  822: 	&Apache::structuretags::shuffle(\@idx_arr);
  823: 	my $bodytext = '';
  824: 	my $show=$#randomlist;
  825: 	my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
  826: 	$showarg--;
  827: 	if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
  828: 	for(0 .. $show) {
  829: 	    $bodytext .= "$randomlist[ $idx_arr[$_] ]";
  830: 	}
  831: 	&Apache::lonxml::newparser($parser,\$bodytext);
  832:     } elsif ($target eq 'edit' ) {
  833: 	$result .=&Apache::edit::tag_start($target,$token);
  834: 	$result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
  835: 					   $token,5);
  836: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  837:     } elsif ($target eq 'modified' ) {
  838: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  839: 						     $safeeval,'show');
  840: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
  841:     }
  842:     return $result;
  843: }
  844: 
  845: sub shuffle {
  846:     my $a=shift;
  847:     my $i;
  848:     if (defined(@$a)) {
  849: 	&Apache::response::setrandomnumber();
  850: 	for($i=@$a;--$i;) {
  851: 	    my $j=int(&Math::Random::random_uniform() * ($i+1));
  852: 	    next if $i == $j;
  853: 	    @$a[$i,$j] = @$a[$j,$i];
  854: 	}
  855:     }
  856: }
  857: 
  858: sub end_randomlist {
  859:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  860:     my $result;
  861:     if ($target eq 'edit' ) {
  862: 	$result=&Apache::edit::tag_end($target,$token,
  863: 				       'End Randomly Parsed Block');
  864:     }
  865:     return $result;
  866: }
  867: 
  868: sub start_part {
  869:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  870:     my $result='';
  871:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
  872:     if ($id eq '') { $id = $Apache::lonxml::curdepth; }
  873:     $Apache::inputtags::part=$id;
  874:     push(@Apache::inputtags::partlist,$id);
  875:     @Apache::inputtags::response=();
  876:     @Apache::inputtags::previous=();
  877:     @Apache::inputtags::previous_version=();
  878:     $Apache::lonhomework::problemstatus=
  879: 	&Apache::lonnet::EXT("resource.$id.problemstatus");
  880:     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
  881: 
  882:     if ($target eq 'meta') {
  883: 	return &Apache::response::mandatory_part_meta;
  884:     } elsif ($target eq 'web' || $target eq 'grade' ||
  885: 	     $target eq 'answer' || $target eq 'tex') {
  886: 	if ($hidden) {
  887: 	    my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
  888: 	} else {
  889: 	    my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
  890: 	    push (@Apache::inputtags::status,$status);
  891: 	    my $expression='$external::datestatus="'.$status.'";';
  892: 	    $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
  893: 	    &Apache::run::run($expression,$safeeval);
  894: 	    if ( $status eq 'CLOSED' ) {
  895: 		my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
  896: 		if ( $target eq "web" ) {
  897: 		    $result="<br />Part is not open to be viewed. It $accessmsg<br />";
  898: 		} elsif ( $target eq 'tex' ) {
  899: 		    $result="\\end{minipage}\\vskip 0 mm Part is not open to be viewed. It $accessmsg \\\\\\begin{minipage}{\\textwidth}";
  900: 		}
  901: 	    } else {
  902: 		if ($target eq 'tex') {
  903: 		    $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
  904: 		    my $weight = &Apache::lonnet::EXT("resource.$id.weight");
  905: 		    if ($Apache::lonhomework::type eq 'exam') { $result .= '\fbox{\textit{'.$weight.' pt}}';}
  906: 		}
  907: 	    }
  908: 	}
  909:     } elsif ($target eq 'edit') {
  910: 	$result.=&Apache::edit::tag_start($target,$token);
  911: 	$result.=&Apache::edit::text_arg('Part ID:','id',$token).
  912: 	    &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help").
  913: 		&Apache::edit::end_row().&Apache::edit::start_spanning_row();
  914:     } elsif ($target eq 'modified') {
  915: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  916: 						     $safeeval,'id');
  917: 	if ($constructtag) {
  918: 	    $result = &Apache::edit::rebuild_tag($token);
  919: 	    $result.=&Apache::edit::handle_insert();
  920: 	}
  921:     }
  922:     return $result;
  923: }
  924: 
  925: sub end_part {
  926:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  927:     &Apache::lonxml::debug("in end_part $target ");
  928:     my $status=$Apache::inputtags::status['-1'];
  929:     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
  930:     my $result='';
  931:     if ( $target eq 'meta' ) {
  932: 	$result='';
  933:     } elsif ( $target eq 'grade' && $status eq 'CAN_ANSWER' && !$hidden) {
  934: 	$result=&Apache::inputtags::grade;
  935:     } elsif (($target eq 'web' || $target eq 'tex') && !$hidden ) {
  936: 	my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
  937: 							$target);
  938: 	if ($Apache::lonhomework::type eq 'exam') {$gradestatus='';}
  939: 	$result=$gradestatus;
  940:     } elsif ($target eq 'edit') {
  941: 	$result=&Apache::edit::end_table();
  942:     }
  943:     pop @Apache::inputtags::status;
  944:     $Apache::inputtags::part='';
  945:     return $result;
  946: }
  947: 
  948: sub start_preduedate {
  949:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  950:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
  951: 	if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
  952: 	    $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER' &&
  953: 	    $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
  954: 	    &Apache::lonxml::get_all_text("/preduedate",$parser);
  955: 	}
  956:     }
  957:     return '';
  958: }
  959: 
  960: sub end_preduedate {
  961:     return '';
  962: }
  963: 
  964: sub start_postanswerdate {
  965:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  966:     if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
  967: 	if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
  968: 	    &Apache::lonxml::get_all_text("/postanswerdate",$parser);
  969: 	}
  970:     } elsif ($target eq 'tex') {
  971: 	return '\vskip 0 mm \noindent';
  972:     }
  973:     return '';
  974: }
  975: 
  976: sub end_postanswerdate {
  977:     return '';
  978: }
  979: 
  980: sub start_notsolved {
  981:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  982:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
  983: 	$target eq 'tex') {
  984: 	my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
  985: 	&Apache::lonxml::debug("not solved has :$gradestatus:");
  986: 	if ($gradestatus =~ /^correct/) {
  987: 	    &Apache::lonxml::debug("skipping");
  988: 	    &Apache::lonxml::get_all_text("/notsolved",$parser);
  989: 	}
  990:     }
  991:     return '';
  992: }
  993: 
  994: sub end_notsolved {
  995:     return '';
  996: }
  997: 
  998: sub start_solved {
  999:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1000:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
 1001: 	$target eq 'tex') {
 1002: 	my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
 1003: 	if ($gradestatus !~ /^correct/) {
 1004: 	    &Apache::lonxml::get_all_text("/solved",$parser);
 1005: 	}
 1006:     }
 1007:     return '';
 1008: }
 1009: 
 1010: sub end_solved {
 1011:     return '';
 1012: }
 1013: 
 1014: sub start_startouttext {
 1015:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1016:     my @result=(''.'');
 1017:     if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
 1018:     return (@result);
 1019: }
 1020: 
 1021: sub end_startouttext {
 1022:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1023:     my $result='';
 1024:     my $text='';
 1025: 
 1026:     if ($target eq 'edit') {
 1027: 	$text=&Apache::lonxml::get_all_text("endouttext",$parser);
 1028: 	$result.=&Apache::edit::start_table($token)."<tr><td>Text Block</td>
 1029: <td>Delete:".
 1030:                  &Apache::edit::deletelist($target,$token)
 1031: 		 ."</td>
 1032: <td>".
 1033:                  &Apache::edit::insertlist($target,$token).
 1034: 		 &Apache::edit::end_row().
 1035:                  &Apache::edit::start_spanning_row()."\n"
 1036: 		 .'<table><tr><td>'.
 1037: 		 &Apache::loncommon::help_open_topic("Greek_Symbols",
 1038: 						     'Greek Symbols',
 1039: 						     undef,undef,600)
 1040: 		 .'</td><td>'.
 1041: 		 &Apache::loncommon::help_open_topic("Other_Symbols",
 1042: 						     'Other Symbols',
 1043: 						     undef,undef,600)
 1044: 		 .'</td></tr></table>'.
 1045: 		 &Apache::edit::editfield($token->[1],$text,"",80,4);
 1046:     }
 1047:     if ($target eq 'modified') {
 1048: 	$text=&Apache::lonxml::get_all_text("endouttext",$parser);
 1049: 	$result='<startouttext />'.&Apache::edit::modifiedfield();
 1050:     }
 1051:     if ($target eq 'tex') {
 1052: 	$result .= '\noindent ';
 1053:     }
 1054:     return $result;
 1055: }
 1056: 
 1057: sub start_endouttext {
 1058:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1059:     my $result='';
 1060:     if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
 1061:     if ($target eq "modified") {
 1062: 	$result='<endouttext />'.
 1063: 	    &Apache::edit::handle_insertafter('startouttext'); }
 1064:     return $result;
 1065: }
 1066: 
 1067: sub end_endouttext {
 1068:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1069:     my @result=('','');
 1070:     if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
 1071:     return (@result);
 1072: }
 1073: 
 1074: sub delete_startouttext {
 1075:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 1076:     #  my $text=&Apache::lonxml::get_all_text("endouttext",$parser);
 1077:     my $text=$$parser['-1']->get_text("/endouttext");
 1078:     my $ntoken=$$parser['-1']->get_token();
 1079:     &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
 1080:     &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
 1081:     # Deleting 2 parallel tag pairs, but we need the numbers later to look like
 1082:     # they did the last time round
 1083:     &Apache::lonxml::increasedepth($ntoken);
 1084:     &Apache::lonxml::decreasedepth($ntoken);
 1085:     return 1;
 1086: }
 1087: 
 1088: 1;
 1089: __END__

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