File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.217: download - view: text, annotated - select for diffs
Tue Oct 14 00:21:12 2003 UTC (20 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- BUG#2280 resources attempt to register whil in CSTR

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

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