--- loncom/homework/structuretags.pm 2007/10/31 01:37:52 1.408 +++ loncom/homework/structuretags.pm 2009/06/09 12:56:27 1.449 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.408 2007/10/31 01:37:52 albertel Exp $ +# $Id: structuretags.pm,v 1.449 2009/06/09 12:56:27 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,6 +27,29 @@ # ### +=pod + +=head1 NAME + +Apache::structuretags + +=head1 SYNOPSIS + + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + + +=head1 NOTABLE SUBROUTINES + +=over + +=item + +=back + +=cut + package Apache::structuretags; @@ -36,6 +59,7 @@ use Apache::File(); use Apache::lonmenu; use Apache::lonlocal; use Apache::lonxml; +use Apache::londefdef; use Apache::lonenc(); use Time::HiRes qw( gettimeofday tv_interval ); use lib '/home/httpd/lib/perl/'; @@ -74,7 +98,14 @@ sub start_tex { if ($target ne 'edit' && $target ne 'modified') { my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style); if ($target eq 'tex') { - return $bodytext.' '; + + # If inside a table, occurrences of \\ must be removed; + # else the table blows up. + + if (&Apache::londefdef::is_inside_of($tagstack, "table")) { + $bodytext =~ s/\\\\//g; + } + return $bodytext.'{}'; } } elsif ($target eq "edit" ) { my $bodytext = @@ -94,6 +125,7 @@ sub end_tex { sub homework_js { return &Apache::loncommon::resize_textarea_js(). + &setmode_javascript(). <<'JS'; JS } +sub setmode_javascript { + return <<"ENDSCRIPT"; + +ENDSCRIPT +} + sub page_start { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name, $extra_head)=@_; @@ -135,6 +179,12 @@ sub page_start { $extra_head .= &homework_js(); + if ($env{'environment.wysiwygeditor'} eq 'on') { + $extra_head .= &Apache::lonhtmlcommon::dragmath_js("FCKEditMathPopup"); + } else { + $extra_head .= &Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); + } + my %body_args; if (defined($found{'html'})) { $body_args{'skip_phases'}{'head'}=1; @@ -153,6 +203,7 @@ sub page_start { } } + my $pageheader = ''; if (defined($found{'body'})) { $body_args{'skip_phases'}{'body'}=1; } elsif (!defined($found{'body'}) @@ -161,6 +212,9 @@ sub page_start { if ($env{'environment.remote'} ne 'off') { $body_args{'only_body'} = 1; } + $pageheader = &Apache::lonhtmlcommon::breadcrumbs() # FIXME add breadcrumbs + .&Apache::loncommon::head_subbox( + &Apache::loncommon::CSTR_pageheader()); } } elsif (!defined($found{'body'})) { my %add_entries; @@ -172,21 +226,21 @@ sub page_start { my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack, $safeeval); - if ($bgcolor eq '' ) { $bgcolor = '#FFFFFF'; } + 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; - if ($env{'environment.remote'} eq 'off' - && $env{'request.state'} eq 'construct') { - $body_args{'only_body'} = 1; - } + $body_args{'bgcolor'} = $bgcolor; + # $body_args{'no_title'} = 1; + $body_args{'force_register'} = 1; + $body_args{'add_entries'} = \%add_entries; + if ($env{'environment.remote'} eq 'off' + && $env{'request.state'} eq 'construct') { + $body_args{'only_body'} = 1; + } } $body_args{'no_auto_mt_title'} = 1; my $page_start = &Apache::loncommon::start_page($name,$extra_head, \%body_args); - + $page_start .= $pageheader; if (!defined($found{'body'}) && $env{'request.state'} ne 'construct' && ($target eq 'web' || $target eq 'webgrade')) { @@ -199,7 +253,7 @@ sub page_start { } } - if (!defined($found{'body'})) { + if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') { $page_start .= &Apache::lonxml::message_location(); } @@ -299,32 +353,44 @@ sub remember_problem_state { '; } +sub problem_edit_buttons { + return ' +
+ + + +
+
+ + +
'; +} + sub problem_edit_header { - return ''. + return ''. &Apache::structuretags::remember_problem_state().'
'.&mt('Problem Editing').&Apache::loncommon::help_open_menu('Problem Editing','Problem_Editor_XML_Index',5,'Authoring').' -
-
- - - - -
-
- - -
+
'. +&problem_edit_buttons().'
+'.&Apache::lonxml::message_location().' '. '
'; } sub problem_edit_footer { - return '

