--- loncom/interface/lonhtmlcommon.pm 2003/02/19 20:13:45 1.12
+++ loncom/interface/lonhtmlcommon.pm 2012/09/10 09:51:06 1.322
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.12 2003/02/19 20:13:45 matthew Exp $
+# $Id: lonhtmlcommon.pm,v 1.322 2012/09/10 09:51:06 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -55,15 +55,384 @@ html.
package Apache::lonhtmlcommon;
-use Time::Local;
use strict;
+use Time::Local;
+use Time::HiRes;
+use Apache::lonlocal;
+use Apache::lonnet;
+use HTML::Entities();
+use LONCAPA;
+
+sub java_not_enabled {
+ return "\n".''.
+ &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.').
+ "\n";
+}
+
+sub coursepreflink {
+ my ($text,$category)=@_;
+ if (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
+ return '&"').'">'.$text.'';
+ } else {
+ return '';
+ }
+}
+
+sub raw_href_to_link {
+ my ($message)=@_;
+ $message=~s/(https?\:\/\/[^\s\'\"\<]+)([\s\<]|$)/$1<\/tt><\/a>$2/gi;
+ return $message;
+}
+
+sub entity_encode {
+ my ($text)=@_;
+ return &HTML::Entities::encode($text, '<>&"');
+}
+
+sub direct_parm_link {
+ my ($linktext,$symb,$filter,$part,$target)=@_;
+ $symb=&entity_encode($symb);
+ $filter=&entity_encode($filter);
+ $part=&entity_encode($part);
+ if (($symb) && (&Apache::lonnet::allowed('opa')) && ($target ne 'tex')) {
+ return "$linktext";
+ } else {
+ return $linktext;
+ }
+}
+##############################################
+##############################################
+
+=item &confirm_success()
+
+Successful completion of an operation message
+
+=cut
+
+sub confirm_success {
+ my ($message,$failure)=@_;
+ if ($failure) {
+ return ''."\n"
+ .' '."\n"
+ .$message."\n"
+ .''."\n";
+ } else {
+ return ''."\n"
+ .' '."\n"
+ .$message."\n"
+ .''."\n";
+ }
+}
+
+##############################################
+##############################################
+
+=pod
+
+=item &dragmath_button()
+
+Creates a button that launches a dragmath popup-window, in which an
+expression can be edited and pasted as LaTeX into a specified textarea.
+
+ textarea - Name of the textarea to edit.
+ helpicon - If true, show a help icon to the right of the button.
+
+=cut
+
+sub dragmath_button {
+ my ($textarea,$helpicon) = @_;
+ my $help_text;
+ if ($helpicon) {
+ $help_text = &Apache::loncommon::help_open_topic('Authoring_Math_Editor',undef,undef,undef,undef,'mathhelpicon_'.$textarea);
+ }
+ my $buttontext=&mt('Edit Math');
+ return <$help_text
+ENDDRAGMATH
+}
+
+##############################################
+
+=pod
+
+=item &dragmath_js()
+
+Javascript used to open pop-up window containing dragmath applet which
+can be used to paste LaTeX into a textarea.
+
+=cut
+
+sub dragmath_js {
+ my ($popup) = @_;
+ return <
+ //
+
+
+ENDDRAGMATHJS
+}
+
+##############################################
+##############################################
+
+=pod
+
+=item &dependencies_button()
+
+Creates a button that launches a popup-window, in which dependencies
+for the web page in the main window can be added to, replaced or deleted.
+
+=cut
+
+sub dependencies_button {
+ my $buttontext=&mt('Manage Dependencies');
+ return <<"END";
+
+END
+}
+
+##############################################
+
+=pod
+
+=item &dependencycheck_js()
+
+Javascript used to open pop-up window containing interface to manage
+dependencies for a web page uploaded diretcly to a course.
+
+=cut
+
+sub dependencycheck_js {
+ my ($symb,$title,$url) = @_;
+ my $link = '/adm/dependencies?symb='.&HTML::Entities::encode($symb,'<>&"').
+ '&title='.&HTML::Entities::encode($title,'<>&"').
+ '&url='.&HTML::Entities::encode($url,'<>&"');
+ return <
+ //
+
+ENDJS
+}
+
+##############################################
+##############################################
+
+=pod
+
+=item &authorbombs()
+
+=cut
+
+##############################################
+##############################################
+
+sub authorbombs {
+ my $url=shift;
+ $url=&Apache::lonnet::declutter($url);
+ my ($udom,$uname)=($url=~m{^($LONCAPA::domain_re)/($LONCAPA::username_re)/});
+ my %bombs=&Apache::lonmsg::all_url_author_res_msg($uname,$udom);
+ foreach my $bomb (keys(%bombs)) {
+ if ($bomb =~ /^$udom\/$uname\//) {
+ return ''.
+ &Apache::loncommon::help_open_topic('About_Bombs');
+ }
+ }
+ return '';
+}
+
+##############################################
+##############################################
+
+sub recent_filename {
+ my $area=shift;
+ return 'nohist_recent_'.&escape($area);
+}
+
+sub store_recent {
+ my ($area,$name,$value,$freeze)=@_;
+ my $file=&recent_filename($area);
+ my %recent=&Apache::lonnet::dump($file);
+ if (scalar(keys(%recent))>20) {
+# remove oldest value
+ my $oldest=time();
+ my $delkey='';
+ foreach my $item (keys(%recent)) {
+ my $thistime=(split(/\&/,$recent{$item}))[0];
+ if (($thistime ne "always_include") && ($thistime<$oldest)) {
+ $oldest=$thistime;
+ $delkey=$item;
+ }
+ }
+ &Apache::lonnet::del($file,[$delkey]);
+ }
+# store new value
+ my $timestamp;
+ if ($freeze) {
+ $timestamp = "always_include";
+ } else {
+ $timestamp = time();
+ }
+ &Apache::lonnet::put($file,{ $name =>
+ $timestamp.'&'.&escape($value) });
+}
+
+sub remove_recent {
+ my ($area,$names)=@_;
+ my $file=&recent_filename($area);
+ return &Apache::lonnet::del($file,$names);
+}
+
+sub select_recent {
+ my ($area,$fieldname,$event)=@_;
+ my %recent=&Apache::lonnet::dump(&recent_filename($area));
+ my $return="\n\n";
+ return $return;
+}
+
+sub get_recent {
+ my ($area, $n) = @_;
+ my %recent=&Apache::lonnet::dump(&recent_filename($area));
+
+# Create hash with key as time and recent as value
+# Begin filling return_hash with any 'always_include' option
+ my %time_hash = ();
+ my %return_hash = ();
+ foreach my $item (keys(%recent)) {
+ my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
+ if ($thistime eq 'always_include') {
+ $return_hash{$item} = &unescape($thisvalue);
+ $n--;
+ } else {
+ $time_hash{$thistime} = $item;
+ }
+ }
+
+# Sort by decreasing time and return key value pairs
+ my $idx = 1;
+ foreach my $item (reverse(sort(keys(%time_hash)))) {
+ $return_hash{$time_hash{$item}} =
+ &unescape((split(/\&/,$recent{$time_hash{$item}}))[1]);
+ if ($n && ($idx++ >= $n)) {last;}
+ }
+
+ return %return_hash;
+}
+
+sub get_recent_frozen {
+ my ($area) = @_;
+ my %recent=&Apache::lonnet::dump(&recent_filename($area));
+
+# Create hash with all 'frozen' items
+ my %return_hash = ();
+ foreach my $item (keys(%recent)) {
+ my ($thistime,$thisvalue)=(split(/\&/,$recent{$item}));
+ if ($thistime eq 'always_include') {
+ $return_hash{$item} = &unescape($thisvalue);
+ }
+ }
+ return %return_hash;
+}
+
+
+
+=pod
+
+=item &textbox()
+
+=cut
+
+##############################################
+##############################################
+sub textbox {
+ my ($name,$value,$size,$special) = @_;
+ $size = 40 if (! defined($size));
+ $value = &HTML::Entities::encode($value,'<>&"');
+ my $Str = '';
+ return $Str;
+}
##############################################
##############################################
=pod
-=item &date_setter
+=item &checkbox()
+
+=cut
+
+##############################################
+##############################################
+sub checkbox {
+ my ($name,$checked,$value) = @_;
+ my $Str = '\n";
$result .= <
+
ENDJS
- $result .= " ');
+ }
+ }
+ $result .= "\n\n";
return $result;
}
+sub get_timedates {
+ my ($epoch) = @_;
+ my $dt = DateTime->from_epoch(epoch => $epoch)
+ ->set_time_zone(&Apache::lonlocal::gettimezone());
+ my $tzname = $dt->time_zone_short_name();
+ my $sec = $dt->second;
+ my $min = $dt->minute;
+ my $hour = $dt->hour;
+ my $mday = $dt->day;
+ my $month = $dt->month;
+ if ($month) {
+ $month --;
+ }
+ my $year = $dt->year;
+ return ($tzname,$sec,$min,$hour,$mday,$month,$year);
+}
+
+sub build_url {
+ my ($base, $fields)=@_;
+ my $url;
+ $url = $base.'?';
+ foreach my $key (keys(%$fields)) {
+ $url.=&escape($key).'='.&escape($$fields{$key}).'&';
+ }
+ $url =~ s/&$//;
+ return $url;
+}
+
+
##############################################
##############################################
-=item &get_date_from_form
+=pod
+
+=item &get_date_from_form()
+
+get_date_from_form retrieves the date specified in an &date_setter form.
Inputs:
@@ -185,7 +692,7 @@ Inputs:
=item $dname
-The name passed to &datesetter, which prefixes the form elements.
+The name passed to &date_setter, which prefixes the form elements.
=item $defaulttime
@@ -203,44 +710,68 @@ sub get_date_from_form {
my ($dname) = @_;
my ($sec,$min,$hour,$day,$month,$year);
#
- if (defined($ENV{'form.'.$dname.'_second'})) {
- my $tmpsec = $ENV{'form.'.$dname.'_second'};
+ if (defined($env{'form.'.$dname.'_second'})) {
+ my $tmpsec = $env{'form.'.$dname.'_second'};
if (($tmpsec =~ /^\d+$/) && ($tmpsec >= 0) && ($tmpsec < 60)) {
$sec = $tmpsec;
}
+ if (!defined($tmpsec) || $tmpsec eq '') { $sec = 0; }
+ } else {
+ $sec = 0;
}
- if (defined($ENV{'form.'.$dname.'_minute'})) {
- my $tmpmin = $ENV{'form.'.$dname.'_minute'};
+ if (defined($env{'form.'.$dname.'_minute'})) {
+ my $tmpmin = $env{'form.'.$dname.'_minute'};
if (($tmpmin =~ /^\d+$/) && ($tmpmin >= 0) && ($tmpmin < 60)) {
$min = $tmpmin;
}
+ if (!defined($tmpmin) || $tmpmin eq '') { $min = 0; }
+ } else {
+ $min = 0;
}
- if (defined($ENV{'form.'.$dname.'_hour'})) {
- my $tmphour = $ENV{'form.'.$dname.'_hour'};
- if (($tmphour =~ /^\d+$/) && ($tmphour > 0) && ($tmphour < 32)) {
+ if (defined($env{'form.'.$dname.'_hour'})) {
+ my $tmphour = $env{'form.'.$dname.'_hour'};
+ if (($tmphour =~ /^\d+$/) && ($tmphour >= 0) && ($tmphour < 24)) {
$hour = $tmphour;
}
+ } else {
+ $hour = 0;
}
- if (defined($ENV{'form.'.$dname.'_day'})) {
- my $tmpday = $ENV{'form.'.$dname.'_day'};
+ if (defined($env{'form.'.$dname.'_day'})) {
+ my $tmpday = $env{'form.'.$dname.'_day'};
if (($tmpday =~ /^\d+$/) && ($tmpday > 0) && ($tmpday < 32)) {
$day = $tmpday;
}
}
- if (defined($ENV{'form.'.$dname.'_month'})) {
- my $tmpmonth = $ENV{'form.'.$dname.'_month'};
+ if (defined($env{'form.'.$dname.'_month'})) {
+ my $tmpmonth = $env{'form.'.$dname.'_month'};
if (($tmpmonth =~ /^\d+$/) && ($tmpmonth > 0) && ($tmpmonth < 13)) {
- $month = $tmpmonth - 1;
+ $month = $tmpmonth;
}
}
- if (defined($ENV{'form.'.$dname.'_year'})) {
- my $tmpyear = $ENV{'form.'.$dname.'_year'};
- if (($tmpyear =~ /^\d+$/) && ($tmpyear > 1900)) {
- $year = $tmpyear - 1900;
+ if (defined($env{'form.'.$dname.'_year'})) {
+ my $tmpyear = $env{'form.'.$dname.'_year'};
+ if (($tmpyear =~ /^\d+$/) && ($tmpyear >= 1970)) {
+ $year = $tmpyear;
}
}
- if (eval(&timelocal($sec,$min,$hour,$day,$month,$year))) {
- return &timelocal($sec,$min,$hour,$day,$month,$year);
+ if (($year<1970) || ($year>2037)) { return undef; }
+ if (defined($sec) && defined($min) && defined($hour) &&
+ defined($day) && defined($month) && defined($year)) {
+ my $timezone = &Apache::lonlocal::gettimezone();
+ my $dt = DateTime->new( year => $year,
+ month => $month,
+ day => $day,
+ hour => $hour,
+ minute => $min,
+ second => $sec,
+ time_zone => $timezone,
+ );
+ my $epoch_time = $dt->epoch;
+ if ($epoch_time ne '') {
+ return $epoch_time;
+ } else {
+ return undef;
+ }
} else {
return undef;
}
@@ -249,426 +780,2582 @@ sub get_date_from_form {
##############################################
##############################################
-sub AscendOrderOptions {
- my ($order, $page, $formName)=@_;
+=pod
+
+=item &pjump_javascript_definition()
+
+Returns javascript defining the 'pjump' function, which opens up a
+parameter setting wizard.
- my $OpSel1 = '';
- my $OpSel2 = '';
+=cut
- if($order eq 'Ascending') {
- $OpSel1 = ' selected';
+##############################################
+##############################################
+sub pjump_javascript_definition {
+ my $Str = <Ascending'."\n".
- ''."\n";
+ foreach my $type (['Active', &mt('Currently Has Access')],
+ ['Future', &mt('Will Have Future Access')],
+ ['Expired', &mt('Previously Had Access')],
+ ['Any', &mt('Any Access Status')]) {
+ my ($name,$label) = @$type;
+ $Str .= ''."\n";
+ sub add_breadcrumb {
+ push(@Crumbs,@_);
}
- $Str .= '
[], tools => [], advtools => []);
+ }
+
+ #this cleans data received from lonmenu::innerregister
+ @html = grep {defined $_ && $_ ne ''} @html;
+ for (@html) {
+ s/align="(right|left)"//;
+# s/// if $category ne 'advtools';
+ }
+
+ push @{$tools{$category}}, @html;
}
- $Str .= '>All Parts
'."\n";
- $Str .= ''."\n";
+=item &clear_breadcrumb_tools()
- return $Str;
+Clears the breadcrumb toolbar container.
+
+returns: nothing
+
+=cut
+
+ sub clear_breadcrumb_tools {
+ undef(%tools);
+ }
+
+=item &render_tools(\$breadcrumbs)
+
+Creates html for breadcrumb tools (categories navigation and tools) and inserts
+\$breadcrumbs at the correct position.
+
+input: \$breadcrumbs - a reference to the string containing prepared
+breadcrumbs.
+
+returns: nothing
+
+=cut
+
+#TODO might split this in separate functions for each category
+ sub render_tools {
+ my ($breadcrumbs) = @_;
+ return unless (keys(%tools));
+
+ my $navigation = list_from_array($tools{navigation},
+ { listattr => { class=>"LC_breadcrumb_tools_navigation" } });
+ my $tools = list_from_array($tools{tools},
+ { listattr => { class=>"LC_breadcrumb_tools_tools" } });
+ $$breadcrumbs = list_from_array([$navigation, $tools, $$breadcrumbs],
+ { listattr => { class=>'LC_breadcrumb_tools_outerlist' } });
+ }
+
+=pod
+
+=item &render_advtools(\$breadcrumbs)
+
+Creates html for advanced tools (category advtools) and inserts \$breadcrumbs
+at the correct position.
+
+input: \$breadcrumbs - a reference to the string containing prepared
+breadcrumbs (after render_tools call).
+
+returns: nothing
+
+=cut
+
+ sub render_advtools {
+ my ($breadcrumbs) = @_;
+ return unless (defined $tools{'advtools'})
+ and (scalar(@{$tools{'advtools'}}) > 0);
+
+ $$breadcrumbs .= Apache::loncommon::head_subbox(
+ funclist_from_array($tools{'advtools'}) );
+ }
+
+} # End of scope for @Crumbs
+
+############################################################
+############################################################
+
+# Nested table routines.
+#
+# Routines to display form items in a multi-row table with 2 columns.
+# Uses nested tables to divide form elements into segments.
+# For examples of use see loncom/interface/lonnotify.pm
+#
+# Can be used in following order: ...
+# &start_pick_box()
+# row1
+# row2
+# row3 ... etc.
+# &submit_row()
+# &end_pick_box()
+#
+# where row1, row 2 etc. are chosen from &role_select_row,&course_select_row,
+# &status_select_row and &email_default_row
+#
+# Can also be used in following order:
+#
+# &start_pick_box()
+# &row_title()
+# &row_closure()
+# &row_title()
+# &row_closure() ... etc.
+# &submit_row()
+# &end_pick_box()
+#
+# In general a &submit_row() call should proceed the call to &end_pick_box(),
+# as this routine adds a button for form submission.
+# &submit_row() does not require a &row_closure after it.
+#
+# &start_pick_box() creates a bounding table with 1-pixel wide black border.
+# rows should be placed between calls to &start_pick_box() and &end_pick_box.
+#
+# &row_title() adds a title in the left column for each segment.
+# &row_closure() closes a row with a 1-pixel wide black line.
+#
+# &role_select_row() provides a select box from which to choose 1 or more roles
+# &course_select_row provides ways of picking groups of courses
+# radio buttons: all, by category or by picking from a course picker pop-up
+# note: by category option is only displayed if a domain has implemented
+# selection by year, semester, department, number etc.
+#
+# &status_select_row() provides a select box from which to choose 1 or more
+# access types (current access, prior access, and future access)
+#
+# &email_default_row() provides text boxes for default e-mail suffixes for
+# different authentication types in a domain.
+#
+# &row_title() and &row_closure() are called internally by the &*_select_row
+# routines, but can also be called directly to start and end rows which have
+# needs that are not accommodated by the *_select_row() routines.
+
+{ # Start: row_count block for pick_box
+my @row_count;
+
+sub start_pick_box {
+ my ($css_class,$id) = @_;
+ if (defined($css_class)) {
+ $css_class = 'class="'.$css_class.'"';
+ } else {
+ $css_class= 'class="LC_pick_box"';
+ }
+ my $table_id;
+ if (defined($id)) {
+ $table_id = ' id="'.$id.'"';
+ }
+ unshift(@row_count,0);
+ my $output = <<"END";
+
';
+ }
+ return $return;
+}
-=pod
+##############################################
+##############################################
-=item &MultipleSectionSelect()
+# topic_bar
+#
+# Generates a div containing an (optional) number with a white background followed by a
+# title with a background color defined in the corresponding CSS: LC_topic_bar
+# Inputs:
+# 1. number to display.
+# If input for number is empty only the title will be displayed.
+# 2. title text to display.
+# 3. optional id for the
+# Outputs - a scalar containing html mark-up for the div.
+
+sub topic_bar {
+ my ($num,$title,$id) = @_;
+ my $number = '';
+ if ($num ne '') {
+ $number = ''.$num.'';
+ }
+ if ($id ne '') {
+ $id = 'id="'.$id.'"';
+ }
+ return '
'.$number.$title.'
';
+}
-Inputs:
+##############################################
+##############################################
+# 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).
-=over 4
-=item $sections A references to an array containing the names of all the
-sections used in a class.
+sub echo_form_input {
+ my ($excluded,$regexps) = @_;
+ my $output = '';
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.(.+)$/) {
+ my $name = $1;
+ my $match = 0;
+ if (ref($excluded) eq 'ARRAY') {
+ next if (grep(/^\Q$name\E$/,@{$excluded}));
+ }
+ if (ref($regexps) eq 'ARRAY') {
+ if (@{$regexps} > 0) {
+ foreach my $regexp (@{$regexps}) {
+ if ($name =~ /$regexp/) {
+ $match = 1;
+ last;
+ }
+ }
+ }
+ }
+ next if ($match);
+ if (ref($env{$key}) eq 'ARRAY') {
+ foreach my $value (@{$env{$key}}) {
+ $value = &HTML::Entities::encode($value,'<>&"');
+ $output .= ''."\n";
+ }
+ } else {
+ my $value = &HTML::Entities::encode($env{$key},'<>&"');
+ $output .= ''."\n";
+ }
+ }
+ }
+ return $output;
+}
-=item $selectedSections A reference to an array containing the names of the
-currently selected sections.
+##############################################
+##############################################
+# 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});
+ }
+ }
+ }
+ }
-=back
+ foreach my $key (keys(%env)) {
+ if ($key =~ /^form\.(.+)$/) {
+ my $name = $1;
+ if (exists($$elements{$name})) {
+ @{$values{$name}} = &Apache::loncommon::get_env_multiple($key);
+ }
+ }
+ }
-Returns: a string containing HTML for a multiple select box for
-selecting sections of a course.
+ 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') || ($$elements{$name} eq 'hidden')) {
+ 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{$key}';\n".
+ " }\n";
+ }
+ }
+ $turninpathtext .= " return '';\n";
+ if (ref($multiples) eq 'HASH') {
+ foreach my $key (sort(keys(%{$multiples}))) {
+ $multtext .= " if (prefix == '$key') {\n".
+ " return '$multiples->{$key}';\n".
+ " }\n";
+ }
+ }
+ $multtext .= " return '';\n";
-########################################################
-########################################################
-sub MultipleSectionSelect {
- my ($sections,$selectedSections)=@_;
+ $arrayindexofjs = &Apache::loncommon::javascript_array_indexof();
+ return <<"ENDSCRIPT";
+
-=item &Title()
+$arrayindexofjs
-Inputs: $pageName a string containing the name of the page to be sent
-to &Apache::loncommon::bodytag.
+ENDSCRIPT
+}
-Returns: string containing being and complete and
-as well as a '."\n";
- return $Str;
+ if (document.getElementById(scrolltableid) == null) {
+ return;
+ } else {
+ scrolltable = document.getElementById(scrolltableid);
+ }
+
+ init_geometry();
+ var vph = Geometry.getViewportHeight();
+ var vpw = Geometry.getViewportWidth();
+
+FIRST
+ if ($context eq 'docs') {
+ $output .= "
+ var alltabs = ['$tabidstr'];
+";
+ } elsif ($context eq 'params') {
+ $output .= "
+ if (document.getElementById('$names{'boxh'}') == null) {
+ return;
+ }
+";
+ }
+ $output .= <<"SECOND";
+ var listwchange;
+ if (chkw == 1) {
+ var boxw = document.getElementById("$names{'boxw'}").offsetWidth;
+ var itemw;
+ var itemid = document.getElementById("$names{'item'}");
+ if (itemid != null) {
+ itemw = itemid.offsetWidth;
+ }
+ var itemwstart = itemw;
+
+ var scrollboxw = scrollbox.offsetWidth;
+ var scrollboxscrollw = scrollbox.scrollWidth;
+
+ var offsetw = parseInt(vpw * $offsetwfrac);
+ var paddingw = parseInt(vpw * $paddingwfrac);
+
+ var minscrollboxw = $minw;
+ var maxcolw = 0;
+SECOND
+ if ($context eq 'docs') {
+ $output .= <<"DOCSONE";
+ var actabw = 0;
+ for (var i=0; i maxcolw) {
+ maxcolw = actabw;
+ }
+ } else {
+ if (document.getElementById(alltabs[i]) != null) {
+ var thistab = document.getElementById(alltabs[i]);
+ thistab.style.visibility = 'hidden';
+ thistab.style.display = 'block';
+ var tabw = document.getElementById(alltabs[i]).offsetWidth;
+ thistab.style.display = 'none';
+ thistab.style.visibility = '';
+ if (tabw > maxcolw) {
+ maxcolw = tabw;
+ }
+ }
+ }
+ }
+DOCSONE
+ } elsif ($context eq 'params') {
+ $output .= <<"PARAMSONE";
+ var parmlevelrows = new Array();
+ var mapmenucells = new Array();
+ parmlevelrows = document.getElementById("$names{'boxh'}").rows;
+ var numrows = parmlevelrows.length;
+ if (numrows > 1) {
+ mapmenucells = parmlevelrows[2].getElementsByTagName('td');
+ }
+ maxcolw = mapmenucells[0].offsetWidth;
+PARAMSONE
+ }
+ $output .= <<"THIRD";
+ if (maxcolw > 0) {
+ var newscrollboxw;
+ if (maxcolw+paddingw+scrollboxscrollw scrollboxheight) {
+ if (freevspace > offsetv) {
+ newscrollboxheight = scrollboxheight+freevspace-offsetv;
+ if (newscrollboxheight < minvscrollbox) {
+ newscrollboxheight = minvscrollbox;
+ }
+ scrollbox.style.height = newscrollboxheight+"px";
+ }
+ }
+ }
+ scrollboxheight = scrollbox.offsetHeight;
+ var itemh = document.getElementById("$names{'item'}").offsetHeight;
+
+ if (scrollboxscrollheight <= scrollboxheight) {
+ if ((itemh+offsetv)= 0) {
+ return true;
+ }
+ return false;
+ }
+}
+END
+ return $scripttag;
+}
+
+
+# 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";
+};
-Inputs: $CacheData, $keyID, $headings, $spacePadding
-$CacheData: pointer to a hash tied to the cached data database
+# 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;
+}
+
+
+# USAGE: scripttag(scriptcode, [start|end|both]);
+#
+# EXAMPLES:
+# - scripttag("alert('Hello World!')", 'both')
+# returns:
+#
+#
+# NOTES:
+# - works currently only for javascripts
+#
+# OUTPUT:
+# Scriptcode properly enclosed in ");
+Returns: HTML code with function list end
+=cut
- $r->rflush();
+sub end_funclist {
+ return "\n";
}
-# update progress
-sub Update_PrgWin {
- my ($displayString,$r)=@_;
- $r->print('');
- $r->rflush();
-}
+=pod
-# close Progress Line
-sub Close_PrgWin {
- my ($r)=@_;
- $r->print(''."\n");
- $r->rflush();
-}
+=item &funclist_from_array( \@array, {legend => 'text for legend'} )
+
+Constructs a XHTML list from \@array with the first item being visually
+highlighted and set to the value of legend or 'Functions' if legend is
+empty.
+
+=over
+
+=item \@array
+
+A reference to the array containing text that will be wrapped in tags.
+
+=item { legend => 'text' }
+
+A string that's used as visually highlighted first item. 'Functions' is used if
+it's value evaluates to false.
+
+=back
+
+returns: XHTML list as string.
+
+=back
+
+=cut
+
+sub funclist_from_array {
+ my ($items, $args) = @_;
+ return unless(ref($items) eq 'ARRAY');
+ $args->{legend} ||= mt('Functions');
+ return list_from_array( [$args->{legend}, @$items],
+ { listattr => {class => 'LC_funclist'} });
+}
1;
+
__END__