File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.189: download - view: text, annotated - select for diffs
Mon Jun 23 19:55:18 2003 UTC (20 years, 11 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Bug 1823 is fixed - </body> tag does not appear in TeX output anymore.

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

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