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

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.253   ! albertel    4: # $Id: structuretags.pm,v 1.252 2004/05/27 22:25:16 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.210     albertel   39: use Apache::lonlocal;
1.231     sakharuk   40: use Apache::lonxml;
1.1       albertel   41: 
1.78      harris41   42: BEGIN {
1.248     albertel   43:     &Apache::lonxml::register('Apache::structuretags',('block','languageblock','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startouttext','endouttext','simpleeditbutton','definetag'));
1.10      albertel   44: }
                     45: 
                     46: sub start_web {
1.159     albertel   47:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.200     albertel   48:     my $bodytext=&Apache::lonxml::get_all_text("/web",$parser);
                     49:     if ($target eq 'web') {
                     50: 	return $bodytext;
1.159     albertel   51:     }
                     52:     return '';
1.10      albertel   53: }
                     54: 
                     55: sub end_web {
1.44      ng         56:     return '';
1.10      albertel   57: }
                     58: 
                     59: sub start_tex {
1.159     albertel   60:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.198     sakharuk   61:     my $result='';
1.200     albertel   62:     my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser);
                     63:     if ($target eq 'tex') {
                     64: 	return $bodytext.' ';
1.159     albertel   65:     }
1.198     sakharuk   66:     return $result;;
1.10      albertel   67: }
                     68: 
                     69: sub end_tex {
1.44      ng         70:     return '';
1.9       albertel   71: }
                     72: 
1.48      albertel   73: sub page_start {
1.159     albertel   74:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                     75:     my %found;
1.207     albertel   76:     foreach my $taginside (@$tagstack) {
1.159     albertel   77: 	foreach my $taglookedfor ('html','body','form') {
                     78: 	    if ($taginside =~ /^$taglookedfor$/i) {$found{$taglookedfor} = 1;}
                     79: 	}
                     80:     }
                     81: 
                     82:     my $result;
                     83:     my $head_tag_start;
                     84:     if (!defined($found{'html'})) {
                     85: 	$result=&Apache::londefdef::start_html($target,$token,$tagstack,
                     86: 					       $parstack,$parser,$safeeval);
1.218     albertel   87: 	$head_tag_start='<head>'.&Apache::lonmenu::registerurl(undef,$target);
1.159     albertel   88:     }
                     89:     my $body_tag_start;
                     90:     if (!defined($found{'body'})) {
                     91: 	$body_tag_start='<body onLoad="'.&Apache::lonmenu::loadevents().'" '.
                     92: 	    'onUnload="'.&Apache::lonmenu::unloadevents().'" ';
                     93: 	my $background=&Apache::lonxml::get_param('background',$parstack,
                     94: 						  $safeeval);
1.199     www        95: 	if ($ENV{'browser.imagesuppress'} eq 'on') { $background=''; }
1.159     albertel   96: 	if ($background) {
                     97: 	    $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
                     98: 		$background;
                     99: 	    $body_tag_start.='background="'.$background.'" ';
                    100: 	} else {
                    101: 	    my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,
                    102: 						   $safeeval);
1.199     www       103: 	    if (($bgcolor) && ($ENV{'browser.blackwhite'} ne 'on')) {
1.159     albertel  104: 		$body_tag_start.='bgcolor="'.$bgcolor.'" ';
                    105: 	    } else {
                    106: 		$body_tag_start.='bgcolor="#ffffff"';
                    107: 	    }
1.199     www       108: 	}
                    109: 	if ($ENV{'browser.fontenhance'} eq 'on') {
                    110: 	    $body_tag_start.=' style="font-size: x-large;" ';
1.159     albertel  111: 	}
                    112: 	$body_tag_start.='>'.&Apache::lonmenu::menubuttons(undef,$target,1);
                    113: 	if ($target eq 'web' && $ENV{'request.state'} ne 'construct') {
1.165     albertel  114: 	    my ($symb,undef,undef,undef,$publicuser)=
                    115: 		&Apache::lonxml::whichuser();
                    116: 	    if ($symb eq '' && !$publicuser) {
1.159     albertel  117: 		my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference");
1.211     albertel  118: 		$help=&mt("Browsing resource, all submissions are temporary.")."<br />";
1.159     albertel  119: 		$body_tag_start.=$help;
                    120: 	    }
                    121: 	}
1.245     albertel  122: 	$body_tag_start.=&Apache::lonxml::message_location();
1.159     albertel  123:     }
                    124:     my $form_tag_start;
                    125:     if (!defined($found{'form'})) {
                    126: 	$form_tag_start='<form name="lonhomework" method="POST" action="'.
                    127: 	    $ENV{'request.uri'}.'">';
                    128:     }
                    129:     return ($result,$head_tag_start,$body_tag_start,$form_tag_start);
1.105     albertel  130: }
                    131: 
1.141     matthew   132: #use Time::HiRes();
1.105     albertel  133: sub get_resource_name {
1.159     albertel  134:     my ($parstack,$safeeval)=@_;
1.204     albertel  135:     if (defined($Apache::lonhomework::name)) {
                    136: 	return $Apache::lonhomework::name;
                    137:     }
1.159     albertel  138:     my $name=&Apache::lonnet::gettitle();
                    139:     if ($name eq '') {
                    140: 	$name=&Apache::lonnet::EXT('resource.title');
                    141: 	if ($name eq 'con_lost') { $name = ''; }
                    142:     }
1.204     albertel  143:     if ($name!~/\S+/) {
                    144: 	$name=$ENV{'request.uri'};
1.205     albertel  145: 	$name=~s-.*/([^/]+)$-$1-;
1.204     albertel  146:     }
1.159     albertel  147:     $Apache::lonhomework::name=$name;
                    148:     return $name;
1.105     albertel  149: }
                    150: 
                    151: sub setup_rndseed {
1.159     albertel  152:     my ($safeeval)=@_;
                    153:     my $rndseed;
1.162     albertel  154:     my ($symb)=&Apache::lonxml::whichuser();
1.247     albertel  155:     if ($ENV{'request.state'} eq "construct" || $symb eq '' ||
                    156:           $Apache::lonhomework::history{'resource.CODE'}) {
1.159     albertel  157: 	$rndseed=$ENV{'form.rndseed'};
                    158: 	if (!$rndseed) {
1.162     albertel  159: 	    $rndseed=$Apache::lonhomework::history{'rndseed'};
                    160: 	    if (!$rndseed) {
                    161: 		$rndseed=time;
                    162: 	    }
1.237     albertel  163: 	    $ENV{'form.rndseed'}=$rndseed;
1.162     albertel  164: 	}
1.210     albertel  165: 	if ($ENV{'form.resetdata'} eq &mt('New Problem Variation') ||
                    166: 	    $ENV{'form.newrandomization'} eq &mt('New Randomization')) {
1.190     albertel  167: 	    srand(time);
                    168: 	    $rndseed=int(rand(2100000000));
1.159     albertel  169: 	    $ENV{'form.rndseed'}=$rndseed;
1.180     albertel  170: 	    delete($ENV{'form.resetdata'});
                    171: 	    delete($ENV{'form.newrandomization'});
1.159     albertel  172: 	}
1.187     albertel  173: 	if (defined($rndseed) && $rndseed ne int($rndseed)) {
                    174: 	   $rndseed=join(',',&Math::Random::random_seed_from_phrase($rndseed));
                    175:         }
1.247     albertel  176:         if ($Apache::lonhomework::history{'resource.CODE'}) {
                    177: 	   $rndseed=&Apache::lonnet::rndseed();
                    178: 	}
1.221     albertel  179: 	if ($safeeval) {
                    180: 	    &Apache::lonxml::debug("Setting rndseed to $rndseed");
1.250     albertel  181: 	    &Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval);
1.221     albertel  182: 	}
1.159     albertel  183:     }
                    184:     return $rndseed;
