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

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

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