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

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.174   ! sakharuk    4: # $Id: structuretags.pm,v 1.173 2003/05/14 16:49:13 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.170     www        41:     &Apache::lonxml::register('Apache::structuretags',('block','languageblock','instructorcomment','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') {
1.172     albertel  483: 		if ($target ne 'tex' &&
                    484: 		    $ENV{'form.answer_output_mode'} ne 'tex') {
                    485: 		    $result.="</form></body>\n";
1.159     albertel  486: 		}
                    487: 	    } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER' ||
                    488: 		     $status eq 'UNCHECKEDOUT' ) {
                    489: 		if ($target ne 'tex') {
                    490: 		    $result.="</body>\n";
                    491: 		}
                    492: 	    }
                    493: 	    if ($target eq 'web') {
                    494: 		$result.=&Apache::lonxml::xmlend();
                    495: 	    } elsif ($target eq 'tex') {
1.174   ! sakharuk  496: 		$result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
1.159     albertel  497: 		if (not $ENV{'request.symb'} =~ m/\.page_/) {
                    498: 		    $result .= '\end{minipage}\end{document} ';
                    499: 		} else {
                    500: 		    $result .= '';
                    501: 		}
                    502: 	    }
                    503: 	}
                    504: 	if ($target eq 'grade') {
                    505: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    506: 	    &finalize_storage();
                    507: 	}
1.172     albertel  508: 	if ($target eq 'answer' && ($ENV{'request.state'} eq 'construct')
1.173     albertel  509: 	    && $ENV{'form.answer_output_mode'} ne 'tex') {
1.172     albertel  510: 	    $result.='</html>'; # normally we get it from xmlend, but in CSTR
                    511: 	                        # we always show answer mode too.
1.159     albertel  512: 	}
                    513:     } elsif ($target eq 'meta') {
                    514: 	if ($Apache::inputtags::part eq '0') {
                    515: 	    $result=&Apache::response::mandatory_part_meta;
                    516: 	}
                    517:     } elsif ($target eq 'edit') {
                    518: 	&Apache::lonxml::debug("in end_problem with $target, edit");
                    519: 	$result = &problem_edit_footer();
                    520:     }
1.155     albertel  521: 
1.159     albertel  522:     undef(%Apache::lonhomework::history);
                    523:     undef(%Apache::lonhomework::results);
                    524:     undef($Apache::inputtags::part);
                    525:     undef($Apache::lonhomework::parsing_a_problem);
                    526: 
                    527:     return $result;
1.48      albertel  528: }
                    529: 
1.108     albertel  530: 
1.48      albertel  531: sub start_library {
1.159     albertel  532:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    533:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start);
1.109     albertel  534: 
1.159     albertel  535:     if ($target eq 'edit') {
                    536: 	($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    537: 	    &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
                    538: 	$result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
                    539: 	    &problem_edit_header();
                    540: 	my $temp=&Apache::edit::insertlist($target,$token);
                    541: 	$result.=$temp;
                    542:     } elsif ($target eq 'modified') {
                    543: 	$result=$token->[4];
                    544: 	$result.=&Apache::edit::handle_insert();
                    545:     } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
                    546: 	     $ENV{'request.state'} eq "construct" ) {
                    547: 	($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    548: 	    &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
                    549: 	my $name=&get_resource_name($parstack,$safeeval);
                    550: 	my $rndseed=&setup_rndseed($safeeval);
                    551: 	$result.="$head_tag_start<title>$name</title></head>
1.105     albertel  552:               $body_tag_start \n $form_tag_start".	
1.159     albertel  553: 		  '<input type="hidden" name="submitted" value="yes" />';
                    554: 	$result.=&problem_web_to_edit_header($rndseed);
                    555:     }
                    556:     return $result;
1.48      albertel  557: }
                    558: 
                    559: sub end_library {
1.159     albertel  560:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    561:     my $result='';
                    562:     if ($target eq 'edit') {
                    563: 	$result=&problem_edit_footer();
                    564:     } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
                    565: 	     $ENV{'request.state'} eq "construct") {
                    566: 	$result.='</form></body>'.&Apache::lonxml::xmlend();
                    567:     }
                    568:     return $result;
