--- loncom/homework/structuretags.pm 2006/03/02 21:20:30 1.337 +++ loncom/homework/structuretags.pm 2006/06/26 22:33:22 1.359 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.337 2006/03/02 21:20:30 albertel Exp $ +# $Id: structuretags.pm,v 1.359 2006/06/26 22:33:22 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,7 +36,11 @@ use Apache::File(); use Apache::lonmenu; use Apache::lonlocal; use Apache::lonxml; +use Apache::lonenc(); use Time::HiRes qw( gettimeofday tv_interval ); +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + BEGIN { &Apache::lonxml::register('Apache::structuretags',('block','languageblock','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startouttext','endouttext','simpleeditbutton','definetag')); } @@ -44,7 +48,7 @@ BEGIN { sub start_web { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style); - if ($target eq 'web') { + if ($target eq 'web' || $target eq 'webgrade') { return $bodytext; } return ''; @@ -68,35 +72,9 @@ sub end_tex { return ''; } -sub body_tag_start { - my ($target,$background,$bgcolor)=@_; - my $body_tag_start=''; } if ($target eq 'edit') { - $head_tag_start.=&Apache::edit::js_change_detection(); + $extra_head.=&Apache::edit::js_change_detection(). + "\n"; } } - my $body_tag_start; - if (!defined($found{'body'}) && $env{'request.state'} eq 'construct') { - if ($env{'environment.remote'} eq 'off') { - if ($target eq 'web' || $target eq 'edit') { - $body_tag_start=&Apache::loncommon::bodytag(); - $body_tag_start.=&Apache::lonxml::message_location(); - } - } else { - if ($target eq 'web' || $target eq 'edit') { - $body_tag_start=&Apache::loncommon::bodytag(undef,undef,undef,1); - $body_tag_start.=&Apache::lonxml::message_location(); - } + + if (defined($found{'body'})) { + $body_args{'skip_phases'}{'body'}=1; + } elsif (!defined($found{'body'}) + && $env{'request.state'} eq 'construct') { + if ($target eq 'web' || $target eq 'edit') { + # no extra args to bodytag } } elsif (!defined($found{'body'})) { + my %add_entries; my $background=&Apache::lonxml::get_param('background',$parstack, $safeeval); + if ($background ne '' ) { + $add_entries{'background'} = $background; + } + my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack, $safeeval); - $body_tag_start=&body_tag_start($target,$background,$bgcolor); - if ( ($target eq 'web' || $target eq 'webgrade') - && $env{'request.state'} ne 'construct') { - my ($symb,undef,undef,undef,$publicuser)= - &Apache::lonxml::whichuser(); - if ($symb eq '' && !$publicuser) { - my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference"); - $help=&mt("Browsing resource, all submissions are temporary.")."
"; - $body_tag_start.=$help; - } + if ($bgcolor eq '' ) { $bgcolor = '#FFFFFF'; } + + $body_args{'bgcolor'} = $bgcolor; + $body_args{'no_title'} = 1; + $body_args{'force_register'} = 1; + $body_args{'add_entries'} = \%add_entries; + } + + my $page_start = &Apache::loncommon::start_page($name,$extra_head, + \%body_args); + + if (!defined($found{'body'}) + && $env{'request.state'} ne 'construct' + && ($target eq 'web' || $target eq 'webgrade')) { + + my ($symb,undef,undef,undef,$publicuser)= &Apache::lonxml::whichuser(); + if ($symb eq '' && !$publicuser) { + my $help = &Apache::loncommon::help_open_topic("Ambiguous_Reference"); + $help=&mt("Browsing resource, all submissions are temporary.")."
"; + $page_start .= $help; } - $body_tag_start.=&Apache::lonxml::message_location(); } + + if (!defined($found{'body'})) { + $page_start .= &Apache::lonxml::message_location(); + } + my $form_tag_start; if (!defined($found{'form'})) { $form_tag_start='
'; + } } - return ($result,$head_tag_start,$body_tag_start,$form_tag_start); + return ($page_start,$form_tag_start); } #use Time::HiRes(); @@ -243,7 +251,7 @@ sub problem_edit_header {
'. - &Apache::loncommon::help_open_menu('','Problem Editing Help','Problem_Editor_XML_Index','',5,'Authoring',undef,undef,undef,'Problem Editing Help') + &Apache::loncommon::help_open_menu('Problem Editing Help','Problem_Editor_XML_Index',5,'Authoring',undef,undef,undef,'Problem Editing Help') .'
'. '
'; } @@ -251,8 +259,8 @@ sub problem_edit_header { sub problem_edit_footer { return '

