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