1.105     albertel  185: }
                    186: 
                    187: sub problem_edit_header {
1.159     albertel  188:     return '<input type="hidden" name="submitted" value="edit" />
1.210     albertel  189:        <input type="hidden" name="problemmode" value="'.&mt('Edit').'" />
1.243     matthew   190:        <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />
                    191:        <input type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />
                    192:        <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" /> <hr />
                    193:        <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes and Edit').'" />
                    194:        <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" /><table><tr><td>'.
1.229     www       195:        &Apache::loncommon::help_open_topic('Problem_Editor_XML_Index',
                    196: 					   'Problem Editing Help').'</td><td>'.
                    197:        &Apache::loncommon::help_open_faq(5).
                    198:        &Apache::loncommon::help_open_bug('Authoring').'</td></tr></table>'.
1.228     www       199:        '<table border="0"><tr><td bgcolor="#DDDDDD">';
1.105     albertel  200: }
                    201: 
                    202: sub problem_edit_footer {
1.210     albertel  203:     return '</td></tr></table><br /><input type="submit" name="submit" value="'.&mt('Submit Changes and Edit').'" />
                    204:     <input type="submit" name="submit" value="'.&mt('Submit Changes and View').'" />';
1.105     albertel  205: }
                    206: 
1.235     albertel  207: sub option {
                    208:     my ($value,$name) = @_;
                    209:     my $result ="<option value='".$value."' ";
                    210:     if ($ENV{'form.'.$name} eq $value) {
                    211: 	$result.=" selected='on' ";
                    212:     }
                    213:     $result.='>';
                    214:     return $result;
                    215: }
                    216: 
1.105     albertel  217: sub problem_web_to_edit_header {
1.159     albertel  218:     my ($rndseed)=@_;
1.210     albertel  219:     my $result.='<input type="hidden" name="problemmode" value="'.&mt('View').'" />
1.243     matthew   220:              <input type="submit" name="problemmode" accesskey="e" value="'.&mt('Edit').'" />
                    221:              <input type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />
                    222:              <input type="submit" name="newrandomization" accesskey="a" value="'.&mt('New Randomization').'" />
                    223:              <input type="submit" name="resetdata" accesskey="r" value="'.&mt('Reset Submissions').'" />
1.210     albertel  224:              <nobr><input type="submit" name="changerandseed" value="'.&mt('Change Random Seed To:').'" />
1.175     albertel  225:               <input type="text" name="rndseed" width="10" value="'.
                    226: 	       $rndseed.'"
                    227:            onChange="javascript:document.lonhomework.changerandseed.click()" /></nobr>
1.105     albertel  228:              <input type="checkbox" name="showallfoils" ';
1.159     albertel  229:     if (defined($ENV{'form.showallfoils'})) { $result.='checked="on"'; }
1.228     www       230:     $result.= ' />'.&mt('&nbsp;Show&nbsp;All&nbsp;Foils').
                    231: 	&Apache::loncommon::help_open_topic('Problem_Editor_Testing_Area','Testing Problems').
                    232: 	'<hr />';
1.235     albertel  233:     $result.="
                    234: <nobr>
                    235: Problem Status:
                    236: <select name='problemstate'>
                    237:   <option name=''></option>
                    238:   ".&option('CLOSED'               ,'problemstate').&mt("Closed")."</option>
                    239:   ".&option('CAN_ANSWER'           ,'problemstate').&mt("Answerable")."</option>
                    240:   ".&option('CANNOT_ANSWER_tries'  ,'problemstate').&mt("Open with full tries")."</option>
                    241:   ".&option('CANNOT_ANSWER_correct','problemstate').&mt("Open and correct")."</option>
                    242:   ".&option('SHOW_ANSWER'          ,'problemstate').&mt("Show Answer")."</option>
                    243: </select>
                    244: </nobr>
                    245: <nobr>
                    246: Problem Type:
                    247: <select name='problemtype'>
                    248:   <option name=''></option>
1.242     albertel  249:   ".&option('exam'   ,'problemtype').&mt("Exam Problem")."</option>
                    250:   ".&option('problem','problemtype').&mt("Homework problem")."</option>
                    251:   ".&option('survey' ,'problemtype').&mt("Survey Question")."</option>
1.235     albertel  252: </select>
                    253: </nobr>
                    254: <nobr>
                    255: Feedback Mode:
                    256: <select name='problemstatus'>
                    257:   <option value=''></option>
1.242     albertel  258:   ".&option('yes','problemstatus').&mt("Show Feedback")."</option>
                    259:   ".&option('no', 'problemstatus').&mt("Don't Show Feedback")."</option>
1.235     albertel  260: </select>
                    261: </nobr>
1.242     albertel  262: <input type='submit' name='changeproblemmode' value='".&mt("Change")."' />
1.235     albertel  263: <hr />";
1.159     albertel  264:     my $numtoanalyze=$ENV{'form.numtoanalyze'};
1.176     albertel  265:     if (!$numtoanalyze) { $numtoanalyze=20; }
1.210     albertel  266:     $result.= '<input type="submit" name="problemmode" value='.
                    267: 	&mt('"Calculate answers').'" /> for
1.136     albertel  268:              <input type="text" name="numtoanalyze" value="'.
1.210     albertel  269: 	     $numtoanalyze.'" size="5" /> '.&mt('versions of this problem').
                    270: 	     '.'.&Apache::loncommon::help_open_topic("Analyze_Problem",
1.176     albertel  271: 						     '',undef,undef,300).
1.210     albertel  272: 						     '<hr />';
1.159     albertel  273:     return $result;
1.48      albertel  274: }
                    275: 
1.65      albertel  276: sub initialize_storage {
1.159     albertel  277:     %Apache::lonhomework::results=();
1.162     albertel  278:     %Apache::lonhomework::history=();
1.159     albertel  279:     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
1.162     albertel  280:     if ($ENV{'request.state'} eq 'construct' || $symb eq '') {
1.159     albertel  281: 	%Apache::lonhomework::history=
                    282: 	    &Apache::lonnet::tmprestore($ENV{'request.uri'},'',$domain,$name);
                    283: 	my ($temp)=keys %Apache::lonhomework::history ;
                    284: 	&Apache::lonxml::debug("Return message of $temp");
                    285:     } else {
                    286: 	%Apache::lonhomework::history=
                    287: 	    &Apache::lonnet::restore($symb,$courseid,$domain,$name);
                    288:     }
                    289:     #ignore error conditions
1.67      albertel  290:     my ($temp)=keys %Apache::lonhomework::history ;
1.159     albertel  291:     if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
1.65      albertel  292: }
                    293: 
                    294: # -------------------------------------------------------------finalize_storage
                    295: # Stores away the result has to a student's environment
                    296: # checks form.grade_ for specific values, other wises stores
                    297: # to the running users environment
                    298: sub finalize_storage {
1.159     albertel  299:     my $result;
                    300:     my ($temp) = keys %Apache::lonhomework::results;
                    301:     if ( $temp ne '' ) {
                    302: 	my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
1.162     albertel  303: 	if ($ENV{'request.state'} eq 'construct' || $symb eq '') {
                    304: 	    $Apache::lonhomework::results{'rndseed'}=$ENV{'form.rndseed'};
1.159     albertel  305: 	    $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,
                    306: 					$ENV{'request.uri'},'',$domain,$name);
                    307: 	    &Apache::lonxml::debug('Construct Store return message:'.$result);
                    308: 	} else {
                    309: 	    $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
                    310: 					    $symb,$courseid,$domain,$name);
                    311: 	    &Apache::lonxml::debug('Store return message:'.$result);
                    312: 	}
1.67      albertel  313:     }
1.159     albertel  314:     return $result;
1.65      albertel  315: }
                    316: 
                    317: sub checkout_msg {
1.211     albertel  318:     my %lt=&Apache::lonlocal::texthash( 
                    319: 		'resource'=>'The resource needs to be checked out',
                    320: 		'id_expln'=>'As a resource gets checked out, a unique timestamped ID is given to it, and a permanent record is left in the system.',
                    321:                 'warning'=>'Checking out resources is subject to course policies, and may exclude future credit even if done erroneously.',
                    322:                 'checkout'=>'Check out Exam for Viewing',
                    323: 		'checkout?'=>'Check out Exam?');
1.159     albertel  324:     return (<<ENDCHECKOUT);
1.211     albertel  325: <h2>$lt{'resource'}</h2>
                    326:     <p>$lt{'id_expln'}</p>
                    327: <font color="red">
                    328: <p>$lt{'warning'}</p>
1.91      albertel  329: </font>
                    330: <form name="checkout" method="POST" action="$ENV{'request.uri'}">
                    331: <input type="hidden" name="doescheckout" value="yes" />
1.211     albertel  332: <input type="button" name="checkoutbutton" value="$lt{'checkout'}" onClick="javascript:if (confirm('$lt{'checkout?'}')) { document.checkout.submit(); }" />
1.65      albertel  333: </form>
                    334: ENDCHECKOUT
                    335: }
                    336: 
