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