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