1.252     albertel  337: sub firstaccess_msg {
1.253   ! albertel  338:     my ($time,$symb)=@_;
        !           339:     my ($map)=&Apache::lonnet::decode_symb($symb);
        !           340:     my $foldertitle=&Apache::lonnet::gettitle($map);
        !           341:     &Apache::lonxml::debug("map is $map title is $foldertitle");
1.252     albertel  342:     return (<<ENDCHECKOUT);
1.253   ! albertel  343: <h2>The resources in "$foldertitle" are open for a limited time. Once you click the 'Show Resource' button below you have $time to complete all resources "$foldertitle".</h2>
1.252     albertel  344: <form name="markaccess" method="POST" action="$ENV{'request.uri'}">
                    345: <input type="hidden" name="markaccess" value="yes" />
                    346: <input type="button" name="accessbutton" value="Show Resource" onClick="javascript:if (confirm('Start Timer?')) { document.markaccess.submit(); }" />
                    347: </form>
                    348: ENDCHECKOUT
                    349: }
                    350: 
1.204     albertel  351: sub init_problem_globals {
                    352:     my ($type)=@_;
                    353:     #initialize globals
                    354:     if ($type eq 'problem') {
                    355: 	$Apache::inputtags::part='0';
                    356: 	@Apache::inputtags::partlist=('0');
1.241     albertel  357: 
                    358: 	$Apache::lonhomework::problemstatus=&get_problem_status('0')
1.204     albertel  359:     } else {
                    360: 	$Apache::inputtags::part='';
                    361: 	@Apache::inputtags::partlist=();
                    362: 	$Apache::lonhomework::problemstatus='';	
                    363:     }
                    364:     @Apache::inputtags::responselist = ();
                    365:     @Apache::inputtags::importlist = ();
                    366:     @Apache::inputtags::previous=();
                    367:     @Apache::inputtags::previous_version=();
                    368:     $Apache::structuretags::printanswer='No';
                    369:     @Apache::structuretags::whileconds=();
                    370:     @Apache::structuretags::whilebody=();
                    371:     @Apache::structuretags::whileline=();
                    372:     $Apache::lonhomework::scantronmode=0;
                    373:     undef($Apache::lonhomework::name);
                    374: 
                    375: }
                    376: 
                    377: sub reset_problem_globals {
                    378:     my ($type)=@_;
                    379:     undef(%Apache::lonhomework::history);
                    380:     undef(%Apache::lonhomework::results);
                    381:     undef($Apache::inputtags::part);
1.208     albertel  382: #don't undef this, lonhomework.pm takes care of this, we use this to 
                    383: #detect if we try to do 2 problems in one file
                    384: #   undef($Apache::lonhomework::parsing_a_problem);
1.204     albertel  385:     undef($Apache::lonhomework::name);
                    386: }
                    387: 
1.241     albertel  388: sub set_problem_state {
1.240     albertel  389:     my ($part)=@_;
                    390:     if ($ENV{'form.problemstate'} eq 'CANNOT_ANSWER_correct') {
                    391: 	$Apache::lonhomework::history{"resource.$part.solved"}=
                    392: 	    'correct_by_student';
                    393:     }
                    394: }
                    395: 
1.241     albertel  396: sub get_problem_status {
                    397:     my ($part)=@_;
                    398:     my $problem_status=&Apache::lonnet::EXT("resource.$part.problemstatus");
                    399:     &Apache::lonxml::debug("problem status for $part is $problem_status");
                    400:     &Apache::lonxml::debug("env probstat is ".$ENV{'form.problemstatus'});
                    401:     if ($ENV{'request.state'} eq 'construct' &&
                    402: 	defined($ENV{'form.problemstatus'})) {
                    403: 	$problem_status=$ENV{'form.problemstatus'};
                    404:     }
                    405:     return $problem_status;
                    406: }
                    407: 
1.9       albertel  408: sub start_problem {
1.159     albertel  409:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel  410: 
1.184     albertel  411:     if ( $Apache::inputtags::part ne '' ||
                    412: 	 $Apache::lonhomework::parsing_a_problem) {
                    413: 	&Apache::lonxml::error('Only one &lt;problem&gt; allowed in a .problem file');
                    414: 	#my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
1.159     albertel  415: 	return '';
                    416:     }
1.184     albertel  417: 
                    418:     $Apache::lonhomework::parsing_a_problem=1;
1.204     albertel  419:     &init_problem_globals('problem');
1.166     albertel  420: 
                    421:     if (defined($ENV{'scantron.maxquest'})) {
                    422: 	$Apache::lonhomework::scantronmode=1;
                    423:     }
1.161     albertel  424: 
1.246     albertel  425:     &initialize_storage();
1.159     albertel  426:     if ($target ne 'analyze') {
                    427: 	if ($target eq 'web') {
                    428: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.238     albertel  429: 	}
1.241     albertel  430:        	if ($ENV{'request.state'} eq 'construct') { &set_problem_state('0'); }
1.159     albertel  431: 	$Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
1.237     albertel  432: 	if (($ENV{'request.state'} eq 'construct') &&
                    433: 	    defined($ENV{'form.problemtype'})) {
                    434: 	    $Apache::lonhomework::type=$ENV{'form.problemtype'};
                    435: 	}
1.240     albertel  436: 	&Apache::lonxml::debug("Found this to be of type :$Apache::ltonhomework::type:");
1.159     albertel  437:     }
1.164     albertel  438:     if ($Apache::lonhomework::type eq '' ) {
1.159     albertel  439: 	my $uri=$ENV{'request.uri'};
                    440: 	if ($uri=~/\.(\w+)$/) {
                    441: 	    $Apache::lonhomework::type=$1;
                    442: 	    &Apache::lonxml::debug("Using type of $1");
                    443: 	} else {
                    444: 	    $Apache::lonhomework::type='problem';
                    445: 	    &Apache::lonxml::debug("Using default type, problem, :$uri:");
                    446: 	}
1.87      albertel  447:     }
1.58      www       448: 
1.159     albertel  449:     #added vars to the scripting enviroment
1.213     albertel  450:     my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
1.248     albertel  451:     $expression.='$external::type=\''.$Apache::lonhomework::type.'\';';
1.24      albertel  452:     &Apache::run::run($expression,$safeeval);
1.159     albertel  453:     my $status;
                    454:     my $accessmsg;
                    455: 
                    456:     #should get back a <html> or the neccesary stuff to start XML/MathML
                    457:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    458: 	&page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
                    459:     if ($target eq 'tex' and $ENV{'request.symb'} =~ m/\.page_/) {$result='';}
                    460: 
                    461:     if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval); }
                    462:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    463: 	$target eq 'tex') {
                    464: 	#handle exam checkout
                    465: 	if ($Apache::lonhomework::type eq 'exam') {
                    466: 	    my $token=
                    467: 		$Apache::lonhomework::history{"resource.0.outtoken"};
                    468: 	    if (($ENV{'form.doescheckout'}) && (!$token)) {
                    469: 		$token=&Apache::lonxml::maketoken();
                    470: 		$Apache::lonhomework::history{"resource.0.outtoken"}=
                    471: 		    $token;
                    472: 	    }
                    473: 	    $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token);
1.142     albertel  474: 	}
1.252     albertel  475: 	if ($ENV{'form.markaccess'}) {
                    476: 	    &Apache::lonnet::set_first_access('map');
                    477: 	}
1.159     albertel  478: 	#handle rand seed in construction space
                    479: 	my $rndseed=&setup_rndseed($safeeval);
