--- loncom/interface/loncreateuser.pm 2007/12/12 23:59:41 1.207
+++ loncom/interface/loncreateuser.pm 2007/12/14 21:27:07 1.211
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.207 2007/12/12 23:59:41 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.211 2007/12/14 21:27:07 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -115,15 +115,6 @@ sub auth_abbrev {
return %abv_auth;
}
-# ==================================================== Figure out author access
-
-sub authorpriv {
- my ($auname,$audom)=@_;
- unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname))
- || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; }
- return 1;
-}
-
# ====================================================
sub portfolio_quota {
@@ -304,7 +295,7 @@ $userpicker
ENDBLOCK
- if ($cancreate) {
+ if ($cancreate && $env{'form.phase'} eq '') {
my $defdom=$env{'request.role.domain'};
my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
my $helpcrt=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
@@ -747,8 +738,8 @@ $loginscript
ENDTITLE
$r->print('
');
my $personal_table =
- &personal_data_display($ccuname,$ccdomain,$newuser,
- $context,%inst_results);
+ &personal_data_display($ccuname,$ccdomain,$newuser,$context,
+ $inst_results{$ccuname.':'.$ccdomain});
$r->print($personal_table);
my ($home_server_pick,$numlib) =
&Apache::loncommon::home_server_form_item($ccdomain,'hserver',
@@ -828,8 +819,8 @@ $forminfo
ENDCHANGEUSER
$r->print('
');
my ($personal_table,$showforceid) =
- &personal_data_display($ccuname,$ccdomain,$newuser,
- $context,%inst_results);
+ &personal_data_display($ccuname,$ccdomain,$newuser,$context,
+ $inst_results{$ccuname.':'.$ccdomain});
$r->print($personal_table);
if ($showforceid) {
$r->print(&Apache::lonuserutils::forceid_change($context));
@@ -970,7 +961,7 @@ ENDNOPORTPRIV
}
if (($role_code eq 'ca') || ($role_code eq 'aa')) {
$area=~m{/($match_domain)/($match_username)};
- if (&authorpriv($2,$1)) {
+ if (&Apache::lonuserutils::authorpriv($2,$1)) {
$allowed=1;
} else {
$allowed=0;
@@ -1063,7 +1054,8 @@ ENDNOPORTPRIV
#
# Co-Author
#
- if (&authorpriv($env{'user.name'},$env{'request.role.domain'}) &&
+ if (&Apache::lonuserutils::authorpriv($env{'user.name'},
+ $env{'request.role.domain'}) &&
($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
# No sense in assigning co-author role to yourself
$addrolesdisplay = 1;
@@ -1114,7 +1106,8 @@ ENDNOPORTPRIV
&Apache::loncommon::end_data_table_row()."\n".
&Apache::loncommon::end_data_table());
} elsif ($env{'request.role'} =~ /^au\./) {
- if (!(&authorpriv($env{'user.name'},$env{'request.role.domain'}))) {
+ if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
+ $env{'request.role.domain'}))) {
$r->print(''.
&mt('You do not have privileges to assign co-author roles.').
'');
@@ -1360,7 +1353,7 @@ sub modify_login_block {
}
sub personal_data_display {
- my ($ccuname,$ccdomain,$newuser,$context,%inst_results) = @_;
+ my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
my ($output,$showforceid,%userenv,%domconfig);
if (!$newuser) {
# Get the users information
@@ -1401,8 +1394,12 @@ sub personal_data_display {
}
$output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
if ($newuser) {
- if ($inst_results{$item} ne '') {
- $output .= ''.$inst_results{$item};
+ if (ref($inst_results) eq 'HASH') {
+ if ($inst_results->{$item} ne '') {
+ $output .= ''.$inst_results->{$item};
+ } else {
+ $output .= '';
+ }
} else {
$output .= '';
}
@@ -2618,7 +2615,8 @@ sub handler {
({href=>"/adm/createuser",
text=>"User Management"});
}
- my ($permission,$allowed) = &get_permission($context);
+ my ($permission,$allowed) =
+ &Apache::lonuserutils::get_permission($context);
if (!$allowed) {
$env{'user.error.msg'}=
"/adm/createuser:cst:0:0:Cannot create/modify user data ".
@@ -2633,7 +2631,7 @@ sub handler {
if (! exists($env{'form.action'})) {
$r->print(&header());
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
- $r->print(&print_main_menu($permission));
+ $r->print(&print_main_menu($permission,$context));
$r->print(&Apache::loncommon::end_page());
} elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
$r->print(&header());
@@ -2853,35 +2851,68 @@ END
###############################################################
# Menu Phase One
sub print_main_menu {
- my ($permission) = @_;
+ my ($permission,$context) = @_;
+ my %links = (
+ domain => {
+ upload => 'Upload a File of Users',
+ singleuser => 'Add/Manage a Single User',
+ listusers => 'Manage Multiple Users',
+ },
+ author => {
+ upload => 'Upload a File of Co-authors',
+ singleuser => 'Add/Manage a Single Co-author',
+ listusers => 'Display Co-authors and Manage Multiple Users',
+ },
+ course => {
+ upload => 'Upload a File of Course Users',
+ singleuser => 'Add/Manage a Single Course User',
+ listusers => 'Display Class Lists and Manage Multiple Users',
+ },
+ );
my @menu =
(
- { text => 'Upload a File of Users to Modify/Create Users and/or Add roles',
+ { text => $links{$context}{'upload'},
help => 'User_Management_Upload',
action => 'upload',
permission => $permission->{'cusr'},
},
- { text => 'Create User/Set User Roles for a single user',
+ { text => $links{$context}{'singleuser'},
help => 'User_Management_Single_User',
action => 'singleuser',
permission => $permission->{'cusr'},
},
- { text => 'Display Lists of Users',
+ { text => $links{$context}{'listusers'},
help => 'User_Management_List',
action => 'listusers',
- permission => $permission->{'view'},
- },
-# { text => 'Expire User Roles',
-# help => 'User_Management_Drops',
-# action => 'expire',
-# permission => $permission->{'cusr'},
-# },
- { text => 'Edit Custom Roles',
- help => 'Custom_Role_Edit',
- action => 'custom',
- permission => $permission->{'custom'},
+ permission => ($permission->{'view'} || $permission->{'cusr'}),
},
);
+ if ($context eq 'domain' || $context eq 'course') {
+ my $customlink = { text => 'Edit Custom Roles',
+ help => 'Custom_Role_Edit',
+ action => 'custom',
+ permission => $permission->{'custom'},
+ };
+ push(@menu,$customlink);
+ }
+ if ($context eq 'course') {
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my @courselinks =
+ (
+ { text => 'Automated Enrollment Manager',
+ permission => (&Apache::lonnet::auto_run($cnum,$cdom)
+ && $permission->{'cusr'}),
+ url => '/adm/populate',
+ },
+ { text => 'Manage Course Groups',
+ help => 'Course_Manage_Group',
+ permission => $permission->{'grp_manage'},
+ url => '/adm/coursegroups?refpage=cusr',
+ },
+ );
+ push(@menu,@courselinks);
+ }
my $menu_html = '';
foreach my $menu_item (@menu) {
next if (! $menu_item->{'permission'});
@@ -2903,60 +2934,6 @@ sub print_main_menu {
return $menu_html;
}
-sub get_permission {
- my ($context) = @_;
- my %permission;
- if ($context eq 'course') {
- if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) ||
- (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) ||
- (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) ||
- (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) ||
- (&Apache::lonnet::allowed('cst',$env{'request.course.id'}))) {
- $permission{'cusr'} = 1;
- $permission{'view'} =
- &Apache::lonnet::allowed('vcl',$env{'request.course.id'});
-
- }
- if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) {
- $permission{'custom'} = 1;
- }
- if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) {
- $permission{'view'} = 1;
- }
- if (!$permission{'view'}) {
- my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'};
- $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope);
- if ($permission{'view'}) {
- $permission{'view_section'} = $env{'request.course.sec'};
- }
- }
- if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
- $permission{'grp_manage'} = 1;
- }
- } elsif ($context eq 'author') {
- $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
- $permission{'view'} = $permission{'cusr'};
- } else {
- if ((&Apache::lonnet::allowed('cad',$env{'request.role.domain'})) ||
- (&Apache::lonnet::allowed('cli',$env{'request.role.domain'})) ||
- (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
- (&Apache::lonnet::allowed('csc',$env{'request.role.domain'})) ||
- (&Apache::lonnet::allowed('cdg',$env{'request.role.domain'})) ||
- (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) {
- $permission{'cusr'} = 1;
- }
- if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
- $permission{'custom'} = 1;
- }
- $permission{'view'} = $permission{'cusr'};
- }
- my $allowed = 0;
- foreach my $perm (values(%permission)) {
- if ($perm) { $allowed=1; last; }
- }
- return (\%permission,$allowed);
-}
-
sub restore_prev_selections {
my %saveable_parameters = ('srchby' => 'scalar',
'srchin' => 'scalar',
@@ -3378,8 +3355,18 @@ sub crumb_utilities {
my $jsback .= qq|
function backPage(formname,prevphase,prevstate) {
- formname.phase.value = prevphase;
- formname.currstate.value = prevstate;
+ if (typeof prevphase == 'undefined') {
+ formname.phase.value = '';
+ }
+ else {
+ formname.phase.value = prevphase;
+ }
+ if (typeof prevstate == 'undefined') {
+ formname.currstate.value = '';
+ }
+ else {
+ formname.currstate.value = prevstate;
+ }
formname.submit();
}
|;