Diff for /loncom/interface/lonpreferences.pm between versions 1.196.4.28.2.1 and 1.196.4.29

version 1.196.4.28.2.1, 2022/09/19 19:49:26 version 1.196.4.29, 2024/07/04 23:13:07
Line 31 Line 31
 package Apache::lonpreferences;  package Apache::lonpreferences;
   
 use strict;  use strict;
   use LONCAPA;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::File;  use Apache::File;
 use Apache::loncommon();  use Apache::loncommon();
Line 39  use Apache::lonlocal; Line 40  use Apache::lonlocal;
 use Apache::lonnet;  use Apache::lonnet;
 use LONCAPA::lonauthcgi();  use LONCAPA::lonauthcgi();
 use LONCAPA();  use LONCAPA();
 use DateTime::TimeZone();  
   
 ################################################################  ################################################################
 #                       Handler subroutines                    #  #                       Handler subroutines                    #
Line 2183  sub verify_and_change_lockednames { Line 2183  sub verify_and_change_lockednames {
     &print_main_menu($r,$message);      &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";  
 <script type-"text/javascript">  
 // <![CDATA[  
 function toggleTZdisplay(form) {  
     var radioname = 'settimezone';  
     var divid = 'LC_timezone_selector';  
     var num = form.elements[radioname].length;  
     if (num) {  
         var setvis = '';  
         for (var i=0; i<num; i++) {  
             if (form.elements[radioname][i].checked) {  
                 if (form.elements[radioname][i].value == '1') {  
                     if (document.getElementById(divid)) {  
                         document.getElementById(divid).style.display = 'inline-block';  
                     }  
                     setvis = 1;  
                 }  
                 break;  
             }  
         }  
         if (!setvis) {  
             if (document.getElementById(divid)) {  
                 document.getElementById(divid).style.display = 'none';  
             }  
         }  
     }  
     return;  
 }  
 // ]]>  
 </script>  
 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");  
 <form name="prefs" action="/adm/preferences" method="post">  
 <input type="hidden" name="action" value="verify_and_change_timezone" />  
 <span class="LC_nobreak">  
 <label><input type="radio" name="settimezone" value="0"$checked{'lctz'}$onclick />  
 $lt{'lctz'}</label>&nbsp;&nbsp;&nbsp;&nbsp;  
 <label><input type="radio" name="settimezone" value="1"$checked{'owntz'}$onclick />  
 $lt{'owntz'}</label><div style="display:$tzsty" id="LC_timezone_selector">&nbsp;  
 $selector  
 </div></span><br /><br />  
 <input type="submit" value="$lt{'save'}" />  
 </form>  
 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]',  
                     '<i>'.&mt('Your Time Zone').'</i>',  
                     '<tt>"'.$newtimezone.'"</tt>.')).  
                '<br />';  
         }  
     } 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 {  sub print_main_menu {
     my ($r, $message) = @_;      my ($r, $message) = @_;
     # Determine current authentication method      # Determine current authentication method
Line 2311  my %permissions; Line 2197  my %permissions;
 if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {  if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
     $permissions{'aboutme'} = 'F';      $permissions{'aboutme'} = 'F';
 }  }
 if (&Apache::lonnet::usertools_access($user,$domain,'timezone')) {  
     $permissions{'timezone'} = 'F';  
 }  
 my @menu=  my @menu=
     ({ categorytitle=>'Personal Data',      ({ categorytitle=>'Personal Data',
  items =>[   items =>[
Line 2356  my @menu= Line 2239  my @menu=
  icon => 'dismath.png',   icon => 'dismath.png',
  linktitle => 'Change how math is displayed.'   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',      { categorytitle=>'Page Display Settings',
Line 2641  sub handler { Line 2516  sub handler {
     } elsif ($env{'form.action'} eq 'verify_and_change_lockednames') {      } elsif ($env{'form.action'} eq 'verify_and_change_lockednames') {
         &verify_and_change_lockednames($r);          &verify_and_change_lockednames($r);
         $ended = 1;          $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      # Properly end the HTML page of all preference pages

Removed from v.1.196.4.28.2.1  
changed lines
  Added in v.1.196.4.29


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>