--- loncom/homework/structuretags.pm 2004/02/16 20:30:34 1.242 +++ loncom/homework/structuretags.pm 2007/09/11 23:53:05 1.397 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.242 2004/02/16 20:30:34 albertel Exp $ +# $Id: structuretags.pm,v 1.397 2007/09/11 23:53:05 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,9 +25,7 @@ # # http://www.lon-capa.org/ # -# 2/19 Guy -# 6/26/2001 fixed extra web display at end of tags -# 8/17,8/18,8/20 Gerd Kortemeyer +### package Apache::structuretags; @@ -38,17 +36,30 @@ 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','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','startouttext','endouttext','simpleeditbutton','definetag')); } sub start_web { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - my $bodytext=&Apache::lonxml::get_all_text("/web",$parser); - if ($target eq 'web') { - return $bodytext; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if ($target ne 'edit' && $target ne 'modified') { + my $bodytext=&Apache::lonxml::get_all_text("/web",$parser,$style); + if ($target eq 'web' || $target eq 'webgrade') { + return $bodytext; + } + } elsif ($target eq "edit" ) { + my $bodytext = + &Apache::lonxml::get_all_text_unbalanced("/web",$parser); + my $result = &Apache::edit::tag_start($target,$token); + $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1); + return $result; + } elsif ( $target eq "modified" ) { + return $token->[4].&Apache::edit::modifiedfield("/web",$parser); } return ''; } @@ -58,11 +69,21 @@ sub end_web { } sub start_tex { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; - my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser); - if ($target eq 'tex') { - return $bodytext.' '; + if ($target ne 'edit' && $target ne 'modified') { + my $bodytext=&Apache::lonxml::get_all_text("/tex",$parser,$style); + if ($target eq 'tex') { + return $bodytext.' '; + } + } elsif ($target eq "edit" ) { + my $bodytext = + &Apache::lonxml::get_all_text_unbalanced("/tex",$parser); + my $result = &Apache::edit::tag_start($target,$token); + $result .= &Apache::edit::editfield($token->[1],$bodytext,'',80,1); + return $result; + } elsif ( $target eq "modified" ) { + return $token->[4].&Apache::edit::modifiedfield("/tex",$parser); } return $result;; } @@ -72,7 +93,8 @@ sub end_tex { } sub page_start { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name, + $extra_head)=@_; my %found; foreach my $taginside (@$tagstack) { foreach my $taglookedfor ('html','body','form') { @@ -80,130 +102,207 @@ sub page_start { } } - my $result; - my $head_tag_start; - if (!defined($found{'html'})) { - $result=&Apache::londefdef::start_html($target,$token,$tagstack, - $parstack,$parser,$safeeval); - $head_tag_start=''.&Apache::lonmenu::registerurl(undef,$target); + if ($target eq 'tex') { + return + &Apache::londefdef::start_html($target,$token,$tagstack, + $parstack,$parser,$safeeval); + } + + $extra_head.= ' + +'; + + my %body_args; + if (defined($found{'html'})) { + $body_args{'skip_phases'}{'head'}=1; + } else { + + $extra_head .= &Apache::lonhtmlcommon::spellheader(); + + $extra_head .= &Apache::londefdef::generate_css_links(); + + if ($env{'request.state'} eq 'construct') { + $extra_head.=&Apache::edit::js_change_detection(). + "\n"; + } } - my $body_tag_start; - if (!defined($found{'body'})) { - $body_tag_start='"; - $body_tag_start.=$help; - } + + my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack, + $safeeval); + 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{'no_auto_mt_title'} = 1; + 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::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 (!defined($found{'body'})) { + $page_start .= &Apache::lonxml::message_location(); + } + my $form_tag_start; if (!defined($found{'form'})) { - $form_tag_start='
'; + $form_tag_start=''."\n"; + } } - return ($result,$head_tag_start,$body_tag_start,$form_tag_start); + return ($page_start,$form_tag_start); } #use Time::HiRes(); sub get_resource_name { my ($parstack,$safeeval)=@_; + my $name; if (defined($Apache::lonhomework::name)) { - return $Apache::lonhomework::name; - } - my $name=&Apache::lonnet::gettitle(); - if ($name eq '') { - $name=&Apache::lonnet::EXT('resource.title'); - if ($name eq 'con_lost') { $name = ''; } - } - if ($name!~/\S+/) { - $name=$ENV{'request.uri'}; - $name=~s-.*/([^/]+)$-$1-; + $name = $Apache::lonhomework::name; + } else { + my ($symb)=&Apache::lonnet::whichuser(); + $name=&Apache::lonnet::gettitle($symb); + if ($name eq '') { + $name=&Apache::lonnet::EXT('resource.title'); + if ($name eq 'con_lost') { $name = ''; } + } + if ($name!~/\S+/) { + $name=$env{'request.uri'}; + $name=~s-.*/([^/]+)$-$1-; + } + # The name has had html tags escaped: + + $name=~s/<//gs; + + $Apache::lonhomework::name=$name; } - $Apache::lonhomework::name=$name; return $name; } sub setup_rndseed { my ($safeeval)=@_; my $rndseed; - my ($symb)=&Apache::lonxml::whichuser(); - if ($ENV{'request.state'} eq "construct" || $symb eq '') { - $rndseed=$ENV{'form.rndseed'}; + my ($symb)=&Apache::lonnet::whichuser(); + if ($env{'request.state'} eq "construct" + || $symb eq '' + || $Apache::lonhomework::type eq 'practice' + || $Apache::lonhomework::history{'resource.CODE'}) { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['rndseed']); + $rndseed=$env{'form.rndseed'}; if (!$rndseed) { $rndseed=$Apache::lonhomework::history{'rndseed'}; if (!$rndseed) { $rndseed=time; } - $ENV{'form.rndseed'}=$rndseed; + $env{'form.rndseed'}=$rndseed; } - if ($ENV{'form.resetdata'} eq &mt('New Problem Variation') || - $ENV{'form.newrandomization'} eq &mt('New Randomization')) { + if ( ($env{'form.resetdata'} eq &mt('New Problem Variation') + && $env{'form.submitted'} eq 'yes') || + $env{'form.newrandomization'} eq &mt('New Randomization')) { srand(time); $rndseed=int(rand(2100000000)); - $ENV{'form.rndseed'}=$rndseed; - delete($ENV{'form.resetdata'}); - delete($ENV{'form.newrandomization'}); + $env{'form.rndseed'}=$rndseed; + delete($env{'form.resetdata'}); + delete($env{'form.newrandomization'}); } if (defined($rndseed) && $rndseed ne int($rndseed)) { - $rndseed=join(',',&Math::Random::random_seed_from_phrase($rndseed)); + $rndseed=join(':',&Apache::lonnet::digest($rndseed)); } + if ($Apache::lonhomework::history{'resource.CODE'}) { + $rndseed=&Apache::lonnet::rndseed(); + } if ($safeeval) { &Apache::lonxml::debug("Setting rndseed to $rndseed"); - &Apache::run::run('$external::randomseed='.$rndseed.';',$safeeval); + &Apache::run::run('$external::randomseed="'.$rndseed.'";',$safeeval); } } return $rndseed; } +sub remember_problem_state { + return ' + + + '; +} + sub problem_edit_header { - return ' + return ''. + &Apache::structuretags::remember_problem_state().' - - -
- -
'. - &Apache::loncommon::help_open_topic('Problem_Editor_XML_Index', - 'Problem Editing Help').''. - &Apache::loncommon::help_open_faq(5). - &Apache::loncommon::help_open_bug('Authoring').'
'. - '
'; + + +
+ +
'. + &Apache::loncommon::help_open_menu('Problem Editing Help','Problem_Editor_XML_Index',5,'Authoring',undef,undef,undef,'Problem Editing Help') + .'
'. + '
'; } sub problem_edit_footer { return '

