Annotation of loncom/homework/structuretags.pm, revision 1.164

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

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