Annotation of loncom/homework/structuretags.pm, revision 1.465.2.14
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.465.2.14! raeburn 4: # $Id: structuretags.pm,v 1.465.2.13 2011/01/13 18:41:48 raeburn 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.435 jms 30: =pod
31:
32: =head1 NAME
33:
34: Apache::structuretags
35:
36: =head1 SYNOPSIS
37:
38:
39: This is part of the LearningOnline Network with CAPA project
40: described at http://www.lon-capa.org.
41:
42:
43: =head1 NOTABLE SUBROUTINES
44:
45: =over
46:
47: =item
48:
49: =back
50:
51: =cut
52:
1.133 sakharuk 53:
1.1 albertel 54: package Apache::structuretags;
55:
56: use strict;
57: use Apache::lonnet;
1.101 sakharuk 58: use Apache::File();
1.147 www 59: use Apache::lonmenu;
1.210 albertel 60: use Apache::lonlocal;
1.231 sakharuk 61: use Apache::lonxml;
1.434 foxr 62: use Apache::londefdef;
1.338 albertel 63: use Apache::lonenc();
1.267 albertel 64: use Time::HiRes qw( gettimeofday tv_interval );
1.356 www 65: use lib '/home/httpd/lib/perl/';
66: use LONCAPA;
67:
1.78 harris41 68: BEGIN {
1.465.2.2 raeburn 69: &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startpartmarker','startouttext','endpartmarker','endouttext','simpleeditbutton','definetag'));
1.10 albertel 70: }
71:
72: sub start_web {
1.326 albertel 73: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.383 albertel 74: if ($target ne 'edit' && $target ne 'modified') {
75: my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style);
76: if ($target eq 'web' || $target eq 'webgrade') {
77: return $bodytext;
78: }
79: } elsif ($target eq "edit" ) {
80: my $bodytext =
81: &Apache::lonxml::get_all_text_unbalanced("/web",$parser);
82: my $result = &Apache::edit::tag_start($target,$token);
83: $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1);
84: return $result;
85: } elsif ( $target eq "modified" ) {
86: return $token->[4].&Apache::edit::modifiedfield("/web",$parser);
1.159 albertel 87: }
88: return '';
1.10 albertel 89: }
90:
91: sub end_web {
1.44 ng 92: return '';
1.10 albertel 93: }
94:
95: sub start_tex {
1.326 albertel 96: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.198 sakharuk 97: my $result='';
1.383 albertel 98: if ($target ne 'edit' && $target ne 'modified') {
99: my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style);
100: if ($target eq 'tex') {
1.434 foxr 101:
102: # If inside a table, occurrences of \\ must be removed;
103: # else the table blows up.
104:
105: if (&Apache::londefdef::is_inside_of($tagstack, "table")) {
106: $bodytext =~ s/\\\\//g;
107: }
1.432 foxr 108: return $bodytext.'{}';
1.383 albertel 109: }
110: } elsif ($target eq "edit" ) {
111: my $bodytext =
112: &Apache::lonxml::get_all_text_unbalanced("/tex",$parser);
113: my $result = &Apache::edit::tag_start($target,$token);
114: $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1);
115: return $result;
116: } elsif ( $target eq "modified" ) {
117: return $token->[4].&Apache::edit::modifiedfield("/tex",$parser);
1.159 albertel 118: }
1.198 sakharuk 119: return $result;;
1.10 albertel 120: }
121:
122: sub end_tex {
1.44 ng 123: return '';
1.9 albertel 124: }
125:
1.400 albertel 126: sub homework_js {
127: return &Apache::loncommon::resize_textarea_js().
1.416 raeburn 128: &setmode_javascript().
1.400 albertel 129: <<'JS';
130: <script type="text/javascript">
1.465.2.9 raeburn 131: // <![CDATA[
1.465.2.14! raeburn 132: function setSubmittedPart (part,prefix) {
! 133: if (typeof(prefix) == 'undefined') {
! 134: this.document.lonhomework.submitted.value="part_"+part;
! 135: } else {
! 136: for (var i=0;i<this.document.lonhomework.elements.length;i++) {
! 137: if (this.document.lonhomework.elements[i].name == prefix+'submitted') {
! 138: this.document.lonhomework.elements[i].value="part_"+part;
! 139: }
! 140: }
! 141: }
1.400 albertel 142: }
143:
144: function image_response_click (which, e) {
145: init_geometry();
146: if (!e) { e = window.event; } //IE
147: var input_element = document.lonhomework.elements[which];
1.401 albertel 148: var token_element = document.lonhomework.elements[which+'_token'];
1.400 albertel 149: var token = token_element.value;
1.401 albertel 150: var img_element = document.getElementById(which+'_imageresponse');
1.400 albertel 151: var x= e.clientX-getX(img_element)+Geometry.getHorizontalScroll();
152: var y= e.clientY-getY(img_element)+Geometry.getVerticalScroll();
153: var click = x+':'+y;
154: input_element.value = click;
1.465.2.13 raeburn 155: img_element.src = '/adm/randomlabel.png?token='+token+'&clickdata='+click;
1.400 albertel 156: }
1.465.2.9 raeburn 157: // ]]>
1.400 albertel 158: </script>
159: JS
160: }
161:
1.416 raeburn 162: sub setmode_javascript {
163: return <<"ENDSCRIPT";
164: <script type="text/javascript">
1.465.2.13 raeburn 165: // <![CDATA[
1.416 raeburn 166: function setmode(form,probmode) {
167: form.problemmode.value = probmode;
168: form.submit();
169: }
1.465.2.13 raeburn 170: // ]]>
1.416 raeburn 171: </script>
172: ENDSCRIPT
173: }
174:
1.465.2.6 raeburn 175: sub file_delchk_js {
1.465.2.12 raeburn 176: my $delfilewarn = &mt('You have indicated you wish to remove some files previously included in your submission.').'\\n'.
177: &mt('Continue submission with these files removed?');
1.465.2.6 raeburn 178: return <<"ENDSCRIPT";
179: <script type="text/javascript">
1.465.2.9 raeburn 180: // <![CDATA[
1.465.2.6 raeburn 181: function file_deletion_check(formname) {
182: var elemnum = formname.elements.length;
183: if (elemnum == 0) {
184: return true;
185: }
1.465.2.9 raeburn 186: var str = new RegExp("^HWFILE.+_delete\$");
187: var delboxes = new Array();
1.465.2.6 raeburn 188: for (i=0; i<formname.elements.length; i++) {
189: var id = formname.elements[i].id;
190: if (id != '') {
191: if (str.test(id)) {
192: if (formname.elements[i].type == 'checkbox') {
193: if (formname.elements[i].checked) {
1.465.2.9 raeburn 194: delboxes.push(id);
1.465.2.6 raeburn 195: }
196: }
197: }
198: }
199: }
1.465.2.9 raeburn 200: if (delboxes.length > 0) {
1.465.2.6 raeburn 201: if (confirm("$delfilewarn")) {
202: return true;
203: } else {
1.465.2.9 raeburn 204: for (var j=0; j<delboxes.length; j++) {
205: formname.elements[delboxes[j]].checked = false;
206: }
1.465.2.6 raeburn 207: return false;
208: }
209: } else {
210: return true;
211: }
212: }
1.465.2.9 raeburn 213: // ]]>
1.465.2.6 raeburn 214: </script>
215: ENDSCRIPT
216: }
217:
1.48 albertel 218: sub page_start {
1.345 albertel 219: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
220: $extra_head)=@_;
1.159 albertel 221: my %found;
1.207 albertel 222: foreach my $taginside (@$tagstack) {
1.159 albertel 223: foreach my $taglookedfor ('html','body','form') {
224: if ($taginside =~ /^$taglookedfor$/i) {$found{$taglookedfor} = 1;}
225: }
226: }
227:
1.343 albertel 228: if ($target eq 'tex') {
229: return
230: &Apache::londefdef::start_html($target,$token,$tagstack,
231: $parstack,$parser,$safeeval);
232: }
233:
1.465.2.4 raeburn 234: $extra_head .= &homework_js().
235: &Apache::lonhtmlcommon::dragmath_js("EditMathPopup");
236: if (&Apache::lonhtmlcommon::htmlareabrowser()) {
237: my %textarea_args = (
238: dragmath => 'math',
239: );
240: $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
1.425 raeburn 241: }
1.465.2.6 raeburn 242: my $is_task = ($env{'request.uri'} =~ /\.task$/);
243: if ($is_task) {
244: $extra_head .= &file_delchk_js();
245: }
1.425 raeburn 246:
1.344 albertel 247: my %body_args;
248: if (defined($found{'html'})) {
249: $body_args{'skip_phases'}{'head'}=1;
250: } else {
1.343 albertel 251:
1.345 albertel 252: $extra_head .= &Apache::lonhtmlcommon::spellheader();
1.343 albertel 253:
1.379 albertel 254: $extra_head .= &Apache::londefdef::generate_css_links();
255:
1.384 albertel 256: if ($env{'request.state'} eq 'construct') {
1.343 albertel 257: $extra_head.=&Apache::edit::js_change_detection().
258: "<script type=\"text/javascript\">\n".
259: "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
260: &Apache::loncommon::browser_and_searcher_javascript().
261: "\n</script>\n";
262: }
1.159 albertel 263: }
1.343 albertel 264:
1.446 bisitz 265: my $pageheader = '';
1.344 albertel 266: if (defined($found{'body'})) {
267: $body_args{'skip_phases'}{'body'}=1;
268: } elsif (!defined($found{'body'})
269: && $env{'request.state'} eq 'construct') {
1.343 albertel 270: if ($target eq 'web' || $target eq 'edit') {
1.402 albertel 271: if ($env{'environment.remote'} ne 'off') {
272: $body_args{'only_body'} = 1;
273: }
1.450 bisitz 274: # Breadcrumbs for Construction Space
275: &Apache::lonhtmlcommon::clear_breadcrumbs();
276: &Apache::lonhtmlcommon::add_breadcrumb({
277: 'text' => 'Construction Space',
278: 'href' => &Apache::loncommon::authorspace(),
279: });
1.460 droeschl 280: # breadcrumbs (and tools) will be created
281: # in start_page->bodytag->innerregister
282:
1.450 bisitz 283: # FIXME Where are we?
284: # &Apache::lonhtmlcommon::add_breadcrumb({
285: # 'text' => 'Problem Editing', # 'Problem Testing'
286: # 'href' => '',
287: # });
1.460 droeschl 288: $pageheader =&Apache::loncommon::head_subbox(
1.446 bisitz 289: &Apache::loncommon::CSTR_pageheader());
1.297 albertel 290: }
1.272 albertel 291: } elsif (!defined($found{'body'})) {
1.343 albertel 292: my %add_entries;
1.159 albertel 293: my $background=&Apache::lonxml::get_param('background',$parstack,
294: $safeeval);
1.343 albertel 295: if ($background ne '' ) {
296: $add_entries{'background'} = $background;
297: }
1.344 albertel 298:
1.290 albertel 299: my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,
300: $safeeval);
1.446 bisitz 301: if ($bgcolor eq '' ) { $bgcolor = '#FFFFFF'; }
1.344 albertel 302:
1.446 bisitz 303: $body_args{'bgcolor'} = $bgcolor;
304: # $body_args{'no_title'} = 1;
305: $body_args{'force_register'} = 1;
306: $body_args{'add_entries'} = \%add_entries;
307: if ($env{'environment.remote'} eq 'off'
308: && $env{'request.state'} eq 'construct') {
309: $body_args{'only_body'} = 1;
310: }
1.344 albertel 311: }
1.365 albertel 312: $body_args{'no_auto_mt_title'} = 1;
1.344 albertel 313: my $page_start = &Apache::loncommon::start_page($name,$extra_head,
314: \%body_args);
1.446 bisitz 315: $page_start .= $pageheader;
1.462 raeburn 316: if (!defined($found{'body'})
317: && $env{'request.state'} ne 'construct'
318: && ($target eq 'web' || $target eq 'webgrade')) {
319:
320: my ($symb,undef,undef,undef,$publicuser)= &Apache::lonnet::whichuser();
321: if ($symb eq '' && !$publicuser) {
322: $page_start .= '<p class="LC_info">'
323: .&mt('Browsing resource, all submissions are temporary.')
324: .'</p>';
1.457 bisitz 325: }
1.344 albertel 326: }
327:
1.409 albertel 328: if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') {
1.343 albertel 329: $page_start .= &Apache::lonxml::message_location();
1.159 albertel 330: }
1.344 albertel 331:
1.159 albertel 332: my $form_tag_start;
333: if (!defined($found{'form'})) {
1.337 albertel 334: $form_tag_start='<form name="lonhomework" enctype="multipart/form-data" method="post" action="';
1.465 raeburn 335: my $uri = &Apache::loncommon::inhibit_menu_check(
1.455 droeschl 336: &Apache::lonenc::check_encrypt($env{'request.uri'}));
1.464 raeburn 337: $uri = &HTML::Entities::encode($uri,'<>&"');
1.327 albertel 338: $form_tag_start.=$uri.'" ';
339: if ($target eq 'edit') {
340: $form_tag_start.=&Apache::edit::form_change_detection();
341: }
1.465.2.6 raeburn 342: if ($is_task) {
343: $form_tag_start .= ' onsubmit="return file_deletion_check(this);"';
344: }
1.368 albertel 345: $form_tag_start.='>'."\n";
1.355 albertel 346:
347: my $symb=&Apache::lonnet::symbread();
348: if ($symb =~ /\S/) {
349: $symb=
350: &HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb));
351: $form_tag_start.=
1.368 albertel 352: "\t".'<input type="hidden" name="symb" value="'.$symb.'" />'."\n";
1.355 albertel 353: }
1.159 albertel 354: }
1.343 albertel 355: return ($page_start,$form_tag_start);
1.105 albertel 356: }
357:
1.141 matthew 358: #use Time::HiRes();
1.105 albertel 359: sub get_resource_name {
1.159 albertel 360: my ($parstack,$safeeval)=@_;
1.388 foxr 361: my $name;
1.204 albertel 362: if (defined($Apache::lonhomework::name)) {
1.388 foxr 363: $name = $Apache::lonhomework::name;
364: } else {
365: my ($symb)=&Apache::lonnet::whichuser();
1.392 albertel 366: $name=&Apache::lonnet::gettitle($symb);
1.388 foxr 367: if ($name eq '') {
368: $name=&Apache::lonnet::EXT('resource.title');
369: if ($name eq 'con_lost') { $name = ''; }
370: }
371: if ($name!~/\S+/) {
372: $name=$env{'request.uri'};
373: $name=~s-.*/([^/]+)$-$1-;
374: }
375: # The name has had html tags escaped:
376:
377: $name=~s/</</gs;
378: $name=~s/>/>/gs;
379:
380: $Apache::lonhomework::name=$name;
1.204 albertel 381: }
1.159 albertel 382: return $name;
1.105 albertel 383: }
384:
385: sub setup_rndseed {
1.465.2.7 raeburn 386: my ($safeeval,$target)=@_;
1.367 albertel 387: my ($symb)=&Apache::lonnet::whichuser();
1.465.2.7 raeburn 388: my ($questiontype,$set_safespace,$rndseed);
389: if ($target eq 'analyze') {
390: $questiontype = $env{'form.grade_questiontype'};
391: }
392: unless (defined($questiontype)) {
393: $questiontype = $Apache::lonhomework::type;
394: }
1.333 albertel 395: if ($env{'request.state'} eq "construct"
396: || $symb eq ''
397: || $Apache::lonhomework::type eq 'practice'
398: || $Apache::lonhomework::history{'resource.CODE'}) {
1.316 www 399: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.317 albertel 400: ['rndseed']);
1.284 albertel 401: $rndseed=$env{'form.rndseed'};
1.159 albertel 402: if (!$rndseed) {
1.162 albertel 403: $rndseed=$Apache::lonhomework::history{'rndseed'};
404: if (!$rndseed) {
405: $rndseed=time;
406: }
1.284 albertel 407: $env{'form.rndseed'}=$rndseed;
1.162 albertel 408: }
1.465.2.7 raeburn 409: if (($env{'request.state'} eq "construct") &&
410: ($Apache::lonhomework::type eq 'randomizetry')) {
411: my $tries = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.tries"};
412: if ($tries) {
413: $rndseed += $tries;
414: }
415: $env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed;
416: }
1.374 albertel 417: if ( ($env{'form.resetdata'} eq &mt('New Problem Variation')
418: && $env{'form.submitted'} eq 'yes') ||
1.284 albertel 419: $env{'form.newrandomization'} eq &mt('New Randomization')) {
1.190 albertel 420: srand(time);
421: $rndseed=int(rand(2100000000));
1.284 albertel 422: $env{'form.rndseed'}=$rndseed;
423: delete($env{'form.resetdata'});
424: delete($env{'form.newrandomization'});
1.159 albertel 425: }
1.187 albertel 426: if (defined($rndseed) && $rndseed ne int($rndseed)) {
1.307 albertel 427: $rndseed=join(':',&Apache::lonnet::digest($rndseed));
1.187 albertel 428: }
1.247 albertel 429: if ($Apache::lonhomework::history{'resource.CODE'}) {
430: $rndseed=&Apache::lonnet::rndseed();
431: }
1.465.2.7 raeburn 432: $set_safespace = 1;
433: } elsif ($questiontype eq 'randomizetry') {
434: if ($target eq 'analyze') {
435: if (defined($env{'form.grade_rndseed'})) {
436: $rndseed = $env{'form.grade_rndseed'};
437: }
438: }
439: unless (($target eq 'analyze') && (defined($rndseed))) {
440: $rndseed=&Apache::lonnet::rndseed();
441: my $curr_try = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.tries"};
442: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
443: $curr_try ++;
444: }
445: if ($rndseed =~/^(\d+)[,:](\d+)$/) {
446: $rndseed = $1;
447: }
448: if ($curr_try) {
449: my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
450: if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) {
451: my $inc = int(($curr_try-1)/$reqtries);
452: $rndseed += $inc;
453: } else {
454: $rndseed += $curr_try;
455: }
456: }
457: }
458: $set_safespace = 1;
459: }
460: if ($set_safespace) {
461: if ($safeeval) {
462: &Apache::lonxml::debug("Setting rndseed to $rndseed");
463: &Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval);
464: }
465: }
466: unless (($env{'request.state'} eq "construct") || ($symb eq '')) {
467: $env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed;
1.159 albertel 468: }
469: return $rndseed;
1.105 albertel 470: }
471:
1.268 albertel 472: sub remember_problem_state {
473: return '
1.284 albertel 474: <input type="hidden" name="problemstate" value="'.$env{'form.problemstate'}.'" />
475: <input type="hidden" name="problemtype" value="'.$env{'form.problemtype'}.'" />
476: <input type="hidden" name="problemstatus" value="'.$env{'form.problemstatus'}.'" />';
1.268 albertel 477: }
478:
1.465.2.14! raeburn 479: sub problem_edit_action_button {
! 480: my ($name,$action,$accesskey,$text,$flag)=@_;
! 481: my $actionscript="setmode(this.form,'$action')";
! 482: return "\n<input type='button' name='$name' accesskey='$accesskey' value='".&mt($text)."'".
! 483: ($flag?&Apache::edit::submit_ask_anyway($actionscript):&Apache::edit::submit_dont_ask($actionscript))." />";
! 484: }
! 485:
1.423 www 486: sub problem_edit_buttons {
1.465.2.14! raeburn 487: my ($mode)=@_;
! 488: # Buttons that do not save
! 489: my $result='<div class="LC_edit_problem_discards">'.
! 490: &problem_edit_action_button('subdiscview','discard','d','Discard Edits and View',1);
! 491: if ($mode eq 'editxml') {
! 492: $result.=&problem_edit_action_button('subedit','edit','e','Edit',1);
! 493: $result.=&problem_edit_action_button('subundo','undoxml','u','Undo',1);
! 494: $result.=&Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1);
! 495: } else {
! 496: $result.=&problem_edit_action_button('subeditxml','editxml','x','EditXML',1);
! 497: $result.=&problem_edit_action_button('subundo','undo','u','Undo',1);
! 498: }
! 499: $result.="\n</div>";
! 500: # Buttons that save
! 501: $result.='<div class="LC_edit_problem_saves">';
! 502: if ($mode eq 'editxml') {
! 503: $result.=&problem_edit_action_button('subsaveedit','saveeditxml','s','Save and EditXML');
! 504: $result.=&problem_edit_action_button('subsaveview','saveviewxml','v','Save and View');
! 505: } else {
! 506: $result.=&problem_edit_action_button('subsaveedit','saveedit','s','Save and Edit');
! 507: $result.=&problem_edit_action_button('subsaveview','saveview','v','Save and View');
! 508: }
! 509: $result.="\n</div>\n";
! 510: return $result;
1.423 www 511: }
512:
513: sub problem_edit_header {
1.465.2.14! raeburn 514: return '<input type="hidden" name="submitted" value="edit" />'.
! 515: &remember_problem_state('edit').'
1.423 www 516: <div class="LC_edit_problem_header">
517: <div class="LC_edit_problem_header_title">
518: '.&mt('Problem Editing').&Apache::loncommon::help_open_menu('Problem Editing','Problem_Editor_XML_Index',5,'Authoring').'
519: </div>'.
1.465.2.14! raeburn 520: '<input type="hidden" name="problemmode" value="saveedit" />'.
1.423 www 521: &problem_edit_buttons().'
1.459 bisitz 522: <hr style="clear:both;" />
1.409 albertel 523: '.&Apache::lonxml::message_location().'
1.408 albertel 524: </div>
525: '.
1.458 bisitz 526: '<table border="0" width="100%"><tr><td bgcolor="#F8F8F8">';
1.105 albertel 527: }
528:
529: sub problem_edit_footer {
1.412 albertel 530: return '</td></tr></table><br />
531: <div class="LC_edit_problem_footer">
1.453 bisitz 532: <hr />'.
1.423 www 533: &problem_edit_buttons().'
1.459 bisitz 534: <hr style="clear:both;" />
1.412 albertel 535: </div>
536: '.
1.342 albertel 537: "\n</form>\n".&Apache::loncommon::end_page();
1.105 albertel 538: }
539:
1.235 albertel 540: sub option {
541: my ($value,$name) = @_;
542: my $result ="<option value='".$value."' ";
1.284 albertel 543: if ($env{'form.'.$name} eq $value) {
1.235 albertel 544: $result.=" selected='on' ";
545: }
546: $result.='>';
547: return $result;
548: }
549:
1.105 albertel 550: sub problem_web_to_edit_header {
1.159 albertel 551: my ($rndseed)=@_;
1.406 albertel 552: my $result .= '<div class="LC_edit_problem_header">';
553:
554: if (!$Apache::lonhomework::parsing_a_task) {
555: $result .=
556: '<div class="LC_edit_problem_header_title">'.
557: &mt('Problem Testing').
558: &Apache::loncommon::help_open_topic('Problem_Editor_Testing_Area').
559: '</div>';
560: } else {
561: $result .=
562: '<div class="LC_edit_problem_header_title">'.
563: &mt('Task Testing').
564: '</div>';
565: }
566:
1.315 albertel 567: my $show_all_foils_text =
568: ($Apache::lonhomework::parsing_a_task) ?
1.452 bisitz 569: &mt('Show All Instances')
570: : &mt('Show All Foils');
1.315 albertel 571:
1.452 bisitz 572: my $show_all= '<span class="LC_nobreak"><label for="showallfoils">'
573: .'<input type="checkbox" name="showallfoils"';
1.440 bisitz 574: if (defined($env{'form.showallfoils'})) { $show_all.=' checked="checked"'; }
1.452 bisitz 575: $show_all.= ' /> '.$show_all_foils_text
576: .'</label></span>';
1.406 albertel 577:
578:
1.384 albertel 579:
1.406 albertel 580: $result .= '<div class="LC_edit_problem_header_status_row">';
1.313 albertel 581: if (!$Apache::lonhomework::parsing_a_task) {
582: $result.="
1.406 albertel 583: <div class='LC_edit_problem_header_row1'>
584: <span class=\"LC_nobreak\">
1.405 albertel 585: ".&mt("Problem Status:")."
1.235 albertel 586: <select name='problemstate'>
1.270 albertel 587: <option value=''></option>
1.235 albertel 588: ".&option('CLOSED' ,'problemstate').&mt("Closed")."</option>
589: ".&option('CAN_ANSWER' ,'problemstate').&mt("Answerable")."</option>
590: ".&option('CANNOT_ANSWER_tries' ,'problemstate').&mt("Open with full tries")."</option>
591: ".&option('CANNOT_ANSWER_correct','problemstate').&mt("Open and correct")."</option>
592: ".&option('SHOW_ANSWER' ,'problemstate').&mt("Show Answer")."</option>
593: </select>
1.406 albertel 594: </span>
595: <span class=\"LC_nobreak\">
1.405 albertel 596: ".&mt("Problem Type:")."
1.235 albertel 597: <select name='problemtype'>
1.270 albertel 598: <option value=''></option>
1.242 albertel 599: ".&option('exam' ,'problemtype').&mt("Exam Problem")."</option>
1.428 raeburn 600: ".&option('problem','problemtype').&mt("Homework Problem")."</option>
1.242 albertel 601: ".&option('survey' ,'problemtype').&mt("Survey Question")."</option>
1.465 raeburn 602: ".&option('surveycred' ,'problemtype').&mt("Survey Question (with credit)")."</option>
603: ".&option('anonsurvey' ,'problemtype').&mt("Anonymous Survey Question")."</option>
604: ".&option('anonsurveycred' ,'problemtype').&mt("Anonymous Survey Question (with credit)")."</option>
1.428 raeburn 605: ".&option('practice' ,'problemtype').&mt("Practice Problem")."</option>
1.465.2.7 raeburn 606: ".&option('randomizetry' ,'problemtype').&mt("New Randomization Each Try")."</option>
1.235 albertel 607: </select>
1.406 albertel 608: </span>
609: $show_all
610: </div>
611: <div class='LC_edit_problem_header_row2'>
612: <span class=\"LC_nobreak\">
1.405 albertel 613: ".&mt("Feedback Mode:")."
1.235 albertel 614: <select name='problemstatus'>
615: <option value=''></option>
1.242 albertel 616: ".&option('yes','problemstatus').&mt("Show Feedback")."</option>
1.405 albertel 617: ".&option('no', 'problemstatus').&mt("Don't Show Incorect/Correct Feedback")."</option>
618: ".&option('no_feedback_ever', 'problemstatus').&mt("Don't Show Any Feedback")."</option>
1.235 albertel 619: </select>
1.406 albertel 620: </span>
621: ";
622:
1.376 albertel 623: } elsif ($Apache::lonhomework::parsing_a_task) {
624: $result.="
1.406 albertel 625: <div class='LC_edit_problem_header_row1'>
626: <span class=\"LC_nobreak\">
1.405 albertel 627: ".&mt("Problem Status:")."
1.376 albertel 628: <select name='problemstate'>
629: <option value=''></option>
630: ".&option('CLOSED' ,'problemstate').&mt("Closed")."</option>
631: ".&option('CAN_ANSWER' ,'problemstate').&mt("Answerable")."</option>
632: ".&option('WEB_GRADE' ,'problemstate').&mt("Criteria Grading")."</option>
633: ".&option('SHOW_ANSWER' ,'problemstate').&mt("Show Feedback")."</option>
634: </select>
1.406 albertel 635: </span>
636: $show_all
637: ";
638: }
639: $result.='
640: <span class="LC_nobreak">
641: '.&mt('Apply style file: ').'
642: <input type="text" name="style_file" value="'.&HTML::Entities::encode($env{'construct.style'},'"<>&').'" />
643: <a href="javascript:openbrowser(\'lonhomework\',\'style_file\',\'sty\')">'.&mt('Select').'</a>
644: </span>
1.422 www 645: </div>
646: <div class="LC_edit_problem_header_row1">'.
647: &Apache::lonxml::renderingoptions().'
1.406 albertel 648: </div>
649: <input type="submit" name="changeproblemmode" value="'.&mt("Change View").'" />
650: <input type="submit" name="clear_style_file" accesskey="d" value="'.&mt('Show Default View').'" />
651: <input type="submit" name="resetdata" accesskey="r" value="'.&mt('Reset Submissions').'" />
652: </div>
1.453 bisitz 653: <hr />
1.406 albertel 654: <div class="LC_edit_problem_header_randomize_row">
655: <input type="submit" name="newrandomization" accesskey="a" value="'.&mt('New Randomization').'" />
656: <input type="submit" name="changerandseed" value="'.&mt('Change Random Seed To:').'" />
657: <input type="text" name="rndseed" size="10" value="'.
658: $rndseed.'"
659: onchange="javascript:document.lonhomework.changerandseed.click()" />';
660:
661: if (!$Apache::lonhomework::parsing_a_task) {
662: my $numtoanalyze=$env{'form.numtoanalyze'};
663: if (!$numtoanalyze) { $numtoanalyze=20; }
1.408 albertel 664: $result .= '<span class="LC_nobreak">'.
665: &mt('[_1] for [_2] versions.',
1.416 raeburn 666: '<input type="button" name="submitmode" value="'.&mt('Calculate answers').'" '.
1.419 bisitz 667: 'onclick="javascript:setmode(this.form,'."'calcanswers'".')" />'
668: ,'<input type="text" name="numtoanalyze" value="'.
1.408 albertel 669: $numtoanalyze.'" size="5" />').
670: &Apache::loncommon::help_open_topic("Analyze_Problem",'',undef,undef,300).
671: '</span>';
672:
1.313 albertel 673: }
1.406 albertel 674:
675: $result.='
676: </div>
1.453 bisitz 677: <hr />
1.447 bisitz 678: <div>';
1.416 raeburn 679: $result.='<input type="hidden" name="problemmode" value="view" />';
680: $result .= '<input type="button" name="submitmode" accesskey="e" value="'.&mt('Edit').'" '.
681: 'onclick="javascript:setmode(this.form,'."'edit'".')" />';
682: $result .= '<input type="button" name="submitmode" accesskey="x" value="'.&mt('EditXML').'" '.
683: 'onclick="javascript:setmode(this.form,'."'editxml'".')" />';
1.408 albertel 684: $result.='
685: </div>
1.453 bisitz 686: <hr />
1.409 albertel 687: '.&Apache::lonxml::message_location().'
1.406 albertel 688: </div>';
1.159 albertel 689: return $result;
1.48 albertel 690: }
691:
1.65 albertel 692: sub initialize_storage {
1.357 albertel 693: my ($given_symb) = @_;
1.353 albertel 694: undef(%Apache::lonhomework::results);
695: undef(%Apache::lonhomework::history);
1.357 albertel 696: my ($symb,$courseid,$domain,$name) =
1.367 albertel 697: &Apache::lonnet::whichuser($given_symb);
1.353 albertel 698:
699: # anonymous users (CODEd exams) have no data
700: if ($name eq 'anonymous'
701: && !defined($domain)) {
702: return;
703: }
704:
1.333 albertel 705: if ($env{'request.state'} eq 'construct'
706: || $symb eq ''
707: || $Apache::lonhomework::type eq 'practice') {
708:
709: my $namespace = $symb || $env{'request.uri'};
710: if ($env{'form.resetdata'} eq &mt('Reset Submissions') ||
1.374 albertel 711: ($env{'form.resetdata'} eq &mt('New Problem Variation')
712: && $env{'form.submitted'} eq 'yes') ||
1.333 albertel 713: $env{'form.newrandomization'} eq &mt('New Randomization')) {
714: &Apache::lonnet::tmpreset($namespace,'',$domain,$name);
715: &Apache::lonxml::debug("Attempt reset");
716: }
1.159 albertel 717: %Apache::lonhomework::history=
1.333 albertel 718: &Apache::lonnet::tmprestore($namespace,'',$domain,$name);
1.159 albertel 719: my ($temp)=keys %Apache::lonhomework::history ;
720: &Apache::lonxml::debug("Return message of $temp");
721: } else {
722: %Apache::lonhomework::history=
723: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
724: }
1.353 albertel 725:
1.159 albertel 726: #ignore error conditions
1.67 albertel 727: my ($temp)=keys %Apache::lonhomework::history ;
1.159 albertel 728: if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
1.65 albertel 729: }
730:
1.435 jms 731: =pod
732:
733: =item finalize_storage()
734:
735: Stores away the result has to a student's environment
736: checks form.grade_ for specific values, other wises stores
737: to the running users environment
738: Will increment totals for attempts, students, and corrects
739: if running user has student role.
740:
741: =cut
742:
743:
1.65 albertel 744: sub finalize_storage {
1.357 albertel 745: my ($given_symb) = @_;
1.159 albertel 746: my $result;
1.289 albertel 747: if (%Apache::lonhomework::results) {
1.323 albertel 748: my @remove = grep(/^INTERNAL_/,keys(%Apache::lonhomework::results));
749: delete(@Apache::lonhomework::results{@remove});
1.357 albertel 750: my ($symb,$courseid,$domain,$name) =
1.367 albertel 751: &Apache::lonnet::whichuser($given_symb);
1.333 albertel 752: if ($env{'request.state'} eq 'construct'
753: || $symb eq ''
754: || $Apache::lonhomework::type eq 'practice') {
755: my $namespace = $symb || $env{'request.uri'};
1.284 albertel 756: $Apache::lonhomework::results{'rndseed'}=$env{'form.rndseed'};
1.159 albertel 757: $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,
1.333 albertel 758: $namespace,'',$domain,$name);
1.159 albertel 759: &Apache::lonxml::debug('Construct Store return message:'.$result);
760: } else {
761: $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
762: $symb,$courseid,$domain,$name);
763: &Apache::lonxml::debug('Store return message:'.$result);
1.465.2.3 raeburn 764: &store_aggregates($symb,$courseid);
1.159 albertel 765: }
1.323 albertel 766: } else {
767: &Apache::lonxml::debug('Nothing to store');
1.67 albertel 768: }
1.159 albertel 769: return $result;
1.65 albertel 770: }
771:
1.435 jms 772: =pod
773:
774: item store_aggregates()
775:
776: Sends hash of values to be incremented in nohist_resourcetracker.db
777: for the course. Increments total number of attempts, unique students
778: and corrects for each part for an instance of a problem, as appropriate.
779:
780: =cut
781:
1.285 raeburn 782: sub store_aggregates {
783: my ($symb,$courseid) = @_;
1.465.2.7 raeburn 784: my (%aggregate,%anoncounter,%randtrycounter);
1.286 albertel 785: my @parts;
1.288 albertel 786: my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
787: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
1.286 albertel 788: foreach my $key (keys(%Apache::lonhomework::results)) {
1.287 albertel 789: if ($key =~ /resource\.([^\.]+)\.tries/) {
1.286 albertel 790: push(@parts, $1);
1.285 raeburn 791: }
792: }
1.286 albertel 793: foreach my $part (@parts) {
1.465.2.3 raeburn 794: if ($env{'request.role'} =~/^st/) {
795: if ($Apache::lonhomework::results{'resource.'.$part.'.award'}
796: eq 'APPROX_ANS' ||
797: $Apache::lonhomework::results{'resource.'.$part.'.award'}
798: eq 'EXACT_ANS') {
799: $aggregate{$symb."\0".$part."\0correct"} = 1;
800: }
801: if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) {
802: $aggregate{$symb."\0".$part."\0users"} = 1;
803: } else {
804: my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]);
805: if ($last_reset) {
806: if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) {
807: $aggregate{$symb."\0".$part."\0users"} = 1;
808: }
809: }
810: }
811: $aggregate{$symb."\0".$part."\0attempts"} = 1;
1.285 raeburn 812: }
1.465.2.3 raeburn 813: if (($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurvey') ||
1.465.2.7 raeburn 814: ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurveycred') ||
815: ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'randomizetry')) {
816: if ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'randomizetry') {
817: $randtrycounter{$symb."\0".$part} = 1;
818: } else {
819: $anoncounter{$symb."\0".$part} = 1;
820: }
1.465.2.3 raeburn 821: my $needsrelease = $Apache::lonnet::needsrelease{'parameter:type:'.$Apache::lonhomework::results{'resource.'.$part.'.type'}};
822: if ($needsrelease) {
823: my $curr_required = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
824: if ($curr_required eq '') {
825: &Apache::lonnet::update_released_required($needsrelease);
826: } else {
827: my ($currmajor,$currminor) = split(/\./,$curr_required);
828: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
829: if (($currmajor < $needsmajor) || ($currmajor == $needsmajor && $currminor < $needsminor)) {
830: &Apache::lonnet::update_released_required($needsrelease);
831: }
1.292 raeburn 832: }
833: }
1.285 raeburn 834: }
835: }
1.292 raeburn 836: if (keys (%aggregate) > 0) {
1.289 albertel 837: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.292 raeburn 838: $cdomain,$cname);
839: }
1.465.2.3 raeburn 840: if (keys(%anoncounter) > 0) {
1.465.2.8 raeburn 841: &Apache::lonnet::cput('nohist_anonsurveys',\%anoncounter,
842: $cdomain,$cname);
1.465.2.3 raeburn 843: }
1.465.2.7 raeburn 844: if (keys(%randtrycounter) > 0) {
1.465.2.8 raeburn 845: &Apache::lonnet::cput('nohist_randomizetry',\%randtrycounter,
846: $cdomain,$cname);
1.465.2.7 raeburn 847: }
1.292 raeburn 848: }
1.289 albertel 849:
1.65 albertel 850: sub checkout_msg {
1.211 albertel 851: my %lt=&Apache::lonlocal::texthash(
852: 'resource'=>'The resource needs to be checked out',
853: '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.',
854: 'warning'=>'Checking out resources is subject to course policies, and may exclude future credit even if done erroneously.',
855: 'checkout'=>'Check out Exam for Viewing',
856: 'checkout?'=>'Check out Exam?');
1.352 albertel 857: my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.159 albertel 858: return (<<ENDCHECKOUT);
1.211 albertel 859: <h2>$lt{'resource'}</h2>
860: <p>$lt{'id_expln'}</p>
1.449 bisitz 861: <p class="LC_warning">$lt{'warning'}</p>
1.444 bisitz 862: <form name="checkout" method="post" action="$uri">
1.91 albertel 863: <input type="hidden" name="doescheckout" value="yes" />
1.211 albertel 864: <input type="button" name="checkoutbutton" value="$lt{'checkout'}" onClick="javascript:if (confirm('$lt{'checkout?'}')) { document.checkout.submit(); }" />
1.65 albertel 865: </form>
866: ENDCHECKOUT
867: }
868:
1.252 albertel 869: sub firstaccess_msg {
1.253 albertel 870: my ($time,$symb)=@_;
1.414 albertel 871: my $result;
872: my @interval=&Apache::lonnet::EXT("resource.0.interval");
873: if ($interval[1] eq 'map') {
874: my ($map)=&Apache::lonnet::decode_symb($symb);
875: my $foldertitle=&Apache::lonnet::gettitle($map);
876:
877: &Apache::lonxml::debug("map is $map title is $foldertitle");
1.418 bisitz 878: $result .= "<h2>".&mt('The resources in "[_1]" are open for a limited time.'
879: .' Once you click the "Show Resource" button below you have [_2] to complete all resources "[_1]".'
880: ,$foldertitle,$time)."</h2>";
1.414 albertel 881: } elsif ($interval[1] eq 'course') {
882: my $course = $env{'course.'.$env{'request.course.id'}.'.description'};
1.418 bisitz 883: $result .= "<h2>".&mt('The resources in "[_1]" are open for a limited time.'
884: .' Once you click the "Show Resource" button below you have [_2] to complete all resources "[_1]".'
885: ,$course,$time)."</h2>";
1.414 albertel 886: } else {
887: my $title=&Apache::lonnet::gettitle($symb);
1.418 bisitz 888: $result .= "<h2>".&mt('This resource "[_1]" is open for a limited time.'
889: .' Once you click the "Show Resource" button below you have [_2] to complete this resource "[_1]".'
890: ,$title,$time)."</h2>";
1.414 albertel 891: }
1.352 albertel 892: my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.418 bisitz 893: my $buttontext = &mt('Show Resource');
894: my $timertext = &mt('Start Timer?');
1.414 albertel 895: $result .= (<<ENDCHECKOUT);
1.444 bisitz 896: <form name="markaccess" method="post" action="$uri">
1.252 albertel 897: <input type="hidden" name="markaccess" value="yes" />
1.418 bisitz 898: <input type="button" name="accessbutton" value="$buttontext" onClick="javascript:if (confirm('$timertext')) { document.markaccess.submit(); }" />
1.252 albertel 899: </form>
900: ENDCHECKOUT
1.414 albertel 901: return $result;
1.252 albertel 902: }
903:
1.204 albertel 904: sub init_problem_globals {
905: my ($type)=@_;
906: #initialize globals
1.308 foxr 907: # For problems, we start out in part 0 (outside a <part> tag).
908: # and part 0 is used to describe the main body of the <problem>
909: #
1.204 albertel 910: if ($type eq 'problem') {
911: $Apache::inputtags::part='0';
912: @Apache::inputtags::partlist=('0');
1.405 albertel 913: &Apache::lonhomework::set_show_problem_status(&get_problem_status('0'));
1.266 albertel 914: $Apache::lonhomework::ignore_response_errors=0;
1.308 foxr 915:
1.266 albertel 916: } elsif ($type eq 'library') {
1.204 albertel 917: $Apache::inputtags::part='';
918: @Apache::inputtags::partlist=();
1.405 albertel 919: &Apache::lonhomework::reset_show_problem_status();
1.266 albertel 920: $Apache::lonhomework::ignore_response_errors=1;
1.308 foxr 921:
1.304 albertel 922: } elsif ($type eq 'Task') {
923: $Apache::inputtags::part='0';
924: @Apache::inputtags::partlist=('0');
1.405 albertel 925: &Apache::lonhomework::reset_show_problem_status();
1.304 albertel 926: $Apache::lonhomework::ignore_response_errors=1;
1.204 albertel 927: }
1.465.2.11 raeburn 928: @Apache::functionplotresponse::callscripts=();
1.204 albertel 929: @Apache::inputtags::responselist = ();
930: @Apache::inputtags::importlist = ();
931: @Apache::inputtags::previous=();
932: @Apache::inputtags::previous_version=();
933: $Apache::structuretags::printanswer='No';
934: @Apache::structuretags::whileconds=();
935: @Apache::structuretags::whilebody=();
936: @Apache::structuretags::whileline=();
937: $Apache::lonhomework::scantronmode=0;
938: undef($Apache::lonhomework::name);
1.358 albertel 939: undef($Apache::lonhomework::default_type);
940: undef($Apache::lonhomework::type);
1.204 albertel 941: }
942:
943: sub reset_problem_globals {
944: my ($type)=@_;
945: undef(%Apache::lonhomework::history);
946: undef(%Apache::lonhomework::results);
947: undef($Apache::inputtags::part);
1.208 albertel 948: #don't undef this, lonhomework.pm takes care of this, we use this to
949: #detect if we try to do 2 problems in one file
950: # undef($Apache::lonhomework::parsing_a_problem);
1.204 albertel 951: undef($Apache::lonhomework::name);
1.358 albertel 952: undef($Apache::lonhomework::default_type);
953: undef($Apache::lonhomework::type);
954: undef($Apache::lonhomework::scantronmode);
955: undef($Apache::lonhomework::ignore_response_errors);
1.465.2.11 raeburn 956: undef(@Apache::functionplotresponse::callscripts);
1.405 albertel 957: &Apache::lonhomework::reset_show_problem_status();
1.204 albertel 958: }
959:
1.241 albertel 960: sub set_problem_state {
1.240 albertel 961: my ($part)=@_;
1.284 albertel 962: if ($env{'form.problemstate'} eq 'CANNOT_ANSWER_correct') {
1.240 albertel 963: $Apache::lonhomework::history{"resource.$part.solved"}=
964: 'correct_by_student';
965: }
966: }
967:
1.241 albertel 968: sub get_problem_status {
969: my ($part)=@_;
1.267 albertel 970: my $problem_status;
1.284 albertel 971: if ($env{'request.state'} eq 'construct' &&
972: defined($env{'form.problemstatus'})) {
973: $problem_status=$env{'form.problemstatus'};
1.267 albertel 974: } else {
975: $problem_status=&Apache::lonnet::EXT("resource.$part.problemstatus");
976: &Apache::lonxml::debug("problem status for $part is $problem_status");
1.284 albertel 977: &Apache::lonxml::debug("env probstat is ".$env{'form.problemstatus'});
1.241 albertel 978: }
979: return $problem_status;
980: }
981:
1.9 albertel 982: sub start_problem {
1.326 albertel 983: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.19 albertel 984:
1.311 foxr 985: # We'll use the redirection to fix up printing of duedates.
1.321 albertel 986: if (!$Apache::lonxml::metamode) {
987: &Apache::lonxml::startredirection();
988: }
1.311 foxr 989:
1.308 foxr 990: # Problems don't nest and we don't allow more than one <problem> in
991: # a .problem file.
992: #
1.184 albertel 993: if ( $Apache::inputtags::part ne '' ||
994: $Apache::lonhomework::parsing_a_problem) {
995: &Apache::lonxml::error('Only one <problem> allowed in a .problem file');
1.326 albertel 996: #my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,$style);
1.159 albertel 997: return '';
998: }
1.184 albertel 999:
1000: $Apache::lonhomework::parsing_a_problem=1;
1.204 albertel 1001: &init_problem_globals('problem');
1.166 albertel 1002:
1.284 albertel 1003: if (defined($env{'scantron.maxquest'})) {
1.166 albertel 1004: $Apache::lonhomework::scantronmode=1;
1005: }
1.161 albertel 1006:
1.159 albertel 1007: if ($target ne 'analyze') {
1.415 raeburn 1008: my $type = &Apache::lonnet::EXT('resource.0.type');
1009: $Apache::lonhomework::type=$type;
1.284 albertel 1010: if (($env{'request.state'} eq 'construct') &&
1.410 albertel 1011: $env{'form.problemtype'} =~ /\S/) {
1.284 albertel 1012: $Apache::lonhomework::type=$env{'form.problemtype'};
1.237 albertel 1013: }
1.332 albertel 1014: &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
1.159 albertel 1015: }
1.164 albertel 1016: if ($Apache::lonhomework::type eq '' ) {
1.284 albertel 1017: my $uri=$env{'request.uri'};
1.159 albertel 1018: if ($uri=~/\.(\w+)$/) {
1019: $Apache::lonhomework::type=$1;
1020: &Apache::lonxml::debug("Using type of $1");
1021: } else {
1022: $Apache::lonhomework::type='problem';
1023: &Apache::lonxml::debug("Using default type, problem, :$uri:");
1024: }
1.87 albertel 1025: }
1.301 albertel 1026: $Apache::lonhomework::default_type = $Apache::lonhomework::type;
1.58 www 1027:
1.363 albertel 1028: &initialize_storage();
1.389 albertel 1029: if ($target ne 'analyze'
1030: && $env{'request.state'} eq 'construct') {
1031: &set_problem_state('0');
1032: }
1033:
1.366 albertel 1034: if ($target eq 'web') {
1035: &Apache::lonxml::debug(" grading history ");
1036: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1037: }
1.363 albertel 1038:
1.159 albertel 1039: #added vars to the scripting enviroment
1.213 albertel 1040: my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
1.248 albertel 1041: $expression.='$external::type=\''.$Apache::lonhomework::type.'\';';
1.24 albertel 1042: &Apache::run::run($expression,$safeeval);
1.159 albertel 1043: my $status;
1044: my $accessmsg;
1045:
1.343 albertel 1046: my $name= &get_resource_name($parstack,$safeeval);
1.350 albertel 1047: my ($result,$form_tag_start);
1.354 albertel 1048: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
1049: || $target eq 'edit') {
1.350 albertel 1050: ($result,$form_tag_start) =
1051: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
1052: $name);
1053: }
1054:
1.284 albertel 1055: if ($target eq 'tex' and $env{'request.symb'} =~ m/\.page_/) {$result='';}
1.159 albertel 1056:
1.465.2.7 raeburn 1057: if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval,$target); }
1.159 albertel 1058: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1059: $target eq 'tex') {
1060: #handle exam checkout
1061: if ($Apache::lonhomework::type eq 'exam') {
1062: my $token=
1063: $Apache::lonhomework::history{"resource.0.outtoken"};
1.284 albertel 1064: if (($env{'form.doescheckout'}) && (!$token)) {
1.159 albertel 1065: $token=&Apache::lonxml::maketoken();
1066: $Apache::lonhomework::history{"resource.0.outtoken"}=
1067: $token;
1068: }
1.343 albertel 1069: $result.=&Apache::lonxml::printtokenheader($target,$token);
1.142 albertel 1070: }
1.284 albertel 1071: if ($env{'form.markaccess'}) {
1.414 albertel 1072: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1073: &Apache::lonnet::set_first_access($interval[1]);
1.252 albertel 1074: }
1.465.2.7 raeburn 1075:
1076: ($status,$accessmsg,my $slot_name,my $slot) =
1077: &Apache::lonhomework::check_slot_access('0','problem');
1078: push (@Apache::inputtags::status,$status);
1079:
1.159 albertel 1080: #handle rand seed in construction space
1.465.2.7 raeburn 1081: my $rndseed=&setup_rndseed($safeeval,$target);
1.367 albertel 1082: my ($symb)=&Apache::lonnet::whichuser();
1.465.2.7 raeburn 1083:
1.333 albertel 1084: if ($env{'request.state'} ne "construct" &&
1085: ($symb eq '' || $Apache::lonhomework::type eq 'practice')) {
1.162 albertel 1086: $form_tag_start.='<input type="hidden" name="rndseed" value="'.
1.462 raeburn 1087: $rndseed.'" />'.
1088: '<input type="submit" name="resetdata"
1089: value="'.&mt('New Problem Variation').'" />';
1.334 albertel 1090: if (exists($env{'form.username'})) {
1091: $form_tag_start.=
1.164 albertel 1092: '<input type="hidden" name="username"
1.284 albertel 1093: value="'.$env{'form.username'}.'" />';
1.334 albertel 1094: }
1.462 raeburn 1095: if ($env{'request.role.adv'}) {
1096: $form_tag_start.= ' <label class="LC_nobreak">'
1097: .'<input type="checkbox" name="showallfoils"';
1098: if (defined($env{'form.showallfoils'})) {
1099: $form_tag_start.=' checked="checked"';
1100: }
1101: $form_tag_start.= ' /> '
1102: .&mt('Show All Foils')
1103: .'</label>';
1104: }
1.417 www 1105: if ($Apache::lonhomework::type eq 'practice') {
1.428 raeburn 1106: $form_tag_start.=&practice_problem_header();
1.417 www 1107: }
1.462 raeburn 1108: $form_tag_start.='<hr />';
1.465.2.7 raeburn 1109: } elsif (($env{'request.state'} ne "construct") &&
1110: ($Apache::lonhomework::type eq 'randomizetry') &&
1111: ($status eq 'CAN_ANSWER')) {
1112: my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
1113: my $problemstatus = &get_problem_status($Apache::inputtags::part);
1114: $form_tag_start.=&randomizetry_problem_header($problemstatus,$reqtries);
1115: }
1.324 albertel 1116:
1.159 albertel 1117: my $expression='$external::datestatus="'.$status.'";';
1118: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
1119: &Apache::run::run($expression,$safeeval);
1120: &Apache::lonxml::debug("Got $status");
1.324 albertel 1121:
1.159 albertel 1122: if (( $status eq 'CLOSED' ) ||
1123: ( $status eq 'UNCHECKEDOUT') ||
1.252 albertel 1124: ( $status eq 'NOT_YET_VIEWED') ||
1.159 albertel 1125: ( $status eq 'BANNED') ||
1.216 albertel 1126: ( $status eq 'UNAVAILABLE') ||
1.324 albertel 1127: ( $status eq 'NOT_IN_A_SLOT') ||
1.216 albertel 1128: ( $status eq 'INVALID_ACCESS')) {
1.326 albertel 1129: my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,
1130: $style);
1.159 albertel 1131: if ( $target eq "web" ) {
1.343 albertel 1132: my $msg;
1.159 albertel 1133: if ($status eq 'UNAVAILABLE') {
1.245 albertel 1134: $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
1.441 raeburn 1135: } elsif ($status eq 'NOT_IN_A_SLOT') {
1136: $msg.='<h1>'.&mt('You are not currently signed up to work at this time and/or place.').'</h1>';
1.253 albertel 1137: } elsif ($status ne 'NOT_YET_VIEWED') {
1.245 albertel 1138: $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
1.159 albertel 1139: }
1.216 albertel 1140: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
1.393 www 1141: $msg.=&mt('The problem ').$accessmsg;
1.159 albertel 1142: } elsif ($status eq 'UNCHECKEDOUT') {
1.343 albertel 1143: $msg.=&checkout_msg();
1.252 albertel 1144: } elsif ($status eq 'NOT_YET_VIEWED') {
1.253 albertel 1145: $msg.=&firstaccess_msg($accessmsg,$symb);
1.325 albertel 1146: } elsif ($status eq 'NOT_IN_A_SLOT') {
1.441 raeburn 1147: $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work");
1.159 albertel 1148: }
1149: $result.=$msg.'<br />';
1150: } elsif ($target eq 'tex') {
1.332 albertel 1151: my $startminipage = ($env{'form.problem_split'}=~/yes/i)? ''
1152: : '\begin{minipage}{\textwidth}';
1.443 foxr 1153: $result.='\noindent \vskip 1 mm '.
1.332 albertel 1154: $startminipage.'\vskip 0 mm';
1.159 albertel 1155: if ($status eq 'UNAVAILABLE') {
1.211 albertel 1156: $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
1.159 albertel 1157: } else {
1.211 albertel 1158: $result.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
1.159 albertel 1159: }
1160: }
1.324 albertel 1161: } elsif ($status eq 'NEEDS_CHECKIN') {
1.326 albertel 1162: my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,
1163: $style);
1.324 albertel 1164: if ($target eq 'web') {
1.375 albertel 1165: $result .=
1166: &Apache::bridgetask::proctor_validation_screen($slot);
1.324 albertel 1167: } elsif ($target eq 'grade') {
1168: &Apache::bridgetask::proctor_check_auth($slot_name,$slot,
1169: 'problem');
1170: }
1.159 albertel 1171: } elsif ($target eq 'web') {
1.360 albertel 1172: if ($status eq 'CAN_ANSWER'
1173: && $slot_name ne ''
1174: && $Apache::lonhomework::history{'resource.0.checkedin'} eq '') {
1175: # unproctored slot access, self checkin
1176: &Apache::bridgetask::check_in('problem',undef,undef,
1177: $slot_name);
1178: }
1.368 albertel 1179: $result.="\n $form_tag_start \t".
1.227 albertel 1180: '<input type="hidden" name="submitted" value="yes" />';
1181: # create a page header and exit
1.284 albertel 1182: if ($env{'request.state'} eq "construct") {
1183: $result.= &problem_web_to_edit_header($env{'form.rndseed'});
1.428 raeburn 1184: if ($Apache::lonhomework::type eq 'practice') {
1185: $result.= '<input type="submit" name="resetdata" '.
1186: 'value="'.&mt('New Problem Variation').'" />'.
1187: &practice_problem_header().'<hr />';
1188: }
1.227 albertel 1189: }
1190: # if we are viewing someone else preserve that info
1.284 albertel 1191: if (defined $env{'form.grade_symb'}) {
1.227 albertel 1192: foreach my $field ('symb','courseid','domain','username') {
1193: $result .= '<input type="hidden" name="grade_'.$field.
1.284 albertel 1194: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
1.159 albertel 1195: }
1.465.2.7 raeburn 1196: foreach my $field ('questiontype','rndseed') {
1197: if ($env{"form.grade_$field"} ne '') {
1198: $result .= '<input type="hidden" name="grade_'.$field.
1199: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
1200: }
1201: }
1202:
1.159 albertel 1203: }
1204: } elsif ($target eq 'tex') {
1.319 foxr 1205: $result .= 'INSERTTEXFRONTMATTERHERE';
1206:
1.99 sakharuk 1207: }
1.159 albertel 1208: } elsif ($target eq 'edit') {
1.343 albertel 1209: $result .= $form_tag_start.&problem_edit_header();
1.226 albertel 1210: $Apache::lonxml::warnings_error_header=
1211: &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 1212: my $temp=&Apache::edit::insertlist($target,$token);
1213: $result.=$temp;
1214: } elsif ($target eq 'modified') {
1215: $result=$token->[4];
1216: } else {
1217: # page_start returned a starting result, delete it if we don't need it
1218: $result = '';
1.99 sakharuk 1219: }
1.159 albertel 1220: return $result;
1.9 albertel 1221: }
1222:
1223: sub end_problem {
1.159 albertel 1224: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.321 albertel 1225: my $result;
1.310 foxr 1226:
1.321 albertel 1227: if (!$Apache::lonxml::metamode) {
1228: $result = &Apache::lonxml::endredirection(); #started in &start_problem
1.329 albertel 1229: $Apache::lonxml::post_evaluate=0;
1.321 albertel 1230: }
1.319 foxr 1231:
1232: if ($target eq 'tex') {
1.321 albertel 1233: # Figure out the front matter and replace the
1234: # INSERTTEXFRONTMATTERHERE in result with it. note that we do
1235: # this in end_problem because whether or not we display due
1236: # dates depends on whether due dates have already been
1237: # displayed in the problem parts.
1238:
1.319 foxr 1239: my $frontmatter = '';
1240: my $startminipage = '';
1241: if (not $env{'form.problem_split'}=~/yes/) {
1242: $startminipage = '\begin{minipage}{\textwidth}';
1243: }
1244: my $id = $Apache::inputtags::part;
1245: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
1246: my $packages=&Apache::lonnet::metadata($env{'request.uri'},'packages');
1247: my @packages = split /,/,$packages;
1248: my $allow_print_points = 0;
1249: foreach my $partial_key (@packages) {
1250: if ($partial_key=~m/^part_0$/) {
1251: $allow_print_points=1;
1252: }
1253: }
1254: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
1255: if (defined($maxtries) && $maxtries < 0) { $allow_print_points=0; }
1256: if (lc($env{'course.'.$env{'request.course.id'}.
1257: '.disableexampointprint'}) eq 'yes') {
1258: $allow_print_points=0;
1259: }
1260: my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header');
1.443 foxr 1261: my $begin_doc=' \typeout{STAMPOFPASSEDRESOURCESTART Resource <h2>"'.$name_of_resourse.'"</h2> located in <br /><small><b>'.$env{'request.uri'}.'</b></small><br /> STAMPOFPASSEDRESOURCEEND} \noindent ';
1.319 foxr 1262: my $toc_line='\vskip 1 mm\noindent '.$startminipage.
1263: '\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}';
1264:
1265: # Figure out what the due date is and if we need to print
1266: # it in the problem header. We have been logging the
1267: # last due date written to file.
1268:
1269: my $duetime = &Apache::lonnet::EXT("resource.$id.duedate");
1270: my $duedate = POSIX::strftime("%c",localtime($duetime));
1.448 bisitz 1271: my $duedate_text = &mt('Due date: [_1]'
1272: ,&Apache::lonlocal::locallocaltime($duetime));
1.319 foxr 1273: my $temp_file;
1274: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due";
1275:
1276: # Figure out what the last printed due date is or set it
1277: # to the epoch if no duedates have been printed.
1278:
1279: my $due_file_content = 0; # If the file does not yet exist, time is the epoch.
1280: if (-e $filename) {
1281: $temp_file = Apache::File->new($filename);
1282: my @due_file = <$temp_file>;
1283: $due_file_content = $due_file[$#due_file];
1284: chomp $due_file_content;
1285: }
1286:
1287: # We display the due date iff it is not the same as the last
1288: # duedate in problem header ($due_file_content), and
1289: # none of our parts displayed a duedate.
1290: #
1291: my $parts_with_displayduedate;
1292: if (defined $Apache::outputtags::showonce{'displayduedate'}) {
1293: $parts_with_displayduedate =
1294: scalar(@{$Apache::outputtags::showonce{'displayduedate'}});
1295: } else {
1296: $parts_with_displayduedate = 0;
1297: }
1298: if (($due_file_content != $duetime) && ($parts_with_displayduedate == 0) ) {
1299: $temp_file = Apache::File->new('>'.$filename);
1300: print $temp_file "$duetime\n";
1301: if (not $env{'request.symb'} =~ m/\.page_/) {
1302: if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') {
1303: $frontmatter .= $begin_doc.
1.448 bisitz 1304: '\textit{'.$duedate_text.'} '.$toc_line;
1.319 foxr 1305: } else {
1306: $frontmatter.= $begin_doc.$toc_line;
1.463 foxr 1307: if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) {
1.465.2.14! raeburn 1308: $frontmatter .= '\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}';
1.463 foxr 1309: }
1.319 foxr 1310: }
1311: } else {
1.448 bisitz 1312: $frontmatter .= '\vskip 1mm\textit{'.$duedate_text.'} \\\\\\\\'.$startminipage;
1.319 foxr 1313: }
1314: } else {
1315: if (not $env{'request.symb'} =~ m/\.page_/) {
1316: $frontmatter .= $begin_doc.$toc_line;
1.463 foxr 1317: if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) {
1.465.2.14! raeburn 1318: $frontmatter .= '\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}';
1.463 foxr 1319: }
1.319 foxr 1320: } else {
1.381 albertel 1321: $frontmatter .= '\vskip 1mm \\\\\\\\'.$startminipage;
1.319 foxr 1322: }
1323: }
1324: $result =~ s/INSERTTEXFRONTMATTERHERE/$frontmatter/;
1325: }
1326:
1.159 albertel 1327: my $status=$Apache::inputtags::status['-1'];
1328: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
1329: $target eq 'tex') {
1.249 albertel 1330: if ( $target eq 'grade' && $Apache::inputtags::part eq '0') {
1.159 albertel 1331: # if part is zero, no <part>s existed, so we need to the grading
1.249 albertel 1332: if ($status eq 'CAN_ANSWER' ||$Apache::lonhomework::scantronmode) {
1333: &Apache::inputtags::grade;
1.324 albertel 1334: } elsif ($status eq 'NEEDS_CHECKIN') {
1335: # no need to grade, and don't want to hide data
1.249 albertel 1336: } else {
1337: # move any submission data to .hidden
1338: &Apache::inputtags::hidealldata($Apache::inputtags::part);
1339: }
1.159 albertel 1340: } elsif ( ($target eq 'web' || $target eq 'tex') &&
1341: $Apache::inputtags::part eq '0' &&
1.465.2.14! raeburn 1342: $status ne 'UNCHECKEDOUT' && $status ne 'NOT_YET_VIEWED') {
1.159 albertel 1343: # if part is zero, no <part>s existed, so we need show the current
1344: # grading status
1345: my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
1346: $result.= $gradestatus;
1347: }
1348: if (
1.284 albertel 1349: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.159 albertel 1350: ($target eq 'answer') || ($target eq 'tex')
1351: ) {
1.465.2.14! raeburn 1352: if (($target ne 'tex') &&
! 1353: ($env{'form.answer_output_mode'} ne 'tex')) {
1.254 www 1354: $result.="</form>";
1.159 albertel 1355: }
1356: if ($target eq 'web') {
1.346 albertel 1357: $result.= &Apache::loncommon::end_page({'discussion' => 1});
1.159 albertel 1358: } elsif ($target eq 'tex') {
1.178 sakharuk 1359: my $endminipage = '';
1.284 albertel 1360: if (not $env{'form.problem_split'}=~/yes/) {
1.178 sakharuk 1361: $endminipage = '\end{minipage}';
1362: }
1.284 albertel 1363: if ($env{'form.print_discussions'} eq 'yes') {
1.263 sakharuk 1364: $result.=&Apache::lonxml::xmlend($target,$parser);
1.159 albertel 1365: } else {
1.262 sakharuk 1366: $result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
1.284 albertel 1367: if (not $env{'request.symb'} =~ m/\.page_/) {
1.262 sakharuk 1368: $result .= $endminipage.'\end{document} ';
1369: } else {
1.382 albertel 1370: $result .= $endminipage;
1.262 sakharuk 1371: }
1.159 albertel 1372: }
1373: }
1374: }
1.465.2.11 raeburn 1375: if ($target eq 'web') {
1376: $result.=&Apache::functionplotresponse::init_script();
1377: }
1.159 albertel 1378: if ($target eq 'grade') {
1379: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
1380: &finalize_storage();
1381: }
1.284 albertel 1382: if ($target eq 'answer' && ($env{'request.state'} eq 'construct')
1383: && $env{'form.answer_output_mode'} ne 'tex') {
1.346 albertel 1384: $result.=&Apache::loncommon::end_page({'discussion' => 1});
1.294 albertel 1385: # normally we get it from above, but in CSTR
1.172 albertel 1386: # we always show answer mode too.
1.159 albertel 1387: }
1388: } elsif ($target eq 'meta') {
1389: if ($Apache::inputtags::part eq '0') {
1.179 albertel 1390: @Apache::inputtags::response=();
1.159 albertel 1391: $result=&Apache::response::mandatory_part_meta;
1392: }
1.215 albertel 1393: $result.=&Apache::response::meta_part_order();
1.258 albertel 1394: $result.=&Apache::response::meta_response_order();
1.159 albertel 1395: } elsif ($target eq 'edit') {
1396: &Apache::lonxml::debug("in end_problem with $target, edit");
1.314 albertel 1397: $result .= &problem_edit_footer();
1.320 albertel 1398: } elsif ($target eq 'modified') {
1399: $result .= $token->[2];
1.159 albertel 1400: }
1.155 albertel 1401:
1.284 albertel 1402: if ($env{'request.state'} eq 'construct' && $target eq 'web') {
1.177 albertel 1403: &Apache::inputtags::check_for_duplicate_ids();
1404: }
1.204 albertel 1405:
1406: &reset_problem_globals('problem');
1.159 albertel 1407:
1408: return $result;
1.48 albertel 1409: }
1410:
1.108 albertel 1411:
1.48 albertel 1412: sub start_library {
1.159 albertel 1413: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.343 albertel 1414: my ($result,$form_tag_start);
1.371 albertel 1415: if ($#$tagstack eq 0 && $$tagstack[0] eq 'library') {
1.244 albertel 1416: &init_problem_globals('library');
1417: $Apache::lonhomework::type='problem';
1418: }
1.159 albertel 1419: if ($target eq 'edit') {
1.343 albertel 1420: ($result,$form_tag_start)=
1421: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
1422: 'Edit');
1423: $result.=$form_tag_start.&problem_edit_header();
1.159 albertel 1424: my $temp=&Apache::edit::insertlist($target,$token);
1425: $result.=$temp;
1426: } elsif ($target eq 'modified') {
1427: $result=$token->[4];
1.340 albertel 1428: } elsif (($target eq 'web' || $target eq 'webgrade')
1.371 albertel 1429: && ($#$tagstack eq 0 && $$tagstack[0] eq 'library')
1.340 albertel 1430: && $env{'request.state'} eq "construct" ) {
1.159 albertel 1431: my $name=&get_resource_name($parstack,$safeeval);
1.343 albertel 1432: ($result,$form_tag_start)=
1433: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
1434: $name);
1.465.2.7 raeburn 1435: my $rndseed=&setup_rndseed($safeeval,$target);
1.343 albertel 1436: $result.=" \n $form_tag_start".
1.159 albertel 1437: '<input type="hidden" name="submitted" value="yes" />';
1438: $result.=&problem_web_to_edit_header($rndseed);
1.428 raeburn 1439: if ($Apache::lonhomework::type eq 'practice') {
1440: $result.= '<input type="submit" name="resetdata" '.
1441: 'value="'.&mt('New Problem Variation').'" />'.
1442: &practice_problem_header().'<hr />';
1443: }
1.159 albertel 1444: }
1445: return $result;
1.48 albertel 1446: }
1447:
1448: sub end_library {
1.159 albertel 1449: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1450: my $result='';
1451: if ($target eq 'edit') {
1452: $result=&problem_edit_footer();
1.371 albertel 1453: } elsif ($target eq 'web'
1454: && ($#$tagstack eq 0 && $$tagstack[0] eq 'library')
1455: && $env{'request.state'} eq "construct") {
1.349 albertel 1456: $result.='</form>'.&Apache::loncommon::end_page({'discussion' => 1});
1.159 albertel 1457: }
1.371 albertel 1458: if ( $#$tagstack eq 0 && $$tagstack[0] eq 'library') {
1459: &reset_problem_globals('library');
1460: }
1.159 albertel 1461: return $result;
1.197 www 1462: }
1463:
1464: sub start_definetag {
1.326 albertel 1465: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.197 www 1466:
1467: my $result;
1468:
1469: my $name = $token->[2]->{'name'};
1.326 albertel 1470: my $skip=&Apache::lonxml::get_all_text("/definetag",$parser,$style);
1.396 albertel 1471: if ($target eq 'web') {
1472: if ($name=~/^\//) {
1473: $result=
1474: '<br /><table class="LC_sty_end"><tr><th>'.
1475: &mt('END [_1]'.'<tt>'.$name.'</tt>').'</th></tr>';
1476: } else {
1477: $result=
1478: '<br /><table class="LC_sty_begin"><tr><th>'.
1479: &mt('BEGIN [_1]'.'<tt>'.$name.'</tt>').'</th></tr>';
1480: }
1481: $skip = &HTML::Entities::encode($skip, '<>&"');
1482: $result.='<tr><td><pre>'.$skip.'</pre></td></tr></table>';
1.197 www 1483: }
1484: return $result;
1485: }
1486:
1487: sub end_definetag {
1488: return '';
1.1 albertel 1489: }
1490:
1491: sub start_block {
1.201 albertel 1492: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.131 albertel 1493:
1494: my $result;
1.1 albertel 1495:
1.339 albertel 1496: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1497: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.159 albertel 1498: my $code = $token->[2]->{'condition'};
1.385 albertel 1499: if (defined($code) && $code ne '') {
1.137 albertel 1500: if (!$Apache::lonxml::default_homework_loaded) {
1501: &Apache::lonxml::default_homework_load($safeeval);
1502: }
1.131 albertel 1503: $result = &Apache::run::run($code,$safeeval);
1504: &Apache::lonxml::debug("block :$code: returned :$result:");
1505: } else {
1506: $result='1';
1507: }
1508: if ( ! $result ) {
1.201 albertel 1509: my $skip=&Apache::lonxml::get_all_text("/block",$parser,$style);
1.131 albertel 1510: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
1511: }
1512: $result='';
1513: } elsif ($target eq 'edit') {
1514: $result .=&Apache::edit::tag_start($target,$token);
1515: $result .=&Apache::edit::text_arg('Test Condition:','condition',
1516: $token,40);
1517: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1518: } elsif ($target eq 'modified') {
1519: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1520: $safeeval,'condition');
1521: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.38 albertel 1522: }
1.131 albertel 1523: return $result;
1.1 albertel 1524: }
1525:
1526: sub end_block {
1.167 www 1527: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1528: my $result;
1529: if ($target eq "edit") {
1530: $result.= &Apache::edit::tag_end($target,$token,'');
1531: }
1532: return $result;
1533: }
1534:
1535: sub start_languageblock {
1.201 albertel 1536: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.167 www 1537:
1538: my $result;
1539:
1.339 albertel 1540: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1541: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.201 albertel 1542: my $include = $token->[2]->{'include'};
1543: my $exclude = $token->[2]->{'exclude'};
1.436 raeburn 1544: my @preferred_languages=&Apache::lonlocal::preferred_languages();
1.394 www 1545: # This should not even happen, since we should at least have the server language
1.398 www 1546: if (!$preferred_languages[0]) { $preferred_languages[0]='en'; }
1547: # Now loop over all languages in order of preference
1548: foreach my $preferred_language (@preferred_languages) {
1.394 www 1549: # If the languageblock has no arguments, show the contents
1.399 www 1550: $result=1;
1551: my $found=0;
1.394 www 1552: # Do we have an include argument?
1.398 www 1553: if ($include) {
1.394 www 1554: # If include is specified, by default, don't render the block
1.399 www 1555: $result=0;
1.398 www 1556: foreach my $included_language (split(/\,/,$include)) {
1.394 www 1557: # ... but if my preferred language is included, render it
1.398 www 1558: if ($included_language eq $preferred_language) {
1.399 www 1559: $result=1;
1560: $found=1;
1.398 www 1561: }
1562: }
1563: }
1.394 www 1564: # Do we have an exclude argument?
1.398 www 1565: if ($exclude) {
1.399 www 1566: $result=1;
1.398 www 1567: foreach my $excluded_language (split(/\,/,$exclude)) {
1568: if ($excluded_language eq $preferred_language) {
1.399 www 1569: $result=0;
1570: $found=1;
1.398 www 1571: }
1572: }
1573: }
1.399 www 1574: if ($found) { last; }
1.398 www 1575: }
1.201 albertel 1576: if ( ! $result ) {
1577: my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser,
1578: $style);
1579: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
1580: }
1581: $result='';
1.167 www 1582: } elsif ($target eq 'edit') {
1583: $result .=&Apache::edit::tag_start($target,$token);
1.211 albertel 1584: $result .=&Apache::edit::text_arg(&mt('Include Language:'),'include',
1.167 www 1585: $token,40);
1.211 albertel 1586: $result .=&Apache::edit::text_arg(&mt('Exclude Language:'),'exclude',
1.167 www 1587: $token,40);
1588: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1589: } elsif ($target eq 'modified') {
1590: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.168 albertel 1591: $safeeval,'include',
1592: 'exclude');
1.167 www 1593: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1594: }
1595: return $result;
1596: }
1597:
1598: sub end_languageblock {
1.170 www 1599: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1600: my $result;
1.201 albertel 1601: if ($target eq "edit") {
1.170 www 1602: $result.= &Apache::edit::tag_end($target,$token,'');
1603: }
1604: return $result;
1605: }
1606:
1.397 albertel 1607: {
1608: my %available_texts;
1609: sub start_translated {
1610: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1611: &Apache::lonxml::register('Apache::structuretags',('lang'));
1612: undef(%available_texts);
1613: }
1614:
1615: sub end_translated {
1616: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1617: my $result;
1618: #show the translation on viewable targets
1619: if ($target eq 'web' || $target eq 'tex' || $target eq 'webgrade'||
1620: # or non-viewable targets, if it's embedded in something that
1621: # wants the output
1622: (($target eq 'answer' || $target eq 'analyze'|| $target eq 'grade')
1623: && &Apache::lonxml::in_redirection() ) ) {
1624: my @possibilities = keys(%available_texts);
1625: my $which =
1626: &Apache::loncommon::languages(\@possibilities) || 'default';
1627: $result = $available_texts{$which};
1628: }
1629: undef(%available_texts);
1630: &Apache::lonxml::deregister('Apache::structuretags',('lang'));
1631: return $result;
1632: }
1633:
1634:
1635: sub start_lang {
1636: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1637: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1638: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1639: &Apache::lonxml::startredirection();
1640: }
1641: return '';
1642: }
1643:
1644: sub end_lang {
1645: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1646: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1647: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1648: my $result = &Apache::lonxml::endredirection();
1649: my $which = &Apache::lonxml::get_param('which',$parstack,
1650: $safeeval);
1.431 raeburn 1651: if ($which=~/\w/) {
1652: $available_texts{$which} = $result;
1653: }
1654: my $otherlangs = &Apache::lonxml::get_param('other',$parstack,
1655: $safeeval);
1656: foreach my $language (split(/\s*\,\s*/,$otherlangs)) {
1657: if ($language=~/\w/) {
1658: $available_texts{$language} = $result;
1659: }
1.427 bisitz 1660: }
1661:
1.397 albertel 1662: }
1663: return '';
1664: }
1665: }
1666:
1.170 www 1667: sub start_instructorcomment {
1.201 albertel 1668: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.170 www 1669:
1670: my $result;
1671:
1.339 albertel 1672: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1673: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.465.2.1 raeburn 1674: $result=($env{'request.role'}=~/^(in|cc|co|au|ca|li)/);
1.284 albertel 1675: if ( (! $result) or ($env{'form.instructor_comments'} eq 'hide')) {
1.201 albertel 1676: my $skip=&Apache::lonxml::get_all_text("/instructorcomment",
1677: $parser,$style);
1.170 www 1678: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
1679: }
1680: $result='';
1681: } elsif ($target eq 'edit') {
1682: $result .=&Apache::edit::tag_start($target,$token);
1683: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1684: }
1685: return $result;
1686: }
1687:
1688: sub end_instructorcomment {
1.159 albertel 1689: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 1690: my $result;
1691: if ($target eq "edit") {
1692: $result.= &Apache::edit::tag_end($target,$token,'');
1693: }
1694: return $result;
1.4 tsai 1695: }
1696:
1697: sub start_while {
1.326 albertel 1698: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 1699:
1.160 albertel 1700: my $result;
1.339 albertel 1701: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1702: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.160 albertel 1703: my $code = $token->[2]->{'condition'};
1.4 tsai 1704:
1.160 albertel 1705: push( @Apache::structuretags::whileconds, $code);
1706: if (!$Apache::lonxml::default_homework_loaded) {
1707: &Apache::lonxml::default_homework_load($safeeval);
1708: }
1709: my $result = &Apache::run::run($code,$safeeval);
1.326 albertel 1710: my $bodytext=&Apache::lonxml::get_all_text("/while",$parser,$style);
1.160 albertel 1711: push( @Apache::structuretags::whilebody, $bodytext);
1.161 albertel 1712: push( @Apache::structuretags::whileline, $token->[5]);
1713: &Apache::lonxml::debug("s code $code got -$result-");
1.160 albertel 1714: if ( $result ) {
1715: &Apache::lonxml::newparser($parser,\$bodytext);
1716: }
1717: } elsif ($target eq 'edit') {
1718: $result .=&Apache::edit::tag_start($target,$token);
1.211 albertel 1719: $result .=&Apache::edit::text_arg(&mt('Test Condition:'),'condition',
1.160 albertel 1720: $token,40);
1721: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1722: } elsif ($target eq 'modified') {
1723: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1724: $safeeval,'condition');
1725: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.159 albertel 1726: }
1.160 albertel 1727: return $result;
1.4 tsai 1728: }
1729:
1730: sub end_while {
1.159 albertel 1731: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 1732: my $result;
1733:
1.339 albertel 1734: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1735: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.160 albertel 1736: my $code = pop(@Apache::structuretags::whileconds);
1737: my $bodytext = pop(@Apache::structuretags::whilebody);
1.161 albertel 1738: my $line = pop(@Apache::structuretags::whileline);
1739: my $return = &Apache::run::run($code,$safeeval);
1740: my $starttime=time;
1741: my $error=0;
1742: while ($return) {
1743: if (time-$starttime >
1744: $Apache::lonnet::perlvar{'lonScriptTimeout'}) {
1.378 albertel 1745: $return = 0; $error=1; next;
1.161 albertel 1746: }
1747: $result.=&Apache::scripttag::xmlparse($bodytext);
1.380 albertel 1748: if ($target eq 'grade' || $target eq 'answer' ||
1749: $target eq 'analyze') {
1750: # grade/answer/analyze should produce no output but if we
1751: # are redirecting, the redirecter should know what to do
1752: # with the output
1753: if (!$Apache::lonxml::redirection) { undef($result); }
1754: }
1.161 albertel 1755: $return = &Apache::run::run($code,$safeeval);
1756: }
1757: if ($error) {
1.430 bisitz 1758: &Apache::lonxml::error('<pre>'.&mt('Code ran too long. It ran for more than').' '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' '.&mt('seconds occurred while running <while> on line').' '.$line.'</pre>');
1.160 albertel 1759: }
1760: } elsif ($target eq "edit") {
1761: $result.= &Apache::edit::tag_end($target,$token,'');
1.159 albertel 1762: }
1.160 albertel 1763: return $result;
1.1 albertel 1764: }
1.6 tsai 1765:
1.160 albertel 1766: # <randomlist show="1">
1.6 tsai 1767: # <tag1>..</tag1>
1768: # <tag2>..</tag2>
1769: # <tag3>..</tag3>
1.160 albertel 1770: # ...
1.6 tsai 1771: # </randomlist>
1772: sub start_randomlist {
1.326 albertel 1773: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 1774: my $result;
1.339 albertel 1775: if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' ||
1776: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.331 albertel 1777: my $body= &Apache::lonxml::get_all_text("/randomlist",$parser);
1.305 albertel 1778: my $b_parser= HTML::LCParser->new(\$body);
1779: $b_parser->xml_mode(1);
1780: $b_parser->marked_sections(1);
1.159 albertel 1781: my $b_tok;
1782: my @randomlist;
1783: my $list_item;
1784: while($b_tok = $b_parser->get_token() ) {
1785: if($b_tok->[0] eq 'S') { # start tag
1786: # get content of the tag until matching end tag
1787: # get all text upto the matching tag
1788: # and push the content into @randomlist
1789: $list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],
1790: $b_parser);
1791: $list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
1792: push(@randomlist,$list_item);
1793: # print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4],
1794: # $list_item</b>";
1795: }
1796: if($b_tok->[0] eq 'T') { # text
1797: # what to do with text in between tags?
1798: # print "<b>TEXT $b_tok->[1]</b><br />";
1799: }
1800: # if($b_tok->[0] eq 'E') { # end tag, should not happen
1801: # print "<b>END-TAG $b_tok->[1]</b><br />";
1802: # }
1803: }
1.303 albertel 1804: if (@randomlist) {
1805: my @idx_arr = (0 .. $#randomlist);
1806: &Apache::structuretags::shuffle(\@idx_arr);
1807: my $bodytext = '';
1808: my $show=$#randomlist;
1809: my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
1810: $showarg--;
1811: if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
1.439 raeburn 1812: if (($target eq 'analyze') && ($env{'form.check_parts_withrandomlist'})) {
1813: my @currlist;
1814: my $part = $Apache::inputtags::part;
1815: if ($part ne '') {
1816: if (ref($Apache::lonhomework::analyze{'parts_withrandomlist'}) eq 'ARRAY') {
1817: my @currlist = @{$Apache::lonhomework::analyze{'parts_withrandomlist'}};
1818: if (!(grep(/^\Q$part\E$/,@currlist))) {
1819: push(@{$Apache::lonhomework::analyze{'parts_withrandomlist'}},$part);
1820: }
1821: } else {
1822: push(@{$Apache::lonhomework::analyze{'parts_withrandomlist'}},$part);
1823: }
1824: }
1825: }
1.303 albertel 1826: for(0 .. $show) {
1827: $bodytext .= "$randomlist[ $idx_arr[$_] ]";
1828: }
1829: &Apache::lonxml::newparser($parser,\$bodytext);
1.159 albertel 1830: }
1831: } elsif ($target eq 'edit' ) {
1832: $result .=&Apache::edit::tag_start($target,$token);
1833: $result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
1834: $token,5);
1835: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1836: } elsif ($target eq 'modified' ) {
1837: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1838: $safeeval,'show');
1839: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1840: }
1841: return $result;
1.7 tsai 1842: }
1843:
1844: sub shuffle {
1845: my $a=shift;
1846: my $i;
1.303 albertel 1847: if (ref($a) eq 'ARRAY' && @$a) {
1.251 albertel 1848: &Apache::response::pushrandomnumber();
1.159 albertel 1849: for($i=@$a;--$i;) {
1850: my $j=int(&Math::Random::random_uniform() * ($i+1));
1851: next if $i == $j;
1852: @$a[$i,$j] = @$a[$j,$i];
1853: }
1.251 albertel 1854: &Apache::response::poprandomnumber();
1.7 tsai 1855: }
1.6 tsai 1856: }
1857:
1858: sub end_randomlist {
1.159 albertel 1859: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1860: my $result;
1861: if ($target eq 'edit' ) {
1862: $result=&Apache::edit::tag_end($target,$token,
1863: 'End Randomly Parsed Block');
1864: }
1865: return $result;
1.6 tsai 1866: }
1867:
1.283 albertel 1868: sub ordered_show_check {
1869: my $last_part=$Apache::inputtags::partlist[-2];
1870: my $in_order=
1871: &Apache::lonnet::EXT('resource.'.$Apache::inputtags::part.'.ordered');
1872: my $in_order_show=1;
1873: if ($last_part ne '0' && lc($in_order) eq 'yes') {
1874: $in_order_show=&Apache::response::check_status($last_part);
1875: }
1876: return $in_order_show;
1877: }
1878:
1.465.2.2 raeburn 1879: sub start_startpartmarker {
1880: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1881: my $result='';
1882: if ($target eq 'edit') {
1883: $result=&Apache::edit::tag_start($target,$token);
1884: $result.=&mt('Marker for the start of a part. Place end marker below to wrap in-between tags into a new part.').'</td></tr>';
1885: $result.=&Apache::edit::end_table();
1886:
1887: }
1888: return $result;
1889: }
1890:
1891: sub end_startpartmarker {
1892: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1893: my @result;
1894: if ($target eq 'edit') { $result[1]='no'; }
1895: return @result;
1896: }
1897:
1898: sub start_endpartmarker {
1899: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1900: my $result='';
1901: if ($target eq 'edit') {
1902: $result=&Apache::edit::tag_start($target,$token);
1903: $result.=&mt('Marker for the end of a part. Place start marker above to wrap in-between tags into a new part.').'</td></tr>';
1904: $result.=&Apache::edit::end_table();
1905:
1906: }
1907: return $result;
1908: }
1909:
1910: sub end_endpartmarker {
1911: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1912: my @result;
1913: if ($target eq 'edit') { $result[1]='no'; }
1914: return @result;
1915: }
1916:
1.11 albertel 1917: sub start_part {
1.326 albertel 1918: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.321 albertel 1919: if (!$Apache::lonxml::metamode) {
1920: &Apache::lonxml::startredirection(); # we'll use redirection to fix up
1921: # duedates.
1922: }
1.159 albertel 1923: my $result='';
1.386 albertel 1924: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
1.159 albertel 1925: $Apache::inputtags::part=$id;
1.177 albertel 1926: push(@Apache::inputtags::partlist,$id);
1927: @Apache::inputtags::response=();
1.159 albertel 1928: @Apache::inputtags::previous=();
1929: @Apache::inputtags::previous_version=();
1.405 albertel 1930: &Apache::lonhomework::set_show_problem_status(&get_problem_status($id));
1.403 albertel 1931: &Apache::response::reset_params();
1932:
1.159 albertel 1933: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
1.259 albertel 1934: my $newtype=&Apache::lonnet::EXT("resource.$id.type");
1935: if ($newtype) { $Apache::lonhomework::type=$newtype; }
1.283 albertel 1936: my $in_order_show=&ordered_show_check();
1.214 albertel 1937: my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
1.259 albertel 1938: $expression.='$external::type=\''.$Apache::lonhomework::type.'\';';
1.209 albertel 1939: &Apache::run::run($expression,$safeeval);
1.159 albertel 1940:
1941: if ($target eq 'meta') {
1.224 www 1942: my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
1943: return &Apache::response::mandatory_part_meta.
1944: &Apache::response::meta_parameter_write('display','string',$display,'Part Description');
1.159 albertel 1945: } elsif ($target eq 'web' || $target eq 'grade' ||
1946: $target eq 'answer' || $target eq 'tex') {
1.283 albertel 1947: if ($hidden || !$in_order_show) {
1.326 albertel 1948: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser,$style);
1.159 albertel 1949: } else {
1950: my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
1951: push (@Apache::inputtags::status,$status);
1952: my $expression='$external::datestatus="'.$status.'";';
1953: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
1954: &Apache::run::run($expression,$safeeval);
1.284 albertel 1955: if ($env{'request.state'} eq 'construct') {
1.241 albertel 1956: &set_problem_state($Apache::inputtags::part);
1.240 albertel 1957: }
1.216 albertel 1958: if (( $status eq 'CLOSED' ) ||
1959: ( $status eq 'UNCHECKEDOUT') ||
1.252 albertel 1960: ( $status eq 'NOT_YET_VIEWED') ||
1.216 albertel 1961: ( $status eq 'BANNED') ||
1962: ( $status eq 'UNAVAILABLE') ||
1963: ( $status eq 'INVALID_ACCESS')) {
1.326 albertel 1964: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser,
1965: $style);
1.159 albertel 1966: if ( $target eq "web" ) {
1.211 albertel 1967: $result="<br />".&mt('Part is not open to be viewed. It')." $accessmsg<br />";
1.159 albertel 1968: } elsif ( $target eq 'tex' ) {
1.284 albertel 1969: if (not $env{'form.problem_split'}=~/yes/) {
1.211 albertel 1970: $result="\\end{minipage}\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\\\begin{minipage}{\\textwidth}";
1.195 sakharuk 1971: } else {
1.211 albertel 1972: $result="\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\";
1.195 sakharuk 1973: }
1.159 albertel 1974: }
1975: } else {
1976: if ($target eq 'tex') {
1.284 albertel 1977: if (not $env{'form.problem_split'}=~/yes/) {
1.264 sakharuk 1978: if ($$tagstack[-2] eq 'td') {
1.388 foxr 1979: $result.='\noindent \begin{minipage}{\textwidth}\noindent';
1.264 sakharuk 1980: } else {
1981: $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
1982: }
1.195 sakharuk 1983: }
1.159 albertel 1984: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
1.284 albertel 1985: my $allkeys=&Apache::lonnet::metadata($env{'request.uri'},'packages');
1.222 sakharuk 1986: my @allkeys = split /,/,$allkeys;
1987: my $allow_print_points = 0;
1988: foreach my $partial_key (@allkeys) {
1.230 albertel 1989: if ($partial_key=~m/^part_(.*)$/) {
1.222 sakharuk 1990: if ($1 ne '0') {$allow_print_points=1;}
1991: }
1992: }
1.275 albertel 1993: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
1994: if (defined($maxtries) && $maxtries < 0) {
1995: $allow_print_points=0;
1996: }
1.302 albertel 1997: if (lc($env{'course.'.$env{'request.course.id'}.
1998: '.disableexampointprint'}) eq 'yes') {
1999: $allow_print_points=0;
2000: }
1.463 foxr 2001: if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) {
1.465.2.14! raeburn 2002: $result .= '\vskip 10mm\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}';
1.463 foxr 2003:
2004: }
1.233 www 2005: } elsif ($target eq 'web') {
1.465.2.7 raeburn 2006: if ($status eq 'CAN_ANSWER') {
2007: my $problemstatus = &get_problem_status($Apache::inputtags::part);
2008: my $probrandomize = &Apache::lonnet::EXT("resource.$Apache::inputtags::partlist[0].type");
2009: my $probrandtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::partlist[0].randomizeontries");
2010: my $num = scalar(@Apache::inputtags::partlist)-1;
2011: if ($probrandomize eq 'randomizetry') {
2012: if (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.type") ne 'randomizetry') {
2013: $result .= &randomizetry_part_header($problemstatus,'none',$num);
2014: } else {
2015: my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
2016: if ($probrandtries ne $reqtries) {
2017: $result .= &randomizetry_part_header($problemstatus,$reqtries,$num);
2018: }
2019: }
2020: } elsif (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.type") eq 'randomizetry') {
2021: my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
2022: $result .= &randomizetry_part_header($problemstatus,$reqtries,$num);
2023: }
2024: }
1.465.2.5 raeburn 2025: $result.='<a name="'.&escape($Apache::inputtags::part).'"></a>';
1.159 albertel 2026: }
2027: }
2028: }
2029: } elsif ($target eq 'edit') {
2030: $result.=&Apache::edit::tag_start($target,$token);
2031: $result.=&Apache::edit::text_arg('Part ID:','id',$token).
2032: &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help").
1.224 www 2033: ' '.
2034: &Apache::edit::text_arg('Displayed Part Description:','display',$token).
1.159 albertel 2035: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
2036: } elsif ($target eq 'modified') {
2037: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.225 albertel 2038: $safeeval,'id','display');
1.159 albertel 2039: if ($constructtag) {
1.225 albertel 2040: #limiting ids to only letters numbers, and space
1.224 www 2041: $token->[2]->{'id'}=~s/[^A-Za-z0-9 ]//gs;
1.159 albertel 2042: $result = &Apache::edit::rebuild_tag($token);
2043: }
2044: }
2045: return $result;
1.11 albertel 2046: }
2047:
2048: sub end_part {
1.159 albertel 2049: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2050: &Apache::lonxml::debug("in end_part $target ");
2051: my $status=$Apache::inputtags::status['-1'];
2052: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
1.283 albertel 2053: my $in_order_show=&ordered_show_check();
1.321 albertel 2054: my $result;
2055: if (!$Apache::lonxml::metamode) {
2056: $result = &Apache::lonxml::endredirection(); # started in &start_part
1.329 albertel 2057: $Apache::lonxml::post_evaluate=0;
1.321 albertel 2058: }
1.312 albertel 2059: if ($target eq 'grade') {
1.249 albertel 2060: if (($status eq 'CAN_ANSWER' || $Apache::lonhomework::scantronmode) &&
1.283 albertel 2061: !$hidden && $in_order_show) {
1.311 foxr 2062: $result.=&Apache::inputtags::grade;
1.249 albertel 2063: } else {
2064: # move any submission data to .hidden
2065: &Apache::inputtags::hidealldata($Apache::inputtags::part);
2066: }
1.283 albertel 2067: } elsif (($target eq 'web' || $target eq 'tex') &&
2068: !$hidden && $in_order_show) {
1.159 albertel 2069: my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
2070: $target);
1.212 albertel 2071: if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') {
2072: $gradestatus='';
2073: }
1.311 foxr 2074: $result.=$gradestatus;
1.265 sakharuk 2075: if ($$tagstack[-2] eq 'td' and $target eq 'tex') {$result.='\end{minipage}';}
1.181 albertel 2076: } elsif ($target eq 'edit') {
1.311 foxr 2077: $result.=&Apache::edit::end_table();
1.322 albertel 2078: } elsif ($target eq 'modified') {
2079: $result .= $token->[2];
1.159 albertel 2080: }
2081: pop @Apache::inputtags::status;
2082: $Apache::inputtags::part='';
1.295 albertel 2083: $Apache::lonhomework::type = $Apache::lonhomework::default_type;
1.159 albertel 2084: return $result;
1.11 albertel 2085: }
1.1 albertel 2086:
1.25 albertel 2087: sub start_preduedate {
1.326 albertel 2088: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.339 albertel 2089: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2090: $target eq 'tex' || $target eq 'webgrade') {
1.236 albertel 2091: &Apache::lonxml::debug("State in preduedate is ". $Apache::inputtags::status['-1']);
1.300 albertel 2092: if (!$Apache::lonhomework::scantronmode &&
2093: $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
1.236 albertel 2094: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
2095: &Apache::lonxml::debug("Wha? ". ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER'));
1.326 albertel 2096: &Apache::lonxml::get_all_text("/preduedate",$parser,$style);
1.159 albertel 2097: }
1.24 albertel 2098: }
1.159 albertel 2099: return '';
1.24 albertel 2100: }
2101:
1.25 albertel 2102: sub end_preduedate {
1.159 albertel 2103: return '';
1.24 albertel 2104: }
2105:
1.369 foxr 2106: # In all the modes where <postanswerdate> text is
2107: # displayable, all we do is eat up the text between the start/stop
2108: # tags if the conditions are not right to display it.
1.25 albertel 2109: sub start_postanswerdate {
1.326 albertel 2110: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.370 foxr 2111: my $pav = &Apache::lonnet::allowed('pav', $env{'request.course.id'}) ||
2112: &Apache::lonnet::allowed('pav',
2113: $env{'request.course.id'}.'/'.$env{'request.course.sec'});
1.369 foxr 2114: if ($target eq 'web' || $target eq 'grade' || $target eq 'webgrade' ||
1.370 foxr 2115: $target eq 'tex' ) {
1.300 albertel 2116: if ($Apache::lonhomework::scantronmode ||
1.370 foxr 2117: $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER' ||
2118: (($target eq 'tex') && !$pav)) {
1.326 albertel 2119: &Apache::lonxml::get_all_text("/postanswerdate",$parser,$style);
1.159 albertel 2120: }
2121: }
2122: return '';
1.24 albertel 2123: }
2124:
1.25 albertel 2125: sub end_postanswerdate {
1.159 albertel 2126: return '';
1.24 albertel 2127: }
2128:
1.25 albertel 2129: sub start_notsolved {
1.326 albertel 2130: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 2131: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.339 albertel 2132: $target eq 'tex' || $target eq 'webgrade') {
1.159 albertel 2133: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
2134: &Apache::lonxml::debug("not solved has :$gradestatus:");
1.239 albertel 2135: if ($gradestatus =~ /^correct/ &&
2136: &Apache::response::show_answer()) {
1.159 albertel 2137: &Apache::lonxml::debug("skipping");
1.326 albertel 2138: &Apache::lonxml::get_all_text("/notsolved",$parser,$style);
1.159 albertel 2139: }
1.24 albertel 2140: }
1.159 albertel 2141: return '';
1.24 albertel 2142: }
2143:
1.25 albertel 2144: sub end_notsolved {
1.159 albertel 2145: return '';
1.24 albertel 2146: }
2147:
2148: sub start_solved {
1.326 albertel 2149: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 2150: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2151: $target eq 'tex') {
2152: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
1.239 albertel 2153: if ($gradestatus !~ /^correct/ ||
2154: !&Apache::response::show_answer()) {
1.326 albertel 2155: &Apache::lonxml::get_all_text("/solved",$parser,$style);
1.159 albertel 2156: }
1.24 albertel 2157: }
1.159 albertel 2158: return '';
1.24 albertel 2159: }
2160:
2161: sub end_solved {
1.248 albertel 2162: return '';
2163: }
2164:
2165: sub start_problemtype {
1.326 albertel 2166: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.248 albertel 2167: my $result;
1.339 albertel 2168: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2169: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.248 albertel 2170: my $mode=lc(&Apache::lonxml::get_param('mode',$parstack,$safeeval));
2171: if (!defined($mode)) { $mode='show'; }
2172: my $for=&Apache::lonxml::get_param('for',$parstack,$safeeval);
2173: my $found=0;
2174: foreach my $type (split(',',$for)) {
2175: if ($Apache::lonhomework::type eq lc($type)) { $found=1; }
2176: }
2177: if ($mode eq 'show' && !$found) {
1.326 albertel 2178: &Apache::lonxml::get_all_text("/problemtype",$parser,$style);
1.248 albertel 2179: }
2180: if ($mode eq 'hide' && $found) {
1.326 albertel 2181: &Apache::lonxml::get_all_text("/problemtype",$parser,$style);
1.248 albertel 2182: }
2183: } elsif ($target eq 'edit') {
2184: $result .=&Apache::edit::tag_start($target,$token);
2185: $result.=&Apache::edit::select_arg('Mode:','mode',
2186: [['show','Show'],
2187: ['hide','Hide']]
2188: ,$token);
2189: $result .=&Apache::edit::checked_arg('When used as type(s):','for',
2190: [ ['exam','Exam/Quiz Problem'],
2191: ['survey','Survey'],
1.465 raeburn 2192: ['surveycred','Survey (with credit)'],
2193: ['anonsurvey','Anonymous Survey'],
2194: ['anonsurveycred','Anonymous Survey (with credit)'],
1.428 raeburn 2195: ['problem','Homework Problem'],
1.465.2.7 raeburn 2196: ['practice','Practice Problem'],
2197: ['randomizetry','New Randomization Each Try'] ]
1.248 albertel 2198: ,$token);
2199: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2200: } elsif ($target eq 'modified') {
2201: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
2202: $safeeval,'mode','for');
2203: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
2204: }
2205: return $result;
2206: }
2207:
2208: sub end_problemtype {
1.159 albertel 2209: return '';
1.24 albertel 2210: }
1.34 albertel 2211:
2212: sub start_startouttext {
1.159 albertel 2213: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2214: my @result=(''.'');
2215: if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
1.404 albertel 2216:
2217: my $nesting =
2218: &Apache::lonxml::set_state('outtext',
2219: &Apache::lonxml::get_state('outtext')+1);
2220: if ($nesting > 1 && $env{'request.state'} eq 'construct') {
2221: &Apache::lonxml::error("Nesting of <startouttext /> not allowed, on line ".$token->[5]);
2222: }
1.159 albertel 2223: return (@result);
1.34 albertel 2224: }
1.159 albertel 2225:
1.34 albertel 2226: sub end_startouttext {
1.326 albertel 2227: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 2228: my $result='';
2229: my $text='';
2230: if ($target eq 'edit') {
1.424 foxr 2231: my $areaid = 'homework_edit_'.$Apache::lonxml::curdepth;
1.326 albertel 2232: $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style);
1.437 raeburn 2233: $result.=&Apache::edit::start_table($token)."<tr><td>".&mt('Text Block')."</td>"
1.438 bisitz 2234: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
1.437 raeburn 2235: .&Apache::edit::deletelist($target,$token)
1.465.2.4 raeburn 2236: .'</span></td>'
2237: .'<td align="left"><span id="math_'.$areaid.'" />'
2238: .&Apache::lonhtmlcommon::dragmath_button($areaid,1)
2239: .'</td>'
2240: .'<td>'
2241: .&Apache::edit::insertlist($target,$token)
2242: .'</td>'
2243: .'<td align="right" valign="top">' .
2244: &Apache::loncommon::helpLatexCheatsheet().
1.159 albertel 2245: &Apache::edit::end_row().
1.362 albertel 2246: &Apache::edit::start_spanning_row()."\n".
1.255 www 2247: &Apache::edit::editfield($token->[1],$text,"",80,8,1);
1.159 albertel 2248: }
2249: if ($target eq 'modified') {
1.219 albertel 2250: $result='<startouttext />'.&Apache::edit::modifiedfield("endouttext",$parser);
1.159 albertel 2251: }
2252: if ($target eq 'tex') {
2253: $result .= '\noindent ';
2254: }
2255: return $result;
1.34 albertel 2256: }
1.159 albertel 2257:
1.34 albertel 2258: sub start_endouttext {
1.159 albertel 2259: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2260: my $result='';
2261: if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
2262: if ($target eq "modified") {
2263: $result='<endouttext />'.
1.377 albertel 2264: &Apache::edit::handle_insertafter('startouttext');
2265: }
1.404 albertel 2266:
2267: my $nesting =
2268: &Apache::lonxml::set_state('outtext',
2269: &Apache::lonxml::get_state('outtext')-1);
2270: if ($nesting < 0 && $env{'request.state'} eq 'construct') {
2271: &Apache::lonxml::error(" Extraneous <endouttext /> not allowed on line ".$token->[5]);
2272: &Apache::lonxml::set_state('outtext', 0);
2273: }
1.159 albertel 2274: return $result;
1.34 albertel 2275: }
1.159 albertel 2276:
1.34 albertel 2277: sub end_endouttext {
1.159 albertel 2278: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2279: my @result=('','');
2280: if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
2281: return (@result);
1.34 albertel 2282: }
1.159 albertel 2283:
1.45 albertel 2284: sub delete_startouttext {
1.326 albertel 2285: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2286: # my $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style);
1.159 albertel 2287: my $text=$$parser['-1']->get_text("/endouttext");
2288: my $ntoken=$$parser['-1']->get_token();
2289: &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
2290: &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
2291: # Deleting 2 parallel tag pairs, but we need the numbers later to look like
2292: # they did the last time round
2293: &Apache::lonxml::increasedepth($ntoken);
2294: &Apache::lonxml::decreasedepth($ntoken);
2295: return 1;
1.193 www 2296: }
2297:
2298: sub start_simpleeditbutton {
2299: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2300: my $result='';
1.284 albertel 2301: if (($env{'form.simple_edit_button'} ne 'off') &&
1.273 albertel 2302: ($target eq 'web') &&
1.330 albertel 2303: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
1.284 albertel 2304: my $url=$env{'request.noversionuri'};
1.193 www 2305: $url=~s/\?.*$//;
1.367 albertel 2306: my ($symb) = &Apache::lonnet::whichuser();
1.451 bisitz 2307: # Warning makes more sense and is more important on edit screen
1.442 bisitz 2308: # $result='<p class="LC_warning">'
2309: # .&mt('Note: it can take up to 10 minutes for changes to take effect for all users.')
2310: # .&Apache::loncommon::help_open_topic('Caching')
2311: # .'</p>';
1.465.2.14! raeburn 2312: $result.=&Apache::loncommon::head_subbox(
! 2313: &Apache::lonhtmlcommon::start_funclist()
1.451 bisitz 2314: .&Apache::lonhtmlcommon::add_item_funclist(
2315: '<a href="'.$url.'/smpedit?symb='.&escape($symb).'">'
2316: .&mt('Edit').'</a>')
1.465.2.14! raeburn 2317: .&Apache::lonhtmlcommon::end_funclist());
1.442 bisitz 2318:
1.193 www 2319: }
2320: return $result;
2321: }
2322:
2323: sub end_simpleeditbutton {
2324: return '';
1.45 albertel 2325: }
1.34 albertel 2326:
1.428 raeburn 2327: sub practice_problem_header {
2328: return '<span class="LC_info"><h3>'.&mt('Practice Problem').'</h3></span>'.
2329: '<span class="LC_info">'.&mt('Submissions are not permanently recorded').
2330: '</span>';
2331: }
2332:
1.465.2.7 raeburn 2333: sub randomizetry_problem_header {
2334: my ($problemstatus,$reqtries) = @_;
2335: my ($header,$text);
2336: if ($reqtries > 1) {
2337: $header = &mt('New Problem Variation After Every [quant,_1,Try,Tries]',$reqtries);
2338: if (($problemstatus eq 'no') ||
2339: ($problemstatus eq 'no_feedback_ever')) {
2340: $text = &mt('A new variation will be generated after every [quant,_1,try,tries], until the tries limit is reached.',$reqtries);
2341: } else {
2342: $text = &mt('A new variation will be generated after every [quant,_1,try,tries], until correct or tries limit is reached.',$reqtries);
2343: }
2344: } else {
2345: $header = &mt('New Problem Variation Each Try');
2346: if (($problemstatus eq 'no') ||
2347: ($problemstatus eq 'no_feedback_ever')) {
2348: $text = &mt('A new variation will be generated after each try until the tries limit is reached.');
2349:
2350: } else {
2351: $text = &mt('A new variation will be generated after each try until correct or tries limit is reached.');
2352: }
2353: }
2354: return '<span class="LC_info"><h3>'.$header.'</h3></span>'.
2355: '<span class="LC_info">'.$text.'</span><hr />';
2356: }
2357:
2358: sub randomizetry_part_header {
2359: my ($problemstatus,$reqtries,$num) = @_;
2360: my ($header,$text);
2361: if ($reqtries eq 'none') {
2362: $header = &mt('No Question Variation');
2363: $text = &mt('For this question there will no new variation after a try.');
2364: } elsif ($reqtries > 1) {
2365: $header = &mt('New Question Variation After Every [quant,_1,Try,Tries]',$reqtries);
2366: if (($problemstatus eq 'no') ||
2367: ($problemstatus eq 'no_feedback_ever')) {
2368: $text = &mt('For this question a new variation will be generated after every [quant,_1,try,tries], until the tries limit is reached.',$reqtries);
2369: } else {
2370: $text = &mt('For this question a new variation will be generated after every [quant,_1,try,tries], until correct or tries limit is reached.',$reqtries);
2371: }
2372: } else {
2373: $header = &mt('New Question Variation For Each Try');
2374: if (($problemstatus eq 'no') ||
2375: ($problemstatus eq 'no_feedback_ever')) {
2376: $text = &mt('For this question a new variation will be generated after each try until the tries limit is reached.');
2377: } else {
2378: $text = &mt('For this question a new variation will be generated after each try until correct or tries limit is reached.');
2379: }
2380: }
2381: my $output;
2382: if ($num > 1) {
2383: $output .= '<hr />';
2384: }
2385: $output .= '<span class="LC_info"><h4>'.$header.'</h4></span>'.
2386: '<span class="LC_info">'.$text.'</span><br /><br />';
2387: return $output;
2388: }
2389:
1.1 albertel 2390: 1;
2391: __END__
1.435 jms 2392:
2393: =pod
2394:
2395: =back
2396:
2397: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>