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

1.34      albertel    1: # The LearningOnline Network with CAPA 
                      2: # definition of tags that give a structure to a document
1.33      albertel    3: # 2/19 Guy
1.44      ng          4: # 6/26/2001 fixed extra web display at end of <web></web> tags
1.60      www         5: # 8/17,8/18,8/20 Gerd Kortemeyer
1.54      www         6: 
1.1       albertel    7: package Apache::structuretags; 
                      8: 
                      9: use strict;
                     10: use Apache::lonnet;
                     11: 
                     12: sub BEGIN {
1.48      albertel   13:   &Apache::lonxml::register('Apache::structuretags',('block','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','startouttext','endouttext'));
1.37      albertel   14: #  &Apache::lonxml::register_insert('problem','',('part','postanswerdate','preduedate'))
1.10      albertel   15: }
                     16: 
                     17: sub start_web {
1.40      albertel   18:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.10      albertel   19:   my $bodytext=&Apache::lonxml::get_all_text("/web",$$parser[$#$parser]);
1.19      albertel   20:   if ($target eq 'web') {
                     21:     return $bodytext;
                     22:   } 
                     23:   return '';
1.10      albertel   24: }
                     25: 
                     26: sub end_web {
1.44      ng         27:     return '';
1.10      albertel   28: }
                     29: 
                     30: sub start_tex {
1.40      albertel   31:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.10      albertel   32:   my $bodytext=&Apache::lonxml::get_all_text("/tex",$$parser[$#$parser]);
1.19      albertel   33:   if ($target eq 'tex') {
                     34:     return $bodytext
                     35:   }
1.10      albertel   36:   return '';
                     37: }
                     38: 
                     39: sub end_tex {
1.44      ng         40:     return '';
1.9       albertel   41: }
                     42: 
1.48      albertel   43: sub page_start {
                     44:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                     45:   my $result=&Apache::londefdef::start_html($target,$token,$tagstack,$parstack,$parser,$safeeval);
                     46:   my $head_tag_start='<head>'.&Apache::lonxml::registerurl();
                     47:   my $body_tag_start='<body onLoad="'.&Apache::lonxml::loadevents().'" '.
1.50      albertel   48: 	  'onUnload="'.&Apache::lonxml::unloadevents().'" ';
                     49:   my $background=&Apache::lonxml::get_param('background',$parstack,$safeeval);
                     50:   if ($background) {
                     51:     $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
                     52:                                         $background;
                     53:     $body_tag_start.='background="'.$background.'" ';
                     54:   } else {
                     55:     my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,$safeeval);
                     56:     if ($bgcolor) {
                     57:       $body_tag_start.='bgcolor="'.$bgcolor.'" ';
                     58:     } else {
                     59:       $body_tag_start.='bgcolor="#ffffff"';
                     60:     }
                     61:   }
                     62:   $body_tag_start.='>';
1.48      albertel   63:   return ($result,$head_tag_start,$body_tag_start);
                     64: }
                     65: 
1.65      albertel   66: sub initialize_storage {
                     67:   %Apache::lonhomework::results=();
1.66      albertel   68:   my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
1.67      albertel   69:   if ($ENV{'request.state'} eq 'construct') {
                     70:     %Apache::lonhomework::history=
1.72      albertel   71:       &Apache::lonnet::tmprestore($ENV{'request.uri'},'',$domain,$name);
1.67      albertel   72:     my ($temp)=keys %Apache::lonhomework::history ;
                     73:     &Apache::lonxml::debug("Return message of $temp");
                     74:   } else {
                     75:     %Apache::lonhomework::history=
                     76:       &Apache::lonnet::restore($symb,$courseid,$domain,$name);
                     77:   }
1.65      albertel   78:   #ignore error conditions
                     79:   my ($temp)=keys %Apache::lonhomework::history ;
                     80:   if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
                     81: }
                     82: 
                     83: # -------------------------------------------------------------finalize_storage
                     84: # Stores away the result has to a student's environment
                     85: # checks form.grade_ for specific values, other wises stores
                     86: # to the running users environment
                     87: sub finalize_storage {
                     88:   my $result;
                     89:   my ($temp) = keys %Apache::lonhomework::results;
                     90:   if ( $temp ne '' ) {
1.66      albertel   91:     my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
1.67      albertel   92:     if ($ENV{'request.state'} eq 'construct') {
1.72      albertel   93:       $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,
                     94: 				      $ENV{'request.uri'},'',$domain,$name);
1.67      albertel   95:       &Apache::lonxml::debug('Construct Store return message:'.$result);
                     96:     } else {
                     97:       $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
                     98: 				      $symb,$courseid,$domain,$name);
                     99:       &Apache::lonxml::debug('Store return message:'.$result);
                    100:     }
1.65      albertel  101:   }
                    102:   return $result;
                    103: }
                    104: 
                    105: sub checkout_msg {
                    106: return (<<ENDCHECKOUT);
                    107: <h2>The resource needs to be checked out</h2>
                    108: As a resource gets checked out, a unique timestamped ID is given to it, and a
                    109: permanent record is left in the system.<p />
                    110: <font color=red>
                    111: Checking out resources is subject to course policies, and may exclude future
                    112: credit even if done erroneously.<p />
                    113: </font>  
                    114: <form method=post>
                    115: <input type=button name="doescheckout" 
                    116: value="Check out Exam for Viewing" 
                    117: onClick="if (confirm('Check out Exam?')) { this.form.submit(); }" />
                    118: </form>
                    119: ENDCHECKOUT
                    120: }
                    121: 
1.9       albertel  122: sub start_problem {
1.40      albertel  123:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel  124: 
                    125: #intialize globals
                    126:   $Apache::inputtags::part='0';
                    127:   @Apache::inputtags::responselist = ();
1.51      albertel  128:   @Apache::inputtags::previous=();
1.65      albertel  129:   &initialize_storage();
1.73    ! albertel  130:   if ($target eq 'web') {
        !           131:     &Apache::lonhomework::showhash(%Apache::lonhomework::history);
        !           132:   }
1.42      albertel  133:   $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
                    134:   &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
                    135:   if ($Apache::lonhomework::type eq '') {
1.53      albertel  136:     my $uri=$ENV{'request.uri'};
                    137:     if ($uri=~/\.(\w+)$/) {
                    138:       $Apache::lonhomework::type=$1;
                    139:       &Apache::lonxml::debug("Using type of $1");
                    140:     } else {
                    141:       $Apache::lonhomework::type='problem';
                    142:       &Apache::lonxml::debug("Using default type, problem, :$uri:");
                    143:     }
1.42      albertel  144:   }
1.58      www       145: 
1.67      albertel  146:   #added vars to the scripting enviroment
1.19      albertel  147:   my $expression='$external::part='.$Apache::inputtags::part.';';
                    148:   &Apache::run::run($expression,$safeeval);
1.22      albertel  149:   my $status;
1.55      www       150:   my $accessmsg;
1.36      albertel  151: 
1.41      albertel  152:   #should get back a <html> or the neccesary stuff to start XML/MathML
1.48      albertel  153:   my ($result,$head_tag_start,$body_tag_start)=
                    154:     &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
1.36      albertel  155: 
1.67      albertel  156: 
1.68      albertel  157:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
1.67      albertel  158:     #handle exam checkout
                    159:     if ($Apache::lonhomework::type eq 'exam') {
                    160:       my $token=$Apache::lonhomework::history{"resource.0.outtoken"};
                    161:       if (($ENV{'form.doescheckout'}) && (!$token)) {
                    162: 	$token=&Apache::lonxml::maketoken();
                    163: 	$Apache::lonhomework::history{"resource.0.outtoken"}=$token;
                    164:       }
                    165:       $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token);
                    166:     }
                    167: 
                    168:     #handle rand seed in construction space
                    169:     my $rndseed;
                    170:     if ($ENV{'request.state'} eq "construct") {
                    171:       $rndseed=$ENV{'form.rndseed'};
                    172:       if (!$rndseed) {
                    173: 	$rndseed=time;
                    174: 	$ENV{'form.rndseed'}=$rndseed;
1.58      www       175:       }
1.67      albertel  176:       &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval);
                    177:     }
