--- loncom/homework/structuretags.pm 2008/05/27 19:48:55 1.420
+++ loncom/homework/structuretags.pm 2010/08/09 23:39:50 1.461.2.1
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.420 2008/05/27 19:48:55 www Exp $
+# $Id: structuretags.pm,v 1.461.2.1 2010/08/09 23:39:50 raeburn 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 =
@@ -148,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;
@@ -166,6 +203,7 @@ sub page_start {
}
}
+ my $pageheader = '';
if (defined($found{'body'})) {
$body_args{'skip_phases'}{'body'}=1;
} elsif (!defined($found{'body'})
@@ -174,6 +212,22 @@ sub page_start {
if ($env{'environment.remote'} ne 'off') {
$body_args{'only_body'} = 1;
}
+ # Breadcrumbs for Construction Space
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb({
+ 'text' => 'Construction Space',
+ 'href' => &Apache::loncommon::authorspace(),
+ });
+ # breadcrumbs (and tools) will be created
+ # in start_page->bodytag->innerregister
+
+# FIXME Where are we?
+# &Apache::lonhtmlcommon::add_breadcrumb({
+# 'text' => 'Problem Editing', # 'Problem Testing'
+# 'href' => '',
+# });
+ $pageheader =&Apache::loncommon::head_subbox(
+ &Apache::loncommon::CSTR_pageheader());
}
} elsif (!defined($found{'body'})) {
my %add_entries;
@@ -185,31 +239,34 @@ 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')) {
-
- my ($symb,undef,undef,undef,$publicuser)= &Apache::lonnet::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;
- }
+ unless ($env{'request.gcicontext'} eq 'buildtest') {
+ if (!defined($found{'body'})
+ && $env{'request.state'} ne 'construct'
+ && ($target eq 'web' || $target eq 'webgrade')) {
+
+ my ($symb,undef,undef,undef,$publicuser)= &Apache::lonnet::whichuser();
+ if ($symb eq '' && !$publicuser) {
+ $page_start .= '
' + .&mt('Browsing resource, all submissions are temporary.') + .'
'; + } + } } if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') { @@ -219,7 +276,8 @@ sub page_start { my $form_tag_start; if (!defined($found{'form'})) { $form_tag_start=''; } -sub problem_edit_header { - return ''. - &Apache::structuretags::remember_problem_state().' -';
+ '
'. @@ -388,12 +441,14 @@ sub problem_web_to_edit_header { my $show_all_foils_text = ($Apache::lonhomework::parsing_a_task) ? - &mt(' Show All Instances') - : &mt(' Show All Foils'); + &mt('Show All Instances') + : &mt('Show All Foils'); - my $show_all= ''; + my $show_all= ''; @@ -417,8 +472,9 @@ sub problem_web_to_edit_header { $show_all @@ -451,34 +507,21 @@ $show_all $show_all "; } - if (($env{'form.problemlanguage'}) && ($env{'form.problemlanguage'}!~/notset/)) { - $env{'environment.languages'}=$env{'form.problemlanguage'}; - } - my %langchoices=('' => ''); - foreach (&Apache::loncommon::languageids()) { - if (&Apache::loncommon::supportedlanguagecode($_)) { - $langchoices{&Apache::loncommon::supportedlanguagecode($_)} - = &Apache::loncommon::plainlanguagedescription($_); - } - } $result.=' '.&mt('Apply style file: ').' &').'" /> '.&mt('Select').' -
- '.
- &mt('Language: ').
- &Apache::loncommon::select_form($env{'environment.languages'},'problemlanguage',
- %langchoices).'
-
+
+ '.
+ &Apache::lonxml::renderingoptions().'
- +
@@ -502,7 +545,8 @@ $show_all
$result.='
- ';
+ ';
return $result;
@@ -554,12 +599,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;
@@ -590,13 +642,23 @@ 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;
+ my (%aggregate,%subtracker);
+ my $tracksub;
+ if ($symb =~ m{^uploaded/gcitest/$LONCAPA::match_courseid/default_1261144274.sequence___\d+___gci/gci/}) {
+ $tracksub = 1;
+ }
my @parts;
my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cname = $env{'course.'.$env{'request.course.id'}.'.num'};
@@ -611,6 +673,9 @@ sub store_aggregates {
$Apache::lonhomework::results{'resource.'.$part.'.award'}
eq 'EXACT_ANS') {
$aggregate{$symb."\0".$part."\0correct"} = 1;
+ if ($tracksub) {
+ $subtracker{$env{'user.name'}.':'.$env{'user.domain'}."\0correct"} ++;
+ }
}
if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) {
$aggregate{$symb."\0".$part."\0users"} = 1;
@@ -623,11 +688,22 @@ sub store_aggregates {
}
}
$aggregate{$symb."\0".$part."\0attempts"} = 1;
+ if ($tracksub) {
+ if ($Apache::lonhomework::type eq 'survey') {
+ $subtracker{$env{'user.name'}.':'.$env{'user.domain'}."\0surveysubs"} ++;
+ } else {
+ $subtracker{$env{'user.name'}.':'.$env{'user.domain'}."\0attempts"} ++;
+ }
+ }
}
if (keys (%aggregate) > 0) {
&Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
$cdomain,$cname);
}
+ if (keys(%subtracker) > 0) {
+ &Apache::lonnet::cinc('nohist_submissiontracker',\%subtracker,
+ $cdomain,$cname);
+ }
}
sub checkout_msg {
@@ -641,10 +717,8 @@ sub checkout_msg {
return (<+ ';
$result.='';
$result .= '';
@@ -510,6 +554,7 @@ $show_all
'onclick="javascript:setmode(this.form,'."'editxml'".')" />';
$result.='
+ '.&Apache::lonxml::message_location().' $lt{'id_expln'} - -$lt{'warning'} - - @@ -678,7 +752,7 @@ sub firstaccess_msg { my $buttontext = &mt('Show Resource'); my $timertext = &mt('Start Timer?'); $result .= (<'.&mt('Practice Problem').''. - ''.&mt('Submissions are not permanently recorded').''; + $form_tag_start.=&practice_problem_header(); + } + unless ($env{'request.gcicontext'} eq 'buildtest') { + $form_tag_start.=''; } - $form_tag_start.=' '; } ($status,$accessmsg,my $slot_name,my $slot) = @@ -907,6 +987,8 @@ sub start_problem { 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 eq 'NOT_IN_A_SLOT') { + $msg.=''.&mt('You are not currently signed up to work at this time and/or place.').''; } elsif ($status ne 'NOT_YET_VIEWED') { $msg.=''.&mt('Not open to be viewed').''; } @@ -917,13 +999,13 @@ sub start_problem { } elsif ($status eq 'NOT_YET_VIEWED') { $msg.=&firstaccess_msg($accessmsg,$symb); } elsif ($status eq 'NOT_IN_A_SLOT') { - $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work."); + $msg.=&Apache::bridgetask::add_request_another_attempt_button("Sign up for time to work"); } $result.=$msg.''; } elsif ($target eq 'tex') { my $startminipage = ($env{'form.problem_split'}=~/yes/i)? '' : '\begin{minipage}{\textwidth}'; - $result.='\begin{document}\noindent \vskip 1 mm '. + $result.='\noindent \vskip 1 mm '. $startminipage.'\vskip 0 mm'; if ($status eq 'UNAVAILABLE') { $result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm '; @@ -954,6 +1036,11 @@ sub start_problem { # create a page header and exit if ($env{'request.state'} eq "construct") { $result.= &problem_web_to_edit_header($env{'form.rndseed'}); + if ($Apache::lonhomework::type eq 'practice') { + $result.= ''. + &practice_problem_header().' '; + } } # if we are viewing someone else preserve that info if (defined $env{'form.grade_symb'}) { @@ -1019,7 +1106,7 @@ sub end_problem { $allow_print_points=0; } my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header'); - my $begin_doc='\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource "'.$name_of_resourse.'"located in'.$env{'request.uri'}.' STAMPOFPASSEDRESOURCEEND} \noindent '; + my $begin_doc=' \typeout{STAMPOFPASSEDRESOURCESTART Resource "'.$name_of_resourse.'"located in'.$env{'request.uri'}.' STAMPOFPASSEDRESOURCEEND} \noindent '; my $toc_line='\vskip 1 mm\noindent '.$startminipage. '\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}'; @@ -1029,6 +1116,8 @@ sub end_problem { my $duetime = &Apache::lonnet::EXT("resource.$id.duedate"); my $duedate = POSIX::strftime("%c",localtime($duetime)); + my $duedate_text = &mt('Due date: [_1]' + ,&Apache::lonlocal::locallocaltime($duetime)); my $temp_file; my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due"; @@ -1060,13 +1149,13 @@ sub end_problem { if (not $env{'request.symb'} =~ m/\.page_/) { if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') { $frontmatter .= $begin_doc. - '\textit{Due date: '.$duedate.'} '.$toc_line; + '\textit{'.$duedate_text.'} '.$toc_line; } else { $frontmatter.= $begin_doc.$toc_line; if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';} } } else { - $frontmatter .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\'.$startminipage; + $frontmatter .= '\vskip 1mm\textit{'.$duedate_text.'} \\\\\\\\'.$startminipage; } } else { if (not $env{'request.symb'} =~ m/\.page_/) { @@ -1189,6 +1278,11 @@ sub start_library { $result.=" \n $form_tag_start". ''; $result.=&problem_web_to_edit_header($rndseed); + if ($Apache::lonhomework::type eq 'practice') { + $result.= ''. + &practice_problem_header().' '; + } } return $result; } @@ -1289,7 +1383,7 @@ sub start_languageblock { $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { my $include = $token->[2]->{'include'}; my $exclude = $token->[2]->{'exclude'}; - my @preferred_languages=&Apache::loncommon::preferred_languages(); + my @preferred_languages=&Apache::lonlocal::preferred_languages(); # This should not even happen, since we should at least have the server language if (!$preferred_languages[0]) { $preferred_languages[0]='en'; } # Now loop over all languages in order of preference @@ -1396,7 +1490,17 @@ sub end_languageblock { my $result = &Apache::lonxml::endredirection(); my $which = &Apache::lonxml::get_param('which',$parstack, $safeeval); - $available_texts{$which} = $result; + if ($which=~/\w/) { + $available_texts{$which} = $result; + } + my $otherlangs = &Apache::lonxml::get_param('other',$parstack, + $safeeval); + foreach my $language (split(/\s*\,\s*/,$otherlangs)) { + if ($language=~/\w/) { + $available_texts{$language} = $result; + } + } + } return ''; } @@ -1493,7 +1597,7 @@ sub end_while { $return = &Apache::run::run($code,$safeeval); } if ($error) { - &Apache::lonxml::error(' '.&mt('Code ran too long. It ran for more than').' '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' '.&mt('seconds occured while running <while> on line').' '.$line.''); + &Apache::lonxml::error(' '.&mt('Code ran too long. It ran for more than').' '.$Apache::lonnet::perlvar{'lonScriptTimeout'}.' '.&mt('seconds occurred while running <while> on line').' '.$line.''); } } elsif ($target eq "edit") { $result.= &Apache::edit::tag_end($target,$token,''); @@ -1547,6 +1651,20 @@ sub start_randomlist { my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval); $showarg--; if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; } + if (($target eq 'analyze') && ($env{'form.check_parts_withrandomlist'})) { + my @currlist; + my $part = $Apache::inputtags::part; + if ($part ne '') { + if (ref($Apache::lonhomework::analyze{'parts_withrandomlist'}) eq 'ARRAY') { + my @currlist = @{$Apache::lonhomework::analyze{'parts_withrandomlist'}}; + if (!(grep(/^\Q$part\E$/,@currlist))) { + push(@{$Apache::lonhomework::analyze{'parts_withrandomlist'}},$part); + } + } else { + push(@{$Apache::lonhomework::analyze{'parts_withrandomlist'}},$part); + } + } + } for(0 .. $show) { $bodytext .= "$randomlist[ $idx_arr[$_] ]"; } @@ -1853,7 +1971,8 @@ sub start_problemtype { $result .=&Apache::edit::checked_arg('When used as type(s):','for', [ ['exam','Exam/Quiz Problem'], ['survey','Survey'], - ['problem','Homework Problem'] ] + ['problem','Homework Problem'], + ['practice','Practice Problem'] ] ,$token); $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); } elsif ($target eq 'modified') { @@ -1886,17 +2005,23 @@ sub end_startouttext { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; my $text=''; - if ($target eq 'edit') { + my $areaid = 'homework_edit_'.$Apache::lonxml::curdepth; $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style); - $result.=&Apache::edit::start_table($token)." ".&mt('Text Block')." |
-".&mt('Delete:').
- &Apache::edit::deletelist($target,$token)
- ." |
-".
- &Apache::edit::insertlist($target,$token).
- ' | ' .
- &Apache::loncommon::helpLatexCheatsheet().
+ $result.=&Apache::edit::start_table($token)." | ".&mt('Text Block')." | "
+ .''.&mt('Delete?').' '
+ .&Apache::edit::deletelist($target,$token)
+ .' | ';
+ unless ($env{'environment.wysiwygeditor'} eq 'on') {
+ $result .= ''
+ .&Apache::lonhtmlcommon::dragmath_button($areaid,1)
+ .' | '
+ .''
+ .&Apache::edit::insertlist($target,$token)
+ .' | ';
+ }
+ $result.='' .
+ &Apache::loncommon::helpLatexCheatsheet().
&Apache::edit::end_row().
&Apache::edit::start_spanning_row()."\n".
&Apache::edit::editfield($token->[1],$text,"",80,8,1);
@@ -1959,9 +2084,17 @@ sub start_simpleeditbutton {
my $url=$env{'request.noversionuri'};
$url=~s/\?.*$//;
my ($symb) = &Apache::lonnet::whichuser();
- $result=' |
'; +# Warning makes more sense and is more important on edit screen +# $result=' ' +# .&mt('Note: it can take up to 10 minutes for changes to take effect for all users.') +# .&Apache::loncommon::help_open_topic('Caching') +# .' '; + $result.=&Apache::lonhtmlcommon::start_funclist() + .&Apache::lonhtmlcommon::add_item_funclist( + '' + .&mt('Edit').'') + .&Apache::lonhtmlcommon::end_funclist(); + } return $result; } @@ -1970,5 +2103,17 @@ sub end_simpleeditbutton { return ''; } +sub practice_problem_header { + return ''.&mt('Practice Problem').''. + ''.&mt('Submissions are not permanently recorded'). + ''; +} + 1; __END__ + +=pod + +=back + +=cut |