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

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

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