1.55      www       178:     ($status,$accessmsg) = &Apache::lonhomework::check_access('0');
1.22      albertel  179:     push (@Apache::inputtags::status,$status);
1.24      albertel  180:     my $expression='$external::datestatus="'.$status.'";';
                    181:     $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
                    182:     &Apache::run::run($expression,$safeeval);
1.54      www       183:     if (( $status eq 'CLOSED' ) ||
                    184:         ( $status eq 'UNCHECKEDOUT') ||
                    185:         ( $status eq 'BANNED')) {
1.21      albertel  186:       my $bodytext=&Apache::lonxml::get_all_text("/problem",$$parser[$#$parser]);
                    187:       if ( $target eq "web" ) {
1.41      albertel  188: 	$result.= $head_tag_start.'</head>';
1.54      www       189:         my $msg=$body_tag_start.
                    190: 	    '<h1>Not open to be viewed</h1>';
                    191:         if ($status eq 'CLOSED') {
1.55      www       192: 	    $msg.='The problem '.$accessmsg;
1.54      www       193: 	} elsif ($status eq 'UNCHECKEDOUT') {
1.65      albertel  194:             $msg.=&checkout_msg;
1.54      www       195:         }
1.67      albertel  196: 	$result.=$msg.'<br />';
                    197:       }
                    198:     } elsif ($target eq 'web') {
                    199:       my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
                    200:       if ($name eq '') { 
                    201: 	$name=&Apache::lonnet::EXT('resource.title');
                    202: 	if ($name eq 'con_lost') { $name = ''; }
1.21      albertel  203:       }
1.67      albertel  204:       $Apache::lonhomework::name=$name;
                    205:       if ($status eq 'CAN_ANSWER') {
                    206: 	# create a page header and exit
                    207: 	$result.="$head_tag_start<title>$name</title></head>\n
1.41      albertel  208:               $body_tag_start\n
1.36      albertel  209:               <form name=\"lonhomework\" method=\"POST\" action=\"".$ENV{'request.uri'}."\">".
                    210: 		'<input type="hidden" name="submitted" value="yes" />';
1.67      albertel  211: 	if ($ENV{'request.state'} eq "construct") {
                    212: 	  $result.=
                    213: 	    '<input type="hidden" name="problemmode" value="View" />
                    214:              <input type="submit" name="problemmode" value="Edit" />
1.73    ! albertel  215:              <input type="submit" name="problemmode" value="EditXML" />
1.67      albertel  216:              Random Seed:<input type="text" name="rndseed" width="10" value="'.
1.72      albertel  217: 	       $rndseed.'" />
1.73    ! albertel  218:              <input type="submit" name="changerandseed" value="Change" />
1.72      albertel  219:              <input type="submit" name="resetdata" value="Reset Submissions" />
                    220:              <hr />';
1.67      albertel  221: 	}
                    222: 	# if we are viewing someone else preserve that info
                    223: 	if (defined $ENV{'form.grade_symb'}) {
                    224: 	  foreach my $field ('symb','courseid','domain','username') {
                    225: 	    $result .= '<input type="hidden" name="grade_'.$field.
                    226: 	      '" value="'.$ENV{"form.grade_$field"}.'" />'."\n";
                    227: 	  }
1.65      albertel  228: 	}
1.67      albertel  229:       } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER'
                    230: 	       || $status eq 'CLOSED') {
                    231: 	$result.=$head_tag_start.
                    232: 	  "<title>$name</title></head>\n$body_tag_start\n";
1.65      albertel  233:       }
1.22      albertel  234:     }
1.67      albertel  235:   } elsif ($target eq 'edit') {
1.41      albertel  236:     $result.=$head_tag_start."</head>".$body_tag_start.
1.67      albertel  237:       '<form name="lonhomework" method="POST" action="'.
                    238: 	$ENV{'request.uri'}.'">
1.41      albertel  239:        <input type="hidden" name="submitted" value="edit" />
                    240:        <input type="hidden" name="problemmode" value="Edit" />
                    241:        <input type="submit" name="problemmode" value="View" />
1.73    ! albertel  242:        <input type="submit" name="problemmode" value="EditXML" />
1.41      albertel  243:        <input type="submit" name="Undo" value="undo" /> <hr />
1.49      albertel  244:        <input type="submit" name="submit" value="Submit Changes" /><br />
1.41      albertel  245:       ';
1.39      albertel  246:     my $temp=&Apache::edit::insertlist($target,$token);
1.36      albertel  247:     $result.=$temp;
1.67      albertel  248:   } elsif ($target eq 'modified') {
1.37      albertel  249:     $result=$token->[4];
                    250:     $result.=&Apache::edit::handle_insert();
1.67      albertel  251:   } else {
                    252:     # page_start returned a starting result, delete it if we don't need it
                    253:     $result = '';
1.37      albertel  254:   }
1.67      albertel  255:   return $result;
1.9       albertel  256: }
                    257: 
                    258: sub end_problem {
1.40      albertel  259:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.16      albertel  260:   my $result='';
1.24      albertel  261:   my $status=$Apache::inputtags::status['-1'];
1.68      albertel  262:   if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ) {
1.28      albertel  263:     if ( $target eq 'grade' && $Apache::inputtags::part eq '0' &&
                    264:        $status eq 'CAN_ANSWER') {
1.19      albertel  265:       # if part is zero, no <part>s existed, so we need to the grading
                    266:       &Apache::inputtags::grade;
1.68      albertel  267:     } elsif ( $target eq 'web' && $Apache::inputtags::part eq '0') {
1.19      albertel  268:       # if part is zero, no <part>s existed, so we need show the current 
                    269:       # grading status
1.20      albertel  270:       $result.= &Apache::inputtags::gradestatus($Apache::inputtags::part);
1.41      albertel  271:     }
1.68      albertel  272:     if (
                    273: 	($target eq 'web' && ($ENV{'request.state'} ne 'construct')) ||
                    274: 	($target eq 'answer')
                    275:        ) {
1.22      albertel  276:       if ($status eq 'CAN_ANSWER') {
                    277: 	$result.="</form></body>\n"; 
1.28      albertel  278:       } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER') {
1.41      albertel  279: 	$result.="</body>\n";
                    280:       }
1.50      albertel  281:       $result.=&Apache::lonxml::xmlend();
1.22      albertel  282:     }
1.65      albertel  283:     if ($target eq 'grade') { 
                    284:       &Apache::lonhomework::showhash(%Apache::lonhomework::results);
                    285:       &finalize_storage();
                    286:     }
                    287:   } elsif ($target eq 'meta') {
1.18      albertel  288:     if ($Apache::inputtags::part eq '0') {
1.16      albertel  289:       $result=&Apache::response::mandatory_part_meta;
                    290:     }
1.65      albertel  291:   } elsif ($target eq 'edit') {
1.34      albertel  292:     &Apache::lonxml::debug("in end_problem with $target, edit");
1.48      albertel  293:     $result='<br /><input type="submit" name="submit" value="Submit Changes" />';
                    294:   }
                    295:   return $result;
                    296: }
                    297: 
                    298: sub start_library {
                    299:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    300:   my ($result,$head_tag_start,$body_tag_start)=
                    301:     &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
                    302:   if ($target eq 'edit') {
                    303:     $result.=$head_tag_start."</head>".$body_tag_start.
                    304:       '<form name="lonhomework" method="POST" action="'.$ENV{'request.uri'}.'">
                    305:        <input type="hidden" name="submitted" value="edit" />
                    306:        <input type="hidden" name="problemmode" value="Edit" />
                    307:        <input type="submit" name="problemmode" value="View" />
                    308:        <input type="submit" name="Undo" value="undo" /> <hr />
                    309:       ';
                    310:     my $temp=&Apache::edit::insertlist($target,$token);
                    311:     $result.=$temp;
                    312:     return $result;
                    313:   }
                    314:   if ($target eq 'modified') {
                    315:     $result=$token->[4];
                    316:     $result.=&Apache::edit::handle_insert();
                    317:     return $result;
                    318:   }
                    319:   return '';
                    320: }
                    321: 
                    322: sub end_library {
                    323:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    324:   my $result='';
                    325:   if ($target eq 'edit') {
1.34      albertel  326:     $result='<br /><input type="submit" name="submit" value="Submit Changes" />';
                    327:   }
1.16      albertel  328:   return $result;
1.1       albertel  329: }
                    330: 
                    331: sub start_block {
1.40      albertel  332:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.1       albertel  333: 
1.68      albertel  334:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
1.38      albertel  335:     my $code = @$parstack[$#$parstack];
                    336:     $code =~ s/\"//g;
                    337:     $code .=';return $condition;';
                    338:     #  print "<br />$code<br />";
                    339:     my $result = &Apache::run::run($code,$safeeval);
                    340:     &Apache::lonxml::debug("block :$code: returned :$result:");
                    341:     if ( ! $result ) { 
                    342:       my $skip=&Apache::lonxml::get_all_text("/block",$$parser[$#$parser]);
                    343:       &Apache::lonxml::debug("skipping ahead :$skip: $$parser[$#$parser]");
                    344:     }
1.1       albertel  345:   }
                    346:   return "";
                    347: }
                    348: 
                    349: sub end_block {
1.38      albertel  350:   return '';
1.4       tsai      351: }
                    352: 
                    353: sub start_while {
1.40      albertel  354:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.4       tsai      355: 
                    356:   my $code = @$parstack[$#$parstack];
                    357:   $code =~ s/\"//g;
                    358:   $code .=';return $condition;';
                    359: 
1.5       tsai      360:   push( @Apache::structuretags::whileconds, $code); 
1.4       tsai      361:   my $result = &Apache::run::run($code,$safeeval);
                    362:   my $bodytext=$$parser[$#$parser]->get_text("/while");
1.5       tsai      363:   push( @Apache::structuretags::whilebody, $bodytext);
                    364:   if ( $result ) { 
1.8       albertel  365:     &Apache::lonxml::newparser($parser,\$bodytext);
1.4       tsai      366:   }
                    367:   return "";
                    368: }
                    369: 
                    370: sub end_while {
1.40      albertel  371:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.5       tsai      372:   my $code = pop @Apache::structuretags::whileconds;
                    373:   my $bodytext = pop @Apache::structuretags::whilebody;
                    374:   my $result = &Apache::run::run($code,$safeeval);
                    375:   if ( $result ) { 
1.8       albertel  376:     &Apache::lonxml::newparser($parser,\$bodytext);
1.5       tsai      377:   } 
                    378:   return "";
1.1       albertel  379: }
1.6       tsai      380: 
                    381: # <randomlist> 
                    382: #  <tag1>..</tag1>
                    383: #  <tag2>..</tag2>
                    384: #  <tag3>..</tag3>
                    385: #  ... 
                    386: # </randomlist>
                    387: sub start_randomlist {
1.40      albertel  388:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.71      albertel  389:   if ($target eq 'answer' || $target eq 'grade' || $target eq 'web') {
                    390:     my $body= &Apache::lonxml::get_all_text("/randomlist",$$parser[$#$parser]);
                    391:     my $b_parser= HTML::TokeParser->new(\$body);
                    392:     my $b_tok;
                    393:     my @randomlist;
                    394:     my $list_item;
                    395:     while($b_tok = $b_parser->get_token() ) {
                    396:       if($b_tok->[0] eq 'S') { # start tag
                    397: 	# get content of the tag until matching end tag
                    398: 	# get all text upto the matching tag
                    399: 	# and push the content into @randomlist
                    400: 	$list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],$b_parser);
                    401: 	$list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
                    402: 	push(@randomlist,$list_item);
                    403: 	#  print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4], $list_item</b>";
                    404:       }
                    405:       if($b_tok->[0] eq 'T') { # text
                    406: 	# what to do with text in between tags?
                    407: 	#  print "<b>TEXT $b_tok->[1]</b><br />";
                    408:       }
                    409:       # if($b_tok->[0] eq 'E') { # end tag, should not happen
                    410:       #  print "<b>END-TAG $b_tok->[1]</b><br />";
                    411:       # }
                    412:     }
1.6       tsai      413: 
1.71      albertel  414:     my @idx_arr = (0 .. $#randomlist);
                    415:     &Apache::structuretags::shuffle(\@idx_arr);
                    416:     my $bodytext = '';
                    417:     for(0 .. $#randomlist) {
                    418:       $bodytext .= "$randomlist[ $idx_arr[$_] ]";
1.6       tsai      419:     }
1.71      albertel  420:     &Apache::lonxml::newparser($parser,\$bodytext);
1.7       tsai      421:   }
1.6       tsai      422:   return "";
1.7       tsai      423: }
                    424: 
                    425: sub shuffle {
                    426:     my $a=shift;
                    427:     my $i;
1.70      albertel  428:     if (defined(@$a)) {
                    429:       &Apache::response::setrandomnumber();
                    430:       for($i=@$a;--$i;) {
                    431: 	my $j=int rand($i+1);
                    432: 	next if $i == $j;
                    433: 	@$a[$i,$j] = @$a[$j,$i];
                    434:       }
1.7       tsai      435:     }
1.6       tsai      436: }
                    437: 
                    438: sub end_randomlist {
1.46      albertel  439:   return '';
1.6       tsai      440: }
                    441: 
1.11      albertel  442: sub start_part {
1.40      albertel  443:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.39      albertel  444:   my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
1.47      albertel  445:   if ($id eq '') { $id = $Apache::lonxml::curdepth; }
1.14      albertel  446:   $Apache::inputtags::part=$id;
1.18      albertel  447:   @Apache::inputtags::responselist = ();
1.51      albertel  448:   @Apache::inputtags::previous=();
1.15      www       449:   if ($target eq 'meta') {
1.16      albertel  450:     return &Apache::response::mandatory_part_meta;
1.68      albertel  451:   } elsif ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
1.55      www       452:     my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
1.23      albertel  453:     push (@Apache::inputtags::status,$status);
                    454:     my $expression='$external::datestatus="'.$status.'";';
                    455:     $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
                    456:     &Apache::run::run($expression,$safeeval);
                    457:     if ( $status eq 'CLOSED' ) {
1.21      albertel  458:       my $bodytext=&Apache::lonxml::get_all_text("/part",$$parser[$#$parser]);
                    459:       if ( $target eq "web" ) {
1.55      www       460: 	return "<br />Part is not open to be viewed. It $accessmsg<br />";
1.21      albertel  461:       }
                    462:     }
1.15      www       463:   }
1.19      albertel  464:   return '';
1.11      albertel  465: }
                    466: 
                    467: sub end_part {
1.40      albertel  468:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.18      albertel  469:   &Apache::lonxml::debug("in end_part $target ");
1.28      albertel  470:   my $status=$Apache::inputtags::status['-1'];
1.23      albertel  471:   pop @Apache::inputtags::status;
1.19      albertel  472:   if ( $target eq 'meta' ) { return ''; }
1.37      albertel  473:   if ( $target eq 'grade' && $status eq 'CAN_ANSWER') {
                    474:     return &Apache::inputtags::grade;
1.28      albertel  475:   }
1.37      albertel  476:   if ($target eq 'web') {
                    477:     return &Apache::inputtags::gradestatus($Apache::inputtags::part);
                    478:   }
                    479:   return '';
1.11      albertel  480: }
1.1       albertel  481: 
1.25      albertel  482: sub start_preduedate {
1.40      albertel  483:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.68      albertel  484:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
1.29      albertel  485:     if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
                    486: 	$Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER' ) {
1.26      albertel  487:       &Apache::lonxml::get_all_text("/preduedate",$$parser[$#$parser]);
1.24      albertel  488:     }
                    489:   }
                    490:   return '';
                    491: }
                    492: 
1.25      albertel  493: sub end_preduedate {
1.24      albertel  494:   return '';
                    495: }
                    496: 
1.25      albertel  497: sub start_postanswerdate {
1.40      albertel  498:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.34      albertel  499:   if ($target eq 'web' || $target eq 'grade') {
1.24      albertel  500:     if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
1.26      albertel  501:       &Apache::lonxml::get_all_text("/postanswerdate",$$parser[$#$parser]);
1.24      albertel  502:     }
                    503:   }
                    504:   return '';
                    505: }
                    506: 
1.25      albertel  507: sub end_postanswerdate {
1.24      albertel  508:   return '';
                    509: }
                    510: 
1.25      albertel  511: sub start_notsolved {
1.40      albertel  512:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.68      albertel  513:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
1.24      albertel  514:     my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
                    515:     &Apache::lonxml::debug("not solved has :$gradestatus:");
                    516:     if ($gradestatus =~ /^correct/) {
                    517:       &Apache::lonxml::debug("skipping");
1.26      albertel  518:       &Apache::lonxml::get_all_text("/notsolved",$$parser[$#$parser]);
1.24      albertel  519:     }
                    520:   }
                    521:   return '';
                    522: }
                    523: 
1.25      albertel  524: sub end_notsolved {
1.24      albertel  525:   return '';
                    526: }
                    527: 
                    528: sub start_solved {
1.40      albertel  529:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.68      albertel  530:   if ($target eq 'web' || $target eq 'grade' || $target eq 'answer') {
1.24      albertel  531:     my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
                    532:     if ($gradestatus !~ /^correct/) {
                    533:       &Apache::lonxml::get_all_text("/solved",$$parser[$#$parser]);
                    534:     }
                    535:   }
                    536:   return '';
                    537: }
                    538: 
                    539: sub end_solved {
                    540:   return '';
                    541: }
1.34      albertel  542: 
                    543: sub start_startouttext {
1.40      albertel  544:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.35      albertel  545:   my @result=(''.'');
                    546:   if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
                    547:   return (@result);
1.34      albertel  548: }
                    549: sub end_startouttext {
1.40      albertel  550:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.34      albertel  551:   my $result='';
1.35      albertel  552:   my $text='';
                    553: 
1.34      albertel  554:   if ($target eq 'edit') {
1.70      albertel  555:     $text=&Apache::lonxml::get_all_text("endouttext",$$parser[-1]);
1.43      albertel  556:     $result.=&Apache::edit::start_table($token)."<tr><td>Text Block</td>
1.42      albertel  557: <td>Delete:".
                    558:   &Apache::edit::deletelist($target,$token)
                    559:   ."</td>
                    560: <td>".
                    561:   &Apache::edit::insertlist($target,$token).
                    562:     "</td>
                    563: </tr><tr><td colspan=\"3\">\n".
1.45      albertel  564: 	&Apache::edit::editfield($token->[1],$text,"",50,4);
1.35      albertel  565:   }
                    566:   if ($target eq 'modified') {
                    567:     $text=&Apache::lonxml::get_all_text("endouttext",$$parser['-1']);
                    568:     $result='<startouttext />'.&Apache::edit::modifiedfield();
1.34      albertel  569:   }
                    570:   return $result;
                    571: }
                    572: sub start_endouttext {
1.40      albertel  573:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.34      albertel  574:   my $result='';
1.43      albertel  575:   if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
1.35      albertel  576:   if ($target eq "modified") { $result='<endouttext />'; }
1.34      albertel  577:   return $result;
                    578: }
                    579: sub end_endouttext {
1.40      albertel  580:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.35      albertel  581:   my @result=('','');
                    582:   if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
                    583:   return (@result);
1.34      albertel  584: }
1.45      albertel  585: sub delete_startouttext {
                    586:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    587: #  my $text=&Apache::lonxml::get_all_text("endouttext",$$parser['-1']);
                    588:   my $text=$$parser['-1']->get_text("/endouttext");
1.69      albertel  589:   my $ntoken=$$parser['-1']->get_token();
                    590:   &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
                    591:   &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
1.45      albertel  592:   # Deleting 2 parallel tag pairs, but we need the numbers later to look like 
                    593:   # they did the last time round
1.69      albertel  594:   &Apache::lonxml::increasedepth($ntoken);
                    595:   &Apache::lonxml::decreasedepth($ntoken);
1.45      albertel  596:   return 1;
                    597: }
1.34      albertel  598: 
1.1       albertel  599: 1;
                    600: __END__

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