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

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

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