END
+ $r->print(&Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table().' ');
+ if ($env{'form.cid'} ne $userenv{'id'}) {
+ &Apache::lonnet::idput($env{'form.ccdomain'},
+ ($env{'form.ccuname'} => $env{'form.cid'}));
+ if (($recurseid) &&
+ (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
+ my %userupdate = (
+ lastname => $env{'form.clasaname'},
+ middlename => $env{'form.cmiddlename'},
+ firstname => $env{'form.cfirstname'},
+ generation => $env{'fora.cgeneration'},
+ id => $env{'form.cid'},
+ );
+ my $idresult =
+ &Apache::lonuserutils::propagate_id_change(
+ $env{'form.ccuname'},$env{'form.ccdomain'},
+ \%userupdate);
+ $r->print(' '.$idresult.' ');
+ }
+ }
if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
($env{'form.ccuname'} eq $env{'user.name'})) {
my %newenvhash;
@@ -1774,32 +1943,54 @@ END
} else { # error occurred
$r->print(''.&mt('Unable to successfully change environment for').' '.
$env{'form.ccuname'}.' '.&mt('in domain').' '.
- $env{'form.ccdomain'}.'');
+ $env{'form.ccdomain'}.' ');
}
} else { # End of if ($env ... ) logic
- my $putresult;
- if ($quotachanged) {
- $putresult = &Apache::lonnet::put
- ('environment',\%changeHash,
- $env{'form.ccdomain'},$env{'form.ccuname'});
- }
- # They did not want to change the users name but we can
- # still tell them what the name is
+ # They did not want to change the users name or quota but we can
+ # still tell them what the name and quota are
my %lt=&Apache::lonlocal::texthash(
+ 'id' => "ID/Student number",
'mail' => "Permanent e-mail",
'disk' => "Disk space allocated to user's portfolio files",
);
$r->print(<<"END");
-
');
+ }
+ if (@mod_disallowed) {
+ my ($rolestr,$contextname);
+ if (@longroles > 0) {
+ $rolestr = join(', ',@longroles);
+ } else {
+ $rolestr = &mt('No roles');
}
+ if ($context eq 'course') {
+ $contextname = &mt('course');
+ } elsif ($context eq 'author') {
+ $contextname = &mt('co-author');
+ }
+ $r->print(&mt('The following fields were not updated: ').'
');
+ my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
+ foreach my $field (@mod_disallowed) {
+ $r->print('
'.$fieldtitles{$field}.'
'."\n");
+ }
+ $r->print('
');
+ if (@mod_disallowed == 1) {
+ $r->print(&mt("You do not have the authority to change this field given the user's current set of active/future [_1] roles:",$contextname));
+ } else {
+ $r->print(&mt("You do not have the authority to change these fields given the user's current set of active/future [_1] roles:",$contextname));
+ }
+ $r->print(''.$rolestr.' '.
+ &mt('Contact your helpdesk for more information.',"javascript:helpMenu('display')").' ');
}
+ $r->print($no_forceid_alert.
+ &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
}
##
my $now=time;
@@ -1820,11 +2011,13 @@ END
$r->print(&mt('Revoking [_1] in [_2]: [_3]',
$role,$scope,''.$result.'').' ');
if ($role eq 'st') {
- my $result = &classlist_drop($scope,$env{'form.ccuname'},
- $env{'form.ccdomain'},$now);
+ my $result =
+ &Apache::lonuserutils::classlist_drop($scope,
+ $env{'form.ccuname'},$env{'form.ccdomain'},
+ $now);
$r->print($result);
}
- }
+ }
if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
# Revoke custom role
$r->print(&mt('Revoking custom role:').
@@ -1845,8 +2038,10 @@ END
$r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
''.$result.'').' ');
if ($role eq 'st') {
- my $result = &classlist_drop($scope,$env{'form.ccuname'},
- $env{'form.ccdomain'},$now);
+ my $result =
+ &Apache::lonuserutils::classlist_drop($scope,
+ $env{'form.ccuname'},$env{'form.ccdomain'},
+ $now);
$r->print($result);
}
}
@@ -2023,6 +2218,23 @@ END
$r->print(&Apache::loncommon::end_page());
}
+sub get_defaultquota_text {
+ my ($settingstatus) = @_;
+ my $defquotatext;
+ 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});
+ }
+ }
+ return $defquotatext;
+}
+
sub update_result_form {
my ($uhome) = @_;
my $outcome =
@@ -2030,6 +2242,9 @@ sub update_result_form {
foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
$outcome .= ''."\n";
}
+ if ($env{'form.origname'} ne '') {
+ $outcome .= ''."\n";
+ }
foreach my $item ('sortby','seluname','seludom') {
if (exists($env{'form.'.$item})) {
$outcome .= ''."\n";
@@ -2045,30 +2260,6 @@ sub update_result_form {
return $outcome;
}
-sub classlist_drop {
- my ($scope,$uname,$udom,$now) = @_;
- my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
- my $cid=$cdom.'_'.$cnum;
- my $user = $uname.':'.$udom;
- if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
- my $result =
- &Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
- return &mt('Drop from classlist: [_1]',
- ''.$result.'').' ';
- }
-}
-
-sub active_student_roles {
- my ($cnum,$cdom,$uname,$udom) = @_;
- my %roles =
- &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
- ['future','active'],['st']);
- return exists($roles{"$cnum:$cdom:st"});
-}
-
sub quota_admin {
my ($setquota,$changeHash) = @_;
my $quotachanged;
@@ -2412,17 +2603,20 @@ sub handler {
if ($env{'request.course.id'}) {
$context = 'course';
} elsif ($env{'request.role'} =~ /^au\./) {
- $context = 'construction_space';
+ $context = 'author';
} else {
$context = 'domain';
}
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['action','state']);
+ ['action','state','callingform','roletype','showrole','bulkaction']);
&Apache::lonhtmlcommon::clear_breadcrumbs();
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>"/adm/createuser",
- text=>"User Management"});
- my ($permission,$allowed) = &get_permission($context);
+ if ($env{'form.action'} ne 'dateselect') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>"/adm/createuser",
+ text=>"User Management"});
+ }
+ my ($permission,$allowed) =
+ &Apache::lonuserutils::get_permission($context);
if (!$allowed) {
$env{'user.error.msg'}=
"/adm/createuser:cst:0:0:Cannot create/modify user data ".
@@ -2437,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());
@@ -2471,7 +2665,7 @@ sub handler {
if (! exists($env{'form.state'})) {
&Apache::lonuserutils::print_expire_menu($r,$context);
} elsif ($env{'form.state'} eq 'done') {
- &Apache::lonuserutils::expire_user_list($r);
+ &Apache::lonuserutils::expire_user_list($r,$context);
} else {
&Apache::lonuserutils::print_expire_menu($r,$context);
}
@@ -2485,8 +2679,20 @@ sub handler {
$srch->{$item} = $env{'form.'.$item};
}
- if (($phase eq 'get_user_info') || ($phase eq 'userpicked')) {
- if ($env{'form.phase'} eq 'get_user_info') {
+ if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
+ ($phase eq 'createnewuser')) {
+ if ($env{'form.phase'} eq 'createnewuser') {
+ my $response;
+ if ($env{'form.srchterm'} !~ /^$match_username$/) {
+ my $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
+ &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);
+ }
+ } elsif ($env{'form.phase'} eq 'get_user_info') {
my ($currstate,$response,$forcenewuser,$results) =
&user_search_result($srch);
if ($env{'form.currstate'} eq 'modify') {
@@ -2494,7 +2700,7 @@ sub handler {
}
if ($currstate eq 'select') {
&print_user_selection_page($r,$response,$srch,$results,
- 'createuser',\@search);
+ 'createuser',\@search,$context);
} elsif ($currstate eq 'modify') {
my ($ccuname,$ccdomain);
if (($srch->{'srchby'} eq 'uname') &&
@@ -2511,22 +2717,23 @@ sub handler {
$response = '';
}
&print_user_modification_page($r,$ccuname,$ccdomain,
- $srch,$response);
+ $srch,$response,$context);
} elsif ($currstate eq 'query') {
&print_user_query_page($r,'createuser');
} else {
- &print_username_entry_form($r,$response,$srch,
+ &print_username_entry_form($r,$context,$response,$srch,
$forcenewuser);
}
} elsif ($env{'form.phase'} eq 'userpicked') {
my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
- &print_user_modification_page($r,$ccuname,$ccdomain,$srch);
+ &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
+ $context);
}
} elsif ($env{'form.phase'} eq 'update_user_data') {
- &update_user_data($r);
+ &update_user_data($r,$context);
} else {
- &print_username_entry_form($r,undef,$srch);
+ &print_username_entry_form($r,$context,undef,$srch);
}
} elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
if ($env{'form.phase'} eq 'set_custom_roles') {
@@ -2534,32 +2741,48 @@ sub handler {
} else {
&custom_role_editor($r);
}
- } elsif ($env{'form.action'} eq 'listusers' && $permission->{'view'}) {
- my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
- my $formname = 'studentform';
- if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
- ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
- &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
- $formname);
- my $js = &add_script($jscript).$cb_jscript;
- my $loadcode =
- &Apache::lonuserutils::course_selector_loadcode($formname);
- if ($loadcode ne '') {
- $r->print(&header($js,{'onload' => $loadcode,}));
+ } elsif (($env{'form.action'} eq 'listusers') &&
+ ($permission->{'view'} || $permission->{'cusr'})) {
+ if ($env{'form.phase'} eq 'bulkchange') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'backPage(document.studentform)',
+ text=>"List Users"});
+ my $setting = $env{'form.roletype'};
+ my $choice = $env{'form.bulkaction'};
+ $r->print(&header());
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
+ 'User_Management_List'));
+ if ($permission->{'cusr'}) {
+ &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice);
+ }
+ } else {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=listusers',
+ text=>"List Users"});
+ my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
+ my $formname = 'studentform';
+ if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
+ ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
+ &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
+ $formname);
+ $jscript .= &verify_user_display();
+ my $js = &add_script($jscript).$cb_jscript;
+ my $loadcode =
+ &Apache::lonuserutils::course_selector_loadcode($formname);
+ if ($loadcode ne '') {
+ $r->print(&header($js,{'onload' => $loadcode,}));
+ } else {
+ $r->print(&header($js));
+ }
} else {
- $r->print(&header($js));
+ $r->print(&header(&add_script(&verify_user_display())));
}
- } else {
- $r->print(&header());
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
+ 'User_Management_List'));
+ &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
+ $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
+ $r->print(&Apache::loncommon::end_page());
}
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href=>'/adm/createuser?action=listusers',
- text=>"List Users"});
- $r->print(&Apache::lonhtmlcommon::breadcrumbs("List Users",
- 'User_Management_List'));
- &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
- $formname,$totcodes,$codetitles,$idlist,$idlist_titles);
- $r->print(&Apache::loncommon::end_page());
} elsif ($env{'form.action'} eq 'expire' && $permission->{'cusr'}) {
$r->print(&header());
&Apache::lonhtmlcommon::add_breadcrumb
@@ -2570,26 +2793,37 @@ sub handler {
if (! exists($env{'form.state'})) {
&Apache::lonuserutils::print_expire_menu($r,$context);
} elsif ($env{'form.state'} eq 'done') {
- &Apache::lonuserutiles::expire_user_list($r);
+ &Apache::lonuserutiles::expire_user_list($r,$context);
} else {
&print_expire_menu($r,$context);
}
$r->print(&Apache::loncommon::end_page());
+ } 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::loncommon::end_page());
+ } else {
+ $r->print(&header().
+ ''.&mt('You do not have permission to modify dates or sections for users').''.
+ &Apache::loncommon::end_page());
+ }
} else {
$r->print(&header());
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management')); $r->print(&print_main_menu($permission));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
+ $r->print(&print_main_menu($permission,$context));
$r->print(&Apache::loncommon::end_page());
}
return OK;
}
sub header {
- my ($jscript,$loaditems) = @_;
+ my ($jscript,$loaditems,$args) = @_;
my $start_page;
if (ref($loaditems) eq 'HASH') {
- $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems,});
+ $start_page=&Apache::loncommon::start_page('User Management',$jscript,{'add_entries' => $loaditems});
} else {
- $start_page=&Apache::loncommon::start_page('User Management',$jscript);
+ $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
}
return $start_page;
}
@@ -2599,39 +2833,86 @@ sub add_script {
return '';
}
+sub verify_user_display {
+ my $output = <<"END";
+
+function display_update() {
+ document.studentform.action.value = 'listusers';
+ document.studentform.phase.value = 'display';
+ document.studentform.submit();
+}
+
+END
+ return $output;
+
+}
+
###############################################################
###############################################################
# 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'});
@@ -2653,57 +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'};
- }
- }
- }
- } elsif ($context eq 'construction_space') {
- $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',
@@ -3106,6 +3336,10 @@ sub crumb_utilities {
srchtype => 'selectbox',
srchdomain => 'selectbox',
},
+ crtusername => {
+ srchterm => 'text',
+ srchdomain => 'selectbox',
+ },
docustom => {
rolename => 'selectbox',
newrolename => 'textbox',
@@ -3173,7 +3407,9 @@ sub course_level_table {
'.$area.' Domain: '.$domain.'
'."\n";
if ($role ne 'cc') {
if (%sections_count) {
- my $currsec = &course_sections(\%sections_count,$protectedcourse.'_'.$role);
+ my $currsec =
+ &Apache::lonuserutils::course_sections(\%sections_count,
+ $protectedcourse.'_'.$role);
$table .=
'
'.
'
@@ -3213,7 +3449,9 @@ ENDTIMEENTRY
'.$plrole.'
'.$area.'
'."\n";
if (%sections_count) {
- my $currsec = &course_sections(\%sections_count,$customrole);
+ my $currsec =
+ &Apache::lonuserutils::course_sections(\%sections_count,
+ $customrole);
$table.=
'