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

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.170   ! www         4: # $Id: structuretags.pm,v 1.169 2003/05/09 22:24:05 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') {
                    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.170   ! www       657:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
        !           658:     my $result;
        !           659:     if ($target eq "edit") {
        !           660: 	$result.= &Apache::edit::tag_end($target,$token,'');
        !           661:     }
        !           662:     return $result;
        !           663: }
        !           664: 
        !           665: sub start_instructorcomment {
        !           666:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
        !           667: 
        !           668:     my $result;
        !           669: 
        !           670:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
        !           671: 	$target eq 'tex' || $target eq 'analyze') {
        !           672:         $result=($ENV{'request.role'}=~/^(in|cc|au|ca|li)/);
        !           673: 	if ( ! $result ) {
        !           674: 	    my $skip=&Apache::lonxml::get_all_text("/instructorcomment",$parser);
        !           675: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
        !           676: 	}
        !           677: 	$result='';
        !           678:     } elsif ($target eq 'edit') {
        !           679: 	$result .=&Apache::edit::tag_start($target,$token);
        !           680: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
        !           681:     }
        !           682:     return $result;
        !           683: }
        !           684: 
        !           685: sub end_instructorcomment {
1.159     albertel  686:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160     albertel  687:     my $result;
                    688:     if ($target eq "edit") {
                    689: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    690:     }
                    691:     return $result;
1.4       tsai      692: }
                    693: 
                    694: sub start_while {
1.159     albertel  695:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    696: 
1.160     albertel  697:     my $result;
1.161     albertel  698:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.160     albertel  699: 	$target eq 'tex' || $target eq 'analyze') {
                    700: 	my $code = $token->[2]->{'condition'};
1.4       tsai      701: 
1.160     albertel  702: 	push( @Apache::structuretags::whileconds, $code);
                    703: 	if (!$Apache::lonxml::default_homework_loaded) {
                    704: 	    &Apache::lonxml::default_homework_load($safeeval);
                    705: 	}
                    706: 	my $result = &Apache::run::run($code,$safeeval);
1.161     albertel  707: 	my $bodytext=&Apache::lonxml::get_all_text("/while",$parser);
1.160     albertel  708: 	push( @Apache::structuretags::whilebody, $bodytext);
1.161     albertel  709: 	push( @Apache::structuretags::whileline, $token->[5]);
                    710: 	&Apache::lonxml::debug("s code $code got -$result-");
1.160     albertel  711: 	if ( $result ) {
                    712: 	    &Apache::lonxml::newparser($parser,\$bodytext);
                    713: 	}
                    714:     } elsif ($target eq 'edit') {
                    715: 	$result .=&Apache::edit::tag_start($target,$token);
                    716: 	$result .=&Apache::edit::text_arg('Test Condition:','condition',
                    717: 					  $token,40);
                    718: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    719:     } elsif ($target eq 'modified') {
                    720: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    721: 						     $safeeval,'condition');
                    722: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.159     albertel  723:     }
1.160     albertel  724:     return $result;
1.4       tsai      725: }
                    726: 
                    727: sub end_while {
1.159     albertel  728:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160     albertel  729:     my $result;
                    730: 
                    731:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    732: 	$target eq 'tex' || $target eq 'analyze') {
                    733: 	my $code = pop(@Apache::structuretags::whileconds);
                    734: 	my $bodytext = pop(@Apache::structuretags::whilebody);
1.161     albertel  735: 	my $line = pop(@Apache::structuretags::whileline);
                    736: 	my $return = &Apache::run::run($code,$safeeval);
                    737: 	my $starttime=time;
                    738: 	my $error=0;
                    739: 	while ($return) {
                    740: 	    if (time-$starttime >
                    741: 		$Apache::lonnet::perlvar{'lonScriptTimeout'}) {
                    742: 		$return = 0; $error=1; next;
                    743: 	    }
                    744: 	    $result.=&Apache::scripttag::xmlparse($bodytext);
                    745: 	    $return = &Apache::run::run($code,$safeeval);
                    746: 	}
                    747: 	if ($error) {
                    748: 	    &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  749: 	}
                    750:     } elsif ($target eq "edit") {
                    751: 	$result.= &Apache::edit::tag_end($target,$token,'');
1.159     albertel  752:     }
1.160     albertel  753:     return $result;
1.1       albertel  754: }
1.6       tsai      755: 
1.160     albertel  756: # <randomlist show="1">
1.6       tsai      757: #  <tag1>..</tag1>
                    758: #  <tag2>..</tag2>
                    759: #  <tag3>..</tag3>
