Annotation of loncom/homework/structuretags.pm, revision 1.176
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.176 ! albertel 4: # $Id: structuretags.pm,v 1.175 2003/05/15 21:44: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';
277: @Apache::inputtags::responselist = ();
278: @Apache::inputtags::previous=();
279: @Apache::inputtags::previous_version=();
280: $Apache::structuretags::printanswer='No';
1.161 albertel 281: @Apache::structuretags::whileconds=();
282: @Apache::structuretags::whilebody=();
283: @Apache::structuretags::whileline=();
1.166 albertel 284: $Apache::lonhomework::scantronmode=0;
1.169 albertel 285: $Apache::lonhomework::problemstatus=
286: &Apache::lonnet::EXT('resource.0.problemstatus');
1.166 albertel 287:
288: if (defined($ENV{'scantron.maxquest'})) {
289: $Apache::lonhomework::scantronmode=1;
290: }
1.161 albertel 291:
1.159 albertel 292: if ($target ne 'analyze') {
293: &initialize_storage();
294: if ($target eq 'web') {
295: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
296: }
297: $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
298: &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
299: }
1.164 albertel 300: if ($Apache::lonhomework::type eq '' ) {
1.159 albertel 301: my $uri=$ENV{'request.uri'};
302: if ($uri=~/\.(\w+)$/) {
303: $Apache::lonhomework::type=$1;
304: &Apache::lonxml::debug("Using type of $1");
305: } else {
306: $Apache::lonhomework::type='problem';
307: &Apache::lonxml::debug("Using default type, problem, :$uri:");
308: }
1.87 albertel 309: }
1.58 www 310:
1.159 albertel 311: #added vars to the scripting enviroment
312: my $expression='$external::part='.$Apache::inputtags::part.';';
1.24 albertel 313: &Apache::run::run($expression,$safeeval);
1.159 albertel 314: my $status;
315: my $accessmsg;
316:
317: #should get back a <html> or the neccesary stuff to start XML/MathML
318: my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
319: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
320: if ($target eq 'tex' and $ENV{'request.symb'} =~ m/\.page_/) {$result='';}
321:
322: if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval); }
323: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
324: $target eq 'tex') {
325: #handle exam checkout
326: if ($Apache::lonhomework::type eq 'exam') {
327: my $token=
328: $Apache::lonhomework::history{"resource.0.outtoken"};
329: if (($ENV{'form.doescheckout'}) && (!$token)) {
330: $token=&Apache::lonxml::maketoken();
331: $Apache::lonhomework::history{"resource.0.outtoken"}=
332: $token;
333: }
334: $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token);
1.142 albertel 335: }
1.159 albertel 336:
337: #handle rand seed in construction space
338: my $rndseed=&setup_rndseed($safeeval);
1.162 albertel 339: my ($symb)=&Apache::lonxml::whichuser();
1.163 albertel 340: if ($ENV{'request.state'} ne "construct" && $symb eq '') {
1.162 albertel 341: $form_tag_start.='<input type="hidden" name="rndseed" value="'.
342: $rndseed.'" />'.
343: '<input type="submit" name="resetdata"
1.164 albertel 344: value="New Problem Variation" />'.
345: '<input type="hidden" name="username"
346: value="'.$ENV{'form.username'}.'" />';
1.162 albertel 347: }
1.159 albertel 348: ($status,$accessmsg) = &Apache::lonhomework::check_access('0');
349: push (@Apache::inputtags::status,$status);
350: my $expression='$external::datestatus="'.$status.'";';
351: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
352: &Apache::run::run($expression,$safeeval);
353: &Apache::lonxml::debug("Got $status");
354: if (( $status eq 'CLOSED' ) ||
355: ( $status eq 'UNCHECKEDOUT') ||
356: ( $status eq 'BANNED') ||
357: ( $status eq 'UNAVAILABLE')) {
358: my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
359: if ( $target eq "web" ) {
360: $result.= $head_tag_start.'</head>';
361: my $msg=$body_tag_start;
362: if ($status eq 'UNAVAILABLE') {
363: $result.='<h1>Unable to determine if this resource is open due to network problems. Please try again later.</h1>';
364: } else {
365: $result.='<h1>Not open to be viewed</h1>';
366: }
367: if ($status eq 'CLOSED') {
368: $msg.='The problem '.$accessmsg;
369: } elsif ($status eq 'UNCHECKEDOUT') {
370: $msg.=&checkout_msg;
371: }
372: $result.=$msg.'<br />';
373: } elsif ($target eq 'tex') {
374: $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
375: if ($status eq 'UNAVAILABLE') {
376: $result.='Unable to determine if this resource is open due to network problems. Please try again later.\vskip 0 mm ';
377: } else {
378: $result.="Problem is not open to be viewed. It $accessmsg \\vskip 0 mm ";
379: }
380: }
381: } elsif ($target eq 'web') {
382: my $name= &get_resource_name($parstack,$safeeval);
383: if ($status eq 'CAN_ANSWER') {
384: # create a page header and exit
385: $result.="$head_tag_start<title>$name</title></head>
1.158 sakharuk 386: $body_tag_start \n $form_tag_start".
1.159 albertel 387: '<input type="hidden" name="submitted" value="yes" />';
388: if ($ENV{'request.state'} eq "construct") {
389: $result.= &problem_web_to_edit_header($rndseed);
390: }
391: # if we are viewing someone else preserve that info
392: if (defined $ENV{'form.grade_symb'}) {
393: foreach my $field ('symb','courseid','domain','username') {
394: $result .= '<input type="hidden" name="grade_'.$field.
395: '" value="'.$ENV{"form.grade_$field"}.'" />'."\n";
396: }
397: }
398: } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER'
399: || $status eq 'CLOSED' || $status eq 'UNAVALAILABLE') {
400: $result.=$head_tag_start.
401: "<title>$name</title></head>\n$body_tag_start\n";
402: }
403: } elsif ($target eq 'tex') {
404: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
405: if ($name eq '') {
406: $name=&Apache::lonnet::EXT('resource.title');
407: if ($name eq 'con_lost') { $name = ''; }
408: }
409: $Apache::lonhomework::name=$name;
410: my $id = $Apache::inputtags::part;
411: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
412: my $allkeys=&Apache::lonnet::metadata($ENV{'request.uri'},'keys');
413: my @allkeys = split /,/,$allkeys;
414: my $allow_print_points = 0;
415: foreach my $partial_key (@allkeys) {
416: if ($partial_key=~m/weight/) {
417: $allow_print_points++;
418: }
419: }
420: my $duedate = &Apache::lonnet::EXT("resource.$id.duedate");
421: $duedate = POSIX::strftime("%c",localtime($duedate));
422: my $temp_file;
423: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.due";
424: if (-e $filename) {
425: $temp_file = Apache::File->new($filename);
426: } else {
427: $temp_file = Apache::File->new('>>'.$filename);
428: }
429: my @due_file_content = <$temp_file>;
430: my $due_file_content = $due_file_content[$#due_file_content];
431: chomp $due_file_content;
432: my $name_of_resourse= &get_resource_name($parstack,$safeeval);
433: if ($due_file_content ne $duedate) {
434: $temp_file = Apache::File->new('>'.$filename);
435: print $temp_file "$duedate\n";
436: if (not $ENV{'request.symb'} =~ m/\.page_/) {
437: if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') {
438: $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}';
439: } else {
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 \vskip 1 mm \noindent\begin{minipage}{\textwidth}';
441: if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
442: }
1.104 sakharuk 443: } else {
1.159 albertel 444: $result .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\';
1.104 sakharuk 445: }
1.101 sakharuk 446: } else {
1.159 albertel 447: if (not $ENV{'request.symb'} =~ m/\.page_/) {
448: $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}';
449: if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
450: } else {
451: $result .= '\vskip 1mm \\\\\\\\';
452: }
453: }
1.99 sakharuk 454: }
1.159 albertel 455: } elsif ($target eq 'edit') {
456: $result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
457: &problem_edit_header();
458: my $temp=&Apache::edit::insertlist($target,$token);
459: $result.=$temp;
460: } elsif ($target eq 'modified') {
461: $result=$token->[4];
462: $result.=&Apache::edit::handle_insert();
463: } else {
464: # page_start returned a starting result, delete it if we don't need it
465: $result = '';
1.99 sakharuk 466: }
1.159 albertel 467: return $result;
1.9 albertel 468: }
469:
470: sub end_problem {
1.159 albertel 471: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
472: my $result='';
473: my $status=$Apache::inputtags::status['-1'];
474: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
475: $target eq 'tex') {
476: if ( $target eq 'grade' && $Apache::inputtags::part eq '0' &&
477: $status eq 'CAN_ANSWER' ) {
478: # if part is zero, no <part>s existed, so we need to the grading
479: &Apache::inputtags::grade;
480: } elsif ( ($target eq 'web' || $target eq 'tex') &&
481: $Apache::inputtags::part eq '0' &&
482: $status ne 'UNCHECKEDOUT') {
483: # if part is zero, no <part>s existed, so we need show the current
484: # grading status
485: my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
486: $result.= $gradestatus;
487: }
488: if (
489: (($target eq 'web') && ($ENV{'request.state'} ne 'construct')) ||
490: ($target eq 'answer') || ($target eq 'tex')
491: ) {
492: if ($status eq 'CAN_ANSWER') {
1.172 albertel 493: if ($target ne 'tex' &&
494: $ENV{'form.answer_output_mode'} ne 'tex') {
495: $result.="</form></body>\n";
1.159 albertel 496: }
497: } elsif ($status eq 'SHOW_ANSWER' || $status eq 'CANNOT_ANSWER' ||
498: $status eq 'UNCHECKEDOUT' ) {
499: if ($target ne 'tex') {
500: $result.="</body>\n";
501: }
502: }
503: if ($target eq 'web') {
504: $result.=&Apache::lonxml::xmlend();
505: } elsif ($target eq 'tex') {
1.174 sakharuk 506: $result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
1.159 albertel 507: if (not $ENV{'request.symb'} =~ m/\.page_/) {
508: $result .= '\end{minipage}\end{document} ';
509: } else {
510: $result .= '';
511: }
512: }
513: }
514: if ($target eq 'grade') {
515: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
516: &finalize_storage();
517: }
1.172 albertel 518: if ($target eq 'answer' && ($ENV{'request.state'} eq 'construct')
1.173 albertel 519: && $ENV{'form.answer_output_mode'} ne 'tex') {
1.172 albertel 520: $result.='</html>'; # normally we get it from xmlend, but in CSTR
521: # we always show answer mode too.
1.159 albertel 522: }
523: } elsif ($target eq 'meta') {
524: if ($Apache::inputtags::part eq '0') {
525: $result=&Apache::response::mandatory_part_meta;
526: }
527: } elsif ($target eq 'edit') {
528: &Apache::lonxml::debug("in end_problem with $target, edit");
529: $result = &problem_edit_footer();
530: }
1.155 albertel 531:
1.159 albertel 532: undef(%Apache::lonhomework::history);
533: undef(%Apache::lonhomework::results);
534: undef($Apache::inputtags::part);
535: undef($Apache::lonhomework::parsing_a_problem);
536:
537: return $result;
1.48 albertel 538: }
539:
1.108 albertel 540:
1.48 albertel 541: sub start_library {
1.159 albertel 542: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
543: my ($result,$head_tag_start,$body_tag_start,$form_tag_start);
1.109 albertel 544:
1.159 albertel 545: if ($target eq 'edit') {
546: ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
547: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
548: $result.=$head_tag_start."</head>".$body_tag_start.$form_tag_start.
549: &problem_edit_header();
550: my $temp=&Apache::edit::insertlist($target,$token);
551: $result.=$temp;
552: } elsif ($target eq 'modified') {
553: $result=$token->[4];
554: $result.=&Apache::edit::handle_insert();
555: } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
556: $ENV{'request.state'} eq "construct" ) {
557: ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
558: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
559: my $name=&get_resource_name($parstack,$safeeval);
560: my $rndseed=&setup_rndseed($safeeval);
561: $result.="$head_tag_start<title>$name</title></head>
1.105 albertel 562: $body_tag_start \n $form_tag_start".
1.159 albertel 563: '<input type="hidden" name="submitted" value="yes" />';
564: $result.=&problem_web_to_edit_header($rndseed);
565: }
566: return $result;
1.48 albertel 567: }
568:
569: sub end_library {
1.159 albertel 570: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
571: my $result='';
572: if ($target eq 'edit') {
573: $result=&problem_edit_footer();
574: } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
575: $ENV{'request.state'} eq "construct") {
576: $result.='</form></body>'.&Apache::lonxml::xmlend();
577: }
578: return $result;
1.1 albertel 579: }
580:
581: sub start_block {
1.131 albertel 582: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
583:
584: my $result;
1.1 albertel 585:
1.160 albertel 586: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.131 albertel 587: $target eq 'tex' || $target eq 'analyze') {
1.159 albertel 588: my $code = $token->[2]->{'condition'};
1.131 albertel 589: if ($code) {
1.137 albertel 590: if (!$Apache::lonxml::default_homework_loaded) {
591: &Apache::lonxml::default_homework_load($safeeval);
592: }
1.131 albertel 593: $result = &Apache::run::run($code,$safeeval);
594: &Apache::lonxml::debug("block :$code: returned :$result:");
595: } else {
596: $result='1';
597: }
598: if ( ! $result ) {
1.146 albertel 599: my $skip=&Apache::lonxml::get_all_text("/block",$parser);
1.131 albertel 600: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
601: }
602: $result='';
603: } elsif ($target eq 'edit') {
604: $result .=&Apache::edit::tag_start($target,$token);
605: $result .=&Apache::edit::text_arg('Test Condition:','condition',
606: $token,40);
607: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
608: } elsif ($target eq 'modified') {
609: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
610: $safeeval,'condition');
611: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.38 albertel 612: }
1.131 albertel 613: return $result;
1.1 albertel 614: }
615:
616: sub end_block {
1.167 www 617: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
618: my $result;
619: if ($target eq "edit") {
620: $result.= &Apache::edit::tag_end($target,$token,'');
621: }
622: return $result;
623: }
624:
625: sub start_languageblock {
626: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
627:
628: my $result;
629:
630: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
631: $target eq 'tex' || $target eq 'analyze') {
632: my $include = $token->[2]->{'include'};
633: my $exclude = $token->[2]->{'exclude'};
634: my %languages=&Apache::loncommon::display_languages();
635: $result='1';
636: if ($include) {
637: $result='';
638: foreach (split(/\,/,$include)) {
639: if ($languages{$_}) { $result='1'; }
640: }
641: }
642: if ($exclude) {
643: foreach (split(/\,/,$exclude)) {
644: if ($languages{$_}) { $result='0'; }
645: }
646: }
647: if ( ! $result ) {
648: my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser);
649: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
650: }
651: $result='';
652: } elsif ($target eq 'edit') {
653: $result .=&Apache::edit::tag_start($target,$token);
654: $result .=&Apache::edit::text_arg('Include Language:','include',
655: $token,40);
656: $result .=&Apache::edit::text_arg('Exclude Language:','exclude',
657: $token,40);
658: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
659: } elsif ($target eq 'modified') {
660: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.168 albertel 661: $safeeval,'include',
662: 'exclude');
1.167 www 663: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
664: }
665: return $result;
666: }
667:
668: sub end_languageblock {
1.170 www 669: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
670: my $result;
671: if ($target eq "edit") {
672: $result.= &Apache::edit::tag_end($target,$token,'');
673: }
674: return $result;
675: }
676:
677: sub start_instructorcomment {
678: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
679:
680: my $result;
681:
682: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
683: $target eq 'tex' || $target eq 'analyze') {
684: $result=($ENV{'request.role'}=~/^(in|cc|au|ca|li)/);
685: if ( ! $result ) {
686: my $skip=&Apache::lonxml::get_all_text("/instructorcomment",$parser);
687: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
688: }
689: $result='';
690: } elsif ($target eq 'edit') {
691: $result .=&Apache::edit::tag_start($target,$token);
692: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
693: }
694: return $result;
695: }
696:
697: sub end_instructorcomment {
1.159 albertel 698: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 699: my $result;
700: if ($target eq "edit") {
701: $result.= &Apache::edit::tag_end($target,$token,'');
702: }
703: return $result;
1.4 tsai 704: }
705:
706: sub start_while {
1.159 albertel 707: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
708:
1.160 albertel 709: my $result;
1.161 albertel 710: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.160 albertel 711: $target eq 'tex' || $target eq 'analyze') {
712: my $code = $token->[2]->{'condition'};
1.4 tsai 713:
1.160 albertel 714: push( @Apache::structuretags::whileconds, $code);
715: if (!$Apache::lonxml::default_homework_loaded) {
716: &Apache::lonxml::default_homework_load($safeeval);
717: }
718: my $result = &Apache::run::run($code,$safeeval);
1.161 albertel 719: my $bodytext=&Apache::lonxml::get_all_text("/while",$parser);
1.160 albertel 720: push( @Apache::structuretags::whilebody, $bodytext);
1.161 albertel 721: push( @Apache::structuretags::whileline, $token->[5]);
722: &Apache::lonxml::debug("s code $code got -$result-");
1.160 albertel 723: if ( $result ) {
724: &Apache::lonxml::newparser($parser,\$bodytext);
725: }
726: } elsif ($target eq 'edit') {
727: $result .=&Apache::edit::tag_start($target,$token);
728: $result .=&Apache::edit::text_arg('Test Condition:','condition',
729: $token,40);
730: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
731: } elsif ($target eq 'modified') {
732: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
733: $safeeval,'condition');
734: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.159 albertel 735: }
1.160 albertel 736: return $result;
1.4 tsai 737: }
738:
739: sub end_while {
1.159 albertel 740: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 741: my $result;
742:
743: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
744: $target eq 'tex' || $target eq 'analyze') {
745: my $code = pop(@Apache::structuretags::whileconds);
746: my $bodytext = pop(@Apache::structuretags::whilebody);
1.161 albertel 747: my $line = pop(@Apache::structuretags::whileline);
748: my $return = &Apache::run::run($code,$safeeval);
749: my $starttime=time;
750: my $error=0;
751: while ($return) {
752: if (time-$starttime >
753: $Apache::lonnet::perlvar{'lonScriptTimeout'}) {
754: $return = 0; $error=1; next;
755: }
756: $result.=&Apache::scripttag::xmlparse($bodytext);
757: $return = &Apache::run::run($code,$safeeval);
758: }
759: if ($error) {
760: &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 761: }
762: } elsif ($target eq "edit") {
763: $result.= &Apache::edit::tag_end($target,$token,'');
1.159 albertel 764: }
1.160 albertel 765: return $result;
1.1 albertel 766: }
1.6 tsai 767:
1.160 albertel 768: # <randomlist show="1">
1.6 tsai 769: # <tag1>..</tag1>
770: # <tag2>..</tag2>
771: # <tag3>..</tag3>
1.160 albertel 772: # ...
1.6 tsai 773: # </randomlist>
774: sub start_randomlist {
1.159 albertel 775: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
776: my $result;
777: if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' ||
778: $target eq 'tex' || $target eq 'analyze') {
779: my $body= &Apache::lonxml::get_all_text("/randomlist",$parser);
780: my $b_parser= HTML::TokeParser->new(\$body);
781: my $b_tok;
782: my @randomlist;
783: my $list_item;
784: while($b_tok = $b_parser->get_token() ) {
785: if($b_tok->[0] eq 'S') { # start tag
786: # get content of the tag until matching end tag
787: # get all text upto the matching tag
788: # and push the content into @randomlist
789: $list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],
790: $b_parser);
791: $list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
792: push(@randomlist,$list_item);
793: # print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4],
794: # $list_item</b>";
795: }
796: if($b_tok->[0] eq 'T') { # text
797: # what to do with text in between tags?
798: # print "<b>TEXT $b_tok->[1]</b><br />";
799: }
800: # if($b_tok->[0] eq 'E') { # end tag, should not happen
801: # print "<b>END-TAG $b_tok->[1]</b><br />";
802: # }
803: }
804: my @idx_arr = (0 .. $#randomlist);
805: &Apache::structuretags::shuffle(\@idx_arr);
806: my $bodytext = '';
807: my $show=$#randomlist;
808: my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
809: $showarg--;
810: if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
811: for(0 .. $show) {
812: $bodytext .= "$randomlist[ $idx_arr[$_] ]";
813: }
814: &Apache::lonxml::newparser($parser,\$bodytext);
815: } elsif ($target eq 'edit' ) {
816: $result .=&Apache::edit::tag_start($target,$token);
817: $result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
818: $token,5);
819: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
820: } elsif ($target eq 'modified' ) {
821: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
822: $safeeval,'show');
823: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
824: }
825: return $result;
1.7 tsai 826: }
827:
828: sub shuffle {
829: my $a=shift;
830: my $i;
1.70 albertel 831: if (defined(@$a)) {
1.159 albertel 832: &Apache::response::setrandomnumber();
833: for($i=@$a;--$i;) {
834: my $j=int(&Math::Random::random_uniform() * ($i+1));
835: next if $i == $j;
836: @$a[$i,$j] = @$a[$j,$i];
837: }
1.7 tsai 838: }
1.6 tsai 839: }
840:
841: sub end_randomlist {
1.159 albertel 842: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
843: my $result;
844: if ($target eq 'edit' ) {
845: $result=&Apache::edit::tag_end($target,$token,
846: 'End Randomly Parsed Block');
847: }
848: return $result;
1.6 tsai 849: }
850:
1.11 albertel 851: sub start_part {
1.159 albertel 852: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
853: my $result='';
854: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
855: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
856: $Apache::inputtags::part=$id;
857: @Apache::inputtags::responselist = ();
858: @Apache::inputtags::previous=();
859: @Apache::inputtags::previous_version=();
1.169 albertel 860: $Apache::lonhomework::problemstatus=
861: &Apache::lonnet::EXT("resource.$id.problemstatus");
1.159 albertel 862: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
863:
864: if ($target eq 'meta') {
865: return &Apache::response::mandatory_part_meta;
866: } elsif ($target eq 'web' || $target eq 'grade' ||
867: $target eq 'answer' || $target eq 'tex') {
868: if ($hidden) {
869: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
870: } else {
871: my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
872: push (@Apache::inputtags::status,$status);
873: my $expression='$external::datestatus="'.$status.'";';
874: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
875: &Apache::run::run($expression,$safeeval);
876: if ( $status eq 'CLOSED' ) {
877: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser);
878: if ( $target eq "web" ) {
879: $result="<br />Part is not open to be viewed. It $accessmsg<br />";
880: } elsif ( $target eq 'tex' ) {
881: $result="\\end{minipage}\\vskip 0 mm Part is not open to be viewed. It $accessmsg \\\\\\begin{minipage}{\\textwidth}";
882: }
883: } else {
884: if ($target eq 'tex') {
885: $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
886: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
887: if ($Apache::lonhomework::type eq 'exam') { $result .= '\fbox{\textit{'.$weight.' pt}}';}
888: }
889: }
890: }
891: } elsif ($target eq 'edit') {
892: $result.=&Apache::edit::tag_start($target,$token);
893: $result.=&Apache::edit::text_arg('Part ID:','id',$token).
894: &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help").
895: &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,'id');
899: if ($constructtag) {
900: $result = &Apache::edit::rebuild_tag($token);
901: $result.=&Apache::edit::handle_insert();
902: }
903: }
904: return $result;
1.11 albertel 905: }
906:
907: sub end_part {
1.159 albertel 908: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
909: &Apache::lonxml::debug("in end_part $target ");
910: my $status=$Apache::inputtags::status['-1'];
911: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
912: my $result='';
913: if ( $target eq 'meta' ) {
914: $result='';
915: } elsif ( $target eq 'grade' && $status eq 'CAN_ANSWER' && !$hidden) {
916: $result=&Apache::inputtags::grade;
917: } elsif (($target eq 'web' || $target eq 'tex') && !$hidden ) {
918: my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
919: $target);
920: if ($Apache::lonhomework::type eq 'exam') {$gradestatus='';}
921: $result=$gradestatus;
922: }
923: pop @Apache::inputtags::status;
924: $Apache::inputtags::part='';
925: return $result;
1.11 albertel 926: }
1.1 albertel 927:
1.25 albertel 928: sub start_preduedate {
1.159 albertel 929: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
930: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') {
931: if ($Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
932: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER' &&
933: $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
934: &Apache::lonxml::get_all_text("/preduedate",$parser);
935: }
1.24 albertel 936: }
1.159 albertel 937: return '';
1.24 albertel 938: }
939:
1.25 albertel 940: sub end_preduedate {
1.159 albertel 941: return '';
1.24 albertel 942: }
943:
1.25 albertel 944: sub start_postanswerdate {
1.159 albertel 945: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
946: if ($target eq 'web' || $target eq 'grade' || $target eq 'tex') {
947: if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
948: &Apache::lonxml::get_all_text("/postanswerdate",$parser);
949: }
950: } elsif ($target eq 'tex') {
951: return '\vskip 0 mm \noindent';
952: }
953: return '';
1.24 albertel 954: }
955:
1.25 albertel 956: sub end_postanswerdate {
1.159 albertel 957: return '';
1.24 albertel 958: }
959:
1.25 albertel 960: sub start_notsolved {
1.159 albertel 961: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
962: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
963: $target eq 'tex') {
964: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
965: &Apache::lonxml::debug("not solved has :$gradestatus:");
966: if ($gradestatus =~ /^correct/) {
967: &Apache::lonxml::debug("skipping");
968: &Apache::lonxml::get_all_text("/notsolved",$parser);
969: }
1.24 albertel 970: }
1.159 albertel 971: return '';
1.24 albertel 972: }
973:
1.25 albertel 974: sub end_notsolved {
1.159 albertel 975: return '';
1.24 albertel 976: }
977:
978: sub start_solved {
1.159 albertel 979: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
980: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
981: $target eq 'tex') {
982: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
983: if ($gradestatus !~ /^correct/) {
984: &Apache::lonxml::get_all_text("/solved",$parser);
985: }
1.24 albertel 986: }
1.159 albertel 987: return '';
1.24 albertel 988: }
989:
990: sub end_solved {
1.159 albertel 991: return '';
1.24 albertel 992: }
1.34 albertel 993:
994: sub start_startouttext {
1.159 albertel 995: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
996: my @result=(''.'');
997: if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
998: return (@result);
1.34 albertel 999: }
1.159 albertel 1000:
1.34 albertel 1001: sub end_startouttext {
1.159 albertel 1002: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1003: my $result='';
1004: my $text='';
1005:
1006: if ($target eq 'edit') {
1007: $text=&Apache::lonxml::get_all_text("endouttext",$parser);
1008: $result.=&Apache::edit::start_table($token)."<tr><td>Text Block</td>
1.42 albertel 1009: <td>Delete:".
1.159 albertel 1010: &Apache::edit::deletelist($target,$token)
1011: ."</td>
1.42 albertel 1012: <td>".
1.159 albertel 1013: &Apache::edit::insertlist($target,$token).
1014: &Apache::edit::end_row().
1015: &Apache::edit::start_spanning_row()."\n"
1016: .'<table><tr><td>'.
1017: &Apache::loncommon::help_open_topic("Greek_Symbols",
1018: 'Greek Symbols',
1019: undef,undef,600)
1020: .'</td><td>'.
1021: &Apache::loncommon::help_open_topic("Other_Symbols",
1022: 'Other Symbols',
1023: undef,undef,600)
1024: .'</td></tr></table>'.
1025: &Apache::edit::editfield($token->[1],$text,"",80,4);
1026: }
1027: if ($target eq 'modified') {
1028: $text=&Apache::lonxml::get_all_text("endouttext",$parser);
1029: $result='<startouttext />'.&Apache::edit::modifiedfield();
1030: }
1031: if ($target eq 'tex') {
1032: $result .= '\noindent ';
1033: }
1034: return $result;
1.34 albertel 1035: }
1.159 albertel 1036:
1.34 albertel 1037: sub start_endouttext {
1.159 albertel 1038: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1039: my $result='';
1040: if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
1041: if ($target eq "modified") {
1042: $result='<endouttext />'.
1043: &Apache::edit::handle_insertafter('startouttext'); }
1044: return $result;
1.34 albertel 1045: }
1.159 albertel 1046:
1.34 albertel 1047: sub end_endouttext {
1.159 albertel 1048: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1049: my @result=('','');
1050: if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
1051: return (@result);
1.34 albertel 1052: }
1.159 albertel 1053:
1.45 albertel 1054: sub delete_startouttext {
1.159 albertel 1055: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1056: # my $text=&Apache::lonxml::get_all_text("endouttext",$parser);
1057: my $text=$$parser['-1']->get_text("/endouttext");
1058: my $ntoken=$$parser['-1']->get_token();
1059: &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
1060: &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
1061: # Deleting 2 parallel tag pairs, but we need the numbers later to look like
1062: # they did the last time round
1063: &Apache::lonxml::increasedepth($ntoken);
1064: &Apache::lonxml::decreasedepth($ntoken);
1065: return 1;
1.45 albertel 1066: }
1.34 albertel 1067:
1.1 albertel 1068: 1;
1069: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>