--- loncom/homework/structuretags.pm 2008/11/25 13:16:17 1.435 +++ loncom/homework/structuretags.pm 2010/08/08 02:00:50 1.474 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.435 2008/11/25 13:16:17 jms Exp $ +# $Id: structuretags.pm,v 1.474 2010/08/08 02:00:50 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -66,7 +66,7 @@ use lib '/home/httpd/lib/perl/'; use LONCAPA; BEGIN { - &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')); + &Apache::lonxml::register('Apache::structuretags',('block','languageblock','translated','instructorcomment','while','randomlist','problem','library','web','tex','part','preduedate','postanswerdate','solved','notsolved','problemtype','startpartmarker','startouttext','endpartmarker','endouttext','simpleeditbutton','definetag')); } sub start_web { @@ -177,12 +177,13 @@ sub page_start { $parstack,$parser,$safeeval); } - $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"); + $extra_head .= &homework_js(). + &Apache::lonhtmlcommon::dragmath_js("EditMathPopup"); + if (&Apache::lonhtmlcommon::htmlareabrowser()) { + my %textarea_args = ( + dragmath => 'math', + ); + $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args); } my %body_args; @@ -203,14 +204,28 @@ sub page_start { } } + my $pageheader = ''; 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') { - 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; @@ -222,31 +237,30 @@ 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{'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; - } + if ($symb eq '' && !$publicuser) { + $page_start .= '

' + .&mt('Browsing resource, all submissions are temporary.') + .'

'; + } } if (!defined($found{'body'}) && $env{'request.state'} ne 'construct') { @@ -256,7 +270,9 @@ sub page_start { my $form_tag_start; if (!defined($found{'form'})) { $form_tag_start='
'. &problem_edit_buttons().' -
+
'.&Apache::lonxml::message_location().' '. - ''; + $result.=&Apache::edit::end_table(); + + } + return $result; +} + +sub end_startpartmarker { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my @result; + if ($target eq 'edit') { $result[1]='no'; } + return @result; +} + +sub start_endpartmarker { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $result=''; + if ($target eq 'edit') { + $result=&Apache::edit::tag_start($target,$token); + $result.=&mt('Marker for the end of a part. Place start marker above to wrap in-between tags into a new part.').''; + $result.=&Apache::edit::end_table(); + + } + return $result; +} + +sub end_endpartmarker { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my @result; + if ($target eq 'edit') { $result[1]='no'; } + return @result; +} + + + + + sub start_part { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; if (!$Apache::lonxml::metamode) { @@ -1736,7 +1830,10 @@ sub start_part { '.disableexampointprint'}) eq 'yes') { $allow_print_points=0; } - if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { $result .= '\fbox{\textit{'.$weight.' pt}}';} + if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { + $result .= '\vskip 10mm\fbox{\textit{'.$weight.' pt}}'; + + } } elsif ($target eq 'web') { $result.=''; } @@ -1905,6 +2002,9 @@ sub start_problemtype { $result .=&Apache::edit::checked_arg('When used as type(s):','for', [ ['exam','Exam/Quiz Problem'], ['survey','Survey'], + ['surveycred','Survey (with credit)'], + ['anonsurvey','Anonymous Survey'], + ['anonsurveycred','Anonymous Survey (with credit)'], ['problem','Homework Problem'], ['practice','Practice Problem'] ] ,$token); @@ -1942,21 +2042,18 @@ sub end_startouttext { 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)." -"; - unless ($env{'environment.wysiwygeditor'} eq 'on') { - $result .= '' - .''; - } - $result.='" + .'' + .'' + .'' + .'
'; + '
'; } sub problem_edit_footer { return '