1.1       albertel  569: }
                    570: 
                    571: sub start_block {
1.131     albertel  572:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    573: 
                    574:     my $result;
1.1       albertel  575: 
1.160     albertel  576:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.131     albertel  577: 	$target eq 'tex' || $target eq 'analyze') {
1.159     albertel  578: 	my $code = $token->[2]->{'condition'};
1.131     albertel  579: 	if ($code) {
1.137     albertel  580: 	    if (!$Apache::lonxml::default_homework_loaded) {
                    581: 		&Apache::lonxml::default_homework_load($safeeval);
                    582: 	    }
1.131     albertel  583: 	    $result = &Apache::run::run($code,$safeeval);
                    584: 	    &Apache::lonxml::debug("block :$code: returned :$result:");
                    585: 	} else {
                    586: 	    $result='1';
                    587: 	}
                    588: 	if ( ! $result ) {
1.146     albertel  589: 	    my $skip=&Apache::lonxml::get_all_text("/block",$parser);
1.131     albertel  590: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
                    591: 	}
                    592: 	$result='';
                    593:     } elsif ($target eq 'edit') {
                    594: 	$result .=&Apache::edit::tag_start($target,$token);
                    595: 	$result .=&Apache::edit::text_arg('Test Condition:','condition',
                    596: 					  $token,40);
                    597: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    598:     } elsif ($target eq 'modified') {
                    599: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    600: 						     $safeeval,'condition');
                    601: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.38      albertel  602:     }
1.131     albertel  603:     return $result;
1.1       albertel  604: }
                    605: 
                    606: sub end_block {
1.167     www       607:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    608:     my $result;
                    609:     if ($target eq "edit") {
                    610: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    611:     }
                    612:     return $result;
                    613: }
                    614: 
                    615: sub start_languageblock {
                    616:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    617: 
                    618:     my $result;
                    619: 
                    620:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    621: 	$target eq 'tex' || $target eq 'analyze') {
                    622: 	my $include = $token->[2]->{'include'};
                    623: 	my $exclude = $token->[2]->{'exclude'};
                    624:         my %languages=&Apache::loncommon::display_languages();
                    625:         $result='1';
                    626: 	if ($include) {
                    627:             $result='';
                    628:             foreach (split(/\,/,$include)) {
                    629:                 if ($languages{$_}) { $result='1'; }
                    630:             }
                    631: 	}
                    632:         if ($exclude) {
                    633:             foreach (split(/\,/,$exclude)) {
                    634:                 if ($languages{$_}) { $result='0'; }
                    635:             }
                    636: 	}
                    637: 	if ( ! $result ) {
                    638: 	    my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser);
                    639: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
                    640: 	}
                    641: 	$result='';
                    642:     } elsif ($target eq 'edit') {
                    643: 	$result .=&Apache::edit::tag_start($target,$token);
                    644: 	$result .=&Apache::edit::text_arg('Include Language:','include',
                    645: 					  $token,40);
                    646: 	$result .=&Apache::edit::text_arg('Exclude Language:','exclude',
                    647: 					  $token,40);
                    648: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    649:     } elsif ($target eq 'modified') {
                    650: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.168     albertel  651: 						     $safeeval,'include',
                    652: 						     'exclude');
