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