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