1.160     albertel  760: #  ...
1.6       tsai      761: # </randomlist>
                    762: sub start_randomlist {
1.159     albertel  763:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    764:     my $result;
                    765:     if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' ||
                    766: 	$target eq 'tex' || $target eq 'analyze') {
                    767: 	my $body= &Apache::lonxml::get_all_text("/randomlist",$parser);
                    768: 	my $b_parser= HTML::TokeParser->new(\$body);
                    769: 	my $b_tok;
                    770: 	my @randomlist;
                    771: 	my $list_item;
                    772: 	while($b_tok = $b_parser->get_token() ) {
                    773: 	    if($b_tok->[0] eq 'S') { # start tag
                    774: 		# get content of the tag until matching end tag
                    775: 		# get all text upto the matching tag
                    776: 		# and push the content into @randomlist
                    777: 		$list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],
                    778: 							   $b_parser);
                    779: 		$list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
                    780: 		push(@randomlist,$list_item);
                    781: 		#  print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4],
                    782:                 #         $list_item</b>";
                    783: 	    }
                    784: 	    if($b_tok->[0] eq 'T') { # text
                    785: 		# what to do with text in between tags?
                    786: 		#  print "<b>TEXT $b_tok->[1]</b><br />";
                    787: 	    }
                    788: 	    # if($b_tok->[0] eq 'E') { # end tag, should not happen
                    789: 	    #  print "<b>END-TAG $b_tok->[1]</b><br />";
                    790: 	    # }
                    791: 	}
                    792: 	my @idx_arr = (0 .. $#randomlist);
                    793: 	&Apache::structuretags::shuffle(\@idx_arr);
                    794: 	my $bodytext = '';
                    795: 	my $show=$#randomlist;
                    796: 	my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
                    797: 	$showarg--;
                    798: 	if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
                    799: 	for(0 .. $show) {
                    800: 	    $bodytext .= "$randomlist[ $idx_arr[$_] ]";
                    801: 	}
                    802: 	&Apache::lonxml::newparser($parser,\$bodytext);
                    803:     } elsif ($target eq 'edit' ) {
                    804: 	$result .=&Apache::edit::tag_start($target,$token);
                    805: 	$result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
                    806: 					   $token,5);
                    807: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    808:     } elsif ($target eq 'modified' ) {
                    809: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    810: 						     $safeeval,'show');
                    811: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    812:     }
                    813:     return $result;
1.7       tsai      814: }
                    815: 
                    816: sub shuffle {
                    817:     my $a=shift;
                    818:     my $i;
1.70      albertel  819:     if (defined(@$a)) {
1.159     albertel  820: 	&Apache::response::setrandomnumber();
                    821: 	for($i=@$a;--$i;) {
                    822: 	    my $j=int(&Math::Random::random_uniform() * ($i+1));
                    823: 	    next if $i == $j;
                    824: 	    @$a[$i,$j] = @$a[$j,$i];
                    825: 	}
1.7       tsai      826:     }
1.6       tsai      827: }
                    828: 
                    829: sub end_randomlist {
1.159     albertel  830:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    831:     my $result;
                    832:     if ($target eq 'edit' ) {
                    833: 	$result=&Apache::edit::tag_end($target,$token,
                    834: 				       'End Randomly Parsed Block');
                    835:     }
                    836:     return $result;
1.6       tsai      837: }
                    838: 
