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

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

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