1.162     albertel  480: 	my ($symb)=&Apache::lonxml::whichuser();
1.163     albertel  481: 	if ($ENV{'request.state'} ne "construct" && $symb eq '') {
1.162     albertel  482: 	    $form_tag_start.='<input type="hidden" name="rndseed" value="'.
                    483: 		$rndseed.'" />'.
                    484: 		    '<input type="submit" name="resetdata"
1.211     albertel  485:                              value="'.&mt('New Problem Variation').'" />'.
1.164     albertel  486: 		    '<input type="hidden" name="username"
1.185     albertel  487:                              value="'.$ENV{'form.username'}.'" /> <br />';
1.162     albertel  488: 	}
1.159     albertel  489: 	($status,$accessmsg) = &Apache::lonhomework::check_access('0');
                    490: 	push (@Apache::inputtags::status,$status);
                    491: 	my $expression='$external::datestatus="'.$status.'";';
                    492: 	$expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
                    493: 	&Apache::run::run($expression,$safeeval);
                    494: 	&Apache::lonxml::debug("Got $status");
                    495: 	if (( $status eq 'CLOSED' ) ||
                    496: 	    ( $status eq 'UNCHECKEDOUT') ||
1.252     albertel  497: 	    ( $status eq 'NOT_YET_VIEWED') ||
1.159     albertel  498: 	    ( $status eq 'BANNED') ||
1.216     albertel  499: 	    ( $status eq 'UNAVAILABLE') ||
                    500: 	    ( $status eq 'INVALID_ACCESS')) {
1.159     albertel  501: 	    my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
                    502: 	    if ( $target eq "web" ) {
                    503: 		$result.= $head_tag_start.'</head>';
                    504: 		my $msg=$body_tag_start;
                    505: 		if ($status eq 'UNAVAILABLE') {
1.245     albertel  506: 		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.253   ! albertel  507: 		} elsif ($status ne 'NOT_YET_VIEWED') {
1.245     albertel  508: 		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
1.159     albertel  509: 		}
1.216     albertel  510: 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
1.159     albertel  511: 		    $msg.='The problem '.$accessmsg;
                    512: 		} elsif ($status eq 'UNCHECKEDOUT') {
                    513: 		    $msg.=&checkout_msg;
1.252     albertel  514: 		} elsif ($status eq 'NOT_YET_VIEWED') {
1.253   ! albertel  515: 		    $msg.=&firstaccess_msg($accessmsg,$symb);
1.159     albertel  516: 		}
                    517: 		$result.=$msg.'<br />';
                    518: 	    } elsif ($target eq 'tex') {
                    519: 		$result.='\begin{document}\noindent \vskip 1 mm  \begin{minipage}{\textwidth}\vskip 0 mm';
                    520: 		if ($status eq 'UNAVAILABLE') {
1.211     albertel  521: 		    $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
1.159     albertel  522: 		} else {
1.211     albertel  523: 		    $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
1.159     albertel  524: 		}
                    525: 	    }
                    526: 	} elsif ($target eq 'web') {
                    527: 	    my $name= &get_resource_name($parstack,$safeeval);
1.227     albertel  528: 	    $result.="$head_tag_start<title>$name</title></head>
1.158     sakharuk  529:               $body_tag_start \n $form_tag_start".	
1.227     albertel  530: 	      '<input type="hidden" name="submitted" value="yes" />';
                    531: 	    # create a page header and exit
                    532: 	    if ($ENV{'request.state'} eq "construct") {
                    533: 		$result.= &problem_web_to_edit_header($ENV{'form.rndseed'});
                    534: 	    }
                    535: 	    # if we are viewing someone else preserve that info
                    536: 	    if (defined $ENV{'form.grade_symb'}) {
                    537: 		foreach my $field ('symb','courseid','domain','username') {
                    538: 		    $result .= '<input type="hidden" name="grade_'.$field.
                    539: 			'" value="'.$ENV{"form.grade_$field"}.'" />'."\n";
1.159     albertel  540: 		}
                    541: 	    }
                    542: 	} elsif ($target eq 'tex') {
1.192     sakharuk  543: 	    my $startminipage = '';
1.191     sakharuk  544: 	    if (not $ENV{'form.problem_split'}=~/yes/) {
1.192     sakharuk  545: 		$startminipage = '\begin{minipage}{\textwidth}';
1.178     sakharuk  546: 	    }
1.159     albertel  547: 	    my $id = $Apache::inputtags::part;
                    548: 	    my $weight = &Apache::lonnet::EXT("resource.$id.weight");
1.223     sakharuk  549: 	    my $packages=&Apache::lonnet::metadata($ENV{'request.uri'},'packages');
                    550: 	    my @packages = split /,/,$packages;
                    551: 	    my $allow_print_points = 0;
                    552: 	    foreach my $partial_key (@packages) {
1.230     albertel  553: 		if ($partial_key=~m/^part_0$/) {
1.223     sakharuk  554: 		    $allow_print_points=1;
1.159     albertel  555: 		}
                    556: 	    }
                    557: 	    my $duedate = &Apache::lonnet::EXT("resource.$id.duedate"); 
                    558: 	    $duedate = POSIX::strftime("%c",localtime($duedate));
                    559: 	    my $temp_file;
                    560: 	    my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.due";
                    561: 	    if (-e $filename) {
                    562: 		$temp_file = Apache::File->new($filename);
                    563: 	    } else {
                    564: 		$temp_file = Apache::File->new('>>'.$filename);
                    565: 	    }
                    566: 	    my @due_file_content = <$temp_file>;
                    567: 	    my $due_file_content = $due_file_content[$#due_file_content];
                    568: 	    chomp $due_file_content;
1.231     sakharuk  569: 	    my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval));
1.159     albertel  570: 	    if ($due_file_content ne $duedate) {
                    571: 		$temp_file = Apache::File->new('>'.$filename);
                    572: 		print $temp_file "$duedate\n";
                    573: 		if (not $ENV{'request.symb'} =~ m/\.page_/) {
                    574: 		    if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') {
1.206     sakharuk  575: 			$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 '.$startminipage.'\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}';	
1.159     albertel  576: 		    } else {
1.206     sakharuk  577: 			$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'.$startminipage.'\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}';
1.159     albertel  578: 			if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
                    579: 		    }
1.104     sakharuk  580: 		} else {
1.159     albertel  581: 		    $result .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\';
1.104     sakharuk  582: 		}
1.101     sakharuk  583: 	    } else {
1.159     albertel  584: 		if (not $ENV{'request.symb'} =~ m/\.page_/) {
1.206     sakharuk  585: 		    $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'.$startminipage.'\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}';	
1.159     albertel  586: 		    if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
                    587: 		} else {
                    588: 		    $result .= '\vskip 1mm \\\\\\\\';
                    589: 		}
                    590: 	    }