1.11      albertel  839: sub start_part {
1.159     albertel  840:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    841:     my $result='';
                    842:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
                    843:     if ($id eq '') { $id = $Apache::lonxml::curdepth; }
                    844:     $Apache::inputtags::part=$id;
                    845:     @Apache::inputtags::responselist = ();
                    846:     @Apache::inputtags::previous=();
                    847:     @Apache::inputtags::previous_version=();
1.169     albertel  848:     $Apache::lonhomework::problemstatus=
                    849: 	&Apache::lonnet::EXT("resource.$id.problemstatus");
1.159     albertel  850:     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
                    851: 
                    852:     if ($target eq 'meta') {
                    853: 	return &Apache::response::mandatory_part_meta;
                    854:     } elsif ($target eq 'web' || $target eq 'grade' ||
                    855: 	     $target eq 'answer' || $target eq 'tex') {
                    856: 	if ($hidden) {
                    857: 	    my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
                    858: 	} else {
                    859: 	    my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
                    860: 	    push (@Apache::inputtags::status,$status);
                    861: 	    my $expression='$external::datestatus="'.$status.'";';
                    862: 	    $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
                    863: 	    &Apache::run::run($expression,$safeeval);
                    864: 	    if ( $status eq 'CLOSED' ) {
                    865: 		my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
                    866: 		if ( $target eq "web" ) {
                    867: 		    $result="<br />Part is not open to be viewed. It $accessmsg<br />";
                    868: 		} elsif ( $target eq 'tex' ) {
                    869: 		    $result="\\end{minipage}\\vskip 0 mm Part is not open to be viewed. It $accessmsg \\\\\\begin{minipage}{\\textwidth}";
                    870: 		}
                    871: 	    } else {
                    872: 		if ($target eq 'tex') {
                    873: 		    $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
                    874: 		    my $weight = &Apache::lonnet::EXT("resource.$id.weight");
                    875: 		    if ($Apache::lonhomework::type eq 'exam') { $result .= '\fbox{\textit{'.$weight.' pt}}';}
                    876: 		}
                    877: 	    }
                    878: 	}
                    879:     } elsif ($target eq 'edit') {
                    880: 	$result.=&Apache::edit::tag_start($target,$token);
                    881: 	$result.=&Apache::edit::text_arg('Part ID:','id',$token).
                    882: 	    &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help").
                    883: 		&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    884:     } elsif ($target eq 'modified') {
                    885: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    886: 						     $safeeval,'id');
                    887: 	if ($constructtag) {
                    888: 	    $result = &Apache::edit::rebuild_tag($token);
                    889: 	    $result.=&Apache::edit::handle_insert();
                    890: 	}
                    891:     }
                    892:     return $result;
1.11      albertel  893: }
                    894: 
                    895: sub end_part {
1.159     albertel  896:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    897:     &Apache::lonxml::debug("in end_part $target ");
                    898:     my $status=$Apache::inputtags::status['-1'];
                    899:     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
                    900:     my $result='';
                    901:     if ( $target eq 'meta' ) {
                    902: 	$result='';
                    903:     } elsif ( $target eq 'grade' && $status eq 'CAN_ANSWER' && !$hidden) {
                    904: 	$result=&Apache::inputtags::grade;
                    905:     } elsif (($target eq 'web' || $target eq 'tex') && !$hidden ) {
                    906: 	my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
                    907: 							$target);
                    908: 	if ($Apache::lonhomework::type eq 'exam') {$gradestatus='';}
                    909: 	$result=$gradestatus;
                    910:     }
                    911:     pop @Apache::inputtags::status;
                    912:     $Apache::inputtags::part='';
                    913:     return $result;
1.11      albertel  914: }
1.1       albertel  915: 
1.25      albertel  916: sub start_preduedate {
1.159     albertel  917:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    918:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
                    919: 	if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
                    920: 	    $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER' &&
                    921: 	    $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
                    922: 	    &Apache::lonxml::get_all_text("/preduedate",$parser);
                    923: 	}
1.24      albertel  924:     }
1.159     albertel  925:     return '';
1.24      albertel  926: }
                    927: 
1.25      albertel  928: sub end_preduedate {
1.159     albertel  929:     return '';
1.24      albertel  930: }
                    931: 
1.25      albertel  932: sub start_postanswerdate {
1.159     albertel  933:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    934:     if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
                    935: 	if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
                    936: 	    &Apache::lonxml::get_all_text("/postanswerdate",$parser);
                    937: 	}
                    938:     } elsif ($target eq 'tex') {
                    939: 	return '\vskip 0 mm \noindent';
                    940:     }
                    941:     return '';
1.24      albertel  942: }
                    943: 
1.25      albertel  944: sub end_postanswerdate {
1.159     albertel  945:     return '';
1.24      albertel  946: }
                    947: 
1.25      albertel  948: sub start_notsolved {
1.159     albertel  949:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    950:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    951: 	$target eq 'tex') {
                    952: 	my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
                    953: 	&Apache::lonxml::debug("not solved has :$gradestatus:");
                    954: 	if ($gradestatus =~ /^correct/) {
                    955: 	    &Apache::lonxml::debug("skipping");
                    956: 	    &Apache::lonxml::get_all_text("/notsolved",$parser);
                    957: 	}
1.24      albertel  958:     }
1.159     albertel  959:     return '';
1.24      albertel  960: }
                    961: 
