[LON-CAPA-cvs] cvs: loncom /interface domainprefs.pm /localize lonlocal.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sat, 31 May 2008 23:37:49 -0000


raeburn		Sat May 31 19:37:49 2008 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm 
    /loncom/localize	lonlocal.pm 
  Log:
  Bug 5722.
  A default timezone can be set for a domain via the Domain Configuration menu.  This will be the timezone in effect in courses in the domain for which a course-specific timezone has not been set in the course environment.
  
  
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.53 loncom/interface/domainprefs.pm:1.54
--- loncom/interface/domainprefs.pm:1.53	Wed May 28 23:27:33 2008
+++ loncom/interface/domainprefs.pm	Sat May 31 19:37:46 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.53 2008/05/29 03:27:33 raeburn Exp $
+# $Id: domainprefs.pm,v 1.54 2008/05/31 23:37:46 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -96,7 +96,7 @@
                                   col2 => '',}],
                     },
         'defaults' => 
-                    { text => 'Default authentication/language',
+                    { text => 'Default authentication/language/timezone',
                       help => '',
                       header => [{col1 => 'Setting',
                                   col2 => 'Value'}],
@@ -1782,7 +1782,7 @@
 
 sub print_defaults {
     my ($dom,$rowtotal) = @_;
-    my @items = ('auth_def','auth_arg_def','lang_def');
+    my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');
     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
     my $titles = &defaults_titles();
     my $rownum = 0;
@@ -1814,6 +1814,9 @@
                               '" value="'.$auth.'"'.$checked.'/>'.
                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
             }
+        } elsif ($item eq 'timezone_def') {
+            my $includeempty = 1;
+            $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
         } else {
             $datatable .= '<input type="text" name="'.$item.'" value="'.
                           $domdefaults{$item}.'" />';
@@ -1830,6 +1833,7 @@
                    'auth_def'      => 'Default authentication type',
                    'auth_arg_def'  => 'Default authentication argument',
                    'lang_def'      => 'Default language',
+                   'timezone_def'  => 'Default timezone',
                  );
     return (\%titles);
 }
@@ -4067,7 +4071,7 @@
     my ($dom,$r) = @_;
     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
-    my @items = ('auth_def','auth_arg_def','lang_def');
+    my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');
     my @authtypes = ('internal','krb4','krb5','localauth');
     foreach my $item (@items) {
         $newvalues{$item} = $env{'form.'.$item};
@@ -4088,6 +4092,13 @@
                     push(@errors,$item);
                 }
             }
+        } elsif ($item eq 'timezone_def') {
+            if ($newvalues{$item} ne '') {
+                my @timezones = &DateTime::TimeZone->all_names;
+                if (!grep(/^\Q$newvalues{$item}\E/,@timezones)) {
+                    push(@errors,$item);   
+                }
+            }
         }
         if (grep(/^\Q$item\E$/,@errors)) {
             $newvalues{$item} = $domdefaults{$item};
@@ -4099,6 +4110,7 @@
                          defaults => { auth_def => $newvalues{'auth_def'},
                                        auth_arg_def => $newvalues{'auth_arg_def'},
                                        lang_def => $newvalues{'lang_def'},
+                                       timezone_def => $newvalues{'timezone_def'},
                                      }
                        );
     my $title = &defaults_titles();
@@ -4131,10 +4143,12 @@
             my $cachetime = 24*60*60;
             &Apache::lonnet::do_cache_new('domdefaults',$dom,
                                           $defaults_hash{'defaults'},$cachetime);
-            my $sysmail = $r->dir_config('lonSysEMail');
-            &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
+            if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'}) {
+                my $sysmail = $r->dir_config('lonSysEMail');
+                &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
+            }
         } else {
-            $resulttext = &mt('No changes made to default authentication/language settings');
+            $resulttext = &mt('No changes made to default authentication/language/timezone settings');
         }
     } else {
         $resulttext = '<span class="LC_error">'.
Index: loncom/localize/lonlocal.pm
diff -u loncom/localize/lonlocal.pm:1.44 loncom/localize/lonlocal.pm:1.45
--- loncom/localize/lonlocal.pm:1.44	Fri May 16 12:11:56 2008
+++ loncom/localize/lonlocal.pm	Sat May 31 19:37:49 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Localization routines
 #
-# $Id: lonlocal.pm,v 1.44 2008/05/16 16:11:56 raeburn Exp $
+# $Id: lonlocal.pm,v 1.45 2008/05/31 23:37:49 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -267,9 +267,16 @@
 
 # ========================================================== Localize localtime
 sub gettimezone {
-    my ($time) = @_;
     if ($Apache::lonnet::env{'course.'.$Apache::lonnet::env{'request.course.id'}.'.timezone'}) {
 	return $Apache::lonnet::env{'course.'.$Apache::lonnet::env{'request.course.id'}.'.timezone'};
+    } elsif ($Apache::lonnet::env{'request.course.id'} ne '') {
+        my $cdom = $Apache::lonnet::env{'course.'.$Apache::lonnet::env{'request.course.id'}.'.domain'};
+        if ($cdom ne '') {
+            my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
+            if ($domdefaults{'timezone_def'} ne '') {
+                return $domdefaults{'timezone_def'};
+            }
+        }
     }
     return 'local';
 }