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