--- loncom/interface/loncreateuser.pm 2008/02/22 05:05:57 1.235
+++ loncom/interface/loncreateuser.pm 2008/08/26 23:20:22 1.249.2.6
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.235 2008/02/22 05:05:57 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.249.2.6 2008/08/26 23:20:22 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -967,7 +967,7 @@ sub display_existing_roles {
if (defined($coursedata{'description'})) {
$carea=$coursedata{'description'}.
' '. &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').' '.$visactions->{'vis'}.' '.$visactions->{'gen'}.'
'.&mt('Domain').': '.$coursedom.(' 'x8).
- &Apache::loncommon::syllabuswrapper('Syllabus',$coursedir,$coursedom);
+ &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
$sortkey.="\0".$coursedata{'description'};
$class=$coursedata{'type'};
} else {
@@ -1396,10 +1396,12 @@ 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',
@@ -1407,7 +1409,10 @@ sub personal_data_display {
'permanentemail','id'],$ccdomain,$ccuname);
%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",
@@ -1416,7 +1421,7 @@ sub personal_data_display {
'lastname' => "Last Name",
'generation' => "Generation",
'permanentemail' => "Permanent e-mail address",
- 'id' => "ID/Student Number",
+ 'id' => "Student/Employee ID",
'lg' => "Login Data"
);
my %textboxsize = (
@@ -1432,40 +1437,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) = @_;
@@ -1789,7 +1847,7 @@ sub update_user_data {
$env{'form.c'.$item} = $userenv{$item};
}
}
- # Check to see if we can change the ID/student number
+ # Check to see if we can change the Student/Employee ID
my $forceid = $env{'form.forceid'};
my $recurseid = $env{'form.recurseid'};
my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
@@ -1800,7 +1858,10 @@ sub update_user_data {
(!$forceid)) {
if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
$env{'form.cid'} = $userenv{'id'};
- $no_forceid_alert = &mt('New student/employeeID does not match existing ID for this user.').'
'.&mt('Change is not permitted without checking the \'Force ID change\' checkbox on the previous page.').'
'."\n";
+ $no_forceid_alert = &mt('New Student/Employee ID does not match existing ID for this user.')
+ .'
'
+ .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
+ .'
'."\n";
}
}
if ($env{'form.cid'} ne $userenv{'id'}) {
@@ -1914,7 +1975,7 @@ sub update_user_data {
'mddl' => "middle",
'lst' => "last",
'gen' => "generation",
- 'id' => "ID/Student number",
+ 'id' => "Student/Employee ID",
'mail' => "permanent e-mail",
'disk' => "disk space allocated to portfolio files",
'prvs' => "Previous",
@@ -1986,7 +2047,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').' '.
@@ -1997,7 +2058,7 @@ END
# 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",
+ 'id' => "Student/Employee ID",
'mail' => "Permanent e-mail",
'disk' => "Disk space allocated to user's portfolio files",
);
@@ -2040,14 +2101,17 @@ END
$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));
+ $r->print(''
+ .$no_forceid_alert
+ .&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 +2177,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 +2190,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 +2212,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 +2244,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 +2259,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 +2286,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 +2297,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 +2319,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 +2333,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 +2361,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 +2401,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 +2416,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 '') {
@@ -2556,7 +2625,7 @@ sub custom_role_editor {
'crl' => "Course Level",
'dml' => "Domain Level",
'ssl' => "System Level");
- $r->print('Select a Template
');
+ $r->print(&mt('Select a Template').'
');
$r->print('');
@@ -2667,7 +2736,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 +2811,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
+ ({href=>'/adm/createuser?action=selfenroll',
+ text=>"Result"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
+ 'Course_Self_Enrollment'));
+ $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'));
@@ -3073,19 +3171,34 @@ 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'}),
url => '/adm/populate',
- });
+ },
+ { text => 'Configure User Self-enrollment',
+ help => 'Course_Self_Enrollment',
+ action => 'selfenroll',
+ permission => $permission->{'cusr'},
+ });
}
push(@courselinks,
{ text => 'Manage Course Groups',
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 = '';
@@ -3120,6 +3233,815 @@ sub restore_prev_selections {
\%saveable_parameters);
}
+sub print_selfenroll_menu {
+ my ($r,$context,$permission) = @_;
+ my $formname = 'enrollstudent';
+ my $nolink = 1;
+ my ($row,$lt) = &get_selfenroll_titles();
+ 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";
+ my ($visible,$cansetvis,$vismsgs,$visactions) = &visible_in_cat($cdom,$cnum);
+ if (ref($visactions) eq 'HASH') {
+ if ($visible) {
+ $output .= '
'.$visactions->{'yous'}.
+ '
'.$visactions->{'coca'};
+ if (ref($vismsgs) eq 'ARRAY') {
+ $output .= '
'.$visactions->{'make'}.'';
+ foreach my $item (@{$vismsgs}) {
+ $output .= '
';
+ }
+ $output .= '
'; + } + $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:').' |