File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.169: download - view: text, annotated - select for diffs
Fri May 9 22:24:05 2003 UTC (20 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- some of BUG#628, also needed for online exams, disable feedback to students about whether they are correct or not.

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

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