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