'. - &Apache::lonhtmlcommon::htmlareaselectactive(@Apache::lonxml::htmlareafields). - "\n
\n".&Apache::loncommon::endbodytag()."\n"; + &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()). + "\n\n".&Apache::loncommon::end_page(); } sub option { @@ -334,9 +342,18 @@ Feedback Mode: } sub initialize_storage { - %Apache::lonhomework::results=(); - %Apache::lonhomework::history=(); - my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); + my ($given_symb) = @_; + undef(%Apache::lonhomework::results); + undef(%Apache::lonhomework::history); + my ($symb,$courseid,$domain,$name) = + &Apache::lonxml::whichuser($given_symb); + + # anonymous users (CODEd exams) have no data + if ($name eq 'anonymous' + && !defined($domain)) { + return; + } + if ($env{'request.state'} eq 'construct' || $symb eq '' || $Apache::lonhomework::type eq 'practice') { @@ -356,6 +373,7 @@ sub initialize_storage { %Apache::lonhomework::history= &Apache::lonnet::restore($symb,$courseid,$domain,$name); } + #ignore error conditions my ($temp)=keys %Apache::lonhomework::history ; if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); } @@ -368,11 +386,13 @@ sub initialize_storage { # Will increment totals for attempts, students, and corrects # if running user has student role. sub finalize_storage { + my ($given_symb) = @_; my $result; if (%Apache::lonhomework::results) { my @remove = grep(/^INTERNAL_/,keys(%Apache::lonhomework::results)); delete(@Apache::lonhomework::results{@remove}); - my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); + my ($symb,$courseid,$domain,$name) = + &Apache::lonxml::whichuser($given_symb); if ($env{'request.state'} eq 'construct' || $symb eq '' || $Apache::lonhomework::type eq 'practice') { @@ -443,13 +463,14 @@ sub checkout_msg { 'warning'=>'Checking out resources is subject to course policies, and may exclude future credit even if done erroneously.', 'checkout'=>'Check out Exam for Viewing', 'checkout?'=>'Check out Exam?'); + my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'}); return (<$lt{'resource'}

$lt{'id_expln'}

$lt{'warning'}

