--- loncom/interface/lonpreferences.pm 2001/12/19 17:17:46 1.2
+++ loncom/interface/lonpreferences.pm 2015/01/19 15:36:01 1.215
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.2 2001/12/19 17:17:46 albertel Exp $
+# $Id: lonpreferences.pm,v 1.215 2015/01/19 15:36:01 goltermann Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,41 +25,2361 @@
#
# http://www.lon-capa.org/
#
-# (Internal Server Error Handler
-#
-# (Login Screen
-# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
-# 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
-#
-# 3/1/1 Gerd Kortemeyer)
-#
-# 3/1 Gerd Kortemeyer
+# This package uses the "londes.js" javascript code.
#
+# TODOs that have to be completed:
+# interface with lonnet to change the password
+
package Apache::lonpreferences;
use strict;
+use LONCAPA;
use Apache::Constants qw(:common);
+use Apache::File;
+use Apache::loncommon();
+use Apache::lonhtmlcommon();
+use Apache::lonlocal;
+use Apache::lonnet;
+use LONCAPA::lonauthcgi();
+use LONCAPA();
+
+################################################################
+# Handler subroutines #
+################################################################
+
+################################################################
+# Language Change Subroutines #
+################################################################
+
+sub wysiwygchanger {
+ my $r = shift;
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changewysiwyg',
+ text => 'Change WYSIWYG Preferences'});
+ $r->print(Apache::loncommon::start_page('Content Display Settings'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change WYSIWYG Preferences'));
+
+ my %userenv = &Apache::lonnet::get
+ ('environment',['wysiwygeditor']);
+ my $onselect='checked="checked"';
+ my $offselect='';
+ if ($userenv{'wysiwygeditor'} eq 'on') {
+ $onselect='';
+ $offselect='checked="checked"';
+ }
+ my $switchoff=&mt('Disable WYSIWYG editor');
+ my $switchon=&mt('Enable WYSIWYG editor');
+ my $warning='';
+ if ($env{'user.adv'}) {
+ $warning.='
'.&mt("The WYSIWYG editor only supports simple HTML and is in many cases unsuited for advanced authoring. In a number of cases, it may destroy advanced authoring involving LaTeX and script function calls.")."
";
+ }
+ $r->print(<
+
+$warning
+
+
+
+ENDLSCREEN
+ $r->print(' ');
+}
+
+
+sub verify_and_change_wysiwyg {
+ my $r = shift;
+ my $newsetting=$env{'form.wysiwyg'};
+ &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
+ &Apache::lonnet::appenv({'environment.wysiwygeditor' => $newsetting});
+ my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.&mt('WYSIWYG Editor').'',''.&mt($newsetting).''));
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r,$message);
+}
+
+################################################################
+# Language Change Subroutines #
+################################################################
+sub languagechanger {
+ my $r = shift;
+
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changelanguages',
+ text => 'Change Language'});
+ $r->print(Apache::loncommon::start_page('Content Display Settings'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language'));
+ my %userenv = &Apache::lonnet::get('environment',['languages']);
+ my $language=$userenv{'languages'};
+
+ $r->print(
+ ''
+ );
+}
+
+
+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=&Apache::lonhtmlcommon::confirm_success(
+ &mt('Set [_1] to [_2]',
+ ''.&mt('Preferred language').'',
+ '"'.$newlanguage.'".'))
+ .' '
+ .&mt('The change will become active on the next page.');
+ } else {
+ &Apache::lonnet::del('environment',['languages']);
+ &Apache::lonnet::delenv('environment.languages');
+ $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]',''.&mt('Preferred language').''));
+ }
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &Apache::loncommon::flush_langs_cache($user,$domain);
+ &print_main_menu($r, $message);
+}
+
+################################################################
+# Tex Engine Change Subroutines #
+################################################################
+sub texenginechanger {
+ my $r = shift;
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changetexenginepref',
+ text => 'Math display settings'});
+ $r->print(Apache::loncommon::start_page('Content Display Settings'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Math display settings'));
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get('environment',['texengine']);
+ my $texengine=$userenv{'texengine'};
-sub handler {
+ my %mathchoices=('' => 'Default',
+ 'tth' => 'tth (TeX to HTML)',
+ #'ttm' => 'TeX to MathML',
+ 'jsMath' => 'jsMath',
+ 'MathJax' => 'MathJax',
+ 'mimetex' => 'mimetex (Convert to Images)',
+ 'raw' => 'Raw (Screen Reader)'
+ );
+ %mathchoices = &Apache::lonlocal::texthash(%mathchoices);
+ my $selectionbox=
+ &Apache::loncommon::select_form(
+ $texengine,
+ 'texengine',
+ \%mathchoices);
+ my $MathJax_start=&Apache::lontexconvert::MathJax_header();
+ my $jsMath_start=&Apache::lontexconvert::jsMath_header();
+ my %lt=&Apache::lonlocal::texthash(
+ 'headline' => 'Change how math is displayed',
+ 'preftxt' => 'Preferred method to display math',
+ 'change' => 'Save',
+ 'exmpl' => 'Examples',
+ 'mathjax' => 'MathJax:',
+ 'mathjaxinfo' => 'MathJax provides rendered equations whose source code can be extracted in TeX and MathML formats by right clicking the equation.',
+ 'jsmath' => 'jsMath:',
+ 'tth' => 'tth (TeX to HTML):',
+ 'mimetex' => 'mimetex (Convert to Images):',
+ );
+
+ my $jsMathWarning='
'
+ .'
'
+ .&mt("It looks like you don't have the TeX math fonts installed.")
+ .'
'
+ .'
'
+ .&mt('The jsMath example on this page may not look right without them. '
+ .'The [_1]jsMath Home Page[_2] has information on how to download the '
+ .'needed fonts. In the meantime, jsMath will do the best it can '
+ .'with the fonts you have, but it may not be pretty and some equations '
+ .'may not be rendered correctly.'
+ ,''
+ ,'')
+ .'
';
+ $r->print(<
+
+$iconic_preview
+$iconsonly_preview
+
+
+ENDSCREEN
+}
+
+sub verify_and_change_icons {
+ my $r = shift;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my $newicons = $env{'form.menumode'};
+ my %lt = &icon_options();
+ my $newchoice = $newicons;
+ if ($lt{$newicons}) {
+ $newchoice = $lt{$newicons};
+ }
+ &Apache::lonnet::put('environment',{'icons' => $newicons});
+ &Apache::lonnet::appenv({'environment.icons' => $newicons});
+ my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.&mt('Menu Display').'',''.$newchoice.''));
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r, $message);
+}
+
+sub icon_options {
+ return &Apache::lonlocal::texthash(
+ iconic => 'Use icons and text',
+ iconsonly => 'Use icons only',
+ );
+}
+
+sub icon_previews {
+ my %icon_text = (
+ annotate => 'Notes',
+ wishlist => 'Stored Links',
+ catalog => 'Info',
+ evaluate => 'Evaluate',
+ feedback => 'Communicate',
+ printout => 'Print',
+ );
+ my %inlinetools = (
+ printout => "s&8&3&prt.png&$icon_text{'printout'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document",
+ wishlist => "s&9&1&wishlist-link.png&$icon_text{'wishlist'}&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository",
+ evaluate => "s&8&1&eval.png&$icon_text{'evaluate'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource",
+ feedback => "s&8&2&fdbk.png&$icon_text{'feedback'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource",
+ annotate => "s&9&3&anot.png&$icon_text{'annotate'}&tations[_1]&annotate()&Make notes and annotations about this resource",
+ catalog => "s&6&3&catalog.png&$icon_text{'catalog'}&info[_1]&catalog_info()&Show Metadata",
+ );
+ my @toolsorder = qw(annotate wishlist evaluate feedback printout catalog);
+ return (\%inlinetools,\@toolsorder);
+}
+
+################################################################
+# Clicker Subroutines #
+################################################################
+
+sub clickerchanger {
+ my $r = shift;
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changeclicker',
+ text => 'Register Clicker'});
+ $r->print(Apache::loncommon::start_page('Other'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Register Clicker'));
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get
+ ('environment',['clickers']);
+ my $clickers=$userenv{'clickers'};
+ $clickers=~s/\,/\n/gs;
+ my $text=&mt('Enter response device ("clicker") numbers');
+ my $change=&mt('Save');
+ my $helplink=&Apache::loncommon::help_open_topic('Clicker_Registration',&mt('Locating your clicker ID'));
+ $r->print(<
+
+
+
+
+
+ENDSCREEN
+}
+
+sub verify_and_change_clicker {
+ my $r = shift;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my $newclickers = $env{'form.clickers'};
+ $newclickers=~s/[^\w\:\-]+/\,/gs;
+ $newclickers=~tr/a-z/A-Z/;
+ $newclickers=~s/[\:\-]+/\-/g;
+ $newclickers=~s/\,+/\,/g;
+ $newclickers=~s/^\,//;
+ $newclickers=~s/\,$//;
+ &Apache::lonnet::put('environment',{'clickers' => $newclickers});
+ &Apache::lonnet::appenv({'environment.clickers' => $newclickers});
+ my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Registering clickers: [_1]',$newclickers));
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r, $message);
+}
+
+################################################################
+# Domcoord Access Subroutines #
+################################################################
+
+sub domcoordchanger {
+ my $r = shift;
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changedomcoord',
+ text => 'Restrict Domain Coordinator Access'});
+ $r->print(Apache::loncommon::start_page('Restrict Domain Coordinator Access'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Restrict Domain Coordinator Access'));
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get
+ ('environment',['domcoord.author']);
+ my $constchecked='';
+ if ($userenv{'domcoord.author'} eq 'blocked') {
+ $constchecked=' checked="checked"';
+ }
+ my $text=&mt('By default, the Domain Coordinator can enter your Authoring Space.');
+ my $construction=&mt('Block access to Authoring Space');
+ my $change=&mt('Save');
+ $r->print(<
+
+$text
+
+
+
+ENDSCREEN
+}
+
+sub verify_and_change_domcoord {
+ my $r = shift;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %domcoord=('domcoord.author' => '');
+ if ($env{'form.construction'}) { $domcoord{'domcoord.author'}='blocked'; }
+ &Apache::lonnet::put('environment',\%domcoord);
+ &Apache::lonnet::appenv({'environment.domcoord.author' => $domcoord{'domcoord.author'}});
+ my $status='';
+ if ($domcoord{'domcoord.author'} eq 'blocked') {
+ $status=&mt('on');
+ } else {
+ $status=&mt('off');
+ }
+ my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.&mt('Block access to Authoring Space').'',''.$status.''));
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r,$message);
+}
+
+#################################################################
+## Lock Subroutines #
+#################################################################
+
+sub lockwarning {
+ my $r = shift;
+ my $title=&mt('Action locked');
+ my $texttop=&mt('LON-CAPA is currently performing the following actions:');
+ my $textbottom=&mt('Changing roles or logging out may result in data corruption.');
+ my ($num,%which)=&Apache::lonnet::get_locks();
+ my $which='';
+ foreach my $id (keys(%which)) {
+ $which.='
'.$which{$id}.'
';
+ }
+ my $change=&mt('Override');
+ $r->print(<
+
+
$title
+$texttop
+
+$which
+
+$textbottom
+
+
+ENDSCREEN
+}
+
+sub verify_and_change_lockwarning {
+ my $r = shift;
+ &Apache::lonnet::remove_all_locks();
+ $r->print(&mt('Cleared locks.'));
+}
+
+
+################################################################
+# Message Forward #
+################################################################
+
+sub msgforwardchanger {
+ my ($r,$message) = @_;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get('environment',['msgforward','notification','critnotification','notifywithhtml']);
+ my $msgforward=$userenv{'msgforward'};
+ my %lt = &Apache::lonlocal::texthash(
+ all => 'All',
+ crit => 'Critical only',
+ reg => 'Non-critical only',
+ foad => 'Forward to account(s)',
+ fwdm => 'Forward messages to other account(s) in LON-CAPA',
+ noti => 'E-mail notification of LON-CAPA messages',
+ mnot => 'E-mail address(es) which should be notified about new LON-CAPA messages',
+ chg => 'Save',
+ email => 'The e-mail address entered in row ',
+ notv => 'is not a valid e-mail address',
+ toen => "To enter multiple addresses, enter one address at a time, click 'Change' and then add the next one",
+ prme => 'Back',
+ );
+ $lt{'foad_exmpl'} = &mt('e.g. [_1]userA:domain1,userB:domain2,...[_2]','','');
+ $lt{'mnot_exmpl'} = &mt('e.g. [_1]joe@doe.com[_2]','','');
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changemsgforward',
+ text => 'Messages & Notifications'});
+ $r->print(Apache::loncommon::start_page('Messages & Notifications'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Messages & Notifications'));
+ my $forwardingHelp = &Apache::loncommon::help_open_topic("Prefs_Forwarding");
+ my $notificationHelp = &Apache::loncommon::help_open_topic("Prefs_Notification");
+ my $criticalMessageHelp = &Apache::loncommon::help_open_topic("Course_Critical_Message");
+ my @allow_html = split(/,/,$userenv{'notifywithhtml'});
+ my %allnot = &get_notifications(\%userenv);
+ my $validatescript = &Apache::lonhtmlcommon::javascript_valid_email();
+ my $jscript = qq|
+
+|;
+ $r->print(<$lt{'fwdm'} $forwardingHelp
+
+|);
+
+}
+
+sub get_notifications {
+ my ($userenv) = @_;
+ my %allnot;
+ my @critnot = split(/,/,$userenv->{'critnotification'});
+ my @regnot = split(/,/,$userenv->{'notification'});
+ foreach my $item (@critnot) {
+ $allnot{$item}{crit} = 1;
+ }
+ foreach my $item (@regnot) {
+ $allnot{$item}{reg} = 1;
+ }
+ return %allnot;
+}
+
+sub verify_and_change_msgforward {
+ my $r = shift;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my $newscreen = '';
+ my $message='';
+ foreach my $recip (split(/\,/,$env{'form.msgforward'})) {
+ my ($msuser,$msdomain);
+ if ($recip =~ /:/) {
+ ($msuser,$msdomain)=split(':',$recip);
+ } else {
+ ($msuser,$msdomain)=split(/\@/,$recip);
+ }
+ $msuser = &LONCAPA::clean_username($msuser);
+ $msdomain = &LONCAPA::clean_domain($msdomain);
+ if (($msuser) && ($msdomain)) {
+ if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
+ $newscreen.=$msuser.':'.$msdomain.',';
+ } else {
+ $message.= &mt('No such user: ').''.$msuser.':'.$msdomain.' ';
+ }
+ }
+ }
+ $newscreen=~s/\,$//;
+ if ($newscreen) {
+ &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
+ &Apache::lonnet::appenv({'environment.msgforward' => $newscreen});
+ $message .= &Apache::lonhtmlcommon::confirm_success(&mt('Set message forwarding to ').'"'.$newscreen.'". ');
+ } else {
+ &Apache::lonnet::del('environment',['msgforward']);
+ &Apache::lonnet::delenv('environment.msgforward');
+ $message.= &Apache::lonhtmlcommon::confirm_success(&mt("Set message forwarding to 'off'.").' ');
+ }
+ my $critnotification;
+ my $notification;
+ my $notify_with_html;
+ my $lastnotify = $env{'form.numnotify'}-1;
+ my $totaladdresses = 0;
+ for (my $i=0; $i<$env{'form.numnotify'}; $i++) {
+ if ((!defined($env{'form.del_notify_'.$i})) &&
+ ((($i==$lastnotify) && ($env{'form.add_notify_'.$lastnotify} == 1)) ||
+ ($i<$lastnotify))) {
+ if (defined($env{'form.address_'.$i})) {
+ if ($env{'form.notify_type_'.$i} eq 'all') {
+ $critnotification .= $env{'form.address_'.$i}.',';
+ $notification .= $env{'form.address_'.$i}.',';
+ } elsif ($env{'form.notify_type_'.$i} eq 'crit') {
+ $critnotification .= $env{'form.address_'.$i}.',';
+ } elsif ($env{'form.notify_type_'.$i} eq 'reg') {
+ $notification .= $env{'form.address_'.$i}.',';
+ }
+ if ($env{'form.html_'.$i} eq '1') {
+ $notify_with_html .= $env{'form.address_'.$i}.',';
+ }
+ $totaladdresses ++;
+ }
+ }
+ }
+ $critnotification =~ s/,$//;
+ $critnotification=~s/\s//gs;
+ $notification =~ s/,$//;
+ $notification=~s/\s//gs;
+ $notify_with_html =~ s/,$//;
+ $notify_with_html =~ s/\s//gs;
+ if ($notification) {
+ &Apache::lonnet::put('environment',{'notification' => $notification});
+ &Apache::lonnet::appenv({'environment.notification' => $notification});
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set non-critical message notification address(es) to ').'"'.$notification.'". ');
+ } else {
+ &Apache::lonnet::del('environment',['notification']);
+ &Apache::lonnet::delenv('environment.notification');
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt("Set non-critical message notification to 'off'.").' ');
+ }
+ if ($critnotification) {
+ &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
+ &Apache::lonnet::appenv({'environment.critnotification' => $critnotification});
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set critical message notification address(es) to ').'"'.$critnotification.'". ');
+ } else {
+ &Apache::lonnet::del('environment',['critnotification']);
+ &Apache::lonnet::delenv('environment.critnotification');
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt("Set critical message notification to 'off'.").' ');
+ }
+ if ($critnotification || $notification) {
+ if ($notify_with_html) {
+ &Apache::lonnet::put('environment',{'notifywithhtml' => $notify_with_html});
+ &Apache::lonnet::appenv({'environment.notifywithhtml' => $notify_with_html});
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set address(es) to receive excerpts with html retained ').'"'.$notify_with_html.'".');
+ } else {
+ &Apache::lonnet::del('environment',['notifywithhtml']);
+ &Apache::lonnet::delenv('environment.notifywithhtml');
+ if ($totaladdresses == 1) {
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt("Set notification address to receive excerpts with html stripped."));
+ } else {
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt("Set all notification addresses to receive excerpts with html stripped."));
+ }
+ }
+ } else {
+ &Apache::lonnet::del('environment',['notifywithhtml']);
+ &Apache::lonnet::delenv('environment.notifywithhtml');
+ }
+ &Apache::loncommon::flush_email_cache($user,$domain);
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &msgforwardchanger($r,$message);
+}
+
+################################################################
+# Colors #
+################################################################
+
+sub colorschanger {
+ my $r = shift;
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changecolors',
+ text => 'Change Colors'});
+ $r->print(Apache::loncommon::start_page('Page Display Settings'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Colors'));
+# figure out colors
+ my $function=&Apache::loncommon::get_users_function();
+ my $domain=&Apache::loncommon::determinedomain();
+ my %colortypes=&Apache::lonlocal::texthash(
+ 'pgbg' => 'Page Background Color',
+ 'tabbg' => 'Header Background Color',
+ 'sidebg' => 'Header Border Color',
+ 'font' => 'Font Color',
+ 'fontmenu' => 'Font Menu Color',
+ 'link' => 'Un-Visited Link Color',
+ 'vlink' => 'Visited Link Color',
+ 'alink' => 'Active Link Color',
+ );
+ my $start_data_table = &Apache::loncommon::start_data_table();
+ my $chtable='';
+ foreach my $item (sort(keys(%colortypes))) {
+ my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain);
+ $chtable.=&Apache::loncommon::start_data_table_row().
+ '
'.$colortypes{$item}.'
'.
+ &Apache::loncommon::end_data_table_row()."\n";
+ }
+ my $end_data_table = &Apache::loncommon::end_data_table();
+ my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
+ my $savebutton = &mt('Save');
+ my $resetbutton = &mt('Reset All');
+ my $resetbuttondesc = &mt('Reset All Colors to Default');
+ my $colorchooser=&Apache::lonhtmlcommon::color_picker();
+ $r->print('
+');
+ $r->print(<
+
+
+
+
+
+ENDCOL
+}
+
+sub verify_and_change_colors {
+ my $r = shift;
+# figure out colors
+ my $function=&Apache::loncommon::get_users_function();
+ my $domain=&Apache::loncommon::determinedomain();
+ my %colortypes=&Apache::lonlocal::texthash(
+ 'pgbg' => 'Page Background Color',
+ 'tabbg' => 'Header Background Color',
+ 'sidebg' => 'Header Border Color',
+ 'font' => 'Font Color',
+ 'fontmenu' => 'Font Menu Color',
+ 'link' => 'Un-Visited Link Color',
+ 'vlink' => 'Visited Link Color',
+ 'alink' => 'Active Link Color',
+ );
+
+ my $message='';
+ foreach my $item (keys(%colortypes)) {
+ my $color=$env{'form.'.$item};
+ if (!($color =~ /^#/)) {
+ $color = '#' . $color;
+ }
+ my $entry='color.'.$function.'.'.$item;
+ if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
+ &Apache::lonnet::put('environment',{$entry => $color});
+ &Apache::lonnet::appenv({'environment.'.$entry => $color});
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.$colortypes{$item}.'','"'.$color.'"'))
+ .' ';
+ } else {
+ &Apache::lonnet::del('environment',[$entry]);
+ &Apache::lonnet::delenv('environment.'.$entry);
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]',''.$colortypes{$item}.''))
+ .' ';
+ }
+ }
+ $message=&Apache::loncommon::confirmwrapper($message);
+
+ my $now = time;
+ &Apache::lonnet::put('environment',{'color.timestamp' => $now});
+ &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
+
+ &print_main_menu($r, $message);
+}
+
+######################################################
+# password handler subroutines #
+######################################################
+sub passwordchanger {
+ my ($r,$errormessage,$caller,$mailtoken) = @_;
+ # This function is a bit of a mess....
+ # Passwords are encrypted using londes.js (DES encryption)
+ $errormessage = ($errormessage || '');
+ my ($user,$domain,$currentpass);
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changepass',
+ text => 'Change Password'});
+ unless ($caller eq 'reset_by_email') {
+ $r->print(Apache::loncommon::start_page('Personal Data'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Password'));
+ }
+ if ((!defined($caller)) || ($caller eq 'preferences')) {
+ $user = $env{'user.name'};
+ $domain = $env{'user.domain'};
+ if (!defined($caller)) {
+ $caller = 'preferences';
+ }
+ } elsif ($caller eq 'reset_by_email') {
+ my %data = &Apache::lonnet::tmpget($mailtoken);
+ if (keys(%data) == 0) {
+ $r->print(
+ '
'
+ .&mt('Sorry, the URL you provided to complete the reset of your password was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a [_1]new request[_2] for a password reset, and follow the link to the new URL included in the e-mail that will be sent to you, to allow you to enter a new password.'
+ ,'','')
+ .'
",
+ $caller,$mailtoken);
+ return 1;
+ }
+ } else {
+ $user = $env{'user.name'};
+ $domain = $env{'user.domain'};
+ $homeserver = $env{'user.home'};
+ }
+ my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
+ # Check for authentication types that allow changing of the password.
+ if ($currentauth !~ /^(unix|internal):/) {
+ if ($caller eq 'reset_by_email') {
+ &passwordchanger($r,"
\n".
+ &mt("Authentication type for this user can not be changed by this mechanism").
+ "\n
",
+ $caller,$mailtoken);
+ return 1;
+ } else {
+ return;
+ }
+ }
+ #
+ my $currentpass = $env{'form.currentpass'};
+ my $newpass1 = $env{'form.newpass_1'};
+ my $newpass2 = $env{'form.newpass_2'};
+ my $logtoken = $env{'form.logtoken'};
+ # Check for empty data
+ unless (defined($currentpass) &&
+ defined($newpass1) &&
+ defined($newpass2) ){
+ &passwordchanger($r,"
\n".
+ &mt("One or more password fields were blank").
+ "\n
",$caller,$mailtoken);
+ return;
+ }
+ # Get the keys
+ my $lonhost = $r->dir_config('lonHostID');
+ my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
+ if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
+ # I do not a have a better idea about how to handle this
+ my $tryagain_text = &mt('Please log out and try again.');
+ if ($caller eq 'reset_by_email') {
+ $tryagain_text = &mt('Please try again later.');
+ }
+ my $unable=&mt("Unable to retrieve saved token for password decryption");
+ $r->print(<
+$unable. $tryagain_text
+
+ENDERROR
+ # Probably should log an error here
+ return 1;
+ }
+ my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
+ #
+ $currentpass = &Apache::loncommon::des_decrypt($ckey ,$currentpass);
+ $newpass1 = &Apache::loncommon::des_decrypt($n1key,$newpass1);
+ $newpass2 = &Apache::loncommon::des_decrypt($n2key,$newpass2);
+ #
+ if ($caller eq 'reset_by_email') {
+ my %data = &Apache::lonnet::tmpget($mailtoken);
+ if (keys(%data) == 0) {
+ &passwordchanger($r,
+ ''.
+ &mt('Could not verify current authentication.').' '.
+ &mt('Please try again.').'',$caller,$mailtoken);
+ return 1;
+ }
+ if ($currentpass ne $data{'temppasswd'}) {
+ &passwordchanger($r,
+ ''.
+ &mt('Could not verify current authentication.').' '.
+ &mt('Please try again.').'',$caller,$mailtoken);
+ return 1;
+ }
+ }
+ if ($newpass1 ne $newpass2) {
+ &passwordchanger($r,
+ ''.
+ &mt('The new passwords you entered do not match.').' '.
+ &mt('Please try again.').'',$caller,$mailtoken);
+ return 1;
+ }
+ if (length($newpass1) < 7) {
+ &passwordchanger($r,
+ ''.
+ &mt('Passwords must be a minimum of 7 characters long.').' '.
+ &mt('Please try again.').'',$caller,$mailtoken);
+ return 1;
+ }
+ #
+ # Check for bad characters
+ my $badpassword = 0;
+ foreach (split(//,$newpass1)) {
+ $badpassword = 1 if ((ord($_)<32)||(ord($_)>126));
+ }
+ if ($badpassword) {
+ # I can't figure out how to enter bad characters on my browser.
+ my $errormessage =''.
+ &mt('The password you entered contained illegal characters.').' '.
+ &mt('Valid characters are').(<<"ENDERROR");
+: space and
+