--- loncom/interface/lonpreferences.pm 2021/12/14 00:30:54 1.196.4.28 +++ loncom/interface/lonpreferences.pm 2022/09/19 19:49:26 1.196.4.28.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # Preferences # -# $Id: lonpreferences.pm,v 1.196.4.28 2021/12/14 00:30:54 raeburn Exp $ +# $Id: lonpreferences.pm,v 1.196.4.28.2.1 2022/09/19 19:49:26 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,7 +31,6 @@ package Apache::lonpreferences; use strict; -use LONCAPA; use Apache::Constants qw(:common); use Apache::File; use Apache::loncommon(); @@ -40,6 +39,7 @@ use Apache::lonlocal; use Apache::lonnet; use LONCAPA::lonauthcgi(); use LONCAPA(); +use DateTime::TimeZone(); ################################################################ # Handler subroutines # @@ -2094,13 +2094,9 @@ sub change_authoring_settings { sub lockednameschanger { my $r = shift; - &Apache::lonhtmlcommon::add_breadcrumb( - { href => '/adm/preferences?action=changelockednames', - text => 'Automatic name changes'}); - $r->print(Apache::loncommon::start_page('Automatic name changes')); - $r->print(Apache::lonhtmlcommon::breadcrumbs('Allow/disallow name updates')); my %userenv = &Apache::lonnet::get('environment',['lockedname']); my $lockedname=''; + my $ended; if (&can_toggle_namelocking()) { if ($userenv{'lockedname'}) { $lockedname = ' checked="checked"'; @@ -2118,6 +2114,11 @@ sub lockednameschanger { } } if (keys(%updateable)) { + &Apache::lonhtmlcommon::add_breadcrumb( + { href => '/adm/preferences?action=changelockednames', + text => 'Automatic name changes'}); + $r->print(Apache::loncommon::start_page('Automatic name changes')); + $r->print(Apache::lonhtmlcommon::breadcrumbs('Allow/disallow name updates')); my %longnames = &Apache::lonlocal::texthash ( firstname => 'First Name', middlename => 'Middle Name', @@ -2144,11 +2145,14 @@ ENDSCREEN } else { my $message = &mt('Based on your institutional affiliation no name information is automatically updated for your LON-CAPA account.'); &print_main_menu($r,$message); + $ended = 1; } } else { my $message = &mt('You are not permitted to set a user preference for automatic name updates for your LON-CAPA account.'); &print_main_menu($r,$message); + $ended = 1; } + return $ended; } sub verify_and_change_lockednames { @@ -2179,6 +2183,120 @@ sub verify_and_change_lockednames { &print_main_menu($r,$message); } +sub timezonechanger { + my $r = shift; + my $uname = $env{'user.name'}; + my $udom = $env{'user.domain'}; + if (&Apache::lonnet::usertools_access($uname,$udom,'timezone')) { + my $js = <<"ENDSCRIPT"; + +ENDSCRIPT + my %loaditems = ( + onload => 'javascript:toggleTZdisplay(document.prefs);', + ); + my $args = { 'add_entries' => \%loaditems }; + &Apache::lonhtmlcommon::add_breadcrumb( + { href => '/adm/preferences?action=', + text => 'Set Your Time Zone'}); + $r->print(Apache::loncommon::start_page('Set Your Time Zone',$js,$args)); + $r->print(Apache::lonhtmlcommon::breadcrumbs('Set Your Time Zone')); + my %userenv = &Apache::lonnet::get('environment',['timezone']); + my $timezone = $userenv{'timezone'}; + my %lt = &Apache::lonlocal::texthash( + lctz => 'Use Time Zone set by LON-CAPA', + owntz => 'Use Time Zone set by you', + save => 'Save', + ); + my (%checked,$tzsty); + if ($userenv{'timezone'} ne '') { + $checked{'owntz'} = ' checked="checked"'; + $tzsty = 'inline-block'; + } else { + $checked{'lctz'} = ' checked="checked"'; + $tzsty = 'none'; + } + my $onclick = ' onclick="javascript:toggleTZdisplay(this.form);"'; + my $selector = &Apache::loncommon::select_timezone('timezone',$timezone,undef,1); + $r->print(<<"END"); +
+ + +     +
  +$selector +


+ +
+END + } + return; +} + +sub verify_and_change_timezone { + my $r = shift; + my $currtimezone = $env{'environment.timezone'}; + my $newtimezone; + if ($env{'form.settimezone'}) { + $newtimezone = $env{'form.timezone'}; + if (DateTime::TimeZone->is_valid_name($env{'form.timezone'})) { + $newtimezone = $env{'form.timezone'}; + } + } + my $message=''; + if ($newtimezone) { + if ($newtimezone eq $currtimezone) { + $message = &mt('Time Zone settings unchanged'); + } else { + &Apache::lonnet::put('environment',{'timezone' => $newtimezone}); + &Apache::lonnet::appenv({'environment.timezone' => $newtimezone}); + $message=&Apache::lonhtmlcommon::confirm_success( + &mt('Set [_1] to [_2]', + ''.&mt('Your Time Zone').'', + '"'.$newtimezone.'".')). + '
'; + } + } elsif ($currtimezone) { + &Apache::lonnet::del('environment',['timezone']); + &Apache::lonnet::delenv('environment.timezone'); + $message=&Apache::lonhtmlcommon::confirm_success(&mt('Time Zone now set by LON-CAPA')); + } else { + $message = &mt('Time Zone settings unchanged'); + } + $message=&Apache::loncommon::confirmwrapper($message); + &print_main_menu($r,$message); + return; +} + sub print_main_menu { my ($r, $message) = @_; # Determine current authentication method @@ -2193,6 +2311,9 @@ my %permissions; if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) { $permissions{'aboutme'} = 'F'; } +if (&Apache::lonnet::usertools_access($user,$domain,'timezone')) { + $permissions{'timezone'} = 'F'; +} my @menu= ({ categorytitle=>'Personal Data', items =>[ @@ -2235,6 +2356,14 @@ my @menu= icon => 'dismath.png', linktitle => 'Change how math is displayed.' }, + { + linktext => 'Time Zone', + url => '/adm/preferences?action=changetimezone', + permission => $permissions{'timezone'}, + #help => '', + icon => 'timezone.png', + linktitle => 'Set your time zone.', + } ] }, { categorytitle=>'Page Display Settings', @@ -2508,10 +2637,14 @@ sub handler { &print_main_menu($r); $ended = 1; } elsif ($env{'form.action'} eq 'changelockednames') { - &lockednameschanger($r); + $ended = &lockednameschanger($r); } elsif ($env{'form.action'} eq 'verify_and_change_lockednames') { &verify_and_change_lockednames($r); $ended = 1; + } elsif ($env{'form.action'} eq 'changetimezone') { + &timezonechanger($r); + } elsif ($env{'form.action'} eq 'verify_and_change_timezone') { + &verify_and_change_timezone($r); } # Properly end the HTML page of all preference pages