File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.199: download - view: text, annotated - select for diffs
Fri Jul 25 10:44:36 2003 UTC (20 years, 9 months ago) by www
Branches: MAIN
CVS tags: HEAD
Accessibility features work as advertised.

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

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