--- loncom/interface/lonhelper.pm 2003/05/08 20:10:49 1.26 +++ loncom/interface/lonhelper.pm 2003/05/12 19:33:57 1.27 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.26 2003/05/08 20:10:49 bowersj2 Exp $ +# $Id: lonhelper.pm,v 1.27 2003/05/12 19:33:57 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -234,6 +234,7 @@ sub real_handler { my $file; read $fh, $file, 100000000; + # Send header, don't cache this page if ($r->header_only) { if ($ENV{'browser.mathml'}) { @@ -2362,6 +2363,101 @@ sub end_eval { 1; +package Apache::lonhelper::final; + +=pod + +=head2 Element: final + + is a special element that works with helpers that use the +tag. It goes through all the states and elements, executing the +snippets and collecting the results. Finally, it takes the user out of the +helper, going to a provided page. + +=cut + +no strict; +@ISA = ("Apache::lonhelper::element"); +use strict; + +BEGIN { + &Apache::lonhelper::register('Apache::lonhelper::final', + ('final', 'exitpage')); +} + +sub new { + my $ref = Apache::lonhelper::element->new(); + bless($ref); +} + +sub start_final { return ''; } + +sub end_final { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + + if ($target ne 'helper') { + return ''; + } + + Apache::lonhelper::final->new(); + + return ''; +} + +sub start_exitpage { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + + if ($target ne 'helper') { + return ''; + } + + $paramHash->{EXIT_PAGE} = &Apache::lonxml::get_all_text('/exitpage', + $parser); + + return ''; +} + +sub end_exitpage { return ''; } + +sub render { + my $self = shift; + + my @results; + + # Collect all the results + for my $stateName (keys %{$helper->{STATES}}) { + my $state = $helper->{STATES}->{$stateName}; + + for my $element (@{$state->{ELEMENTS}}) { + if (defined($element->{FINAL_CODE})) { + # Compile the code. + my $code = 'sub { my $helper = shift; ' . $element->{FINAL_CODE} . + '}'; + $code = eval($code); + die 'Error while executing final code for element with var ' . + $element->{'variable'} . ', Perl said: ' . $@ if $@; + + my $result = &$code($helper); + if ($result) { + push @results, $result; + } + } + } + } + + if (scalar(@results) == 0) { + return ''; + } + + my $result = "
    \n"; + for my $re (@results) { + $result .= '
  • ' . $re . "
  • \n"; + } + return $result . '
'; +} + +1; + package Apache::lonhelper::parmwizfinal; # This is the final state for the parmwizard. It is not generally useful, @@ -2409,60 +2505,72 @@ sub render { 'due_date' => "0_duedate", 'answer_date' => "0_answerdate"); - my $result = "
\n"; - $result .= '

Confirm that this information is correct, then click "Finish Wizard" to complete setting the parameter.

    '; my $affectedResourceId = ""; my $parm_name = $parmTypeHash{$vars->{ACTION_TYPE}}; my $level = ""; - - # Print the type of manipulation: - $result .= '
  • Setting the ' . $dateTypeHash{$vars->{ACTION_TYPE}} - . "
  • \n"; - if ($vars->{ACTION_TYPE} eq 'due_date' || - $vars->{ACTION_TYPE} eq 'answer_date') { - # for due dates, we default to "date end" type entries - $result .= "\n"; - $result .= "\n"; - $result .= "\n"; - } elsif ($vars->{ACTION_TYPE} eq 'open_date') { - $result .= "\n"; - $result .= "\n"; - $result .= "\n"; - } - + my $resourceString; + my $symb; + my $paramlevel; + # Print the granularity, depending on the action if ($vars->{GRANULARITY} eq 'whole_course') { - $result .= '
  • for all resources in the course
  • '; + $resourceString .= '
  • for all resources in the course
  • '; $level = 9; # general course, see lonparmset.pm perldoc $affectedResourceId = "0.0"; + $symb = 'a'; + $paramlevel = 'general'; } elsif ($vars->{GRANULARITY} eq 'map') { my $navmap = Apache::lonnavmaps::navmap->new( $ENV{"request.course.fn"}.".db", $ENV{"request.course.fn"}."_parms.db", 0, 0); my $res = $navmap->getById($vars->{RESOURCE_ID}); my $title = $res->compTitle(); + $symb = $res->symb(); $navmap->untieHashes(); - $result .= "
  • for the map named $title
  • "; + $resourceString .= "
  • for the map named $title
  • "; $level = 8; $affectedResourceId = $vars->{RESOURCE_ID}; + $paramlevel = 'map'; } else { my $navmap = Apache::lonnavmaps::navmap->new( $ENV{"request.course.fn"}.".db", $ENV{"request.course.fn"}."_parms.db", 0, 0); my $res = $navmap->getById($vars->{RESOURCE_ID}); + $symb = $res->symb(); my $title = $res->compTitle(); $navmap->untieHashes(); - $result .= "
  • for the resource named $title
  • "; + $resourceString .= "
  • for the resource named $title
  • "; $level = 7; $affectedResourceId = $vars->{RESOURCE_ID}; + $paramlevel = 'full'; } + my $result = "\n"; + $result .= '

    Confirm that this information is correct, then click "Finish Wizard" to complete setting the parameter.

      '; + + # Print the type of manipulation: + $result .= '
    • Setting the ' . $dateTypeHash{$vars->{ACTION_TYPE}} + . "
    • \n"; + if ($vars->{ACTION_TYPE} eq 'due_date' || + $vars->{ACTION_TYPE} eq 'answer_date') { + # for due dates, we default to "date end" type entries + $result .= "\n"; + $result .= "\n"; + $result .= "\n"; + } elsif ($vars->{ACTION_TYPE} eq 'open_date') { + $result .= "\n"; + $result .= "\n"; + $result .= "\n"; + } + + $result .= $resourceString; + # Print targets if ($vars->{TARGETS} eq 'course') { $result .= '
    • for all students in course
    • '; @@ -2475,7 +2583,10 @@ sub render { } else { # FIXME: This is probably wasteful! Store the name! my $classlist = Apache::loncoursedata::get_classlist(); - my $name = $classlist->{$vars->{USER_NAME}}->[6]; + my $username = $vars->{USER_NAME}; + # Chop off everything after the last colon (section) + $username = substr($username, 0, rindex($username, ':')); + my $name = $classlist->{$username}->[6]; $result .= "
    • for $name
    • "; $level -= 6; my ($uname, $udom) = split /:/, $vars->{USER_NAME}; @@ -2493,6 +2604,12 @@ sub render { # print pres_marker $result .= "\n\n"; + + # Make the table appear + $result .= "\n"; + $result .= "\n"; + $result .= "\n"; + $result .= "\n"; $result .= "

      \n";