File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.208: download - view: text, annotated - select for diffs
Fri Sep 5 02:31:49 2003 UTC (20 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- BUG#2068, multiple problems in one file are not a good idea, and I was too tricky for my own good, now commenting my trickyness.

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

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