File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.198: download - view: text, annotated - select for diffs
Thu Jul 17 18:42:13 2003 UTC (20 years, 10 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Changes in <tex> tag to avoid parsing content between <tex> </tex> for tex target. That's neccessary to print Ed's problems.

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

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