--- loncom/interface/loncommon.pm 2007/12/08 19:19:02 1.623
+++ loncom/interface/loncommon.pm 2008/03/06 21:42:51 1.645
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.623 2007/12/08 19:19:02 raeburn Exp $
+# $Id: loncommon.pm,v 1.645 2008/03/06 21:42:51 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,6 +78,58 @@ my $readit;
## Global Variables
##
+
+# ----------------------------------------------- SSI with retries:
+#
+
+=pod
+
+=head1 Server Side incliude with retries:
+
+=over 4
+
+=item * ssi_with_retries(resource, retries form)
+
+Performs an ssi with some number of retries. Retries continue either
+until the result is ok or until the retry count supplied by the
+caller is exhausted.
+
+Inputs:
+resource - Identifies the resource to insert.
+retries - Count of the number of retries allowed.
+form - Hash that identifies the rendering options.
+
+Returns:
+content - The content of the response. If retries were exhausted this is empty.
+response - The response from the last attempt (which may or may not have been successful.
+
+=cut
+
+sub ssi_with_retries {
+ my ($resource, $retries, %form) = @_;
+
+
+ my $ok = 0; # True if we got a good response.
+ my $content;
+ my $response;
+
+ # Try to get the ssi done. within the retries count:
+
+ do {
+ ($content, $response) = &Apache::lonnet::ssi($resource, %form);
+ $ok = $response->is_success;
+ $retries--;
+ } while (!$ok && ($retries > 0));
+
+ if (!$ok) {
+ $content = ''; # On error return an empty content.
+ }
+ return ($content, $response);
+
+}
+
+
+
# ----------------------------------------------- Filetypes/Languages/Copyright
my %language;
my %supported_language;
@@ -472,7 +524,10 @@ sub setsec_javascript {
my ($sec_element,$formname) = @_;
my $setsections = qq|
function setSect(sectionlist) {
- var sectionsArray = sectionlist.split(",");
+ var sectionsArray = new Array();
+ if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
+ sectionsArray = sectionlist.split(",");
+ }
var numSections = sectionsArray.length;
document.$formname.$sec_element.length = 0;
if (numSections == 0) {
@@ -779,10 +834,10 @@ sub helpLatexCheatsheet {
}
return '
'.
$addOther .
- &Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols',
+ &Apache::loncommon::help_open_topic("Greek_Symbols",&mt('Greek Symbols'),
undef,undef,600)
.' | '.
- &Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols',
+ &Apache::loncommon::help_open_topic("Other_Symbols",&mt('Other Symbols'),
undef,undef,600)
.' |
';
}
@@ -2239,42 +2294,6 @@ sub get_assignable_auth {
}
###############################################################
-## Get Authentication Defaults for Domain ##
-###############################################################
-
-=pod
-
-=head1 Domains and Authentication
-
-Returns default authentication type and an associated argument as
-listed in file 'domain.tab'.
-
-=over 4
-
-=item * get_auth_defaults
-
-get_auth_defaults($target_domain) returns the default authentication
-type and an associated argument (initial password or a kerberos domain).
-These values are stored in lonTabs/domain.tab
-
-($def_auth, $def_arg) = &get_auth_defaults($target_domain);
-
-If target_domain is not found in domain.tab, returns nothing ('').
-
-=cut
-
-#-------------------------------------------
-sub get_auth_defaults {
- my $domain=shift;
- return (&Apache::lonnet::domain($domain,'auth_def'),
- &Apache::lonnet::domain($domain,'auth_arg_def'));
-
-}
-###############################################################
-## End Get Authentication Defaults for Domain ##
-###############################################################
-
-###############################################################
## Get Kerberos Defaults for Domain ##
###############################################################
##
@@ -2289,8 +2308,8 @@ sub get_auth_defaults {
=item * get_kerberos_defaults
get_kerberos_defaults($target_domain) returns the default kerberos
-version and domain. If not found in domain.tabs, it defaults to
-version 4 and the domain of the server.
+version and domain. If not found, it defaults to version 4 and the
+domain of the server.
($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
@@ -2299,9 +2318,12 @@ version 4 and the domain of the server.
#-------------------------------------------
sub get_kerberos_defaults {
my $domain=shift;
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_auth_defaults($domain);
- unless ($krbdef =~/^krb/ && $krbdefdom) {
+ my ($krbdef,$krbdefdom);
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
+ if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
+ $krbdef = $domdefaults{'auth_def'};
+ $krbdefdom = $domdefaults{'auth_arg_def'};
+ } else {
$ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
my $krbdefdom=$1;
$krbdefdom=~tr/a-z/A-Z/;
@@ -2880,21 +2902,15 @@ sub preferred_languages {
map { (split(/\s*;\s*/,$_))[0] } (split(/\s*,\s*/,$browser));
push(@languages,@browser);
}
- if (&Apache::lonnet::domain($env{'user.domain'},'lang_def')) {
- @languages=(@languages,
- &Apache::lonnet::domain($env{'user.domain'},
- 'lang_def'));
- }
- if (&Apache::lonnet::domain($env{'request.role.domain'},'lang_def')) {
- @languages=(@languages,
- &Apache::lonnet::domain($env{'request.role.domain'},
- 'lang_def'));
- }
- if (&Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
- 'lang_def')) {
- @languages=(@languages,
- &Apache::lonnet::domain($Apache::lonnet::perlvar{'lonDefDomain'},
- 'lang_def'));
+
+ foreach my $domtype ($env{'user.domain'},$env{'request.role.domain'},
+ $Apache::lonnet::perlvar{'lonDefDomain'}) {
+ if ($domtype ne '') {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($domtype);
+ if ($domdefs{'lang_def'} ne '') {
+ push(@languages,$domdefs{'lang_def'});
+ }
+ }
}
# turn "en-ca" into "en-ca,en"
my @genlanguages;
@@ -3667,45 +3683,78 @@ sub get_domainconf {
my %domconfig = &Apache::lonnet::get_dom('configuration',
['login','rolecolors'],$udom);
- my %designhash;
+ my (%designhash,%legacy);
if (keys(%domconfig) > 0) {
if (ref($domconfig{'login'}) eq 'HASH') {
- foreach my $key (keys(%{$domconfig{'login'}})) {
- $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
+ if (keys(%{$domconfig{'login'}})) {
+ foreach my $key (keys(%{$domconfig{'login'}})) {
+ $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
+ }
+ } else {
+ $legacy{'login'} = 1;
}
+ } else {
+ $legacy{'login'} = 1;
}
if (ref($domconfig{'rolecolors'}) eq 'HASH') {
- foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
- if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
- foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
- $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
+ if (keys(%{$domconfig{'rolecolors'}})) {
+ foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
+ if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
+ foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
+ $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
+ }
}
}
+ } else {
+ $legacy{'rolecolors'} = 1;
}
+ } else {
+ $legacy{'rolecolors'} = 1;
}
- } else {
- my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
- my $designfile = $designdir.'/'.$udom.'.tab';
- if (-e $designfile) {
- if ( open (my $fh,"<$designfile") ) {
- while (my $line = <$fh>) {
- next if ($line =~ /^\#/);
- chomp($line);
- my ($key,$val)=(split(/\=/,$line));
- if ($val) { $designhash{$udom.'.'.$key}=$val; }
+ if (keys(%legacy) > 0) {
+ my %legacyhash = &get_legacy_domconf($udom);
+ foreach my $item (keys(%legacyhash)) {
+ if ($item =~ /^\Q$udom\E\.login/) {
+ if ($legacy{'login'}) {
+ $designhash{$item} = $legacyhash{$item};
+ }
+ } else {
+ if ($legacy{'rolecolors'}) {
+ $designhash{$item} = $legacyhash{$item};
+ }
}
- close($fh);
}
}
- if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
- $designhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
- }
+ } else {
+ %designhash = &get_legacy_domconf($udom);
}
&Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
$cachetime);
return %designhash;
}
+sub get_legacy_domconf {
+ my ($udom) = @_;
+ my %legacyhash;
+ my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
+ my $designfile = $designdir.'/'.$udom.'.tab';
+ if (-e $designfile) {
+ if ( open (my $fh,"<$designfile") ) {
+ while (my $line = <$fh>) {
+ next if ($line =~ /^\#/);
+ chomp($line);
+ my ($key,$val)=(split(/\=/,$line));
+ if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
+ }
+ close($fh);
+ }
+ }
+ if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
+ $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
+ }
+ return %legacyhash;
+}
+
=pod
=item * &domainlogo()
@@ -3755,10 +3804,10 @@ Returns: value of designparamter $which
sub designparm {
my ($which,$domain)=@_;
if ($env{'browser.blackwhite'} eq 'on') {
- if ($which=~/\.(font|alink|vlink|link)$/) {
+ if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
return '#000000';
}
- if ($which=~/\.(pgbg|sidebg)$/) {
+ if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
return '#FFFFFF';
}
if ($which=~/\.tabbg$/) {
@@ -3777,7 +3826,7 @@ sub designparm {
$output = $defaultdesign{$which};
}
if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
- ($which =~ /login\.(img|logo|domlogo)/)) {
+ ($which =~ /login\.(img|logo|domlogo|login)/)) {
if ($output =~ m{^/(adm|res)/}) {
if ($output =~ m{^/res/}) {
my $local_name = &Apache::lonnet::filelocation('',$output);
@@ -3945,7 +3994,7 @@ ENDROLE
$dc_info = '('.$dc_info.')';
}
- if ($env{'environment.remote'} eq 'off') {
+ if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
# No Remote
if ($env{'request.state'} eq 'construct') {
$forcereg=1;
@@ -3968,9 +4017,9 @@ ENDROLE
$lastitem = $thisdisfn;
}
$titleinfo =
- &Apache::loncommon::help_open_menu('','',3,'Authoring').
- 'Construction Space: '.
- '