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