File:  [LON-CAPA] / loncom / homework / structuretags.pm
Revision 1.175: download - view: text, annotated - select for diffs
Thu May 15 21:44:23 2003 UTC (20 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
-integrates interface updates requested in BUG#1264

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

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