1.167     www       653: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    654:     }
                    655:     return $result;
                    656: }
                    657: 
                    658: sub end_languageblock {
1.170     www       659:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    660:     my $result;
                    661:     if ($target eq "edit") {
                    662: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    663:     }
                    664:     return $result;
                    665: }
                    666: 
                    667: sub start_instructorcomment {
                    668:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    669: 
                    670:     my $result;
                    671: 
                    672:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    673: 	$target eq 'tex' || $target eq 'analyze') {
                    674:         $result=($ENV{'request.role'}=~/^(in|cc|au|ca|li)/);
                    675: 	if ( ! $result ) {
                    676: 	    my $skip=&Apache::lonxml::get_all_text("/instructorcomment",$parser);
                    677: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
                    678: 	}
                    679: 	$result='';
                    680:     } elsif ($target eq 'edit') {
                    681: 	$result .=&Apache::edit::tag_start($target,$token);
                    682: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    683:     }
                    684:     return $result;
                    685: }
                    686: 
                    687: sub end_instructorcomment {
1.159     albertel  688:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160     albertel  689:     my $result;
                    690:     if ($target eq "edit") {
                    691: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    692:     }
                    693:     return $result;
1.4       tsai      694: }
                    695: 
                    696: sub start_while {
1.159     albertel  697:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    698: 
1.160     albertel  699:     my $result;
1.161     albertel  700:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.160     albertel  701: 	$target eq 'tex' || $target eq 'analyze') {
                    702: 	my $code = $token->[2]->{'condition'};
1.4       tsai      703: 
1.160     albertel  704: 	push( @Apache::structuretags::whileconds, $code);
                    705: 	if (!$Apache::lonxml::default_homework_loaded) {
                    706: 	    &Apache::lonxml::default_homework_load($safeeval);
                    707: 	}
                    708: 	my $result = &Apache::run::run($code,$safeeval);
1.161     albertel  709: 	my $bodytext=&Apache::lonxml::get_all_text("/while",$parser);
1.160     albertel  710: 	push( @Apache::structuretags::whilebody, $bodytext);
1.161     albertel  711: 	push( @Apache::structuretags::whileline, $token->[5]);
                    712: 	&Apache::lonxml::debug("s code $code got -$result-");
1.160     albertel  713: 	if ( $result ) {
                    714: 	    &Apache::lonxml::newparser($parser,\$bodytext);
                    715: 	}
                    716:     } elsif ($target eq 'edit') {
                    717: 	$result .=&Apache::edit::tag_start($target,$token);
                    718: 	$result .=&Apache::edit::text_arg('Test Condition:','condition',
                    719: 					  $token,40);
                    720: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    721:     } elsif ($target eq 'modified') {
                    722: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    723: 						     $safeeval,'condition');
                    724: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.159     albertel  725:     }
1.160     albertel  726:     return $result;
1.4       tsai      727: }
                    728: 
                    729: sub end_while {
1.159     albertel  730:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160     albertel  731:     my $result;
                    732: 
                    733:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    734: 	$target eq 'tex' || $target eq 'analyze') {
                    735: 	my $code = pop(@Apache::structuretags::whileconds);
                    736: 	my $bodytext = pop(@Apache::structuretags::whilebody);
1.161     albertel  737: 	my $line = pop(@Apache::structuretags::whileline);
                    738: 	my $return = &Apache::run::run($code,$safeeval);
                    739: 	my $starttime=time;
                    740: 	my $error=0;
                    741: 	while ($return) {
                    742: 	    if (time-$starttime >
                    743: 		$Apache::lonnet::perlvar{'lonScriptTimeout'}) {
                    744: 		$return = 0; $error=1; next;
                    745: 	    }
                    746: 	    $result.=&Apache::scripttag::xmlparse($bodytext);
                    747: 	    $return = &Apache::run::run($code,$safeeval);
                    748: 	}
                    749: 	if ($error) {
                    750: 	    &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  751: 	}
                    752:     } elsif ($target eq "edit") {
                    753: 	$result.= &Apache::edit::tag_end($target,$token,'');
1.159     albertel  754:     }
1.160     albertel  755:     return $result;
1.1       albertel  756: }
1.6       tsai      757: 
1.160     albertel  758: # <randomlist show="1">
1.6       tsai      759: #  <tag1>..</tag1>
                    760: #  <tag2>..</tag2>
                    761: #  <tag3>..</tag3>