1.99      sakharuk  591: 	}
1.159     albertel  592:     } elsif ($target eq 'edit') {
                    593: 	$result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
                    594: 	    &problem_edit_header();
1.226     albertel  595: 	$Apache::lonxml::warnings_error_header=
                    596: 	    &mt("Editor Errors - these errors might not effect the running of the problem, but they will likely cause problems with further use of the Edit mode. Please use the EditXML mode to fix these errors.")."<br />";
1.159     albertel  597: 	my $temp=&Apache::edit::insertlist($target,$token);
                    598: 	$result.=$temp;
                    599:     } elsif ($target eq 'modified') {
                    600: 	$result=$token->[4];
                    601: 	$result.=&Apache::edit::handle_insert();
                    602:     } else {
                    603: 	# page_start returned a starting result, delete it if we don't need it
                    604: 	$result = '';
1.99      sakharuk  605:     }
1.159     albertel  606:     return $result;
1.9       albertel  607: }
                    608: 
                    609: sub end_problem {
1.159     albertel  610:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    611:     my $result='';
                    612:     my $status=$Apache::inputtags::status['-1'];
                    613:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
                    614: 	$target eq 'tex') {
1.249     albertel  615: 	if ( $target eq 'grade' && $Apache::inputtags::part eq '0') {
1.159     albertel  616: 	    # if part is zero, no <part>s existed, so we need to the grading
1.249     albertel  617: 	    if ($status eq 'CAN_ANSWER' ||$Apache::lonhomework::scantronmode) {
                    618: 		&Apache::inputtags::grade;
                    619: 	    } else {
                    620: 		# move any submission data to .hidden
                    621: 		&Apache::inputtags::hidealldata($Apache::inputtags::part);
                    622: 	    }
1.159     albertel  623: 	} elsif ( ($target eq 'web' || $target eq 'tex') &&
                    624: 		  $Apache::inputtags::part eq '0' &&
1.252     albertel  625: 		  $status ne 'UNCHECKEDOUT' && $status ne 'NOT_YET_VIEWED') {
1.159     albertel  626: 	    # if part is zero, no <part>s existed, so we need show the current
                    627: 	    # grading status
                    628: 	    my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
                    629: 	    $result.= $gradestatus;
                    630: 	}
                    631: 	if (
                    632: 	    (($target eq 'web') && ($ENV{'request.state'} ne 'construct')) ||
                    633: 	    ($target eq 'answer') || ($target eq 'tex')
                    634: 	   ) {
1.227     albertel  635: 	    if ($target ne 'tex' &&
                    636: 		$ENV{'form.answer_output_mode'} ne 'tex') {
                    637: 		$result.="</form></body>\n";
1.159     albertel  638: 	    }
                    639: 	    if ($target eq 'web') {
                    640: 		$result.=&Apache::lonxml::xmlend();
                    641: 	    } elsif ($target eq 'tex') {
1.178     sakharuk  642: 		my $endminipage = '';
1.191     sakharuk  643: 		if (not $ENV{'form.problem_split'}=~/yes/) {
1.178     sakharuk  644: 		    $endminipage = '\end{minipage}';
                    645: 		}
1.174     sakharuk  646: 		$result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
1.159     albertel  647: 		if (not $ENV{'request.symb'} =~ m/\.page_/) {
1.178     sakharuk  648: 		    $result .= $endminipage.'\end{document} ';
1.159     albertel  649: 		} else {
                    650: 		    $result .= '';
                    651: 		}
                    652: 	    }
                    653: 	}
                    654: 	if ($target eq 'grade') {
                    655: 	    &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    656: 	    &finalize_storage();
                    657: 	}
1.172     albertel  658: 	if ($target eq 'answer' && ($ENV{'request.state'} eq 'construct')
1.173     albertel  659: 	    && $ENV{'form.answer_output_mode'} ne 'tex') {
1.172     albertel  660: 	    $result.='</html>'; # normally we get it from xmlend, but in CSTR
                    661: 	                        # we always show answer mode too.
1.159     albertel  662: 	}
                    663:     } elsif ($target eq 'meta') {
                    664: 	if ($Apache::inputtags::part eq '0') {
1.179     albertel  665: 	    @Apache::inputtags::response=();
1.159     albertel  666: 	    $result=&Apache::response::mandatory_part_meta;
                    667: 	}
1.215     albertel  668: 	$result.=&Apache::response::meta_part_order();
1.159     albertel  669:     } elsif ($target eq 'edit') {
                    670: 	&Apache::lonxml::debug("in end_problem with $target, edit");
                    671: 	$result = &problem_edit_footer();
                    672:     }
1.155     albertel  673: 
1.177     albertel  674:     if ($ENV{'request.state'} eq 'construct' && $target eq 'web') {
                    675: 	&Apache::inputtags::check_for_duplicate_ids();
                    676:     }
1.204     albertel  677: 
                    678:     &reset_problem_globals('problem');
1.159     albertel  679: 
                    680:     return $result;
1.48      albertel  681: }
                    682: 
1.108     albertel  683: 
1.48      albertel  684: sub start_library {
1.159     albertel  685:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    686:     my ($result,$head_tag_start,$body_tag_start,$form_tag_start);
1.244     albertel  687:     if ($$tagstack[0] eq 'library') {
                    688: 	&init_problem_globals('library');
                    689: 	$Apache::lonhomework::type='problem';
                    690:     }
1.159     albertel  691:     if ($target eq 'edit') {
                    692: 	($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    693: 	    &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
                    694: 	$result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
                    695: 	    &problem_edit_header();
                    696: 	my $temp=&Apache::edit::insertlist($target,$token);
                    697: 	$result.=$temp;
                    698:     } elsif ($target eq 'modified') {
                    699: 	$result=$token->[4];
                    700: 	$result.=&Apache::edit::handle_insert();
                    701:     } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
                    702: 	     $ENV{'request.state'} eq "construct" ) {
                    703: 	($result,$head_tag_start,$body_tag_start,$form_tag_start)=
                    704: 	    &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
                    705: 	my $name=&get_resource_name($parstack,$safeeval);
                    706: 	my $rndseed=&setup_rndseed($safeeval);
                    707: 	$result.="$head_tag_start<title>$name</title></head>
1.105     albertel  708:               $body_tag_start \n $form_tag_start".	
1.159     albertel  709: 		  '<input type="hidden" name="submitted" value="yes" />';
                    710: 	$result.=&problem_web_to_edit_header($rndseed);
                    711:     }
                    712:     return $result;
1.48      albertel  713: }
                    714: 
                    715: sub end_library {
1.159     albertel  716:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    717:     my $result='';
                    718:     if ($target eq 'edit') {
                    719: 	$result=&problem_edit_footer();
                    720:     } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
                    721: 	     $ENV{'request.state'} eq "construct") {
                    722: 	$result.='</form></body>'.&Apache::lonxml::xmlend();
                    723:     }
1.204     albertel  724:     if ($$tagstack[0] eq 'library') { &reset_problem_globals('library') };
1.159     albertel  725:     return $result;
1.197     www       726: }
                    727: 
                    728: sub start_definetag {
                    729:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    730: 
                    731:     my $result;
                    732: 
                    733:     my $name = $token->[2]->{'name'};
                    734:     my $skip=&Apache::lonxml::get_all_text("/definetag",$parser);
                    735:     if ($name=~/^\//) {
                    736: 	$result=
                    737:  '<br /><table bgcolor="#FFBBBB"><tr><th>END <tt>'.$name.'</tt></th></tr>';
                    738:     } else {
                    739: 	$result=
                    740:  '<br /><table bgcolor="#BBFFBB"><tr><th>BEGIN <tt>'.$name.'</tt></th></tr>';
                    741:     }
                    742:     $skip=~s/\</\&lt\;/gs;
                    743:     $skip=~s/\>/\&gt\;/gs;
                    744:     $result.='<tr><td><pre>'.$skip.'</pre></td></tr></table>';
                    745:     return $result;
                    746: }
                    747: 
                    748: sub end_definetag {
                    749:     return '';
1.1       albertel  750: }
                    751: 
                    752: sub start_block {
1.201     albertel  753:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.131     albertel  754: 
                    755:     my $result;
1.1       albertel  756: 
1.160     albertel  757:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.131     albertel  758: 	$target eq 'tex' || $target eq 'analyze') {
1.159     albertel  759: 	my $code = $token->[2]->{'condition'};
1.201     albertel  760: 	if (defined($code)) {
1.137     albertel  761: 	    if (!$Apache::lonxml::default_homework_loaded) {
                    762: 		&Apache::lonxml::default_homework_load($safeeval);
                    763: 	    }
1.131     albertel  764: 	    $result = &Apache::run::run($code,$safeeval);
                    765: 	    &Apache::lonxml::debug("block :$code: returned :$result:");
                    766: 	} else {
                    767: 	    $result='1';
                    768: 	}
                    769: 	if ( ! $result ) {
1.201     albertel  770: 	    my $skip=&Apache::lonxml::get_all_text("/block",$parser,$style);
1.131     albertel  771: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
                    772: 	}
                    773: 	$result='';
                    774:     } elsif ($target eq 'edit') {
                    775: 	$result .=&Apache::edit::tag_start($target,$token);
                    776: 	$result .=&Apache::edit::text_arg('Test Condition:','condition',
                    777: 					  $token,40);
                    778: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    779:     } elsif ($target eq 'modified') {
                    780: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    781: 						     $safeeval,'condition');
                    782: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.38      albertel  783:     }
1.131     albertel  784:     return $result;
1.1       albertel  785: }
                    786: 
                    787: sub end_block {
1.167     www       788:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    789:     my $result;
                    790:     if ($target eq "edit") {
                    791: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    792:     }
                    793:     return $result;
                    794: }
                    795: 
                    796: sub start_languageblock {
1.201     albertel  797:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.167     www       798: 
                    799:     my $result;
                    800: 
                    801:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    802: 	$target eq 'tex' || $target eq 'analyze') {
1.201     albertel  803: 	my $include = $token->[2]->{'include'};
                    804: 	my $exclude = $token->[2]->{'exclude'};
                    805:         my %languages=&Apache::loncommon::display_languages();
                    806:         $result='1';
                    807: 	if ($include) {
                    808:             $result='';
                    809:             foreach (split(/\,/,$include)) {
                    810:                 if ($languages{$_}) { $result='1'; }
                    811:             }
                    812: 	}
                    813:         if ($exclude) {
                    814:             foreach (split(/\,/,$exclude)) {
                    815:                 if ($languages{$_}) { $result='0'; }
                    816:             }
                    817: 	}
                    818: 	if ( ! $result ) {
                    819: 	    my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser,
                    820: 						   $style);
                    821: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
                    822: 	}
                    823: 	$result='';
