--- loncom/interface/lonhtmlcommon.pm 2009/11/04 17:51:26 1.238
+++ loncom/interface/lonhtmlcommon.pm 2010/01/26 13:08:08 1.265
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common html routines
#
-# $Id: lonhtmlcommon.pm,v 1.238 2009/11/04 17:51:26 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.265 2010/01/26 13:08:08 wenzelju Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -62,11 +62,25 @@ use Apache::lonlocal;
use Apache::lonnet;
use LONCAPA;
+
+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;
+}
+
##############################################
##############################################
-=pod
-
=item confirm_success
Successful completion of an operation message
@@ -76,7 +90,7 @@ Successful completion of an operation me
sub confirm_success {
my ($message,$failure)=@_;
if ($failure) {
- return ''."\n"
+ return ''."\n"
.' '."\n"
.$message."\n"
.' '."\n";
@@ -111,7 +125,7 @@ sub dragmath_button {
}
my $buttontext=&mt('Edit Math');
return < $help_text
+ $help_text
ENDDRAGMATH
}
@@ -123,7 +137,6 @@ ENDDRAGMATH
Javascript used to open pop-up window containing dragmath applet which
can be used to paste LaTeX into a textarea.
-
=cut
sub dragmath_js {
@@ -222,6 +235,9 @@ sub select_recent {
unless ($value =~/^error\:/) {
my $escaped = &Apache::loncommon::escape_url($value);
&Apache::loncommon::inhibit_menu_check(\$escaped);
+ if ($area eq 'residx') {
+ next if ((!&Apache::lonnet::allowed('bre',$value)) && (!&Apache::lonnet::allowed('bro',$value)));
+ }
$return.="\n".
&unescape((split(/\&/,$recent{$value}))[1]).
' ';
@@ -364,7 +380,8 @@ dname_hour, dname_min, and dname_sec.
The current setting for this time parameter. A unix format time
(time in seconds since the beginning of Jan 1st, 1970, GMT.
-An undefined value is taken to indicate the value is the current time.
+An undefined value is taken to indicate the value is the current time
+unless it is requested to leave it empty. See $includeempty.
Also, to be explicit, a value of 'now' also indicates the current time.
=item $special
@@ -374,6 +391,9 @@ the date_setter. See lonparmset for exa
=item $includeempty
+If it is set (true) and no date/time value is provided,
+the date/time fields are left empty.
+
=item $state
Specifies the initial state of the form elements. Either 'disabled' or empty.
@@ -393,7 +413,11 @@ sub date_setter {
my ($formname,$dname,$currentvalue,$special,$includeempty,$state,
$no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_;
my $now = time;
- my $wasdefined=1;
+
+ my $tzname;
+ my ($sec,$min,$hour,$mday,$month,$year) = ('', '', undef,''.''.'');
+ #other potentially useful values: wkday,yrday,is_daylight_savings
+
if (! defined($state) || $state ne 'disabled') {
$state = '';
}
@@ -401,33 +425,24 @@ sub date_setter {
$no_hh_mm_ss = 0;
}
if ($currentvalue eq 'now') {
- $currentvalue = $now;
+ $currentvalue = $now;
}
- if ((!defined($currentvalue)) || ($currentvalue eq '')) {
- $wasdefined=0;
- if ($includeempty) {
- $currentvalue = 0;
- } else {
- $currentvalue = $now;
- }
+
+ # Default value: Set empty date field to current time
+ # unless empty inclusion is requested
+ if ((!$includeempty) && (!$currentvalue)) {
+ $currentvalue = $now;
}
- # other potentially useful values: wkday,yrday,is_daylight_savings
- my $tzname;
- my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','','');
+ # Do we have a date? Split it!
if ($currentvalue) {
- ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue);
- }
- unless ($wasdefined) {
- ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($now);
- if (($defhour) || ($defmin) || ($defsec)) {
- $sec=($defsec?$defsec:0);
- $min=($defmin?$defmin:0);
- $hour=($defhour?$defhour:0);
- } elsif (!$includeempty) {
- $sec=0;
- $min=0;
- $hour=0;
- }
+ ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue);
+
+ #No values provided for hour, min, sec? Use default 0
+ if (($defhour) || ($defmin) || ($defsec)) {
+ $sec = ($defsec ? $defsec : 0);
+ $min = ($defmin ? $defmin : 0);
+ $hour = ($defhour ? $defhour : 0);
+ }
}
my $result = "\n\n";
$result .= <'; }
- $output.=''.$prefix.'/';
- if ($env{'user.adv'}) {
- my $path=$prefix.'/';
- foreach my $dir (split('/',$uri)) {
+ my $output='';
+ $output.=$prefix.'/';
+ if (($env{'user.adv'}) || ($env{'user.author'})) {
+ my $path=$prefix.'/';
+ foreach my $dir (split('/',$uri)) {
if (! $dir) { next; }
$path .= $dir;
- if ($path eq $uri) {
- if ($skiplast) {
- $output.=$dir;
+ if ($path eq $uri) {
+ if ($skiplast) {
+ $output.=$dir;
last;
- }
- } else {
- $path.='/';
- }
+ }
+ } else {
+ $path.='/';
+ }
my $href_path = &HTML::Entities::encode($path,'<>&"');
- &Apache::loncommon::inhibit_menu_check(\$href_path);
- if ($form) {
- my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();';
- $output.=qq{$dir /};
- } else {
- $output.=qq{$dir /};
- }
- }
+ &Apache::loncommon::inhibit_menu_check(\$href_path);
+ if ($form) {
+ my $href = 'javascript:'.$form.".action='".$href_path."';".$form.'.submit();';
+ $output.=qq{$dir /};
+ } else {
+ $output.=qq{$dir /};
+ }
+ }
} else {
- foreach my $dir (split('/',$uri)) {
+ foreach my $dir (split('/',$uri)) {
if (! $dir) { next; }
- $output.=$dir.'/';
- }
+ $output.=$dir.'/';
+ }
}
if ($uri !~ m|/$|) { $output=~s|/$||; }
- return $output.' '.($noformat?'':' ');
+ $output.=' ';
+
+ return $output;
}
# --------------------- A function that generates a window for the spellchecker
@@ -1224,11 +1237,18 @@ ENDLINK
}
sub htmlareaheaders {
- return if (&htmlareablocked());
- return if (!&htmlareabrowser());
- return (<
-ENDHEADERS
+ my $s="";
+ if (&htmlareabrowser()) {
+ $s.=(<
+ENDEDITOR
+ }
+ $s.=(<
+
+
+ENDJQUERY
+ return $s;
}
# ----------------------------------------------------------------- Preferences
@@ -1263,21 +1283,78 @@ sub htmlarea_lang {
sub htmlareaselectactive {
my @fields=@_;
unless (&htmlareabrowser()) { return ''; }
- if (&htmlareablocked()) { return ' '.&enablelink(@fields); }
- my $output=' '.
@@ -1342,6 +1419,7 @@ returns: nothing
############################################################
{
my @Crumbs;
+ my %tools = ();
sub breadcrumbs {
my ($component,$component_help,$menulink,$helplink,$css_class,$no_mt, $CourseBreadcrumbs) = @_;
@@ -1382,28 +1460,29 @@ returns: nothing
}
}
my $links = join "",
- map {
- $faq = $_->{'faq'} if (exists($_->{'faq'}));
- $bug = $_->{'bug'} if (exists($_->{'bug'}));
- $help = $_->{'help'} if (exists($_->{'help'}));
-
- my $result = htmltag( 'a',
- $_->{no_mt} ?
- $_->{text} : mt($_->{text}),
- {
- href => $_->{href},
- title => $_->{no_mt} ?
- $_->{title} : mt($_->{title}),
- target => $_->{target},
- });
- $result = htmltag( 'li', "$result $crumbsymbol");
- } @Crumbs;
+ map {
+ $faq = $_->{'faq'} if (exists($_->{'faq'}));
+ $bug = $_->{'bug'} if (exists($_->{'bug'}));
+ $help = $_->{'help'} if (exists($_->{'help'}));
+
+ my $result = $_->{no_mt} ? $_->{text} : mt($_->{text});
+
+ if ($_->{href}){
+ $result = htmltag( 'a', $result,
+ { href => $_->{href},
+ title => $_->{no_mt} ? $_->{title} : mt($_->{title}),
+ target => $_->{target}, });
+ }
+
+ $result = htmltag( 'li', "$result $crumbsymbol");
+ } @Crumbs;
#should the last Element be translated?
- $links .= htmltag( 'li',
- htmltag( 'b',
- $last->{'no_mt'} ?
- $last->{'text'} : mt($last->{'text'}) ));
+
+ my $lasttext = $last->{'no_mt'} ? $last->{'text'}
+ : mt( $last->{'text'} );
+
+ $links .= htmltag( 'li', htmltag('b', $lasttext), {title => $lasttext});
my $icons = '';
$faq = $last->{'faq'} if (exists($last->{'faq'}));
@@ -1438,8 +1517,10 @@ returns: nothing
.$links;
}
+ render_tools(\$links);
$links = htmltag('div', $links,
{ id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ;
+ render_advtools(\$links);
# Return the @Crumbs stack to what we started with
push(@Crumbs,$last);
@@ -1450,11 +1531,111 @@ returns: nothing
sub clear_breadcrumbs {
undef(@Crumbs);
+ undef(%tools);
}
sub add_breadcrumb {
push(@Crumbs,@_);
}
+
+=item add_breadcrumb_tool($category, $html)
+
+Adds $html to $category of the breadcrumb toolbar container.
+
+$html is usually a link to a page that invokes a function on the currently
+displayed data (e.g. print when viewing a problem)
+
+Currently there are 3 possible values for $category:
+
+=over
+
+=item navigation
+left of breadcrumbs line
+
+=item tools
+right of breadcrumbs line
+
+=item advtools
+advanced tools shown in a separate box below breadcrumbs line
+
+=back
+
+returns: nothing
+
+=cut
+
+ sub add_breadcrumb_tool {
+ my ($category, @html) = @_;
+ return unless @html;
+ if (!defined(%tools)) {
+ %tools = ( navigation => [], 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;
+ }
+
+=item clear_breadcrumb_tools()
+
+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 defined %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' } });
+ }
+
+=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
@@ -1547,7 +1728,7 @@ END
}
sub row_title {
- my ($title,$css_title_class,$css_value_class) = @_;
+ my ($title,$css_title_class,$css_value_class, $css_value_furtherAttributes) = @_;
$row_count[0]++;
my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
$css_title_class ||= 'LC_pick_box_title';
@@ -1559,7 +1740,7 @@ sub row_title {
$title .= ':';
}
my $output = <<"ENDONE";
-
+
$title
@@ -1815,21 +1996,25 @@ sub course_custom_roles {
# 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
-#
+# 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.
+# Outputs - a scalar containing html mark-up for the div.
+
sub topic_bar {
- my ($imgnum,$title) = @_;
- return ''
- .'
'
- .' '.$title
- .'
';
+ my ($num,$title) = @_;
+ my $number = '';
+ if ($num ne '') {
+ $number = ''.$num.' ';
+ }
+ return ''.$number.$title.'
';
}
##############################################
##############################################
-
# echo_form_input
#
# Generates html markup to add form elements from the referrer page
@@ -1894,7 +2079,6 @@ sub echo_form_input {
##############################################
##############################################
-
# set_form_elements
#
# Generates javascript to set form elements to values based on
@@ -2112,7 +2296,7 @@ sub htmltag{
# USAGE: inittags(@tags);
#
# EXAMPLES:
-# - my ($h1, $h2, $h3) = initTags( qw( h1 h2 h3 ) )
+# - 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.
@@ -2161,6 +2345,38 @@ sub scripttag {
};
+=item list_from_array( \@array, { listattr =>{}, itemattr =>{} } )
+
+Constructs a XHTML list from \@array.
+
+input:
+
+=over
+
+=item \@array
+
+A reference to the array containing text that will be wrapped in tags.
+
+=item { listattr => {}, itemattr =>{} }
+
+Attributes for and passed in as hash references.
+See htmltag() for more details.
+
+=back
+
+returns: XHTML list as String.
+
+=cut
+
+# \@items, {listattr => { class => 'abc', id => 'xyx' }, itemattr => {class => 'abc', id => 'xyx'}}
+sub list_from_array {
+ my ($items, $args) = @_;
+ my ($ul, $li) = inittags( qw(ul li) );
+ my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items;
+ return $ul->( $listitems, $args->{listattr} );
+}
+
+
##############################################
##############################################
@@ -2190,12 +2406,6 @@ sub scripttag {
#
# Outputs: A scalar containing the html markup for the menu.
-# ---- 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
@@ -2285,8 +2495,7 @@ Returns: HTML code with function list st
sub start_funclist {
my($legendtext)=@_;
$legendtext=&mt('Functions') if !$legendtext;
- return "\n$legendtext \n"
- .''."\n";
+ return ''.$legendtext.' '."\n";
}
@@ -2319,9 +2528,6 @@ sub add_item_funclist {
return ''.$content.' '."\n";
}
-##############################################
-##############################################
-
=pod
=item &end_funclist
@@ -2337,17 +2543,46 @@ add_item_funclist
Inputs: ./.
Returns: HTML code with function list end
-
=cut
-##############################################
-##############################################
-
sub end_funclist {
- my($r)=@_;
- return " \n \n";
+ return " \n";
}
+=pod
+
+=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) = @_;
+ $args->{legend} ||= mt('Functions');
+ return list_from_array( [$args->{legend}, @$items],
+ { listattr => {class => 'LC_funclist'} });
+}
+
1;
__END__