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