1.25      albertel  962: sub end_notsolved {
1.159     albertel  963:     return '';
1.24      albertel  964: }
                    965: 
                    966: sub start_solved {
1.159     albertel  967:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    968:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    969: 	$target eq 'tex') {
                    970: 	my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
                    971: 	if ($gradestatus !~ /^correct/) {
                    972: 	    &Apache::lonxml::get_all_text("/solved",$parser);
                    973: 	}
1.24      albertel  974:     }
1.159     albertel  975:     return '';
1.24      albertel  976: }
                    977: 
                    978: sub end_solved {
1.159     albertel  979:     return '';
1.24      albertel  980: }
1.34      albertel  981: 
                    982: sub start_startouttext {
1.159     albertel  983:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    984:     my @result=(''.'');
                    985:     if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
                    986:     return (@result);
1.34      albertel  987: }
1.159     albertel  988: 
1.34      albertel  989: sub end_startouttext {
1.159     albertel  990:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    991:     my $result='';
                    992:     my $text='';
                    993: 
                    994:     if ($target eq 'edit') {
                    995: 	$text=&Apache::lonxml::get_all_text("endouttext",$parser);
                    996: 	$result.=&Apache::edit::start_table($token)."<tr><td>Text Block</td>
1.42      albertel  997: <td>Delete:".
1.159     albertel  998:                  &Apache::edit::deletelist($target,$token)
                    999: 		 ."</td>
1.42      albertel 1000: <td>".
1.159     albertel 1001:                  &Apache::edit::insertlist($target,$token).
                   1002: 		 &Apache::edit::end_row().
                   1003:                  &Apache::edit::start_spanning_row()."\n"
                   1004: 		 .'<table><tr><td>'.
                   1005: 		 &Apache::loncommon::help_open_topic("Greek_Symbols",
                   1006: 						     'Greek Symbols',
                   1007: 						     undef,undef,600)
                   1008: 		 .'</td><td>'.
                   1009: 		 &Apache::loncommon::help_open_topic("Other_Symbols",
                   1010: 						     'Other Symbols',
                   1011: 						     undef,undef,600)
                   1012: 		 .'</td></tr></table>'.
                   1013: 		 &Apache::edit::editfield($token->[1],$text,"",80,4);
                   1014:     }
                   1015:     if ($target eq 'modified') {
                   1016: 	$text=&Apache::lonxml::get_all_text("endouttext",$parser);
                   1017: 	$result='<startouttext />'.&Apache::edit::modifiedfield();
                   1018:     }
                   1019:     if ($target eq 'tex') {
                   1020: 	$result .= '\noindent ';
                   1021:     }
                   1022:     return $result;
1.34      albertel 1023: }
1.159     albertel 1024: 
1.34      albertel 1025: sub start_endouttext {
1.159     albertel 1026:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1027:     my $result='';
                   1028:     if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
                   1029:     if ($target eq "modified") {
                   1030: 	$result='<endouttext />'.
                   1031: 	    &Apache::edit::handle_insertafter('startouttext'); }
                   1032:     return $result;
1.34      albertel 1033: }
1.159     albertel 1034: 
1.34      albertel 1035: sub end_endouttext {
1.159     albertel 1036:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1037:     my @result=('','');
                   1038:     if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
                   1039:     return (@result);
1.34      albertel 1040: }
1.159     albertel 1041: 
1.45      albertel 1042: sub delete_startouttext {
1.159     albertel 1043:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1044:     #  my $text=&Apache::lonxml::get_all_text("endouttext",$parser);
                   1045:     my $text=$$parser['-1']->get_text("/endouttext");
                   1046:     my $ntoken=$$parser['-1']->get_token();
                   1047:     &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
                   1048:     &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
                   1049:     # Deleting 2 parallel tag pairs, but we need the numbers later to look like
                   1050:     # they did the last time round
                   1051:     &Apache::lonxml::increasedepth($ntoken);
                   1052:     &Apache::lonxml::decreasedepth($ntoken);
                   1053:     return 1;
1.45      albertel 1054: }
1.34      albertel 1055: 
1.1       albertel 1056: 1;
                   1057: __END__

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