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