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