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