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