1.167     www       824:     } elsif ($target eq 'edit') {
                    825: 	$result .=&Apache::edit::tag_start($target,$token);
1.211     albertel  826: 	$result .=&Apache::edit::text_arg(&mt('Include Language:'),'include',
1.167     www       827: 					  $token,40);
1.211     albertel  828: 	$result .=&Apache::edit::text_arg(&mt('Exclude Language:'),'exclude',
1.167     www       829: 					  $token,40);
                    830: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    831:     } elsif ($target eq 'modified') {
                    832: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.168     albertel  833: 						     $safeeval,'include',
                    834: 						     'exclude');
1.167     www       835: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    836:     }
                    837:     return $result;
                    838: }
                    839: 
                    840: sub end_languageblock {
1.170     www       841:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    842:     my $result;
1.201     albertel  843:     if ($target eq "edit") {
1.170     www       844: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    845:     }
                    846:     return $result;
                    847: }
                    848: 
                    849: sub start_instructorcomment {
1.201     albertel  850:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.170     www       851: 
                    852:     my $result;
                    853: 
                    854:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    855: 	$target eq 'tex' || $target eq 'analyze') {
                    856:         $result=($ENV{'request.role'}=~/^(in|cc|au|ca|li)/);
                    857: 	if ( ! $result ) {
1.201     albertel  858: 	    my $skip=&Apache::lonxml::get_all_text("/instructorcomment",
                    859: 						   $parser,$style);
1.170     www       860: 	    &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
                    861: 	}
                    862: 	$result='';
                    863:     } elsif ($target eq 'edit') {
                    864: 	$result .=&Apache::edit::tag_start($target,$token);
                    865: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    866:     }
                    867:     return $result;
                    868: }
                    869: 
                    870: sub end_instructorcomment {
1.159     albertel  871:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160     albertel  872:     my $result;
                    873:     if ($target eq "edit") {
                    874: 	$result.= &Apache::edit::tag_end($target,$token,'');
                    875:     }
                    876:     return $result;
1.4       tsai      877: }
                    878: 
                    879: sub start_while {
1.159     albertel  880:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    881: 
1.160     albertel  882:     my $result;
1.161     albertel  883:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.160     albertel  884: 	$target eq 'tex' || $target eq 'analyze') {
                    885: 	my $code = $token->[2]->{'condition'};
1.4       tsai      886: 
1.160     albertel  887: 	push( @Apache::structuretags::whileconds, $code);
                    888: 	if (!$Apache::lonxml::default_homework_loaded) {
                    889: 	    &Apache::lonxml::default_homework_load($safeeval);
                    890: 	}
                    891: 	my $result = &Apache::run::run($code,$safeeval);
1.161     albertel  892: 	my $bodytext=&Apache::lonxml::get_all_text("/while",$parser);
1.160     albertel  893: 	push( @Apache::structuretags::whilebody, $bodytext);
1.161     albertel  894: 	push( @Apache::structuretags::whileline, $token->[5]);
                    895: 	&Apache::lonxml::debug("s code $code got -$result-");
1.160     albertel  896: 	if ( $result ) {
                    897: 	    &Apache::lonxml::newparser($parser,\$bodytext);
                    898: 	}
                    899:     } elsif ($target eq 'edit') {
                    900: 	$result .=&Apache::edit::tag_start($target,$token);
1.211     albertel  901: 	$result .=&Apache::edit::text_arg(&mt('Test Condition:'),'condition',
1.160     albertel  902: 					  $token,40);
                    903: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    904:     } elsif ($target eq 'modified') {
                    905: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    906: 						     $safeeval,'condition');
                    907: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.159     albertel  908:     }
1.160     albertel  909:     return $result;
1.4       tsai      910: }
                    911: 
                    912: sub end_while {
1.159     albertel  913:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160     albertel  914:     my $result;
                    915: 
                    916:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                    917: 	$target eq 'tex' || $target eq 'analyze') {
                    918: 	my $code = pop(@Apache::structuretags::whileconds);
                    919: 	my $bodytext = pop(@Apache::structuretags::whilebody);
1.161     albertel  920: 	my $line = pop(@Apache::structuretags::whileline);
                    921: 	my $return = &Apache::run::run($code,$safeeval);
                    922: 	my $starttime=time;
                    923: 	my $error=0;
                    924: 	while ($return) {
                    925: 	    if (time-$starttime >
                    926: 		$Apache::lonnet::perlvar{'lonScriptTimeout'}) {
                    927: 		$return = 0; $error=1; next;
                    928: 	    }
                    929: 	    $result.=&Apache::scripttag::xmlparse($bodytext);
                    930: 	    $return = &Apache::run::run($code,$safeeval);
                    931: 	}
                    932: 	if ($error) {
1.211     albertel  933: 	    &Apache::lonxml::error('<pre>'.&mt('Code ran too long. It ran for more than').' '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' '.&mt('seconds occured while running &lt;while$gt; on line').' '.$line.'</pre>');
1.160     albertel  934: 	}
                    935:     } elsif ($target eq "edit") {
                    936: 	$result.= &Apache::edit::tag_end($target,$token,'');
1.159     albertel  937:     }
1.160     albertel  938:     return $result;
1.1       albertel  939: }
1.6       tsai      940: 
1.160     albertel  941: # <randomlist show="1">
1.6       tsai      942: #  <tag1>..</tag1>
                    943: #  <tag2>..</tag2>
                    944: #  <tag3>..</tag3>
1.160     albertel  945: #  ...
1.6       tsai      946: # </randomlist>
                    947: sub start_randomlist {
1.159     albertel  948:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    949:     my $result;
                    950:     if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' ||
                    951: 	$target eq 'tex' || $target eq 'analyze') {
                    952: 	my $body= &Apache::lonxml::get_all_text("/randomlist",$parser);
                    953: 	my $b_parser= HTML::TokeParser->new(\$body);
                    954: 	my $b_tok;
                    955: 	my @randomlist;
                    956: 	my $list_item;
                    957: 	while($b_tok = $b_parser->get_token() ) {
                    958: 	    if($b_tok->[0] eq 'S') { # start tag
                    959: 		# get content of the tag until matching end tag
                    960: 		# get all text upto the matching tag
                    961: 		# and push the content into @randomlist
                    962: 		$list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],
                    963: 							   $b_parser);
                    964: 		$list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
                    965: 		push(@randomlist,$list_item);
                    966: 		#  print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4],
                    967:                 #         $list_item</b>";
                    968: 	    }
                    969: 	    if($b_tok->[0] eq 'T') { # text
                    970: 		# what to do with text in between tags?
                    971: 		#  print "<b>TEXT $b_tok->[1]</b><br />";
                    972: 	    }
                    973: 	    # if($b_tok->[0] eq 'E') { # end tag, should not happen
                    974: 	    #  print "<b>END-TAG $b_tok->[1]</b><br />";
                    975: 	    # }
                    976: 	}
                    977: 	my @idx_arr = (0 .. $#randomlist);
                    978: 	&Apache::structuretags::shuffle(\@idx_arr);
                    979: 	my $bodytext = '';
                    980: 	my $show=$#randomlist;
                    981: 	my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
                    982: 	$showarg--;
                    983: 	if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
                    984: 	for(0 .. $show) {
                    985: 	    $bodytext .= "$randomlist[ $idx_arr[$_] ]";
                    986: 	}
                    987: 	&Apache::lonxml::newparser($parser,\$bodytext);
                    988:     } elsif ($target eq 'edit' ) {
                    989: 	$result .=&Apache::edit::tag_start($target,$token);
                    990: 	$result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
                    991: 					   $token,5);
                    992: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                    993:     } elsif ($target eq 'modified' ) {
                    994: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    995: 						     $safeeval,'show');
                    996: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                    997:     }
                    998:     return $result;
