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