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