Annotation of loncom/homework/structuretags.pm, revision 1.190
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.190 ! albertel 4: # $Id: structuretags.pm,v 1.189 2003/06/23 19:55:18 sakharuk 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.133 sakharuk 32:
1.1 albertel 33: package Apache::structuretags;
34:
35: use strict;
36: use Apache::lonnet;
1.101 sakharuk 37: use Apache::File();
1.147 www 38: use Apache::lonmenu;
1.1 albertel 39:
1.78 harris41 40: BEGIN {
1.170 www 41: &Apache::lonxml::register('Apache::structuretags',('block','languageblock','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','startouttext','endouttext'));
1.10 albertel 42: }
43:
44: sub start_web {
1.159 albertel 45: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.182 albertel 46: if (!($target eq 'web' || $target eq 'edit' || $target eq 'modified' ||
47: $target eq 'answer' || $target eq 'grade' || $target eq 'meta' )) {
48: my $bodytext=&Apache::lonxml::get_all_text("/web",$parser);
1.159 albertel 49: }
50: return '';
1.10 albertel 51: }
52:
53: sub end_web {
1.44 ng 54: return '';
1.10 albertel 55: }
56:
57: sub start_tex {
1.159 albertel 58: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.182 albertel 59: if (!($target eq 'tex' || $target eq 'edit' || $target eq 'modified' ||
60: $target eq 'answer' || $target eq 'grade' || $target eq 'meta' )) {
61: &Apache::lonxml::debug("tex 1");
62: my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser);
1.159 albertel 63: }
64: return '';
1.10 albertel 65: }
66:
67: sub end_tex {
1.44 ng 68: return '';
1.9 albertel 69: }
70:
1.48 albertel 71: sub page_start {
1.159 albertel 72: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
73: my %found;
74: foreach my $taginside ($tagstack) {
75: foreach my $taglookedfor ('html','body','form') {
76: if ($taginside =~ /^$taglookedfor$/i) {$found{$taglookedfor} = 1;}
77: }
78: }
79:
80: my $result;
81: my $head_tag_start;
82: if (!defined($found{'html'})) {
83: $result=&Apache::londefdef::start_html($target,$token,$tagstack,
84: $parstack,$parser,$safeeval);
85: $head_tag_start='<head>'.&Apache::lonmenu::registerurl(undef,$target);
86: }
87: my $body_tag_start;
88: if (!defined($found{'body'})) {
89: $body_tag_start='<body onLoad="'.&Apache::lonmenu::loadevents().'" '.
90: 'onUnload="'.&Apache::lonmenu::unloadevents().'" ';
91: my $background=&Apache::lonxml::get_param('background',$parstack,
92: $safeeval);
93: if ($background) {
94: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
95: $background;
96: $body_tag_start.='background="'.$background.'" ';
97: } else {
98: my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,
99: $safeeval);
100: if ($bgcolor) {
101: $body_tag_start.='bgcolor="'.$bgcolor.'" ';
102: } else {
103: $body_tag_start.='bgcolor="#ffffff"';
104: }
105: }
106: $body_tag_start.='>'.&Apache::lonmenu::menubuttons(undef,$target,1);
107: if ($target eq 'web' && $ENV{'request.state'} ne 'construct') {
1.165 albertel 108: my ($symb,undef,undef,undef,$publicuser)=
109: &Apache::lonxml::whichuser();
110: if ($symb eq '' && !$publicuser) {
1.159 albertel 111: my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference");
1.162 albertel 112: $help="Browsing resource, all submissions are temporary.<br />";
1.159 albertel 113: $body_tag_start.=$help;
114: }
115: }
116: }
117: my $form_tag_start;
118: if (!defined($found{'form'})) {
119: $form_tag_start='<form name="lonhomework" method="POST" action="'.
120: $ENV{'request.uri'}.'">';
121: }
122: return ($result,$head_tag_start,$body_tag_start,$form_tag_start);
1.105 albertel 123: }
124:
1.141 matthew 125: #use Time::HiRes();
1.105 albertel 126: sub get_resource_name {
1.159 albertel 127: my ($parstack,$safeeval)=@_;
128: my $name=&Apache::lonnet::gettitle();
129: if ($name eq '') {
130: $name=&Apache::lonnet::EXT('resource.title');
131: if ($name eq 'con_lost') { $name = ''; }
132: }
133: $Apache::lonhomework::name=$name;
134: return $name;
1.105 albertel 135: }
136:
137: sub setup_rndseed {
1.159 albertel 138: my ($safeeval)=@_;
139: my $rndseed;
1.162 albertel 140: my ($symb)=&Apache::lonxml::whichuser();
141: if ($ENV{'request.state'} eq "construct" || $symb eq '') {
1.159 albertel 142: $rndseed=$ENV{'form.rndseed'};
143: if (!$rndseed) {
1.162 albertel 144: $rndseed=$Apache::lonhomework::history{'rndseed'};
145: if (!$rndseed) {
146: $rndseed=time;
147: $ENV{'form.rndseed'}=$rndseed;
148: }
149: }
1.175 albertel 150: if ($ENV{'form.resetdata'} eq 'New Problem Variation' ||
151: $ENV{'form.newrandomization'} eq 'New Randomization') {
1.190 ! albertel 152: srand(time);
! 153: $rndseed=int(rand(2100000000));
1.159 albertel 154: $ENV{'form.rndseed'}=$rndseed;
1.180 albertel 155: delete($ENV{'form.resetdata'});
156: delete($ENV{'form.newrandomization'});
1.159 albertel 157: }
1.187 albertel 158: if (defined($rndseed) && $rndseed ne int($rndseed)) {
159: $rndseed=join(',',&Math::Random::random_seed_from_phrase($rndseed));
160: }
1.159 albertel 161: &Apache::lonxml::debug("Setting rndseed to $rndseed");
162: &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval);
163: }
164: return $rndseed;
1.105 albertel 165: }
166:
167: sub problem_edit_header {
1.159 albertel 168: return '<input type="hidden" name="submitted" value="edit" />
1.105 albertel 169: <input type="hidden" name="problemmode" value="Edit" />
170: <input type="submit" name="problemmode" value="Discard Edits and View" />
171: <input type="submit" name="problemmode" value="EditXML" />
172: <input type="submit" name="Undo" value="undo" /> <hr />
1.135 www 173: <input type="submit" name="submit" value="Submit Changes and Edit" />
174: <input type="submit" name="submit" value="Submit Changes and View" /><br /><p> </p><table border="0"><tr><td bgcolor="#DDDDDD">
1.105 albertel 175: ';
176: }
177:
178: sub problem_edit_footer {
1.159 albertel 179: return '</td></tr></table><br /><input type="submit" name="submit" value="Submit Changes and Edit" />
1.105 albertel 180: <input type="submit" name="submit" value="Submit Changes and View" />';
181: }
182:
183: sub problem_web_to_edit_header {
1.159 albertel 184: my ($rndseed)=@_;
185: my $result.='<input type="hidden" name="problemmode" value="View" />
1.105 albertel 186: <input type="submit" name="problemmode" value="Edit" />
187: <input type="submit" name="problemmode" value="EditXML" />
1.175 albertel 188: <input type="submit" name="newrandomization" value="New Randomization" />
1.105 albertel 189: <input type="submit" name="resetdata" value="Reset Submissions" />
1.175 albertel 190: <nobr><input type="submit" name="changerandseed" value="Change Random Seed To:" />
191: <input type="text" name="rndseed" width="10" value="'.
192: $rndseed.'"
193: onChange="javascript:document.lonhomework.changerandseed.click()" /></nobr>
1.105 albertel 194: <input type="checkbox" name="showallfoils" ';
1.159 albertel 195: if (defined($ENV{'form.showallfoils'})) { $result.='checked="on"'; }
196: $result.= ' /> Show All Foils
1.105 albertel 197: <hr />';
1.159 albertel 198: my $numtoanalyze=$ENV{'form.numtoanalyze'};
1.176 albertel 199: if (!$numtoanalyze) { $numtoanalyze=20; }
200: $result.= '<input type="submit" name="problemmode" value="Calculate answers" /> for
1.136 albertel 201: <input type="text" name="numtoanalyze" value="'.
1.176 albertel 202: $numtoanalyze.'" size="5" /> versions of this problem.'.
203: &Apache::loncommon::help_open_topic("Analyze_Problem",
204: '',undef,undef,300).
205: '<hr />';
1.159 albertel 206: return $result;
1.48 albertel 207: }
208:
1.65 albertel 209: sub initialize_storage {
1.159 albertel 210: %Apache::lonhomework::results=();
1.162 albertel 211: %Apache::lonhomework::history=();
1.159 albertel 212: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
1.162 albertel 213: if ($ENV{'request.state'} eq 'construct' || $symb eq '') {
1.159 albertel 214: %Apache::lonhomework::history=
215: &Apache::lonnet::tmprestore($ENV{'request.uri'},'',$domain,$name);
216: my ($temp)=keys %Apache::lonhomework::history ;
217: &Apache::lonxml::debug("Return message of $temp");
218: } else {
219: %Apache::lonhomework::history=
220: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
221: }
222: #ignore error conditions
1.67 albertel 223: my ($temp)=keys %Apache::lonhomework::history ;
1.159 albertel 224: if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
1.65 albertel 225: }
226:
227: # -------------------------------------------------------------finalize_storage
228: # Stores away the result has to a student's environment
229: # checks form.grade_ for specific values, other wises stores
230: # to the running users environment
231: sub finalize_storage {
1.159 albertel 232: my $result;
233: my ($temp) = keys %Apache::lonhomework::results;
234: if ( $temp ne '' ) {
235: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
1.162 albertel 236: if ($ENV{'request.state'} eq 'construct' || $symb eq '') {
237: $Apache::lonhomework::results{'rndseed'}=$ENV{'form.rndseed'};
1.159 albertel 238: $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,
239: $ENV{'request.uri'},'',$domain,$name);
240: &Apache::lonxml::debug('Construct Store return message:'.$result);
241: } else {
242: $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
243: $symb,$courseid,$domain,$name);
244: &Apache::lonxml::debug('Store return message:'.$result);
245: }
1.67 albertel 246: }
1.159 albertel 247: return $result;
1.65 albertel 248: }
249:
250: sub checkout_msg {
1.159 albertel 251: return (<<ENDCHECKOUT);
1.65 albertel 252: <h2>The resource needs to be checked out</h2>
253: As a resource gets checked out, a unique timestamped ID is given to it, and a
254: permanent record is left in the system.<p />
255: <font color=red>
256: Checking out resources is subject to course policies, and may exclude future
257: credit even if done erroneously.<p />
1.91 albertel 258: </font>
259: <form name="checkout" method="POST" action="$ENV{'request.uri'}">
260: <input type="hidden" name="doescheckout" value="yes" />
261: <input type="button" name="checkoutbutton" value="Check out Exam for Viewing" onClick="javascript:if (confirm('Check out Exam?')) { document.checkout.submit(); }" />
1.65 albertel 262: </form>
263: ENDCHECKOUT
264: }
265:
1.9 albertel 266: sub start_problem {
1.159 albertel 267: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19 albertel 268:
1.184 albertel 269: if ( $Apache::inputtags::part ne '' ||
270: $Apache::lonhomework::parsing_a_problem) {
271: &Apache::lonxml::error('Only one <problem> allowed in a .problem file');
272: #my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
1.159 albertel 273: return '';
274: }
1.184 albertel 275:
276: $Apache::lonhomework::parsing_a_problem=1;
1.161 albertel 277: #initialize globals
1.159 albertel 278: $Apache::inputtags::part='0';
1.177 albertel 279: @Apache::inputtags::partlist=('0');
1.159 albertel 280: @Apache::inputtags::responselist = ();
1.177 albertel 281: @Apache::inputtags::importlist = ();
1.159 albertel 282: @Apache::inputtags::previous=();
283: @Apache::inputtags::previous_version=();
284: $Apache::structuretags::printanswer='No';
1.161 albertel 285: @Apache::structuretags::whileconds=();
286: @Apache::structuretags::whilebody=();
287: @Apache::structuretags::whileline=();
1.166 albertel 288: $Apache::lonhomework::scantronmode=0;
1.169 albertel 289: $Apache::lonhomework::problemstatus=
290: &Apache::lonnet::EXT('resource.0.problemstatus');
1.166 albertel 291:
292: if (defined($ENV{'scantron.maxquest'})) {
293: $Apache::lonhomework::scantronmode=1;
294: }
1.161 albertel 295:
1.159 albertel 296: if ($target ne 'analyze') {
297: &initialize_storage();
298: if ($target eq 'web') {
299: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
300: }
301: $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
302: &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
303: }
1.164 albertel 304: if ($Apache::lonhomework::type eq '' ) {
1.159 albertel 305: my $uri=$ENV{'request.uri'};
306: if ($uri=~/\.(\w+)$/) {
307: $Apache::lonhomework::type=$1;
308: &Apache::lonxml::debug("Using type of $1");
309: } else {
310: $Apache::lonhomework::type='problem';
311: &Apache::lonxml::debug("Using default type, problem, :$uri:");
312: }
1.87 albertel 313: }
1.58 www 314:
1.159 albertel 315: #added vars to the scripting enviroment
316: my $expression='$external::part='.$Apache::inputtags::part.';';
1.24 albertel 317: &Apache::run::run($expression,$safeeval);
1.159 albertel 318: my $status;
319: my $accessmsg;
320:
321: #should get back a <html> or the neccesary stuff to start XML/MathML
322: my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
323: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
324: if ($target eq 'tex' and $ENV{'request.symb'} =~ m/\.page_/) {$result='';}
325:
326: if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval); }
327: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
328: $target eq 'tex') {
329: #handle exam checkout
330: if ($Apache::lonhomework::type eq 'exam') {
331: my $token=
332: $Apache::lonhomework::history{"resource.0.outtoken"};
333: if (($ENV{'form.doescheckout'}) && (!$token)) {
334: $token=&Apache::lonxml::maketoken();
335: $Apache::lonhomework::history{"resource.0.outtoken"}=
336: $token;
337: }
338: $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token);
1.142 albertel 339: }
1.159 albertel 340:
341: #handle rand seed in construction space
342: my $rndseed=&setup_rndseed($safeeval);
1.162 albertel 343: my ($symb)=&Apache::lonxml::whichuser();
1.163 albertel 344: if ($ENV{'request.state'} ne "construct" && $symb eq '') {
1.162 albertel 345: $form_tag_start.='<input type="hidden" name="rndseed" value="'.
346: $rndseed.'" />'.
347: '<input type="submit" name="resetdata"
1.164 albertel 348: value="New Problem Variation" />'.
349: '<input type="hidden" name="username"
1.185 albertel 350: value="'.$ENV{'form.username'}.'" /> <br />';
1.162 albertel 351: }
1.159 albertel 352: ($status,$accessmsg) = &Apache::lonhomework::check_access('0');
353: push (@Apache::inputtags::status,$status);
354: my $expression='$external::datestatus="'.$status.'";';
355: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
356: &Apache::run::run($expression,$safeeval);
357: &Apache::lonxml::debug("Got $status");
358: if (( $status eq 'CLOSED' ) ||
359: ( $status eq 'UNCHECKEDOUT') ||
360: ( $status eq 'BANNED') ||
361: ( $status eq 'UNAVAILABLE')) {
362: my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
363: if ( $target eq "web" ) {
364: $result.= $head_tag_start.'</head>';
365: my $msg=$body_tag_start;
366: if ($status eq 'UNAVAILABLE') {
367: $result.='<h1>Unable to determine if this resource is open due to network problems. Please try again later.</h1>';
368: } else {
369: $result.='<h1>Not open to be viewed</h1>';
370: }
371: if ($status eq 'CLOSED') {
372: $msg.='The problem '.$accessmsg;
373: } elsif ($status eq 'UNCHECKEDOUT') {
374: $msg.=&checkout_msg;
375: }
376: $result.=$msg.'<br />';
377: } elsif ($target eq 'tex') {
378: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
379: if ($status eq 'UNAVAILABLE') {
380: $result.='Unable to determine if this resource is open due to network problems. Please try again later.\vskip 0 mm ';
381: } else {
382: $result.="Problem is not open to be viewed. It $accessmsg \\vskip 0 mm ";
383: }
384: }
385: } elsif ($target eq 'web') {
386: my $name= &get_resource_name($parstack,$safeeval);
387: if ($status eq 'CAN_ANSWER') {
388: # create a page header and exit
389: $result.="$head_tag_start<title>$name</title></head>
1.158 sakharuk 390: $body_tag_start \n $form_tag_start".
1.159 albertel 391: '<input type="hidden" name="submitted" value="yes" />';
392: if ($ENV{'request.state'} eq "construct") {
1.187 albertel 393: $result.= &problem_web_to_edit_header($ENV{'form.rndseed'});
1.159 albertel 394: }
395: # if we are viewing someone else preserve that info
396: if (defined $ENV{'form.grade_symb'}) {
397: foreach my $field ('symb','courseid','domain','username') {
398: $result .= '<input type="hidden" name="grade_'.$field.
399: '" value="'.$ENV{"form.grade_$field"}.'" />'."\n";
400: }
401: }
402: } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER'
403: || $status eq 'CLOSED' || $status eq 'UNAVALAILABLE') {
404: $result.=$head_tag_start.
405: "<title>$name</title></head>\n$body_tag_start\n";
406: }
407: } elsif ($target eq 'tex') {
1.178 sakharuk 408: my $startminipage = '';
409: if ($ENV{'form.problem_split'} ne 'yes') {
410: $startminipage = '\begin{minipage}{\textwidth}';
411: }
1.159 albertel 412: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
413: if ($name eq '') {
414: $name=&Apache::lonnet::EXT('resource.title');
415: if ($name eq 'con_lost') { $name = ''; }
416: }
417: $Apache::lonhomework::name=$name;
418: my $id = $Apache::inputtags::part;
419: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
420: my $allkeys=&Apache::lonnet::metadata($ENV{'request.uri'},'keys');
421: my @allkeys = split /,/,$allkeys;
422: my $allow_print_points = 0;
423: foreach my $partial_key (@allkeys) {
424: if ($partial_key=~m/weight/) {
425: $allow_print_points++;
426: }
427: }
428: my $duedate = &Apache::lonnet::EXT("resource.$id.duedate");
429: $duedate = POSIX::strftime("%c",localtime($duedate));
430: my $temp_file;
431: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.due";
432: if (-e $filename) {
433: $temp_file = Apache::File->new($filename);
434: } else {
435: $temp_file = Apache::File->new('>>'.$filename);
436: }
437: my @due_file_content = <$temp_file>;
438: my $due_file_content = $due_file_content[$#due_file_content];
439: chomp $due_file_content;
440: my $name_of_resourse= &get_resource_name($parstack,$safeeval);
441: if ($due_file_content ne $duedate) {
442: $temp_file = Apache::File->new('>'.$filename);
443: print $temp_file "$duedate\n";
444: if (not $ENV{'request.symb'} =~ m/\.page_/) {
445: if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') {
1.178 sakharuk 446: $result .= '\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource <h2>"'.$name_of_resourse.'"</h2> located in <br /><small><b>'.$ENV{'request.uri'}.'</b></small><br /> STAMPOFPASSEDRESOURCEEND} \noindent\textit{Due date: '.$duedate.'} \vskip 1 mm\noindent '.$startminipage;
1.159 albertel 447: } else {
1.178 sakharuk 448: $result .= '\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource <h2>"'.$name_of_resourse.'"</h2> located in <br /><small><b>'.$ENV{'request.uri'}.'</b></small><br /> STAMPOFPASSEDRESOURCEEND} \noindent \vskip 1 mm \noindent'.$startminipage;
1.159 albertel 449: if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
450: }
1.104 sakharuk 451: } else {
1.159 albertel 452: $result .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\';
1.104 sakharuk 453: }
1.101 sakharuk 454: } else {
1.159 albertel 455: if (not $ENV{'request.symb'} =~ m/\.page_/) {
1.178 sakharuk 456: $result .= '\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource <h2>"'.$name_of_resourse.'"</h2> located in <br /><small><b>'.$ENV{'request.uri'}.'</b></small><br /> STAMPOFPASSEDRESOURCEEND} \noindent \vskip 1 mm\noindent'.$startminipage;
1.159 albertel 457: if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
458: } else {
459: $result .= '\vskip 1mm \\\\\\\\';
460: }
461: }
1.99 sakharuk 462: }
1.159 albertel 463: } elsif ($target eq 'edit') {
464: $result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
465: &problem_edit_header();
466: my $temp=&Apache::edit::insertlist($target,$token);
467: $result.=$temp;
468: } elsif ($target eq 'modified') {
469: $result=$token->[4];
470: $result.=&Apache::edit::handle_insert();
471: } else {
472: # page_start returned a starting result, delete it if we don't need it
473: $result = '';
1.99 sakharuk 474: }
1.159 albertel 475: return $result;
1.9 albertel 476: }
477:
478: sub end_problem {
1.159 albertel 479: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
480: my $result='';
481: my $status=$Apache::inputtags::status['-1'];
482: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
483: $target eq 'tex') {
484: if ( $target eq 'grade' && $Apache::inputtags::part eq '0' &&
485: $status eq 'CAN_ANSWER' ) {
486: # if part is zero, no <part>s existed, so we need to the grading
487: &Apache::inputtags::grade;
488: } elsif ( ($target eq 'web' || $target eq 'tex') &&
489: $Apache::inputtags::part eq '0' &&
490: $status ne 'UNCHECKEDOUT') {
491: # if part is zero, no <part>s existed, so we need show the current
492: # grading status
493: my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
494: $result.= $gradestatus;
495: }
496: if (
497: (($target eq 'web') && ($ENV{'request.state'} ne 'construct')) ||
498: ($target eq 'answer') || ($target eq 'tex')
499: ) {
500: if ($status eq 'CAN_ANSWER') {
1.172 albertel 501: if ($target ne 'tex' &&
502: $ENV{'form.answer_output_mode'} ne 'tex') {
503: $result.="</form></body>\n";
1.159 albertel 504: }
505: } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER' ||
506: $status eq 'UNCHECKEDOUT' ) {
1.189 sakharuk 507: if ($target ne 'tex' &&
508: $ENV{'form.answer_output_mode'} ne 'tex') {
1.159 albertel 509: $result.="</body>\n";
510: }
511: }
512: if ($target eq 'web') {
513: $result.=&Apache::lonxml::xmlend();
514: } elsif ($target eq 'tex') {
1.178 sakharuk 515: my $endminipage = '';
516: if ($ENV{'form.problem_split'} ne 'yes') {
517: $endminipage = '\end{minipage}';
518: }
1.174 sakharuk 519: $result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
1.159 albertel 520: if (not $ENV{'request.symb'} =~ m/\.page_/) {
1.178 sakharuk 521: $result .= $endminipage.'\end{document} ';
1.159 albertel 522: } else {
523: $result .= '';
524: }
525: }
526: }
527: if ($target eq 'grade') {
528: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
529: &finalize_storage();
530: }
1.172 albertel 531: if ($target eq 'answer' && ($ENV{'request.state'} eq 'construct')
1.173 albertel 532: && $ENV{'form.answer_output_mode'} ne 'tex') {
1.172 albertel 533: $result.='</html>'; # normally we get it from xmlend, but in CSTR
534: # we always show answer mode too.
1.159 albertel 535: }
536: } elsif ($target eq 'meta') {
537: if ($Apache::inputtags::part eq '0') {
1.179 albertel 538: @Apache::inputtags::response=();
1.159 albertel 539: $result=&Apache::response::mandatory_part_meta;
540: }
541: } elsif ($target eq 'edit') {
542: &Apache::lonxml::debug("in end_problem with $target, edit");
543: $result = &problem_edit_footer();
544: }
1.155 albertel 545:
1.177 albertel 546: if ($ENV{'request.state'} eq 'construct' && $target eq 'web') {
547: &Apache::inputtags::check_for_duplicate_ids();
548: }
1.159 albertel 549: undef(%Apache::lonhomework::history);
550: undef(%Apache::lonhomework::results);
551: undef($Apache::inputtags::part);
552: undef($Apache::lonhomework::parsing_a_problem);
553:
554: return $result;
1.48 albertel 555: }
556:
1.108 albertel 557:
1.48 albertel 558: sub start_library {
1.159 albertel 559: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
560: my ($result,$head_tag_start,$body_tag_start,$form_tag_start);
1.109 albertel 561:
1.159 albertel 562: if ($target eq 'edit') {
563: ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
564: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
565: $result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
566: &problem_edit_header();
567: my $temp=&Apache::edit::insertlist($target,$token);
568: $result.=$temp;
569: } elsif ($target eq 'modified') {
570: $result=$token->[4];
571: $result.=&Apache::edit::handle_insert();
572: } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
573: $ENV{'request.state'} eq "construct" ) {
574: ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
575: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
576: my $name=&get_resource_name($parstack,$safeeval);
577: my $rndseed=&setup_rndseed($safeeval);
578: $result.="$head_tag_start<title>$name</title></head>
1.105 albertel 579: $body_tag_start \n $form_tag_start".
1.159 albertel 580: '<input type="hidden" name="submitted" value="yes" />';
581: $result.=&problem_web_to_edit_header($rndseed);
582: }
583: return $result;
1.48 albertel 584: }
585:
586: sub end_library {
1.159 albertel 587: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
588: my $result='';
589: if ($target eq 'edit') {
590: $result=&problem_edit_footer();
591: } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
592: $ENV{'request.state'} eq "construct") {
593: $result.='</form></body>'.&Apache::lonxml::xmlend();
594: }
595: return $result;
1.1 albertel 596: }
597:
598: sub start_block {
1.131 albertel 599: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
600:
601: my $result;
1.1 albertel 602:
1.160 albertel 603: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.131 albertel 604: $target eq 'tex' || $target eq 'analyze') {
1.159 albertel 605: my $code = $token->[2]->{'condition'};
1.131 albertel 606: if ($code) {
1.137 albertel 607: if (!$Apache::lonxml::default_homework_loaded) {
608: &Apache::lonxml::default_homework_load($safeeval);
609: }
1.131 albertel 610: $result = &Apache::run::run($code,$safeeval);
611: &Apache::lonxml::debug("block :$code: returned :$result:");
612: } else {
613: $result='1';
614: }
615: if ( ! $result ) {
1.146 albertel 616: my $skip=&Apache::lonxml::get_all_text("/block",$parser);
1.131 albertel 617: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
618: }
619: $result='';
620: } elsif ($target eq 'edit') {
621: $result .=&Apache::edit::tag_start($target,$token);
622: $result .=&Apache::edit::text_arg('Test Condition:','condition',
623: $token,40);
624: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
625: } elsif ($target eq 'modified') {
626: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
627: $safeeval,'condition');
628: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.38 albertel 629: }
1.131 albertel 630: return $result;
1.1 albertel 631: }
632:
633: sub end_block {
1.167 www 634: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
635: my $result;
636: if ($target eq "edit") {
637: $result.= &Apache::edit::tag_end($target,$token,'');
638: }
639: return $result;
640: }
641:
642: sub start_languageblock {
643: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
644:
645: my $result;
646:
647: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
648: $target eq 'tex' || $target eq 'analyze') {
1.186 albertel 649: &Apache::lonxml::startredirection();
1.167 www 650: } elsif ($target eq 'edit') {
651: $result .=&Apache::edit::tag_start($target,$token);
652: $result .=&Apache::edit::text_arg('Include Language:','include',
653: $token,40);
654: $result .=&Apache::edit::text_arg('Exclude Language:','exclude',
655: $token,40);
656: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
657: } elsif ($target eq 'modified') {
658: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.168 albertel 659: $safeeval,'include',
660: 'exclude');
1.167 www 661: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
662: }
663: return $result;
664: }
665:
666: sub end_languageblock {
1.170 www 667: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
668: my $result;
1.186 albertel 669:
670: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
671: $target eq 'tex' || $target eq 'analyze') {
672: my $text=&Apache::lonxml::endredirection();
673: my $include= &Apache::lonxml::get_param('include',$parstack,$safeeval);
674: my $exclude= &Apache::lonxml::get_param('exclude',$parstack,$safeeval);
675: my %languages=&Apache::loncommon::display_languages();
676: $result='1';
677: if ($include) {
678: $result='';
679: foreach (split(/\,/,$include)) {
680: if ($languages{$_}) { $result='1'; }
681: }
682: }
683: if ($exclude) {
684: foreach (split(/\,/,$exclude)) {
685: if ($languages{$_}) { $result='0'; }
686: }
687: }
688: if ( ! $result ) {
689: $result='';
690: } else {
691: $result=$text;
692: }
693: } elsif ($target eq "edit") {
1.170 www 694: $result.= &Apache::edit::tag_end($target,$token,'');
695: }
696: return $result;
697: }
698:
699: sub start_instructorcomment {
700: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
701:
702: my $result;
703:
704: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
705: $target eq 'tex' || $target eq 'analyze') {
706: $result=($ENV{'request.role'}=~/^(in|cc|au|ca|li)/);
707: if ( ! $result ) {
708: my $skip=&Apache::lonxml::get_all_text("/instructorcomment",$parser);
709: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
710: }
711: $result='';
712: } elsif ($target eq 'edit') {
713: $result .=&Apache::edit::tag_start($target,$token);
714: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
715: }
716: return $result;
717: }
718:
719: sub end_instructorcomment {
1.159 albertel 720: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 721: my $result;
722: if ($target eq "edit") {
723: $result.= &Apache::edit::tag_end($target,$token,'');
724: }
725: return $result;
1.4 tsai 726: }
727:
728: sub start_while {
1.159 albertel 729: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
730:
1.160 albertel 731: my $result;
1.161 albertel 732: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.160 albertel 733: $target eq 'tex' || $target eq 'analyze') {
734: my $code = $token->[2]->{'condition'};
1.4 tsai 735:
1.160 albertel 736: push( @Apache::structuretags::whileconds, $code);
737: if (!$Apache::lonxml::default_homework_loaded) {
738: &Apache::lonxml::default_homework_load($safeeval);
739: }
740: my $result = &Apache::run::run($code,$safeeval);
1.161 albertel 741: my $bodytext=&Apache::lonxml::get_all_text("/while",$parser);
1.160 albertel 742: push( @Apache::structuretags::whilebody, $bodytext);
1.161 albertel 743: push( @Apache::structuretags::whileline, $token->[5]);
744: &Apache::lonxml::debug("s code $code got -$result-");
1.160 albertel 745: if ( $result ) {
746: &Apache::lonxml::newparser($parser,\$bodytext);
747: }
748: } elsif ($target eq 'edit') {
749: $result .=&Apache::edit::tag_start($target,$token);
750: $result .=&Apache::edit::text_arg('Test Condition:','condition',
751: $token,40);
752: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
753: } elsif ($target eq 'modified') {
754: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
755: $safeeval,'condition');
756: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.159 albertel 757: }
1.160 albertel 758: return $result;
1.4 tsai 759: }
760:
761: sub end_while {
1.159 albertel 762: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 763: my $result;
764:
765: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
766: $target eq 'tex' || $target eq 'analyze') {
767: my $code = pop(@Apache::structuretags::whileconds);
768: my $bodytext = pop(@Apache::structuretags::whilebody);
1.161 albertel 769: my $line = pop(@Apache::structuretags::whileline);
770: my $return = &Apache::run::run($code,$safeeval);
771: my $starttime=time;
772: my $error=0;
773: while ($return) {
774: if (time-$starttime >
775: $Apache::lonnet::perlvar{'lonScriptTimeout'}) {
776: $return = 0; $error=1; next;
777: }
778: $result.=&Apache::scripttag::xmlparse($bodytext);
779: $return = &Apache::run::run($code,$safeeval);
780: }
781: if ($error) {
782: &Apache::lonxml::error('<pre>Code ran too long. It ran for more than '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' seconds occured while running <while$gt; on line '.$line.'</pre>');
1.160 albertel 783: }
784: } elsif ($target eq "edit") {
785: $result.= &Apache::edit::tag_end($target,$token,'');
1.159 albertel 786: }
1.160 albertel 787: return $result;
1.1 albertel 788: }
1.6 tsai 789:
1.160 albertel 790: # <randomlist show="1">
1.6 tsai 791: # <tag1>..</tag1>
792: # <tag2>..</tag2>
793: # <tag3>..</tag3>
1.160 albertel 794: # ...
1.6 tsai 795: # </randomlist>
796: sub start_randomlist {
1.159 albertel 797: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
798: my $result;
799: if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' ||
800: $target eq 'tex' || $target eq 'analyze') {
801: my $body= &Apache::lonxml::get_all_text("/randomlist",$parser);
802: my $b_parser= HTML::TokeParser->new(\$body);
803: my $b_tok;
804: my @randomlist;
805: my $list_item;
806: while($b_tok = $b_parser->get_token() ) {
807: if($b_tok->[0] eq 'S') { # start tag
808: # get content of the tag until matching end tag
809: # get all text upto the matching tag
810: # and push the content into @randomlist
811: $list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],
812: $b_parser);
813: $list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
814: push(@randomlist,$list_item);
815: # print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4],
816: # $list_item</b>";
817: }
818: if($b_tok->[0] eq 'T') { # text
819: # what to do with text in between tags?
820: # print "<b>TEXT $b_tok->[1]</b><br />";
821: }
822: # if($b_tok->[0] eq 'E') { # end tag, should not happen
823: # print "<b>END-TAG $b_tok->[1]</b><br />";
824: # }
825: }
826: my @idx_arr = (0 .. $#randomlist);
827: &Apache::structuretags::shuffle(\@idx_arr);
828: my $bodytext = '';
829: my $show=$#randomlist;
830: my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
831: $showarg--;
832: if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
833: for(0 .. $show) {
834: $bodytext .= "$randomlist[ $idx_arr[$_] ]";
835: }
836: &Apache::lonxml::newparser($parser,\$bodytext);
837: } elsif ($target eq 'edit' ) {
838: $result .=&Apache::edit::tag_start($target,$token);
839: $result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
840: $token,5);
841: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
842: } elsif ($target eq 'modified' ) {
843: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
844: $safeeval,'show');
845: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
846: }
847: return $result;
1.7 tsai 848: }
849:
850: sub shuffle {
851: my $a=shift;
852: my $i;
1.70 albertel 853: if (defined(@$a)) {
1.159 albertel 854: &Apache::response::setrandomnumber();
855: for($i=@$a;--$i;) {
856: my $j=int(&Math::Random::random_uniform() * ($i+1));
857: next if $i == $j;
858: @$a[$i,$j] = @$a[$j,$i];
859: }
1.7 tsai 860: }
1.6 tsai 861: }
862:
863: sub end_randomlist {
1.159 albertel 864: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
865: my $result;
866: if ($target eq 'edit' ) {
867: $result=&Apache::edit::tag_end($target,$token,
868: 'End Randomly Parsed Block');
869: }
870: return $result;
1.6 tsai 871: }
872:
1.11 albertel 873: sub start_part {
1.159 albertel 874: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
875: my $result='';
876: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
877: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
878: $Apache::inputtags::part=$id;
1.177 albertel 879: push(@Apache::inputtags::partlist,$id);
880: @Apache::inputtags::response=();
1.159 albertel 881: @Apache::inputtags::previous=();
882: @Apache::inputtags::previous_version=();
1.169 albertel 883: $Apache::lonhomework::problemstatus=
884: &Apache::lonnet::EXT("resource.$id.problemstatus");
1.159 albertel 885: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
886:
887: if ($target eq 'meta') {
888: return &Apache::response::mandatory_part_meta;
889: } elsif ($target eq 'web' || $target eq 'grade' ||
890: $target eq 'answer' || $target eq 'tex') {
891: if ($hidden) {
892: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
893: } else {
894: my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
895: push (@Apache::inputtags::status,$status);
896: my $expression='$external::datestatus="'.$status.'";';
897: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
898: &Apache::run::run($expression,$safeeval);
899: if ( $status eq 'CLOSED' ) {
900: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
901: if ( $target eq "web" ) {
902: $result="<br />Part is not open to be viewed. It $accessmsg<br />";
903: } elsif ( $target eq 'tex' ) {
904: $result="\\end{minipage}\\vskip 0 mm Part is not open to be viewed. It $accessmsg \\\\\\begin{minipage}{\\textwidth}";
905: }
906: } else {
907: if ($target eq 'tex') {
908: $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
909: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
910: if ($Apache::lonhomework::type eq 'exam') { $result .= '\fbox{\textit{'.$weight.' pt}}';}
911: }
912: }
913: }
914: } elsif ($target eq 'edit') {
915: $result.=&Apache::edit::tag_start($target,$token);
916: $result.=&Apache::edit::text_arg('Part ID:','id',$token).
917: &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help").
918: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
919: } elsif ($target eq 'modified') {
920: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
921: $safeeval,'id');
922: if ($constructtag) {
923: $result = &Apache::edit::rebuild_tag($token);
924: $result.=&Apache::edit::handle_insert();
925: }
926: }
927: return $result;
1.11 albertel 928: }
929:
930: sub end_part {
1.159 albertel 931: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
932: &Apache::lonxml::debug("in end_part $target ");
933: my $status=$Apache::inputtags::status['-1'];
934: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
935: my $result='';
936: if ( $target eq 'meta' ) {
937: $result='';
938: } elsif ( $target eq 'grade' && $status eq 'CAN_ANSWER' && !$hidden) {
939: $result=&Apache::inputtags::grade;
940: } elsif (($target eq 'web' || $target eq 'tex') && !$hidden ) {
941: my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
942: $target);
943: if ($Apache::lonhomework::type eq 'exam') {$gradestatus='';}
944: $result=$gradestatus;
1.181 albertel 945: } elsif ($target eq 'edit') {
946: $result=&Apache::edit::end_table();
1.159 albertel 947: }
948: pop @Apache::inputtags::status;
949: $Apache::inputtags::part='';
950: return $result;
1.11 albertel 951: }
1.1 albertel 952:
1.25 albertel 953: sub start_preduedate {
1.159 albertel 954: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
955: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
956: if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
957: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER' &&
958: $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
959: &Apache::lonxml::get_all_text("/preduedate",$parser);
960: }
1.24 albertel 961: }
1.159 albertel 962: return '';
1.24 albertel 963: }
964:
1.25 albertel 965: sub end_preduedate {
1.159 albertel 966: return '';
1.24 albertel 967: }
968:
1.25 albertel 969: sub start_postanswerdate {
1.159 albertel 970: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
971: if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
972: if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
973: &Apache::lonxml::get_all_text("/postanswerdate",$parser);
974: }
975: } elsif ($target eq 'tex') {
976: return '\vskip 0 mm \noindent';
977: }
978: return '';
1.24 albertel 979: }
980:
1.25 albertel 981: sub end_postanswerdate {
1.159 albertel 982: return '';
1.24 albertel 983: }
984:
1.25 albertel 985: sub start_notsolved {
1.159 albertel 986: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
987: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
988: $target eq 'tex') {
989: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
990: &Apache::lonxml::debug("not solved has :$gradestatus:");
991: if ($gradestatus =~ /^correct/) {
992: &Apache::lonxml::debug("skipping");
993: &Apache::lonxml::get_all_text("/notsolved",$parser);
994: }
1.24 albertel 995: }
1.159 albertel 996: return '';
1.24 albertel 997: }
998:
1.25 albertel 999: sub end_notsolved {
1.159 albertel 1000: return '';
1.24 albertel 1001: }
1002:
1003: sub start_solved {
1.159 albertel 1004: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1005: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1006: $target eq 'tex') {
1007: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
1008: if ($gradestatus !~ /^correct/) {
1009: &Apache::lonxml::get_all_text("/solved",$parser);
1010: }
1.24 albertel 1011: }
1.159 albertel 1012: return '';
1.24 albertel 1013: }
1014:
1015: sub end_solved {
1.159 albertel 1016: return '';
1.24 albertel 1017: }
1.34 albertel 1018:
1019: sub start_startouttext {
1.159 albertel 1020: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1021: my @result=(''.'');
1022: if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
1023: return (@result);
1.34 albertel 1024: }
1.159 albertel 1025:
1.34 albertel 1026: sub end_startouttext {
1.159 albertel 1027: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1028: my $result='';
1029: my $text='';
1030:
1031: if ($target eq 'edit') {
1032: $text=&Apache::lonxml::get_all_text("endouttext",$parser);
1033: $result.=&Apache::edit::start_table($token)."<tr><td>Text Block</td>
1.42 albertel 1034: <td>Delete:".
1.159 albertel 1035: &Apache::edit::deletelist($target,$token)
1036: ."</td>
1.42 albertel 1037: <td>".
1.159 albertel 1038: &Apache::edit::insertlist($target,$token).
1039: &Apache::edit::end_row().
1040: &Apache::edit::start_spanning_row()."\n"
1.188 bowersj2 1041: . &Apache::loncommon::helpLatexCheatsheet () .
1.159 albertel 1042: &Apache::edit::editfield($token->[1],$text,"",80,4);
1043: }
1044: if ($target eq 'modified') {
1045: $text=&Apache::lonxml::get_all_text("endouttext",$parser);
1046: $result='<startouttext />'.&Apache::edit::modifiedfield();
1047: }
1048: if ($target eq 'tex') {
1049: $result .= '\noindent ';
1050: }
1051: return $result;
1.34 albertel 1052: }
1.159 albertel 1053:
1.34 albertel 1054: sub start_endouttext {
1.159 albertel 1055: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1056: my $result='';
1057: if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
1058: if ($target eq "modified") {
1059: $result='<endouttext />'.
1060: &Apache::edit::handle_insertafter('startouttext'); }
1061: return $result;
1.34 albertel 1062: }
1.159 albertel 1063:
1.34 albertel 1064: sub end_endouttext {
1.159 albertel 1065: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1066: my @result=('','');
1067: if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
1068: return (@result);
1.34 albertel 1069: }
1.159 albertel 1070:
1.45 albertel 1071: sub delete_startouttext {
1.159 albertel 1072: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1073: # my $text=&Apache::lonxml::get_all_text("endouttext",$parser);
1074: my $text=$$parser['-1']->get_text("/endouttext");
1075: my $ntoken=$$parser['-1']->get_token();
1076: &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
1077: &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
1078: # Deleting 2 parallel tag pairs, but we need the numbers later to look like
1079: # they did the last time round
1080: &Apache::lonxml::increasedepth($ntoken);
1081: &Apache::lonxml::decreasedepth($ntoken);
1082: return 1;
1.45 albertel 1083: }
1.34 albertel 1084:
1.1 albertel 1085: 1;
1086: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>