1.160     albertel  762: #  ...
1.6       tsai      763: # </randomlist>
                    764: sub start_randomlist {
1.159     albertel  765:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    766:     my $result;
                    767:     if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' ||
                    768: 	$target eq 'tex' || $target eq 'analyze') {
                    769: 	my $body= &Apache::lonxml::get_all_text("/randomlist",$parser);
                    770: 	my $b_parser= HTML::TokeParser->new(\$body);
                    771: 	my $b_tok;
                    772: 	my @randomlist;
                    773: 	my $list_item;
                    774: 	while($b_tok = $b_parser->get_token() ) {
                    775: 	    if($b_tok->[0] eq 'S') { # start tag
                    776: 		# get content of the tag until matching end tag
                    777: 		# get all text upto the matching tag
                    778: 		# and push the content into @randomlist
                    779: 		$list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],
                    780: 							   $b_parser);
                    781: 		$list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
                    782: 		push(@randomlist,$list_item);
                    783: 		#  print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4],
                    784:                 #         $list_item</b>";
                    785: 	    }
                    786: 	    if($b_tok->[0] eq 'T') { # text
                    787: 		# what to do with text in between tags?
                    788: 		#  print "<b>TEXT $b_tok->[1]</b><br />";
                    789: 	    }
                    790: 	    # if($b_tok->[0] eq 'E') { # end tag, should not happen
                    791: 	    #  print "<b>END-TAG $b_tok->[1]</b><br />";
                    792: 	    # }
                    793: 	}
                    794: 	my @idx_arr = (0 .. $#randomlist);
                    795: 	&Apache::structuretags::shuffle(\@idx_arr);
                    796: 	my $bodytext = '';
                    797: 	my $show=$#randomlist;
                    798: 	my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
                    799: 	$showarg--;
                    800: 	if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
                    801: 	for(0 .. $show) {
                    802: 	    $bodytext .= "$randomlist[ $idx_arr[$_] ]";
                    803: 	}
                    804: 	&Apache::lonxml::newparser($parser,\$bodytext);
                    805:     } elsif ($target eq 'edit' ) {
                    806: 	$result .=&Apache::edit::tag_start($target,$token);
                    807: 	$result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
                    808: 					   $token,5);
                    809: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    810:     } elsif ($target eq 'modified' ) {
                    811: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    812: 						     $safeeval,'show');
                    813: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    814:     }
                    815:     return $result;
1.7       tsai      816: }
                    817: 
                    818: sub shuffle {
                    819:     my $a=shift;
                    820:     my $i;
1.70      albertel  821:     if (defined(@$a)) {
1.159     albertel  822: 	&Apache::response::setrandomnumber();
                    823: 	for($i=@$a;--$i;) {
                    824: 	    my $j=int(&Math::Random::random_uniform() * ($i+1));
                    825: 	    next if $i == $j;
                    826: 	    @$a[$i,$j] = @$a[$j,$i];
                    827: 	}
1.7       tsai      828:     }
1.6       tsai      829: }
                    830: 
                    831: sub end_randomlist {
1.159     albertel  832:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    833:     my $result;
                    834:     if ($target eq 'edit' ) {
                    835: 	$result=&Apache::edit::tag_end($target,$token,
                    836: 				       'End Randomly Parsed Block');
                    837:     }
                    838:     return $result;
1.6       tsai      839: }
                    840: 
