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

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

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