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