1.11      albertel  841: sub start_part {
1.159     albertel  842:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    843:     my $result='';
                    844:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
                    845:     if ($id eq '') { $id = $Apache::lonxml::curdepth; }
                    846:     $Apache::inputtags::part=$id;
                    847:     @Apache::inputtags::responselist = ();
                    848:     @Apache::inputtags::previous=();
                    849:     @Apache::inputtags::previous_version=();
1.169     albertel  850:     $Apache::lonhomework::problemstatus=
                    851: 	&Apache::lonnet::EXT("resource.$id.problemstatus");
1.159     albertel  852:     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
                    853: 
                    854:     if ($target eq 'meta') {
                    855: 	return &Apache::response::mandatory_part_meta;
                    856:     } elsif ($target eq 'web' || $target eq 'grade' ||
                    857: 	     $target eq 'answer' || $target eq 'tex') {
                    858: 	if ($hidden) {
                    859: 	    my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
                    860: 	} else {
                    861: 	    my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
                    862: 	    push (@Apache::inputtags::status,$status);
                    863: 	    my $expression='$external::datestatus="'.$status.'";';
                    864: 	    $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
                    865: 	    &Apache::run::run($expression,$safeeval);
                    866: 	    if ( $status eq 'CLOSED' ) {
                    867: 		my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
                    868: 		if ( $target eq "web" ) {
                    869: 		    $result="<br />Part is not open to be viewed. It $accessmsg<br />";
                    870: 		} elsif ( $target eq 'tex' ) {
                    871: 		    $result="\\end{minipage}\\vskip 0 mm Part is not open to be viewed. It $accessmsg \\\\\\begin{minipage}{\\textwidth}";
                    872: 		}
                    873: 	    } else {
                    874: 		if ($target eq 'tex') {
                    875: 		    $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
                    876: 		    my $weight = &Apache::lonnet::EXT("resource.$id.weight");
                    877: 		    if ($Apache::lonhomework::type eq 'exam') { $result .= '\fbox{\textit{'.$weight.' pt}}';}
                    878: 		}
                    879: 	    }
                    880: 	}
                    881:     } elsif ($target eq 'edit') {
                    882: 	$result.=&Apache::edit::tag_start($target,$token);
                    883: 	$result.=&Apache::edit::text_arg('Part ID:','id',$token).
                    884: 	    &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help").
                    885: 		&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    886:     } elsif ($target eq 'modified') {
                    887: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    888: 						     $safeeval,'id');
                    889: 	if ($constructtag) {
                    890: 	    $result = &Apache::edit::rebuild_tag($token);
                    891: 	    $result.=&Apache::edit::handle_insert();
                    892: 	}
                    893:     }
                    894:     return $result;
1.11      albertel  895: }
                    896: 
                    897: sub end_part {
1.159     albertel  898:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    899:     &Apache::lonxml::debug("in end_part $target ");
                    900:     my $status=$Apache::inputtags::status['-1'];
                    901:     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
                    902:     my $result='';
                    903:     if ( $target eq 'meta' ) {
                    904: 	$result='';
                    905:     } elsif ( $target eq 'grade' && $status eq 'CAN_ANSWER' && !$hidden) {
                    906: 	$result=&Apache::inputtags::grade;
                    907:     } elsif (($target eq 'web' || $target eq 'tex') && !$hidden ) {
                    908: 	my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
                    909: 							$target);
                    910: 	if ($Apache::lonhomework::type eq 'exam') {$gradestatus='';}
                    911: 	$result=$gradestatus;
                    912:     }
                    913:     pop @Apache::inputtags::status;
                    914:     $Apache::inputtags::part='';
                    915:     return $result;
1.11      albertel  916: }
1.1       albertel  917: 
1.25      albertel  918: sub start_preduedate {
1.159     albertel  919:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    920:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
                    921: 	if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
                    922: 	    $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER' &&
                    923: 	    $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
                    924: 	    &Apache::lonxml::get_all_text("/preduedate",$parser);
                    925: 	}
1.24      albertel  926:     }
1.159     albertel  927:     return '';
1.24      albertel  928: }
                    929: 
1.25      albertel  930: sub end_preduedate {
1.159     albertel  931:     return '';
1.24      albertel  932: }
                    933: 
1.25      albertel  934: sub start_postanswerdate {
1.159     albertel  935:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    936:     if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
                    937: 	if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
                    938: 	    &Apache::lonxml::get_all_text("/postanswerdate",$parser);
                    939: 	}
                    940:     } elsif ($target eq 'tex') {
                    941: 	return '\vskip 0 mm \noindent';
                    942:     }
                    943:     return '';
1.24      albertel  944: }
                    945: 
1.25      albertel  946: sub end_postanswerdate {
1.159     albertel  947:     return '';
1.24      albertel  948: }
                    949: 
1.25      albertel  950: sub start_notsolved {
1.159     albertel  951:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    952:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    953: 	$target eq 'tex') {
                    954: 	my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
                    955: 	&Apache::lonxml::debug("not solved has :$gradestatus:");
                    956: 	if ($gradestatus =~ /^correct/) {
                    957: 	    &Apache::lonxml::debug("skipping");
                    958: 	    &Apache::lonxml::get_all_text("/notsolved",$parser);
                    959: 	}
1.24      albertel  960:     }
1.159     albertel  961:     return '';
1.24      albertel  962: }
                    963: 
