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