'. - - &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()). "\n\n".&Apache::loncommon::end_page(); } @@ -420,12 +434,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= ''; @@ -451,6 +467,9 @@ sub problem_web_to_edit_header { ".&option('exam' ,'problemtype').&mt("Exam Problem")." ".&option('problem','problemtype').&mt("Homework Problem")." ".&option('survey' ,'problemtype').&mt("Survey Question")." + ".&option('surveycred' ,'problemtype').&mt("Survey Question (with credit)")." + ".&option('anonsurvey' ,'problemtype').&mt("Anonymous Survey Question")." + ".&option('anonsurveycred' ,'problemtype').&mt("Anonymous Survey Question (with credit)")." ".&option('practice' ,'problemtype').&mt("Practice Problem")." @@ -498,7 +517,7 @@ $show_all -
+
@@ -522,7 +541,8 @@ $show_all $result.='
-
'; +
+
'; $result.=''; $result .= ''; @@ -530,6 +550,7 @@ $show_all 'onclick="javascript:setmode(this.form,'."'editxml'".')" />'; $result.='
+
'.&Apache::lonxml::message_location().'
'; return $result; @@ -607,9 +628,7 @@ sub finalize_storage { $result=&Apache::lonnet::cstore(\%Apache::lonhomework::results, $symb,$courseid,$domain,$name); &Apache::lonxml::debug('Store return message:'.$result); - if ($env{'request.role'} =~/^st/) { - &store_aggregates($symb,$courseid); - } + &store_aggregates($symb,$courseid); } } else { &Apache::lonxml::debug('Nothing to store'); @@ -629,7 +648,7 @@ item store_aggregates() sub store_aggregates { my ($symb,$courseid) = @_; - my %aggregate; + my (%aggregate,%anoncounter); my @parts; my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cname = $env{'course.'.$env{'request.course.id'}.'.num'}; @@ -639,28 +658,51 @@ sub store_aggregates { } } foreach my $part (@parts) { - if ($Apache::lonhomework::results{'resource.'.$part.'.award'} - eq 'APPROX_ANS' || - $Apache::lonhomework::results{'resource.'.$part.'.award'} - eq 'EXACT_ANS') { - $aggregate{$symb."\0".$part."\0correct"} = 1; + if ($env{'request.role'} =~/^st/) { + if ($Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'APPROX_ANS' || + $Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'EXACT_ANS') { + $aggregate{$symb."\0".$part."\0correct"} = 1; + } + if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) { + $aggregate{$symb."\0".$part."\0users"} = 1; + } else { + my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]); + if ($last_reset) { + if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) { + $aggregate{$symb."\0".$part."\0users"} = 1; + } + } + } + $aggregate{$symb."\0".$part."\0attempts"} = 1; } - if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) { - $aggregate{$symb."\0".$part."\0users"} = 1; - } else { - my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]); - if ($last_reset) { - if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) { - $aggregate{$symb."\0".$part."\0users"} = 1; + if (($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurvey') || + ($Apache::lonhomework::results{'resource.'.$part.'.type'} eq 'anonsurveycred')) { + $anoncounter{$symb."\0".$part} = 1; + my $needsrelease = $Apache::lonnet::needsrelease{'parameter:type:'.$Apache::lonhomework::results{'resource.'.$part.'.type'}}; + if ($needsrelease) { + my $curr_required = $env{'course.'.$env{'request.course.id'}.'.internal.releaserequired'}; + if ($curr_required eq '') { + &Apache::lonnet::update_released_required($needsrelease); + } else { + my ($currmajor,$currminor) = split(/\./,$curr_required); + my ($needsmajor,$needsminor) = split(/\./,$needsrelease); + if (($currmajor < $needsmajor) || ($currmajor == $needsmajor && $currminor < $needsminor)) { + &Apache::lonnet::update_released_required($needsrelease); + } } } } - $aggregate{$symb."\0".$part."\0attempts"} = 1; } if (keys (%aggregate) > 0) { &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate, $cdomain,$cname); } + if (keys(%anoncounter) > 0) { + &Apache::lonnet::cinc('nohist_anonsurveys',\%anoncounter, + $cdomain,$cname); + } } sub checkout_msg { @@ -674,10 +716,8 @@ sub checkout_msg { return (<$lt{'resource'}

$lt{'id_expln'}

- -

$lt{'warning'}

-
-
+

$lt{'warning'}

+
@@ -711,7 +751,7 @@ sub firstaccess_msg { my $buttontext = &mt('Show Resource'); my $timertext = &mt('Start Timer?'); $result .= (< +
@@ -873,17 +913,6 @@ sub start_problem { if ($target eq 'analyze') { my $rndseed=&setup_rndseed($safeeval); } if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { - #handle exam checkout - if ($Apache::lonhomework::type eq 'exam') { - my $token= - $Apache::lonhomework::history{"resource.0.outtoken"}; - if (($env{'form.doescheckout'}) && (!$token)) { - $token=&Apache::lonxml::maketoken(); - $Apache::lonhomework::history{"resource.0.outtoken"}= - $token; - } - $result.=&Apache::lonxml::printtokenheader($target,$token); - } if ($env{'form.markaccess'}) { my @interval=&Apache::lonnet::EXT("resource.0.interval"); &Apache::lonnet::set_first_access($interval[1]); @@ -903,13 +932,14 @@ sub start_problem { value="'.$env{'form.username'}.'" />'; } if ($env{'request.role.adv'}) { - $form_tag_start.= - ' '; } if ($Apache::lonhomework::type eq 'practice') { $form_tag_start.=&practice_problem_header(); @@ -939,6 +969,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').'

'; } @@ -949,13 +981,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 '; @@ -1056,7 +1088,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.'}'; @@ -1066,6 +1098,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"; @@ -1097,18 +1131,22 @@ 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}}';} + 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_/) { $frontmatter .= $begin_doc.$toc_line; - if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';} + if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { + $frontmatter .= '\fbox{\textit{'.$weight.' pt}}'; + } } else { $frontmatter .= '\vskip 1mm \\\\\\\\'.$startminipage; } @@ -1144,7 +1182,6 @@ sub end_problem { if ($target ne 'tex' && $env{'form.answer_output_mode'} ne 'tex') { $result.=""; - $result.= &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()); } if ($target eq 'web') { $result.= &Apache::loncommon::end_page({'discussion' => 1}); @@ -1331,7 +1368,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 @@ -1461,7 +1498,7 @@ sub start_instructorcomment { 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)/); + $result=($env{'request.role'}=~/^(in|cc|co|au|ca|li)/); if ( (! $result) or ($env{'form.instructor_comments'} eq 'hide')) { my $skip=&Apache::lonxml::get_all_text("/instructorcomment", $parser,$style); @@ -1599,6 +1636,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[$_] ]"; } @@ -1652,6 +1703,49 @@ sub ordered_show_check { return $in_order_show; } + +sub start_startpartmarker { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my $result=''; + if ($target eq 'edit') { + $result=&Apache::edit::tag_start($target,$token); + $result.=&mt('Marker for the start of a part. Place end marker below to wrap in-between tags into a new part.').'
".&mt('Text Block')."".&mt('Delete:'). - &Apache::edit::deletelist($target,$token) - ."' - .&Apache::lonhtmlcommon::dragmath_button($areaid,1) - .'' - .&Apache::edit::insertlist($target,$token) - .'' . - &Apache::loncommon::helpLatexCheatsheet(). + $result.=&Apache::edit::start_table($token)."
".&mt('Text Block')."'.&mt('Delete?').' ' + .&Apache::edit::deletelist($target,$token) + .'' + .&Apache::lonhtmlcommon::dragmath_button($areaid,1) + .'' + .&Apache::edit::insertlist($target,$token) + .'' . + &Apache::loncommon::helpLatexCheatsheet(). &Apache::edit::end_row(). &Apache::edit::start_spanning_row()."\n". &Apache::edit::editfield($token->[1],$text,"",80,8,1); @@ -2019,9 +2116,17 @@ sub start_simpleeditbutton { my $url=$env{'request.noversionuri'}; $url=~s/\?.*$//; my ($symb) = &Apache::lonnet::whichuser(); - $result='
'. - ''.&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').'

'; +# 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; }