Annotation of loncom/homework/structuretags.pm, revision 1.350
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.350 ! albertel 4: # $Id: structuretags.pm,v 1.349 2006/04/20 02:05:30 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.338 albertel 39: use Apache::lonenc();
1.267 albertel 40: use Time::HiRes qw( gettimeofday tv_interval );
1.78 harris41 41: BEGIN {
1.248 albertel 42: &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 43: }
44:
45: sub start_web {
1.326 albertel 46: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
47: my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style);
1.339 albertel 48: if ($target eq 'web' || $target eq 'webgrade') {
1.200 albertel 49: return $bodytext;
1.159 albertel 50: }
51: return '';
1.10 albertel 52: }
53:
54: sub end_web {
1.44 ng 55: return '';
1.10 albertel 56: }
57:
58: sub start_tex {
1.326 albertel 59: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.198 sakharuk 60: my $result='';
1.326 albertel 61: my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style);
1.200 albertel 62: if ($target eq 'tex') {
63: return $bodytext.' ';
1.159 albertel 64: }
1.198 sakharuk 65: return $result;;
1.10 albertel 66: }
67:
68: sub end_tex {
1.44 ng 69: return '';
1.9 albertel 70: }
71:
1.48 albertel 72: sub page_start {
1.345 albertel 73: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
74: $extra_head)=@_;
1.159 albertel 75: my %found;
1.207 albertel 76: foreach my $taginside (@$tagstack) {
1.159 albertel 77: foreach my $taglookedfor ('html','body','form') {
78: if ($taginside =~ /^$taglookedfor$/i) {$found{$taglookedfor} = 1;}
79: }
80: }
81:
1.343 albertel 82: if ($target eq 'tex') {
83: return
84: &Apache::londefdef::start_html($target,$token,$tagstack,
85: $parstack,$parser,$safeeval);
86: }
87:
1.344 albertel 88: my %body_args;
89: if (defined($found{'html'})) {
90: $body_args{'skip_phases'}{'head'}=1;
91: } else {
1.343 albertel 92:
1.345 albertel 93: $extra_head .= &Apache::lonhtmlcommon::spellheader();
1.343 albertel 94:
1.336 albertel 95: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile');
1.335 albertel 96: if ($css_href =~ /\S/) {
97: &Apache::lonxml::extlink($css_href);
1.343 albertel 98: $extra_head .=
1.335 albertel 99: '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />';
100: }
1.327 albertel 101: if ($target eq 'edit') {
1.343 albertel 102: $extra_head.=&Apache::edit::js_change_detection().
103: "<script type=\"text/javascript\">\n".
104: "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
105: &Apache::loncommon::browser_and_searcher_javascript().
106: "\n</script>\n";
107: }
1.159 albertel 108: }
1.343 albertel 109:
1.344 albertel 110: if (defined($found{'body'})) {
111: $body_args{'skip_phases'}{'body'}=1;
112: } elsif (!defined($found{'body'})
113: && $env{'request.state'} eq 'construct') {
1.343 albertel 114: if ($target eq 'web' || $target eq 'edit') {
1.344 albertel 115: # no extra args to bodytag
1.297 albertel 116: }
1.272 albertel 117: } elsif (!defined($found{'body'})) {
1.343 albertel 118: my %add_entries;
1.159 albertel 119: my $background=&Apache::lonxml::get_param('background',$parstack,
120: $safeeval);
1.343 albertel 121: if ($background ne '' ) {
122: $add_entries{'background'} = $background;
123: }
1.344 albertel 124:
1.290 albertel 125: my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,
126: $safeeval);
1.344 albertel 127: if ($bgcolor eq '' ) { $bgcolor = '#FFFFFF'; }
128:
129: $body_args{'bgcolor'} = $bgcolor;
130: $body_args{'no_title'} = 1;
131: $body_args{'force_register'} = 1;
132: $body_args{'add_entries'} = \%add_entries;
133: }
134:
135: my $page_start = &Apache::loncommon::start_page($name,$extra_head,
136: \%body_args);
137:
138: if (!defined($found{'body'})
139: && $env{'request.state'} ne 'construct'
140: && ($target eq 'web' || $target eq 'webgrade')) {
141:
142: my ($symb,undef,undef,undef,$publicuser)= &Apache::lonxml::whichuser();
143: if ($symb eq '' && !$publicuser) {
144: my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference");
145: $help=&mt("Browsing resource, all submissions are temporary.")."<br />";
146: $page_start .= $help;
1.159 albertel 147: }
1.344 albertel 148: }
149:
150: if (!defined($found{'body'})) {
1.343 albertel 151: $page_start .= &Apache::lonxml::message_location();
1.159 albertel 152: }
1.344 albertel 153:
1.159 albertel 154: my $form_tag_start;
155: if (!defined($found{'form'})) {
1.337 albertel 156: $form_tag_start='<form name="lonhomework" enctype="multipart/form-data" method="post" action="';
1.338 albertel 157: my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.327 albertel 158: $form_tag_start.=$uri.'" ';
159: if ($target eq 'edit') {
160: $form_tag_start.=&Apache::edit::form_change_detection();
161: }
162: $form_tag_start.='>';
1.159 albertel 163: }
1.350 ! albertel 164: &Apache::lonnet::logthis("page_start -- ".length($page_start));
1.343 albertel 165: return ($page_start,$form_tag_start);
1.105 albertel 166: }
167:
1.141 matthew 168: #use Time::HiRes();
1.105 albertel 169: sub get_resource_name {
1.159 albertel 170: my ($parstack,$safeeval)=@_;
1.204 albertel 171: if (defined($Apache::lonhomework::name)) {
172: return $Apache::lonhomework::name;
173: }
1.279 albertel 174: my ($symb)=&Apache::lonxml::whichuser();
175: my $name=&Apache::lonnet::gettitle($symb);
1.159 albertel 176: if ($name eq '') {
177: $name=&Apache::lonnet::EXT('resource.title');
178: if ($name eq 'con_lost') { $name = ''; }
179: }
1.204 albertel 180: if ($name!~/\S+/) {
1.284 albertel 181: $name=$env{'request.uri'};
1.205 albertel 182: $name=~s-.*/([^/]+)$-$1-;
1.204 albertel 183: }
1.159 albertel 184: $Apache::lonhomework::name=$name;
185: return $name;
1.105 albertel 186: }
187:
188: sub setup_rndseed {
1.159 albertel 189: my ($safeeval)=@_;
190: my $rndseed;
1.162 albertel 191: my ($symb)=&Apache::lonxml::whichuser();
1.333 albertel 192: if ($env{'request.state'} eq "construct"
193: || $symb eq ''
194: || $Apache::lonhomework::type eq 'practice'
195: || $Apache::lonhomework::history{'resource.CODE'}) {
1.316 www 196: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.317 albertel 197: ['rndseed']);
1.284 albertel 198: $rndseed=$env{'form.rndseed'};
1.159 albertel 199: if (!$rndseed) {
1.162 albertel 200: $rndseed=$Apache::lonhomework::history{'rndseed'};
201: if (!$rndseed) {
202: $rndseed=time;
203: }
1.284 albertel 204: $env{'form.rndseed'}=$rndseed;
1.162 albertel 205: }
1.284 albertel 206: if ($env{'form.resetdata'} eq &mt('New Problem Variation') ||
207: $env{'form.newrandomization'} eq &mt('New Randomization')) {
1.190 albertel 208: srand(time);
209: $rndseed=int(rand(2100000000));
1.284 albertel 210: $env{'form.rndseed'}=$rndseed;
211: delete($env{'form.resetdata'});
212: delete($env{'form.newrandomization'});
1.159 albertel 213: }
1.187 albertel 214: if (defined($rndseed) && $rndseed ne int($rndseed)) {
1.307 albertel 215: $rndseed=join(':',&Apache::lonnet::digest($rndseed));
1.187 albertel 216: }
1.247 albertel 217: if ($Apache::lonhomework::history{'resource.CODE'}) {
218: $rndseed=&Apache::lonnet::rndseed();
219: }
1.221 albertel 220: if ($safeeval) {
221: &Apache::lonxml::debug("Setting rndseed to $rndseed");
1.250 albertel 222: &Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval);
1.221 albertel 223: }
1.159 albertel 224: }
225: return $rndseed;
1.105 albertel 226: }
227:
1.268 albertel 228: sub remember_problem_state {
229: return '
1.284 albertel 230: <input type="hidden" name="problemstate" value="'.$env{'form.problemstate'}.'" />
231: <input type="hidden" name="problemtype" value="'.$env{'form.problemtype'}.'" />
232: <input type="hidden" name="problemstatus" value="'.$env{'form.problemstatus'}.'" />';
1.268 albertel 233: }
234:
1.105 albertel 235: sub problem_edit_header {
1.268 albertel 236: return '<input type="hidden" name="submitted" value="edit" />'.
237: &Apache::structuretags::remember_problem_state().'
1.210 albertel 238: <input type="hidden" name="problemmode" value="'.&mt('Edit').'" />
1.243 matthew 239: <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />
1.328 albertel 240: <input '.&Apache::edit::submit_ask_anyway().' type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />
1.243 matthew 241: <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" /> <hr />
242: <input type="submit" name="submit" accesskey="s" value="'.&mt('Submit Changes and Edit').'" />
243: <input type="submit" name="submit" accesskey="v" value="'.&mt('Submit Changes and View').'" /><table><tr><td>'.
1.260 albertel 244: &Apache::loncommon::help_open_menu('','Problem Editing Help','Problem_Editor_XML_Index','',5,'Authoring',undef,undef,undef,'Problem Editing Help')
245: .'</td></tr></table>'.
1.282 albertel 246: '<table border="0" width="100%"><tr><td bgcolor="#DDDDDD">';
1.105 albertel 247: }
248:
249: sub problem_edit_footer {
1.210 albertel 250: return '</td></tr></table><br /><input type="submit" name="submit" value="'.&mt('Submit Changes and Edit').'" />
1.255 www 251: <input type="submit" name="submit" value="'.&mt('Submit Changes and View').'" />'.
1.348 albertel 252: &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()).
1.342 albertel 253: "\n</form>\n".&Apache::loncommon::end_page();
1.105 albertel 254: }
255:
1.235 albertel 256: sub option {
257: my ($value,$name) = @_;
258: my $result ="<option value='".$value."' ";
1.284 albertel 259: if ($env{'form.'.$name} eq $value) {
1.235 albertel 260: $result.=" selected='on' ";
261: }
262: $result.='>';
263: return $result;
264: }
265:
1.105 albertel 266: sub problem_web_to_edit_header {
1.159 albertel 267: my ($rndseed)=@_;
1.313 albertel 268: my $result.='<input type="hidden" name="problemmode" value="'.&mt('View').'" />';
269: if (!$Apache::lonhomework::parsing_a_task) {
270: $result .= '<input type="submit" name="problemmode" accesskey="e" value="'.&mt('Edit').'" />';
271: }
272: $result .= '<input type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />
1.243 matthew 273: <input type="submit" name="newrandomization" accesskey="a" value="'.&mt('New Randomization').'" />
274: <input type="submit" name="resetdata" accesskey="r" value="'.&mt('Reset Submissions').'" />
1.210 albertel 275: <nobr><input type="submit" name="changerandseed" value="'.&mt('Change Random Seed To:').'" />
1.270 albertel 276: <input type="text" name="rndseed" size="10" value="'.
1.175 albertel 277: $rndseed.'"
1.270 albertel 278: onchange="javascript:document.lonhomework.changerandseed.click()" /></nobr>
1.281 albertel 279: <label><input type="checkbox" name="showallfoils" ';
1.315 albertel 280: my $show_all_foils_text =
281: ($Apache::lonhomework::parsing_a_task) ?
282: &mt(' Show All Instances')
283: : &mt(' Show All Foils');
284:
1.284 albertel 285: if (defined($env{'form.showallfoils'})) { $result.='checked="on"'; }
1.315 albertel 286: $result.= ' />'.$show_all_foils_text.
1.228 www 287: &Apache::loncommon::help_open_topic('Problem_Editor_Testing_Area','Testing Problems').
1.281 albertel 288: '</label><hr />';
1.313 albertel 289: if (!$Apache::lonhomework::parsing_a_task) {
290: $result.="
1.235 albertel 291: <nobr>
292: Problem Status:
293: <select name='problemstate'>
1.270 albertel 294: <option value=''></option>
1.235 albertel 295: ".&option('CLOSED' ,'problemstate').&mt("Closed")."</option>
296: ".&option('CAN_ANSWER' ,'problemstate').&mt("Answerable")."</option>
297: ".&option('CANNOT_ANSWER_tries' ,'problemstate').&mt("Open with full tries")."</option>
298: ".&option('CANNOT_ANSWER_correct','problemstate').&mt("Open and correct")."</option>
299: ".&option('SHOW_ANSWER' ,'problemstate').&mt("Show Answer")."</option>
300: </select>
301: </nobr>
302: <nobr>
303: Problem Type:
304: <select name='problemtype'>
1.270 albertel 305: <option value=''></option>
1.242 albertel 306: ".&option('exam' ,'problemtype').&mt("Exam Problem")."</option>
307: ".&option('problem','problemtype').&mt("Homework problem")."</option>
308: ".&option('survey' ,'problemtype').&mt("Survey Question")."</option>
1.235 albertel 309: </select>
310: </nobr>
311: <nobr>
312: Feedback Mode:
313: <select name='problemstatus'>
314: <option value=''></option>
1.242 albertel 315: ".&option('yes','problemstatus').&mt("Show Feedback")."</option>
316: ".&option('no', 'problemstatus').&mt("Don't Show Feedback")."</option>
1.235 albertel 317: </select>
318: </nobr>
1.242 albertel 319: <input type='submit' name='changeproblemmode' value='".&mt("Change")."' />
1.235 albertel 320: <hr />";
1.313 albertel 321: my $numtoanalyze=$env{'form.numtoanalyze'};
322: if (!$numtoanalyze) { $numtoanalyze=20; }
323: $result.= '<input type="submit" name="problemmode" value='.
324: &mt('"Calculate answers').'" /> for
1.136 albertel 325: <input type="text" name="numtoanalyze" value="'.
1.210 albertel 326: $numtoanalyze.'" size="5" /> '.&mt('versions of this problem').
327: '.'.&Apache::loncommon::help_open_topic("Analyze_Problem",
1.176 albertel 328: '',undef,undef,300).
1.210 albertel 329: '<hr />';
1.313 albertel 330: }
1.159 albertel 331: return $result;
1.48 albertel 332: }
333:
1.65 albertel 334: sub initialize_storage {
1.159 albertel 335: %Apache::lonhomework::results=();
1.162 albertel 336: %Apache::lonhomework::history=();
1.159 albertel 337: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
1.333 albertel 338: if ($env{'request.state'} eq 'construct'
339: || $symb eq ''
340: || $Apache::lonhomework::type eq 'practice') {
341:
342: my $namespace = $symb || $env{'request.uri'};
343: if ($env{'form.resetdata'} eq &mt('Reset Submissions') ||
344: $env{'form.resetdata'} eq &mt('New Problem Variation') ||
345: $env{'form.newrandomization'} eq &mt('New Randomization')) {
346: &Apache::lonnet::tmpreset($namespace,'',$domain,$name);
347: &Apache::lonxml::debug("Attempt reset");
348: }
1.159 albertel 349: %Apache::lonhomework::history=
1.333 albertel 350: &Apache::lonnet::tmprestore($namespace,'',$domain,$name);
1.159 albertel 351: my ($temp)=keys %Apache::lonhomework::history ;
352: &Apache::lonxml::debug("Return message of $temp");
353: } else {
354: %Apache::lonhomework::history=
355: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
356: }
357: #ignore error conditions
1.67 albertel 358: my ($temp)=keys %Apache::lonhomework::history ;
1.159 albertel 359: if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
1.65 albertel 360: }
361:
362: # -------------------------------------------------------------finalize_storage
363: # Stores away the result has to a student's environment
364: # checks form.grade_ for specific values, other wises stores
365: # to the running users environment
1.285 raeburn 366: # Will increment totals for attempts, students, and corrects
367: # if running user has student role.
1.65 albertel 368: sub finalize_storage {
1.159 albertel 369: my $result;
1.289 albertel 370: if (%Apache::lonhomework::results) {
1.323 albertel 371: my @remove = grep(/^INTERNAL_/,keys(%Apache::lonhomework::results));
372: delete(@Apache::lonhomework::results{@remove});
1.159 albertel 373: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
1.333 albertel 374: if ($env{'request.state'} eq 'construct'
375: || $symb eq ''
376: || $Apache::lonhomework::type eq 'practice') {
377: my $namespace = $symb || $env{'request.uri'};
1.284 albertel 378: $Apache::lonhomework::results{'rndseed'}=$env{'form.rndseed'};
1.159 albertel 379: $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,
1.333 albertel 380: $namespace,'',$domain,$name);
1.159 albertel 381: &Apache::lonxml::debug('Construct Store return message:'.$result);
382: } else {
383: $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
384: $symb,$courseid,$domain,$name);
385: &Apache::lonxml::debug('Store return message:'.$result);
1.285 raeburn 386: if ($env{'request.role'} =~/^st/) {
387: &store_aggregates($symb,$courseid);
388: }
1.159 albertel 389: }
1.323 albertel 390: } else {
391: &Apache::lonxml::debug('Nothing to store');
1.67 albertel 392: }
1.159 albertel 393: return $result;
1.65 albertel 394: }
1.289 albertel 395: use Data::Dumper;
1.65 albertel 396:
1.285 raeburn 397: # -------------------------------------------------------------store_aggregates
398: # Sends hash of values to be incremented in nohist_resourcetracker.db
399: # for the course. Increments total number of attempts, unique students
400: # and corrects for each part for an instance of a problem, as appropriate.
401: sub store_aggregates {
402: my ($symb,$courseid) = @_;
1.286 albertel 403: my %aggregate;
404: my @parts;
1.288 albertel 405: my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
406: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
1.286 albertel 407: foreach my $key (keys(%Apache::lonhomework::results)) {
1.287 albertel 408: if ($key =~ /resource\.([^\.]+)\.tries/) {
1.286 albertel 409: push(@parts, $1);
1.285 raeburn 410: }
411: }
1.286 albertel 412: foreach my $part (@parts) {
413: if ($Apache::lonhomework::results{'resource.'.$part.'.award'}
414: eq 'APPROX_ANS' ||
415: $Apache::lonhomework::results{'resource.'.$part.'.award'}
416: eq 'EXACT_ANS') {
1.287 albertel 417: $aggregate{$symb."\0".$part."\0correct"} = 1;
1.285 raeburn 418: }
1.286 albertel 419: if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) {
1.287 albertel 420: $aggregate{$symb."\0".$part."\0users"} = 1;
1.292 raeburn 421: } else {
1.293 albertel 422: my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]);
1.292 raeburn 423: if ($last_reset) {
1.293 albertel 424: if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) {
1.292 raeburn 425: $aggregate{$symb."\0".$part."\0users"} = 1;
426: }
427: }
1.285 raeburn 428: }
1.287 albertel 429: $aggregate{$symb."\0".$part."\0attempts"} = 1;
1.285 raeburn 430: }
1.292 raeburn 431: if (keys (%aggregate) > 0) {
1.289 albertel 432: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.292 raeburn 433: $cdomain,$cname);
434: }
435: }
1.289 albertel 436:
1.65 albertel 437: sub checkout_msg {
1.211 albertel 438: my %lt=&Apache::lonlocal::texthash(
439: 'resource'=>'The resource needs to be checked out',
440: '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.',
441: 'warning'=>'Checking out resources is subject to course policies, and may exclude future credit even if done erroneously.',
442: 'checkout'=>'Check out Exam for Viewing',
443: 'checkout?'=>'Check out Exam?');
1.159 albertel 444: return (<<ENDCHECKOUT);
1.211 albertel 445: <h2>$lt{'resource'}</h2>
446: <p>$lt{'id_expln'}</p>
447: <font color="red">
448: <p>$lt{'warning'}</p>
1.91 albertel 449: </font>
1.284 albertel 450: <form name="checkout" method="POST" action="$env{'request.uri'}">
1.91 albertel 451: <input type="hidden" name="doescheckout" value="yes" />
1.211 albertel 452: <input type="button" name="checkoutbutton" value="$lt{'checkout'}" onClick="javascript:if (confirm('$lt{'checkout?'}')) { document.checkout.submit(); }" />
1.65 albertel 453: </form>
454: ENDCHECKOUT
455: }
456:
1.252 albertel 457: sub firstaccess_msg {
1.253 albertel 458: my ($time,$symb)=@_;
459: my ($map)=&Apache::lonnet::decode_symb($symb);
460: my $foldertitle=&Apache::lonnet::gettitle($map);
461: &Apache::lonxml::debug("map is $map title is $foldertitle");
1.252 albertel 462: return (<<ENDCHECKOUT);
1.253 albertel 463: <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.284 albertel 464: <form name="markaccess" method="POST" action="$env{'request.uri'}">
1.252 albertel 465: <input type="hidden" name="markaccess" value="yes" />
466: <input type="button" name="accessbutton" value="Show Resource" onClick="javascript:if (confirm('Start Timer?')) { document.markaccess.submit(); }" />
467: </form>
468: ENDCHECKOUT
469: }
470:
1.204 albertel 471: sub init_problem_globals {
472: my ($type)=@_;
473: #initialize globals
1.308 foxr 474: # For problems, we start out in part 0 (outside a <part> tag).
475: # and part 0 is used to describe the main body of the <problem>
476: #
1.204 albertel 477: if ($type eq 'problem') {
478: $Apache::inputtags::part='0';
479: @Apache::inputtags::partlist=('0');
1.266 albertel 480: $Apache::lonhomework::problemstatus=&get_problem_status('0');
481: $Apache::lonhomework::ignore_response_errors=0;
1.308 foxr 482:
1.266 albertel 483: } elsif ($type eq 'library') {
1.204 albertel 484: $Apache::inputtags::part='';
485: @Apache::inputtags::partlist=();
486: $Apache::lonhomework::problemstatus='';
1.266 albertel 487: $Apache::lonhomework::ignore_response_errors=1;
1.308 foxr 488:
1.304 albertel 489: } elsif ($type eq 'Task') {
490: $Apache::inputtags::part='0';
491: @Apache::inputtags::partlist=('0');
492: $Apache::lonhomework::problemstatus='';
493: $Apache::lonhomework::ignore_response_errors=1;
1.204 albertel 494: }
495: @Apache::inputtags::responselist = ();
496: @Apache::inputtags::importlist = ();
497: @Apache::inputtags::previous=();
498: @Apache::inputtags::previous_version=();
499: $Apache::structuretags::printanswer='No';
500: @Apache::structuretags::whileconds=();
501: @Apache::structuretags::whilebody=();
502: @Apache::structuretags::whileline=();
503: $Apache::lonhomework::scantronmode=0;
504: undef($Apache::lonhomework::name);
505:
506: }
507:
508: sub reset_problem_globals {
509: my ($type)=@_;
510: undef(%Apache::lonhomework::history);
511: undef(%Apache::lonhomework::results);
512: undef($Apache::inputtags::part);
1.208 albertel 513: #don't undef this, lonhomework.pm takes care of this, we use this to
514: #detect if we try to do 2 problems in one file
515: # undef($Apache::lonhomework::parsing_a_problem);
1.204 albertel 516: undef($Apache::lonhomework::name);
517: }
518:
1.241 albertel 519: sub set_problem_state {
1.240 albertel 520: my ($part)=@_;
1.284 albertel 521: if ($env{'form.problemstate'} eq 'CANNOT_ANSWER_correct') {
1.240 albertel 522: $Apache::lonhomework::history{"resource.$part.solved"}=
523: 'correct_by_student';
524: }
525: }
526:
1.241 albertel 527: sub get_problem_status {
528: my ($part)=@_;
1.267 albertel 529: my $problem_status;
1.284 albertel 530: if ($env{'request.state'} eq 'construct' &&
531: defined($env{'form.problemstatus'})) {
532: $problem_status=$env{'form.problemstatus'};
1.267 albertel 533: } else {
534: $problem_status=&Apache::lonnet::EXT("resource.$part.problemstatus");
535: &Apache::lonxml::debug("problem status for $part is $problem_status");
1.284 albertel 536: &Apache::lonxml::debug("env probstat is ".$env{'form.problemstatus'});
1.241 albertel 537: }
538: return $problem_status;
539: }
540:
1.9 albertel 541: sub start_problem {
1.326 albertel 542: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.19 albertel 543:
1.311 foxr 544: # We'll use the redirection to fix up printing of duedates.
1.321 albertel 545: if (!$Apache::lonxml::metamode) {
546: &Apache::lonxml::startredirection();
547: }
1.311 foxr 548:
1.308 foxr 549: # Problems don't nest and we don't allow more than one <problem> in
550: # a .problem file.
551: #
1.184 albertel 552: if ( $Apache::inputtags::part ne '' ||
553: $Apache::lonhomework::parsing_a_problem) {
554: &Apache::lonxml::error('Only one <problem> allowed in a .problem file');
1.326 albertel 555: #my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,$style);
1.159 albertel 556: return '';
557: }
1.184 albertel 558:
559: $Apache::lonhomework::parsing_a_problem=1;
1.204 albertel 560: &init_problem_globals('problem');
1.166 albertel 561:
1.284 albertel 562: if (defined($env{'scantron.maxquest'})) {
1.166 albertel 563: $Apache::lonhomework::scantronmode=1;
564: }
1.161 albertel 565:
1.246 albertel 566: &initialize_storage();
1.159 albertel 567: if ($target ne 'analyze') {
568: if ($target eq 'web') {
569: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1.238 albertel 570: }
1.284 albertel 571: if ($env{'request.state'} eq 'construct') { &set_problem_state('0'); }
1.159 albertel 572: $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type');
1.284 albertel 573: if (($env{'request.state'} eq 'construct') &&
574: defined($env{'form.problemtype'})) {
575: $Apache::lonhomework::type=$env{'form.problemtype'};
1.237 albertel 576: }
1.332 albertel 577: &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
1.159 albertel 578: }
1.164 albertel 579: if ($Apache::lonhomework::type eq '' ) {
1.284 albertel 580: my $uri=$env{'request.uri'};
1.159 albertel 581: if ($uri=~/\.(\w+)$/) {
582: $Apache::lonhomework::type=$1;
583: &Apache::lonxml::debug("Using type of $1");
584: } else {
585: $Apache::lonhomework::type='problem';
586: &Apache::lonxml::debug("Using default type, problem, :$uri:");
587: }
1.87 albertel 588: }
1.301 albertel 589: $Apache::lonhomework::default_type = $Apache::lonhomework::type;
1.58 www 590:
1.159 albertel 591: #added vars to the scripting enviroment
1.213 albertel 592: my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
1.248 albertel 593: $expression.='$external::type=\''.$Apache::lonhomework::type.'\';';
1.24 albertel 594: &Apache::run::run($expression,$safeeval);
1.159 albertel 595: my $status;
596: my $accessmsg;
597:
1.343 albertel 598: my $name= &get_resource_name($parstack,$safeeval);
1.350 ! albertel 599: my ($result,$form_tag_start);
! 600: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex') {
! 601: ($result,$form_tag_start) =
! 602: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
! 603: $name);
! 604: }
! 605:
1.284 albertel 606: if ($target eq 'tex' and $env{'request.symb'} =~ m/\.page_/) {$result='';}
1.159 albertel 607:
608: if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval); }
609: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
610: $target eq 'tex') {
611: #handle exam checkout
612: if ($Apache::lonhomework::type eq 'exam') {
613: my $token=
614: $Apache::lonhomework::history{"resource.0.outtoken"};
1.284 albertel 615: if (($env{'form.doescheckout'}) && (!$token)) {
1.159 albertel 616: $token=&Apache::lonxml::maketoken();
617: $Apache::lonhomework::history{"resource.0.outtoken"}=
618: $token;
619: }
1.343 albertel 620: $result.=&Apache::lonxml::printtokenheader($target,$token);
1.142 albertel 621: }
1.284 albertel 622: if ($env{'form.markaccess'}) {
1.252 albertel 623: &Apache::lonnet::set_first_access('map');
624: }
1.159 albertel 625: #handle rand seed in construction space
626: my $rndseed=&setup_rndseed($safeeval);
1.162 albertel 627: my ($symb)=&Apache::lonxml::whichuser();
1.333 albertel 628: if ($env{'request.state'} ne "construct" &&
629: ($symb eq '' || $Apache::lonhomework::type eq 'practice')) {
1.162 albertel 630: $form_tag_start.='<input type="hidden" name="rndseed" value="'.
631: $rndseed.'" />'.
632: '<input type="submit" name="resetdata"
1.334 albertel 633: value="'.&mt('New Problem Variation').'" />';
634: if (exists($env{'form.username'})) {
635: $form_tag_start.=
1.164 albertel 636: '<input type="hidden" name="username"
1.284 albertel 637: value="'.$env{'form.username'}.'" />';
1.334 albertel 638: }
1.333 albertel 639: if ($env{'request.role.adv'}) {
1.267 albertel 640: $form_tag_start.=
1.300 albertel 641: ' <label><input type="checkbox" name="showallfoils" ';
1.284 albertel 642: if (defined($env{'form.showallfoils'})) {
1.267 albertel 643: $form_tag_start.='checked="on"';
644: }
1.300 albertel 645: $form_tag_start.= ' />'.&mt(' Show All Foils').
646: '</label>';
1.267 albertel 647: }
648: $form_tag_start.='<hr />';
1.162 albertel 649: }
1.324 albertel 650:
651: ($status,$accessmsg,my $slot_name,my $slot) =
652: &Apache::lonhomework::check_slot_access('0','problem');
1.159 albertel 653: push (@Apache::inputtags::status,$status);
1.324 albertel 654:
1.159 albertel 655: my $expression='$external::datestatus="'.$status.'";';
656: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
657: &Apache::run::run($expression,$safeeval);
658: &Apache::lonxml::debug("Got $status");
1.324 albertel 659:
1.159 albertel 660: if (( $status eq 'CLOSED' ) ||
661: ( $status eq 'UNCHECKEDOUT') ||
1.252 albertel 662: ( $status eq 'NOT_YET_VIEWED') ||
1.159 albertel 663: ( $status eq 'BANNED') ||
1.216 albertel 664: ( $status eq 'UNAVAILABLE') ||
1.324 albertel 665: ( $status eq 'NOT_IN_A_SLOT') ||
1.216 albertel 666: ( $status eq 'INVALID_ACCESS')) {
1.326 albertel 667: my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,
668: $style);
1.159 albertel 669: if ( $target eq "web" ) {
1.343 albertel 670: my $msg;
1.159 albertel 671: if ($status eq 'UNAVAILABLE') {
1.245 albertel 672: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.253 albertel 673: } elsif ($status ne 'NOT_YET_VIEWED') {
1.245 albertel 674: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
1.159 albertel 675: }
1.216 albertel 676: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
1.159 albertel 677: $msg.='The problem '.$accessmsg;
678: } elsif ($status eq 'UNCHECKEDOUT') {
1.343 albertel 679: $msg.=&checkout_msg();
1.252 albertel 680: } elsif ($status eq 'NOT_YET_VIEWED') {
1.253 albertel 681: $msg.=&firstaccess_msg($accessmsg,$symb);
1.325 albertel 682: } elsif ($status eq 'NOT_IN_A_SLOT') {
683: $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work.");
1.159 albertel 684: }
685: $result.=$msg.'<br />';
686: } elsif ($target eq 'tex') {
1.332 albertel 687: my $startminipage = ($env{'form.problem_split'}=~/yes/i)? ''
688: : '\begin{minipage}{\textwidth}';
689: $result.='\begin{document}\noindent \vskip 1 mm '.
690: $startminipage.'\vskip 0 mm';
1.159 albertel 691: if ($status eq 'UNAVAILABLE') {
1.211 albertel 692: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
1.159 albertel 693: } else {
1.211 albertel 694: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
1.159 albertel 695: }
696: }
1.324 albertel 697: } elsif ($status eq 'NEEDS_CHECKIN') {
1.326 albertel 698: my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,
699: $style);
1.324 albertel 700: if ($target eq 'web') {
701: $result .= &Apache::bridgetask::proctor_validation_screen();
702: } elsif ($target eq 'grade') {
703: &Apache::bridgetask::proctor_check_auth($slot_name,$slot,
704: 'problem');
705: }
1.159 albertel 706: } elsif ($target eq 'web') {
1.343 albertel 707: $result.="\n $form_tag_start".
1.227 albertel 708: '<input type="hidden" name="submitted" value="yes" />';
709: # create a page header and exit
1.284 albertel 710: if ($env{'request.state'} eq "construct") {
711: $result.= &problem_web_to_edit_header($env{'form.rndseed'});
1.227 albertel 712: }
713: # if we are viewing someone else preserve that info
1.284 albertel 714: if (defined $env{'form.grade_symb'}) {
1.227 albertel 715: foreach my $field ('symb','courseid','domain','username') {
716: $result .= '<input type="hidden" name="grade_'.$field.
1.284 albertel 717: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
1.159 albertel 718: }
719: }
720: } elsif ($target eq 'tex') {
1.319 foxr 721: $result .= 'INSERTTEXFRONTMATTERHERE';
722:
1.99 sakharuk 723: }
1.159 albertel 724: } elsif ($target eq 'edit') {
1.343 albertel 725: $result .= $form_tag_start.&problem_edit_header();
1.226 albertel 726: $Apache::lonxml::warnings_error_header=
727: &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 728: my $temp=&Apache::edit::insertlist($target,$token);
729: $result.=$temp;
730: } elsif ($target eq 'modified') {
731: $result=$token->[4];
732: $result.=&Apache::edit::handle_insert();
733: } else {
734: # page_start returned a starting result, delete it if we don't need it
735: $result = '';
1.99 sakharuk 736: }
1.159 albertel 737: return $result;
1.9 albertel 738: }
739:
740: sub end_problem {
1.159 albertel 741: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.321 albertel 742: my $result;
1.310 foxr 743:
1.321 albertel 744: if (!$Apache::lonxml::metamode) {
745: $result = &Apache::lonxml::endredirection(); #started in &start_problem
1.329 albertel 746: $Apache::lonxml::post_evaluate=0;
1.321 albertel 747: }
1.319 foxr 748:
749: if ($target eq 'tex') {
1.321 albertel 750:
751: # Figure out the front matter and replace the
752: # INSERTTEXFRONTMATTERHERE in result with it. note that we do
753: # this in end_problem because whether or not we display due
754: # dates depends on whether due dates have already been
755: # displayed in the problem parts.
756:
1.319 foxr 757: my $frontmatter = '';
758: my $startminipage = '';
759: if (not $env{'form.problem_split'}=~/yes/) {
760: $startminipage = '\begin{minipage}{\textwidth}';
761: }
762: my $id = $Apache::inputtags::part;
763: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
764: my $packages=&Apache::lonnet::metadata($env{'request.uri'},'packages');
765: my @packages = split /,/,$packages;
766: my $allow_print_points = 0;
767: foreach my $partial_key (@packages) {
768: if ($partial_key=~m/^part_0$/) {
769: $allow_print_points=1;
770: }
771: }
772: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
773: if (defined($maxtries) && $maxtries < 0) { $allow_print_points=0; }
774: if (lc($env{'course.'.$env{'request.course.id'}.
775: '.disableexampointprint'}) eq 'yes') {
776: $allow_print_points=0;
777: }
778: my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header');
779: my $begin_doc='\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource <h2>"'.$name_of_resourse.'"</h2> located in <br /><small><b>'.$env{'request.uri'}.'</b></small><br /> STAMPOFPASSEDRESOURCEEND} \noindent ';
780: my $toc_line='\vskip 1 mm\noindent '.$startminipage.
781: '\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}';
782:
783: # Figure out what the due date is and if we need to print
784: # it in the problem header. We have been logging the
785: # last due date written to file.
786:
787: my $duetime = &Apache::lonnet::EXT("resource.$id.duedate");
788: my $duedate = POSIX::strftime("%c",localtime($duetime));
789: my $temp_file;
790: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due";
791:
792: # Figure out what the last printed due date is or set it
793: # to the epoch if no duedates have been printed.
794:
795: my $due_file_content = 0; # If the file does not yet exist, time is the epoch.
796: if (-e $filename) {
797: $temp_file = Apache::File->new($filename);
798: my @due_file = <$temp_file>;
799: $due_file_content = $due_file[$#due_file];
800: chomp $due_file_content;
801: }
802:
803: # We display the due date iff it is not the same as the last
804: # duedate in problem header ($due_file_content), and
805: # none of our parts displayed a duedate.
806: #
807: my $parts_with_displayduedate;
808: if (defined $Apache::outputtags::showonce{'displayduedate'}) {
809: $parts_with_displayduedate =
810: scalar(@{$Apache::outputtags::showonce{'displayduedate'}});
811: } else {
812: $parts_with_displayduedate = 0;
813: }
814: if (($due_file_content != $duetime) && ($parts_with_displayduedate == 0) ) {
815: $temp_file = Apache::File->new('>'.$filename);
816: print $temp_file "$duetime\n";
817: if (not $env{'request.symb'} =~ m/\.page_/) {
818: if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') {
819: $frontmatter .= $begin_doc.
820: '\textit{Due date: '.$duedate.'} '.$toc_line;
821: } else {
822: $frontmatter.= $begin_doc.$toc_line;
823: if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';}
824: }
825: } else {
826: $frontmatter .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\';
827: }
828: } else {
829: if (not $env{'request.symb'} =~ m/\.page_/) {
830: $frontmatter .= $begin_doc.$toc_line;
831: if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';}
832: } else {
833: $frontmatter .= '\vskip 1mm \\\\\\\\';
834: }
835: }
836: $result =~ s/INSERTTEXFRONTMATTERHERE/$frontmatter/;
837: }
838:
1.159 albertel 839: my $status=$Apache::inputtags::status['-1'];
840: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
841: $target eq 'tex') {
1.249 albertel 842: if ( $target eq 'grade' && $Apache::inputtags::part eq '0') {
1.159 albertel 843: # if part is zero, no <part>s existed, so we need to the grading
1.249 albertel 844: if ($status eq 'CAN_ANSWER' ||$Apache::lonhomework::scantronmode) {
845: &Apache::inputtags::grade;
1.324 albertel 846: } elsif ($status eq 'NEEDS_CHECKIN') {
847: # no need to grade, and don't want to hide data
1.249 albertel 848: } else {
849: # move any submission data to .hidden
850: &Apache::inputtags::hidealldata($Apache::inputtags::part);
851: }
1.159 albertel 852: } elsif ( ($target eq 'web' || $target eq 'tex') &&
853: $Apache::inputtags::part eq '0' &&
1.252 albertel 854: $status ne 'UNCHECKEDOUT' && $status ne 'NOT_YET_VIEWED') {
1.159 albertel 855: # if part is zero, no <part>s existed, so we need show the current
856: # grading status
857: my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
858: $result.= $gradestatus;
859: }
860: if (
1.284 albertel 861: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.159 albertel 862: ($target eq 'answer') || ($target eq 'tex')
863: ) {
1.227 albertel 864: if ($target ne 'tex' &&
1.284 albertel 865: $env{'form.answer_output_mode'} ne 'tex') {
1.254 www 866: $result.="</form>";
1.348 albertel 867: $result.= &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields());
1.159 albertel 868: }
869: if ($target eq 'web') {
1.346 albertel 870: $result.= &Apache::loncommon::end_page({'discussion' => 1});
1.159 albertel 871: } elsif ($target eq 'tex') {
1.178 sakharuk 872: my $endminipage = '';
1.284 albertel 873: if (not $env{'form.problem_split'}=~/yes/) {
1.178 sakharuk 874: $endminipage = '\end{minipage}';
875: }
1.284 albertel 876: if ($env{'form.print_discussions'} eq 'yes') {
1.263 sakharuk 877: $result.=&Apache::lonxml::xmlend($target,$parser);
1.159 albertel 878: } else {
1.262 sakharuk 879: $result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
1.284 albertel 880: if (not $env{'request.symb'} =~ m/\.page_/) {
1.262 sakharuk 881: $result .= $endminipage.'\end{document} ';
882: } else {
883: $result .= '';
884: }
1.159 albertel 885: }
886: }
887: }
888: if ($target eq 'grade') {
889: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
890: &finalize_storage();
891: }
1.284 albertel 892: if ($target eq 'answer' && ($env{'request.state'} eq 'construct')
893: && $env{'form.answer_output_mode'} ne 'tex') {
1.346 albertel 894: $result.=&Apache::loncommon::end_page({'discussion' => 1});
1.294 albertel 895: # normally we get it from above, but in CSTR
1.172 albertel 896: # we always show answer mode too.
1.159 albertel 897: }
898: } elsif ($target eq 'meta') {
899: if ($Apache::inputtags::part eq '0') {
1.179 albertel 900: @Apache::inputtags::response=();
1.159 albertel 901: $result=&Apache::response::mandatory_part_meta;
902: }
1.215 albertel 903: $result.=&Apache::response::meta_part_order();
1.258 albertel 904: $result.=&Apache::response::meta_response_order();
1.159 albertel 905: } elsif ($target eq 'edit') {
906: &Apache::lonxml::debug("in end_problem with $target, edit");
1.314 albertel 907: $result .= &problem_edit_footer();
1.320 albertel 908: } elsif ($target eq 'modified') {
909: $result .= $token->[2];
910: $result.=&Apache::edit::handle_insertafter($token->[1]);
1.159 albertel 911: }
1.155 albertel 912:
1.284 albertel 913: if ($env{'request.state'} eq 'construct' && $target eq 'web') {
1.177 albertel 914: &Apache::inputtags::check_for_duplicate_ids();
915: }
1.204 albertel 916:
917: &reset_problem_globals('problem');
1.159 albertel 918:
919: return $result;
1.48 albertel 920: }
921:
1.108 albertel 922:
1.48 albertel 923: sub start_library {
1.159 albertel 924: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.343 albertel 925: my ($result,$form_tag_start);
1.244 albertel 926: if ($$tagstack[0] eq 'library') {
927: &init_problem_globals('library');
928: $Apache::lonhomework::type='problem';
929: }
1.159 albertel 930: if ($target eq 'edit') {
1.343 albertel 931: ($result,$form_tag_start)=
932: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
933: 'Edit');
934: $result.=$form_tag_start.&problem_edit_header();
1.159 albertel 935: my $temp=&Apache::edit::insertlist($target,$token);
936: $result.=$temp;
937: } elsif ($target eq 'modified') {
938: $result=$token->[4];
939: $result.=&Apache::edit::handle_insert();
1.340 albertel 940: } elsif (($target eq 'web' || $target eq 'webgrade')
941: && $$tagstack[0] eq 'library'
942: && $env{'request.state'} eq "construct" ) {
1.159 albertel 943: my $name=&get_resource_name($parstack,$safeeval);
1.343 albertel 944: ($result,$form_tag_start)=
945: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
946: $name);
1.159 albertel 947: my $rndseed=&setup_rndseed($safeeval);
1.343 albertel 948: $result.=" \n $form_tag_start".
1.159 albertel 949: '<input type="hidden" name="submitted" value="yes" />';
950: $result.=&problem_web_to_edit_header($rndseed);
951: }
952: return $result;
1.48 albertel 953: }
954:
955: sub end_library {
1.159 albertel 956: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
957: my $result='';
958: if ($target eq 'edit') {
959: $result=&problem_edit_footer();
960: } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' &&
1.284 albertel 961: $env{'request.state'} eq "construct") {
1.349 albertel 962: $result.='</form>'.&Apache::loncommon::end_page({'discussion' => 1});
1.159 albertel 963: }
1.204 albertel 964: if ($$tagstack[0] eq 'library') { &reset_problem_globals('library') };
1.159 albertel 965: return $result;
1.197 www 966: }
967:
968: sub start_definetag {
1.326 albertel 969: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.197 www 970:
971: my $result;
972:
973: my $name = $token->[2]->{'name'};
1.326 albertel 974: my $skip=&Apache::lonxml::get_all_text("/definetag",$parser,$style);
1.197 www 975: if ($name=~/^\//) {
976: $result=
977: '<br /><table bgcolor="#FFBBBB"><tr><th>END <tt>'.$name.'</tt></th></tr>';
978: } else {
979: $result=
980: '<br /><table bgcolor="#BBFFBB"><tr><th>BEGIN <tt>'.$name.'</tt></th></tr>';
981: }
982: $skip=~s/\</\<\;/gs;
983: $skip=~s/\>/\>\;/gs;
984: $result.='<tr><td><pre>'.$skip.'</pre></td></tr></table>';
985: return $result;
986: }
987:
988: sub end_definetag {
989: return '';
1.1 albertel 990: }
991:
992: sub start_block {
1.201 albertel 993: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.131 albertel 994:
995: my $result;
1.1 albertel 996:
1.339 albertel 997: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
998: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.159 albertel 999: my $code = $token->[2]->{'condition'};
1.201 albertel 1000: if (defined($code)) {
1.137 albertel 1001: if (!$Apache::lonxml::default_homework_loaded) {
1002: &Apache::lonxml::default_homework_load($safeeval);
1003: }
1.131 albertel 1004: $result = &Apache::run::run($code,$safeeval);
1005: &Apache::lonxml::debug("block :$code: returned :$result:");
1006: } else {
1007: $result='1';
1008: }
1009: if ( ! $result ) {
1.201 albertel 1010: my $skip=&Apache::lonxml::get_all_text("/block",$parser,$style);
1.131 albertel 1011: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
1012: }
1013: $result='';
1014: } elsif ($target eq 'edit') {
1015: $result .=&Apache::edit::tag_start($target,$token);
1016: $result .=&Apache::edit::text_arg('Test Condition:','condition',
1017: $token,40);
1018: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1019: } elsif ($target eq 'modified') {
1020: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1021: $safeeval,'condition');
1022: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.38 albertel 1023: }
1.131 albertel 1024: return $result;
1.1 albertel 1025: }
1026:
1027: sub end_block {
1.167 www 1028: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1029: my $result;
1030: if ($target eq "edit") {
1031: $result.= &Apache::edit::tag_end($target,$token,'');
1032: }
1033: return $result;
1034: }
1035:
1036: sub start_languageblock {
1.201 albertel 1037: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.167 www 1038:
1039: my $result;
1040:
1.339 albertel 1041: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1042: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.201 albertel 1043: my $include = $token->[2]->{'include'};
1044: my $exclude = $token->[2]->{'exclude'};
1045: my %languages=&Apache::loncommon::display_languages();
1046: $result='1';
1047: if ($include) {
1048: $result='';
1049: foreach (split(/\,/,$include)) {
1050: if ($languages{$_}) { $result='1'; }
1051: }
1052: }
1053: if ($exclude) {
1054: foreach (split(/\,/,$exclude)) {
1055: if ($languages{$_}) { $result='0'; }
1056: }
1057: }
1058: if ( ! $result ) {
1059: my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser,
1060: $style);
1061: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
1062: }
1063: $result='';
1.167 www 1064: } elsif ($target eq 'edit') {
1065: $result .=&Apache::edit::tag_start($target,$token);
1.211 albertel 1066: $result .=&Apache::edit::text_arg(&mt('Include Language:'),'include',
1.167 www 1067: $token,40);
1.211 albertel 1068: $result .=&Apache::edit::text_arg(&mt('Exclude Language:'),'exclude',
1.167 www 1069: $token,40);
1070: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1071: } elsif ($target eq 'modified') {
1072: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.168 albertel 1073: $safeeval,'include',
1074: 'exclude');
1.167 www 1075: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1076: }
1077: return $result;
1078: }
1079:
1080: sub end_languageblock {
1.170 www 1081: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1082: my $result;
1.201 albertel 1083: if ($target eq "edit") {
1.170 www 1084: $result.= &Apache::edit::tag_end($target,$token,'');
1085: }
1086: return $result;
1087: }
1088:
1089: sub start_instructorcomment {
1.201 albertel 1090: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.170 www 1091:
1092: my $result;
1093:
1.339 albertel 1094: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1095: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.284 albertel 1096: $result=($env{'request.role'}=~/^(in|cc|au|ca|li)/);
1097: if ( (! $result) or ($env{'form.instructor_comments'} eq 'hide')) {
1.201 albertel 1098: my $skip=&Apache::lonxml::get_all_text("/instructorcomment",
1099: $parser,$style);
1.170 www 1100: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
1101: }
1102: $result='';
1103: } elsif ($target eq 'edit') {
1104: $result .=&Apache::edit::tag_start($target,$token);
1105: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1106: }
1107: return $result;
1108: }
1109:
1110: sub end_instructorcomment {
1.159 albertel 1111: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 1112: my $result;
1113: if ($target eq "edit") {
1114: $result.= &Apache::edit::tag_end($target,$token,'');
1115: }
1116: return $result;
1.4 tsai 1117: }
1118:
1119: sub start_while {
1.326 albertel 1120: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 1121:
1.160 albertel 1122: my $result;
1.339 albertel 1123: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1124: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.160 albertel 1125: my $code = $token->[2]->{'condition'};
1.4 tsai 1126:
1.160 albertel 1127: push( @Apache::structuretags::whileconds, $code);
1128: if (!$Apache::lonxml::default_homework_loaded) {
1129: &Apache::lonxml::default_homework_load($safeeval);
1130: }
1131: my $result = &Apache::run::run($code,$safeeval);
1.326 albertel 1132: my $bodytext=&Apache::lonxml::get_all_text("/while",$parser,$style);
1.160 albertel 1133: push( @Apache::structuretags::whilebody, $bodytext);
1.161 albertel 1134: push( @Apache::structuretags::whileline, $token->[5]);
1135: &Apache::lonxml::debug("s code $code got -$result-");
1.160 albertel 1136: if ( $result ) {
1137: &Apache::lonxml::newparser($parser,\$bodytext);
1138: }
1139: } elsif ($target eq 'edit') {
1140: $result .=&Apache::edit::tag_start($target,$token);
1.211 albertel 1141: $result .=&Apache::edit::text_arg(&mt('Test Condition:'),'condition',
1.160 albertel 1142: $token,40);
1143: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1144: } elsif ($target eq 'modified') {
1145: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1146: $safeeval,'condition');
1147: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.159 albertel 1148: }
1.160 albertel 1149: return $result;
1.4 tsai 1150: }
1151:
1152: sub end_while {
1.159 albertel 1153: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 1154: my $result;
1155:
1.339 albertel 1156: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1157: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.160 albertel 1158: my $code = pop(@Apache::structuretags::whileconds);
1159: my $bodytext = pop(@Apache::structuretags::whilebody);
1.161 albertel 1160: my $line = pop(@Apache::structuretags::whileline);
1161: my $return = &Apache::run::run($code,$safeeval);
1162: my $starttime=time;
1163: my $error=0;
1164: while ($return) {
1165: if (time-$starttime >
1166: $Apache::lonnet::perlvar{'lonScriptTimeout'}) {
1.270 albertel 1167: #$return = 0; $error=1; next;
1.161 albertel 1168: }
1169: $result.=&Apache::scripttag::xmlparse($bodytext);
1170: $return = &Apache::run::run($code,$safeeval);
1171: }
1172: if ($error) {
1.270 albertel 1173: &Apache::lonxml::error('<pre>'.&mt('Code ran too long. It ran for more than').' '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' '.&mt('seconds occured while running <while> on line').' '.$line.'</pre>');
1.160 albertel 1174: }
1175: } elsif ($target eq "edit") {
1176: $result.= &Apache::edit::tag_end($target,$token,'');
1.159 albertel 1177: }
1.160 albertel 1178: return $result;
1.1 albertel 1179: }
1.6 tsai 1180:
1.160 albertel 1181: # <randomlist show="1">
1.6 tsai 1182: # <tag1>..</tag1>
1183: # <tag2>..</tag2>
1184: # <tag3>..</tag3>
1.160 albertel 1185: # ...
1.6 tsai 1186: # </randomlist>
1187: sub start_randomlist {
1.326 albertel 1188: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 1189: my $result;
1.339 albertel 1190: if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' ||
1191: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.331 albertel 1192: my $body= &Apache::lonxml::get_all_text("/randomlist",$parser);
1.305 albertel 1193: my $b_parser= HTML::LCParser->new(\$body);
1194: $b_parser->xml_mode(1);
1195: $b_parser->marked_sections(1);
1.159 albertel 1196: my $b_tok;
1197: my @randomlist;
1198: my $list_item;
1199: while($b_tok = $b_parser->get_token() ) {
1200: if($b_tok->[0] eq 'S') { # start tag
1201: # get content of the tag until matching end tag
1202: # get all text upto the matching tag
1203: # and push the content into @randomlist
1204: $list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],
1205: $b_parser);
1206: $list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
1207: push(@randomlist,$list_item);
1208: # print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4],
1209: # $list_item</b>";
1210: }
1211: if($b_tok->[0] eq 'T') { # text
1212: # what to do with text in between tags?
1213: # print "<b>TEXT $b_tok->[1]</b><br />";
1214: }
1215: # if($b_tok->[0] eq 'E') { # end tag, should not happen
1216: # print "<b>END-TAG $b_tok->[1]</b><br />";
1217: # }
1218: }
1.303 albertel 1219: if (@randomlist) {
1220: my @idx_arr = (0 .. $#randomlist);
1221: &Apache::structuretags::shuffle(\@idx_arr);
1222: my $bodytext = '';
1223: my $show=$#randomlist;
1224: my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
1225: $showarg--;
1226: if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
1227: for(0 .. $show) {
1228: $bodytext .= "$randomlist[ $idx_arr[$_] ]";
1229: }
1230: &Apache::lonxml::newparser($parser,\$bodytext);
1.159 albertel 1231: }
1232: } elsif ($target eq 'edit' ) {
1233: $result .=&Apache::edit::tag_start($target,$token);
1234: $result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
1235: $token,5);
1236: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1237: } elsif ($target eq 'modified' ) {
1238: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1239: $safeeval,'show');
1240: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1241: }
1242: return $result;
1.7 tsai 1243: }
1244:
1245: sub shuffle {
1246: my $a=shift;
1247: my $i;
1.303 albertel 1248: if (ref($a) eq 'ARRAY' && @$a) {
1.251 albertel 1249: &Apache::response::pushrandomnumber();
1.159 albertel 1250: for($i=@$a;--$i;) {
1251: my $j=int(&Math::Random::random_uniform() * ($i+1));
1252: next if $i == $j;
1253: @$a[$i,$j] = @$a[$j,$i];
1254: }
1.251 albertel 1255: &Apache::response::poprandomnumber();
1.7 tsai 1256: }
1.6 tsai 1257: }
1258:
1259: sub end_randomlist {
1.159 albertel 1260: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1261: my $result;
1262: if ($target eq 'edit' ) {
1263: $result=&Apache::edit::tag_end($target,$token,
1264: 'End Randomly Parsed Block');
1265: }
1266: return $result;
1.6 tsai 1267: }
1268:
1.283 albertel 1269: sub ordered_show_check {
1270: my $last_part=$Apache::inputtags::partlist[-2];
1271: my $in_order=
1272: &Apache::lonnet::EXT('resource.'.$Apache::inputtags::part.'.ordered');
1273: my $in_order_show=1;
1274: if ($last_part ne '0' && lc($in_order) eq 'yes') {
1275: $in_order_show=&Apache::response::check_status($last_part);
1276: }
1277: return $in_order_show;
1278: }
1279:
1.11 albertel 1280: sub start_part {
1.326 albertel 1281: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.321 albertel 1282: if (!$Apache::lonxml::metamode) {
1283: &Apache::lonxml::startredirection(); # we'll use redirection to fix up
1284: # duedates.
1285: }
1.159 albertel 1286: my $result='';
1287: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
1.296 albertel 1288: if ($id =~ /^\s*$/) { $id = $Apache::lonxml::curdepth; }
1.159 albertel 1289: $Apache::inputtags::part=$id;
1.177 albertel 1290: push(@Apache::inputtags::partlist,$id);
1291: @Apache::inputtags::response=();
1.159 albertel 1292: @Apache::inputtags::previous=();
1293: @Apache::inputtags::previous_version=();
1.241 albertel 1294: $Apache::lonhomework::problemstatus=&get_problem_status($id);
1.159 albertel 1295: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
1.259 albertel 1296: my $newtype=&Apache::lonnet::EXT("resource.$id.type");
1297: if ($newtype) { $Apache::lonhomework::type=$newtype; }
1.283 albertel 1298: my $in_order_show=&ordered_show_check();
1.214 albertel 1299: my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
1.259 albertel 1300: $expression.='$external::type=\''.$Apache::lonhomework::type.'\';';
1.209 albertel 1301: &Apache::run::run($expression,$safeeval);
1.159 albertel 1302:
1303: if ($target eq 'meta') {
1.224 www 1304: my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
1305: return &Apache::response::mandatory_part_meta.
1306: &Apache::response::meta_parameter_write('display','string',$display,'Part Description');
1.159 albertel 1307: } elsif ($target eq 'web' || $target eq 'grade' ||
1308: $target eq 'answer' || $target eq 'tex') {
1.283 albertel 1309: if ($hidden || !$in_order_show) {
1.326 albertel 1310: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser,$style);
1.159 albertel 1311: } else {
1312: my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
1313: push (@Apache::inputtags::status,$status);
1314: my $expression='$external::datestatus="'.$status.'";';
1315: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
1316: &Apache::run::run($expression,$safeeval);
1.284 albertel 1317: if ($env{'request.state'} eq 'construct') {
1.241 albertel 1318: &set_problem_state($Apache::inputtags::part);
1.240 albertel 1319: }
1.216 albertel 1320: if (( $status eq 'CLOSED' ) ||
1321: ( $status eq 'UNCHECKEDOUT') ||
1.252 albertel 1322: ( $status eq 'NOT_YET_VIEWED') ||
1.216 albertel 1323: ( $status eq 'BANNED') ||
1324: ( $status eq 'UNAVAILABLE') ||
1325: ( $status eq 'INVALID_ACCESS')) {
1.326 albertel 1326: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser,
1327: $style);
1.159 albertel 1328: if ( $target eq "web" ) {
1.211 albertel 1329: $result="<br />".&mt('Part is not open to be viewed. It')." $accessmsg<br />";
1.159 albertel 1330: } elsif ( $target eq 'tex' ) {
1.284 albertel 1331: if (not $env{'form.problem_split'}=~/yes/) {
1.211 albertel 1332: $result="\\end{minipage}\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\\\begin{minipage}{\\textwidth}";
1.195 sakharuk 1333: } else {
1.211 albertel 1334: $result="\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\";
1.195 sakharuk 1335: }
1.159 albertel 1336: }
1337: } else {
1338: if ($target eq 'tex') {
1.284 albertel 1339: if (not $env{'form.problem_split'}=~/yes/) {
1.264 sakharuk 1340: if ($$tagstack[-2] eq 'td') {
1341: $result.='\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
1342: } else {
1343: $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
1344: }
1.195 sakharuk 1345: }
1.159 albertel 1346: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
1.284 albertel 1347: my $allkeys=&Apache::lonnet::metadata($env{'request.uri'},'packages');
1.222 sakharuk 1348: my @allkeys = split /,/,$allkeys;
1349: my $allow_print_points = 0;
1350: foreach my $partial_key (@allkeys) {
1.230 albertel 1351: if ($partial_key=~m/^part_(.*)$/) {
1.222 sakharuk 1352: if ($1 ne '0') {$allow_print_points=1;}
1353: }
1354: }
1.275 albertel 1355: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
1356: if (defined($maxtries) && $maxtries < 0) {
1357: $allow_print_points=0;
1358: }
1.302 albertel 1359: if (lc($env{'course.'.$env{'request.course.id'}.
1360: '.disableexampointprint'}) eq 'yes') {
1361: $allow_print_points=0;
1362: }
1.222 sakharuk 1363: if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { $result .= '\fbox{\textit{'.$weight.' pt}}';}
1.233 www 1364: } elsif ($target eq 'web') {
1365: $result.='<a name="'.&Apache::lonnet::escape($Apache::inputtags::part).'" />';
1.159 albertel 1366: }
1367: }
1368: }
1369: } elsif ($target eq 'edit') {
1370: $result.=&Apache::edit::tag_start($target,$token);
1371: $result.=&Apache::edit::text_arg('Part ID:','id',$token).
1372: &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help").
1.224 www 1373: ' '.
1374: &Apache::edit::text_arg('Displayed Part Description:','display',$token).
1.159 albertel 1375: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
1376: } elsif ($target eq 'modified') {
1377: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.225 albertel 1378: $safeeval,'id','display');
1.159 albertel 1379: if ($constructtag) {
1.225 albertel 1380: #limiting ids to only letters numbers, and space
1.224 www 1381: $token->[2]->{'id'}=~s/[^A-Za-z0-9 ]//gs;
1.159 albertel 1382: $result = &Apache::edit::rebuild_tag($token);
1383: $result.=&Apache::edit::handle_insert();
1384: }
1385: }
1386: return $result;
1.11 albertel 1387: }
1388:
1389: sub end_part {
1.159 albertel 1390: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1391: &Apache::lonxml::debug("in end_part $target ");
1392: my $status=$Apache::inputtags::status['-1'];
1393: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
1.283 albertel 1394: my $in_order_show=&ordered_show_check();
1.321 albertel 1395: my $result;
1396: if (!$Apache::lonxml::metamode) {
1397: $result = &Apache::lonxml::endredirection(); # started in &start_part
1.329 albertel 1398: $Apache::lonxml::post_evaluate=0;
1.321 albertel 1399: }
1.312 albertel 1400: if ($target eq 'grade') {
1.249 albertel 1401: if (($status eq 'CAN_ANSWER' || $Apache::lonhomework::scantronmode) &&
1.283 albertel 1402: !$hidden && $in_order_show) {
1.311 foxr 1403: $result.=&Apache::inputtags::grade;
1.249 albertel 1404: } else {
1405: # move any submission data to .hidden
1406: &Apache::inputtags::hidealldata($Apache::inputtags::part);
1407: }
1.283 albertel 1408: } elsif (($target eq 'web' || $target eq 'tex') &&
1409: !$hidden && $in_order_show) {
1.159 albertel 1410: my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
1411: $target);
1.212 albertel 1412: if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') {
1413: $gradestatus='';
1414: }
1.311 foxr 1415: $result.=$gradestatus;
1.265 sakharuk 1416: if ($$tagstack[-2] eq 'td' and $target eq 'tex') {$result.='\end{minipage}';}
1.181 albertel 1417: } elsif ($target eq 'edit') {
1.311 foxr 1418: $result.=&Apache::edit::end_table();
1.322 albertel 1419: } elsif ($target eq 'modified') {
1420: $result .= $token->[2];
1421: $result.=&Apache::edit::handle_insertafter($token->[1]);
1.159 albertel 1422: }
1423: pop @Apache::inputtags::status;
1424: $Apache::inputtags::part='';
1.295 albertel 1425: $Apache::lonhomework::type = $Apache::lonhomework::default_type;
1.159 albertel 1426: return $result;
1.11 albertel 1427: }
1.1 albertel 1428:
1.25 albertel 1429: sub start_preduedate {
1.326 albertel 1430: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.339 albertel 1431: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1432: $target eq 'tex' || $target eq 'webgrade') {
1.236 albertel 1433: &Apache::lonxml::debug("State in preduedate is ". $Apache::inputtags::status['-1']);
1.300 albertel 1434: if (!$Apache::lonhomework::scantronmode &&
1435: $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
1.236 albertel 1436: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
1437: &Apache::lonxml::debug("Wha? ". ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER'));
1.326 albertel 1438: &Apache::lonxml::get_all_text("/preduedate",$parser,$style);
1.159 albertel 1439: }
1.24 albertel 1440: }
1.159 albertel 1441: return '';
1.24 albertel 1442: }
1443:
1.25 albertel 1444: sub end_preduedate {
1.159 albertel 1445: return '';
1.24 albertel 1446: }
1447:
1.25 albertel 1448: sub start_postanswerdate {
1.326 albertel 1449: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.339 albertel 1450: if ($target eq 'web' || $target eq 'grade' || $target eq 'webgrade') {
1.300 albertel 1451: if ($Apache::lonhomework::scantronmode ||
1452: $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') {
1.326 albertel 1453: &Apache::lonxml::get_all_text("/postanswerdate",$parser,$style);
1.159 albertel 1454: }
1455: } elsif ($target eq 'tex') {
1.326 albertel 1456: &Apache::lonxml::get_all_text("/postanswerdate",$parser,$style);
1.159 albertel 1457: }
1458: return '';
1.24 albertel 1459: }
1460:
1.25 albertel 1461: sub end_postanswerdate {
1.159 albertel 1462: return '';
1.24 albertel 1463: }
1464:
1.25 albertel 1465: sub start_notsolved {
1.326 albertel 1466: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 1467: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.339 albertel 1468: $target eq 'tex' || $target eq 'webgrade') {
1.159 albertel 1469: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
1470: &Apache::lonxml::debug("not solved has :$gradestatus:");
1.239 albertel 1471: if ($gradestatus =~ /^correct/ &&
1472: &Apache::response::show_answer()) {
1.159 albertel 1473: &Apache::lonxml::debug("skipping");
1.326 albertel 1474: &Apache::lonxml::get_all_text("/notsolved",$parser,$style);
1.159 albertel 1475: }
1.24 albertel 1476: }
1.159 albertel 1477: return '';
1.24 albertel 1478: }
1479:
1.25 albertel 1480: sub end_notsolved {
1.159 albertel 1481: return '';
1.24 albertel 1482: }
1483:
1484: sub start_solved {
1.326 albertel 1485: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 1486: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1487: $target eq 'tex') {
1488: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
1.239 albertel 1489: if ($gradestatus !~ /^correct/ ||
1490: !&Apache::response::show_answer()) {
1.326 albertel 1491: &Apache::lonxml::get_all_text("/solved",$parser,$style);
1.159 albertel 1492: }
1.24 albertel 1493: }
1.159 albertel 1494: return '';
1.24 albertel 1495: }
1496:
1497: sub end_solved {
1.248 albertel 1498: return '';
1499: }
1500:
1501: sub start_problemtype {
1.326 albertel 1502: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.248 albertel 1503: my $result;
1.339 albertel 1504: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1505: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.248 albertel 1506: my $mode=lc(&Apache::lonxml::get_param('mode',$parstack,$safeeval));
1507: if (!defined($mode)) { $mode='show'; }
1508: my $for=&Apache::lonxml::get_param('for',$parstack,$safeeval);
1509: my $found=0;
1510: foreach my $type (split(',',$for)) {
1511: if ($Apache::lonhomework::type eq lc($type)) { $found=1; }
1512: }
1513: if ($mode eq 'show' && !$found) {
1.326 albertel 1514: &Apache::lonxml::get_all_text("/problemtype",$parser,$style);
1.248 albertel 1515: }
1516: if ($mode eq 'hide' && $found) {
1.326 albertel 1517: &Apache::lonxml::get_all_text("/problemtype",$parser,$style);
1.248 albertel 1518: }
1519: } elsif ($target eq 'edit') {
1520: $result .=&Apache::edit::tag_start($target,$token);
1521: $result.=&Apache::edit::select_arg('Mode:','mode',
1522: [['show','Show'],
1523: ['hide','Hide']]
1524: ,$token);
1525: $result .=&Apache::edit::checked_arg('When used as type(s):','for',
1526: [ ['exam','Exam/Quiz Problem'],
1527: ['survey','Survey'],
1528: ['problem','Homework Problem'] ]
1529: ,$token);
1530: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1531: } elsif ($target eq 'modified') {
1532: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1533: $safeeval,'mode','for');
1534: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1535: }
1536: return $result;
1537: }
1538:
1539: sub end_problemtype {
1.159 albertel 1540: return '';
1.24 albertel 1541: }
1.34 albertel 1542:
1543: sub start_startouttext {
1.159 albertel 1544: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1545: my @result=(''.'');
1546: if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
1547: return (@result);
1.34 albertel 1548: }
1.159 albertel 1549:
1.34 albertel 1550: sub end_startouttext {
1.326 albertel 1551: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 1552: my $result='';
1553: my $text='';
1554:
1555: if ($target eq 'edit') {
1.326 albertel 1556: $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style);
1.211 albertel 1557: $result.=&Apache::edit::start_table($token)."<tr><td>".&mt('Text Block')."</td>
1558: <td>".&mt('Delete:').
1.159 albertel 1559: &Apache::edit::deletelist($target,$token)
1560: ."</td>
1.42 albertel 1561: <td>".
1.159 albertel 1562: &Apache::edit::insertlist($target,$token).
1563: &Apache::edit::end_row().
1564: &Apache::edit::start_spanning_row()."\n"
1.188 bowersj2 1565: . &Apache::loncommon::helpLatexCheatsheet () .
1.255 www 1566: &Apache::edit::editfield($token->[1],$text,"",80,8,1);
1.159 albertel 1567: }
1568: if ($target eq 'modified') {
1.219 albertel 1569: $result='<startouttext />'.&Apache::edit::modifiedfield("endouttext",$parser);
1.159 albertel 1570: }
1571: if ($target eq 'tex') {
1572: $result .= '\noindent ';
1573: }
1574: return $result;
1.34 albertel 1575: }
1.159 albertel 1576:
1.34 albertel 1577: sub start_endouttext {
1.159 albertel 1578: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1579: my $result='';
1580: if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
1581: if ($target eq "modified") {
1582: $result='<endouttext />'.
1583: &Apache::edit::handle_insertafter('startouttext'); }
1584: return $result;
1.34 albertel 1585: }
1.159 albertel 1586:
1.34 albertel 1587: sub end_endouttext {
1.159 albertel 1588: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1589: my @result=('','');
1590: if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
1591: return (@result);
1.34 albertel 1592: }
1.159 albertel 1593:
1.45 albertel 1594: sub delete_startouttext {
1.326 albertel 1595: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1596: # my $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style);
1.159 albertel 1597: my $text=$$parser['-1']->get_text("/endouttext");
1598: my $ntoken=$$parser['-1']->get_token();
1599: &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
1600: &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
1601: # Deleting 2 parallel tag pairs, but we need the numbers later to look like
1602: # they did the last time round
1603: &Apache::lonxml::increasedepth($ntoken);
1604: &Apache::lonxml::decreasedepth($ntoken);
1605: return 1;
1.193 www 1606: }
1607:
1608: sub start_simpleeditbutton {
1609: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1610: my $result='';
1.284 albertel 1611: if (($env{'form.simple_edit_button'} ne 'off') &&
1.273 albertel 1612: ($target eq 'web') &&
1.330 albertel 1613: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
1.284 albertel 1614: my $url=$env{'request.noversionuri'};
1.193 www 1615: $url=~s/\?.*$//;
1.278 albertel 1616: my ($symb) = &Apache::lonxml::whichuser();
1.194 www 1617: $result='<table width="100%" bgcolor="#FFFFAA" border="2"><tr><td>'.
1.278 albertel 1618: '<a href="'.$url.'/smpedit?symb='.&Apache::lonnet::escape($symb).'">'.&mt('Edit').'</a> - '.&mt('Note: it can take up to 10 minutes for changes to take effect for all users.').
1.196 www 1619: &Apache::loncommon::help_open_topic('Caching').'</td></tr></table><br />';
1.193 www 1620: }
1621: return $result;
1622: }
1623:
1624: sub end_simpleeditbutton {
1625: return '';
1.45 albertel 1626: }
1.34 albertel 1627:
1.1 albertel 1628: 1;
1629: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>