--- loncom/interface/loncreateuser.pm 2006/11/21 21:38:44 1.134
+++ loncom/interface/loncreateuser.pm 2007/07/20 23:57:06 1.159
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.134 2006/11/21 21:38:44 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.159 2007/07/20 23:57:06 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -65,8 +65,7 @@ use Apache::lonnet;
use Apache::loncommon;
use Apache::lonlocal;
use Apache::longroup;
-use lib '/home/httpd/lib/perl/';
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
my $loginscript; # piece of javascript used in two separate instances
my $generalrule;
@@ -99,8 +98,8 @@ sub initialize_authen_forms {
sub my_custom_roles {
my %returnhash=();
my %rolehash=&Apache::lonnet::dump('roles');
- foreach (keys %rolehash) {
- if ($_=~/^rolesdef\_(\w+)$/) {
+ foreach my $key (keys %rolehash) {
+ if ($key=~/^rolesdef\_(\w+)$/) {
$returnhash{$1}=$1;
}
}
@@ -122,11 +121,72 @@ sub portfolio_quota {
my ($ccuname,$ccdomain) = @_;
my %lt = &Apache::lonlocal::texthash(
'disk' => "Disk space allocated to user's portfolio files",
+ 'cuqu' => "Current quota",
+ 'cust' => "Custom quota",
+ 'defa' => "Default",
+ 'chqu' => "Change quota",
);
- my $output = '
'.$lt{'disk'}.' '.
+ my ($currquota,$quotatype,$inststatus,$defquota) =
+ &Apache::loncommon::get_user_quota($ccuname,$ccdomain);
+ my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($ccdomain);
+ my ($longinsttype,$showquota,$custom_on,$custom_off,$defaultinfo);
+ if ($inststatus ne '') {
+ if ($usertypes->{$inststatus} ne '') {
+ $longinsttype = $usertypes->{$inststatus};
+ }
+ }
+ $custom_on = ' ';
+ $custom_off = ' checked="checked" ';
+ my $quota_javascript = <<"END_SCRIPT";
+
+END_SCRIPT
+ if ($quotatype eq 'custom') {
+ $custom_on = $custom_off;
+ $custom_off = ' ';
+ $showquota = $currquota;
+ if ($longinsttype eq '') {
+ $defaultinfo = &mt('For this user, the default quota would be [_1]
+ Mb.',$defquota);
+ } else {
+ $defaultinfo = &mt("For this user, the default quota would be [_1]
+ Mb, as determined by the user's institutional
+ affiliation ([_2]).",$defquota,$longinsttype);
+ }
+ } else {
+ if ($longinsttype eq '') {
+ $defaultinfo = &mt('For this user, the default quota is [_1]
+ Mb.',$defquota);
+ } else {
+ $defaultinfo = &mt("For this user, the default quota of [_1]
+ Mb, is determined by the user's institutional
+ affiliation ([_2]).",$defquota,$longinsttype);
+ }
+ }
+ my $output = $quota_javascript.
+ ''.$lt{'disk'}.' '.
+ $lt{'cuqu'}.': '.$currquota.' Mb. '.
+ $defaultinfo.''.$lt{'chqu'}.
+ ': '.
+ ' '.$lt{'defa'}.' ('.$defquota.' Mb). '.
+ ' '.
+ $lt{'cust'}.': '.
' Mb';
+ $showquota.'" onfocus="javascript:quota_changes('."'quota'".')" '.
+ '/> Mb';
return $output;
}
@@ -135,7 +195,6 @@ sub portfolio_quota {
sub print_username_entry_form {
my ($r) = @_;
my $defdom=$env{'request.role.domain'};
- my @domains = &Apache::loncommon::get_domains();
my $domform = &Apache::loncommon::select_dom_form($defdom,'ccdomain');
my $selscript=&Apache::loncommon::studentbrowser_javascript();
my $start_page =
@@ -162,10 +221,10 @@ sub print_username_entry_form {
$r->print(<<"ENDDOCUMENT");
$start_page
".&Apache::loncommon::end_page());
}
@@ -1026,7 +1050,8 @@ sub update_user_data {
$r->print($error.&mt('No login name specified').'.'.$end);
return;
}
- if ( $env{'form.ccuname'} =~/\W/) {
+ if ( $env{'form.ccuname'} ne
+ &LONCAPA::clean_username($env{'form.ccuname'}) ) {
$r->print($error.&mt('Invalid login name').'. '.
&mt('Only letters, numbers, and underscores are valid').'.'.
$end);
@@ -1036,9 +1061,10 @@ sub update_user_data {
$r->print($error.&mt('No domain specified').'.'.$end);
return;
}
- if ( $env{'form.ccdomain'} =~/\W/) {
+ if ( $env{'form.ccdomain'} ne
+ &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
$r->print($error.&mt ('Invalid domain name').'. '.
- &mt('Only letters, numbers, and underscores are valid').'.'.
+ &mt('Only letters, numbers, periods, dashes, and underscores are valid').'.'.
$end);
return;
}
@@ -1097,8 +1123,8 @@ ENDNEWUSERHEAD
if (lc($desiredhost) eq 'default') {
$desiredhost = undef;
} else {
- my %home_servers = &Apache::loncommon::get_library_servers
- ($env{'form.ccdomain'});
+ my %home_servers =
+ &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
if (! exists($home_servers{$desiredhost})) {
$r->print($error.&mt('Invalid home server specified'));
return;
@@ -1115,7 +1141,7 @@ ENDNEWUSERHEAD
my $home = &Apache::lonnet::homeserver($env{'form.ccuname'},
$env{'form.ccdomain'});
$r->print(' '.&mt('Home server').': '.$home.' '.
- $Apache::lonnet::libserv{$home});
+ &Apache::lonnet::hostname($home));
} elsif (($env{'form.login'} ne 'nochange') &&
($env{'form.login'} ne '' )) {
# Modify user privileges
@@ -1148,31 +1174,66 @@ ENDMODIFYUSERHEAD
# Check for need to change
my %userenv = &Apache::lonnet::get
('environment',['firstname','middlename','lastname','generation',
- 'portfolioquota'],$env{'form.ccdomain'},$env{'form.ccuname'});
+ 'portfolioquota','inststatus'],$env{'form.ccdomain'},
+ $env{'form.ccuname'});
my ($tmp) = keys(%userenv);
if ($tmp =~ /^(con_lost|error)/i) {
%userenv = ();
}
# Check to see if we need to change user information
- foreach ('firstname','middlename','lastname','generation') {
+ foreach my $item ('firstname','middlename','lastname','generation') {
# Strip leading and trailing whitespace
- $env{'form.c'.$_} =~ s/(\s+$|^\s+)//g;
+ $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
}
- my ($quotachanged,$namechanged,$oldportfolioquota);
+ my ($quotachanged,$namechanged,$oldportfolioquota,$newportfolioquota,
+ $inststatus,$isdefault,$defquotatext);
+ my ($defquota,$settingstatus) =
+ &Apache::loncommon::default_quota($env{'form.ccdomain'},$inststatus);
my %changeHash;
- if (exists($userenv{'portfolioquota'})) {
+ if ($userenv{'portfolioquota'} ne '') {
$oldportfolioquota = $userenv{'portfolioquota'};
- if (exists($env{'form.portfolioquota'})) {
- if ($env{'form.portfolioquota'} ne $userenv{'portfolioquota'}) {
- if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
- # Current user has quota modification privileges
- $quotachanged = 1;
- $changeHash{'portfolioquota'} = $env{'form.portfolioquota'};
- }
+ if ($env{'form.customquota'} == 1) {
+ if ($env{'form.portfolioquota'} eq '') {
+ $newportfolioquota = 0;
+ } else {
+ $newportfolioquota = $env{'form.portfolioquota'};
+ $newportfolioquota =~ s/[^\d\.]//g;
}
+ if ($newportfolioquota != $userenv{'portfolioquota'}) {
+ $quotachanged = "a_admin($newportfolioquota,\%changeHash);
+ }
+ } else {
+ $quotachanged = "a_admin('',\%changeHash);
+ $newportfolioquota = $defquota;
+ $isdefault = 1;
}
} else {
- $oldportfolioquota = &default_quota($env{'form.ccdomain'});
+ $oldportfolioquota = $defquota;
+ if ($env{'form.customquota'} == 1) {
+ if ($env{'form.portfolioquota'} eq '') {
+ $newportfolioquota = 0;
+ } else {
+ $newportfolioquota = $env{'form.portfolioquota'};
+ $newportfolioquota =~ s/[^\d\.]//g;
+ }
+ $quotachanged = "a_admin($newportfolioquota,\%changeHash);
+ } else {
+ $newportfolioquota = $defquota;
+ $isdefault = 1;
+ }
+ }
+ if ($isdefault) {
+ if ($settingstatus eq '') {
+ $defquotatext = &mt('(default)');
+ } else {
+ my ($usertypes,$order) =
+ &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
+ if ($usertypes->{$settingstatus} eq '') {
+ $defquotatext = &mt('(default)');
+ } else {
+ $defquotatext = &mt('(default for [_1])',$usertypes->{$settingstatus});
+ }
+ }
}
if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) &&
($env{'form.cfirstname'} ne $userenv{'firstname'} ||
@@ -1216,16 +1277,24 @@ ENDMODIFYUSERHEAD
$userenv{'middlename'}
$userenv{'lastname'}
$userenv{'generation'}
- $oldportfolioquota
+ $oldportfolioquota Mb
$lt{'chto'}
$env{'form.cfirstname'}
$env{'form.cmiddlename'}
$env{'form.clastname'}
$env{'form.cgeneration'}
- $env{'form.portfolioquota'} Mb
+ $newportfolioquota Mb $defquotatext
END
+ if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
+ ($env{'form.ccuname'} eq $env{'user.name'})) {
+ my %newenvhash;
+ foreach my $key (keys(%changeHash)) {
+ $newenvhash{'environment.'.$key} = $changeHash{$key};
+ }
+ &Apache::lonnet::appenv(%newenvhash);
+ }
} else { # error occurred
$r->print("".&mt('Unable to successfully change environment for')." ".
$env{'form.ccuname'}." ".&mt('in domain')." ".
@@ -1252,8 +1321,10 @@ END
$lt{'gen'}: $userenv{'generation'}
END
if ($putresult eq 'ok') {
- if ($oldportfolioquota ne $env{'form.portfolioquota'}) {
- $r->print(''.$lt{'disk'}.': '.$env{'form.portfolioquota'}.' Mb ');
+ if ($oldportfolioquota != $newportfolioquota) {
+ $r->print(''.$lt{'disk'}.': '.$newportfolioquota.' Mb '.
+ $defquotatext.' ');
+ &Apache::lonnet::appenv('environment.portfolioquota' => $changeHash{'portfolioquota'});
}
}
}
@@ -1261,56 +1332,56 @@ END
##
my $now=time;
$r->print(''.&mt('Modifying Roles').' ');
- foreach (keys (%env)) {
- next if (! $env{$_});
+ foreach my $key (keys (%env)) {
+ next if (! $env{$key});
# Revoke roles
- if ($_=~/^form\.rev/) {
- if ($_=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
+ if ($key=~/^form\.rev/) {
+ if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
# Revoke standard role
$r->print(&mt('Revoking').' '.$2.' in '.$1.': '.
&Apache::lonnet::revokerole($env{'form.ccdomain'},
$env{'form.ccuname'},$1,$2).' ');
if ($2 eq 'st') {
- $1=~/^\/(\w+)\/(\w+)/;
+ $1=~m{^/($match_domain)/($match_courseid)};
my $cid=$1.'_'.$2;
- $r->print(&mt('Drop from classlist').': '.
- &Apache::lonnet::critical('put:'.
- $env{'course.'.$cid.'.domain'}.':'.
- $env{'course.'.$cid.'.num'}.':classlist:'.
- &escape($env{'form.ccuname'}.':'.
- $env{'form.ccdomain'}).'='.
- &escape($now.':'),
- $env{'course.'.$cid.'.home'}).' ');
+ my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
+ my $result =
+ &Apache::lonnet::cput('classlist',
+ { $user => $now },
+ $env{'course.'.$cid.'.domain'},
+ $env{'course.'.$cid.'.num'});
+ $r->print(&mt('Drop from classlist: [_1]',
+ ''.$result.' ').' ');
}
}
- if ($_=~/^form\.rev\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
+ if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
# Revoke custom role
$r->print(&mt('Revoking custom role:').
- ' '.$4.' by '.$3.'@'.$2.' in '.$1.': '.
+ ' '.$4.' by '.$3.':'.$2.' in '.$1.': '.
&Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
$env{'form.ccuname'},$1,$2,$3,$4).
' ');
}
- } elsif ($_=~/^form\.del/) {
- if ($_=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
+ } elsif ($key=~/^form\.del/) {
+ if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
# Delete standard role
$r->print(&mt('Deleting').' '.$2.' in '.$1.': '.
&Apache::lonnet::assignrole($env{'form.ccdomain'},
$env{'form.ccuname'},$1,$2,$now,0,1).' ');
if ($2 eq 'st') {
- $1=~/^\/(\w+)\/(\w+)/;
+ $1=~m{^/($match_domain)/($match_courseid)};
my $cid=$1.'_'.$2;
- $r->print(&mt('Drop from classlist').': '.
- &Apache::lonnet::critical('put:'.
- $env{'course.'.$cid.'.domain'}.':'.
- $env{'course.'.$cid.'.num'}.':classlist:'.
- &escape($env{'form.ccuname'}.':'.
- $env{'form.ccdomain'}).'='.
- &escape($now.':'),
- $env{'course.'.$cid.'.home'}).' ');
+ my $user = $env{'form.ccuname'}.':'.$env{'form.ccdomain'};
+ my $result =
+ &Apache::lonnet::cput('classlist',
+ { $user => $now },
+ $env{'course.'.$cid.'.domain'},
+ $env{'course.'.$cid.'.num'});
+ $r->print(&mt('Drop from classlist: [_1]',
+ ''.$result.' ').' ');
}
}
- if ($_=~/^form\.del\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
+ if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
# Delete custom role
$r->print(&mt('Deleting custom role [_1] by [_2]@[_3] in [_4]',
@@ -1319,17 +1390,17 @@ END
$env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
0,1).' ');
}
- } elsif ($_=~/^form\.ren/) {
+ } elsif ($key=~/^form\.ren/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
# Re-enable standard role
- if ($_=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
+ if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
my $url = $1;
my $role = $2;
my $logmsg;
my $output;
if ($role eq 'st') {
- if ($url =~ m-^/(\w+)/(\w+)/?(\w*)$-) {
+ if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$1,$2,$3);
if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course')) {
$output = "Error: $result\n";
@@ -1349,7 +1420,7 @@ END
$r->print($output);
}
# Re-enable custom role
- if ($_=~/^form\.ren\:([^\_]+)\_cr\.cr\/(\w+)\/(\w+)\/(\w+)$/) {
+ if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
my $result = &Apache::lonnet::assigncustomrole(
$env{'form.ccdomain'}, $env{'form.ccuname'},
@@ -1357,10 +1428,10 @@ END
$r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : [_5] ',
$rolename,$rnam,$rdom,$url,$result).' ');
}
- } elsif ($_=~/^form\.act/) {
+ } elsif ($key=~/^form\.act/) {
my $udom = $env{'form.ccdomain'};
my $uname = $env{'form.ccuname'};
- if ($_=~/^form\.act\_([^\_]+)\_([^\_]+)\_cr_cr_([^\_]+)_(\w+)_([^\_]+)$/) {
+ if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
# Activate a custom role
my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
my $url='/'.$one.'/'.$two;
@@ -1391,7 +1462,7 @@ END
$r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
}
}
- } elsif ($_=~/^form\.act\_([^\_]+)\_(\w+)\_([^\_]+)$/) {
+ } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
# Activate roles for sections with 3 id numbers
# set start, end times, and the url for the class
my ($one,$two,$three)=($1,$2,$3);
@@ -1430,7 +1501,7 @@ END
$r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
}
}
- } elsif ($_=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
+ } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
# Activate roles for sections with two id numbers
# set start, end times, and the url for the class
my $start = ( $env{'form.start_'.$1.'_'.$2} ?
@@ -1460,7 +1531,7 @@ END
}
}
} else {
- $r->print(' '.&mt('ERROR').': '.&mt('Unknown command').' '.$_.'
');
+ $r->print(''.&mt('ERROR').': '.&mt('Unknown command').' '.$key.'
');
}
foreach my $key (sort(keys(%disallowed))) {
if (($key eq 'none') || ($key eq 'all')) {
@@ -1478,6 +1549,17 @@ END
$r->print(&Apache::loncommon::end_page());
}
+sub quota_admin {
+ my ($setquota,$changeHash) = @_;
+ my $quotachanged;
+ if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
+ # Current user has quota modification privileges
+ $quotachanged = 1;
+ $changeHash->{'portfolioquota'} = $setquota;
+ }
+ return $quotachanged;
+}
+
sub build_roles {
my ($sectionstr,$sections,$role) = @_;
my $num_sections = 0;
@@ -1490,7 +1572,7 @@ sub build_roles {
} else {
foreach my $sec (@secnums) {
$sec =~ ~s/\W//g;
- unless ($sec eq "") {
+ if (!($sec eq "")) {
if (exists($$sections{$sec})) {
$$sections{$sec} ++;
} else {
@@ -1523,35 +1605,35 @@ sub custom_role_editor {
$rolename=~s/[^A-Za-z0-9]//gs;
- unless ($rolename) {
+ if (!$rolename) {
&print_username_entry_form($r);
return;
}
-
- $r->print(&Apache::loncommon::start_page('Custom Role Editor'));
+# ------------------------------------------------------- What can be assigned?
+ my %full=();
+ my %courselevel=();
+ my %courselevelcurrent=();
my $syspriv='';
my $dompriv='';
my $coursepriv='';
+ my $body_top;
+ my ($disp_dummy,$disp_roles) = &Apache::lonnet::get('roles',["st"]);
my ($rdummy,$roledef)=
&Apache::lonnet::get('roles',["rolesdef_$rolename"]);
# ------------------------------------------------------- Does this role exist?
- $r->print('');
+ $body_top .= '';
if (($rdummy ne 'con_lost') && ($roledef ne '')) {
- $r->print(&mt('Existing Role').' "');
+ $body_top .= &mt('Existing Role').' "';
# ------------------------------------------------- Get current role privileges
($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
} else {
- $r->print(&mt('New Role').' "');
+ $body_top .= &mt('New Role').' "';
$roledef='';
}
- $r->print($rolename.'" ');
-# ------------------------------------------------------- What can be assigned?
- my %full=();
- my %courselevel=();
- my %courselevelcurrent=();
- foreach (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
- my ($priv,$restrict)=split(/\&/,$_);
- unless ($restrict) { $restrict='F'; }
+ $body_top .= $rolename.'" ';
+ foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) {
+ my ($priv,$restrict)=split(/\&/,$item);
+ if (!$restrict) { $restrict='F'; }
$courselevel{$priv}=$restrict;
if ($coursepriv=~/\:$priv/) {
$courselevelcurrent{$priv}=1;
@@ -1560,9 +1642,9 @@ sub custom_role_editor {
}
my %domainlevel=();
my %domainlevelcurrent=();
- foreach (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
- my ($priv,$restrict)=split(/\&/,$_);
- unless ($restrict) { $restrict='F'; }
+ foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:d'})) {
+ my ($priv,$restrict)=split(/\&/,$item);
+ if (!$restrict) { $restrict='F'; }
$domainlevel{$priv}=$restrict;
if ($dompriv=~/\:$priv/) {
$domainlevelcurrent{$priv}=1;
@@ -1571,47 +1653,136 @@ sub custom_role_editor {
}
my %systemlevel=();
my %systemlevelcurrent=();
- foreach (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
- my ($priv,$restrict)=split(/\&/,$_);
- unless ($restrict) { $restrict='F'; }
+ foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:s'})) {
+ my ($priv,$restrict)=split(/\&/,$item);
+ if (!$restrict) { $restrict='F'; }
$systemlevel{$priv}=$restrict;
if ($syspriv=~/\:$priv/) {
$systemlevelcurrent{$priv}=1;
}
$full{$priv}=1;
}
+ my $button_code = "\n";
+ my $head_script = "\n";
+ $head_script .= ''."\n";
+ $r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
+ $r->print($body_top);
my %lt=&Apache::lonlocal::texthash(
'prv' => "Privilege",
'crl' => "Course Level",
'dml' => "Domain Level",
- 'ssl' => "System Level"
- );
+ 'ssl' => "System Level");
+ $r->print('Select a Template ');
+ $r->print('');
$r->print(<
+