--- loncom/interface/lonhelper.pm 2006/05/30 21:48:00 1.153 +++ loncom/interface/lonhelper.pm 2008/12/19 20:51:35 1.169 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.153 2006/05/30 21:48:00 foxr Exp $ +# $Id: lonhelper.pm,v 1.169 2008/12/19 20:51:35 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -81,25 +81,28 @@ State tags are also required to have an human name of the state, and will be displayed as the header on top of the screen for the user. +State tags may also optionally have an attribute "help" which should be +the filename of a help file, this will add a blue ? to the title. + =head2 Example Helper Skeleton An example of the tags so far: - + -Of course this does nothing. In order for the wizard to do something, it is -necessary to put actual elements into the wizard. Documentation for each +Of course this does nothing. In order for the helper to do something, it is +necessary to put actual elements into the helper. Documentation for each of these elements follows. =head1 Creating a Helper With Code, Not XML -In some situations, such as the printing wizard (see lonprintout.pm), +In some situations, such as the printing helper (see lonprintout.pm), writing the helper in XML would be too complicated, because of scope issues or the fact that the code actually outweighs the XML. It is possible to create a helper via code, though it is a little odd. @@ -185,7 +188,6 @@ use Apache::lonlocal; use Apache::lonnet; use Apache::longroup; use Apache::lonselstudent; -use lib '/home/httpd/lib/perl/'; use LONCAPA; # Register all the tags with the helper, so the helper can @@ -335,7 +337,8 @@ sub start_state { } Apache::lonhelper::state->new($token->[2]{'name'}, - $token->[2]{'title'}); + $token->[2]{'title'}, + $token->[2]{'help'}); return ''; } @@ -365,6 +368,7 @@ use Apache::loncommon; use Apache::File; use Apache::lonlocal; use Apache::lonnet; +use LONCAPA; sub new { my $proto = shift; @@ -470,9 +474,8 @@ sub _saveVars { sub _varsInFile { my $self = shift; my @vars = (); - for my $key (keys %{$self->{VARS}}) { - push @vars, &Apache::lonnet::escape($key) . '=' . - &Apache::lonnet::escape($self->{VARS}->{$key}); + for my $key (keys(%{$self->{VARS}})) { + push(@vars, &escape($key) . '=' . &escape($self->{VARS}->{$key})); } return join ('&', @vars); } @@ -487,7 +490,7 @@ sub declareVar { $self->{VARS}->{$var} = ''; } - my $envname = 'form.' . $var . '.forminput'; + my $envname = 'form.' . $var . '_forminput'; if (defined($env{$envname})) { if (ref($env{$envname})) { $self->{VARS}->{$var} = join('|||', @{$env{$envname}}); @@ -578,6 +581,7 @@ sub display { # Phase 4: Display. my $stateTitle=&mt($state->title()); + my $stateHelp= $state->help(); my $browser_searcher_js = ' - + RADIO $env{'form.condition'} = !$self->{'toponly'}; @@ -2207,6 +2430,7 @@ RADIO 'resource_no_folder_link' => 1, 'closeAllPages' => $self->{'closeallpages'}, 'suppressEmptySequences' => $self->{'suppressEmptySequences'}, + 'include_top_level_map' => $self->{'include_top_level_map'}, 'iterator_map' => $mapUrl } ); @@ -2358,6 +2582,7 @@ sub render { # Current personel + $result .= '

'.&mt('Select Currently Enrolled Students and Active Course Personnel').'

'; $result .= &Apache::lonselstudent::render_student_list( $current_members, "helpform", "current", @@ -2369,10 +2594,12 @@ sub render { # If activeonly is not set then we can also give the expired students: # - if (!$self->{'activeonly'} && ((scalar @$expired_members) > 0)) { + if (!$self->{'activeonly'} && ((scalar(@$future_members)) > 0)) { # And future. + $result .= '

'.&mt('Select Future Enrolled Students and Future Course Personnel').'

'; + $result .= &Apache::lonselstudent::render_student_list( $future_members, "helpform", "future", @@ -2380,8 +2607,11 @@ sub render { $self->{'multichoice'}, $self->{'variable'}, 0); + } + if (!$self->{'activeonly'} && ((scalar(@$expired_members)) > 0)) { # Past + $result .= '

'.&mt('Select Previously Enrolled Students and Inactive Course Personnel').'

'; $result .= &Apache::lonselstudent::render_student_list($expired_members, "helpform", "past", @@ -2399,7 +2629,7 @@ sub render { sub postprocess { my $self = shift; - my $result = $env{'form.' . $self->{'variable'} . '.forminput'}; + my $result = $env{'form.' . $self->{'variable'} . '_forminput'}; if (!$result && !$self->{'emptyallowed'}) { if ($self->{'coursepersonnel'}) { $self->{ERROR_MSG} = @@ -2584,7 +2814,7 @@ sub render { function checkall(value, checkName) { for (i=0; i" . "{'multichoice'} && $choices == 0) { $result .= ' checked="checked"'; @@ -2762,7 +2992,7 @@ sub fileState { sub postprocess { my $self = shift; - my $result = $env{'form.' . $self->{'variable'} . '.forminput'}; + my $result = $env{'form.' . $self->{'variable'} . '_forminput'}; if (!$result) { $self->{ERROR_MSG} = 'You must choose at least one file '. 'to continue.'; @@ -2998,7 +3228,7 @@ sub render { $result .= '

