--- loncom/interface/loncreateuser.pm 2008/03/08 03:48:41 1.237
+++ loncom/interface/loncreateuser.pm 2008/07/17 20:05:14 1.257
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.237 2008/03/08 03:48:41 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.257 2008/07/17 20:05:14 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1396,18 +1396,25 @@ sub modify_login_block {
}
sub personal_data_display {
- my ($ccuname,$ccdomain,$newuser,$context,$inst_results) = @_;
+ my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$rolesarray) = @_;
my ($output,$showforceid,%userenv,%canmodify);
my @userinfo = ('firstname','middlename','lastname','generation',
'permanentemail','id');
+ my $rowcount = 0;
+ my $editable = 0;
if (!$newuser) {
# Get the users information
%userenv = &Apache::lonnet::get('environment',
['firstname','middlename','lastname','generation',
'permanentemail','id'],$ccdomain,$ccuname);
+ }
+ if (!$newuser) {
%canmodify =
&Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
- \@userinfo);
+ \@userinfo,$rolesarray);
+ } elsif ($context eq 'selfcreate') {
+ %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
+ $inst_results,$rolesarray);
}
my %lt=&Apache::lonlocal::texthash(
'pd' => "Personal Data",
@@ -1432,40 +1439,93 @@ sub personal_data_display {
&Apache::lonhtmlcommon::start_pick_box();
foreach my $item (@userinfo) {
my $rowtitle = $lt{$item};
+ my $hiderow = 0;
if ($item eq 'generation') {
$rowtitle = $genhelp.$rowtitle;
}
- $output .= &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
+ my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
if ($newuser) {
if (ref($inst_results) eq 'HASH') {
if ($inst_results->{$item} ne '') {
- $output .= ''.$inst_results->{$item};
+ $row .= ''.$inst_results->{$item};
} else {
- $output .= '';
+ if ($context eq 'selfcreate') {
+ if ($canmodify{$item}) {
+ $row .= '';
+ $editable ++;
+ } else {
+ $hiderow = 1;
+ }
+ } else {
+ $row .= '';
+ }
}
} else {
- $output .= '';
+ if ($context eq 'selfcreate') {
+ if ($canmodify{$item}) {
+ $row .= '';
+ $editable ++;
+ } else {
+ $hiderow = 1;
+ }
+ } else {
+ $row .= '';
+ }
}
} else {
if ($canmodify{$item}) {
- $output .= '';
+ $row .= '';
} else {
- $output .= $userenv{$item};
+ $row .= $userenv{$item};
}
if ($item eq 'id') {
$showforceid = $canmodify{$item};
}
}
- $output .= &Apache::lonhtmlcommon::row_closure(1);
+ $row .= &Apache::lonhtmlcommon::row_closure(1);
+ if (!$hiderow) {
+ $output .= $row;
+ $rowcount ++;
+ }
}
$output .= &Apache::lonhtmlcommon::end_pick_box();
if (wantarray) {
- return ($output,$showforceid);
+ if ($context eq 'selfcreate') {
+ return($output,$rowcount,$editable);
+ } else {
+ return ($output,$showforceid);
+ }
} else {
return $output;
}
}
+sub selfcreate_canmodify {
+ my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
+ if (ref($inst_results) eq 'HASH') {
+ my @inststatuses = &get_inststatuses($inst_results);
+ if (@inststatuses == 0) {
+ @inststatuses = ('default');
+ }
+ $rolesarray = \@inststatuses;
+ }
+ my %canmodify =
+ &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
+ $rolesarray);
+ return %canmodify;
+}
+
+sub get_inststatuses {
+ my ($insthashref) = @_;
+ my @inststatuses = ();
+ if (ref($insthashref) eq 'HASH') {
+ if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
+ @inststatuses = @{$insthashref->{'inststatus'}};
+ }
+ }
+ return @inststatuses;
+}
+
# ================================================================= Phase Three
sub update_user_data {
my ($r,$context) = @_;
@@ -1986,7 +2046,7 @@ END
foreach my $key (keys(%changeHash)) {
$newenvhash{'environment.'.$key} = $changeHash{$key};
}
- &Apache::lonnet::appenv(%newenvhash);
+ &Apache::lonnet::appenv(\%newenvhash);
}
} else { # error occurred
$r->print(''.&mt('Unable to successfully change environment for').' '.
@@ -2041,13 +2101,14 @@ END
&mt('Contact your helpdesk for more information.',"javascript:helpMenu('display')").' '. &mt('Enroll Another Student').' '.
+ &mt('Enroll Another Student').' '.&mt('Modify this user: ([_1])',$userinfo).''.(' 'x5).''.&mt('Create/Modify Another User').' '
+ .&mt('Modify this user: [_1]',''.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')').''
+ .(' 'x5).''
+ .&mt('Create/Modify Another User').' '.&mt('Create or edit another custom role').'
');
}
$r->print($no_forceid_alert.
- &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts, \%curr_rules));
+ &Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules));
}
if ($env{'form.action'} eq 'singlestudent') {
- &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser);
- $r->print('
');
if ($role eq 'st') {
@@ -2110,7 +2174,7 @@ sub update_roles {
$r->print(&mt('Revoking custom role:').
' '.$4.' by '.$3.':'.$2.' in '.$1.': '.
&Apache::lonnet::revokecustomrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$1,$2,$3,$4).
+ $env{'form.ccuname'},$1,$2,$3,$4,'','',$context).
'
');
if (!grep(/^cr$/,@rolechanges)) {
push(@rolechanges,'cr');
@@ -2123,7 +2187,8 @@ sub update_roles {
my $result =
&Apache::lonnet::assignrole($env{'form.ccdomain'},
$env{'form.ccuname'},
- $scope,$role,$now,0,1);
+ $scope,$role,$now,0,1,'',
+ $context);
$r->print(&mt('Deleting [_1] in [_2]: [_3]',$role,$scope,
''.$result.'').'
');
if ($role eq 'st') {
@@ -2144,7 +2209,7 @@ sub update_roles {
$rolename,$rnam,$rdom,$url).': '.
&Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
$env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
- 0,1).'
');
+ 0,1,$context).'
');
if (!grep(/^cr$/,@rolechanges)) {
push(@rolechanges,'cr');
}
@@ -2176,7 +2241,8 @@ sub update_roles {
}
} else {
my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
- $env{'form.ccuname'},$url,$role,0,$now);
+ $env{'form.ccuname'},$url,$role,0,$now,'','',
+ $context);
$output = &mt('Re-enabling [_1] in [_2]: [_3]',
$role,$url,$result).'
';
}
@@ -2190,7 +2256,7 @@ sub update_roles {
my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
my $result = &Apache::lonnet::assigncustomrole(
$env{'form.ccdomain'}, $env{'form.ccuname'},
- $url,$rdom,$rnam,$rolename,0,$now);
+ $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
$r->print(&mt('Re-enabling custom role [_1] by [_2]@[_3] in [_4] : [_5]',
$rolename,$rnam,$rdom,$url,$result).'
');
if (!grep(/^cr$/,@rolechanges)) {
@@ -2217,7 +2283,7 @@ sub update_roles {
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end));
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
@@ -2228,7 +2294,7 @@ sub update_roles {
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end));
+ $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
}
}
if (!grep(/^cr$/,@rolechanges)) {
@@ -2250,7 +2316,7 @@ sub update_roles {
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
} else {
my %curr_groups =
&Apache::longroup::coursegroups($one,$two);
@@ -2264,13 +2330,13 @@ sub update_roles {
next;
}
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context));
}
}
if (!grep(/^\Q$three\E$/,@rolechanges)) {
@@ -2292,19 +2358,19 @@ sub update_roles {
my %sections = ();
my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
if ($num_sections == 0) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
} else {
my $emptysec = 0;
foreach my $sec (sort {$a cmp $b} keys %sections) {
if ($sec ne '') {
my $securl = $url.'/'.$sec;
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
} else {
$emptysec = 1;
}
}
if ($emptysec) {
- $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,''));
+ $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
}
}
if (!grep(/^\Q$two\E$/,@rolechanges)) {
@@ -2332,7 +2398,7 @@ sub update_roles {
}
sub enroll_single_student {
- my ($r,$uhome,$amode,$genpwd,$now,$newuser) = @_;
+ my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context) = @_;
$r->print(''.&mt('Enrolling Student').'
');
# Remove non alphanumeric values from section
@@ -2347,7 +2413,7 @@ sub enroll_single_student {
$env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
$env{'form.cmiddlename'},$env{'form.clastname'},
$env{'form.generation'},$env{'form.sections'},$enddate,
- $startdate,'manual',undef,$env{'request.course.id'});
+ $startdate,'manual',undef,$env{'request.course.id'},'',$context);
if ($enroll_result =~ /^ok/) {
$r->print(&mt('[_1] enrolled',$env{'form.ccuname'}.':'.$env{'form.ccdomain'}));
if ($env{'form.sections'} ne '') {
@@ -2667,7 +2733,7 @@ sub make_button_code {
}
# ---------------------------------------------------------- Call to definerole
sub set_custom_role {
- my ($r) = @_;
+ my ($r,$context) = @_;
my $rolename=$env{'form.rolename'};
$rolename=~s/[^A-Za-z0-9]//gs;
if (!$rolename) {
@@ -2742,7 +2808,7 @@ sub set_custom_role {
$url,
$env{'user.domain'},
$env{'user.name'},
- $rolename));
+ $rolename,undef,undef,undef,$context));
}
$r->print(''.&mt('Self-enrollment with a student role').'
'."\n");
&print_selfenroll_menu($r,$context,$permission);
} elsif ($env{'form.state'} eq 'done') {
&Apache::lonhtmlcommon::add_breadcrumb
@@ -2986,9 +3052,19 @@ sub handler {
text=>"Result"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
'Course_Self_Enrollment'));
- &update_selfenroll_config($r,$context);
+ $r->print(''.&mt('Self-enrollment with a student role').'
'."\n");
+ &update_selfenroll_config($r,$context,$permission);
}
$r->print(&Apache::loncommon::end_page());
+ } elsif ($env{'form.action'} eq 'changelogs') {
+ $r->print(&header());
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=changelogs',
+ text=>"User Management Logs"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Changes',
+ 'Course_User_Logs'));
+ &print_userchangelogs_display($r,$context,$permission);
+ $r->print(&Apache::loncommon::end_page());
} else {
$r->print(&header());
$r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
@@ -3092,7 +3168,7 @@ sub print_main_menu {
});
if (!exists($permission->{'cusr_section'})) {
push(@courselinks,
- { text => 'Automated Student Enrollment Manager',
+ { text => 'Automated Enrollment Manager',
help => 'Course_Automated_Enrollment',
permission => (&Apache::lonnet::auto_run($cnum,$cdom)
&& $permission->{'cusr'}),
@@ -3109,7 +3185,17 @@ sub print_main_menu {
help => 'Course_Manage_Group',
permission => $permission->{'grp_manage'},
url => '/adm/coursegroups?refpage=cusr',
- });
+ },
+ { text => 'View Change Logs',
+ help => 'Course_User_Logs',
+ action => 'changelogs',
+ permission => $permission->{'cusr'},
+ },);
+# { text => 'View Log-in History',
+# help => 'Course_User_Logins',
+# action => 'logins',
+# permission => $permission->{'cusr'},
+# });
push(@menu,@courselinks);
}
my $menu_html = '';
@@ -3152,12 +3238,203 @@ sub print_selfenroll_menu {
my $groupslist = &Apache::lonuserutils::get_groupslist();
my $setsec_js =
&Apache::lonuserutils::setsections_javascript($formname,$groupslist);
+ my %alerts = &Apache::lonlocal::texthash(
+ acto => 'Activation of self-enrollment was selected for the following domain(s)',
+ butn => 'but no user types have been checked.',
+ wilf => "Please uncheck 'activate' or check at least one type.",
+ );
+ my $selfenroll_js = <<"ENDSCRIPT";
+function update_types(caller,num) {
+ var delidx = getIndexByName('selfenroll_delete');
+ var actidx = getIndexByName('selfenroll_activate');
+ if (caller == 'selfenroll_all') {
+ var selall;
+ for (var i=0; i'.$lt->{'selfenroll'}.'
'."\n".
- '
'; + } + $count ++; + } + if (($count > 0) && ($count%$numinrow == 0)) { + $output .= ' |
'.
+ ''.&mt('Changes/page:').' '. + &Apache::lonmeta::selectbox('show',$curr->{'show'},undef, + (&mt('all'),5,10,20,50,100,1000,10000)). + ' | '; + my $startform = + &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date', + $curr->{'rolelog_start_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + my $endform = + &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date', + $curr->{'rolelog_end_date'},undef, + undef,undef,undef,undef,undef,undef,$nolink); + my %lt = &rolechg_contexts(); + $output .= ' | '.&mt('Window during which changes occurred:').'
| '. + ' | '.&mt('Role:').' '. + ' | '.
+ &mt('Context:').' |