- '; + '. + &Apache::lonhtmlcommon::htmlareaselectactive(&Apache::lonhtmlcommon::get_htmlareafields()). + "\n\n".&Apache::loncommon::end_page(); } sub option { my ($value,$name) = @_; my $result =" ".&option('problem','problemtype').&mt("Homework problem")." ".&option('survey' ,'problemtype').&mt("Survey Question")." @@ -257,31 +368,67 @@ Feedback Mode:
"; - my $numtoanalyze=$ENV{'form.numtoanalyze'}; - if (!$numtoanalyze) { $numtoanalyze=20; } - $result.= ' for + my $numtoanalyze=$env{'form.numtoanalyze'}; + if (!$numtoanalyze) { $numtoanalyze=20; } + $result.= ' for '.&mt('versions of this problem'). '.'.&Apache::loncommon::help_open_topic("Analyze_Problem", '',undef,undef,300). '
'; + } elsif ($Apache::lonhomework::parsing_a_task) { + $result.=" + +Problem Status: + + + +
"; + } return $result; } sub initialize_storage { - %Apache::lonhomework::results=(); - %Apache::lonhomework::history=(); - my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); - if ($ENV{'request.state'} eq 'construct' || $symb eq '') { + my ($given_symb) = @_; + undef(%Apache::lonhomework::results); + undef(%Apache::lonhomework::history); + my ($symb,$courseid,$domain,$name) = + &Apache::lonnet::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') { + + my $namespace = $symb || $env{'request.uri'}; + if ($env{'form.resetdata'} eq &mt('Reset Submissions') || + ($env{'form.resetdata'} eq &mt('New Problem Variation') + && $env{'form.submitted'} eq 'yes') || + $env{'form.newrandomization'} eq &mt('New Randomization')) { + &Apache::lonnet::tmpreset($namespace,'',$domain,$name); + &Apache::lonxml::debug("Attempt reset"); + } %Apache::lonhomework::history= - &Apache::lonnet::tmprestore($ENV{'request.uri'},'',$domain,$name); + &Apache::lonnet::tmprestore($namespace,'',$domain,$name); my ($temp)=keys %Apache::lonhomework::history ; &Apache::lonxml::debug("Return message of $temp"); } else { %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=(); } @@ -291,25 +438,78 @@ sub initialize_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. sub finalize_storage { + my ($given_symb) = @_; my $result; - my ($temp) = keys %Apache::lonhomework::results; - if ( $temp ne '' ) { - my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); - if ($ENV{'request.state'} eq 'construct' || $symb eq '') { - $Apache::lonhomework::results{'rndseed'}=$ENV{'form.rndseed'}; + if (%Apache::lonhomework::results) { + my @remove = grep(/^INTERNAL_/,keys(%Apache::lonhomework::results)); + delete(@Apache::lonhomework::results{@remove}); + my ($symb,$courseid,$domain,$name) = + &Apache::lonnet::whichuser($given_symb); + if ($env{'request.state'} eq 'construct' + || $symb eq '' + || $Apache::lonhomework::type eq 'practice') { + my $namespace = $symb || $env{'request.uri'}; + $Apache::lonhomework::results{'rndseed'}=$env{'form.rndseed'}; $result=&Apache::lonnet::tmpstore(\%Apache::lonhomework::results, - $ENV{'request.uri'},'',$domain,$name); + $namespace,'',$domain,$name); &Apache::lonxml::debug('Construct Store return message:'.$result); } else { $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); + } } + } else { + &Apache::lonxml::debug('Nothing to store'); } 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. +sub store_aggregates { + my ($symb,$courseid) = @_; + my %aggregate; + my @parts; + my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cname = $env{'course.'.$env{'request.course.id'}.'.num'}; + foreach my $key (keys(%Apache::lonhomework::results)) { + if ($key =~ /resource\.([^\.]+)\.tries/) { + push(@parts, $1); + } + } + 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 ($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 (keys (%aggregate) > 0) { + &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate, + $cdomain,$cname); + } +} + sub checkout_msg { my %lt=&Apache::lonlocal::texthash( 'resource'=>'The resource needs to be checked out', @@ -317,31 +517,58 @@ 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'}

-
+
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 $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". +
+ + +
+ENDCHECKOUT +} + sub init_problem_globals { my ($type)=@_; #initialize globals + # For problems, we start out in part 0 (outside a tag). + # and part 0 is used to describe the main body of the + # if ($type eq 'problem') { $Apache::inputtags::part='0'; @Apache::inputtags::partlist=('0'); + $Apache::lonhomework::problemstatus=&get_problem_status('0'); + $Apache::lonhomework::ignore_response_errors=0; - $Apache::lonhomework::problemstatus=&get_problem_status('0') - } else { + } elsif ($type eq 'library') { $Apache::inputtags::part=''; @Apache::inputtags::partlist=(); $Apache::lonhomework::problemstatus=''; + $Apache::lonhomework::ignore_response_errors=1; + + } elsif ($type eq 'Task') { + $Apache::inputtags::part='0'; + @Apache::inputtags::partlist=('0'); + $Apache::lonhomework::problemstatus=''; + $Apache::lonhomework::ignore_response_errors=1; } @Apache::inputtags::responselist = (); @Apache::inputtags::importlist = (); @@ -353,7 +580,8 @@ sub init_problem_globals { @Apache::structuretags::whileline=(); $Apache::lonhomework::scantronmode=0; undef($Apache::lonhomework::name); - + undef($Apache::lonhomework::default_type); + undef($Apache::lonhomework::type); } sub reset_problem_globals { @@ -365,11 +593,16 @@ 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 { my ($part)=@_; - if ($ENV{'form.problemstate'} eq 'CANNOT_ANSWER_correct') { + if ($env{'form.problemstate'} eq 'CANNOT_ANSWER_correct') { $Apache::lonhomework::history{"resource.$part.solved"}= 'correct_by_student'; } @@ -377,48 +610,53 @@ sub set_problem_state { sub get_problem_status { my ($part)=@_; - my $problem_status=&Apache::lonnet::EXT("resource.$part.problemstatus"); - &Apache::lonxml::debug("problem status for $part is $problem_status"); - &Apache::lonxml::debug("env probstat is ".$ENV{'form.problemstatus'}); - if ($ENV{'request.state'} eq 'construct' && - defined($ENV{'form.problemstatus'})) { - $problem_status=$ENV{'form.problemstatus'}; + my $problem_status; + if ($env{'request.state'} eq 'construct' && + defined($env{'form.problemstatus'})) { + $problem_status=$env{'form.problemstatus'}; + } else { + $problem_status=&Apache::lonnet::EXT("resource.$part.problemstatus"); + &Apache::lonxml::debug("problem status for $part is $problem_status"); + &Apache::lonxml::debug("env probstat is ".$env{'form.problemstatus'}); } return $problem_status; } sub start_problem { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + + # We'll use the redirection to fix up printing of duedates. + if (!$Apache::lonxml::metamode) { + &Apache::lonxml::startredirection(); + } + # Problems don't nest and we don't allow more than one in + # a .problem file. + # if ( $Apache::inputtags::part ne '' || $Apache::lonhomework::parsing_a_problem) { &Apache::lonxml::error('Only one <problem> allowed in a .problem file'); - #my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser); + #my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser,$style); return ''; } $Apache::lonhomework::parsing_a_problem=1; &init_problem_globals('problem'); - if (defined($ENV{'scantron.maxquest'})) { + if (defined($env{'scantron.maxquest'})) { $Apache::lonhomework::scantronmode=1; } if ($target ne 'analyze') { - &initialize_storage(); - if ($target eq 'web') { - &Apache::lonhomework::showhash(%Apache::lonhomework::history); - } - if ($ENV{'request.state'} eq 'construct') { &set_problem_state('0'); } $Apache::lonhomework::type=&Apache::lonnet::EXT('resource.0.type'); - if (($ENV{'request.state'} eq 'construct') && - defined($ENV{'form.problemtype'})) { - $Apache::lonhomework::type=$ENV{'form.problemtype'}; + if (($env{'request.state'} eq 'construct') && + defined($env{'form.problemtype'})) { + $Apache::lonhomework::type=$env{'form.problemtype'}; } - &Apache::lonxml::debug("Found this to be of type :$Apache::ltonhomework::type:"); + &Apache::lonxml::debug("Found this to be of type :$Apache::lonhomework::type:"); } if ($Apache::lonhomework::type eq '' ) { - my $uri=$ENV{'request.uri'}; + my $uri=$env{'request.uri'}; if ($uri=~/\.(\w+)$/) { $Apache::lonhomework::type=$1; &Apache::lonxml::debug("Using type of $1"); @@ -427,17 +665,36 @@ sub start_problem { &Apache::lonxml::debug("Using default type, problem, :$uri:"); } } + $Apache::lonhomework::default_type = $Apache::lonhomework::type; + + &initialize_storage(); + if ($target ne 'analyze' + && $env{'request.state'} eq 'construct') { + &set_problem_state('0'); + } + + if ($target eq 'web') { + &Apache::lonxml::debug(" grading history "); + &Apache::lonhomework::showhash(%Apache::lonhomework::history); + } #added vars to the scripting enviroment my $expression='$external::part=\''.$Apache::inputtags::part.'\';'; + $expression.='$external::type=\''.$Apache::lonhomework::type.'\';'; &Apache::run::run($expression,$safeeval); 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); - if ($target eq 'tex' and $ENV{'request.symb'} =~ m/\.page_/) {$result='';} + 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); } if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || @@ -446,135 +703,131 @@ sub start_problem { if ($Apache::lonhomework::type eq 'exam') { my $token= $Apache::lonhomework::history{"resource.0.outtoken"}; - if (($ENV{'form.doescheckout'}) && (!$token)) { + if (($env{'form.doescheckout'}) && (!$token)) { $token=&Apache::lonxml::maketoken(); $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'); } - #handle rand seed in construction space my $rndseed=&setup_rndseed($safeeval); - my ($symb)=&Apache::lonxml::whichuser(); - if ($ENV{'request.state'} ne "construct" && $symb eq '') { + my ($symb)=&Apache::lonnet::whichuser(); + if ($env{'request.state'} ne "construct" && + ($symb eq '' || $Apache::lonhomework::type eq 'practice')) { $form_tag_start.=''. ''. + value="'.&mt('New Problem Variation').'" />'; + if (exists($env{'form.username'})) { + $form_tag_start.= '
'; + value="'.$env{'form.username'}.'" />'; + } + if ($env{'request.role.adv'}) { + $form_tag_start.= + '
'.$skip.'
'; return $result; } @@ -723,10 +1095,10 @@ 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 (defined($code) && $code ne '') { if (!$Apache::lonxml::default_homework_loaded) { &Apache::lonxml::default_homework_load($safeeval); } @@ -767,21 +1139,29 @@ 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(); + my $preferred_language=(&Apache::loncommon::preferred_languages)[0]; +# This should not even happen, since we should at least have the server language + if (!$preferred_language) { $preferred_language='en'; } +# If the languageblock has no arguments, show the contents $result='1'; +# Do we have an include argument? if ($include) { +# If include is specified, by default, don't render the block $result=''; - foreach (split(/\,/,$include)) { - if ($languages{$_}) { $result='1'; } + foreach my $included_language (split(/\,/,$include)) { +# ... but if my preferred language is included, render it + if ($included_language eq $preferred_language) { $result='1'; } } } +# Do we have an exclude argument? if ($exclude) { - foreach (split(/\,/,$exclude)) { - if ($languages{$_}) { $result='0'; } + $result='1'; + foreach my $excluded_language (split(/\,/,$exclude)) { + if ($excluded_language eq $preferred_language) { $result='0'; } } } if ( ! $result ) { @@ -815,15 +1195,65 @@ sub end_languageblock { return $result; } +{ + my %available_texts; + sub start_translated { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + &Apache::lonxml::register('Apache::structuretags',('lang')); + undef(%available_texts); + } + + sub end_translated { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $result; + #show the translation on viewable targets + if ($target eq 'web' || $target eq 'tex' || $target eq 'webgrade'|| + # or non-viewable targets, if it's embedded in something that + # wants the output + (($target eq 'answer' || $target eq 'analyze'|| $target eq 'grade') + && &Apache::lonxml::in_redirection() ) ) { + my @possibilities = keys(%available_texts); + my $which = + &Apache::loncommon::languages(\@possibilities) || 'default'; + $result = $available_texts{$which}; + } + undef(%available_texts); + &Apache::lonxml::deregister('Apache::structuretags',('lang')); + return $result; + } + + + sub start_lang { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { + &Apache::lonxml::startredirection(); + } + return ''; + } + + sub end_lang { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || + $target eq 'tex' || $target eq 'analyze' || $target eq 'webgrade') { + my $result = &Apache::lonxml::endredirection(); + my $which = &Apache::lonxml::get_param('which',$parstack, + $safeeval); + $available_texts{$which} = $result; + } + return ''; + } +} + sub start_instructorcomment { 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') { - $result=($ENV{'request.role'}=~/^(in|cc|au|ca|li)/); - if ( ! $result ) { + 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", $parser,$style); &Apache::lonxml::debug("skipping ahead :$skip: $$parser[-1]"); @@ -846,11 +1276,11 @@ sub end_instructorcomment { } sub start_while { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + 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); @@ -858,7 +1288,7 @@ sub start_while { &Apache::lonxml::default_homework_load($safeeval); } my $result = &Apache::run::run($code,$safeeval); - my $bodytext=&Apache::lonxml::get_all_text("/while",$parser); + my $bodytext=&Apache::lonxml::get_all_text("/while",$parser,$style); push( @Apache::structuretags::whilebody, $bodytext); push( @Apache::structuretags::whileline, $token->[5]); &Apache::lonxml::debug("s code $code got -$result-"); @@ -882,8 +1312,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); @@ -896,10 +1326,17 @@ sub end_while { $return = 0; $error=1; next; } $result.=&Apache::scripttag::xmlparse($bodytext); + if ($target eq 'grade' || $target eq 'answer' || + $target eq 'analyze') { + # grade/answer/analyze should produce no output but if we + # are redirecting, the redirecter should know what to do + # with the output + if (!$Apache::lonxml::redirection) { undef($result); } + } $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$gt; on line').' '.$line.'
'); + &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.'
'); } } elsif ($target eq "edit") { $result.= &Apache::edit::tag_end($target,$token,''); @@ -914,12 +1351,14 @@ sub end_while { # ... # sub start_randomlist { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + 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::TokeParser->new(\$body); + my $b_parser= HTML::LCParser->new(\$body); + $b_parser->xml_mode(1); + $b_parser->marked_sections(1); my $b_tok; my @randomlist; my $list_item; @@ -943,17 +1382,19 @@ sub start_randomlist { # print "END-TAG $b_tok->[1]
"; # } } - my @idx_arr = (0 .. $#randomlist); - &Apache::structuretags::shuffle(\@idx_arr); - my $bodytext = ''; - my $show=$#randomlist; - my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval); - $showarg--; - if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; } - for(0 .. $show) { - $bodytext .= "$randomlist[ $idx_arr[$_] ]"; + if (@randomlist) { + my @idx_arr = (0 .. $#randomlist); + &Apache::structuretags::shuffle(\@idx_arr); + my $bodytext = ''; + my $show=$#randomlist; + my $showarg=&Apache::lonxml::get_param('show',$parstack,$safeeval); + $showarg--; + if ( ($showarg >= 0) && ($showarg < $show) ) { $show = $showarg; } + for(0 .. $show) { + $bodytext .= "$randomlist[ $idx_arr[$_] ]"; + } + &Apache::lonxml::newparser($parser,\$bodytext); } - &Apache::lonxml::newparser($parser,\$bodytext); } elsif ($target eq 'edit' ) { $result .=&Apache::edit::tag_start($target,$token); $result .=&Apache::edit::text_arg('Maximum Tags to Show:','show', @@ -970,13 +1411,14 @@ sub start_randomlist { sub shuffle { my $a=shift; my $i; - if (defined(@$a)) { - &Apache::response::setrandomnumber(); + if (ref($a) eq 'ARRAY' && @$a) { + &Apache::response::pushrandomnumber(); for($i=@$a;--$i;) { my $j=int(&Math::Random::random_uniform() * ($i+1)); next if $i == $j; @$a[$i,$j] = @$a[$j,$i]; } + &Apache::response::poprandomnumber(); } } @@ -990,11 +1432,25 @@ sub end_randomlist { return $result; } +sub ordered_show_check { + my $last_part=$Apache::inputtags::partlist[-2]; + my $in_order= + &Apache::lonnet::EXT('resource.'.$Apache::inputtags::part.'.ordered'); + my $in_order_show=1; + if ($last_part ne '0' && lc($in_order) eq 'yes') { + $in_order_show=&Apache::response::check_status($last_part); + } + return $in_order_show; +} + sub start_part { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + if (!$Apache::lonxml::metamode) { + &Apache::lonxml::startredirection(); # we'll use redirection to fix up + # duedates. + } my $result=''; - my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval); - if ($id eq '') { $id = $Apache::lonxml::curdepth; } + my $id= &Apache::lonxml::get_id($parstack,$safeeval); $Apache::inputtags::part=$id; push(@Apache::inputtags::partlist,$id); @Apache::inputtags::response=(); @@ -1002,7 +1458,11 @@ sub start_part { @Apache::inputtags::previous_version=(); $Apache::lonhomework::problemstatus=&get_problem_status($id); my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part); + my $newtype=&Apache::lonnet::EXT("resource.$id.type"); + if ($newtype) { $Apache::lonhomework::type=$newtype; } + my $in_order_show=&ordered_show_check(); my $expression='$external::part=\''.$Apache::inputtags::part.'\';'; + $expression.='$external::type=\''.$Apache::lonhomework::type.'\';'; &Apache::run::run($expression,$safeeval); if ($target eq 'meta') { @@ -1011,27 +1471,29 @@ sub start_part { &Apache::response::meta_parameter_write('display','string',$display,'Part Description'); } elsif ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { - if ($hidden) { - my $bodytext=&Apache::lonxml::get_all_text("/part",$parser); + if ($hidden || !$in_order_show) { + my $bodytext=&Apache::lonxml::get_all_text("/part",$parser,$style); } else { my ($status,$accessmsg) = &Apache::lonhomework::check_access($id); push (@Apache::inputtags::status,$status); my $expression='$external::datestatus="'.$status.'";'; $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$id.solved"}.'";'; &Apache::run::run($expression,$safeeval); - if ($ENV{'request.state'} eq 'construct') { + if ($env{'request.state'} eq 'construct') { &set_problem_state($Apache::inputtags::part); } if (( $status eq 'CLOSED' ) || ( $status eq 'UNCHECKEDOUT') || + ( $status eq 'NOT_YET_VIEWED') || ( $status eq 'BANNED') || ( $status eq 'UNAVAILABLE') || ( $status eq 'INVALID_ACCESS')) { - my $bodytext=&Apache::lonxml::get_all_text("/part",$parser); + my $bodytext=&Apache::lonxml::get_all_text("/part",$parser, + $style); if ( $target eq "web" ) { $result="
".&mt('Part is not open to be viewed. It')." $accessmsg
"; } elsif ( $target eq 'tex' ) { - if (not $ENV{'form.problem_split'}=~/yes/) { + if (not $env{'form.problem_split'}=~/yes/) { $result="\\end{minipage}\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\\\begin{minipage}{\\textwidth}"; } else { $result="\\vskip 0 mm ".&mt('Part is not open to be viewed. It')." $accessmsg \\\\"; @@ -1039,11 +1501,15 @@ sub start_part { } } else { if ($target eq 'tex') { - if (not $ENV{'form.problem_split'}=~/yes/) { - $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent'; + if (not $env{'form.problem_split'}=~/yes/) { + if ($$tagstack[-2] eq 'td') { + $result.='\noindent \begin{minipage}{\textwidth}\noindent'; + } else { + $result.='\noindent \end{minipage}\vskip 0 mm \noindent \begin{minipage}{\textwidth}\noindent'; + } } my $weight = &Apache::lonnet::EXT("resource.$id.weight"); - my $allkeys=&Apache::lonnet::metadata($ENV{'request.uri'},'packages'); + my $allkeys=&Apache::lonnet::metadata($env{'request.uri'},'packages'); my @allkeys = split /,/,$allkeys; my $allow_print_points = 0; foreach my $partial_key (@allkeys) { @@ -1051,9 +1517,17 @@ sub start_part { if ($1 ne '0') {$allow_print_points=1;} } } + my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); + if (defined($maxtries) && $maxtries < 0) { + $allow_print_points=0; + } + if (lc($env{'course.'.$env{'request.course.id'}. + '.disableexampointprint'}) eq 'yes') { + $allow_print_points=0; + } if (($Apache::lonhomework::type eq 'exam') && ($allow_print_points)) { $result .= '\fbox{\textit{'.$weight.' pt}}';} } elsif ($target eq 'web') { - $result.=''; + $result.=''; } } } @@ -1071,7 +1545,6 @@ sub start_part { #limiting ids to only letters numbers, and space $token->[2]->{'id'}=~s/[^A-Za-z0-9 ]//gs; $result = &Apache::edit::rebuild_tag($token); - $result.=&Apache::edit::handle_insert(); } } return $result; @@ -1082,36 +1555,50 @@ sub end_part { &Apache::lonxml::debug("in end_part $target "); my $status=$Apache::inputtags::status['-1']; my $hidden=&Apache::loncommon::check_if_partid_hidden($Apache::inputtags::part); - my $result=''; - if ( $target eq 'meta' ) { - $result=''; - } elsif ($target eq 'grade' && - ($status eq 'CAN_ANSWER' || $Apache::lonhomework::scantronmode) && - !$hidden) { - $result=&Apache::inputtags::grade; - } elsif (($target eq 'web' || $target eq 'tex') && !$hidden ) { + my $in_order_show=&ordered_show_check(); + my $result; + if (!$Apache::lonxml::metamode) { + $result = &Apache::lonxml::endredirection(); # started in &start_part + $Apache::lonxml::post_evaluate=0; + } + if ($target eq 'grade') { + if (($status eq 'CAN_ANSWER' || $Apache::lonhomework::scantronmode) && + !$hidden && $in_order_show) { + $result.=&Apache::inputtags::grade; + } else { + # move any submission data to .hidden + &Apache::inputtags::hidealldata($Apache::inputtags::part); + } + } elsif (($target eq 'web' || $target eq 'tex') && + !$hidden && $in_order_show) { my $gradestatus=&Apache::inputtags::gradestatus($Apache::inputtags::part, $target); if ($Apache::lonhomework::type eq 'exam' && $target eq 'tex') { $gradestatus=''; } - $result=$gradestatus; + $result.=$gradestatus; + if ($$tagstack[-2] eq 'td' and $target eq 'tex') {$result.='\end{minipage}';} } elsif ($target eq 'edit') { - $result=&Apache::edit::end_table(); + $result.=&Apache::edit::end_table(); + } elsif ($target eq 'modified') { + $result .= $token->[2]; } pop @Apache::inputtags::status; $Apache::inputtags::part=''; + $Apache::lonhomework::type = $Apache::lonhomework::default_type; return $result; } sub start_preduedate { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + 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::inputtags::status['-1'] ne 'CAN_ANSWER' && + if (!$Apache::lonhomework::scantronmode && + $Apache::inputtags::status['-1'] ne 'CAN_ANSWER' && $Apache::inputtags::status['-1'] ne 'CANNOT_ANSWER') { &Apache::lonxml::debug("Wha? ". ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER')); - &Apache::lonxml::get_all_text("/preduedate",$parser); + &Apache::lonxml::get_all_text("/preduedate",$parser,$style); } } return ''; @@ -1121,14 +1608,21 @@ sub end_preduedate { return ''; } +# In all the modes where text is +# displayable, all we do is eat up the text between the start/stop +# tags if the conditions are not right to display it. sub start_postanswerdate { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - if ($target eq 'web' || $target eq 'grade') { - if ($Apache::inputtags::status['-1'] ne 'SHOW_ANSWER') { - &Apache::lonxml::get_all_text("/postanswerdate",$parser); + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + my $pav = &Apache::lonnet::allowed('pav', $env{'request.course.id'}) || + &Apache::lonnet::allowed('pav', + $env{'request.course.id'}.'/'.$env{'request.course.sec'}); + if ($target eq 'web' || $target eq 'grade' || $target eq 'webgrade' || + $target eq 'tex' ) { + if ($Apache::lonhomework::scantronmode || + $Apache::inputtags::status['-1'] ne 'SHOW_ANSWER' || + (($target eq 'tex') && !$pav)) { + &Apache::lonxml::get_all_text("/postanswerdate",$parser,$style); } - } elsif ($target eq 'tex') { - &Apache::lonxml::get_all_text("/postanswerdate",$parser); } return ''; } @@ -1138,15 +1632,15 @@ sub end_postanswerdate { } sub start_notsolved { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + 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/ && &Apache::response::show_answer()) { &Apache::lonxml::debug("skipping"); - &Apache::lonxml::get_all_text("/notsolved",$parser); + &Apache::lonxml::get_all_text("/notsolved",$parser,$style); } } return ''; @@ -1157,13 +1651,13 @@ sub end_notsolved { } sub start_solved { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' || $target eq 'tex') { my $gradestatus=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"}; if ($gradestatus !~ /^correct/ || !&Apache::response::show_answer()) { - &Apache::lonxml::get_all_text("/solved",$parser); + &Apache::lonxml::get_all_text("/solved",$parser,$style); } } return ''; @@ -1173,6 +1667,48 @@ sub end_solved { return ''; } +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' || $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); + my $found=0; + foreach my $type (split(',',$for)) { + if ($Apache::lonhomework::type eq lc($type)) { $found=1; } + } + if ($mode eq 'show' && !$found) { + &Apache::lonxml::get_all_text("/problemtype",$parser,$style); + } + if ($mode eq 'hide' && $found) { + &Apache::lonxml::get_all_text("/problemtype",$parser,$style); + } + } elsif ($target eq 'edit') { + $result .=&Apache::edit::tag_start($target,$token); + $result.=&Apache::edit::select_arg('Mode:','mode', + [['show','Show'], + ['hide','Hide']] + ,$token); + $result .=&Apache::edit::checked_arg('When used as type(s):','for', + [ ['exam','Exam/Quiz Problem'], + ['survey','Survey'], + ['problem','Homework Problem'] ] + ,$token); + $result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); + } elsif ($target eq 'modified') { + my $constructtag=&Apache::edit::get_new_args($token,$parstack, + $safeeval,'mode','for'); + if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } + } + return $result; +} + +sub end_problemtype { + return ''; +} + sub start_startouttext { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my @result=(''.''); @@ -1181,22 +1717,23 @@ sub start_startouttext { } sub end_startouttext { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $result=''; my $text=''; if ($target eq 'edit') { - $text=&Apache::lonxml::get_all_text("endouttext",$parser); + $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(). &Apache::edit::end_row(). - &Apache::edit::start_spanning_row()."\n" - . &Apache::loncommon::helpLatexCheatsheet () . - &Apache::edit::editfield($token->[1],$text,"",80,4); + &Apache::edit::start_spanning_row()."\n". + &Apache::edit::editfield($token->[1],$text,"",80,8,1); } if ($target eq 'modified') { $result=''.&Apache::edit::modifiedfield("endouttext",$parser); @@ -1213,7 +1750,8 @@ sub start_endouttext { if ($target eq "edit" ) { $result="".&Apache::edit::end_table()."\n"; } if ($target eq "modified") { $result=''. - &Apache::edit::handle_insertafter('startouttext'); } + &Apache::edit::handle_insertafter('startouttext'); + } return $result; } @@ -1225,8 +1763,8 @@ sub end_endouttext { } sub delete_startouttext { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; - # my $text=&Apache::lonxml::get_all_text("endouttext",$parser); + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + # my $text=&Apache::lonxml::get_all_text("endouttext",$parser,$style); my $text=$$parser['-1']->get_text("/endouttext"); my $ntoken=$$parser['-1']->get_token(); &Apache::lonxml::debug("Deleting :$text: and :$ntoken->[0]:$ntoken->[1]:$ntoken->[2]: for startouttext"); @@ -1241,12 +1779,14 @@ sub delete_startouttext { sub start_simpleeditbutton { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result=''; - if (($target eq 'web') && - (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))) { - my $url=$ENV{'request.noversionuri'}; + if (($env{'form.simple_edit_button'} ne 'off') && + ($target eq 'web') && + (&Apache::lonnet::allowed('mdc',$env{'request.course.id'}))) { + my $url=$env{'request.noversionuri'}; $url=~s/\?.*$//; + my ($symb) = &Apache::lonnet::whichuser(); $result='
'. - ''.&mt('Simple Problem Editor').' - '.&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;