' . $self->{ERROR_MSG} . '

'; } - $result .= '{'variable'} . '_forminput"'; if (defined($self->{'size'})) { $result .= ' size="' . $self->{'size'} . '"'; @@ -3131,7 +3361,8 @@ sub start_clause { die 'Error in clause of condition, Perl said: ' . $@ if $@; if (!&$clause($helper, $paramHash)) { # Discard all text until the /condition. - &Apache::lonxml::get_all_text('/condition', $parser); + my $end_tag = $paramHash->{SKIPTAG} || '/condition'; + &Apache::lonxml::get_all_text($end_tag, $parser); } } @@ -3336,7 +3567,7 @@ sub overrideForm { package Apache::lonhelper::parmwizfinal; -# This is the final state for the parmwizard. It is not generally useful, +# This is the final state for the parm helper. It is not generally useful, # so it is not perldoc'ed. It does its own processing. # It is represented with , and # should later be moved to lonparmset.pm . @@ -3402,7 +3633,7 @@ sub render { # Print the granularity, depending on the action if ($vars->{GRANULARITY} eq 'whole_course') { - $resourceString .= '
  • '.&mt('for all resources in the course').'
  • '; + $resourceString .= '
  • '.&mt('for [_1]all resources in the course[_2]','','').'
  • '; if ($vars->{TARGETS} eq 'course') { $level = 14; # general course, see lonparmset.pm perldoc } elsif ($vars->{TARGETS} eq 'section') { @@ -3417,10 +3648,16 @@ sub render { $paramlevel = 'general'; } elsif ($vars->{GRANULARITY} eq 'map') { my $navmap = Apache::lonnavmaps::navmap->new(); - my $res = $navmap->getByMapPc($vars->{RESOURCE_ID}); - my $title = $res->compTitle(); - $symb = $res->symb(); - $resourceString .= '
  • '.&mt('for the map named [_1]',"$title").'
  • '; + if (defined($navmap)) { + my $res = $navmap->getByMapPc($vars->{RESOURCE_ID}); + my $title = $res->compTitle(); + $symb = $res->symb(); + $resourceString .= '
  • '.&mt('for the map named [_1]',"$title").'
  • '; + } else { + $resourceString .= '
  • '.&mt('for the map ID [_1] (name unavailable)',''.$vars->{RESOURCE_ID}.'').'
  • '; + &Apache::lonnet::logthis('Retrieval of map title failed in lonhelper.pm - could not create navmap object for course.'); + + } if ($vars->{TARGETS} eq 'course') { $level = 13; # general course, see lonparmset.pm perldoc } elsif ($vars->{TARGETS} eq 'section') { @@ -3433,13 +3670,18 @@ sub render { $affectedResourceId = $vars->{RESOURCE_ID}; $paramlevel = 'map'; } else { - my $navmap = Apache::lonnavmaps::navmap->new(); - my $res = $navmap->getById($vars->{RESOURCE_ID}); my $part = $vars->{RESOURCE_ID_part}; if ($part ne 'All Parts' && $part) { $parm_name=~s/^0/$part/; } else { $part=&mt('All Parts'); } - $symb = $res->symb(); - my $title = $res->compTitle(); - $resourceString .= '
  • '.&mt('for the resource named [_1] part [_2]',"$title","$part").'
  • '; + my $navmap = Apache::lonnavmaps::navmap->new(); + if (defined($navmap)) { + my $res = $navmap->getById($vars->{RESOURCE_ID}); + $symb = $res->symb(); + my $title = $res->compTitle(); + $resourceString .= '
  • '.&mt('for the resource named [_1] part [_2]',"$title","$part").'
  • '; + } else { + $resourceString .= '
  • '.&mt('for the resource ID [_1] (name unavailable) part [_2]',''.$vars->{RESOURCE_ID}.'',"$part").'
  • '; + &Apache::lonnet::logthis('Retrieval of resource title failed in lonhelper.pm - could not create navmap object for course.'); + } if ($vars->{TARGETS} eq 'course') { $level = 10; # general course, see lonparmset.pm perldoc } elsif ($vars->{TARGETS} eq 'section') { @@ -3518,7 +3760,7 @@ sub render { # Print targets if ($vars->{TARGETS} eq 'course') { - $result .= '
  • '.&mt('for all students in course').'
  • '; + $result .= '
  • '.&mt('for [_1]all students in course[_2]','','').'
  • '; } elsif ($vars->{TARGETS} eq 'section') { my $section = $vars->{SECTION_NAME}; $result .= '
  • '.&mt('for section [_1]',"$section").'
  • '; @@ -3543,7 +3785,8 @@ sub render { # Print value if ($vars->{ACTION_TYPE} ne 'tries' && $vars->{ACTION_TYPE} ne 'weight') { - $result .= '
  • '.&mt('to [_1] ([_2])',"".ctime($vars->{PARM_DATE})."",Apache::lonnavmaps::timeToHumanString($vars->{PARM_DATE}))."
  • \n"; + my $showdate = &Apache::lonlocal::locallocaltime($vars->{PARM_DATE}); + $result .= '
  • '.&mt('to [_1] ([_2])',"".$showdate."",Apache::lonnavmaps::timeToHumanString($vars->{PARM_DATE}))."
  • \n"; } # print pres_marker