--- loncom/interface/lonpreferences.pm	2003/08/29 03:08:18	1.27
+++ loncom/interface/lonpreferences.pm	2003/11/08 01:45:26	1.33
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.27 2003/08/29 03:08:18 bowersj2 Exp $
+# $Id: lonpreferences.pm,v 1.33 2003/11/08 01:45:26 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -51,6 +51,7 @@ use Crypt::DES;
 use DynaLoader; # for Crypt::DES version
 use Apache::loncommon();
 use Apache::lonhtmlcommon();
+use Apache::lonlocal;
 
 #
 # Write lonnet::passwd to do the call below.
@@ -101,6 +102,70 @@ sub des_decrypt {
 ################################################################
 
 ################################################################
+#         Language Change Subroutines                          #
+################################################################
+sub languagechanger {
+    my $r = shift;
+    my $user       = $ENV{'user.name'};
+    my $domain     = $ENV{'user.domain'};
+    my %userenv = &Apache::lonnet::get
+        ('environment',['languages']);
+    my $language=$userenv{'languages'};
+
+    my $bodytag=&Apache::loncommon::bodytag(
+              'Change Your Language Preferences');
+    my $pref=&mt('Preferred language');
+    my %langchoices=('' => 'No language preference');
+    foreach (&Apache::loncommon::languageids()) {
+	if (&Apache::loncommon::supportedlanguagecode($_)) {
+	    $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
+	               = &Apache::loncommon::plainlanguagedescription($_);
+	}
+    }
+    my $selectionbox=&Apache::loncommon::select_form($language,'language',
+						     %langchoices);
+    $r->print(<<ENDLSCREEN);
+<html>
+$bodytag
+
+<form name="server" action="/adm/preferences" method="post">
+<input type="hidden" name="action" value="verify_and_change_languages" />
+<br />$pref: $selectionbox
+ENDLSCREEN
+    $r->print('<br /><input type="submit" value="'.&mt('Change').'" /></form></body></html>');
+}
+
+
+sub verify_and_change_languages {
+    my $r = shift;
+    my $user       = $ENV{'user.name'};
+    my $domain     = $ENV{'user.domain'};
+# Screenname
+    my $newlanguage  = $ENV{'form.language'};
+    $newlanguage=~s/[^\-\w]//g;
+    my $message='';
+    if ($newlanguage) {
+        &Apache::lonnet::put('environment',{'languages' => $newlanguage});
+        &Apache::lonnet::appenv('environment.languages' => $newlanguage);
+        $message='Set new preferred languages to '.$newlanguage;
+    } else {
+        &Apache::lonnet::del('environment',['languages']);
+        &Apache::lonnet::delenv('environment\.languages');
+        $message='Reset preferred language';
+    }
+    my $bodytag=&Apache::loncommon::bodytag(
+                    'Change Your Language Preferences');
+    $r->print(<<ENDVCSCREEN);
+<html>
+$bodytag
+</p>
+$message
+</body></html>
+ENDVCSCREEN
+}
+
+
+################################################################
 #         Anonymous Discussion Name Change Subroutines         #
 ################################################################
 sub screennamechanger {
@@ -635,7 +700,7 @@ sub handler {
     my $r = shift;
     my $user = $ENV{'user.name'};
     my $domain = $ENV{'user.domain'};
-    $r->content_type('text/html');
+    &Apache::loncommon::content_type($r,'text/html');
     # Some pages contain DES keys and should not be cached.
     &Apache::loncommon::no_cache($r);
     $r->send_http_header;
@@ -657,6 +722,10 @@ sub handler {
         &colorschanger($r);
     } elsif ($ENV{'form.action'} eq 'verify_and_change_colors') {
         &verify_and_change_colors($r);
+    } elsif ($ENV{'form.action'} eq 'changelanguages') {
+        &languagechanger($r);
+    } elsif ($ENV{'form.action'} eq 'verify_and_change_languages') {
+        &verify_and_change_languages($r);
     } elsif ($ENV{'form.action'} eq 'debugtoggle') {
 	if (($ENV{'user.name'} eq 'albertel' ) ||
             ($ENV{'user.name'} eq 'kortemey' ) ||
@@ -715,6 +784,13 @@ ENDABOUTME
 </form>
 ENDCOLORFORM
 
+	    $r->print(<<ENDLANGUAGES);
+<form name="client" action="/adm/preferences" method="post">
+<input type="hidden" name="action" value="changelanguages" />
+<input type="submit" value="Change language preferences" />
+</form>
+ENDLANGUAGES
+
 	if (($ENV{'user.name'} eq 'albertel' ) ||
             ($ENV{'user.name'} eq 'kortemey' ) ||
             ($ENV{'user.name'} eq 'korte')) {