--- loncom/interface/loncreateuser.pm 2007/12/21 16:23:54 1.218
+++ loncom/interface/loncreateuser.pm 2007/12/21 20:34:26 1.221
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.218 2007/12/21 16:23:54 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.221 2007/12/21 20:34:26 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1397,15 +1397,17 @@ sub modify_login_block {
sub personal_data_display {
my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
- my ($output,$showforceid,%userenv,%domconfig);
+ my ($output,$showforceid,%userenv,%canmodify);
+ my @userinfo = ('firstname','middlename','lastname','generation',
+ 'permanentemail','id');
if (!$newuser) {
# Get the users information
%userenv = &Apache::lonnet::get('environment',
['firstname','middlename','lastname','generation',
'permanentemail','id'],$ccdomain,$ccuname);
- %domconfig =
- &Apache::lonnet::get_dom('configuration',['usermodification'],
- $ccdomain);
+ %canmodify =
+ &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
+ \@userinfo);
}
my %lt=&Apache::lonlocal::texthash(
'pd' => "Personal Data",
@@ -1417,8 +1419,6 @@ sub personal_data_display {
'id' => "ID/Student Number",
'lg' => "Login Data"
);
- my @userinfo = ('firstname','middlename','lastname','generation',
- 'permanentemail','id');
my %textboxsize = (
firstname => '15',
middlename => '15',
@@ -1447,33 +1447,14 @@ sub personal_data_display {
$output .= '';
}
} else {
- my $canmodify = 0;
- if (&Apache::lonnet::allowed('mau',$ccdomain)) {
- $canmodify = 1;
- } else {
- if (ref($domconfig{'usermodification'}) eq 'HASH') {
- if (ref($domconfig{'usermodification'}{$context}) eq 'HASH') {
- foreach my $key (keys(%{$domconfig{'usermodification'}{$context}})) {
- if (ref($domconfig{'usermodification'}{$context}{$key}) eq 'HASH') {
- if ($domconfig{'usermodification'}{$context}{$key}{$item}) {
- $canmodify = 1;
- last;
- }
- }
- }
- }
- } elsif ($context eq 'course') {
- $canmodify = 1;
- }
- }
- if ($canmodify) {
+ if ($canmodify{$item}) {
$output .= '';
} else {
$output .= $userenv{$item};
}
if ($item eq 'id') {
- $showforceid = $canmodify;
- }
+ $showforceid = $canmodify{$item};
+ }
}
$output .= &Apache::lonhtmlcommon::row_closure(1);
}
@@ -1495,7 +1476,9 @@ sub update_user_data {
my $end = '
';
my $rtnlink = ''.
- &mt('Return to previous page').''.&Apache::loncommon::end_page();
+ &mt('Return to previous page').''.
+ &Apache::loncommon::end_page();
+ my $now = time;
my $title;
if (exists($env{'form.makeuser'})) {
$title='Set Privileges for New User';
@@ -1520,14 +1503,12 @@ sub update_user_data {
}
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
- text=>"Set user role",
+ text=>$breadcrumb_text{'modify'},
faq=>282,bug=>'Instructor Interface',},
{href=>"/adm/createuser",
text=>"Result",
faq=>282,bug=>'Instructor Interface',});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
-
- my %disallowed;
$r->print(&update_result_form($uhome));
# Check Inputs
if (! $env{'form.ccuname'} ) {
@@ -1552,6 +1533,9 @@ sub update_user_data {
$end.$rtnlink);
return;
}
+ if ($uhome eq 'no_host') {
+ $newuser = 1;
+ }
if (! exists($env{'form.makeuser'})) {
# Modifying an existing user, so check the validity of the name
if ($uhome eq 'no_host') {
@@ -1589,7 +1573,6 @@ sub update_user_data {
return;
}
-
$r->print('
".&mt('If the student is currently logged-in to LON-CAPA, the new role will be available when the student next logs in.')."
"); + } + } else { + $r->print(&mt('unable to enroll').": ".$enroll_result); + } + return; } sub get_defaultquota_text { @@ -2301,7 +2339,7 @@ sub update_result_form { } $outcome .= ''."\n". ''."\n". - ''."\n". + ''."\n". ''; return $outcome; } @@ -2692,10 +2730,11 @@ sub handler { if (! exists($env{'form.state'})) { &Apache::lonuserutils::print_first_users_upload_form($r,$context); } elsif ($env{'form.state'} eq 'got_file') { - &Apache::lonuserutils::print_upload_manager_form($r,$context); + &Apache::lonuserutils::print_upload_manager_form($r,$context, + $permission); } elsif ($env{'form.state'} eq 'enrolling') { if ($env{'form.datatoken'}) { - &Apache::lonuserutils::upfile_drop_add($r,$context); + &Apache::lonuserutils::upfile_drop_add($r,$context,$permission); } } else { &Apache::lonuserutils::print_first_users_upload_form($r,$context); @@ -2717,16 +2756,18 @@ sub handler { my $response; if ($env{'form.srchterm'} !~ /^$match_username$/) { my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @'); + $env{'form.phase'} = ''; &print_username_entry_form($r,$context,$response,$srch); } else { my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'}); my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'}); &print_user_modification_page($r,$ccuname,$ccdomain, - $srch,$response,$context); + $srch,$response,$context, + $permission); } } elsif ($env{'form.phase'} eq 'get_user_info') { my ($currstate,$response,$forcenewuser,$results) = - &user_search_result($srch); + &user_search_result($context,$srch); if ($env{'form.currstate'} eq 'modify') { $currstate = $env{'form.currstate'}; } @@ -2755,7 +2796,8 @@ sub handler { $response = ''; } &print_user_modification_page($r,$ccuname,$ccdomain, - $srch,$response,$context); + $srch,$response,$context, + $permission); } elsif ($currstate eq 'query') { &print_user_query_page($r,'createuser'); } else { @@ -2766,7 +2808,7 @@ sub handler { my $ccuname = &LONCAPA::clean_username($env{'form.seluname'}); my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'}); &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'', - $context); + $context,$permission); } } elsif ($env{'form.phase'} eq 'update_user_data') { &update_user_data($r,$context); @@ -2783,15 +2825,22 @@ sub handler { ($permission->{'view'} || $permission->{'cusr'})) { if ($env{'form.phase'} eq 'bulkchange') { &Apache::lonhtmlcommon::add_breadcrumb - ({href=>'backPage(document.studentform)', - text=>"List Users"}); + ({href=>'/adm/createuser?action=listusers', + text=>"List Users"}, + {href=>"/adm/createuser", + text=>"Result"}); my $setting = $env{'form.roletype'}; my $choice = $env{'form.bulkaction'}; $r->print(&header()); - $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users", + $r->print(&Apache::lonhtmlcommon::breadcrumbs("Update Users", 'User_Management_List')); if ($permission->{'cusr'}) { &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice); + $r->print(''.&mt('Display User Lists').'');
+ $r->print(&Apache::loncommon::end_page());
+ } else {
+ $r->print(&mt('You are not authorized to make bulk changes to user roles'));
+ $r->print(&Apache::loncommon::end_page());
}
} else {
&Apache::lonhtmlcommon::add_breadcrumb
@@ -2844,7 +2893,8 @@ sub handler {
} elsif ($env{'form.action'} eq 'dateselect') {
if ($permission->{'cusr'}) {
$r->print(&header(undef,undef,{'no_nav_bar' => 1}).
- &Apache::lonuserutils::date_section_selector($context).
+ &Apache::lonuserutils::date_section_selector($context,
+ $permission).
&Apache::loncommon::end_page());
} else {
$r->print(&header().
@@ -2898,17 +2948,17 @@ sub print_main_menu {
my %links = (
domain => {
upload => 'Upload a File of Users',
- singleuser => 'Add/Manage a Single User',
+ singleuser => 'Add/Modify a Single User',
listusers => 'Manage Multiple Users',
},
author => {
upload => 'Upload a File of Co-authors',
- singleuser => 'Add/Manage a Single Co-author',
+ singleuser => 'Add/Modify 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',
+ singleuser => 'Add/Modify a Single Course User',
listusers => 'Display Class Lists and Manage Multiple Users',
},
);
@@ -3002,7 +3052,7 @@ sub restore_prev_selections {
#-------------------------------------------------- functions for &phase_two
sub user_search_result {
- my ($srch) = @_;
+ my ($context,$srch) = @_;
my %allhomes;
my %inst_matches;
my %srch_results;
@@ -3071,14 +3121,14 @@ sub user_search_result {
my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
if ($uhome eq 'no_host') {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} else {
$currstate = 'modify';
}
} else {
%srch_results = &Apache::lonnet::usersearch($srch);
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
} else {
my $courseusers = &get_courseusers();
@@ -3087,7 +3137,7 @@ sub user_search_result {
$currstate = 'modify';
} else {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
} else {
foreach my $user (keys(%$courseusers)) {
@@ -3114,7 +3164,7 @@ sub user_search_result {
}
}
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
}
}
}
@@ -3124,7 +3174,7 @@ sub user_search_result {
($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
if ($dirsrchres eq 'ok') {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} else {
my $showdom = &display_domain_info($srch->{'srchdomain'});
$response = ''.
@@ -3138,7 +3188,7 @@ sub user_search_result {
if ($srch->{'srchin'} eq 'dom') {
%srch_results = &Apache::lonnet::usersearch($srch);
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} elsif ($srch->{'srchin'} eq 'crs') {
my $courseusers = &get_courseusers();
foreach my $user (keys(%$courseusers)) {
@@ -3190,14 +3240,14 @@ sub user_search_result {
}
}
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} elsif ($srch->{'srchin'} eq 'alc') {
$currstate = 'query';
} elsif ($srch->{'srchin'} eq 'instd') {
($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
if ($dirsrchres eq 'ok') {
($currstate,$response,$forcenewuser) =
- &build_search_response($srch,%srch_results);
+ &build_search_response($context,$srch,%srch_results);
} else {
my $showdom = &display_domain_info($srch->{'srchdomain'}); $response = ''.
&mt('Institutional directory search is not available in domain: [_1]',$showdom).
@@ -3303,7 +3353,7 @@ sub get_courseusers {
}
sub build_search_response {
- my ($srch,%srch_results) = @_;
+ my ($context,$srch,%srch_results) = @_;
my ($currstate,$response,$forcenewuser);
my %names = (
'uname' => 'username',
@@ -3362,8 +3412,15 @@ sub build_search_response {
}
}
if (!($srch->{'srchby'} eq 'uname' && $srch->{'srchin'} eq 'dom' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchdomain'} eq $env{'request.role.domain'})) {
- my $showdom = &display_domain_info($env{'request.role.domain'});
+ my $cancreate =
+ &Apache::lonuserutils::can_create_user($env{'request.role.domain'},$context);
+ if ($cancreate) {
+ my $showdom = &display_domain_info($env{'request.role.domain'});
$response .= '
'.&mt("To add a new user (you can only create new users in your current role's domain - [_1]):",$env{'request.role.domain'}).'
';
+ } else {
+ my $helplink = ' href="javascript:helpMenu('."'display'".')"';
+ $response .= '
'.&mt("You are not authorized to create new users in your current role's domain - [_1].",$env{'request.role.domain'}).'
'.&mt('Contact the helpdesk if you need to create a new user.',$helplink).'
';
+ }
}
}
}
@@ -3465,83 +3522,24 @@ sub course_level_table {
}
my @roles = &Apache::lonuserutils::roles_by_context('course');
foreach my $role (@roles) {
+ my $plrole=&Apache::lonnet::plaintext($role);
if (&Apache::lonnet::allowed('c'.$role,$thiscourse)) {
- my $plrole=&Apache::lonnet::plaintext($role);
- $table .= &Apache::loncommon::start_data_table_row().
-'
'.$lt{'exs'}.' '. - $currsec.' | '.
- ''. - ' | '.$lt{'new'}.' '. - ''. - ' | '.
- '
'.
- $lt{'exs'}.' '.$currsec.' | '.
- ''. - ' | '.$lt{'new'}.' '. - ' | '.
- ''.
- '
'.$lt->{'exs'}.' '. + $currsec.' |
+ + | '.$lt->{'new'}.' '. + ''. + ' | '."\n".
+ '