1.25      albertel  964: sub end_notsolved {
1.159     albertel  965:     return '';
1.24      albertel  966: }
                    967: 
                    968: sub start_solved {
1.159     albertel  969:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    970:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    971: 	$target eq 'tex') {
                    972: 	my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
                    973: 	if ($gradestatus !~ /^correct/) {
                    974: 	    &Apache::lonxml::get_all_text("/solved",$parser);
                    975: 	}
1.24      albertel  976:     }
1.159     albertel  977:     return '';
1.24      albertel  978: }
                    979: 
                    980: sub end_solved {
1.159     albertel  981:     return '';
1.24      albertel  982: }
1.34      albertel  983: 
                    984: sub start_startouttext {
1.159     albertel  985:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    986:     my @result=(''.'');
                    987:     if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
                    988:     return (@result);
1.34      albertel  989: }
1.159     albertel  990: 
1.34      albertel  991: sub end_startouttext {
1.159     albertel  992:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    993:     my $result='';
                    994:     my $text='';
                    995: 
                    996:     if ($target eq 'edit') {
                    997: 	$text=&Apache::lonxml::get_all_text("endouttext",$parser);
                    998: 	$result.=&Apache::edit::start_table($token)."<tr><td>Text Block</td>
1.42      albertel  999: <td>Delete:".
1.159     albertel 1000:                  &Apache::edit::deletelist($target,$token)
                   1001: 		 ."</td>
1.42      albertel 1002: <td>".
1.159     albertel 1003:                  &Apache::edit::insertlist($target,$token).
                   1004: 		 &Apache::edit::end_row().
                   1005:                  &Apache::edit::start_spanning_row()."\n"
                   1006: 		 .'<table><tr><td>'.
                   1007: 		 &Apache::loncommon::help_open_topic("Greek_Symbols",
                   1008: 						     'Greek Symbols',
                   1009: 						     undef,undef,600)
                   1010: 		 .'</td><td>'.
                   1011: 		 &Apache::loncommon::help_open_topic("Other_Symbols",
                   1012: 						     'Other Symbols',
                   1013: 						     undef,undef,600)
                   1014: 		 .'</td></tr></table>'.
                   1015: 		 &Apache::edit::editfield($token->[1],$text,"",80,4);
                   1016:     }
                   1017:     if ($target eq 'modified') {
                   1018: 	$text=&Apache::lonxml::get_all_text("endouttext",$parser);
                   1019: 	$result='<startouttext />'.&Apache::edit::modifiedfield();
                   1020:     }
                   1021:     if ($target eq 'tex') {
                   1022: 	$result .= '\noindent ';
                   1023:     }
                   1024:     return $result;
1.34      albertel 1025: }
1.159     albertel 1026: 
1.34      albertel 1027: sub start_endouttext {
1.159     albertel 1028:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1029:     my $result='';
                   1030:     if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
                   1031:     if ($target eq "modified") {
                   1032: 	$result='<endouttext />'.
                   1033: 	    &Apache::edit::handle_insertafter('startouttext'); }
                   1034:     return $result;
1.34      albertel 1035: }
1.159     albertel 1036: 
1.34      albertel 1037: sub end_endouttext {
1.159     albertel 1038:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1039:     my @result=('','');
                   1040:     if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
                   1041:     return (@result);
1.34      albertel 1042: }
1.159     albertel 1043: 
1.45      albertel 1044: sub delete_startouttext {
1.159     albertel 1045:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1046:     #  my $text=&Apache::lonxml::get_all_text("endouttext",$parser);
                   1047:     my $text=$$parser['-1']->get_text("/endouttext");
                   1048:     my $ntoken=$$parser['-1']->get_token();
                   1049:     &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
                   1050:     &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
                   1051:     # Deleting 2 parallel tag pairs, but we need the numbers later to look like
                   1052:     # they did the last time round
                   1053:     &Apache::lonxml::increasedepth($ntoken);
                   1054:     &Apache::lonxml::decreasedepth($ntoken);
                   1055:     return 1;
1.45      albertel 1056: }
1.34      albertel 1057: 
1.1       albertel 1058: 1;
                   1059: __END__

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