1.7       tsai      999: }
                   1000: 
                   1001: sub shuffle {
                   1002:     my $a=shift;
                   1003:     my $i;
1.70      albertel 1004:     if (defined(@$a)) {
1.251     albertel 1005: 	&Apache::response::pushrandomnumber();
1.159     albertel 1006: 	for($i=@$a;--$i;) {
                   1007: 	    my $j=int(&Math::Random::random_uniform() * ($i+1));
                   1008: 	    next if $i == $j;
                   1009: 	    @$a[$i,$j] = @$a[$j,$i];
                   1010: 	}
1.251     albertel 1011: 	&Apache::response::poprandomnumber();
1.7       tsai     1012:     }
1.6       tsai     1013: }
                   1014: 
                   1015: sub end_randomlist {
1.159     albertel 1016:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1017:     my $result;
                   1018:     if ($target eq 'edit' ) {
                   1019: 	$result=&Apache::edit::tag_end($target,$token,
                   1020: 				       'End Randomly Parsed Block');
                   1021:     }
                   1022:     return $result;
1.6       tsai     1023: }
                   1024: 
1.11      albertel 1025: sub start_part {
1.159     albertel 1026:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1027:     my $result='';
                   1028:     my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
                   1029:     if ($id eq '') { $id = $Apache::lonxml::curdepth; }
                   1030:     $Apache::inputtags::part=$id;
1.177     albertel 1031:     push(@Apache::inputtags::partlist,$id);
                   1032:     @Apache::inputtags::response=();
1.159     albertel 1033:     @Apache::inputtags::previous=();
                   1034:     @Apache::inputtags::previous_version=();
1.241     albertel 1035:     $Apache::lonhomework::problemstatus=&get_problem_status($id);
1.159     albertel 1036:     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
1.214     albertel 1037:     my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
1.209     albertel 1038:     &Apache::run::run($expression,$safeeval);
1.159     albertel 1039: 
                   1040:     if ($target eq 'meta') {
1.224     www      1041: 	my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
                   1042: 	return &Apache::response::mandatory_part_meta.
                   1043: 	       &Apache::response::meta_parameter_write('display','string',$display,'Part Description');
1.159     albertel 1044:     } elsif ($target eq 'web' || $target eq 'grade' ||
                   1045: 	     $target eq 'answer' || $target eq 'tex') {
                   1046: 	if ($hidden) {
                   1047: 	    my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
                   1048: 	} else {
                   1049: 	    my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
                   1050: 	    push (@Apache::inputtags::status,$status);
                   1051: 	    my $expression='$external::datestatus="'.$status.'";';
                   1052: 	    $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
                   1053: 	    &Apache::run::run($expression,$safeeval);
1.240     albertel 1054: 	    if ($ENV{'request.state'} eq 'construct') {
1.241     albertel 1055: 		&set_problem_state($Apache::inputtags::part); 
1.240     albertel 1056: 	    }
1.216     albertel 1057: 	    if (( $status eq 'CLOSED' ) ||
                   1058: 		( $status eq 'UNCHECKEDOUT') ||
1.252     albertel 1059: 		( $status eq 'NOT_YET_VIEWED') ||
1.216     albertel 1060: 		( $status eq 'BANNED') ||
                   1061: 		( $status eq 'UNAVAILABLE') ||
                   1062: 		( $status eq 'INVALID_ACCESS')) {
1.159     albertel 1063: 		my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
                   1064: 		if ( $target eq "web" ) {
1.211     albertel 1065: 		    $result="<br />".&mt('Part is not open to be viewed. It')." $accessmsg<br />";
1.159     albertel 1066: 		} elsif ( $target eq 'tex' ) {
1.195     sakharuk 1067: 		    if (not $ENV{'form.problem_split'}=~/yes/) {
1.211     albertel 1068: 			$result="\\end{minipage}\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\\\begin{minipage}{\\textwidth}";
1.195     sakharuk 1069: 		    } else {
1.211     albertel 1070: 			$result="\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\";
1.195     sakharuk 1071: 		    }
1.159     albertel 1072: 		}
                   1073: 	    } else {
                   1074: 		if ($target eq 'tex') {
1.195     sakharuk 1075: 		    if (not $ENV{'form.problem_split'}=~/yes/) {
                   1076: 			$result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
                   1077: 		    }
1.159     albertel 1078: 		    my $weight = &Apache::lonnet::EXT("resource.$id.weight");
1.230     albertel 1079: 		    my $allkeys=&Apache::lonnet::metadata($ENV{'request.uri'},'packages');
1.222     sakharuk 1080: 		    my @allkeys = split /,/,$allkeys;
                   1081: 		    my $allow_print_points = 0;
                   1082: 		    foreach my $partial_key (@allkeys) {
1.230     albertel 1083: 			if ($partial_key=~m/^part_(.*)$/) {
1.222     sakharuk 1084: 			    if ($1 ne '0') {$allow_print_points=1;}
                   1085: 			}
                   1086: 		    }
                   1087: 		    if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
1.233     www      1088: 		} elsif ($target eq 'web') {
                   1089: 		    $result.='<a name="'.&Apache::lonnet::escape($Apache::inputtags::part).'" />';
1.159     albertel 1090: 		}
                   1091: 	    }
                   1092: 	}
                   1093:     } elsif ($target eq 'edit') {
                   1094: 	$result.=&Apache::edit::tag_start($target,$token);
                   1095: 	$result.=&Apache::edit::text_arg('Part ID:','id',$token).
                   1096: 	    &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help").
1.224     www      1097: 	    '&nbsp;&nbsp;'.
                   1098: &Apache::edit::text_arg('Displayed Part Description:','display',$token).
1.159     albertel 1099: 		&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                   1100:     } elsif ($target eq 'modified') {
                   1101: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.225     albertel 1102: 						     $safeeval,'id','display');
1.159     albertel 1103: 	if ($constructtag) {
1.225     albertel 1104: 	    #limiting ids to only letters numbers, and space
1.224     www      1105: 	    $token->[2]->{'id'}=~s/[^A-Za-z0-9 ]//gs;
1.159     albertel 1106: 	    $result = &Apache::edit::rebuild_tag($token);
                   1107: 	    $result.=&Apache::edit::handle_insert();
                   1108: 	}
                   1109:     }
                   1110:     return $result;
1.11      albertel 1111: }
                   1112: 
                   1113: sub end_part {
1.159     albertel 1114:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1115:     &Apache::lonxml::debug("in end_part $target ");
                   1116:     my $status=$Apache::inputtags::status['-1'];
                   1117:     my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
                   1118:     my $result='';
                   1119:     if ( $target eq 'meta' ) {
                   1120: 	$result='';
1.249     albertel 1121:     } elsif ($target eq 'grade') {
                   1122: 	if (($status eq 'CAN_ANSWER' || $Apache::lonhomework::scantronmode) &&
                   1123: 	    !$hidden) {
                   1124: 	    $result=&Apache::inputtags::grade;
                   1125: 	} else {
                   1126: 	    # move any submission data to .hidden
                   1127: 	    &Apache::inputtags::hidealldata($Apache::inputtags::part);
                   1128: 	}
1.159     albertel 1129:     } elsif (($target eq 'web' || $target eq 'tex') && !$hidden ) {
                   1130: 	my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
                   1131: 							$target);
1.212     albertel 1132: 	if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') {
                   1133: 	    $gradestatus='';
                   1134: 	}
1.159     albertel 1135: 	$result=$gradestatus;
1.181     albertel 1136:     } elsif ($target eq 'edit') {
                   1137: 	$result=&Apache::edit::end_table();
1.159     albertel 1138:     }
                   1139:     pop @Apache::inputtags::status;
                   1140:     $Apache::inputtags::part='';
                   1141:     return $result;
1.11      albertel 1142: }
1.1       albertel 1143: 
1.25      albertel 1144: sub start_preduedate {
1.159     albertel 1145:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1146:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
1.236     albertel 1147: 	&Apache::lonxml::debug("State in preduedate is ". $Apache::inputtags::status['-1']);
1.159     albertel 1148: 	if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
1.236     albertel 1149: 	    $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
                   1150: 	    &Apache::lonxml::debug("Wha? ". ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER'));
1.159     albertel 1151: 	    &Apache::lonxml::get_all_text("/preduedate",$parser);
                   1152: 	}
1.24      albertel 1153:     }
1.159     albertel 1154:     return '';
1.24      albertel 1155: }
                   1156: 
1.25      albertel 1157: sub end_preduedate {
1.159     albertel 1158:     return '';
1.24      albertel 1159: }
                   1160: 
