--- loncom/interface/loncreateuser.pm 2008/05/12 17:52:09 1.239
+++ loncom/interface/loncreateuser.pm 2008/07/02 16:08:21 1.246
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Create a user
#
-# $Id: loncreateuser.pm,v 1.239 2008/05/12 17:52:09 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.246 2008/07/02 16:08:21 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2069,7 +2069,10 @@ END
if ($env{'form.popup'}) {
$r->print('
'.&mt('Close window').'
');
} else {
- $r->print(''.&mt('Modify this user: ([_1])',$userinfo).''.(' 'x5).''.&mt('Create/Modify Another User').'
');
+ $r->print(''
+ .&mt('Modify this user: [_1]',''.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')').''
+ .(' 'x5).''
+ .&mt('Create/Modify Another User').'
');
}
}
$r->print(&Apache::loncommon::end_page());
@@ -2146,7 +2149,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');
}
@@ -2193,7 +2196,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)) {
@@ -2220,7 +2223,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);
@@ -2231,7 +2234,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)) {
@@ -2253,7 +2256,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);
@@ -2267,13 +2270,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)) {
@@ -2295,19 +2298,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)) {
@@ -2670,7 +2673,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) {
@@ -2745,7 +2748,7 @@ sub set_custom_role {
$url,
$env{'user.domain'},
$env{'user.name'},
- $rolename));
+ $rolename,undef,undef,undef,$context));
}
$r->print(''.&mt('Create or edit another custom role').'
');
@@ -2889,7 +2892,7 @@ sub handler {
}
} elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
if ($env{'form.phase'} eq 'set_custom_roles') {
- &set_custom_role($r);
+ &set_custom_role($r,$context);
} else {
&custom_role_editor($r);
}
@@ -2981,7 +2984,7 @@ sub handler {
if (!exists($env{'form.state'})) {
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
'Course_Self_Enrollment'));
-
+ $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
@@ -2989,7 +2992,8 @@ 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') {
@@ -3104,7 +3108,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'}),
@@ -3122,15 +3126,15 @@ sub print_main_menu {
permission => $permission->{'grp_manage'},
url => '/adm/coursegroups?refpage=cusr',
},
- { text => 'View Log-in History',
- help => 'Course_User_Logins',
- action => 'logins',
- permission => $permission->{'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);
}
@@ -3178,8 +3182,10 @@ sub print_selfenroll_menu {
$setsec_js."\n".
''."\n".
''.$lt->{'selfenroll'}.'
'."\n".
- '';
+ '
'
+ .'';
$r->print($output);
return;
}
+sub new_selfenroll_dom_row {
+ my ($newdom,$num) = @_;
+ my $domdesc = &Apache::lonnet::domain($newdom);
+ my $output;
+ if ($domdesc ne '') {
+ $output .= &Apache::loncommon::start_data_table_row()
+ .''.&mt('Domain:').' '.$domdesc
+ .' ('.$newdom.') | ';
+ my @currinsttypes;
+ $output .= ''.&mt('User types:').' '
+ .&selfenroll_inst_types($num,$newdom,\@currinsttypes).' | '
+ .&Apache::loncommon::end_data_table_row();
+ }
+ return $output;
+}
+
+sub selfenroll_inst_types {
+ my ($num,$currdom,$currinsttypes) = @_;
+ my $output;
+ my $numinrow = 4;
+ my $count = 0;
+ my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
+ if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
+ $output .= '';
+ }
+ return $output;
+}
+
sub selfenroll_date_forms {
my ($startform,$endform) = @_;
my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
- &Apache::lonhtmlcommon::row_title(&mt('Starts'),
+ &Apache::lonhtmlcommon::row_title(&mt('Start date'),
'LC_oddrow_value')."\n".
$startform."\n".
&Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::row_title(&mt('Ends'),
+ &Apache::lonhtmlcommon::row_title(&mt('End date'),
'LC_oddrow_value')."\n".
$endform."\n".
&Apache::lonhtmlcommon::row_closure(1).
@@ -3547,7 +3672,13 @@ sub user_search_result {
if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
($srch->{'srchin'} eq 'alc')) {
if ($srch->{'srchby'} eq 'uname') {
- if ($srch->{'srchterm'} !~ /^$match_username$/) {
+ my $unamecheck = $srch->{'srchterm'};
+ if ($srch->{'srchtype'} eq 'contains') {
+ if ($unamecheck !~ /^\w/) {
+ $unamecheck = 'a'.$unamecheck;
+ }
+ }
+ if ($unamecheck !~ /^$match_username$/) {
$response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
}
}
@@ -4138,13 +4269,13 @@ ENDTIMEENTRY
}
sub update_selfenroll_config {
- my ($r,$context) = @_;
+ my ($r,$context,$permission) = @_;
my ($row,$lt) = &get_selfenroll_titles();
- my $groupslist = &Apache::lonuserutils::get_groupslist();
+ my %curr_groups = &Apache::longroup::coursegroups();
my (%changes,%warning);
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
- $r->print(''.$lt->{'selfenroll'}.'
'."\n");
+ my $curr_types;
if (ref($row) eq 'ARRAY') {
foreach my $item (@{$row}) {
if ($item eq 'enroll_dates') {
@@ -4165,13 +4296,47 @@ sub update_selfenroll_config {
$changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
}
}
+ } elsif ($item eq 'types') {
+ $curr_types =
+ $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
+ if ($env{'form.selfenroll_all'}) {
+ if ($curr_types ne '*') {
+ $changes{'internal.selfenroll_types'} = '*';
+ } else {
+ next;
+ }
+ } elsif ($curr_types eq '') {
+ my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_0');
+ if (@types > 0) {
+ $changes{'internal.selfenroll_types'} = $env{'form.selfenroll_dom_0'}.':'.join(',',@types);
+ }
+ } else {
+ my @entries = split(/;/,$curr_types);
+ my $num = 0;
+ my @latesttypes;
+ my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
+ my $newnum = 0;
+ for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
+ if (!grep(/^$j$/,@deletedoms)) {
+ my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
+ @types = sort(@types);
+ my $typestr = join(',',@types);
+ $latesttypes[$newnum] = $env{'form.selfenroll_dom_'.$j}.':'.$typestr;
+ $newnum ++;
+ }
+ }
+ my $selfenroll_types = join(';',@latesttypes);
+ if ($selfenroll_types ne $curr_types) {
+ $changes{'internal.selfenroll_types'} = $selfenroll_types;
+ }
+ }
} else {
my $curr_val =
$env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
my $newval = $env{'form.selfenroll_'.$item};
if ($item eq 'section') {
$newval = $env{'form.sections'};
- if (grep(/^\Q$newval\E$/,keys(%{$groupslist}))) {
+ if (defined($curr_groups{$newval})) {
$newval = $curr_val;
$warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'
'.&mt('Group names and section names must be distinct');
} elsif ($newval eq 'all') {
@@ -4185,7 +4350,7 @@ sub update_selfenroll_config {
if ($newval ne $curr_val) {
$changes{'internal.selfenroll_'.$item} = $newval;
}
- }
+ }
}
if (keys(%warning) > 0) {
foreach my $item (@{$row}) {
@@ -4225,7 +4390,7 @@ sub update_selfenroll_config {
foreach my $type ('start','end') {
if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
- $r->print(''.&mt('[_1]: [_2] set to "[_3]".',
+ $r->print(''.&mt('[_1]: "[_2]" set to "[_3]".',
$title,$type,$newdate).'');
}
}
@@ -4233,14 +4398,27 @@ sub update_selfenroll_config {
foreach my $type ('start','end') {
if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
- $r->print(''.&mt('[_1]: [_2] set to "[_3]".',
+ $r->print(''.&mt('[_1]: "[_2]" set to "[_3]".',
$title,$type,$newdate).'');
}
}
} else {
if (exists($changes{'internal.selfenroll_'.$item})) {
- $r->print(''.&mt('[_1] set to "[_2]".',$title,
- $changes{'internal.selfenroll_'.$item}).''."\n");
+ my $newval = $changes{'internal.selfenroll_'.$item};
+ if ($item eq 'types') {
+ if ($newval eq '') {
+ $newval = &mt('None');
+ } elsif ($newval eq '*') {
+ $newval = &mt('Any user in any domain');
+ }
+ } elsif ($item eq 'registered') {
+ if ($newval eq '1') {
+ $newval = &mt('Yes');
+ } elsif ($newval eq '0') {
+ $newval = &mt('No');
+ }
+ }
+ $r->print(''.&mt('"[_1]" set to "[_2]".',$title,$newval).''."\n");
}
}
}
@@ -4259,18 +4437,20 @@ sub update_selfenroll_config {
} else {
$r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.'));
}
+ if ($env{'form.selfenroll_newdom'} ne '') {
+ &print_selfenroll_menu($r,$context,$permission);
+ }
return;
}
sub get_selfenroll_titles {
my @row = ('types','registered','enroll_dates','access_dates','section');
my %lt = &Apache::lonlocal::texthash (
- selfenroll => 'Self-enrollment with a student role',
types => 'Users allowed to self-enroll in this course',
- registered => 'Restrict self-enrollment to registered students?',
+ registered => 'Restrict self-enrollment to students officially registered for the course',
enroll_dates => 'Dates self-enrollment available',
- access_dates => 'Access dates for self-enrolled users',
- section => 'Section',
+ access_dates => 'Course access dates for self-enrolled users',
+ section => 'Section assigned to self-enrolled users',
);
return (\@row,\%lt);
}