Annotation of loncom/homework/structuretags.pm, revision 1.571
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.571 ! raeburn 4: # $Id: structuretags.pm,v 1.570 2019/11/07 02:58:37 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.500 foxr 64: use Apache::loncommon();
1.267 albertel 65: use Time::HiRes qw( gettimeofday tv_interval );
1.571 ! raeburn 66: use HTML::Entities();
1.356 www 67: use lib '/home/httpd/lib/perl/';
68: use LONCAPA;
69:
1.78 harris41 70: BEGIN {
1.553 damieng 71: &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','print','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startpartmarker','startouttext','endpartmarker','endouttext','simpleeditbutton','definetag'));
1.10 albertel 72: }
73:
1.500 foxr 74:
75: #---------------------------------------------------------------------------------
76: #
77: # This section of code deals with hyphenation management.
78: # We must do three things:
79: # - keep track fo the desired languages to alter the header.
80: # - provide hyphenation selection as needed by each language that appears in the
81: # text.
82: # - Provide the header text needed to make available the desired hyphenations.
83: #
84: #
85:
86: # Hash whose keys are the languages encountered in the document/resource.
87: #
88:
89: my %languages_required;
90: ##
91: # Given a language selection as input returns a chunk of LaTeX that
92: # selects the required hyphenator.
93: #
94: # @param language - the language being selected.
95: # @return string
96: # @retval The LaTeX needed to select the hyphenation appropriate to the language.
97: #
98: sub select_hyphenation {
99: my $language = shift;
100:
101: $language = &Apache::loncommon::latexlanguage($language); # Translate -> latex language.
102:
103: # If there is no latex language there's not much we can do:
104:
105: if ($language) {
106: &require_language($language);
107: my $babel_hyphenation = "\\selectlanguage{$language}";
108:
109: return $babel_hyphenation;
110: } else {
111: return '';
112: }
113: }
114: ##
115: # Selects hyphenation based on the current problem metadata.
116: # This requires that
117: # - There is a language metadata item set for the problem.
118: # - The language has a latex/babel hyphenation.
119: #
120: # @note: Uses &Apache::lonxml::request to locate the Uri associated with
121: # this problem.
122: # @return string (possibly empty).
123: # @retval If not empty an appropriate \selectlanguage{} directive.
124: #
125: sub select_metadata_hyphenation {
126: my $uri = $Apache::lonxml::request->uri;
127: my $language = &Apache::lonnet::metadata($uri, 'language');
128: my $latex_language = &Apache::loncommon::latexhyphenation($language);
129: if ($latex_language) {
130: return '\selectlanguage{'.$latex_language."}\n";
131: }
132: return ''; # no latex hyphenation or no lang metadata.
133: }
134:
135:
136: ##
137: # Clears the set of languages required by the document being rendered.
138: #
139: sub clear_required_languages {
140: %languages_required = ();
141: }
142: ##
143: # Allows an external client of this module to register a need for a language:
144: #
145: # @param LaTeX language required:
146: #
147: sub require_language {
148: my $language = shift;
149: $languages_required{$language} = 1;
150: }
151:
152: ##
153: # Provides the header for babel that indicates the languages
154: # the document requires.
155: # @return string
156: # @retval \usepackage[lang1,lang2...]{babel}
157: # @retval '' if there are no languages_required.
158: sub languages_header {
159: my $header ='';
160: my @languages = (keys(%languages_required));
161:
162: # Only generate the header if there are languages:
163:
164: if (scalar @languages) {
165: my $language_list = join(',', (@languages));
166: $header = '\usepackage['.$language_list."]{babel}\n";
167: }
168: return $header;
169: }
170:
171: #----------------------------------------------------------------------------------
172:
1.10 albertel 173: sub start_web {
1.326 albertel 174: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.383 albertel 175: if ($target ne 'edit' && $target ne 'modified') {
176: my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style);
177: if ($target eq 'web' || $target eq 'webgrade') {
178: return $bodytext;
179: }
180: } elsif ($target eq "edit" ) {
181: my $bodytext =
182: &Apache::lonxml::get_all_text_unbalanced("/web",$parser);
183: my $result = &Apache::edit::tag_start($target,$token);
184: $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1);
185: return $result;
186: } elsif ( $target eq "modified" ) {
187: return $token->[4].&Apache::edit::modifiedfield("/web",$parser);
1.159 albertel 188: }
189: return '';
1.10 albertel 190: }
191:
192: sub end_web {
1.44 ng 193: return '';
1.10 albertel 194: }
195:
1.553 damieng 196: sub start_print {
197: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
198: if ($target ne 'edit' && $target ne 'modified') {
199: if ($target ne 'tex') {
200: my $skip = &Apache::lonxml::get_all_text("/print",$parser,$style);
201: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
202: }
203: } elsif ($target eq "edit") {
204: my $bodytext = &Apache::lonxml::get_all_text_unbalanced("/print",$parser);
205: my $result = &Apache::edit::tag_start($target,$token);
206: $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1);
207: return $result;
208: } elsif ($target eq "modified") {
209: return $token->[4].&Apache::edit::modifiedfield("/print",$parser);
210: }
211: return '';
212: }
213:
214: sub end_print {
215: return '';
216: }
217:
1.10 albertel 218: sub start_tex {
1.326 albertel 219: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.198 sakharuk 220: my $result='';
1.383 albertel 221: if ($target ne 'edit' && $target ne 'modified') {
222: my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style);
223: if ($target eq 'tex') {
1.434 foxr 224:
225: # If inside a table, occurrences of \\ must be removed;
226: # else the table blows up.
227:
228: if (&Apache::londefdef::is_inside_of($tagstack, "table")) {
229: $bodytext =~ s/\\\\//g;
230: }
1.432 foxr 231: return $bodytext.'{}';
1.383 albertel 232: }
233: } elsif ($target eq "edit" ) {
234: my $bodytext =
235: &Apache::lonxml::get_all_text_unbalanced("/tex",$parser);
236: my $result = &Apache::edit::tag_start($target,$token);
237: $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1);
238: return $result;
239: } elsif ( $target eq "modified" ) {
240: return $token->[4].&Apache::edit::modifiedfield("/tex",$parser);
1.159 albertel 241: }
1.198 sakharuk 242: return $result;;
1.10 albertel 243: }
244:
245: sub end_tex {
1.44 ng 246: return '';
1.9 albertel 247: }
248:
1.400 albertel 249: sub homework_js {
1.531 raeburn 250: my ($postsubmit,$timeout);
251: if (($env{'request.course.id'}) && ($env{'request.state'} ne 'construct')) {
1.546 raeburn 252: my $crstype = &Apache::loncommon::course_type();
253: if ($crstype eq 'Community') {
1.531 raeburn 254: $crstype = 'community';
1.546 raeburn 255: } elsif ($crstype eq 'Placement') {
256: $crstype = 'placement';
1.531 raeburn 257: } else {
258: if ($env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}) {
259: $crstype = 'official';
260: } elsif ($env{'course.'.$env{'request.course.id'}.'.internal.textbook'}) {
261: $crstype = 'textbook';
262: } else {
263: $crstype = 'unofficial';
264: }
265: }
266: $postsubmit = $env{'course.'.$env{'request.course.id'}.'.internal.postsubmit'};
267: if ($postsubmit eq '') {
268: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
269: $postsubmit = $domdefs{'postsubmit'};
270: unless ($postsubmit eq 'off') {
271: $timeout = $domdefs{$crstype.'postsubtimeout'};
272: }
273: } elsif ($postsubmit eq '0') {
274: $postsubmit = 'off';
275: } elsif ($postsubmit eq '1') {
276: $postsubmit = 'on';
277: $timeout = $env{'course.'.$env{'request.course.id'}.'.internal.postsubtimeout'};
278: if ($timeout eq '') {
279: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
280: $timeout = $domdefs{$crstype.'postsubtimeout'};
281: }
282: }
283: if ($timeout eq '') {
284: $timeout = 60;
285: }
286: } else {
287: my %domdefs = &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
288: $postsubmit = $domdefs{'postsubmit'};
289: unless ($postsubmit eq 'off') {
290: $timeout = 60;
291: }
292: }
293: my $jstimeout = 0;
294: if ($timeout) {
295: $jstimeout = 1000 * $timeout;
296: }
1.400 albertel 297: return &Apache::loncommon::resize_textarea_js().
1.527 golterma 298: &Apache::loncommon::colorfuleditor_js().
1.416 raeburn 299: &setmode_javascript().
1.531 raeburn 300: <<"JS";
1.400 albertel 301: <script type="text/javascript">
1.483 raeburn 302: // <![CDATA[
1.494 raeburn 303: function setSubmittedPart (part,prefix) {
304: if (typeof(prefix) == 'undefined') {
305: this.document.lonhomework.submitted.value="part_"+part;
306: } else {
307: for (var i=0;i<this.document.lonhomework.elements.length;i++) {
308: if (this.document.lonhomework.elements[i].name == prefix+'submitted') {
309: this.document.lonhomework.elements[i].value="part_"+part;
310: }
311: }
312: }
1.400 albertel 313: }
314:
1.532 raeburn 315: function disableAutoComplete (id) {
316: var field = document.getElementById(id);
317: if (field != null && field != undefined){
318: if ('autocomplete' in field) {
319: field.autocomplete = "off";
320: } else {
321: field.setAttribute("autocomplete", "off");
322: }
323: }
324: }
325:
1.400 albertel 326: function image_response_click (which, e) {
327: init_geometry();
328: if (!e) { e = window.event; } //IE
329: var input_element = document.lonhomework.elements[which];
1.401 albertel 330: var token_element = document.lonhomework.elements[which+'_token'];
1.400 albertel 331: var token = token_element.value;
1.401 albertel 332: var img_element = document.getElementById(which+'_imageresponse');
1.400 albertel 333: var x= e.clientX-getX(img_element)+Geometry.getHorizontalScroll();
334: var y= e.clientY-getY(img_element)+Geometry.getVerticalScroll();
335: var click = x+':'+y;
336: input_element.value = click;
1.485 raeburn 337: img_element.src = '/adm/randomlabel.png?token='+token+'&clickdata='+click;
1.400 albertel 338: }
1.520 raeburn 339:
340: var submithandled = 0;
1.521 raeburn 341: var keypresshandled = 0;
1.531 raeburn 342: var postsubmit = '$postsubmit';
1.520 raeburn 343:
1.531 raeburn 344: \$(document).ready(function(){
345: if (postsubmit != 'off') {
346: \$(document).keypress(function(event){
1.521 raeburn 347: var keycode = (event.keyCode ? event.keyCode : event.which);
348: if ((keycode == '13') && (keypresshandled == 0)) {
1.531 raeburn 349: if ( \$( document.activeElement ).hasClass("LC_textline") ) {
1.521 raeburn 350: keypresshandled = 1;
1.531 raeburn 351: var idsArray = \$( document.activeElement ).attr("id").split(/HWVAL_/);
1.521 raeburn 352: if (idsArray.length) {
353: event.preventDefault();
354: var itemsArray = idsArray[1].split(/_/);
355: var buttonId = idsArray[0]+'submit_'+itemsArray[0];
1.531 raeburn 356: \$("#"+buttonId).trigger("click");
1.521 raeburn 357: }
358: }
359: }
360: });
361:
1.531 raeburn 362: \$(document).delegate('form :submit', 'click', function( event ) {
363: if ( \$( this ).hasClass( "LC_hwk_submit" ) ) {
1.520 raeburn 364: var buttonId = this.id;
1.531 raeburn 365: var timeout = $jstimeout;
1.520 raeburn 366: if (submithandled == 0) {
367: submithandled = 1;
1.531 raeburn 368: \$( "#msg_"+buttonId ).css({"display": "inline","background-color": "#87cefa",
1.521 raeburn 369: "color": "black","padding": "2px"}) ;
1.563 raeburn 370: if (( \$(this.form).attr("id") == "LC_page" ) && (\$('input[name="all_submit"]').length )) {
1.522 raeburn 371: if (buttonId != "all_submit") {
1.531 raeburn 372: \$( ".LC_status_"+buttonId ).hide();
1.563 raeburn 373: }
374: if (( "#"+buttonId+"_pressed" ).length) {
375: \$( "#"+buttonId+"_pressed" ).val( "1" );
1.520 raeburn 376: }
1.522 raeburn 377: } else {
1.531 raeburn 378: \$( ".LC_status_"+buttonId ).hide();
1.520 raeburn 379: }
1.531 raeburn 380: \$(this.form).submit();
381: \$( ".LC_hwk_submit" ).prop( "disabled", true);
382: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.520 raeburn 383: event.preventDefault();
1.531 raeburn 384:
385: if (timeout > 0) {
386: setTimeout(function(){
387: \$( "#msg_"+buttonId ).css({"display": "none"});
1.563 raeburn 388: if (( \$(this.form).attr("id") == "LC_page" ) && (\$('input[name="all_submit"]').length )) {
389: if (( "#"+buttonId+"_pressed" ).length) {
390: \$( "#"+buttonId+"_pressed" ).val( "" );
1.531 raeburn 391: }
392: }
393: \$( ".LC_hwk_submit" ).prop( "disabled", false);
394: \$( ".LC_textline" ).prop( "readonly", false);
395: submithandled = 0;
396: keypresshandled = 0;
397: }, timeout);
398: }
1.520 raeburn 399: return true;
400: }
401: }
402: });
1.531 raeburn 403: }
1.520 raeburn 404: });
405:
1.483 raeburn 406: // ]]>
1.400 albertel 407: </script>
408: JS
409: }
410:
1.416 raeburn 411: sub setmode_javascript {
412: return <<"ENDSCRIPT";
413: <script type="text/javascript">
1.485 raeburn 414: // <![CDATA[
1.416 raeburn 415: function setmode(form,probmode) {
1.554 damieng 416: var initial = form.problemmode.value;
1.416 raeburn 417: form.problemmode.value = probmode;
418: form.submit();
1.554 damieng 419: form.problemmode.value = initial;
1.416 raeburn 420: }
1.485 raeburn 421: // ]]>
1.416 raeburn 422: </script>
423: ENDSCRIPT
424: }
425:
1.48 albertel 426: sub page_start {
1.345 albertel 427: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
428: $extra_head)=@_;
1.159 albertel 429: my %found;
1.207 albertel 430: foreach my $taginside (@$tagstack) {
1.159 albertel 431: foreach my $taglookedfor ('html','body','form') {
432: if ($taginside =~ /^$taglookedfor$/i) {$found{$taglookedfor} = 1;}
433: }
434: }
435:
1.343 albertel 436: if ($target eq 'tex') {
437: return
438: &Apache::londefdef::start_html($target,$token,$tagstack,
439: $parstack,$parser,$safeeval);
440: }
441:
1.474 raeburn 442: $extra_head .= &homework_js().
443: &Apache::lonhtmlcommon::dragmath_js("EditMathPopup");
444: if (&Apache::lonhtmlcommon::htmlareabrowser()) {
1.550 raeburn 445: my %textarea_args;
446: if (($env{'request.state'} ne 'construct') ||
447: ($env{'environment.nocodemirror'})) {
448: %textarea_args = (
1.474 raeburn 449: dragmath => 'math',
450: );
1.550 raeburn 451: }
1.474 raeburn 452: $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
1.425 raeburn 453: }
1.478 raeburn 454: my $is_task = ($env{'request.uri'} =~ /\.task$/);
1.528 raeburn 455: my ($needs_upload,$partlist);
1.495 raeburn 456: my ($symb)= &Apache::lonnet::whichuser();
457: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
1.478 raeburn 458: if ($is_task) {
1.495 raeburn 459: $extra_head .= &Apache::lonhtmlcommon::file_submissionchk_js();
1.493 raeburn 460: } else {
461: if (&Apache::lonnet::EXT("resource.$Apache::inputtags::part.uploadedfiletypes") ne '') {
1.495 raeburn 462: unless ($env{'request.state'} eq 'construct') {
463: my $navmap = Apache::lonnavmaps::navmap->new();
464: if (ref($navmap)) {
465: my $mapres = $navmap->getResourceByUrl($map);
1.496 raeburn 466: my $is_page;
467: if (ref($mapres)) {
468: $is_page = $mapres->is_page();
469: }
470: unless ($is_page) {
1.495 raeburn 471: $needs_upload = 1;
472: }
1.528 raeburn 473: if ((ref($tagstack) eq 'ARRAY') && ($tagstack->[-1] eq 'problem')) {
474: my $res = $navmap->getBySymb($symb);
475: if (ref($res)) {
476: $partlist = $res->parts();
477: }
478: }
1.495 raeburn 479: }
480: }
1.493 raeburn 481: } else {
482: unless ($env{'request.state'} eq 'construct') {
483: my $navmap = Apache::lonnavmaps::navmap->new();
484: if (ref($navmap)) {
1.495 raeburn 485: my $mapres = $navmap->getResourceByUrl($map);
1.496 raeburn 486: my $is_page;
487: if (ref($mapres)) {
488: $is_page = $mapres->is_page();
489: }
1.528 raeburn 490: if ($is_page) {
491: if ((ref($tagstack) eq 'ARRAY') && ($tagstack->[-1] eq 'problem')) {
492: my $res = $navmap->getBySymb($symb);
493: if (ref($res)) {
494: $partlist = $res->parts();
495: }
496: }
497: } else {
1.495 raeburn 498: my $res = $navmap->getBySymb($symb);
499: if (ref($res)) {
1.528 raeburn 500: $partlist = $res->parts();
1.495 raeburn 501: if (ref($partlist) eq 'ARRAY') {
502: foreach my $part (@{$partlist}) {
503: my @types = $res->responseType($part);
504: my @ids = $res->responseIds($part);
505: for (my $i=0; $i < scalar(@ids); $i++) {
506: if ($types[$i] eq 'essay') {
507: my $partid = $part.'_'.$ids[$i];
508: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
509: $needs_upload = 1;
510: last;
511: }
1.493 raeburn 512: }
513: }
514: }
1.495 raeburn 515: }
516: }
1.493 raeburn 517: }
518: }
519: }
520: }
1.495 raeburn 521: if ($needs_upload) {
1.538 musolffc 522: $extra_head .= &Apache::lonhtmlcommon::file_submissionchk_js()
523: .'<script type="text/javascript"
524: src="/res/adm/includes/file_upload.js"></script>';
1.495 raeburn 525: }
1.478 raeburn 526: }
1.425 raeburn 527:
1.344 albertel 528: my %body_args;
529: if (defined($found{'html'})) {
530: $body_args{'skip_phases'}{'head'}=1;
531: } else {
1.343 albertel 532:
1.345 albertel 533: $extra_head .= &Apache::lonhtmlcommon::spellheader();
1.343 albertel 534:
1.379 albertel 535: $extra_head .= &Apache::londefdef::generate_css_links();
536:
1.384 albertel 537: if ($env{'request.state'} eq 'construct') {
1.343 albertel 538: $extra_head.=&Apache::edit::js_change_detection().
539: "<script type=\"text/javascript\">\n".
540: "if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
541: &Apache::loncommon::browser_and_searcher_javascript().
542: "\n</script>\n";
1.525 raeburn 543: if ($target eq 'edit') {
544: $extra_head .= &Apache::edit::js_update_linknum();
545: }
1.343 albertel 546: }
1.159 albertel 547: }
1.343 albertel 548:
1.446 bisitz 549: my $pageheader = '';
1.344 albertel 550: if (defined($found{'body'})) {
551: $body_args{'skip_phases'}{'body'}=1;
552: } elsif (!defined($found{'body'})
553: && $env{'request.state'} eq 'construct') {
1.343 albertel 554: if ($target eq 'web' || $target eq 'edit') {
1.542 raeburn 555: unless ($env{'form.inhibitmenu'} eq 'yes') {
556: # Breadcrumbs for Authoring Space
557: &Apache::lonhtmlcommon::clear_breadcrumbs();
558: &Apache::lonhtmlcommon::add_breadcrumb({
559: 'text' => 'Authoring Space',
560: 'href' => &Apache::loncommon::authorspace($env{'request.uri'}),
561: });
562: # breadcrumbs (and tools) will be created
563: # in start_page->bodytag->innerregister
1.460 droeschl 564:
1.450 bisitz 565: # FIXME Where are we?
1.542 raeburn 566: # &Apache::lonhtmlcommon::add_breadcrumb({
567: # 'text' => 'Problem Editing', # 'Problem Testing'
568: # 'href' => '',
569: # });
570: $pageheader = &Apache::loncommon::head_subbox(
571: &Apache::loncommon::CSTR_pageheader());
572: }
573: }
1.272 albertel 574: } elsif (!defined($found{'body'})) {
1.343 albertel 575: my %add_entries;
1.159 albertel 576: my $background=&Apache::lonxml::get_param('background',$parstack,
577: $safeeval);
1.343 albertel 578: if ($background ne '' ) {
579: $add_entries{'background'} = $background;
580: }
1.344 albertel 581:
1.290 albertel 582: my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,
583: $safeeval);
1.446 bisitz 584: if ($bgcolor eq '' ) { $bgcolor = '#FFFFFF'; }
1.344 albertel 585:
1.446 bisitz 586: $body_args{'bgcolor'} = $bgcolor;
587: # $body_args{'no_title'} = 1;
588: $body_args{'force_register'} = 1;
589: $body_args{'add_entries'} = \%add_entries;
1.466 droeschl 590: if ( $env{'request.state'} eq 'construct') {
1.446 bisitz 591: $body_args{'only_body'} = 1;
1.518 raeburn 592: } elsif ($target eq 'web') {
593: $body_args{'print_suppress'} = 1;
1.446 bisitz 594: }
1.344 albertel 595: }
1.365 albertel 596: $body_args{'no_auto_mt_title'} = 1;
1.344 albertel 597: my $page_start = &Apache::loncommon::start_page($name,$extra_head,
598: \%body_args);
1.446 bisitz 599: $page_start .= $pageheader;
1.462 raeburn 600: if (!defined($found{'body'})
601: && $env{'request.state'} ne 'construct'
602: && ($target eq 'web' || $target eq 'webgrade')) {
603:
604: my ($symb,undef,undef,undef,$publicuser)= &Apache::lonnet::whichuser();
605: if ($symb eq '' && !$publicuser) {
606: $page_start .= '<p class="LC_info">'
607: .&mt('Browsing resource, all submissions are temporary.')
608: .'</p>';
1.457 bisitz 609: }
1.344 albertel 610: }
611:
1.409 albertel 612: if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') {
1.343 albertel 613: $page_start .= &Apache::lonxml::message_location();
1.159 albertel 614: }
615: my $form_tag_start;
616: if (!defined($found{'form'})) {
1.337 albertel 617: $form_tag_start='<form name="lonhomework" enctype="multipart/form-data" method="post" action="';
1.465 raeburn 618: my $uri = &Apache::loncommon::inhibit_menu_check(
1.455 droeschl 619: &Apache::lonenc::check_encrypt($env{'request.uri'}));
1.464 raeburn 620: $uri = &HTML::Entities::encode($uri,'<>&"');
1.327 albertel 621: $form_tag_start.=$uri.'" ';
622: if ($target eq 'edit') {
623: $form_tag_start.=&Apache::edit::form_change_detection();
624: }
1.493 raeburn 625: my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
626: my ($path,$multiresp) =
627: &Apache::loncommon::get_turnedin_filepath($symb,$uname,$udom);
1.495 raeburn 628: if (($is_task) || ($needs_upload)) {
629: $form_tag_start .= ' onsubmit="return file_submission_check(this,'."'$path','$multiresp'".');"';
1.478 raeburn 630: }
1.368 albertel 631: $form_tag_start.='>'."\n";
1.355 albertel 632:
633: if ($symb =~ /\S/) {
634: $symb=
635: &HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb));
636: $form_tag_start.=
1.368 albertel 637: "\t".'<input type="hidden" name="symb" value="'.$symb.'" />'."\n";
1.355 albertel 638: }
1.159 albertel 639: }
1.528 raeburn 640: return ($page_start,$form_tag_start,$partlist);
1.105 albertel 641: }
642:
1.141 matthew 643: #use Time::HiRes();
1.105 albertel 644: sub get_resource_name {
1.159 albertel 645: my ($parstack,$safeeval)=@_;
1.388 foxr 646: my $name;
1.204 albertel 647: if (defined($Apache::lonhomework::name)) {
1.388 foxr 648: $name = $Apache::lonhomework::name;
649: } else {
650: my ($symb)=&Apache::lonnet::whichuser();
1.392 albertel 651: $name=&Apache::lonnet::gettitle($symb);
1.388 foxr 652: if ($name eq '') {
653: $name=&Apache::lonnet::EXT('resource.title');
654: if ($name eq 'con_lost') { $name = ''; }
655: }
656: if ($name!~/\S+/) {
657: $name=$env{'request.uri'};
658: $name=~s-.*/([^/]+)$-$1-;
659: }
660: # The name has had html tags escaped:
661:
662: $name=~s/</</gs;
663: $name=~s/>/>/gs;
664:
665: $Apache::lonhomework::name=$name;
1.204 albertel 666: }
1.159 albertel 667: return $name;
1.105 albertel 668: }
669:
670: sub setup_rndseed {
1.570 raeburn 671: my ($safeeval,$target,$probpartlist,$prevparttype)=@_;
1.367 albertel 672: my ($symb)=&Apache::lonnet::whichuser();
1.564 raeburn 673: my ($questiontype,$set_safespace,$rndseed,$numtries,$reqtries);
1.479 raeburn 674: if ($target eq 'analyze') {
675: $questiontype = $env{'form.grade_questiontype'};
676: }
677: unless (defined($questiontype)) {
678: $questiontype = $Apache::lonhomework::type;
679: }
1.564 raeburn 680: if ($Apache::lonhomework::type eq 'randomizetry') {
681: my $partfortries = $Apache::inputtags::part;
1.568 raeburn 682: #
683: # Where question type is "randomizetry" for a problem containing
684: # a single part (and unless type is explicitly set to not be
685: # "randomizetry" for that part), the number of tries used to
686: # determine randomization will be for that part, and randomization
687: # from calls to &random() in a perl script block before the part tag,
688: # will change based on the number of tries, and value of the
689: # "randomizeontries" parameter in effect for the single part.
690: #
1.564 raeburn 691: if (ref($probpartlist) eq 'ARRAY') {
1.568 raeburn 692: if ((@{$probpartlist} == 1) && ($probpartlist->[0] ne $partfortries)) {
693: if (&Apache::lonnet::EXT('resource.'.$probpartlist->[0].'.type') eq 'randomizetry') {
1.566 raeburn 694: $partfortries = $probpartlist->[0];
695: } else {
696: $partfortries = '';
697: }
1.564 raeburn 698: }
699: }
1.566 raeburn 700: if ($partfortries ne '') {
701: $numtries = $Apache::lonhomework::history{"resource.$partfortries.tries"};
702: $reqtries = &Apache::lonnet::EXT("resource.$partfortries.randomizeontries");
703: }
1.564 raeburn 704: }
1.555 raeburn 705: if (($env{'request.state'} eq "construct")
706: || ($symb eq '')
707: || ($Apache::lonhomework::type eq 'practice')
708: || ($Apache::lonhomework::history{'resource.CODE'})
709: || (($env{'form.code_for_randomlist'}) && ($target eq 'analyze'))) {
1.316 www 710: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.317 albertel 711: ['rndseed']);
1.284 albertel 712: $rndseed=$env{'form.rndseed'};
1.159 albertel 713: if (!$rndseed) {
1.162 albertel 714: $rndseed=$Apache::lonhomework::history{'rndseed'};
715: if (!$rndseed) {
716: $rndseed=time;
717: }
1.555 raeburn 718: unless ($env{'form.code_for_randomlist'}) {
719: $env{'form.rndseed'}=$rndseed;
720: }
1.162 albertel 721: }
1.565 raeburn 722: if ((($env{'request.state'} eq "construct") || ($symb eq '')) &&
1.479 raeburn 723: ($Apache::lonhomework::type eq 'randomizetry')) {
1.564 raeburn 724: if ($numtries) {
725: if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) {
726: my $inc = int($numtries/$reqtries);
727: $rndseed += $inc;
728: } else {
729: $rndseed += $numtries;
730: }
1.479 raeburn 731: }
1.480 raeburn 732: $env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed;
1.479 raeburn 733: }
1.551 damieng 734: if ( ($env{'form.resetdata'} eq 'new_problem_variation'
1.374 albertel 735: && $env{'form.submitted'} eq 'yes') ||
1.284 albertel 736: $env{'form.newrandomization'} eq &mt('New Randomization')) {
1.190 albertel 737: srand(time);
738: $rndseed=int(rand(2100000000));
1.284 albertel 739: $env{'form.rndseed'}=$rndseed;
740: delete($env{'form.resetdata'});
741: delete($env{'form.newrandomization'});
1.159 albertel 742: }
1.488 www 743: $rndseed=~s/\,/\:/g;
744: $rndseed=~s/[^\w\d\:\-]//g;
1.489 www 745: if (defined($rndseed)) {
746: my ($c1,$c2)=split(/\:/,$rndseed);
747: unless ($c2) { $c2=0; }
748: unless (($c1==int($c1)) && ($c2==int($c2))) {
749: $rndseed=join(':',&Apache::lonnet::digest($rndseed));
750: }
1.187 albertel 751: }
1.555 raeburn 752: if (($env{'form.code_for_randomlist'}) && ($target eq 'analyze')) {
753: $env{'form.CODE'} = $env{'form.code_for_randomlist'};
754: $rndseed=&Apache::lonnet::rndseed();
755: undef($env{'form.CODE'});
756: } elsif ($Apache::lonhomework::history{'resource.CODE'}) {
1.247 albertel 757: $rndseed=&Apache::lonnet::rndseed();
758: }
1.479 raeburn 759: $set_safespace = 1;
760: } elsif ($questiontype eq 'randomizetry') {
761: if ($target eq 'analyze') {
762: if (defined($env{'form.grade_rndseed'})) {
763: $rndseed = $env{'form.grade_rndseed'};
764: }
765: }
766: unless (($target eq 'analyze') && (defined($rndseed))) {
767: $rndseed=&Apache::lonnet::rndseed();
1.564 raeburn 768: my $curr_try = $numtries;
1.479 raeburn 769: if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
770: $curr_try ++;
771: }
772: if ($rndseed =~/^(\d+)[,:](\d+)$/) {
773: $rndseed = $1;
774: }
775: if ($curr_try) {
776: if (($reqtries =~ /^\d+$/) && ($reqtries > 1)) {
777: my $inc = int(($curr_try-1)/$reqtries);
778: $rndseed += $inc;
779: } else {
780: $rndseed += $curr_try;
781: }
782: }
783: }
784: $set_safespace = 1;
1.528 raeburn 785: if ($target eq 'grade') {
786: $Apache::lonhomework::rawrndseed = $rndseed;
787: }
1.570 raeburn 788: } elsif ($prevparttype eq 'randomizetry') {
789: if ($env{'form.0.rndseed'} ne '') {
790: $set_safespace = 1;
791: $rndseed = $env{'form.0.rndseed'};
792: }
1.479 raeburn 793: }
794: if ($set_safespace) {
795: if ($safeeval) {
796: &Apache::lonxml::debug("Setting rndseed to $rndseed");
797: &Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval);
1.569 raeburn 798: if (($Apache::lonhomework::type eq 'randomizetry') || ($prevparttype eq 'randomizetry')) {
799: &Apache::lonxml::debug("Setting randomizetrypart to $Apache::inputtags::part");
800: &Apache::run::run('$external::randomizetrypart="'.$Apache::inputtags::part.'";',$safeeval);
801: }
1.479 raeburn 802: }
803: }
804: unless (($env{'request.state'} eq "construct") || ($symb eq '')) {
805: $env{'form.'.$Apache::inputtags::part.'.rndseed'}=$rndseed;
1.159 albertel 806: }
807: return $rndseed;
1.105 albertel 808: }
809:
1.268 albertel 810: sub remember_problem_state {
811: return '
1.284 albertel 812: <input type="hidden" name="problemstate" value="'.$env{'form.problemstate'}.'" />
813: <input type="hidden" name="problemtype" value="'.$env{'form.problemtype'}.'" />
814: <input type="hidden" name="problemstatus" value="'.$env{'form.problemstatus'}.'" />';
1.268 albertel 815: }
816:
1.487 www 817: sub problem_edit_action_button {
818: my ($name,$action,$accesskey,$text,$flag)=@_;
819: my $actionscript="setmode(this.form,'$action')";
820: return "\n<input type='button' name='$name' accesskey='$accesskey' value='".&mt($text)."'".
821: ($flag?&Apache::edit::submit_ask_anyway($actionscript):&Apache::edit::submit_dont_ask($actionscript))." />";
822: }
823:
1.423 www 824: sub problem_edit_buttons {
1.487 www 825: my ($mode)=@_;
1.535 droeschl 826: # Buttons that save
827: my $result = '<div style="float:right">';
828: if ($mode eq 'editxml') {
829: $result.=&problem_edit_action_button('subsaveedit','saveeditxml','s','Save and EditXML');
830: $result.=&problem_edit_action_button('subsaveview','saveviewxml','v','Save and View');
831: } else {
832: $result.=&problem_edit_action_button('subsaveedit','saveedit','s','Save and Edit');
833: $result.=&problem_edit_action_button('subsaveview','saveview','v','Save and View');
834: }
835: $result.="\n</div>\n";
1.487 www 836: # Buttons that do not save
1.535 droeschl 837: $result .= '<div>'.
1.487 www 838: &problem_edit_action_button('subdiscview','discard','d','Discard Edits and View',1);
839: if ($mode eq 'editxml') {
840: $result.=&problem_edit_action_button('subedit','edit','e','Edit',1);
841: $result.=&problem_edit_action_button('subundo','undoxml','u','Undo',1);
1.550 raeburn 842: if ($env{'environment.nocodemirror'}) {
843: $result.=&Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1);
844: }
1.487 www 845: } else {
846: $result.=&problem_edit_action_button('subeditxml','editxml','x','EditXML',1);
847: $result.=&problem_edit_action_button('subundo','undo','u','Undo',1);
848: }
849: $result.="\n</div>";
850: return $result;
1.423 www 851: }
852:
853: sub problem_edit_header {
1.527 golterma 854: my ($mode)=@_;
855: my $return = '<input type="hidden" name="submitted" value="edit" />'.
1.487 www 856: &remember_problem_state('edit').'
1.527 golterma 857: <div class="LC_edit_problem_header">
858: <div class="LC_edit_problem_header_title">
859: '.&mt('Problem Editing').$mode.&Apache::loncommon::help_open_menu('Problem Editing','Problem_Editor_XML_Index',5,'Authoring').'
860: </div><div class="LC_edit_actionbar" id="actionbar">'.
861: '<input type="hidden" name="problemmode" value="saveedit" />'.
862: &problem_edit_buttons();
863:
1.535 droeschl 864: $return .= '</div></div>' . &Apache::lonxml::message_location();
1.527 golterma 865: $return .= '<link rel="stylesheet" href="/adm/codemirror/codemirror-combined.css" />
866: <script type="text/javascript" src="/adm/codemirror/codemirror-compressed-colorful.js"></script>';
867:
868: $return .= '<script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
869: <script type="text/javascript">
870: // unless internet explorer
871: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
872: $(document).ready(
873: function() {
874: $(\'.LC_edit_actionbar\').scrollToFixed(
875: {
876: fixed: function(){
1.535 droeschl 877: //$(this).find(\'.LC_edit_actionbar\').css(\'height\', \'31px\');
878: $(this).find(\'.LC_edit_actionbar\');
1.527 golterma 879: }
880: }
881: );
882: }
883: );
884: }
885: </script>
886: <table id="LC_edit_problem_colorful" border="0" width="100%"><tr><td bgcolor="#F8F8F8">';
887: return $return;
1.105 albertel 888: }
889:
890: sub problem_edit_footer {
1.527 golterma 891: my $resource = $env{'request.ambiguous'};
1.412 albertel 892: return '</td></tr></table><br />
893: <div class="LC_edit_problem_footer">
1.453 bisitz 894: <hr />'.
1.423 www 895: &problem_edit_buttons().'
1.459 bisitz 896: <hr style="clear:both;" />
1.527 golterma 897: <script type="text/javascript">
898: restoreState("'.$resource.'");
899: restoreScrollPosition("'.$resource.'");
900: </script>
1.412 albertel 901: </div>
902: '.
1.342 albertel 903: "\n</form>\n".&Apache::loncommon::end_page();
1.105 albertel 904: }
905:
1.235 albertel 906: sub option {
907: my ($value,$name) = @_;
908: my $result ="<option value='".$value."' ";
1.284 albertel 909: if ($env{'form.'.$name} eq $value) {
1.235 albertel 910: $result.=" selected='on' ";
911: }
912: $result.='>';
913: return $result;
914: }
915:
1.105 albertel 916: sub problem_web_to_edit_header {
1.159 albertel 917: my ($rndseed)=@_;
1.406 albertel 918: my $result .= '<div class="LC_edit_problem_header">';
919:
920: if (!$Apache::lonhomework::parsing_a_task) {
921: $result .=
922: '<div class="LC_edit_problem_header_title">'.
923: &mt('Problem Testing').
924: &Apache::loncommon::help_open_topic('Problem_Editor_Testing_Area').
925: '</div>';
926: } else {
927: $result .=
928: '<div class="LC_edit_problem_header_title">'.
929: &mt('Task Testing').
930: '</div>';
931: }
932:
1.315 albertel 933: my $show_all_foils_text =
934: ($Apache::lonhomework::parsing_a_task) ?
1.452 bisitz 935: &mt('Show All Instances')
936: : &mt('Show All Foils');
1.315 albertel 937:
1.452 bisitz 938: my $show_all= '<span class="LC_nobreak"><label for="showallfoils">'
939: .'<input type="checkbox" name="showallfoils"';
1.440 bisitz 940: if (defined($env{'form.showallfoils'})) { $show_all.=' checked="checked"'; }
1.452 bisitz 941: $show_all.= ' /> '.$show_all_foils_text
942: .'</label></span>';
1.406 albertel 943:
944:
1.384 albertel 945:
1.406 albertel 946: $result .= '<div class="LC_edit_problem_header_status_row">';
1.313 albertel 947: if (!$Apache::lonhomework::parsing_a_task) {
948: $result.="
1.406 albertel 949: <div class='LC_edit_problem_header_row1'>
950: <span class=\"LC_nobreak\">
1.405 albertel 951: ".&mt("Problem Status:")."
1.235 albertel 952: <select name='problemstate'>
1.270 albertel 953: <option value=''></option>
1.235 albertel 954: ".&option('CLOSED' ,'problemstate').&mt("Closed")."</option>
955: ".&option('CAN_ANSWER' ,'problemstate').&mt("Answerable")."</option>
956: ".&option('CANNOT_ANSWER_tries' ,'problemstate').&mt("Open with full tries")."</option>
957: ".&option('CANNOT_ANSWER_correct','problemstate').&mt("Open and correct")."</option>
958: ".&option('SHOW_ANSWER' ,'problemstate').&mt("Show Answer")."</option>
959: </select>
1.406 albertel 960: </span>
961: <span class=\"LC_nobreak\">
1.405 albertel 962: ".&mt("Problem Type:")."
1.235 albertel 963: <select name='problemtype'>
1.270 albertel 964: <option value=''></option>
1.509 bisitz 965: ".&option('exam' ,'problemtype').&mt("Bubblesheet Exam Problem")."</option>
1.428 raeburn 966: ".&option('problem','problemtype').&mt("Homework Problem")."</option>
1.242 albertel 967: ".&option('survey' ,'problemtype').&mt("Survey Question")."</option>
1.465 raeburn 968: ".&option('surveycred' ,'problemtype').&mt("Survey Question (with credit)")."</option>
969: ".&option('anonsurvey' ,'problemtype').&mt("Anonymous Survey Question")."</option>
970: ".&option('anonsurveycred' ,'problemtype').&mt("Anonymous Survey Question (with credit)")."</option>
1.428 raeburn 971: ".&option('practice' ,'problemtype').&mt("Practice Problem")."</option>
1.479 raeburn 972: ".&option('randomizetry' ,'problemtype').&mt("New Randomization Each Try")."</option>
1.235 albertel 973: </select>
1.406 albertel 974: </span>
975: $show_all
976: </div>
977: <div class='LC_edit_problem_header_row2'>
978: <span class=\"LC_nobreak\">
1.405 albertel 979: ".&mt("Feedback Mode:")."
1.235 albertel 980: <select name='problemstatus'>
981: <option value=''></option>
1.242 albertel 982: ".&option('yes','problemstatus').&mt("Show Feedback")."</option>
1.517 bisitz 983: ".&option('no', 'problemstatus').&mt("Don't Show Incorrect/Correct Feedback")."</option>
1.405 albertel 984: ".&option('no_feedback_ever', 'problemstatus').&mt("Don't Show Any Feedback")."</option>
1.235 albertel 985: </select>
1.406 albertel 986: </span>
987: ";
988:
1.376 albertel 989: } elsif ($Apache::lonhomework::parsing_a_task) {
990: $result.="
1.406 albertel 991: <div class='LC_edit_problem_header_row1'>
992: <span class=\"LC_nobreak\">
1.405 albertel 993: ".&mt("Problem Status:")."
1.376 albertel 994: <select name='problemstate'>
995: <option value=''></option>
996: ".&option('CLOSED' ,'problemstate').&mt("Closed")."</option>
997: ".&option('CAN_ANSWER' ,'problemstate').&mt("Answerable")."</option>
998: ".&option('WEB_GRADE' ,'problemstate').&mt("Criteria Grading")."</option>
999: ".&option('SHOW_ANSWER' ,'problemstate').&mt("Show Feedback")."</option>
1000: </select>
1.406 albertel 1001: </span>
1002: $show_all
1003: ";
1004: }
1005: $result.='
1006: <span class="LC_nobreak">
1007: '.&mt('Apply style file: ').'
1008: <input type="text" name="style_file" value="'.&HTML::Entities::encode($env{'construct.style'},'"<>&').'" />
1009: <a href="javascript:openbrowser(\'lonhomework\',\'style_file\',\'sty\')">'.&mt('Select').'</a>
1010: </span>
1.422 www 1011: </div>
1012: <div class="LC_edit_problem_header_row1">'.
1013: &Apache::lonxml::renderingoptions().'
1.406 albertel 1014: </div>
1015: <input type="submit" name="changeproblemmode" value="'.&mt("Change View").'" />
1016: <input type="submit" name="clear_style_file" accesskey="d" value="'.&mt('Show Default View').'" />
1.551 damieng 1017: <button type="submit" name="resetdata" accesskey="r" value="reset_submissions">
1018: '.&mt('Reset Submissions').'</button>
1.406 albertel 1019: </div>
1.453 bisitz 1020: <hr />
1.406 albertel 1021: <div class="LC_edit_problem_header_randomize_row">
1022: <input type="submit" name="newrandomization" accesskey="a" value="'.&mt('New Randomization').'" />
1023: <input type="submit" name="changerandseed" value="'.&mt('Change Random Seed To:').'" />
1.488 www 1024: <input type="text" name="rndseed" size="24" value="'.
1.406 albertel 1025: $rndseed.'"
1026: onchange="javascript:document.lonhomework.changerandseed.click()" />';
1027:
1028: if (!$Apache::lonhomework::parsing_a_task) {
1029: my $numtoanalyze=$env{'form.numtoanalyze'};
1030: if (!$numtoanalyze) { $numtoanalyze=20; }
1.408 albertel 1031: $result .= '<span class="LC_nobreak">'.
1032: &mt('[_1] for [_2] versions.',
1.416 raeburn 1033: '<input type="button" name="submitmode" value="'.&mt('Calculate answers').'" '.
1.419 bisitz 1034: 'onclick="javascript:setmode(this.form,'."'calcanswers'".')" />'
1035: ,'<input type="text" name="numtoanalyze" value="'.
1.408 albertel 1036: $numtoanalyze.'" size="5" />').
1037: &Apache::loncommon::help_open_topic("Analyze_Problem",'',undef,undef,300).
1038: '</span>';
1039:
1.313 albertel 1040: }
1.406 albertel 1041:
1042: $result.='
1043: </div>
1.453 bisitz 1044: <hr />
1.447 bisitz 1045: <div>';
1.416 raeburn 1046: $result.='<input type="hidden" name="problemmode" value="view" />';
1047: $result .= '<input type="button" name="submitmode" accesskey="e" value="'.&mt('Edit').'" '.
1048: 'onclick="javascript:setmode(this.form,'."'edit'".')" />';
1049: $result .= '<input type="button" name="submitmode" accesskey="x" value="'.&mt('EditXML').'" '.
1050: 'onclick="javascript:setmode(this.form,'."'editxml'".')" />';
1.541 damieng 1051: if ($env{'browser.type'} ne 'explorer' || $env{'browser.version'} > 9) {
1052: my $uri = $env{'request.uri'};
1.543 damieng 1053: my $daxeurl = '/daxepage'.$uri;
1.541 damieng 1054: $result .= '<input type="button" value="'.&mt('Edit with Daxe').'" '.
1055: 'onclick="window.open(\''.$daxeurl.'\',\'_blank\');" />';
1056: }
1.408 albertel 1057: $result.='
1058: </div>
1.453 bisitz 1059: <hr />
1.409 albertel 1060: '.&Apache::lonxml::message_location().'
1.406 albertel 1061: </div>';
1.159 albertel 1062: return $result;
1.48 albertel 1063: }
1064:
1.65 albertel 1065: sub initialize_storage {
1.357 albertel 1066: my ($given_symb) = @_;
1.353 albertel 1067: undef(%Apache::lonhomework::results);
1068: undef(%Apache::lonhomework::history);
1.357 albertel 1069: my ($symb,$courseid,$domain,$name) =
1.367 albertel 1070: &Apache::lonnet::whichuser($given_symb);
1.353 albertel 1071:
1072: # anonymous users (CODEd exams) have no data
1073: if ($name eq 'anonymous'
1074: && !defined($domain)) {
1075: return;
1076: }
1077:
1.333 albertel 1078: if ($env{'request.state'} eq 'construct'
1079: || $symb eq ''
1080: || $Apache::lonhomework::type eq 'practice') {
1081:
1082: my $namespace = $symb || $env{'request.uri'};
1.551 damieng 1083: if ($env{'form.resetdata'} eq 'reset_submissions' ||
1084: ($env{'form.resetdata'} eq 'new_problem_variation'
1.374 albertel 1085: && $env{'form.submitted'} eq 'yes') ||
1.333 albertel 1086: $env{'form.newrandomization'} eq &mt('New Randomization')) {
1087: &Apache::lonnet::tmpreset($namespace,'',$domain,$name);
1088: &Apache::lonxml::debug("Attempt reset");
1089: }
1.159 albertel 1090: %Apache::lonhomework::history=
1.333 albertel 1091: &Apache::lonnet::tmprestore($namespace,'',$domain,$name);
1.526 raeburn 1092: my ($temp)=keys(%Apache::lonhomework::history) ;
1.159 albertel 1093: &Apache::lonxml::debug("Return message of $temp");
1094: } else {
1095: %Apache::lonhomework::history=
1096: &Apache::lonnet::restore($symb,$courseid,$domain,$name);
1097: }
1.353 albertel 1098:
1.159 albertel 1099: #ignore error conditions
1.526 raeburn 1100: my ($temp)=keys(%Apache::lonhomework::history);
1.159 albertel 1101: if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); }
1.65 albertel 1102: }
1103:
1.435 jms 1104: =pod
1105:
1106: =item finalize_storage()
1107:
1.524 raeburn 1108: Stores away the result hash to a student's environment;
1.523 raeburn 1109: checks form.grade_ for specific values, otherwise stores
1110: to the running user's environment.
1.524 raeburn 1111:
1112: &check_correctness_changes() is called in two circumstances
1113: in which the results hash is to be stored permanently, for
1114: grading triggered by a student's submission, where feedback on
1115: correctness is to be provided to the student.
1116:
1117: 1. Immediately prior to storing the results hash
1118:
1119: To handle the case where a student's submission (and award) were
1120: stored after history was retrieved in &initialize_storage(), e.g.,
1121: if a student submitted answers in quick succession (e.g., from
1122: multiple tabs). &Apache::inputtags::hidealldata() is called for
1123: any parts with out-of-order storage (i.e., correct then incorrect,
1124: where awarded >= 1 when correct).
1125:
1126: 2. Immediately after storing the results hash
1127:
1128: To handle the case where lond on the student's homeserver returns
1129: delay:N -- where N is the number of transactions between the last
1130: retrieved in &initialize_storage() and the last stored immediately
1131: before permanent storage of the current transaction via
1132: lond::store_handler(). &Apache::grades::makehidden() is called
1133: for any parts with out-of-order storage (i.e., correct then incorrect,
1134: where awarded >= 1 when correct).
1135:
1136: Will call &store_aggregates() to increment totals for attempts,
1137: students, and corrects, if running user has student role.
1138:
1.435 jms 1139: =cut
1140:
1141:
1.65 albertel 1142: sub finalize_storage {
1.357 albertel 1143: my ($given_symb) = @_;
1.159 albertel 1144: my $result;
1.289 albertel 1145: if (%Apache::lonhomework::results) {
1.323 albertel 1146: my @remove = grep(/^INTERNAL_/,keys(%Apache::lonhomework::results));
1147: delete(@Apache::lonhomework::results{@remove});
1.357 albertel 1148: my ($symb,$courseid,$domain,$name) =
1.367 albertel 1149: &Apache::lonnet::whichuser($given_symb);
1.562 raeburn 1150: my ($passback,$ltiscope,$ltimap,$ltisymb,$ltiref,$total,$possible,$dopassback);
1.333 albertel 1151: if ($env{'request.state'} eq 'construct'
1152: || $symb eq ''
1153: || $Apache::lonhomework::type eq 'practice') {
1154: my $namespace = $symb || $env{'request.uri'};
1.284 albertel 1155: $Apache::lonhomework::results{'rndseed'}=$env{'form.rndseed'};
1.159 albertel 1156: $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results,
1.333 albertel 1157: $namespace,'',$domain,$name);
1.159 albertel 1158: &Apache::lonxml::debug('Construct Store return message:'.$result);
1159: } else {
1.560 raeburn 1160: my ($laststore,$checkedparts,@parts,%postcorrect,%record);
1.524 raeburn 1161: if (($env{'user.name'} eq $name) && ($env{'user.domain'} eq $domain) &&
1162: (!$Apache::lonhomework::scantronmode) && (!defined($env{'form.grade_symb'})) &&
1163: (!defined($env{'form.grade_courseid'}))) {
1.560 raeburn 1164: if ($env{'request.lti.login'}) {
1165: my ($map)=&Apache::lonnet::decode_symb($symb);
1166: $map = &Apache::lonnet::clutter($map);
1167: ($passback,$ltiscope,$ltimap,$ltisymb,$ltiref) =
1168: &needs_lti_passback($courseid,$symb,$map);
1169: }
1.524 raeburn 1170: if ($Apache::lonhomework::history{'version'}) {
1171: $laststore = $Apache::lonhomework::history{'version'}.'='.
1172: $Apache::lonhomework::history{'timestamp'};
1173: } else {
1174: $laststore = '0=0';
1175: }
1.560 raeburn 1176: %record = &Apache::lonnet::restore($symb,$courseid,$domain,$name);
1.524 raeburn 1177: if ($record{'version'}) {
1178: my ($newversion,$oldversion,$oldtimestamp);
1179: if ($Apache::lonhomework::history{'version'}) {
1180: $oldversion = $Apache::lonhomework::history{'version'};
1181: $oldtimestamp = $Apache::lonhomework::history{'timestamp'};
1182: } else {
1183: $oldversion = 0;
1184: $oldtimestamp = 0;
1185: }
1186: if ($record{'version'} > $oldversion) {
1187: if ($record{'timestamp'} >= $oldtimestamp) {
1188: $laststore = $record{'version'}.'='.$record{'timestamp'};
1189: $newversion = $record{'version'} + 1;
1190: $checkedparts = 1;
1191: foreach my $key (keys(%Apache::lonhomework::results)) {
1192: if ($key =~ /^resource\.([^\.]+)\.solved$/) {
1193: my $part = $1;
1194: if ($Apache::lonhomework::results{$key} eq 'incorrect_attempted') {
1195: push(@parts,$part);
1196: }
1197: }
1198: }
1199: if (@parts) {
1200: my @parts_to_hide = &check_correctness_changes($symb,$courseid,$domain,$name,
1201: \%record,\@parts,$newversion,
1202: $oldversion);
1203: if (@parts_to_hide) {
1204: foreach my $part (@parts_to_hide) {
1205: $postcorrect{$part} = 1;
1206: &Apache::inputtags::hidealldata($part);
1207: }
1208: }
1209: }
1210: }
1211: }
1212: }
1213: }
1.159 albertel 1214: $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results,
1.524 raeburn 1215: $symb,$courseid,$domain,$name,$laststore);
1216: if ($result =~ /^delay\:(\d+)$/) {
1217: my $numtrans = $1;
1218: my ($oldversion) = split(/=/,$laststore);
1219: if ($numtrans) {
1220: my $newversion = $oldversion + 1 + $numtrans;
1221: my @possparts;
1222: if ($checkedparts) {
1223: foreach my $part (@parts) {
1224: unless ($postcorrect{$part}) {
1225: push(@possparts,$part);
1226: }
1227: }
1228: } else {
1229: foreach my $key (keys(%Apache::lonhomework::results)) {
1230: if ($key =~ /^resource\.([^\.]+)\.solved$/) {
1231: my $part = $1;
1232: unless ($postcorrect{$part}) {
1233: if ($Apache::lonhomework::results{$key} eq 'incorrect_attempted') {
1234: push(@possparts,$part);
1235: }
1236: }
1237: }
1238: }
1239: }
1240: if (@possparts) {
1241: my %newrecord = &Apache::lonnet::restore($symb,$courseid,$domain,$name);
1242: my @parts_to_hide = &check_correctness_changes($symb,$courseid,$domain,$name,
1243: \%newrecord,\@possparts,$newversion,
1244: $oldversion);
1245: if (@parts_to_hide) {
1246: my $partslist = join(',',@parts_to_hide);
1247: &Apache::grades::makehidden($newversion,$partslist,\%newrecord,$symb,$domain,$name,1);
1248: }
1249: }
1250: }
1251: }
1.562 raeburn 1252: if ($passback) {
1253: foreach my $key (keys(%Apache::lonhomework::results)) {
1254: if ($key =~ /^resource\.([^\.]+)\.solved$/) {
1255: my $part = $1;
1256: if ((($Apache::lonhomework::results{$key} =~ /^correct_/) ||
1257: ($Apache::lonhomework::results{$key} eq 'incorrect_attempted')) &&
1258: ($Apache::lonhomework::results{"resource.$part.tries"})) {
1259: $dopassback = 1;
1260: last;
1261: }
1262: }
1263: }
1264: }
1265: if (($dopassback) && ($ltiscope eq 'resource') && ($ltisymb eq $symb)) {
1.560 raeburn 1266: $total = 0;
1267: $possible = 0;
1268: my $navmap = Apache::lonnavmaps::navmap->new();
1269: if (ref($navmap)) {
1270: my $res = $navmap->getBySymb($symb);
1271: if (ref($res)) {
1272: my $partlist = $res->parts();
1273: if (ref($partlist) eq 'ARRAY') {
1274: foreach my $part (@{$partlist}) {
1275: unless (exists($Apache::lonhomework::results{"resource.$part.solved"})) {
1276: next if ($Apache::lonhomework::record{"resource.$part.solved"} =~/^excused/);
1277: my $weight = &Apache::lonnet::EXT("resource.$part.weight",$symb);
1278: $possible += $weight;
1279: if (($record{'version'}) && (exists($record{"resource.$part.awarded"}))) {
1280: my $awarded = $record{"resource.$part.awarded"};
1281: if ($awarded) {
1282: $total += $weight * $awarded;
1283: }
1284: }
1285: }
1286: }
1287: }
1288: }
1289: }
1290: foreach my $key (keys(%Apache::lonhomework::results)) {
1291: if ($key =~ /^resource\.([^\.]+)\.awarded$/) {
1292: my $part = $1;
1293: my $weight = &Apache::lonnet::EXT("resource.$part.weight",$symb);
1294: $possible += $weight;
1295: my $awarded = $Apache::lonhomework::results{$key};
1296: if ($awarded) {
1297: $total += $weight * $awarded;
1298: }
1299: }
1300: }
1301: }
1.159 albertel 1302: &Apache::lonxml::debug('Store return message:'.$result);
1.470 raeburn 1303: &store_aggregates($symb,$courseid);
1.562 raeburn 1304: if ($dopassback) {
1.560 raeburn 1305: my $scoreformat = 'decimal';
1306: if (ref($ltiref) eq 'HASH') {
1307: if ($ltiref->{'scoreformat'} =~ /^(decimal|ratio|percentage)$/) {
1308: $scoreformat = $1;
1309: }
1310: }
1311: my $ltigrade = {
1312: 'lti' => $ltiref,
1313: 'cid' => $courseid,
1314: 'uname' => $env{'user.name'},
1315: 'udom' => $env{'user.domain'},
1316: 'pbid' => $env{'request.lti.passbackid'},
1317: 'pburl' => $env{'request.lti.passbackurl'},
1318: 'scope' => $ltiscope,
1319: 'ltimap' => $ltimap,
1320: 'ltisymb' => $ltisymb,
1321: 'format' => $scoreformat,
1322: };
1323: if ($ltiscope eq 'resource') {
1324: $ltigrade->{'total'} = $total;
1325: $ltigrade->{'possible'} = $possible;
1326: }
1327: push(@Apache::lonhomework::ltipassback,$ltigrade);
1328: }
1.159 albertel 1329: }
1.323 albertel 1330: } else {
1331: &Apache::lonxml::debug('Nothing to store');
1.67 albertel 1332: }
1.159 albertel 1333: return $result;
1.65 albertel 1334: }
1335:
1.560 raeburn 1336: sub needs_lti_passback {
1337: my ($courseid,$symb,$map) = @_;
1338: if (($env{'request.lti.passbackid'}) && ($env{'request.lti.passbackurl'})) {
1339: if ($courseid =~ /^($LONCAPA::match_domain)_($LONCAPA::match_courseid)$/) {
1340: my ($cdom,$cnum) = ($1,$2);
1341: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
1342: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
1343: if ($lti{$env{'request.lti.login'}}{'passback'}) {
1344: my ($ltiscope,$ltiuri,$ltisymb) =
1345: &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
1346: $cdom,$cnum,1);
1347: my ($passback,$ltimap);
1348: if ($ltiscope eq 'resource') {
1349: if ($ltisymb eq $symb) {
1350: $passback = 1;
1351: }
1352: } elsif ($ltiscope eq 'map') {
1353: if ($ltiuri eq $map) {
1354: $passback = 1;
1355: $ltimap = $map;
1356: }
1357: } elsif ($ltiscope eq 'course') {
1358: if (($env{'request.lti.uri'} eq "/$cdom/$cnum") || ($env{'request.lti.uri'} eq '')) {
1359: $passback = 1;
1360: }
1361: }
1362: return ($passback,$ltiscope,$ltimap,$ltisymb,$lti{$env{'request.lti.login'}});
1363: }
1364: }
1365: }
1366: }
1367: return;
1368: }
1369:
1.435 jms 1370: =pod
1371:
1.524 raeburn 1372: =item check_correctness_changes()
1373:
1374: For all parts for which current results contain a solved status
1375: of "incorrect_attempted", check if there was a transaction in which
1376: solved was set to "correct_by_student" in the time since the last
1377: transaction (retrieved when &initialize_storage() was called i.e.,
1378: when &start_problem() was called), unless:
1379: (a) questiontype parameter is set to survey or anonymous survey (+/- credit)
1380: (b) problemstatus is set to no or no_feedback_ever
1381: If such a transaction exists, and did not occur after "reset status"
1382: by a user with grading privileges, then the current transaction is an
1383: example of an out-of-order transaction (i.e., incorrect occurring after
1384: correct). Accordingly, the current transaction should be hidden.
1385:
1386: =cut
1387:
1388:
1389: sub check_correctness_changes {
1390: my ($symb,$courseid,$domain,$name,$record,$parts,$newversion,$oldversion) = @_;
1391: my @parts_to_hide;
1392: unless ((ref($record) eq 'HASH') && (ref($parts) eq 'ARRAY')) {
1393: return @parts_to_hide;
1394: }
1395: if (@{$parts}) {
1396: my $usec;
1397: if (($env{'user.name'} eq $name) && ($env{'user.domain'} eq $domain) &&
1398: ($env{'request.course.id'} eq $courseid)) {
1399: $usec = $env{'request.course.sec'};
1400: } else {
1401: $usec = &Apache::lonnet::getsection($domain,$name,$courseid);
1402: }
1403: foreach my $id (@{$parts}) {
1404: next if (($Apache::lonhomework::results{'resource.'.$id.'.type'} =~ /survey/) ||
1405: (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
1406: $domain,$name,$usec,undef,$courseid) =~ /^no/));
1407: my $reset;
1408: for (my $i=$newversion-1; $i>=$oldversion; $i--) {
1409: if (($record->{$i.':resource.'.$id.'.regrader'}) &&
1410: ($record->{$i.':resource.'.$id.'.tries'} eq '') &&
1411: ($record->{$i.':resource.'.$id.'.award'} eq '')) {
1412: $reset = 1;
1413: } elsif (($record->{$i.":resource.$id.solved"} eq 'correct_by_student') &&
1414: ($record->{$i.":resource.$id.awarded"} >= 1)) {
1415: unless ($reset) {
1416: push(@parts_to_hide,$id);
1417: last;
1418: }
1419: }
1420: }
1421: }
1422: }
1423: return @parts_to_hide;
1424: }
1425:
1426: =pod
1427:
1.435 jms 1428: item store_aggregates()
1429:
1430: Sends hash of values to be incremented in nohist_resourcetracker.db
1431: for the course. Increments total number of attempts, unique students
1432: and corrects for each part for an instance of a problem, as appropriate.
1433:
1434: =cut
1435:
1.285 raeburn 1436: sub store_aggregates {
1437: my ($symb,$courseid) = @_;
1.479 raeburn 1438: my (%aggregate,%anoncounter,%randtrycounter);
1.286 albertel 1439: my @parts;
1.288 albertel 1440: my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
1441: my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
1.286 albertel 1442: foreach my $key (keys(%Apache::lonhomework::results)) {
1.287 albertel 1443: if ($key =~ /resource\.([^\.]+)\.tries/) {
1.286 albertel 1444: push(@parts, $1);
1.285 raeburn 1445: }
1446: }
1.286 albertel 1447: foreach my $part (@parts) {
1.470 raeburn 1448: if ($env{'request.role'} =~/^st/) {
1449: if ($Apache::lonhomework::results{'resource.'.$part.'.award'}
1450: eq 'APPROX_ANS' ||
1451: $Apache::lonhomework::results{'resource.'.$part.'.award'}
1452: eq 'EXACT_ANS') {
1453: $aggregate{$symb."\0".$part."\0correct"} = 1;
1454: }
1455: if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) {
1456: $aggregate{$symb."\0".$part."\0users"} = 1;
1457: } else {
1458: my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]);
1459: if ($last_reset) {
1460: if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) {
1461: $aggregate{$symb."\0".$part."\0users"} = 1;
1462: }
1463: }
1464: }
1465: $aggregate{$symb."\0".$part."\0attempts"} = 1;
1.285 raeburn 1466: }
1.470 raeburn 1467: if (($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurvey') ||
1.479 raeburn 1468: ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurveycred') ||
1469: ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'randomizetry')) {
1470: if ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'randomizetry') {
1471: $randtrycounter{$symb."\0".$part} = 1;
1472: } else {
1473: $anoncounter{$symb."\0".$part} = 1;
1474: }
1.545 raeburn 1475: my $needsrelease = $Apache::lonnet::needsrelease{'parameter:type:'.$Apache::lonhomework::results{'resource.'.$part.'.type'}.'::'};
1.537 raeburn 1476: if ($needsrelease) {
1.470 raeburn 1477: my $curr_required = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'};
1478: if ($curr_required eq '') {
1.471 raeburn 1479: &Apache::lonnet::update_released_required($needsrelease);
1.470 raeburn 1480: } else {
1481: my ($currmajor,$currminor) = split(/\./,$curr_required);
1482: my ($needsmajor,$needsminor) = split(/\./,$needsrelease);
1483: if (($currmajor < $needsmajor) || ($currmajor == $needsmajor && $currminor < $needsminor)) {
1.471 raeburn 1484: &Apache::lonnet::update_released_required($needsrelease);
1.470 raeburn 1485: }
1.292 raeburn 1486: }
1487: }
1.285 raeburn 1488: }
1489: }
1.526 raeburn 1490: if (keys(%aggregate) > 0) {
1.289 albertel 1491: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.292 raeburn 1492: $cdomain,$cname);
1493: }
1.472 raeburn 1494: if (keys(%anoncounter) > 0) {
1.481 raeburn 1495: &Apache::lonnet::cput('nohist_anonsurveys',\%anoncounter,
1496: $cdomain,$cname);
1.472 raeburn 1497: }
1.479 raeburn 1498: if (keys(%randtrycounter) > 0) {
1.481 raeburn 1499: &Apache::lonnet::cput('nohist_randomizetry',\%randtrycounter,
1500: $cdomain,$cname);
1.479 raeburn 1501: }
1.292 raeburn 1502: }
1.289 albertel 1503:
1.557 raeburn 1504: sub access_status_msg {
1505: my ($mode,$status,$symb,$target,$ipused,$accessmsg) = @_;
1506: my $msg;
1507: if ($target eq 'web') {
1508: if ($status eq 'UNAVAILABLE') {
1509: $msg.='<p class="LC_error">'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</p>';
1510: } elsif ($status eq 'NOT_IN_A_SLOT') {
1511: $msg.='<p class="LC_warning">'.&mt('You are not currently signed up to work at this time and/or place.').'</p>';
1512: } elsif (($status eq 'RESERVABLE') || ($status eq 'RESERVABLE_LATER') ||
1513: ($status eq 'NOTRESERVABLE')) {
1514: $msg.='<p class="LC_warning">'.&mt('Access requires reservation to work at specific time/place.').'</p>';
1515: } elsif ($status ne 'NOT_YET_VIEWED') {
1516: $msg.='<p class="LC_warning">'.&mt('Not open to be viewed').'</p>';
1517: }
1518: if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
1519: $msg.=&mt('The problem ').$accessmsg;
1520: } elsif ($status eq 'UNCHECKEDOUT') {
1521: $msg.=&checkout_msg();
1522: } elsif ($status eq 'NOT_YET_VIEWED') {
1523: $msg.=&firstaccess_msg($accessmsg,$symb);
1524: } elsif ($status eq 'NOT_IN_A_SLOT') {
1525: $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work");
1526: } elsif ($status eq 'RESERVABLE') {
1527: $msg.=&mt('Available to make a reservation.').' '.&mt('Reservation window closes [_1].',
1528: &Apache::lonnavmaps::timeToHumanString($accessmsg,'end')).
1529: '<br />'.
1530: &Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work");
1531: } elsif ($status eq 'RESERVABLE_LATER') {
1532: $msg.=&mt('Window to make a reservation will open [_1].',
1533: &Apache::lonnavmaps::timeToHumanString($accessmsg,'start'));
1534: } elsif ($status eq 'NOTRESERVABLE') {
1535: $msg.=&mt('Not available to make a reservation.');
1536: } elsif ($status eq 'NEED_DIFFERENT_IP') {
1537: if ($ipused) {
1538: $msg.=&mt('You must use the same computer ([_1]) you used when you first accessed this resource using your time/place-based reservation.',"IP: $ipused");
1539: } else {
1540: $msg.=&mt('Each student must use a different computer to access this resource at this time and/or place.').'<br />'.
1541: &mt('Somebody else has already used this particular computer for that purpose.');
1542: }
1543: }
1544: $msg.='<br />';
1545: } elsif ($target eq 'tex') {
1546: my $startminipage = ($env{'form.problem_split'}=~/yes/i)? ''
1547: : '\begin{minipage}{\textwidth}';
1548:
1549: $msg ='\noindent \vskip 1 mm '.
1550: $startminipage.'\vskip 0 mm';
1551: if ($status eq 'UNAVAILABLE') {
1552: $msg.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
1553: } else {
1554: $msg.=&mt('Problem is not open to be viewed. It')." $accessmsg \\vskip 0 mm ";
1555: }
1556: }
1557: return $msg;
1558: }
1559:
1560: sub checkin_prompt {
1561: my ($target,$slot_name,$slot,$type) = @_;
1562: my $result;
1563: if ($target eq 'web') {
1564: $result = &Apache::bridgetask::proctor_validation_screen($slot);
1565: } elsif ($target eq 'grade') {
1566: if (!&Apache::bridgetask::proctor_check_auth($slot_name,$slot,$type)) {
1567: $result = &mt('An error occurred during check-in');
1568: }
1569: }
1570: return $result;
1571: }
1572:
1573: sub selfcheckin_resource {
1574: my ($resource_due,$slot_name,$slot,$symb) = @_;
1575: if ($slot_name ne '') {
1576: my $checked_in =
1577: $Apache::lonhomework::history{'resource.0.checkedin'};
1578: if ($checked_in eq '') {
1579: # unproctored slot access, self checkin
1580: my $needsiptied;
1581: if (ref($slot)) {
1582: $needsiptied = $slot->{'iptied'};
1583: }
1584: my $check = &Apache::bridgetask::check_in('problem',undef,undef,
1585: $slot_name,$needsiptied);
1586: if ($check =~ /^error: /) {
1587: &Apache::lonnet::logthis("Error during self-checkin of problem (symb: $symb) using slot: $slot_name");
1588: } else {
1589: $checked_in = $Apache::lonhomework::results{"resource.0.checkedin"};
1590: }
1591: }
1592: if ((ref($slot) eq 'HASH') && ($checked_in ne '')) {
1593: if ($slot->{'starttime'} < time()) {
1594: if (!$resource_due) {
1595: $resource_due = $slot->{'endtime'};
1596: } elsif ($slot->{'endtime'} < $resource_due) {
1597: $resource_due = $slot->{'endtime'};
1598: }
1599: }
1600: }
1601: }
1602: return $resource_due;
1603: }
1604:
1.65 albertel 1605: sub checkout_msg {
1.211 albertel 1606: my %lt=&Apache::lonlocal::texthash(
1607: 'resource'=>'The resource needs to be checked out',
1608: '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.',
1609: 'warning'=>'Checking out resources is subject to course policies, and may exclude future credit even if done erroneously.',
1.509 bisitz 1610: 'checkout'=>'Check out Bubblesheet Exam for Viewing',
1611: 'checkout?'=>'Check out Bubblesheet Exam?');
1.352 albertel 1612: my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.159 albertel 1613: return (<<ENDCHECKOUT);
1.211 albertel 1614: <h2>$lt{'resource'}</h2>
1615: <p>$lt{'id_expln'}</p>
1.449 bisitz 1616: <p class="LC_warning">$lt{'warning'}</p>
1.444 bisitz 1617: <form name="checkout" method="post" action="$uri">
1.91 albertel 1618: <input type="hidden" name="doescheckout" value="yes" />
1.514 bisitz 1619: <input type="button" name="checkoutbutton" value="$lt{'checkout'}" onclick="javascript:if (confirm('$lt{'checkout?'}')) { document.checkout.submit(); }" />
1.65 albertel 1620: </form>
1621: ENDCHECKOUT
1622: }
1623:
1.252 albertel 1624: sub firstaccess_msg {
1.253 albertel 1625: my ($time,$symb)=@_;
1.414 albertel 1626: my $result;
1627: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1628: if ($interval[1] eq 'map') {
1629: my ($map)=&Apache::lonnet::decode_symb($symb);
1630: my $foldertitle=&Apache::lonnet::gettitle($map);
1631:
1632: &Apache::lonxml::debug("map is $map title is $foldertitle");
1.504 golterma 1633: $result .= "<h2>".&mt('The resources in "[_1]" are open for a limited time.',$foldertitle)."</h2>"
1634: .'<p>'.&mt('Once you click the "Show Resource" button below you have [_2] to complete all resources "[_1]".'
1635: ,$foldertitle,$time)."</p>";
1.414 albertel 1636: } elsif ($interval[1] eq 'course') {
1637: my $course = $env{'course.'.$env{'request.course.id'}.'.description'};
1.504 golterma 1638: $result .= "<h2>".&mt('The resources in "[_1]" are open for a limited time.',$course)."</h2>"
1.505 golterma 1639: .'<p>'.&mt('Once you click the "Show Resource" button below you have [_2] to complete all resources "[_1]".'
1.504 golterma 1640: ,$course,$time)."</p>";
1.414 albertel 1641: } else {
1642: my $title=&Apache::lonnet::gettitle($symb);
1.504 golterma 1643: $result .= "<h2>".&mt('This resource "[_1]" is open for a limited time.',$title)."</h2>"
1644: .'<p>'.&mt('Once you click the "Show Resource" button below you have [_2] to complete this resource "[_1]".'
1645: ,$title,$time)."</p>";
1.414 albertel 1646: }
1.352 albertel 1647: my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'});
1.418 bisitz 1648: my $buttontext = &mt('Show Resource');
1649: my $timertext = &mt('Start Timer?');
1.571 ! raeburn 1650: my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($symb),'\'"<>&');
1.414 albertel 1651: $result .= (<<ENDCHECKOUT);
1.444 bisitz 1652: <form name="markaccess" method="post" action="$uri">
1.252 albertel 1653: <input type="hidden" name="markaccess" value="yes" />
1.571 ! raeburn 1654: <input type="hidden" name="symb" value="$shownsymb" />
1.514 bisitz 1655: <input type="button" name="accessbutton" value="$buttontext" onclick="javascript:if (confirm('$timertext')) { document.markaccess.submit(); }" />
1.252 albertel 1656: </form>
1657: ENDCHECKOUT
1.414 albertel 1658: return $result;
1.252 albertel 1659: }
1660:
1.204 albertel 1661: sub init_problem_globals {
1662: my ($type)=@_;
1663: #initialize globals
1.308 foxr 1664: # For problems, we start out in part 0 (outside a <part> tag).
1665: # and part 0 is used to describe the main body of the <problem>
1666: #
1.204 albertel 1667: if ($type eq 'problem') {
1668: $Apache::inputtags::part='0';
1669: @Apache::inputtags::partlist=('0');
1.405 albertel 1670: &Apache::lonhomework::set_show_problem_status(&get_problem_status('0'));
1.266 albertel 1671: $Apache::lonhomework::ignore_response_errors=0;
1.308 foxr 1672:
1.266 albertel 1673: } elsif ($type eq 'library') {
1.204 albertel 1674: $Apache::inputtags::part='';
1675: @Apache::inputtags::partlist=();
1.405 albertel 1676: &Apache::lonhomework::reset_show_problem_status();
1.266 albertel 1677: $Apache::lonhomework::ignore_response_errors=1;
1.308 foxr 1678:
1.304 albertel 1679: } elsif ($type eq 'Task') {
1680: $Apache::inputtags::part='0';
1681: @Apache::inputtags::partlist=('0');
1.405 albertel 1682: &Apache::lonhomework::reset_show_problem_status();
1.304 albertel 1683: $Apache::lonhomework::ignore_response_errors=1;
1.204 albertel 1684: }
1.477 www 1685: @Apache::functionplotresponse::callscripts=();
1.204 albertel 1686: @Apache::inputtags::responselist = ();
1687: @Apache::inputtags::importlist = ();
1688: @Apache::inputtags::previous=();
1689: @Apache::inputtags::previous_version=();
1.536 raeburn 1690: $Apache::inputtags::leniency='';
1.204 albertel 1691: $Apache::structuretags::printanswer='No';
1692: @Apache::structuretags::whileconds=();
1693: @Apache::structuretags::whilebody=();
1694: @Apache::structuretags::whileline=();
1695: $Apache::lonhomework::scantronmode=0;
1.566 raeburn 1696: $Apache::lonhomework::randomizetrypart=0;
1.204 albertel 1697: undef($Apache::lonhomework::name);
1.358 albertel 1698: undef($Apache::lonhomework::default_type);
1699: undef($Apache::lonhomework::type);
1.204 albertel 1700: }
1701:
1702: sub reset_problem_globals {
1703: my ($type)=@_;
1704: undef(%Apache::lonhomework::history);
1705: undef(%Apache::lonhomework::results);
1706: undef($Apache::inputtags::part);
1.536 raeburn 1707: undef($Apache::inputtags::leniency);
1.498 raeburn 1708: if ($type eq 'Task') {
1709: undef($Apache::inputtags::slot_name);
1.528 raeburn 1710: } elsif ($type eq 'problem') {
1711: undef($Apache::lonhomework::rawrndseed);
1.498 raeburn 1712: }
1.208 albertel 1713: #don't undef this, lonhomework.pm takes care of this, we use this to
1714: #detect if we try to do 2 problems in one file
1715: # undef($Apache::lonhomework::parsing_a_problem);
1.204 albertel 1716: undef($Apache::lonhomework::name);
1.358 albertel 1717: undef($Apache::lonhomework::default_type);
1718: undef($Apache::lonhomework::type);
1719: undef($Apache::lonhomework::scantronmode);
1.566 raeburn 1720: undef($Apache::inputtags::randomizetrypart);
1.358 albertel 1721: undef($Apache::lonhomework::ignore_response_errors);
1.477 www 1722: undef(@Apache::functionplotresponse::callscripts);
1.405 albertel 1723: &Apache::lonhomework::reset_show_problem_status();
1.204 albertel 1724: }
1725:
1.241 albertel 1726: sub set_problem_state {
1.240 albertel 1727: my ($part)=@_;
1.284 albertel 1728: if ($env{'form.problemstate'} eq 'CANNOT_ANSWER_correct') {
1.240 albertel 1729: $Apache::lonhomework::history{"resource.$part.solved"}=
1730: 'correct_by_student';
1731: }
1732: }
1733:
1.241 albertel 1734: sub get_problem_status {
1735: my ($part)=@_;
1.267 albertel 1736: my $problem_status;
1.284 albertel 1737: if ($env{'request.state'} eq 'construct' &&
1738: defined($env{'form.problemstatus'})) {
1739: $problem_status=$env{'form.problemstatus'};
1.267 albertel 1740: } else {
1741: $problem_status=&Apache::lonnet::EXT("resource.$part.problemstatus");
1742: &Apache::lonxml::debug("problem status for $part is $problem_status");
1.284 albertel 1743: &Apache::lonxml::debug("env probstat is ".$env{'form.problemstatus'});
1.241 albertel 1744: }
1745: return $problem_status;
1746: }
1747:
1.9 albertel 1748: sub start_problem {
1.326 albertel 1749: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.19 albertel 1750:
1.311 foxr 1751: # We'll use the redirection to fix up printing of duedates.
1.321 albertel 1752: if (!$Apache::lonxml::metamode) {
1753: &Apache::lonxml::startredirection();
1754: }
1.311 foxr 1755:
1.308 foxr 1756: # Problems don't nest and we don't allow more than one <problem> in
1757: # a .problem file.
1758: #
1.184 albertel 1759: if ( $Apache::inputtags::part ne '' ||
1760: $Apache::lonhomework::parsing_a_problem) {
1761: &Apache::lonxml::error('Only one <problem> allowed in a .problem file');
1.326 albertel 1762: #my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,$style);
1.159 albertel 1763: return '';
1764: }
1.184 albertel 1765:
1766: $Apache::lonhomework::parsing_a_problem=1;
1.204 albertel 1767: &init_problem_globals('problem');
1.166 albertel 1768:
1.284 albertel 1769: if (defined($env{'scantron.maxquest'})) {
1.166 albertel 1770: $Apache::lonhomework::scantronmode=1;
1771: }
1.161 albertel 1772:
1.159 albertel 1773: if ($target ne 'analyze') {
1.415 raeburn 1774: my $type = &Apache::lonnet::EXT('resource.0.type');
1775: $Apache::lonhomework::type=$type;
1.284 albertel 1776: if (($env{'request.state'} eq 'construct') &&
1.410 albertel 1777: $env{'form.problemtype'} =~ /\S/) {
1.284 albertel 1778: $Apache::lonhomework::type=$env{'form.problemtype'};
1.237 albertel 1779: }
1.332 albertel 1780: &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:");
1.159 albertel 1781: }
1.164 albertel 1782: if ($Apache::lonhomework::type eq '' ) {
1.284 albertel 1783: my $uri=$env{'request.uri'};
1.159 albertel 1784: if ($uri=~/\.(\w+)$/) {
1785: $Apache::lonhomework::type=$1;
1786: &Apache::lonxml::debug("Using type of $1");
1787: } else {
1788: $Apache::lonhomework::type='problem';
1789: &Apache::lonxml::debug("Using default type, problem, :$uri:");
1790: }
1.87 albertel 1791: }
1.301 albertel 1792: $Apache::lonhomework::default_type = $Apache::lonhomework::type;
1.58 www 1793:
1.363 albertel 1794: &initialize_storage();
1.389 albertel 1795: if ($target ne 'analyze'
1796: && $env{'request.state'} eq 'construct') {
1797: &set_problem_state('0');
1798: }
1799:
1.366 albertel 1800: if ($target eq 'web') {
1801: &Apache::lonxml::debug(" grading history ");
1802: &Apache::lonhomework::showhash(%Apache::lonhomework::history);
1803: }
1.363 albertel 1804:
1.159 albertel 1805: #added vars to the scripting enviroment
1.213 albertel 1806: my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
1.248 albertel 1807: $expression.='$external::type=\''.$Apache::lonhomework::type.'\';';
1.24 albertel 1808: &Apache::run::run($expression,$safeeval);
1.159 albertel 1809: my $status;
1810: my $accessmsg;
1.508 raeburn 1811: my $resource_due;
1.540 raeburn 1812: my $ipused;
1.159 albertel 1813:
1.343 albertel 1814: my $name= &get_resource_name($parstack,$safeeval);
1.561 raeburn 1815: my ($result,$form_tag_start,$slot_name,$slot,$probpartlist,$firstaccres);
1.506 raeburn 1816:
1817: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1818: $target eq 'tex') {
1819: if ($env{'form.markaccess'}) {
1820: my @interval=&Apache::lonnet::EXT("resource.0.interval");
1.539 raeburn 1821: my ($timelimit) = split(/_/,$interval[0]);
1.561 raeburn 1822: my $is_set = &Apache::lonnet::set_first_access($interval[1],$timelimit);
1823: unless (($is_set eq 'ok') || ($is_set eq 'already_set')) {
1824: $firstaccres = $is_set;
1825: }
1.506 raeburn 1826: }
1827: }
1828:
1.354 albertel 1829: if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex'
1830: || $target eq 'edit') {
1.528 raeburn 1831: ($result,$form_tag_start,$probpartlist) =
1.350 albertel 1832: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
1833: $name);
1.552 raeburn 1834: } elsif ((($target eq 'grade') && ($Apache::lonhomework::type eq 'randomizetry')) ||
1835: ($target eq 'answer')) {
1.528 raeburn 1836: my ($symb)= &Apache::lonnet::whichuser();
1.568 raeburn 1837: if ($symb ne '') {
1838: my $navmap = Apache::lonnavmaps::navmap->new();
1839: if (ref($navmap)) {
1840: my $res = $navmap->getBySymb($symb);
1841: if (ref($res)) {
1842: $probpartlist = $res->parts();
1843: }
1.528 raeburn 1844: }
1845: }
1.350 albertel 1846: }
1847:
1.552 raeburn 1848: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1849: $target eq 'tex') {
1850:
1851: my ($symb)= &Apache::lonnet::whichuser();
1852: ($status,$accessmsg,$slot_name,$slot,$ipused) =
1853: &Apache::lonhomework::check_slot_access('0','problem',$symb,$probpartlist);
1854: push (@Apache::inputtags::status,$status);
1855: }
1856:
1.284 albertel 1857: if ($target eq 'tex' and $env{'request.symb'} =~ m/\.page_/) {$result='';}
1.159 albertel 1858:
1.479 raeburn 1859: if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval,$target); }
1.159 albertel 1860: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1861: $target eq 'tex') {
1.479 raeburn 1862:
1.568 raeburn 1863: my ($symb) = &Apache::lonnet::whichuser();
1.159 albertel 1864: #handle rand seed in construction space
1.568 raeburn 1865: if (($env{'request.state'} eq 'construct') || ($symb eq '')) {
1866: my $partorder=&Apache::lonnet::metadata($env{'request.uri'},'partorder');
1867: if ($partorder ne '') {
1868: @{$probpartlist} = split(/,/,$partorder);
1869: }
1870: }
1.528 raeburn 1871: my $rndseed=&setup_rndseed($safeeval,$target,$probpartlist);
1872: if (($target eq 'grade') && &Apache::response::submitted()) {
1873: if ($Apache::lonhomework::type eq 'randomizetry') {
1.529 raeburn 1874: $Apache::lonhomework::results{'resource.0.rndseed'}=$rndseed;
1.528 raeburn 1875: } else {
1876: my @parts;
1877: if (ref($probpartlist) eq 'ARRAY') {
1878: @parts = @{$probpartlist};
1879: }
1880: unless (@parts) {
1.529 raeburn 1881: $Apache::lonhomework::results{'resource.0.rndseed'}=$Apache::lonhomework::rawrndseed;
1.528 raeburn 1882: }
1883: }
1884: }
1.479 raeburn 1885:
1.333 albertel 1886: if ($env{'request.state'} ne "construct" &&
1887: ($symb eq '' || $Apache::lonhomework::type eq 'practice')) {
1.565 raeburn 1888: my $rndseedval = $rndseed;
1889: if (($symb eq '') && ($Apache::lonhomework::type eq 'randomizetry')) {
1890: $rndseedval = $env{'form.rndseed'};
1891: }
1.162 albertel 1892: $form_tag_start.='<input type="hidden" name="rndseed" value="'.
1.565 raeburn 1893: $rndseedval.'" />'.
1.551 damieng 1894: '<button type="submit" name="resetdata"
1895: value="new_problem_variation">'.&mt('New Problem Variation').'</button>';
1.334 albertel 1896: if (exists($env{'form.username'})) {
1897: $form_tag_start.=
1.164 albertel 1898: '<input type="hidden" name="username"
1.284 albertel 1899: value="'.$env{'form.username'}.'" />';
1.334 albertel 1900: }
1.462 raeburn 1901: if ($env{'request.role.adv'}) {
1902: $form_tag_start.= ' <label class="LC_nobreak">'
1903: .'<input type="checkbox" name="showallfoils"';
1904: if (defined($env{'form.showallfoils'})) {
1905: $form_tag_start.=' checked="checked"';
1906: }
1907: $form_tag_start.= ' /> '
1908: .&mt('Show All Foils')
1909: .'</label>';
1910: }
1.417 www 1911: if ($Apache::lonhomework::type eq 'practice') {
1.428 raeburn 1912: $form_tag_start.=&practice_problem_header();
1.417 www 1913: }
1.462 raeburn 1914: $form_tag_start.='<hr />';
1.570 raeburn 1915: }
1.565 raeburn 1916: if (($env{'request.state'} ne "construct") &&
1917: ($Apache::lonhomework::type eq 'randomizetry') &&
1918: ($status eq 'CAN_ANSWER') &&
1919: ($env{'course.'.$env{'request.course.id'}.'.type'} ne 'Placement') &&
1920: (!$env{'request.role.adv'})) {
1.549 raeburn 1921: # "New Problem Variation Each Try" header suppressed for Placement Tests, unless course personnel.
1.566 raeburn 1922: my @parts;
1923: if (ref($probpartlist) eq 'ARRAY') {
1924: @parts = @{$probpartlist};
1925: }
1926: unless (@parts) {
1927: my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
1928: my $problemstatus = &get_problem_status($Apache::inputtags::part);
1929: $form_tag_start.=&randomizetry_problem_header($problemstatus,$reqtries,$symb);
1930: }
1.479 raeburn 1931: }
1.324 albertel 1932:
1.159 albertel 1933: my $expression='$external::datestatus="'.$status.'";';
1934: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
1935: &Apache::run::run($expression,$safeeval);
1936: &Apache::lonxml::debug("Got $status");
1.324 albertel 1937:
1.159 albertel 1938: if (( $status eq 'CLOSED' ) ||
1939: ( $status eq 'UNCHECKEDOUT') ||
1.252 albertel 1940: ( $status eq 'NOT_YET_VIEWED') ||
1.159 albertel 1941: ( $status eq 'BANNED') ||
1.216 albertel 1942: ( $status eq 'UNAVAILABLE') ||
1.324 albertel 1943: ( $status eq 'NOT_IN_A_SLOT') ||
1.499 raeburn 1944: ( $status eq 'NOTRESERVABLE') ||
1945: ( $status eq 'RESERVABLE') ||
1946: ( $status eq 'RESERVABLE_LATER') ||
1.540 raeburn 1947: ( $status eq 'INVALID_ACCESS') ||
1948: ( $status eq 'NEED_DIFFERENT_IP')) {
1.326 albertel 1949: my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,
1950: $style);
1.561 raeburn 1951: if (($status eq 'NOT_YET_VIEWED') && ($firstaccres)) {
1952: $result .= '<p class="LC_error">'.
1953: &mt('A problem occurred when trying to start the timer.').'</p>';
1954: }
1.557 raeburn 1955: $result .= &access_status_msg('problem',$status,$symb,$target,$ipused,$accessmsg);
1.324 albertel 1956: } elsif ($status eq 'NEEDS_CHECKIN') {
1.326 albertel 1957: my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,
1958: $style);
1.557 raeburn 1959: $result .= &checkin_prompt($target,$slot_name,$slot,'problem');
1.159 albertel 1960: } elsif ($target eq 'web') {
1.508 raeburn 1961: if ($status eq 'CAN_ANSWER') {
1962: $resource_due = &Apache::lonhomework::due_date(0, $env{'request.symb'});
1963: if ($slot_name ne '') {
1.557 raeburn 1964: $resource_due = &selfcheckin_resource($resource_due,$slot_name,$slot,
1965: $env{'request.symb'});
1.508 raeburn 1966: }
1967: if ($resource_due) {
1968: my $time_left = $resource_due - time();
1969: if ($resource_due && ($time_left > 0) && ($target eq 'web')) {
1970: $result .= &Apache::lonhtmlcommon::set_due_date($resource_due);
1971: }
1972: }
1973: }
1.368 albertel 1974: $result.="\n $form_tag_start \t".
1.227 albertel 1975: '<input type="hidden" name="submitted" value="yes" />';
1976: # create a page header and exit
1.284 albertel 1977: if ($env{'request.state'} eq "construct") {
1.544 damieng 1978: if ($env{'form.inhibitmenu'} eq 'yes') {
1979: # error messages can be useful in any case
1980: $result.= &Apache::lonxml::message_location();
1981: } else {
1.542 raeburn 1982: $result.= &problem_web_to_edit_header($env{'form.rndseed'});
1983: }
1.428 raeburn 1984: if ($Apache::lonhomework::type eq 'practice') {
1.551 damieng 1985: $result.= '<button type="submit" name="resetdata" '.
1986: 'value="new_problem_variation">'.&mt('New Problem Variation').'</button>'.
1987: &practice_problem_header().'<hr />';
1.564 raeburn 1988: } elsif ($Apache::lonhomework::type eq 'randomizetry') {
1989: my $reqtries = &Apache::lonnet::EXT("resource.$Apache::inputtags::part.randomizeontries");
1990: my $problemstatus = &get_problem_status($Apache::inputtags::part);
1991: $result.=&randomizetry_problem_header($problemstatus,$reqtries);
1.428 raeburn 1992: }
1.227 albertel 1993: }
1994: # if we are viewing someone else preserve that info
1.284 albertel 1995: if (defined $env{'form.grade_symb'}) {
1.227 albertel 1996: foreach my $field ('symb','courseid','domain','username') {
1997: $result .= '<input type="hidden" name="grade_'.$field.
1.284 albertel 1998: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
1.159 albertel 1999: }
1.479 raeburn 2000: foreach my $field ('trial','questiontype') {
2001: if ($env{"form.grade_$field"} ne '') {
2002: $result .= '<input type="hidden" name="grade_'.$field.
2003: '" value="'.$env{"form.grade_$field"}.'" />'."\n";
2004: }
2005: }
1.159 albertel 2006: }
1.490 raeburn 2007: if ($env{'form.grade_imsexport'}) {
2008: $result = '';
2009: }
1.159 albertel 2010: } elsif ($target eq 'tex') {
1.319 foxr 2011: $result .= 'INSERTTEXFRONTMATTERHERE';
1.500 foxr 2012: $result .= &select_metadata_hyphenation();
1.99 sakharuk 2013: }
1.159 albertel 2014: } elsif ($target eq 'edit') {
1.343 albertel 2015: $result .= $form_tag_start.&problem_edit_header();
1.226 albertel 2016: $Apache::lonxml::warnings_error_header=
2017: &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 2018: my $temp=&Apache::edit::insertlist($target,$token);
2019: $result.=$temp;
2020: } elsif ($target eq 'modified') {
2021: $result=$token->[4];
2022: } else {
2023: # page_start returned a starting result, delete it if we don't need it
2024: $result = '';
1.99 sakharuk 2025: }
1.159 albertel 2026: return $result;
1.9 albertel 2027: }
2028:
2029: sub end_problem {
1.159 albertel 2030: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.321 albertel 2031: my $result;
1.310 foxr 2032:
1.321 albertel 2033: if (!$Apache::lonxml::metamode) {
2034: $result = &Apache::lonxml::endredirection(); #started in &start_problem
1.329 albertel 2035: $Apache::lonxml::post_evaluate=0;
1.321 albertel 2036: }
1.319 foxr 2037:
2038: if ($target eq 'tex') {
1.321 albertel 2039: # Figure out the front matter and replace the
2040: # INSERTTEXFRONTMATTERHERE in result with it. note that we do
2041: # this in end_problem because whether or not we display due
2042: # dates depends on whether due dates have already been
2043: # displayed in the problem parts.
2044:
1.319 foxr 2045: my $frontmatter = '';
2046: my $startminipage = '';
2047: if (not $env{'form.problem_split'}=~/yes/) {
2048: $startminipage = '\begin{minipage}{\textwidth}';
2049: }
2050: my $id = $Apache::inputtags::part;
2051: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
2052: my $packages=&Apache::lonnet::metadata($env{'request.uri'},'packages');
1.526 raeburn 2053: my @packages = split(/,/,$packages);
1.319 foxr 2054: my $allow_print_points = 0;
2055: foreach my $partial_key (@packages) {
2056: if ($partial_key=~m/^part_0$/) {
2057: $allow_print_points=1;
2058: }
2059: }
2060: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
2061: if (defined($maxtries) && $maxtries < 0) { $allow_print_points=0; }
2062: if (lc($env{'course.'.$env{'request.course.id'}.
2063: '.disableexampointprint'}) eq 'yes') {
2064: $allow_print_points=0;
2065: }
2066: my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header');
1.443 foxr 2067: 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.500 foxr 2068: &clear_required_languages();
1.319 foxr 2069: my $toc_line='\vskip 1 mm\noindent '.$startminipage.
2070: '\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}';
2071:
2072: # Figure out what the due date is and if we need to print
2073: # it in the problem header. We have been logging the
2074: # last due date written to file.
2075:
2076: my $duetime = &Apache::lonnet::EXT("resource.$id.duedate");
2077: my $duedate = POSIX::strftime("%c",localtime($duetime));
1.448 bisitz 2078: my $duedate_text = &mt('Due date: [_1]'
2079: ,&Apache::lonlocal::locallocaltime($duetime));
1.319 foxr 2080: my $temp_file;
2081: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due";
2082:
2083: # Figure out what the last printed due date is or set it
2084: # to the epoch if no duedates have been printed.
2085:
2086: my $due_file_content = 0; # If the file does not yet exist, time is the epoch.
2087: if (-e $filename) {
2088: $temp_file = Apache::File->new($filename);
2089: my @due_file = <$temp_file>;
2090: $due_file_content = $due_file[$#due_file];
2091: chomp $due_file_content;
2092: }
2093:
2094: # We display the due date iff it is not the same as the last
2095: # duedate in problem header ($due_file_content), and
2096: # none of our parts displayed a duedate.
2097: #
2098: my $parts_with_displayduedate;
2099: if (defined $Apache::outputtags::showonce{'displayduedate'}) {
2100: $parts_with_displayduedate =
2101: scalar(@{$Apache::outputtags::showonce{'displayduedate'}});
2102: } else {
2103: $parts_with_displayduedate = 0;
2104: }
2105: if (($due_file_content != $duetime) && ($parts_with_displayduedate == 0) ) {
2106: $temp_file = Apache::File->new('>'.$filename);
2107: print $temp_file "$duetime\n";
2108: if (not $env{'request.symb'} =~ m/\.page_/) {
2109: if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') {
2110: $frontmatter .= $begin_doc.
1.448 bisitz 2111: '\textit{'.$duedate_text.'} '.$toc_line;
1.319 foxr 2112: } else {
2113: $frontmatter.= $begin_doc.$toc_line;
1.463 foxr 2114: if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) {
1.492 christia 2115: $frontmatter .= '\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}';
1.463 foxr 2116: }
1.319 foxr 2117: }
2118: } else {
1.448 bisitz 2119: $frontmatter .= '\vskip 1mm\textit{'.$duedate_text.'} \\\\\\\\'.$startminipage;
1.319 foxr 2120: }
2121: } else {
2122: if (not $env{'request.symb'} =~ m/\.page_/) {
2123: $frontmatter .= $begin_doc.$toc_line;
1.463 foxr 2124: if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) {
1.492 christia 2125: $frontmatter .= '\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}';
1.463 foxr 2126: }
1.319 foxr 2127: } else {
1.381 albertel 2128: $frontmatter .= '\vskip 1mm \\\\\\\\'.$startminipage;
1.319 foxr 2129: }
2130: }
2131: $result =~ s/INSERTTEXFRONTMATTERHERE/$frontmatter/;
2132: }
2133:
1.159 albertel 2134: my $status=$Apache::inputtags::status['-1'];
2135: if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
2136: $target eq 'tex') {
1.249 albertel 2137: if ( $target eq 'grade' && $Apache::inputtags::part eq '0') {
1.159 albertel 2138: # if part is zero, no <part>s existed, so we need to the grading
1.249 albertel 2139: if ($status eq 'CAN_ANSWER' ||$Apache::lonhomework::scantronmode) {
2140: &Apache::inputtags::grade;
1.324 albertel 2141: } elsif ($status eq 'NEEDS_CHECKIN') {
2142: # no need to grade, and don't want to hide data
1.249 albertel 2143: } else {
2144: # move any submission data to .hidden
2145: &Apache::inputtags::hidealldata($Apache::inputtags::part);
2146: }
1.159 albertel 2147: } elsif ( ($target eq 'web' || $target eq 'tex') &&
2148: $Apache::inputtags::part eq '0' &&
1.490 raeburn 2149: $status ne 'UNCHECKEDOUT' && $status ne 'NOT_YET_VIEWED'
2150: && !$env{'form.grade_imsexport'}) {
1.159 albertel 2151: # if part is zero, no <part>s existed, so we need show the current
2152: # grading status
2153: my $gradestatus = &Apache::inputtags::gradestatus($Apache::inputtags::part,$target);
2154: $result.= $gradestatus;
2155: }
2156: if (
1.284 albertel 2157: (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
1.159 albertel 2158: ($target eq 'answer') || ($target eq 'tex')
2159: ) {
1.490 raeburn 2160: if (($target ne 'tex') &&
2161: ($env{'form.answer_output_mode'} ne 'tex') &&
2162: (!$env{'form.grade_imsexport'})) {
1.254 www 2163: $result.="</form>";
1.159 albertel 2164: }
2165: if ($target eq 'web') {
1.507 raeburn 2166: #
2167: # Closing </body></html> not added by end_page().
2168: # Added separately at end of this routine, after added
2169: # <script></script> so document will be valid xhtml.
2170: #
1.546 raeburn 2171: my $showdisc = 1;
1.547 raeburn 2172: if (($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement') &&
2173: (!$env{'request.role.adv'})) {
2174: # For Placement Tests footer with "Post Discussion" and "Send Feedback" links is suppressed.
1.546 raeburn 2175: $showdisc = 0;
1.547 raeburn 2176: my ($symb)= &Apache::lonnet::whichuser();
2177: if ($symb) {
2178: my $navmap = Apache::lonnavmaps::navmap->new();
2179: if (ref($navmap)) {
2180: my $hastries = &Apache::lonplacementtest::has_tries($symb,$navmap);
2181: # For Placement Tests test status is displayed if this is the last resource in the course
1.549 raeburn 2182: # and there are no tries left
1.547 raeburn 2183: unless ($hastries) {
2184: if (&Apache::lonplacementtest::is_lastres($symb,$navmap)) {
2185: my ($score,$incomplete) =
2186: &Apache::lonplacementtest::check_completion(undef,undef,1);
2187: if (!$incomplete) {
2188: $result .= &Apache::lonplacementtest::showresult(1,1);
2189: } elsif ($incomplete < 100) {
2190: $result.= &Apache::lonplacementtest::showincomplete($incomplete,1);
2191: }
2192: } else {
2193: # For Placement Tests score is displayed if test has just been completed
2194: my ($score,$incomplete) = &Apache::lonplacementtest::check_completion(undef,undef,1);
2195: if (!$incomplete) {
2196: $result.= &Apache::lonplacementtest::showresult(1,1);
2197: }
2198: }
2199: }
2200: }
2201: }
1.546 raeburn 2202: }
2203: $result.= &Apache::loncommon::end_page({'discussion' => $showdisc,
1.507 raeburn 2204: 'notbody' => 1});
1.159 albertel 2205: } elsif ($target eq 'tex') {
1.178 sakharuk 2206: my $endminipage = '';
1.284 albertel 2207: if (not $env{'form.problem_split'}=~/yes/) {
1.178 sakharuk 2208: $endminipage = '\end{minipage}';
2209: }
1.284 albertel 2210: if ($env{'form.print_discussions'} eq 'yes') {
1.263 sakharuk 2211: $result.=&Apache::lonxml::xmlend($target,$parser);
1.159 albertel 2212: } else {
1.262 sakharuk 2213: $result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}';
1.284 albertel 2214: if (not $env{'request.symb'} =~ m/\.page_/) {
1.262 sakharuk 2215: $result .= $endminipage.'\end{document} ';
2216: } else {
1.382 albertel 2217: $result .= $endminipage;
1.262 sakharuk 2218: }
1.159 albertel 2219: }
2220: }
2221: }
1.476 www 2222: if ($target eq 'web') {
1.566 raeburn 2223: $result.=&Apache::functionplotresponse::init_script();
2224: if ($Apache::lonhomework::default_type eq 'randomizetry') {
2225: my ($symb) = &Apache::lonnet::whichuser();
2226: if ((($env{'request.state'} eq 'construct') || ($symb eq '')) &&
2227: ($status eq 'CAN_ANSWER')) {
2228: unless (@Apache::inputtags::partlist > 1) {
2229: $result.= <<"ENDJS";
2230: <script type="text/javascript">
2231: // <![CDATA[
2232: \$(document).ready(function() {
2233: \$('#LC_randomizetry_header').css('display','block');
2234: });
2235: // ]]>
2236: </script>
2237: ENDJS
2238: }
2239: }
2240: }
1.476 www 2241: }
1.159 albertel 2242: if ($target eq 'grade') {
2243: &Apache::lonhomework::showhash(%Apache::lonhomework::results);
2244: &finalize_storage();
2245: }
1.284 albertel 2246: if ($target eq 'answer' && ($env{'request.state'} eq 'construct')
2247: && $env{'form.answer_output_mode'} ne 'tex') {
1.346 albertel 2248: $result.=&Apache::loncommon::end_page({'discussion' => 1});
1.294 albertel 2249: # normally we get it from above, but in CSTR
1.172 albertel 2250: # we always show answer mode too.
1.159 albertel 2251: }
2252: } elsif ($target eq 'meta') {
2253: if ($Apache::inputtags::part eq '0') {
1.179 albertel 2254: @Apache::inputtags::response=();
1.159 albertel 2255: $result=&Apache::response::mandatory_part_meta;
2256: }
1.559 raeburn 2257: $result.=&Apache::response::meta_part_order('problem');
1.258 albertel 2258: $result.=&Apache::response::meta_response_order();
1.159 albertel 2259: } elsif ($target eq 'edit') {
2260: &Apache::lonxml::debug("in end_problem with $target, edit");
1.314 albertel 2261: $result .= &problem_edit_footer();
1.320 albertel 2262: } elsif ($target eq 'modified') {
2263: $result .= $token->[2];
1.159 albertel 2264: }
1.155 albertel 2265:
1.284 albertel 2266: if ($env{'request.state'} eq 'construct' && $target eq 'web') {
1.177 albertel 2267: &Apache::inputtags::check_for_duplicate_ids();
2268: }
1.204 albertel 2269:
2270: &reset_problem_globals('problem');
1.159 albertel 2271:
1.502 foxr 2272: #
2273: # This shouild be just above the return so that the
2274: # time put in the javascript is as late as possible in the
2275: # computation:
2276: #
2277: if ($target eq 'web') {
2278: $result .= &Apache::lonhtmlcommon::set_compute_end_time();
1.507 raeburn 2279: #
2280: # Closing tags delayed so any <script></script> tags
2281: # not in head can appear inside body, for valid xhtml.
2282: #
2283: $result .= "</body>\n</html>";
1.502 foxr 2284: }
1.159 albertel 2285: return $result;
1.48 albertel 2286: }
2287:
1.108 albertel 2288:
1.48 albertel 2289: sub start_library {
1.159 albertel 2290: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.343 albertel 2291: my ($result,$form_tag_start);
1.371 albertel 2292: if ($#$tagstack eq 0 && $$tagstack[0] eq 'library') {
1.244 albertel 2293: &init_problem_globals('library');
2294: $Apache::lonhomework::type='problem';
2295: }
1.159 albertel 2296: if ($target eq 'edit') {
1.343 albertel 2297: ($result,$form_tag_start)=
2298: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
2299: 'Edit');
2300: $result.=$form_tag_start.&problem_edit_header();
1.159 albertel 2301: my $temp=&Apache::edit::insertlist($target,$token);
2302: $result.=$temp;
2303: } elsif ($target eq 'modified') {
2304: $result=$token->[4];
1.340 albertel 2305: } elsif (($target eq 'web' || $target eq 'webgrade')
1.371 albertel 2306: && ($#$tagstack eq 0 && $$tagstack[0] eq 'library')
1.340 albertel 2307: && $env{'request.state'} eq "construct" ) {
1.159 albertel 2308: my $name=&get_resource_name($parstack,$safeeval);
1.343 albertel 2309: ($result,$form_tag_start)=
2310: &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval,
2311: $name);
1.479 raeburn 2312: my $rndseed=&setup_rndseed($safeeval,$target);
1.343 albertel 2313: $result.=" \n $form_tag_start".
1.159 albertel 2314: '<input type="hidden" name="submitted" value="yes" />';
2315: $result.=&problem_web_to_edit_header($rndseed);
1.428 raeburn 2316: if ($Apache::lonhomework::type eq 'practice') {
1.551 damieng 2317: $result.= '<button type="submit" name="resetdata" '.
2318: 'value="new_problem_variation">'.&mt('New Problem Variation').'</button>'.
2319: &practice_problem_header().'<hr />';
1.428 raeburn 2320: }
1.159 albertel 2321: }
2322: return $result;
1.48 albertel 2323: }
2324:
2325: sub end_library {
1.159 albertel 2326: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2327: my $result='';
2328: if ($target eq 'edit') {
2329: $result=&problem_edit_footer();
1.371 albertel 2330: } elsif ($target eq 'web'
2331: && ($#$tagstack eq 0 && $$tagstack[0] eq 'library')
2332: && $env{'request.state'} eq "construct") {
1.349 albertel 2333: $result.='</form>'.&Apache::loncommon::end_page({'discussion' => 1});
1.558 raeburn 2334: } elsif ($target eq 'meta') {
1.559 raeburn 2335: $result.=&Apache::response::meta_part_order('library');
1.558 raeburn 2336: $result.=&Apache::response::meta_response_order();
1.159 albertel 2337: }
1.371 albertel 2338: if ( $#$tagstack eq 0 && $$tagstack[0] eq 'library') {
2339: &reset_problem_globals('library');
2340: }
1.159 albertel 2341: return $result;
1.197 www 2342: }
2343:
2344: sub start_definetag {
1.326 albertel 2345: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.197 www 2346:
2347: my $result;
2348:
2349: my $name = $token->[2]->{'name'};
1.326 albertel 2350: my $skip=&Apache::lonxml::get_all_text("/definetag",$parser,$style);
1.396 albertel 2351: if ($target eq 'web') {
2352: if ($name=~/^\//) {
2353: $result=
2354: '<br /><table class="LC_sty_end"><tr><th>'.
2355: &mt('END [_1]'.'<tt>'.$name.'</tt>').'</th></tr>';
2356: } else {
2357: $result=
2358: '<br /><table class="LC_sty_begin"><tr><th>'.
2359: &mt('BEGIN [_1]'.'<tt>'.$name.'</tt>').'</th></tr>';
2360: }
2361: $skip = &HTML::Entities::encode($skip, '<>&"');
2362: $result.='<tr><td><pre>'.$skip.'</pre></td></tr></table>';
1.197 www 2363: }
2364: return $result;
2365: }
2366:
2367: sub end_definetag {
2368: return '';
1.1 albertel 2369: }
2370:
2371: sub start_block {
1.201 albertel 2372: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.131 albertel 2373:
2374: my $result;
1.1 albertel 2375:
1.339 albertel 2376: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2377: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.159 albertel 2378: my $code = $token->[2]->{'condition'};
1.385 albertel 2379: if (defined($code) && $code ne '') {
1.137 albertel 2380: if (!$Apache::lonxml::default_homework_loaded) {
2381: &Apache::lonxml::default_homework_load($safeeval);
2382: }
1.131 albertel 2383: $result = &Apache::run::run($code,$safeeval);
2384: &Apache::lonxml::debug("block :$code: returned :$result:");
2385: } else {
2386: $result='1';
2387: }
2388: if ( ! $result ) {
1.201 albertel 2389: my $skip=&Apache::lonxml::get_all_text("/block",$parser,$style);
1.131 albertel 2390: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
2391: }
2392: $result='';
2393: } elsif ($target eq 'edit') {
2394: $result .=&Apache::edit::tag_start($target,$token);
2395: $result .=&Apache::edit::text_arg('Test Condition:','condition',
2396: $token,40);
2397: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2398: } elsif ($target eq 'modified') {
2399: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
2400: $safeeval,'condition');
2401: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.38 albertel 2402: }
1.131 albertel 2403: return $result;
1.1 albertel 2404: }
2405:
2406: sub end_block {
1.167 www 2407: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2408: my $result;
2409: if ($target eq "edit") {
2410: $result.= &Apache::edit::tag_end($target,$token,'');
2411: }
2412: return $result;
2413: }
1.500 foxr 2414: #
2415: # <languageblock [include='lang1,lang2...'] [exclude='lang1,lang2...']>
2416: # ...
2417: # </languageblock>
2418: #
2419: # This declares the intent to provide content that can be rendered in the
2420: # set of languages in the include specificatino but not in the exclude
2421: # specification. If a currently preferred language is in the include list
2422: # the content in the <languageblock>...</languageblock> is rendered
2423: # If the currently preferred language is in the exclude list,
2424: # the content in the <languageblock>..></languageblock is not rendered.
2425: #
2426: # Pathalogical case handling:
2427: # - Include specified, without the preferred language but exclude specified
2428: # also without the preferred langauge results in rendering the block.
2429: # - Exclude specified without include and excluden not containing a
2430: # preferred language renders the block.
2431: # - Include and exclude both specifying the preferred language does not
2432: # render the block.
2433: # - If neither include/exclude is specified, the block gets rendered.
2434: #
2435: # This tag has no effect when target is in {edit, modified}
2436: #
1.167 www 2437: sub start_languageblock {
1.201 albertel 2438: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.167 www 2439:
1.500 foxr 2440: my $result = '';
1.167 www 2441:
1.339 albertel 2442: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2443: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.201 albertel 2444: my $include = $token->[2]->{'include'};
2445: my $exclude = $token->[2]->{'exclude'};
1.436 raeburn 2446: my @preferred_languages=&Apache::lonlocal::preferred_languages();
1.500 foxr 2447:
2448: # This should not even happen, since we should at least have the server language
2449:
2450: if (!$preferred_languages[0]) {
2451: $preferred_languages[0]='en';
2452: }
2453:
2454: # Now loop over all languages in order of preference
2455:
2456: my $render;
1.398 www 2457: foreach my $preferred_language (@preferred_languages) {
1.500 foxr 2458:
2459: # If neither include/nor exlude is present the block is going
2460: # to get rendered.
2461:
1.399 www 2462: my $found=0;
1.500 foxr 2463: $render=1;
2464:
2465: # If include is specified, don't render the block
2466: # unless the preferred language is included in the set.
2467:
1.398 www 2468: if ($include) {
1.500 foxr 2469: $render=0;
1.398 www 2470: foreach my $included_language (split(/\,/,$include)) {
2471: if ($included_language eq $preferred_language) {
1.500 foxr 2472: $render=1;
1.399 www 2473: $found=1;
1.500 foxr 2474: last; # Only need to find the first.
1.398 www 2475: }
2476: }
2477: }
1.500 foxr 2478: # Do we have an exclude argument?
2479: # If so, and one of the languages matches a preferred language
2480: # inhibit rendering the block. Note that in the pathalogical case the
2481: # author has specified a preferred language in both the include and exclude
2482: # attribte exclude is preferred.
2483:
1.398 www 2484: if ($exclude) {
1.500 foxr 2485: $render=1;
1.398 www 2486: foreach my $excluded_language (split(/\,/,$exclude)) {
2487: if ($excluded_language eq $preferred_language) {
1.500 foxr 2488: $render=0;
1.399 www 2489: $found=1;
1.500 foxr 2490: last; # Only need to find the first.
1.398 www 2491: }
2492: }
2493: }
1.500 foxr 2494: if ($found) {
2495: last; # Done on any match of include or exclude.
2496: }
1.398 www 2497: }
1.500 foxr 2498: # If $render not true skip the entire block until </languageblock>
2499: #
2500:
2501: if ( ! $render ) {
1.201 albertel 2502: my $skip=&Apache::lonxml::get_all_text("/languageblock",$parser,
2503: $style);
2504: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
2505: }
1.500 foxr 2506: # If $render is true, we've not skipped the contents of the <languageglock>
2507: # and the normal loncapa processing flow will render it as a matter of course.
2508:
1.167 www 2509: } elsif ($target eq 'edit') {
2510: $result .=&Apache::edit::tag_start($target,$token);
1.211 albertel 2511: $result .=&Apache::edit::text_arg(&mt('Include Language:'),'include',
1.167 www 2512: $token,40);
1.211 albertel 2513: $result .=&Apache::edit::text_arg(&mt('Exclude Language:'),'exclude',
1.167 www 2514: $token,40);
2515: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2516: } elsif ($target eq 'modified') {
2517: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.168 albertel 2518: $safeeval,'include',
2519: 'exclude');
1.167 www 2520: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
2521: }
2522: return $result;
2523: }
2524:
2525: sub end_languageblock {
1.170 www 2526: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2527: my $result;
1.201 albertel 2528: if ($target eq "edit") {
1.170 www 2529: $result.= &Apache::edit::tag_end($target,$token,'');
2530: }
2531: return $result;
2532: }
1.500 foxr 2533: # languagblock specific tags:
2534: {
2535: # For chunks of a resource that has translations, this hash contains
2536: # the translations available indexed by language name.
2537: #
2538:
2539: my %available_texts;
1.170 www 2540:
1.500 foxr 2541: # <translated> starts a block of a resource that has multiple translations.
2542: # See the <lang> tag as well.
2543: # When </translated> is encountered if there is a translation for the
2544: # currently preferred language, that is rendered inthe web/tex/webgrade
2545: # targets. Otherwise, the default text is rendered.
2546: #
2547: # Note that <lang> is only registered for the duration of the
2548: # <translated>...</translated> block
2549: #
2550: # Pathalogical case handling:
2551: # - If there is no <lang> that specifies a 'default' and there is no
2552: # translation that matches a preferred language, nothing is rendered.
2553: # - Nested <translated>...</translated> might be linguistically supported by
2554: # XML due to the stack nature of tag registration(?) however the rendered
2555: # output will be incorrect because there is only one %available_texts
2556: # has and end_translated clears it.
2557: # - Material outside of a <lang>...</lang> block within the
2558: # <translated>...<translated> block won't render either e.g.:
2559: # <translated>
2560: # The following will be in your preferred langauge:
2561: # <lang which='en'>
2562: # This section in english
2563: # </lang>
2564: # <lang which='sgeiso'>
2565: # Hier es ist auf Deutsch.
2566: # </lang>
2567: # <lang which='sfriso'>
2568: # En Francais
2569: # </lang>
2570: # </translated>
2571: #
2572: # The introductory text prior to the first <lang> tag is not rendered.
2573: #
1.397 albertel 2574: sub start_translated {
2575: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2576: &Apache::lonxml::register('Apache::structuretags',('lang'));
2577: undef(%available_texts);
2578: }
2579:
2580: sub end_translated {
2581: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2582: my $result;
2583: #show the translation on viewable targets
2584: if ($target eq 'web' || $target eq 'tex' || $target eq 'webgrade'||
2585: # or non-viewable targets, if it's embedded in something that
2586: # wants the output
2587: (($target eq 'answer' || $target eq 'analyze'|| $target eq 'grade')
2588: && &Apache::lonxml::in_redirection() ) ) {
2589: my @possibilities = keys(%available_texts);
2590: my $which =
2591: &Apache::loncommon::languages(\@possibilities) || 'default';
1.500 foxr 2592: if ($target eq 'tex') {
2593: $result = &select_hyphenation($which);
2594: }
2595: $result .= $available_texts{$which};
2596: if ($target eq 'tex') {
2597: $result .= &select_metadata_hyphenation(); # Restore original language.
2598: }
1.397 albertel 2599: }
2600: undef(%available_texts);
2601: &Apache::lonxml::deregister('Apache::structuretags',('lang'));
2602: return $result;
2603: }
2604:
1.500 foxr 2605: # <lang [which='language-name'] [other='lang1,lang2...']>
2606: # Specifies that the block contained within it is a translation
2607: # for a specific language specified by the 'which' attribute. The
2608: # 'other' attribute can be used by itself or in conjunction with
2609: # which to specify this tag _may_ be used as a translation for some
2610: # list of languages. e.g.: <lang which='senisoUS' other='senisoCA,senisoAU,seniso'>
2611: # specifying that the block provides a translation for US (primary)
2612: # Canadian, Australian and UK Englush.
2613: #
2614: # Comment: this seems a bit silly why not just support a list of languages
2615: # e.g. <lang which='l1,l2...'> and ditch the other attribute?
2616: #
2617: # Effect:
2618: # The material within the <lang>..</lang> block is stored in the
2619: # specified set of $available_texts hash entries, the appropriate one
2620: # is selected at </translated> time.
2621: #
2622: # Pathalogical case handling:
2623: # If a language occurs multiple times within a <translated> block,
2624: # only the last one is rendered e.g.:
2625: #
2626: # <translated>
2627: # <lang which='senisoUS', other='senisoCA,senisoAU,seniso'>
2628: # Red green color blindness is quite common affecting about 7.8% of
2629: # the male population, but onloy about .65% of the female population.
2630: # </lang>
2631: # Red green colour blindness is quite common affecting about 7.8% of
2632: # the male population, but onloy about .65% of the female population.
2633: # <lang which='seniso', other='senisoCA,senisoAU'>
2634: # </translated>
2635: #
2636: # renders the correct spelling of color (colour) for people who have specified
2637: # a preferred language that is one of the British Commonwealth languages
2638: # even though those are also listed as valid selections for the US english
2639: # <lang> block.
2640: #
1.397 albertel 2641: sub start_lang {
2642: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2643: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2644: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
2645: &Apache::lonxml::startredirection();
2646: }
2647: return '';
2648: }
2649:
2650: sub end_lang {
2651: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
2652: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2653: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
2654: my $result = &Apache::lonxml::endredirection();
2655: my $which = &Apache::lonxml::get_param('which',$parstack,
2656: $safeeval);
1.431 raeburn 2657: if ($which=~/\w/) {
2658: $available_texts{$which} = $result;
2659: }
2660: my $otherlangs = &Apache::lonxml::get_param('other',$parstack,
2661: $safeeval);
2662: foreach my $language (split(/\s*\,\s*/,$otherlangs)) {
2663: if ($language=~/\w/) {
2664: $available_texts{$language} = $result;
2665: }
1.427 bisitz 2666: }
2667:
1.397 albertel 2668: }
2669: return '';
2670: }
1.500 foxr 2671: } # end langauge block specific tags.
2672:
1.397 albertel 2673:
1.170 www 2674: sub start_instructorcomment {
1.201 albertel 2675: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.170 www 2676:
2677: my $result;
2678:
1.339 albertel 2679: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2680: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.468 raeburn 2681: $result=($env{'request.role'}=~/^(in|cc|co|au|ca|li)/);
1.284 albertel 2682: if ( (! $result) or ($env{'form.instructor_comments'} eq 'hide')) {
1.201 albertel 2683: my $skip=&Apache::lonxml::get_all_text("/instructorcomment",
2684: $parser,$style);
1.170 www 2685: &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]");
2686: }
2687: $result='';
2688: } elsif ($target eq 'edit') {
2689: $result .=&Apache::edit::tag_start($target,$token);
2690: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2691: }
2692: return $result;
2693: }
2694:
2695: sub end_instructorcomment {
1.159 albertel 2696: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 2697: my $result;
2698: if ($target eq "edit") {
2699: $result.= &Apache::edit::tag_end($target,$token,'');
2700: }
2701: return $result;
1.4 tsai 2702: }
2703:
2704: sub start_while {
1.326 albertel 2705: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 2706:
1.160 albertel 2707: my $result;
1.339 albertel 2708: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2709: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.160 albertel 2710: my $code = $token->[2]->{'condition'};
1.4 tsai 2711:
1.160 albertel 2712: push( @Apache::structuretags::whileconds, $code);
2713: if (!$Apache::lonxml::default_homework_loaded) {
2714: &Apache::lonxml::default_homework_load($safeeval);
2715: }
2716: my $result = &Apache::run::run($code,$safeeval);
1.326 albertel 2717: my $bodytext=&Apache::lonxml::get_all_text("/while",$parser,$style);
1.160 albertel 2718: push( @Apache::structuretags::whilebody, $bodytext);
1.161 albertel 2719: push( @Apache::structuretags::whileline, $token->[5]);
2720: &Apache::lonxml::debug("s code $code got -$result-");
1.160 albertel 2721: if ( $result ) {
2722: &Apache::lonxml::newparser($parser,\$bodytext);
2723: }
2724: } elsif ($target eq 'edit') {
2725: $result .=&Apache::edit::tag_start($target,$token);
1.211 albertel 2726: $result .=&Apache::edit::text_arg(&mt('Test Condition:'),'condition',
1.160 albertel 2727: $token,40);
2728: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2729: } elsif ($target eq 'modified') {
2730: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
2731: $safeeval,'condition');
2732: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
1.159 albertel 2733: }
1.160 albertel 2734: return $result;
1.4 tsai 2735: }
2736:
2737: sub end_while {
1.159 albertel 2738: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.160 albertel 2739: my $result;
2740:
1.339 albertel 2741: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
2742: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.160 albertel 2743: my $code = pop(@Apache::structuretags::whileconds);
2744: my $bodytext = pop(@Apache::structuretags::whilebody);
1.161 albertel 2745: my $line = pop(@Apache::structuretags::whileline);
2746: my $return = &Apache::run::run($code,$safeeval);
2747: my $starttime=time;
2748: my $error=0;
2749: while ($return) {
2750: if (time-$starttime >
2751: $Apache::lonnet::perlvar{'lonScriptTimeout'}) {
1.378 albertel 2752: $return = 0; $error=1; next;
1.161 albertel 2753: }
2754: $result.=&Apache::scripttag::xmlparse($bodytext);
1.380 albertel 2755: if ($target eq 'grade' || $target eq 'answer' ||
2756: $target eq 'analyze') {
2757: # grade/answer/analyze should produce no output but if we
2758: # are redirecting, the redirecter should know what to do
2759: # with the output
2760: if (!$Apache::lonxml::redirection) { undef($result); }
2761: }
1.161 albertel 2762: $return = &Apache::run::run($code,$safeeval);
2763: }
1.516 bisitz 2764: if ($error) {
2765: &Apache::lonxml::error(
2766: '<pre>'
2767: .&mt('Code ran too long. It ran for more than [_1] seconds.',
2768: $Apache::lonnet::perlvar{'lonScriptTimeout'})
2769: .&mt('This occurred while running <while> on line [_1].',
2770: $line)
2771: .'</pre>');
2772: }
1.160 albertel 2773: } elsif ($target eq "edit") {
2774: $result.= &Apache::edit::tag_end($target,$token,'');
1.159 albertel 2775: }
1.160 albertel 2776: return $result;
1.1 albertel 2777: }
1.6 tsai 2778:
1.160 albertel 2779: # <randomlist show="1">
1.6 tsai 2780: # <tag1>..</tag1>
2781: # <tag2>..</tag2>
2782: # <tag3>..</tag3>
1.160 albertel 2783: # ...
1.6 tsai 2784: # </randomlist>
2785: sub start_randomlist {
1.326 albertel 2786: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 2787: my $result;
1.339 albertel 2788: if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' ||
2789: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.331 albertel 2790: my $body= &Apache::lonxml::get_all_text("/randomlist",$parser);
1.305 albertel 2791: my $b_parser= HTML::LCParser->new(\$body);
2792: $b_parser->xml_mode(1);
2793: $b_parser->marked_sections(1);
1.159 albertel 2794: my $b_tok;
2795: my @randomlist;
2796: my $list_item;
2797: while($b_tok = $b_parser->get_token() ) {
2798: if($b_tok->[0] eq 'S') { # start tag
2799: # get content of the tag until matching end tag
2800: # get all text upto the matching tag
2801: # and push the content into @randomlist
2802: $list_item = &Apache::lonxml::get_all_text('/'.$b_tok->[1],
2803: $b_parser);
2804: $list_item = "$b_tok->[4]"."$list_item"."</$b_tok->[1]>";
2805: push(@randomlist,$list_item);
2806: # print "<br /><b>START-TAG $b_tok->[1], $b_tok->[4],
2807: # $list_item</b>";
2808: }
2809: if($b_tok->[0] eq 'T') { # text
2810: # what to do with text in between tags?
2811: # print "<b>TEXT $b_tok->[1]</b><br />";
2812: }
2813: # if($b_tok->[0] eq 'E') { # end tag, should not happen
2814: # print "<b>END-TAG $b_tok->[1]</b><br />";
2815: # }
2816: }
1.303 albertel 2817: if (@randomlist) {
2818: my @idx_arr = (0 .. $#randomlist);
1.555 raeburn 2819: if ($env{'form.code_for_randomlist'}) {
2820: &Apache::structuretags::shuffle(\@idx_arr,$target);
2821: undef($env{'form.code_for_randomlist'});
2822: } else {
2823: &Apache::structuretags::shuffle(\@idx_arr);
2824: }
1.303 albertel 2825: my $bodytext = '';
2826: my $show=$#randomlist;
2827: my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval);
2828: $showarg--;
2829: if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; }
1.439 raeburn 2830: if (($target eq 'analyze') && ($env{'form.check_parts_withrandomlist'})) {
2831: my @currlist;
2832: my $part = $Apache::inputtags::part;
2833: if ($part ne '') {
2834: if (ref($Apache::lonhomework::analyze{'parts_withrandomlist'}) eq 'ARRAY') {
2835: my @currlist = @{$Apache::lonhomework::analyze{'parts_withrandomlist'}};
2836: if (!(grep(/^\Q$part\E$/,@currlist))) {
2837: push(@{$Apache::lonhomework::analyze{'parts_withrandomlist'}},$part);
2838: }
2839: } else {
2840: push(@{$Apache::lonhomework::analyze{'parts_withrandomlist'}},$part);
2841: }
2842: }
2843: }
1.526 raeburn 2844: for my $i (0 .. $show) {
2845: $bodytext .= "$randomlist[ $idx_arr[$i] ]";
1.303 albertel 2846: }
2847: &Apache::lonxml::newparser($parser,\$bodytext);
1.159 albertel 2848: }
2849: } elsif ($target eq 'edit' ) {
2850: $result .=&Apache::edit::tag_start($target,$token);
2851: $result .=&Apache::edit::text_arg('Maximum Tags to Show:','show',
2852: $token,5);
2853: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2854: } elsif ($target eq 'modified' ) {
2855: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
2856: $safeeval,'show');
2857: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
2858: }
2859: return $result;
1.7 tsai 2860: }
2861:
2862: sub shuffle {
1.555 raeburn 2863: my ($a,$target) = @_;
1.7 tsai 2864: my $i;
1.303 albertel 2865: if (ref($a) eq 'ARRAY' && @$a) {
1.555 raeburn 2866: &Apache::response::pushrandomnumber(undef,$target);
1.159 albertel 2867: for($i=@$a;--$i;) {
2868: my $j=int(&Math::Random::random_uniform() * ($i+1));
2869: next if $i == $j;
2870: @$a[$i,$j] = @$a[$j,$i];
2871: }
1.251 albertel 2872: &Apache::response::poprandomnumber();
1.7 tsai 2873: }
1.6 tsai 2874: }
2875:
2876: sub end_randomlist {
1.159 albertel 2877: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2878: my $result;
2879: if ($target eq 'edit' ) {
2880: $result=&Apache::edit::tag_end($target,$token,
2881: 'End Randomly Parsed Block');
2882: }
2883: return $result;
1.6 tsai 2884: }
2885:
1.283 albertel 2886: sub ordered_show_check {
2887: my $last_part=$Apache::inputtags::partlist[-2];
2888: my $in_order=
2889: &Apache::lonnet::EXT('resource.'.$Apache::inputtags::part.'.ordered');
2890: my $in_order_show=1;
2891: if ($last_part ne '0' && lc($in_order) eq 'yes') {
2892: $in_order_show=&Apache::response::check_status($last_part);
2893: }
2894: return $in_order_show;
2895: }
2896:
1.469 www 2897:
2898: sub start_startpartmarker {
2899: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2900: my $result='';
2901: if ($target eq 'edit') {
2902: $result=&Apache::edit::tag_start($target,$token);
2903: $result.=&mt('Marker for the start of a part. Place end marker below to wrap in-between tags into a new part.').'</td></tr>';
2904: $result.=&Apache::edit::end_table();
2905:
2906: }
2907: return $result;
2908: }
2909:
2910: sub end_startpartmarker {
2911: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2912: my @result;
2913: if ($target eq 'edit') { $result[1]='no'; }
2914: return @result;
2915: }
2916:
2917: sub start_endpartmarker {
2918: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2919: my $result='';
2920: if ($target eq 'edit') {
2921: $result=&Apache::edit::tag_start($target,$token);
2922: $result.=&mt('Marker for the end of a part. Place start marker above to wrap in-between tags into a new part.').'</td></tr>';
2923: $result.=&Apache::edit::end_table();
2924:
2925: }
2926: return $result;
2927: }
2928:
2929: sub end_endpartmarker {
2930: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
2931: my @result;
2932: if ($target eq 'edit') { $result[1]='no'; }
2933: return @result;
2934: }
2935:
2936:
2937:
2938:
2939:
1.11 albertel 2940: sub start_part {
1.326 albertel 2941: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.321 albertel 2942: if (!$Apache::lonxml::metamode) {
2943: &Apache::lonxml::startredirection(); # we'll use redirection to fix up
2944: # duedates.
2945: }
1.159 albertel 2946: my $result='';
1.386 albertel 2947: my $id= &Apache::lonxml::get_id($parstack,$safeeval);
1.159 albertel 2948: $Apache::inputtags::part=$id;
1.177 albertel 2949: push(@Apache::inputtags::partlist,$id);
1.536 raeburn 2950: $Apache::inputtags::leniency='';
1.177 albertel 2951: @Apache::inputtags::response=();
1.159 albertel 2952: @Apache::inputtags::previous=();
2953: @Apache::inputtags::previous_version=();
1.405 albertel 2954: &Apache::lonhomework::set_show_problem_status(&get_problem_status($id));
1.403 albertel 2955: &Apache::response::reset_params();
2956:
1.159 albertel 2957: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
1.259 albertel 2958: my $newtype=&Apache::lonnet::EXT("resource.$id.type");
2959: if ($newtype) { $Apache::lonhomework::type=$newtype; }
1.528 raeburn 2960: if ($Apache::lonhomework::type eq 'randomizetry') {
2961: my $rndseed=&setup_rndseed($safeeval,$target);
2962: if (($target eq 'grade') && &Apache::response::submitted()) {
1.529 raeburn 2963: $Apache::lonhomework::results{"resource.$id.rndseed"}=$rndseed;
1.528 raeburn 2964: }
1.570 raeburn 2965: } elsif (@Apache::inputtags::partlist > 1) {
2966: my $prevparttype = &Apache::lonnet::EXT("resource.$Apache::inputtags::partlist[-2].type");
2967: if ($prevparttype eq 'randomizetry') {
2968: my $rndseed=&setup_rndseed($safeeval,$target,'',$prevparttype);
2969: if (($target eq 'grade') && &Apache::response::submitted()) {
2970: $Apache::lonhomework::results{"resource.$id.rndseed"}=$rndseed;
2971: }
2972: }
1.528 raeburn 2973: } elsif (($target eq 'grade') && &Apache::response::submitted()) {
1.529 raeburn 2974: $Apache::lonhomework::results{"resource.$id.rndseed"}=$Apache::lonhomework::rawrndseed;
1.528 raeburn 2975: }
1.283 albertel 2976: my $in_order_show=&ordered_show_check();
1.214 albertel 2977: my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
1.259 albertel 2978: $expression.='$external::type=\''.$Apache::lonhomework::type.'\';';
1.209 albertel 2979: &Apache::run::run($expression,$safeeval);
1.159 albertel 2980:
2981: if ($target eq 'meta') {
1.224 www 2982: my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
2983: return &Apache::response::mandatory_part_meta.
2984: &Apache::response::meta_parameter_write('display','string',$display,'Part Description');
1.159 albertel 2985: } elsif ($target eq 'web' || $target eq 'grade' ||
2986: $target eq 'answer' || $target eq 'tex') {
1.283 albertel 2987: if ($hidden || !$in_order_show) {
1.326 albertel 2988: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser,$style);
1.159 albertel 2989: } else {
2990: my ($status,$accessmsg) = &Apache::lonhomework::check_access($id);
2991: push (@Apache::inputtags::status,$status);
2992: my $expression='$external::datestatus="'.$status.'";';
2993: $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";';
2994: &Apache::run::run($expression,$safeeval);
1.284 albertel 2995: if ($env{'request.state'} eq 'construct') {
1.241 albertel 2996: &set_problem_state($Apache::inputtags::part);
1.240 albertel 2997: }
1.216 albertel 2998: if (( $status eq 'CLOSED' ) ||
2999: ( $status eq 'UNCHECKEDOUT') ||
1.252 albertel 3000: ( $status eq 'NOT_YET_VIEWED') ||
1.216 albertel 3001: ( $status eq 'BANNED') ||
3002: ( $status eq 'UNAVAILABLE') ||
3003: ( $status eq 'INVALID_ACCESS')) {
1.326 albertel 3004: my $bodytext=&Apache::lonxml::get_all_text("/part",$parser,
3005: $style);
1.159 albertel 3006: if ( $target eq "web" ) {
1.211 albertel 3007: $result="<br />".&mt('Part is not open to be viewed. It')." $accessmsg<br />";
1.159 albertel 3008: } elsif ( $target eq 'tex' ) {
1.284 albertel 3009: if (not $env{'form.problem_split'}=~/yes/) {
1.211 albertel 3010: $result="\\end{minipage}\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\\\begin{minipage}{\\textwidth}";
1.195 sakharuk 3011: } else {
1.211 albertel 3012: $result="\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\";
1.195 sakharuk 3013: }
1.159 albertel 3014: }
3015: } else {
3016: if ($target eq 'tex') {
1.284 albertel 3017: if (not $env{'form.problem_split'}=~/yes/) {
1.264 sakharuk 3018: if ($$tagstack[-2] eq 'td') {
1.388 foxr 3019: $result.='\noindent \begin{minipage}{\textwidth}\noindent';
1.264 sakharuk 3020: } else {
3021: $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent';
3022: }
1.195 sakharuk 3023: }
1.159 albertel 3024: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
1.284 albertel 3025: my $allkeys=&Apache::lonnet::metadata($env{'request.uri'},'packages');
1.526 raeburn 3026: my @allkeys = split(/,/,$allkeys);
1.222 sakharuk 3027: my $allow_print_points = 0;
3028: foreach my $partial_key (@allkeys) {
1.230 albertel 3029: if ($partial_key=~m/^part_(.*)$/) {
1.222 sakharuk 3030: if ($1 ne '0') {$allow_print_points=1;}
3031: }
3032: }
1.275 albertel 3033: my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
3034: if (defined($maxtries) && $maxtries < 0) {
3035: $allow_print_points=0;
3036: }
1.302 albertel 3037: if (lc($env{'course.'.$env{'request.course.id'}.
3038: '.disableexampointprint'}) eq 'yes') {
3039: $allow_print_points=0;
3040: }
1.463 foxr 3041: if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) {
1.492 christia 3042: $result .= '\vskip 10mm\fbox{\textit{'.&mt('[quant,_1,pt,pt]',$weight ).'}}';
1.463 foxr 3043:
3044: }
1.233 www 3045: } elsif ($target eq 'web') {
1.479 raeburn 3046: if ($status eq 'CAN_ANSWER') {
3047: my $problemstatus = &get_problem_status($Apache::inputtags::part);
3048: my $num = scalar(@Apache::inputtags::partlist)-1;
1.567 raeburn 3049: if ((($Apache::lonhomework::default_type eq 'randomizetry') ||
3050: ($Apache::lonhomework::randomizetrypart)) &&
1.566 raeburn 3051: ($Apache::lonhomework::type ne 'randomizetry')) {
3052: $result .= &randomizetry_part_header($problemstatus,'none',$num);
3053: } elsif ($Apache::lonhomework::type eq 'randomizetry') {
3054: $Apache::lonhomework::randomizetrypart = 1;
3055: my $reqtries = &Apache::lonnet::EXT("resource.$id.randomizeontries");
1.479 raeburn 3056: $result .= &randomizetry_part_header($problemstatus,$reqtries,$num);
3057: }
3058: }
1.475 raeburn 3059: $result.='<a name="'.&escape($Apache::inputtags::part).'" ></a>';
1.159 albertel 3060: }
3061: }
3062: }
3063: } elsif ($target eq 'edit') {
3064: $result.=&Apache::edit::tag_start($target,$token);
3065: $result.=&Apache::edit::text_arg('Part ID:','id',$token).
3066: &Apache::loncommon::help_open_topic("Part_Tag_Edit_Help").
1.224 www 3067: ' '.
3068: &Apache::edit::text_arg('Displayed Part Description:','display',$token).
1.159 albertel 3069: &Apache::edit::end_row().&Apache::edit::start_spanning_row();
3070: } elsif ($target eq 'modified') {
3071: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
1.225 albertel 3072: $safeeval,'id','display');
1.159 albertel 3073: if ($constructtag) {
1.225 albertel 3074: #limiting ids to only letters numbers, and space
1.224 www 3075: $token->[2]->{'id'}=~s/[^A-Za-z0-9 ]//gs;
1.159 albertel 3076: $result = &Apache::edit::rebuild_tag($token);
3077: }
3078: }
3079: return $result;
1.11 albertel 3080: }
3081:
3082: sub end_part {
1.159 albertel 3083: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
3084: &Apache::lonxml::debug("in end_part $target ");
3085: my $status=$Apache::inputtags::status['-1'];
3086: my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part);
1.283 albertel 3087: my $in_order_show=&ordered_show_check();
1.321 albertel 3088: my $result;
3089: if (!$Apache::lonxml::metamode) {
3090: $result = &Apache::lonxml::endredirection(); # started in &start_part
1.329 albertel 3091: $Apache::lonxml::post_evaluate=0;
1.321 albertel 3092: }
1.312 albertel 3093: if ($target eq 'grade') {
1.249 albertel 3094: if (($status eq 'CAN_ANSWER' || $Apache::lonhomework::scantronmode) &&
1.283 albertel 3095: !$hidden && $in_order_show) {
1.311 foxr 3096: $result.=&Apache::inputtags::grade;
1.249 albertel 3097: } else {
3098: # move any submission data to .hidden
3099: &Apache::inputtags::hidealldata($Apache::inputtags::part);
3100: }
1.283 albertel 3101: } elsif (($target eq 'web' || $target eq 'tex') &&
3102: !$hidden && $in_order_show) {
1.159 albertel 3103: my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part,
3104: $target);
1.490 raeburn 3105: if (($Apache::lonhomework::type eq 'exam' && $target eq 'tex') ||
3106: ($env{'form.grade_imsexport'})) {
1.212 albertel 3107: $gradestatus='';
3108: }
1.311 foxr 3109: $result.=$gradestatus;
1.265 sakharuk 3110: if ($$tagstack[-2] eq 'td' and $target eq 'tex') {$result.='\end{minipage}';}
1.181 albertel 3111: } elsif ($target eq 'edit') {
1.311 foxr 3112: $result.=&Apache::edit::end_table();
1.322 albertel 3113: } elsif ($target eq 'modified') {
3114: $result .= $token->[2];
1.159 albertel 3115: }
3116: pop @Apache::inputtags::status;
3117: $Apache::inputtags::part='';
1.536 raeburn 3118: $Apache::inputtags::leniency='';
1.295 albertel 3119: $Apache::lonhomework::type = $Apache::lonhomework::default_type;
1.159 albertel 3120: return $result;
1.11 albertel 3121: }
1.1 albertel 3122:
1.25 albertel 3123: sub start_preduedate {
1.326 albertel 3124: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.339 albertel 3125: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
3126: $target eq 'tex' || $target eq 'webgrade') {
1.236 albertel 3127: &Apache::lonxml::debug("State in preduedate is ". $Apache::inputtags::status['-1']);
1.300 albertel 3128: if (!$Apache::lonhomework::scantronmode &&
3129: $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' &&
1.236 albertel 3130: $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') {
3131: &Apache::lonxml::debug("Wha? ". ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER'));
1.326 albertel 3132: &Apache::lonxml::get_all_text("/preduedate",$parser,$style);
1.159 albertel 3133: }
1.24 albertel 3134: }
1.159 albertel 3135: return '';
1.24 albertel 3136: }
3137:
1.25 albertel 3138: sub end_preduedate {
1.159 albertel 3139: return '';
1.24 albertel 3140: }
3141:
1.369 foxr 3142: # In all the modes where <postanswerdate> text is
3143: # displayable, all we do is eat up the text between the start/stop
3144: # tags if the conditions are not right to display it.
1.25 albertel 3145: sub start_postanswerdate {
1.326 albertel 3146: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.370 foxr 3147: my $pav = &Apache::lonnet::allowed('pav', $env{'request.course.id'}) ||
3148: &Apache::lonnet::allowed('pav',
3149: $env{'request.course.id'}.'/'.$env{'request.course.sec'});
1.369 foxr 3150: if ($target eq 'web' || $target eq 'grade' || $target eq 'webgrade' ||
1.370 foxr 3151: $target eq 'tex' ) {
1.300 albertel 3152: if ($Apache::lonhomework::scantronmode ||
1.370 foxr 3153: $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER' ||
3154: (($target eq 'tex') && !$pav)) {
1.326 albertel 3155: &Apache::lonxml::get_all_text("/postanswerdate",$parser,$style);
1.159 albertel 3156: }
3157: }
3158: return '';
1.24 albertel 3159: }
3160:
1.25 albertel 3161: sub end_postanswerdate {
1.159 albertel 3162: return '';
1.24 albertel 3163: }
3164:
1.25 albertel 3165: sub start_notsolved {
1.326 albertel 3166: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 3167: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
1.339 albertel 3168: $target eq 'tex' || $target eq 'webgrade') {
1.159 albertel 3169: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
3170: &Apache::lonxml::debug("not solved has :$gradestatus:");
1.239 albertel 3171: if ($gradestatus =~ /^correct/ &&
3172: &Apache::response::show_answer()) {
1.159 albertel 3173: &Apache::lonxml::debug("skipping");
1.326 albertel 3174: &Apache::lonxml::get_all_text("/notsolved",$parser,$style);
1.159 albertel 3175: }
1.24 albertel 3176: }
1.159 albertel 3177: return '';
1.24 albertel 3178: }
3179:
1.25 albertel 3180: sub end_notsolved {
1.159 albertel 3181: return '';
1.24 albertel 3182: }
3183:
3184: sub start_solved {
1.326 albertel 3185: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 3186: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
3187: $target eq 'tex') {
3188: my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
1.239 albertel 3189: if ($gradestatus !~ /^correct/ ||
3190: !&Apache::response::show_answer()) {
1.326 albertel 3191: &Apache::lonxml::get_all_text("/solved",$parser,$style);
1.159 albertel 3192: }
1.24 albertel 3193: }
1.159 albertel 3194: return '';
1.24 albertel 3195: }
3196:
3197: sub end_solved {
1.248 albertel 3198: return '';
3199: }
3200:
3201: sub start_problemtype {
1.326 albertel 3202: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.248 albertel 3203: my $result;
1.339 albertel 3204: if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
3205: $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') {
1.248 albertel 3206: my $mode=lc(&Apache::lonxml::get_param('mode',$parstack,$safeeval));
3207: if (!defined($mode)) { $mode='show'; }
3208: my $for=&Apache::lonxml::get_param('for',$parstack,$safeeval);
3209: my $found=0;
3210: foreach my $type (split(',',$for)) {
3211: if ($Apache::lonhomework::type eq lc($type)) { $found=1; }
3212: }
3213: if ($mode eq 'show' && !$found) {
1.326 albertel 3214: &Apache::lonxml::get_all_text("/problemtype",$parser,$style);
1.248 albertel 3215: }
3216: if ($mode eq 'hide' && $found) {
1.326 albertel 3217: &Apache::lonxml::get_all_text("/problemtype",$parser,$style);
1.248 albertel 3218: }
3219: } elsif ($target eq 'edit') {
3220: $result .=&Apache::edit::tag_start($target,$token);
3221: $result.=&Apache::edit::select_arg('Mode:','mode',
3222: [['show','Show'],
3223: ['hide','Hide']]
3224: ,$token);
3225: $result .=&Apache::edit::checked_arg('When used as type(s):','for',
1.511 bisitz 3226: [ ['exam','Bubblesheet Exam/Quiz Problem'],
1.248 albertel 3227: ['survey','Survey'],
1.465 raeburn 3228: ['surveycred','Survey (with credit)'],
3229: ['anonsurvey','Anonymous Survey'],
3230: ['anonsurveycred','Anonymous Survey (with credit)'],
1.428 raeburn 3231: ['problem','Homework Problem'],
1.479 raeburn 3232: ['practice','Practice Problem'],
3233: ['randomizetry','New Randomization Each Try'] ]
1.248 albertel 3234: ,$token);
3235: $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
3236: } elsif ($target eq 'modified') {
3237: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
3238: $safeeval,'mode','for');
3239: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
3240: }
3241: return $result;
3242: }
3243:
3244: sub end_problemtype {
1.159 albertel 3245: return '';
1.24 albertel 3246: }
1.34 albertel 3247:
3248: sub start_startouttext {
1.159 albertel 3249: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
3250: my @result=(''.'');
3251: if ($target eq 'edit' || $target eq 'modified' ) { @result=('','no'); }
1.404 albertel 3252:
3253: my $nesting =
3254: &Apache::lonxml::set_state('outtext',
3255: &Apache::lonxml::get_state('outtext')+1);
3256: if ($nesting > 1 && $env{'request.state'} eq 'construct') {
3257: &Apache::lonxml::error("Nesting of <startouttext /> not allowed, on line ".$token->[5]);
3258: }
1.159 albertel 3259: return (@result);
1.34 albertel 3260: }
1.159 albertel 3261:
1.34 albertel 3262: sub end_startouttext {
1.326 albertel 3263: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.159 albertel 3264: my $result='';
3265: my $text='';
3266: if ($target eq 'edit') {
1.424 foxr 3267: my $areaid = 'homework_edit_'.$Apache::lonxml::curdepth;
1.326 albertel 3268: $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style);
1.527 golterma 3269: $result.=&Apache::edit::start_table($token)."<tr><td>".&Apache::loncommon::insert_folding_button()
3270: ." ".&mt('Text Block')."</td>"
1.438 bisitz 3271: .'<td><span class="LC_nobreak">'.&mt('Delete?').' '
1.437 raeburn 3272: .&Apache::edit::deletelist($target,$token)
1.474 raeburn 3273: .'</span></td>'
1.550 raeburn 3274: .'<td><span id="math_'.$areaid.'">';
3275: if ($env{'environment.nocodemirror'}) {
3276: $result.=&Apache::lonhtmlcommon::dragmath_button($areaid,1);
3277: } else {
3278: $result.=' ';
3279: }
3280: $result.='</span></td>'
1.474 raeburn 3281: .'<td>'
3282: .&Apache::edit::insertlist($target,$token)
3283: .'</td>'
1.515 golterma 3284: .'<td class="LC_edit_problem_latexhelper">' .
1.474 raeburn 3285: &Apache::loncommon::helpLatexCheatsheet().
1.159 albertel 3286: &Apache::edit::end_row().
1.362 albertel 3287: &Apache::edit::start_spanning_row()."\n".
1.255 www 3288: &Apache::edit::editfield($token->[1],$text,"",80,8,1);
1.159 albertel 3289: }
3290: if ($target eq 'modified') {
1.219 albertel 3291: $result='<startouttext />'.&Apache::edit::modifiedfield("endouttext",$parser);
1.159 albertel 3292: }
3293: if ($target eq 'tex') {
3294: $result .= '\noindent ';
3295: }
3296: return $result;
1.34 albertel 3297: }
1.159 albertel 3298:
1.34 albertel 3299: sub start_endouttext {
1.159 albertel 3300: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
3301: my $result='';
3302: if ($target eq "edit" ) { $result="</td></tr>".&Apache::edit::end_table()."\n"; }
3303: if ($target eq "modified") {
3304: $result='<endouttext />'.
1.377 albertel 3305: &Apache::edit::handle_insertafter('startouttext');
3306: }
1.404 albertel 3307:
3308: my $nesting =
3309: &Apache::lonxml::set_state('outtext',
3310: &Apache::lonxml::get_state('outtext')-1);
3311: if ($nesting < 0 && $env{'request.state'} eq 'construct') {
3312: &Apache::lonxml::error(" Extraneous <endouttext /> not allowed on line ".$token->[5]);
3313: &Apache::lonxml::set_state('outtext', 0);
3314: }
1.159 albertel 3315: return $result;
1.34 albertel 3316: }
1.159 albertel 3317:
1.34 albertel 3318: sub end_endouttext {
1.159 albertel 3319: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
3320: my @result=('','');
3321: if ($target eq "edit" || $target eq 'modified') { @result=('','no'); }
3322: return (@result);
1.34 albertel 3323: }
1.159 albertel 3324:
1.45 albertel 3325: sub delete_startouttext {
1.326 albertel 3326: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
3327: # my $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style);
1.159 albertel 3328: my $text=$$parser['-1']->get_text("/endouttext");
3329: my $ntoken=$$parser['-1']->get_token();
3330: &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext");
3331: &Apache::lonxml::end_tag($tagstack,$parstack,$ntoken);
3332: # Deleting 2 parallel tag pairs, but we need the numbers later to look like
3333: # they did the last time round
3334: &Apache::lonxml::increasedepth($ntoken);
3335: &Apache::lonxml::decreasedepth($ntoken);
3336: return 1;
1.193 www 3337: }
3338:
3339: sub start_simpleeditbutton {
3340: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
3341: my $result='';
1.284 albertel 3342: if (($env{'form.simple_edit_button'} ne 'off') &&
1.273 albertel 3343: ($target eq 'web') &&
1.330 albertel 3344: (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) {
1.284 albertel 3345: my $url=$env{'request.noversionuri'};
1.193 www 3346: $url=~s/\?.*$//;
1.367 albertel 3347: my ($symb) = &Apache::lonnet::whichuser();
1.451 bisitz 3348: # Warning makes more sense and is more important on edit screen
1.442 bisitz 3349: # $result='<p class="LC_warning">'
3350: # .&mt('Note: it can take up to 10 minutes for changes to take effect for all users.')
3351: # .&Apache::loncommon::help_open_topic('Caching')
3352: # .'</p>';
1.486 www 3353: $result.=&Apache::loncommon::head_subbox(
3354: &Apache::lonhtmlcommon::start_funclist()
1.451 bisitz 3355: .&Apache::lonhtmlcommon::add_item_funclist(
3356: '<a href="'.$url.'/smpedit?symb='.&escape($symb).'">'
3357: .&mt('Edit').'</a>')
1.486 www 3358: .&Apache::lonhtmlcommon::end_funclist());
1.442 bisitz 3359:
1.193 www 3360: }
3361: return $result;
3362: }
3363:
3364: sub end_simpleeditbutton {
3365: return '';
1.45 albertel 3366: }
1.34 albertel 3367:
1.428 raeburn 3368: sub practice_problem_header {
1.556 raeburn 3369: return '<h3 class="LC_info">'.&mt('Practice Problem').'</h3>'.
1.428 raeburn 3370: '<span class="LC_info">'.&mt('Submissions are not permanently recorded').
3371: '</span>';
3372: }
3373:
1.479 raeburn 3374: sub randomizetry_problem_header {
1.566 raeburn 3375: my ($problemstatus,$reqtries,$symb) = @_;
1.479 raeburn 3376: my ($header,$text);
3377: if ($reqtries > 1) {
3378: $header = &mt('New Problem Variation After Every [quant,_1,Try,Tries]',$reqtries);
3379: if (($problemstatus eq 'no') ||
3380: ($problemstatus eq 'no_feedback_ever')) {
3381: $text = &mt('A new variation will be generated after every [quant,_1,try,tries], until the tries limit is reached.',$reqtries);
3382: } else {
3383: $text = &mt('A new variation will be generated after every [quant,_1,try,tries], until correct or tries limit is reached.',$reqtries);
3384: }
3385: } else {
3386: $header = &mt('New Problem Variation Each Try');
3387: if (($problemstatus eq 'no') ||
3388: ($problemstatus eq 'no_feedback_ever')) {
3389: $text = &mt('A new variation will be generated after each try until the tries limit is reached.');
3390:
3391: } else {
3392: $text = &mt('A new variation will be generated after each try until correct or tries limit is reached.');
3393: }
3394: }
1.566 raeburn 3395: if (($env{'request.state'} eq "construct") || ($symb eq '')) {
3396: return '<div class="LC_info" id="LC_randomizetry_header" style="display:none">'.
3397: '<h3>'.$header.'</h3><span class="LC_info">'.$text.'</span><hr /></div>';
3398: } else {
3399: return '<h3 class="LC_info">'.$header.'</h3>'.
3400: '<span class="LC_info">'.$text.'</span><hr />';
3401: }
1.479 raeburn 3402: }
3403:
3404: sub randomizetry_part_header {
3405: my ($problemstatus,$reqtries,$num) = @_;
3406: my ($header,$text);
3407: if ($reqtries eq 'none') {
3408: $header = &mt('No Question Variation');
1.570 raeburn 3409: $text = &mt('For this question there will be no new variation after a try.');
1.479 raeburn 3410: } elsif ($reqtries > 1) {
3411: $header = &mt('New Question Variation After Every [quant,_1,Try,Tries]',$reqtries);
3412: if (($problemstatus eq 'no') ||
3413: ($problemstatus eq 'no_feedback_ever')) {
3414: $text = &mt('For this question a new variation will be generated after every [quant,_1,try,tries], until the tries limit is reached.',$reqtries);
3415: } else {
3416: $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);
3417: }
3418: } else {
3419: $header = &mt('New Question Variation For Each Try');
3420: if (($problemstatus eq 'no') ||
3421: ($problemstatus eq 'no_feedback_ever')) {
3422: $text = &mt('For this question a new variation will be generated after each try until the tries limit is reached.');
3423: } else {
3424: $text = &mt('For this question a new variation will be generated after each try until correct or tries limit is reached.');
3425: }
3426: }
3427: my $output;
3428: if ($num > 1) {
3429: $output .= '<hr />';
3430: }
1.556 raeburn 3431: $output .= '<h4 class="LC_info">'.$header.'</h4>'.
1.479 raeburn 3432: '<span class="LC_info">'.$text.'</span><br /><br />';
3433: return $output;
3434: }
3435:
1.1 albertel 3436: 1;
3437: __END__
1.435 jms 3438:
3439: =pod
3440:
3441: =back
3442:
3443: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>