[LON-CAPA-cvs] cvs: loncom(version_2_8_X) /interface loncommon.pm

raeburn raeburn@source.lon-capa.org
Tue, 23 Dec 2008 19:27:12 -0000


raeburn		Tue Dec 23 19:27:12 2008 EDT

  Modified files:              (Branch: version_2_8_X)
    /loncom/interface	loncommon.pm 
  Log:
  - Backport 1.728.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.692.2.8 loncom/interface/loncommon.pm:1.692.2.9
--- loncom/interface/loncommon.pm:1.692.2.8	Sun Dec 21 15:32:30 2008
+++ loncom/interface/loncommon.pm	Tue Dec 23 19:27:12 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.692.2.8 2008/12/21 15:32:30 raeburn Exp $
+# $Id: loncommon.pm,v 1.692.2.9 2008/12/23 19:27:12 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2717,6 +2717,42 @@
     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
 }
 
+# -------------------------------------------------------------------- getlangs
+
+=pod
+
+=item * &getlangs($uname,$udom)
+
+Gets a user's language preference and returns it as a hash with key:
+language.
+
+=cut
+
+sub getlangs {
+    my ($uname,$udom) = @_;
+    if (!$udom)  { $udom =$env{'user.domain'}; }
+    if (!$uname) { $uname=$env{'user.name'};   }
+    my $id=$uname.':'.$udom;
+    my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
+    if ($cached) {
+        return %{$langs};
+    } else {
+        my %loadlangs=&Apache::lonnet::get('environment',['languages'],
+                                           $udom,$uname);
+        &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
+        return %loadlangs;
+    }
+}
+
+sub flush_langs_cache {
+    my ($uname,$udom)=@_;
+    if (!$udom)  { $udom =$env{'user.domain'}; }
+    if (!$uname) { $uname=$env{'user.name'};   }
+    return if ($udom eq 'public' && $uname eq 'public');
+    my $id=$uname.':'.$udom;
+    &Apache::lonnet::devalidate_cache_new('userlangs',$id);
+}
+
 # ------------------------------------------------------------------ Screenname
 
 =pod