-
+
@@ -461,9 +482,10 @@ sub firstaccess_msg { my ($map)=&Apache::lonnet::decode_symb($symb); my $foldertitle=&Apache::lonnet::gettitle($map); &Apache::lonxml::debug("map is $map title is $foldertitle"); + my $uri = &Apache::lonenc::check_encrypt($env{'request.uri'}); return (<The resources in "$foldertitle" are open for a limited time. Once you click the 'Show Resource' button below you have $time to complete all resources "$foldertitle". -
+
@@ -504,7 +526,9 @@ sub init_problem_globals { @Apache::structuretags::whileline=(); $Apache::lonhomework::scantronmode=0; undef($Apache::lonhomework::name); - + undef($Apache::lonhomework::default_type); + undef($Apache::lonhomework::type); + undef($Apache::lonhomework::problemstatus); } sub reset_problem_globals { @@ -516,6 +540,11 @@ sub reset_problem_globals { #detect if we try to do 2 problems in one file # undef($Apache::lonhomework::parsing_a_problem); undef($Apache::lonhomework::name); + undef($Apache::lonhomework::default_type); + undef($Apache::lonhomework::type); + undef($Apache::lonhomework::scantronmode); + undef($Apache::lonhomework::problemstatus); + undef($Apache::lonhomework::ignore_response_errors); } sub set_problem_state { @@ -597,9 +626,15 @@ sub start_problem { my $status; my $accessmsg; - #should get back a or the neccesary stuff to start XML/MathML - my ($result,$head_tag_start,$body_tag_start,$form_tag_start)= - &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); + my $name= &get_resource_name($parstack,$safeeval); + my ($result,$form_tag_start); + if ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex' + || $target eq 'edit') { + ($result,$form_tag_start) = + &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval, + $name); + } + if ($target eq 'tex' and $env{'request.symb'} =~ m/\.page_/) {$result='';} if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval); } @@ -614,7 +649,7 @@ sub start_problem { $Apache::lonhomework::history{"resource.0.outtoken"}= $token; } - $body_tag_start.=&Apache::lonxml::printtokenheader($target,$token); + $result.=&Apache::lonxml::printtokenheader($target,$token); } if ($env{'form.markaccess'}) { &Apache::lonnet::set_first_access('map'); @@ -664,8 +699,7 @@ sub start_problem { my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser, $style); if ( $target eq "web" ) { - $result.= $head_tag_start.''; - my $msg=$body_tag_start; + my $msg; if ($status eq 'UNAVAILABLE') { $msg.='

'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'

'; } elsif ($status ne 'NOT_YET_VIEWED') { @@ -674,7 +708,7 @@ sub start_problem { if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') { $msg.='The problem '.$accessmsg; } elsif ($status eq 'UNCHECKEDOUT') { - $msg.=&checkout_msg; + $msg.=&checkout_msg(); } elsif ($status eq 'NOT_YET_VIEWED') { $msg.=&firstaccess_msg($accessmsg,$symb); } elsif ($status eq 'NOT_IN_A_SLOT') { @@ -696,17 +730,13 @@ sub start_problem { my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser, $style); if ($target eq 'web') { - $result .= $head_tag_start.''; - $result .= $body_tag_start; $result .= &Apache::bridgetask::proctor_validation_screen(); } elsif ($target eq 'grade') { &Apache::bridgetask::proctor_check_auth($slot_name,$slot, 'problem'); } } elsif ($target eq 'web') { - my $name= &get_resource_name($parstack,$safeeval); - $result.="$head_tag_start$name - $body_tag_start \n $form_tag_start". + $result.="\n $form_tag_start". ''; # create a page header and exit if ($env{'request.state'} eq "construct") { @@ -724,8 +754,7 @@ sub start_problem { } } elsif ($target eq 'edit') { - $result.=$head_tag_start."".$body_tag_start.$form_tag_start. - &problem_edit_header(); + $result .= $form_tag_start.&problem_edit_header(); $Apache::lonxml::warnings_error_header= &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.")."
"; my $temp=&Apache::edit::insertlist($target,$token); @@ -867,10 +896,10 @@ sub end_problem { if ($target ne 'tex' && $env{'form.answer_output_mode'} ne 'tex') { $result.=""; - $result.=&Apache::lonhtmlcommon::htmlareaselectactive(@Apache::lonxml::htmlareafields); + $result.= &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()); } if ($target eq 'web') { - $result.=&Apache::lonxml::xmlend().''; + $result.= &Apache::loncommon::end_page({'discussion' => 1}); } elsif ($target eq 'tex') { my $endminipage = ''; if (not $env{'form.problem_split'}=~/yes/) { @@ -878,7 +907,6 @@ sub end_problem { } if ($env{'form.print_discussions'} eq 'yes') { $result.=&Apache::lonxml::xmlend($target,$parser); - $result=~s/<\/html>//; } else { $result .= '\keephidden{ENDOFPROBLEM}\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}'; if (not $env{'request.symb'} =~ m/\.page_/) { @@ -895,7 +923,7 @@ sub end_problem { } if ($target eq 'answer' && ($env{'request.state'} eq 'construct') && $env{'form.answer_output_mode'} ne 'tex') { - $result.=&Apache::lonxml::xmlend().''; + $result.=&Apache::loncommon::end_page({'discussion' => 1}); # normally we get it from above, but in CSTR # we always show answer mode too. } @@ -926,29 +954,30 @@ sub end_problem { sub start_library { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my ($result,$head_tag_start,$body_tag_start,$form_tag_start); + my ($result,$form_tag_start); if ($$tagstack[0] eq 'library') { &init_problem_globals('library'); $Apache::lonhomework::type='problem'; } if ($target eq 'edit') { - ($result,$head_tag_start,$body_tag_start,$form_tag_start)= - &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); - $result.=$head_tag_start."".$body_tag_start.$form_tag_start. - &problem_edit_header(); + ($result,$form_tag_start)= + &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval, + 'Edit'); + $result.=$form_tag_start.&problem_edit_header(); my $temp=&Apache::edit::insertlist($target,$token); $result.=$temp; } elsif ($target eq 'modified') { $result=$token->[4]; $result.=&Apache::edit::handle_insert(); - } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' && - $env{'request.state'} eq "construct" ) { - ($result,$head_tag_start,$body_tag_start,$form_tag_start)= - &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval); + } elsif (($target eq 'web' || $target eq 'webgrade') + && $$tagstack[0] eq 'library' + && $env{'request.state'} eq "construct" ) { my $name=&get_resource_name($parstack,$safeeval); + ($result,$form_tag_start)= + &page_start($target,$token,$tagstack,$parstack,$parser,$safeeval, + $name); my $rndseed=&setup_rndseed($safeeval); - $result.="$head_tag_start$name - $body_tag_start \n $form_tag_start". + $result.=" \n $form_tag_start". ''; $result.=&problem_web_to_edit_header($rndseed); } @@ -962,8 +991,7 @@ sub end_library { $result=&problem_edit_footer(); } elsif ($target eq 'web' && $$tagstack[0] ne 'problem' && $env{'request.state'} eq "construct") { - $result.=''.&Apache::loncommon::endbodytag(). - &Apache::lonxml::xmlend(); + $result.=''.&Apache::loncommon::end_page({'discussion' => 1}); } if ($$tagstack[0] eq 'library') { &reset_problem_globals('library') }; return $result; @@ -998,8 +1026,8 @@ sub start_block { my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $code = $token->[2]->{'condition'}; if (defined($code)) { if (!$Apache::lonxml::default_homework_loaded) { @@ -1042,8 +1070,8 @@ sub start_languageblock { my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $include = $token->[2]->{'include'}; my $exclude = $token->[2]->{'exclude'}; my %languages=&Apache::loncommon::display_languages(); @@ -1095,8 +1123,8 @@ sub start_instructorcomment { my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { $result=($env{'request.role'}=~/^(in|cc|au|ca|li)/); if ( (! $result) or ($env{'form.instructor_comments'} eq 'hide')) { my $skip=&Apache::lonxml::get_all_text("/instructorcomment", @@ -1124,8 +1152,8 @@ sub start_while { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $code = $token->[2]->{'condition'}; push( @Apache::structuretags::whileconds, $code); @@ -1157,8 +1185,8 @@ sub end_while { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $code = pop(@Apache::structuretags::whileconds); my $bodytext = pop(@Apache::structuretags::whilebody); my $line = pop(@Apache::structuretags::whileline); @@ -1191,8 +1219,8 @@ sub end_while { sub start_randomlist { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result; - if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'answer' || $target eq 'grade' || $target eq 'web' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $body= &Apache::lonxml::get_all_text("/randomlist",$parser); my $b_parser= HTML::LCParser->new(\$body); $b_parser->xml_mode(1); @@ -1366,7 +1394,7 @@ sub start_part { } if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { $result .= '\fbox{\textit{'.$weight.' pt}}';} } elsif ($target eq 'web') { - $result.=''; + $result.=''; } } } @@ -1432,7 +1460,8 @@ sub end_part { sub start_preduedate { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'webgrade') { &Apache::lonxml::debug("State in preduedate is ". $Apache::inputtags::status['-1']); if (!$Apache::lonhomework::scantronmode && $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' && @@ -1450,7 +1479,7 @@ sub end_preduedate { sub start_postanswerdate { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; - if ($target eq 'web' || $target eq 'grade') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'webgrade') { if ($Apache::lonhomework::scantronmode || $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') { &Apache::lonxml::get_all_text("/postanswerdate",$parser,$style); @@ -1468,7 +1497,7 @@ sub end_postanswerdate { sub start_notsolved { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex') { + $target eq 'tex' || $target eq 'webgrade') { my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"}; &Apache::lonxml::debug("not solved has :$gradestatus:"); if ($gradestatus =~ /^correct/ && @@ -1504,8 +1533,8 @@ sub end_solved { sub start_problemtype { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || - $target eq 'tex' || $target eq 'analyze') { + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $mode=lc(&Apache::lonxml::get_param('mode',$parstack,$safeeval)); if (!defined($mode)) { $mode='show'; } my $for=&Apache::lonxml::get_param('for',$parstack,$safeeval); @@ -1618,7 +1647,7 @@ sub start_simpleeditbutton { $url=~s/\?.*$//; my ($symb) = &Apache::lonxml::whichuser(); $result='
'. - ''.&mt('Edit').' - '.&mt('Note: it can take up to 10 minutes for changes to take effect for all users.'). + ''.&mt('Edit').' - '.&mt('Note: it can take up to 10 minutes for changes to take effect for all users.'). &Apache::loncommon::help_open_topic('Caching').'

'; } return $result;