- '. + return '
+ +'. + &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()). "\n\n".&Apache::loncommon::end_page(); } @@ -361,8 +427,8 @@ sub problem_web_to_edit_header { &mt(' Show All Instances') : &mt(' Show All Foils'); - my $show_all= ''; @@ -387,8 +453,9 @@ sub problem_web_to_edit_header { $show_all @@ -421,7 +488,6 @@ $show_all $show_all "; } - $result.=' '.&mt('Apply style file: ').' @@ -429,6 +495,9 @@ $show_all '.&mt('Select').' +
'. + &Apache::lonxml::renderingoptions().' +
@@ -446,8 +515,9 @@ $show_all if (!$numtoanalyze) { $numtoanalyze=20; } $result .= ''. &mt('[_1] for [_2] versions.', - '', - '' + ,''). &Apache::loncommon::help_open_topic("Analyze_Problem",'',undef,undef,300). ''; @@ -456,13 +526,17 @@ $show_all $result.=' -
'; - $result.=''; - $result .= ''; - $result .= ''; - +
+
'; + $result.=''; + $result .= ''; + $result .= ''; $result.='
+
+ '.&Apache::lonxml::message_location().'
'; return $result; } @@ -506,12 +580,19 @@ sub initialize_storage { if ($temp =~ m/^error:.*/) { %Apache::lonhomework::history=(); } } -# -------------------------------------------------------------finalize_storage -# Stores away the result has to a student's environment -# checks form.grade_ for specific values, other wises stores -# to the running users environment -# Will increment totals for attempts, students, and corrects -# if running user has student role. +=pod + +=item finalize_storage() + + Stores away the result has to a student's environment + checks form.grade_ for specific values, other wises stores + to the running users environment + Will increment totals for attempts, students, and corrects + if running user has student role. + +=cut + + sub finalize_storage { my ($given_symb) = @_; my $result; @@ -542,10 +623,16 @@ sub finalize_storage { return $result; } -# -------------------------------------------------------------store_aggregates -# Sends hash of values to be incremented in nohist_resourcetracker.db -# for the course. Increments total number of attempts, unique students -# and corrects for each part for an instance of a problem, as appropriate. +=pod + +item store_aggregates() + + Sends hash of values to be incremented in nohist_resourcetracker.db + for the course. Increments total number of attempts, unique students + and corrects for each part for an instance of a problem, as appropriate. + +=cut + sub store_aggregates { my ($symb,$courseid) = @_; my %aggregate; @@ -593,10 +680,8 @@ sub checkout_msg { return (<$lt{'resource'}

$lt{'id_expln'}

- -

$lt{'warning'}

-
-
+

$lt{'warning'}

+
@@ -605,17 +690,37 @@ ENDCHECKOUT sub firstaccess_msg { my ($time,$symb)=@_; - my ($map)=&Apache::lonnet::decode_symb($symb); - my $foldertitle=&Apache::lonnet::gettitle($map); - &Apache::lonxml::debug("map is $map title is $foldertitle"); + my $result; + my @interval=&Apache::lonnet::EXT("resource.0.interval"); + if ($interval[1] eq 'map') { + my ($map)=&Apache::lonnet::decode_symb($symb); + my $foldertitle=&Apache::lonnet::gettitle($map); + + &Apache::lonxml::debug("map is $map title is $foldertitle"); + $result .= "

".&mt('The resources in "[_1]" are open for a limited time.' + .' Once you click the "Show Resource" button below you have [_2] to complete all resources "[_1]".' + ,$foldertitle,$time)."

"; + } elsif ($interval[1] eq 'course') { + my $course = $env{'course.'.$env{'request.course.id'}.'.description'}; + $result .= "

".&mt('The resources in "[_1]" are open for a limited time.' + .' Once you click the "Show Resource" button below you have [_2] to complete all resources "[_1]".' + ,$course,$time)."

"; + } else { + my $title=&Apache::lonnet::gettitle($symb); + $result .= "

".&mt('This resource "[_1]" is open for a limited time.' + .' Once you click the "Show Resource" button below you have [_2] to complete this resource "[_1]".' + ,$title,$time)."

"; + } 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". -
+ my $buttontext = &mt('Show Resource'); + my $timertext = &mt('Start Timer?'); + $result .= (< - + ENDCHECKOUT + return $result; } sub init_problem_globals { @@ -720,9 +825,10 @@ sub start_problem { } if ($target ne 'analyze') { - $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type'); + my $type = &Apache::lonnet::EXT('resource.0.type'); + $Apache::lonhomework::type=$type; if (($env{'request.state'} eq 'construct') && - defined($env{'form.problemtype'})) { + $env{'form.problemtype'} =~ /\S/) { $Apache::lonhomework::type=$env{'form.problemtype'}; } &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:"); @@ -783,7 +889,8 @@ sub start_problem { $result.=&Apache::lonxml::printtokenheader($target,$token); } if ($env{'form.markaccess'}) { - &Apache::lonnet::set_first_access('map'); + my @interval=&Apache::lonnet::EXT("resource.0.interval"); + &Apache::lonnet::set_first_access($interval[1]); } #handle rand seed in construction space my $rndseed=&setup_rndseed($safeeval); @@ -801,13 +908,16 @@ sub start_problem { } if ($env{'request.role.adv'}) { $form_tag_start.= - '