[LON-CAPA-cvs] cvs: loncom /interface lonpreferences.pm
raeburn
raeburn@source.lon-capa.org
Fri, 12 Mar 2010 15:09:23 -0000
raeburn Fri Mar 12 15:09:23 2010 EDT
Modified files:
/loncom/interface lonpreferences.pm
Log:
- User preference to opt out of automaic name changes based on institutional data.
- Item only displayed in menu if:
(a) Autoupdate is set to run in user's domain.
(b) Autoupdate will update at least one of: first, middle and last name
based on user's institutional affiliations.
(c) Domain configured to allow opt out for user's current institutional
affiliation(s).
- New routines: &lockednameschanger(), &verify_and_change_lockednames,
&can_toggle_namelocking(), &updateable_userinfo()
Index: loncom/interface/lonpreferences.pm
diff -u loncom/interface/lonpreferences.pm:1.185 loncom/interface/lonpreferences.pm:1.186
--- loncom/interface/lonpreferences.pm:1.185 Wed Mar 10 21:25:50 2010
+++ loncom/interface/lonpreferences.pm Fri Mar 12 15:09:23 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.185 2010/03/10 21:25:50 droeschl Exp $
+# $Id: lonpreferences.pm,v 1.186 2010/03/12 15:09:23 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1842,6 +1842,93 @@
&print_main_menu($r,$message);
}
+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='';
+ if (&can_toggle_namelocking()) {
+ if ($userenv{'lockedname'}) {
+ $lockedname = ' checked="checked"';
+ }
+ my %updateable;
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
+ if (ref($domconfig{'autoupdate'}) eq 'HASH') {
+ if ($domconfig{'autoupdate'}{'run'}) {
+ my @inststatuses = split(':',$env{'environment.inststatus'});
+ unless (@inststatuses) {
+ @inststatuses = ('default');
+ }
+ %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
+ }
+ }
+ if (keys(%updateable)) {
+ my %longnames = &Apache::lonlocal::texthash (
+ firstname => 'First Name',
+ middlename => 'Middle Name',
+ lastname => 'Last Name',
+ );
+ my $text=&mt('By default, based on your institutional affiliation, your LON-CAPA account can be automatically updated nightly based on directory information from your institution.').'<br />'.&mt('The following may be updated, unless you disallow updates:').
+ '<ul>';
+ foreach my $item ('firstname','middlename','lastname') {
+ if ($updateable{$item}) {
+ $text .= '<li>'.$longnames{$item}.'</li>';
+ }
+ }
+ $text .= '</ul>';
+ my $locking=&mt('Disallow automatic updates to name information for your LON-CAPA account');
+ my $change=&mt('Save');
+ $r->print(<<ENDSCREEN);
+<form name="prefs" action="/adm/preferences" method="post">
+<input type="hidden" name="action" value="verify_and_change_lockednames" />
+$text<br />
+<label><input type="checkbox" value="1" name="lockednames"$lockedname />$locking</label><br />
+<input type="submit" value="$change" />
+</form>
+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);
+ }
+ } 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);
+ }
+}
+
+sub verify_and_change_lockednames {
+ my $r = shift;
+ my $message;
+ if (&can_toggle_namelocking()) {
+ my $newlockedname = $env{'form.lockednames'};
+ $newlockedname =~ s/\D//g;
+ my $currlockedname = $env{'environment.lockedname'};
+ if ($newlockedname ne $currlockedname) {
+ if ($newlockedname) {
+ if (&Apache::lonnet::put('environment',{lockedname => $newlockedname}) eq 'ok') {
+ &Apache::lonnet::appenv({'environment.lockedname' => $newlockedname});
+ }
+ } elsif (&Apache::lonnet::del('environment',['lockedname']) eq 'ok') {
+ &Apache::lonnet::delenv('environment.lockedname');
+ }
+ }
+ my $status='';
+ if ($newlockedname) {
+ $status=&mt('disallowed');
+ } else {
+ $status=&mt('allowed');
+ }
+ $message=&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]','<i>'.&mt('Automatic update of first, middle and last names if institutional directory information indicates changes').'</i>','<tt>'.$status.'</tt>'));
+ $message=&Apache::loncommon::confirmwrapper($message);
+ }
+ &print_main_menu($r,$message);
+}
+
sub print_main_menu {
my ($r, $message) = @_;
# Determine current authentication method
@@ -1960,6 +2047,18 @@
linktitle => 'Change your password.',
});
}
+
+ if (&can_toggle_namelocking()) {
+ push(@{ $menu[0]->{items} }, {
+ linktext => 'Automatic name changes',
+ url => '/adm/preferences?action=changelockednames',
+ permission => 'F',
+ #help => '',
+ icon => 'system-lock-screen.png',
+ linktitle => 'Allow/disallow propagation of name changes from institutional directory service',
+ });
+ }
+
my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
if (keys(%author_roles) > 0) {
push(@{ $menu[4]->{items} }, {
@@ -1994,7 +2093,7 @@
icon => 'blog.png',
linktitle => 'Toggle Debug Messages.',
});
- }
+ }
$r->print(&Apache::loncommon::start_page('My Space'));
$r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
@@ -2090,6 +2189,10 @@
&toggle_debug();
}
&print_main_menu($r);
+ } elsif ($env{'form.action'} eq 'changelockednames') {
+ &lockednameschanger($r);
+ } elsif ($env{'form.action'} eq 'verify_and_change_lockednames') {
+ &verify_and_change_lockednames($r);
}
# Properly end the HTML page of all preference pages
@@ -2122,5 +2225,52 @@
return $can_toggle;
}
+sub can_toggle_namelocking {
+ my $lockablenames;
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
+ if (ref($domconfig{'autoupdate'}) eq 'HASH') {
+ if ($domconfig{'autoupdate'}{'run'}) {
+ my @inststatuses = split(':',$env{'environment.inststatus'});
+ unless (@inststatuses) {
+ @inststatuses = ('default');
+ }
+ my %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
+ if ($updateable{'lastname'} || $updateable{'firstname'} ||
+ $updateable{'middlename'}) {
+ if (ref($domconfig{'autoupdate'}{'lockablenames'}) eq 'ARRAY') {
+ unless (@inststatuses) {
+ @inststatuses = ('default');
+ }
+ foreach my $status (@inststatuses) {
+ if (grep(/^\Q$status\E$/,@{$domconfig{'autoupdate'}{'lockablenames'}})) {
+ $lockablenames = 1;
+ last;
+ }
+ }
+ }
+ }
+ }
+ }
+ return $lockablenames;
+}
+
+sub updateable_userinfo {
+ my ($autoupdate,$inststatuses) = @_;
+ my %updateable;
+ return %updateable unless ((ref($autoupdate) eq 'HASH') &&
+ (ref($inststatuses) eq 'ARRAY'));
+ if (ref($autoupdate->{'fields'}) eq 'HASH') {
+ foreach my $status (@{$inststatuses}) {
+ if (ref($autoupdate->{'fields'}{$status}) eq 'ARRAY') {
+ foreach my $field (@{$autoupdate->{'fields'}{$status}}) {
+ $updateable{$field} = 1;
+ }
+ }
+ }
+ }
+ return %updateable;
+}
+
1;
__END__