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