1.25      albertel 1161: sub start_postanswerdate {
1.159     albertel 1162:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.234     albertel 1163:     if ($target eq 'web' || $target eq 'grade') {
1.159     albertel 1164: 	if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
                   1165: 	    &Apache::lonxml::get_all_text("/postanswerdate",$parser);
                   1166: 	}
                   1167:     } elsif ($target eq 'tex') {
1.234     albertel 1168: 	&Apache::lonxml::get_all_text("/postanswerdate",$parser);
1.159     albertel 1169:     }
                   1170:     return '';
1.24      albertel 1171: }
                   1172: 
1.25      albertel 1173: sub end_postanswerdate {
1.159     albertel 1174:     return '';
1.24      albertel 1175: }
                   1176: 
1.25      albertel 1177: sub start_notsolved {
1.159     albertel 1178:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1179:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                   1180: 	$target eq 'tex') {
                   1181: 	my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
                   1182: 	&Apache::lonxml::debug("not solved has :$gradestatus:");
1.239     albertel 1183: 	if ($gradestatus =~ /^correct/ &&
                   1184: 	    &Apache::response::show_answer()) {
1.159     albertel 1185: 	    &Apache::lonxml::debug("skipping");
                   1186: 	    &Apache::lonxml::get_all_text("/notsolved",$parser);
                   1187: 	}
1.24      albertel 1188:     }
1.159     albertel 1189:     return '';
1.24      albertel 1190: }
                   1191: 
1.25      albertel 1192: sub end_notsolved {
1.159     albertel 1193:     return '';
1.24      albertel 1194: }
                   1195: 
                   1196: sub start_solved {
1.159     albertel 1197:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1198:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                   1199: 	$target eq 'tex') {
                   1200: 	my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
1.239     albertel 1201: 	if ($gradestatus !~ /^correct/ ||
                   1202: 	    !&Apache::response::show_answer()) {
1.159     albertel 1203: 	    &Apache::lonxml::get_all_text("/solved",$parser);
                   1204: 	}
1.24      albertel 1205:     }
1.159     albertel 1206:     return '';
1.24      albertel 1207: }
                   1208: 
                   1209: sub end_solved {
1.248     albertel 1210:     return '';
                   1211: }
                   1212: 
                   1213: sub start_problemtype {
                   1214:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1215:     my $result;
                   1216:     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
                   1217: 	$target eq 'tex' || $target eq 'analyze') {
                   1218: 	my $mode=lc(&Apache::lonxml::get_param('mode',$parstack,$safeeval));
                   1219: 	if (!defined($mode)) { $mode='show'; }
                   1220: 	my $for=&Apache::lonxml::get_param('for',$parstack,$safeeval);
                   1221: 	my $found=0;
                   1222: 	foreach my $type (split(',',$for)) {
                   1223: 	    if ($Apache::lonhomework::type eq lc($type)) { $found=1; }
                   1224: 	}
                   1225: 	if ($mode eq 'show' && !$found) {
                   1226: 	    &Apache::lonxml::get_all_text("/problemtype",$parser);
                   1227: 	}
                   1228: 	if ($mode eq 'hide' && $found) {
                   1229: 	    &Apache::lonxml::get_all_text("/problemtype",$parser);
                   1230: 	}
                   1231:     } elsif ($target eq 'edit') {
                   1232: 	$result .=&Apache::edit::tag_start($target,$token);
                   1233: 	$result.=&Apache::edit::select_arg('Mode:','mode',
                   1234: 					   [['show','Show'],
                   1235: 					    ['hide','Hide']]
                   1236: 					   ,$token);
                   1237: 	$result .=&Apache::edit::checked_arg('When used as type(s):','for',
                   1238: 					     [ ['exam','Exam/Quiz Problem'],
                   1239: 					       ['survey','Survey'],
                   1240: 					       ['problem','Homework Problem'] ]
                   1241: 					     ,$token);
                   1242: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
                   1243:     } elsif ($target eq 'modified') {
                   1244: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                   1245: 						     $safeeval,'mode','for');
                   1246: 	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
                   1247:     }
                   1248:     return $result;
                   1249: }
                   1250: 
                   1251: sub end_problemtype {
1.159     albertel 1252:     return '';
1.24      albertel 1253: }
1.34      albertel 1254: 
                   1255: sub start_startouttext {
1.159     albertel 1256:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1257:     my @result=(''.'');
                   1258:     if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
                   1259:     return (@result);
1.34      albertel 1260: }
1.159     albertel 1261: 
1.34      albertel 1262: sub end_startouttext {
1.159     albertel 1263:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1264:     my $result='';
                   1265:     my $text='';
                   1266: 
                   1267:     if ($target eq 'edit') {
                   1268: 	$text=&Apache::lonxml::get_all_text("endouttext",$parser);
1.211     albertel 1269: 	$result.=&Apache::edit::start_table($token)."<tr><td>".&mt('Text Block')."</td>
                   1270: <td>".&mt('Delete:').
1.159     albertel 1271:                  &Apache::edit::deletelist($target,$token)
                   1272: 		 ."</td>
1.42      albertel 1273: <td>".
1.159     albertel 1274:                  &Apache::edit::insertlist($target,$token).
                   1275: 		 &Apache::edit::end_row().
                   1276:                  &Apache::edit::start_spanning_row()."\n"
1.188     bowersj2 1277: 		 . &Apache::loncommon::helpLatexCheatsheet () .
1.159     albertel 1278: 		 &Apache::edit::editfield($token->[1],$text,"",80,4);
                   1279:     }
                   1280:     if ($target eq 'modified') {
1.219     albertel 1281: 	$result='<startouttext />'.&Apache::edit::modifiedfield("endouttext",$parser);
1.159     albertel 1282:     }
                   1283:     if ($target eq 'tex') {
                   1284: 	$result .= '\noindent ';
                   1285:     }
                   1286:     return $result;
1.34      albertel 1287: }
1.159     albertel 1288: 
1.34      albertel 1289: sub start_endouttext {
1.159     albertel 1290:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1291:     my $result='';
                   1292:     if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
                   1293:     if ($target eq "modified") {
                   1294: 	$result='<endouttext />'.
                   1295: 	    &Apache::edit::handle_insertafter('startouttext'); }
                   1296:     return $result;
1.34      albertel 1297: }
1.159     albertel 1298: 
1.34      albertel 1299: sub end_endouttext {
1.159     albertel 1300:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1301:     my @result=('','');
                   1302:     if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
                   1303:     return (@result);
1.34      albertel 1304: }
1.159     albertel 1305: 
1.45      albertel 1306: sub delete_startouttext {
1.159     albertel 1307:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1308:     #  my $text=&Apache::lonxml::get_all_text("endouttext",$parser);
                   1309:     my $text=$$parser['-1']->get_text("/endouttext");
                   1310:     my $ntoken=$$parser['-1']->get_token();
                   1311:     &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
                   1312:     &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
                   1313:     # Deleting 2 parallel tag pairs, but we need the numbers later to look like
                   1314:     # they did the last time round
                   1315:     &Apache::lonxml::increasedepth($ntoken);
                   1316:     &Apache::lonxml::decreasedepth($ntoken);
                   1317:     return 1;
1.193     www      1318: }
                   1319: 
                   1320: sub start_simpleeditbutton {
                   1321:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                   1322:     my $result='';
                   1323:     if (($target eq 'web') &&
                   1324:         (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) {
1.220     www      1325:         my $url=$ENV{'request.noversionuri'};
1.193     www      1326:         $url=~s/\?.*$//;
1.194     www      1327: 	$result='<table width="100%" bgcolor="#FFFFAA" border="2"><tr><td>'.
1.211     albertel 1328:                 '<a href="'.$url.'/smpedit">'.&mt('Simple Problem Editor').'</a> - '.&mt('Note: it can take up to 10 minutes for changes to take effect for all users.').
1.196     www      1329: &Apache::loncommon::help_open_topic('Caching').'</td></tr></table><br />';
1.193     www      1330:     }
                   1331:     return $result;
                   1332: }
                   1333: 
                   1334: sub end_simpleeditbutton {
                   1335:     return '';
1.45      albertel 1336: }
1.34      albertel 1337: 
1.1       albertel 1338: 1;
                   1339: __END__

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