File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.202: download - view: text, annotated - select for diffs
Wed Aug 13 15:25:59 2003 UTC (20 years, 8 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Changes to print table of contents for the
1. Sequence of problems;
2. Sequence of files (problems/html/xml/...);
3. Sequence of all problems from the course;
4. Subdirectory;
with exact indication of numbers of pages where particular problem is printed.

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

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