--- loncom/interface/loncommon.pm 2005/03/02 20:35:46 1.254
+++ loncom/interface/loncommon.pm 2006/04/20 02:24:08 1.344
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.254 2005/03/02 20:35:46 matthew Exp $
+# $Id: loncommon.pm,v 1.344 2006/04/20 02:24:08 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -55,13 +55,15 @@ redundancy from other modules and increa
package Apache::loncommon;
use strict;
-use Apache::lonnet();
+use Apache::lonnet;
use GDBM_File;
use POSIX qw(strftime mktime);
-use Apache::Constants qw(:common :http :methods);
use Apache::lonmenu();
use Apache::lonlocal;
use HTML::Entities;
+use Apache::lonhtmlcommon();
+use Apache::loncoursedata();
+use Apache::lontexconvert();
my $readit;
@@ -152,19 +154,20 @@ BEGIN {
my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
opendir(DIR,$designdir);
while ($filename=readdir(DIR)) {
+ if ($filename!~/\.tab$/) { next; }
my ($domain)=($filename=~/^(\w+)\./);
- {
- my $designfile = $designdir.'/'.$filename;
- if ( open (my $fh,"<$designfile") ) {
- while (<$fh>) {
- next if /^\#/;
- chomp;
- my ($key,$val)=(split(/\=/,$_));
- if ($val) { $designhash{$domain.'.'.$key}=$val; }
- }
- close($fh);
- }
- }
+ {
+ my $designfile = $designdir.'/'.$filename;
+ if ( open (my $fh,"<$designfile") ) {
+ while (<$fh>) {
+ next if /^\#/;
+ chomp;
+ my ($key,$val)=(split(/\=/,$_));
+ if ($val) { $designhash{$domain.'.'.$key}=$val; }
+ }
+ close($fh);
+ }
+ }
}
closedir(DIR);
@@ -311,8 +314,8 @@ END
}
sub lastresurl {
- if ($ENV{'environment.lastresurl'}) {
- return $ENV{'environment.lastresurl'}
+ if ($env{'environment.lastresurl'}) {
+ return $env{'environment.lastresurl'}
} else {
return '/res';
}
@@ -329,9 +332,12 @@ sub storeresurl {
sub studentbrowser_javascript {
unless (
- (($ENV{'request.course.id'}) &&
- (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})))
- || ($ENV{'request.role'}=~/^(au|dc|su)/)
+ (($env{'request.course.id'}) &&
+ (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
+ || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ '/'.$env{'request.course.sec'})
+ ))
+ || ($env{'request.role'}=~/^(au|dc|su)/)
) { return ''; }
return (<<'ENDSTDBRW');
'."\n".
- ''."\n";
- }
+
+ $bodytag .= &Apache::lontexconvert::init_math_support();
my $upperleft='';
- if ($bodyonly) {
+ if ($bodyonly
+ || ($env{'request.state'} eq 'construct'
+ && $env{'environment.remote'} ne 'off' )) {
return $bodytag;
- } elsif ($ENV{'browser.interface'} eq 'textual') {
+ } elsif ($env{'browser.interface'} eq 'textual') {
# Accessibility
- return $bodytag.&Apache::lonmenu::menubuttons($forcereg,'web',
- $forcereg).
- '
LON-CAPA: '.$title.'
';
- } elsif ($ENV{'environment.remote'} eq 'off') {
+ $bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
+ if (!$notitle) {
+ $bodytag.='LON-CAPA: '.$title.'
';
+ }
+ return $bodytag;
+ } elsif ($env{'environment.remote'} eq 'off') {
# No Remote
my $roleinfo=(<
- $ENV{'environment.firstname'}
- $ENV{'environment.middlename'}
- $ENV{'environment.lastname'}
- $ENV{'environment.generation'}
+ $env{'environment.firstname'}
+ $env{'environment.middlename'}
+ $env{'environment.lastname'}
+ $env{'environment.generation'}
$role
@@ -2673,9 +2849,9 @@ ENDROLE
$titleinfo = $customtitle;
}
- if ($ENV{'request.state'} eq 'construct') {
+ if ($env{'request.state'} eq 'construct') {
my ($uname,$thisdisfn)=
- ($ENV{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
+ ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
my $formaction='/priv/'.$uname.'/'.$thisdisfn;
$formaction=~s/\/+/\//g;
unless ($customtitle) { #this is for resources; directories have customtitle, and crumbs and select recent are created in lonpubdir.pm
@@ -2699,15 +2875,28 @@ ENDROLE
}
$forcereg=1;
}
- my $titletable = ''.
- ''.
+ ' |
'.
$titleinfo.' | '.$roleinfo.'
';
- if ($ENV{'request.state'} eq 'construct') {
- $bodytag .= &Apache::lonmenu::menubuttons($forcereg,'web',$forcereg,$titletable);
+ }
+ if ($env{'request.state'} eq 'construct') {
+ if ($notopbar) {
+ $bodytag .= $titletable;
+ } else {
+ $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
+ $titletable);
+ }
} else {
- $bodytag .= &Apache::lonmenu::menubuttons($forcereg,'web',$forcereg).
+ if ($notopbar) {
+ $bodytag .= $titletable;
+ } else {
+ $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
$titletable;
+ }
}
return $bodytag;
}
@@ -2722,14 +2911,19 @@ ENDROLE
#
# Extra info if you are the DC
my $dc_info = '';
- if ($ENV{'user.adv'} && exists($ENV{'user.role.dc./'.
- $ENV{'course.'.$ENV{'request.course.id'}.
+ if ($env{'user.adv'} && exists($env{'user.role.dc./'.
+ $env{'course.'.$env{'request.course.id'}.
'.domain'}.'/'})) {
- my $cid = $ENV{'request.course.id'};
- $dc_info.= $cid.' '.$ENV{'course.'.$cid.'.internal.coursecode'};
+ my $cid = $env{'request.course.id'};
+ $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
$dc_info = '('.$dc_info.')';
}
+ # Explicit link to get inline menu
+ my $menu='
'.&mt('Switch to Inline Menu Mode').'';
#
+ if ($notitle) {
+ return $bodytag;
+ }
return(<
@@ -2739,13 +2933,13 @@ $upperleft
-$titleinfo $dc_info
- |
+$titleinfo $dc_info $menu
+ |
- $ENV{'environment.firstname'}
- $ENV{'environment.middlename'}
- $ENV{'environment.lastname'}
- $ENV{'environment.generation'}
+ $env{'environment.firstname'}
+ $env{'environment.middlename'}
+ $env{'environment.lastname'}
+ $env{'environment.generation'}
|
@@ -2758,6 +2952,62 @@ $titleinfo $dc_info
ENDBODY
}
+sub make_attr_string {
+ my ($register,$attr_ref) = @_;
+
+ if ($attr_ref && !ref($attr_ref)) {
+ die("addentries Must be a hash ref ".
+ join(':',caller(1))." ".
+ join(':',caller(0))." ");
+ }
+
+ if ($register) {
+ my ($on_load,$on_unload);
+ foreach my $key (keys(%{$attr_ref})) {
+ if (lc($key) eq 'onload') {
+ $on_load.=$attr_ref->{$key}.';';
+ delete($attr_ref->{$key});
+
+ } elsif (lc($key) eq 'onunload') {
+ $on_unload.=$attr_ref->{$key}.';';
+ delete($attr_ref->{$key});
+ }
+ }
+ $attr_ref->{'onload'} =
+ &Apache::lonmenu::loadevents(). $on_load;
+ $attr_ref->{'onunload'}=
+ &Apache::lonmenu::unloadevents().$on_unload;
+ }
+
+# Accessibility font enhance
+ if ($env{'browser.fontenhance'} eq 'on') {
+ my $style;
+ foreach my $key (keys(%{$attr_ref})) {
+ if (lc($key) eq 'style') {
+ $style.=$attr_ref->{$key}.';';
+ delete($attr_ref->{$key});
+ }
+ }
+ $attr_ref->{'style'}=$style.'; font-size: x-large;';
+ }
+
+ if ($env{'browser.blackwhite'} eq 'on') {
+ delete($attr_ref->{'font'});
+ delete($attr_ref->{'link'});
+ delete($attr_ref->{'alink'});
+ delete($attr_ref->{'vlink'});
+ delete($attr_ref->{'bgcolor'});
+ delete($attr_ref->{'background'});
+ }
+
+ my $attr_string;
+ foreach my $attr (keys(%$attr_ref)) {
+ $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
+ }
+ return $attr_string;
+}
+
+
###############################################
###############################################
@@ -2765,7 +3015,7 @@ ENDBODY
=back
-=head1 HTTP Helpers
+=head1 HTML Helpers
=over 4
@@ -2773,29 +3023,384 @@ ENDBODY
Returns a uniform footer for LON-CAPA web pages.
-Inputs:
-
-=over 4
+Inputs: none
=back
-Returns: A uniform footer for LON-CAPA web pages.
-
=cut
sub endbodytag {
my $endbodytag='