'.
+ &Apache::loncommon::end_data_table_row();
+ }
+ $output .= &Apache::loncommon::end_data_table();
+ $output .= &row_closure();
+ return $output;
+}
-Returns: string containing being and complete and
-as well as a '."\n";
+##############################################
+##############################################
- return $Str;
+# topic_bar
+#
+# Generates a div containing a numbered (static image) followed by a title
+# with a background color defined in the corresponding CSS: LC_topic_bar
+#
+sub topic_bar {
+ my ($imgnum,$title) = @_;
+ return '
'
+ .''
+ .' '.$title
+ .'
';
}
-########################################################
-########################################################
+##############################################
+##############################################
+
+# echo_form_input
+#
+# Generates html markup to add form elements from the referrer page
+# as hidden form elements (values encoded) in the new page.
+#
+# Intended to support two types of use
+# (a) to allow backing up to earlier pages in a multi-page
+# form submission process using a breadcrumb trail.
+#
+# (b) to allow the current page to be reloaded with form elements
+# set on previous page to remain unchanged. An example would
+# be where the a page containing a dynamically-built table of data is
+# is to be redisplayed, with only the sort order of the data changed.
+#
+# Inputs:
+# 1. Reference to array of form elements in the submitted form on
+# the referrer page which are to be excluded from the echoed elements.
+#
+# 2. Reference to array of regular expressions, which if matched in the
+# name of the form element n the referrer page will be omitted from echo.
+#
+# Outputs: A scalar containing the html markup for the echoed form
+# elements (all as hidden elements, with values encoded).
-=pod
-=item &CreateHeadings()
+sub echo_form_input {
+ my ($excluded,$regexps) = @_;
+ my $output = '';
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.(.+)$/) {
+ my $name = $1;
+ my $match = 0;
+ if ((!@{$excluded}) || (!grep/^$name$/,@{$excluded})) {
+ if (defined($regexps)) {
+ if (@{$regexps} > 0) {
+ foreach my $regexp (@{$regexps}) {
+ if ($name =~ /\Q$regexp\E/) {
+ $match = 1;
+ last;
+ }
+ }
+ }
+ }
+ if (!$match) {
+ if (ref($env{$key})) {
+ foreach my $value (@{$env{$key}}) {
+ $value = &HTML::Entities::encode($value,'<>&"');
+ $output .= ''."\n";
+ }
+ } else {
+ my $value = &HTML::Entities::encode($env{$key},'<>&"');
+ $output .= ''."\n";
+ }
+ }
+ }
+ }
+ }
+ return $output;
+}
-This function generates the column headings for the chart.
+##############################################
+##############################################
+
+# set_form_elements
+#
+# Generates javascript to set form elements to values based on
+# corresponding values for the same form elements when the page was
+# previously submitted.
+#
+# Last submission values are read from hidden form elements in referring
+# page which have the same name, i.e., generated by &echo_form_input().
+#
+# Intended to be called by onload event.
+#
+# Inputs:
+# (a) Reference to hash of echoed form elements to be set.
+#
+# In the hash, keys are the form element names, and the values are the
+# element type (selectbox, radio, checkbox or text -for textbox, textarea or
+# hidden).
+#
+# (b) Optional reference to hash of stored elements to be set.
+#
+# If the page being displayed is a page which permits modification of
+# previously stored data, e.g., the first page in a multi-page submission,
+# then if stored is supplied, form elements will be set to the last stored
+# values. If user supplied values are also available for the same elements
+# these will replace the stored values.
+#
+# Output:
+#
+# javascript function - set_form_elements() which sets form elements,
+# expects an argument: formname - the name of the form according to
+# the DOM, e.g., document.compose
+
+sub set_form_elements {
+ my ($elements,$stored) = @_;
+ my %values;
+ my $output .= 'function setFormElements(courseForm) {
+';
+ if (defined($stored)) {
+ foreach my $name (keys(%{$stored})) {
+ if (exists($$elements{$name})) {
+ if (ref($$stored{$name}) eq 'ARRAY') {
+ $values{$name} = $$stored{$name};
+ } else {
+ @{$values{$name}} = ($$stored{$name});
+ }
+ }
+ }
+ }
-=over 4
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.(.+)$/) {
+ my $name = $1;
+ if (exists($$elements{$name})) {
+ @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
+ }
+ }
+ }
-Inputs: $CacheData, $keyID, $headings, $spacePadding
+ foreach my $name (keys(%values)) {
+ for (my $i=0; $i<@{$values{$name}}; $i++) {
+ $values{$name}[$i] = &HTML::Entities::decode($values{$name}[$i],'<>&"');
+ $values{$name}[$i] =~ s/([\r\n\f]+)/\\n/g;
+ $values{$name}[$i] =~ s/"/\\"/g;
+ }
+ if ($$elements{$name} eq 'text') {
+ my $numvalues = @{$values{$name}};
+ if ($numvalues > 1) {
+ my $valuestring = join('","',@{$values{$name}});
+ $output .= qq|
+ var textvalues = new Array ("$valuestring");
+ var total = courseForm.elements['$name'].length;
+ if (total > $numvalues) {
+ total = $numvalues;
+ }
+ for (var i=0; i= 0) {
+ return true;
+ }
+ return false;
+ }
+}
+END
+ return $scripttag;
+}
-$headings: The names of the headings for the student information
-$spacePadding: The spaces to go between columns
+# USAGE: htmltag(element, content, {attribute => value,...});
+#
+# EXAMPLES:
+# - htmltag('a', 'this is an anchor', {href => 'www.example.com',
+# title => 'this is a title'})
+#
+# - You might want to set up needed tags like:
+#
+# my $h3 = sub { return htmltag( "h3", @_ ) };
+#
+# ... and use them: $h3->("This is a headline")
+#
+# - To set up a couple of tags, see sub inittags
+#
+# NOTES:
+# - Empty elements, such as are correctly terminated,
+# i.e. htmltag('br') returns
+# - Empty attributes (title="") are filtered out.
+# - The function will not check for deprecated attributes.
+#
+# OUTPUT: content enclosed in xhtml conform tags
+sub htmltag{
+ return
+ qq|<$_[0]|
+ . join( '', map { qq| $_="${$_[2]}{$_}"| if ${$_[2]}{$_} } keys %{ $_[2] } )
+ . ($_[1] ? qq|>$_[1]$_[0]>| : qq|/>|). "\n";
+};
-Output: $Str
-$Str: A formatted string of the table column headings.
+# USAGE: inittags(@tags);
+#
+# EXAMPLES:
+# - my ($h1, $h2, $h3) = initTags( qw( h1 h2 h3 ) )
+# $h1->("This is a headline") #Returns:
This is a headline
+#
+# NOTES: See sub htmltag for further information.
+#
+# OUTPUT: List of subroutines.
+sub inittags {
+ my @tags = @_;
+ return map { my $tag = $_;
+ sub { return htmltag( $tag, @_ ) }
+ } @tags;
+}
-=back
-=cut
+##############################################
+##############################################
-########################################################
-########################################################
-sub CreateHeadings {
- my ($data,$keyID,$headings,$displayString,$format)=@_;
- my $Str='';
- my $formatting = '';
-
- for(my $index=0; $index<(scalar @$headings); $index++) {
- my $currentHeading=$headings->[$index];
- if($format eq 'preformatted') {
- my @dataLength=split(//,$currentHeading);
- my $length=scalar @dataLength;
- $formatting = (' 'x
- ($data->{$keyID->[$index].':columnWidth'}-$length));
- }
- my $linkdata=$keyID->[$index];
-
- my $tempString = $displayString;
- $tempString =~ s/LINKDATA/$linkdata/;
- $tempString =~ s/DISPLAYDATA/$currentHeading/;
- $tempString =~ s/FORMATTING/$formatting/;
+# generate_menu
+#
+# Generates html markup for a menu.
+#
+# Inputs:
+# An array of following structure:
+# ({ categorytitle => 'Categorytitle',
+# items => [
+# {
+# linktext => 'Text to be displayed',
+# url => 'URL the link is pointing to, i.e. /adm/site?action=dosomething',
+# permission => 'Contains permissions as returned from lonnet::allowed(),
+# must evaluate to true in order to activate the link',
+# icon => 'icon filename',
+# alttext => 'alt text for the icon',
+# help => 'Name of the corresponding helpfile',
+# linktitle => 'Description of the link (used for title tag)'
+# },
+# ...
+# ]
+# },
+# ...
+# )
+#
+# Outputs: A scalar containing the html markup for the menu.
- $Str .= $tempString;
+# ---- Remove when done ----
+# This routine is part of the redesign of LON-CAPA and it's
+# subject to change during this project.
+# Don't rely on its current functionality as it might be
+# changed or removed.
+# --------------------------
+sub generate_menu {
+ my @menu = @_;
+ # subs for specific html elements
+ my ($h3, $div, $ul, $li, $a, $img) = inittags( qw(h3 div ul li a img) );
+
+ my @categories; # each element represents the entire markup for a category
+
+ foreach my $category (@menu) {
+ my @links; # contains the links for the current $category
+ foreach my $link (@{$$category{items}}) {
+ next unless $$link{permission};
+
+ # create the markup for the current $link and push it into @links.
+ # each entry consists of an image and a text optionally followed
+ # by a help link.
+ push @links, $li->(
+ $a->(
+ $img->("", {
+ class => "LC_noBorder LC_middle",
+ src => "/res/adm/pages/$$link{icon}",
+ alt => mt(defined($$link{alttext}) ?
+ $$link{alttext} : $$link{linktext})
+ }), {
+ href => $$link{url},
+ title => mt($$link{linktitle})
+ }).
+ $a->(mt($$link{linktext}), {
+ href => $$link{url},
+ title => mt($$link{linktitle}),
+ class => "LC_menubuttons_link"
+ }).
+ (defined($$link{help}) ?
+ Apache::loncommon::help_open_topic($$link{help}) : ''),
+ {class => "LC_menubuttons_inline_text"});
+ }
+
+ # wrap categorytitle in
, concatenate with
+ # joined and in
tags wrapped @links
+ # and wrap everything in an enclosing
and push it into
+ # @categories
+ # such that each element looks like:
+ #
title
...
...
+ # the category won't be added if there aren't any links
+ push @categories,
+ $div->($h3->(mt($$category{categorytitle}), {class=>"LC_hcell"}).
+ $ul->(join('' ,@links), {class =>"LC_ListStyleNormal" }),
+ {class=>"LC_Box LC_400Box"}) if scalar(@links);
}
- return $Str;
+ # wrap the joined @categories in another
(column layout)
+ return $div->(join('', @categories), {class => "LC_columnSection"});
}
-########################################################
-########################################################
+##############################################
+##############################################
=pod
-=item &FormatStudentInformation()
+=item &start_funclist
+
+Start list of available functions
-This function produces a formatted string of the student\'s information:
-username, domain, section, full name, and PID.
+Typically used to offer a simple list of available functions
+at top or bottom of page.
+All available functions/actions for the current page
+should be included in this list.
+If the optional headline text is not provided, a default text will be used.
+
+
+Related routines:
=over 4
+add_item_funclist
+end_funclist
+=back
-Input: $cache, $name, $keyID, $spacePadding
-$cache: This is a pointer to a hash that is tied to the cached data
+Inputs: (optional) headline text
-$name: The name and domain of the current student in name:domain format
+Returns: HTML code with function list start
-$keyID: A pointer to an array holding the names used to
+=cut
-remove data from the hash. They represent the name of the data to be removed.
+##############################################
+##############################################
-$spacePadding: Extra spaces that represent the space between columns
+sub start_funclist {
+ my($legendtext)=@_;
+ $legendtext=&mt('Functions') if !$legendtext;
+ return "\n";
}
1;
+
__END__