--- loncom/interface/loncreateuser.pm 2008/08/27 20:59:56 1.260 +++ loncom/interface/loncreateuser.pm 2009/05/11 13:07:24 1.293 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Create a user # -# $Id: loncreateuser.pm,v 1.260 2008/08/27 20:59:56 raeburn Exp $ +# $Id: loncreateuser.pm,v 1.293 2009/05/11 13:07:24 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,11 +33,13 @@ package Apache::loncreateuser; =head1 NAME -Apache::loncreateuser - handler to create users and custom roles +Apache::loncreateuser.pm =head1 SYNOPSIS -Apache::loncreateuser provides an Apache handler for creating users, + Handler to create users and custom roles + + Provides an Apache handler for creating users, editing their login parameters, roles, and removing roles, and also creating and assigning custom roles. @@ -66,6 +68,7 @@ use Apache::loncommon; use Apache::lonlocal; use Apache::longroup; use Apache::lonuserutils; +use Apache::selfenroll(); use LONCAPA qw(:DEFAULT :match); my $loginscript; # piece of javascript used in two separate instances @@ -120,11 +123,12 @@ sub auth_abbrev { sub portfolio_quota { my ($ccuname,$ccdomain) = @_; my %lt = &Apache::lonlocal::texthash( - 'disk' => "Disk space allocated to user's portfolio files", - 'cuqu' => "Current quota", - 'cust' => "Custom quota", - 'defa' => "Default", - 'chqu' => "Change quota", + 'usrt' => "User Tools", + 'disk' => "Disk space allocated to user's portfolio files", + 'cuqu' => "Current quota", + 'cust' => "Custom quota", + 'defa' => "Default", + 'chqu' => "Change quota", ); my ($currquota,$quotatype,$inststatus,$defquota) = &Apache::loncommon::get_user_quota($ccuname,$ccdomain); @@ -173,27 +177,108 @@ END_SCRIPT " affiliation ([_2]).",$defquota,$longinsttype); } } - my $output = $quota_javascript. - '
' + .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.") + .' ' + .&mt('Please contact the [_1]helpdesk[_2] for assistance.' + ,'','') + .'
'. + ' | '; + } + } + $output .= '
'.&mt('ERROR').': '.&mt('Unknown command').' '.$key.'
'); if (($key eq 'none') || ($key eq 'all')) { - $r->print('
'.&mt('[_1] may not be used as the name for a section, as it is a reserved word.',$key)); + $r->print(&mt('[_1] may not be used as the name for a section, as it is a reserved word.',''.$key.'')); } else { - $r->print('
'.&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',$key)); + $r->print(&mt('[_1] may not be used as the name for a section, as it is the name of a course group.',''.$key.'')); } - $r->print(' '.&mt('Please go back and choose a different section name.').'
'
+ .&mt('Please [_1]go back[_2] and choose a different section name.'
+ ,''."\n";
$r->print(&Apache::loncommon::start_page('Custom Role Editor',$head_script));
@@ -2625,10 +3135,15 @@ sub custom_role_editor {
'crl' => "Course Level",
'dml' => "Domain Level",
'ssl' => "System Level");
- $r->print(&mt('Select a Template').' ';
- if (exists($menu_item->{'help'})) {
- $menu_html.=
- &Apache::loncommon::help_open_topic($menu_item->{'help'});
- }
- $menu_html.='';
- if (exists($menu_item->{'url'})) {
- $menu_html.=qq{};
- } else {
- $menu_html.=
- qq{};
- }
- $menu_html.= &mt($menu_item->{'text'}).'';
- $menu_html.=' '.$visactions->{'vis'}.' '.$visactions->{'vis'}.' '.$visactions->{'miss'}.' '.$visactions->{'gen'}.' '.&mt('The following were enrolled in the course:').'
');
- $r->print('');
+
+ $r->print(''.$privtext.' '.
- ($courselevel{$priv}?'':' ').
+ ($courselevel{$priv}?'':' ').
' '.
- ($domainlevel{$priv}?'':' ').
+ ($domainlevel{$priv}?'':' ').
' '.
- ($systemlevel{$priv}?'':' ').
+ ($systemlevel{$priv}?'':' ').
' '.
&Apache::loncommon::end_data_table_row());
}
@@ -2659,7 +3174,7 @@ ENDCCF
''."\n".''."\n".
''."\n".
- ''.
+ ''.
&Apache::loncommon::end_page());
}
# --------------------------------------------------------
@@ -2688,34 +3203,35 @@ sub make_script_template {
my ($priv_item, $dummy) = split(/\&/,$priv);
$role_c{$priv_item} = 1;
}
+ my %role_d;
+ @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
+ foreach my $priv(@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_d{$priv_item} = 1;
+ }
+ my %role_s;
+ @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
+ foreach my $priv(@temp) {
+ my ($priv_item, $dummy) = split(/\&/,$priv);
+ $role_s{$priv_item} = 1;
+ }
foreach my $priv_item (keys(%full_c)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
- if (exists($role_c{$priv})) {
+ if ((exists($role_c{$priv})) || (exists($role_d{$priv})) ||
+ (exists($role_s{$priv}))) {
$return_script .= "document.form1.$priv"."_c.checked = true;\n";
} else {
$return_script .= "document.form1.$priv"."_c.checked = false;\n";
}
}
- my %role_d;
- @temp = split(/:/,$Apache::lonnet::pr{$role.':d'});
- foreach my $priv(@temp) {
- my ($priv_item, $dummy) = split(/\&/,$priv);
- $role_d{$priv_item} = 1;
- }
foreach my $priv_item (keys(%full_d)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
- if (exists($role_d{$priv})) {
+ if ((exists($role_d{$priv})) || (exists($role_s{$priv}))) {
$return_script .= "document.form1.$priv"."_d.checked = true;\n";
} else {
$return_script .= "document.form1.$priv"."_d.checked = false;\n";
}
}
- my %role_s;
- @temp = split(/:/,$Apache::lonnet::pr{$role.':s'});
- foreach my $priv(@temp) {
- my ($priv_item, $dummy) = split(/\&/,$priv);
- $role_s{$priv_item} = 1;
- }
foreach my $priv_item (keys(%full_s)) {
my ($priv, $dummy) = split(/\&/,$priv_item);
if (exists($role_s{$priv})) {
@@ -2731,7 +3247,7 @@ sub make_script_template {
sub make_button_code {
my ($role) = @_;
my $label = &Apache::lonnet::plaintext($role);
- my $button_code = '';
+ my $button_code = '';
return ($button_code);
}
# ---------------------------------------------------------- Call to definerole
@@ -2841,8 +3357,11 @@ sub handler {
if ($env{'form.action'} ne 'dateselect') {
&Apache::lonhtmlcommon::add_breadcrumb
({href=>"/adm/createuser",
- text=>"User Management"});
+ text=>"User Management",
+ help=>'Course_Create_Class_List,Course_Change_Privileges,Course_View_Class_List,Course_Editing_Custom_Roles,Course_Add_Student,Course_Drop_Student,Course_Automated_Enrollment,Course_Self_Enrollment,Course_Manage_Group'});
}
+ #SD Following files not added to help, because the corresponding .tex-files seem to
+ #be missing: Course_Approve_Selfenroll,Course_User_Logs,
my ($permission,$allowed) =
&Apache::lonuserutils::get_permission($context);
if (!$allowed) {
@@ -3059,6 +3578,29 @@ sub handler {
&update_selfenroll_config($r,$context,$permission);
}
$r->print(&Apache::loncommon::end_page());
+ } elsif ($env{'form.action'} eq 'selfenrollqueue') {
+ $r->print(&header());
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=selfenrollqueue',
+ text=>"Enrollment requests"});
+ my $cid = $env{'request.course.id'};
+ my $cdom = $env{'course.'.$cid.'.domain'};
+ my $cnum = $env{'course.'.$cid.'.num'};
+ if (!exists($env{'form.state'})) {
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment requests',
+ 'Course_SelfEnrollment_Approval'));
+ $r->print(''.&mt('Pending enrollment requests').'
'."\n");
+ &display_selfenroll_queue($r,$context,$permission,$cnum,$cdom);
+ } elsif ($env{'form.state'} eq 'done') {
+ &Apache::lonhtmlcommon::add_breadcrumb
+ ({href=>'/adm/createuser?action=selfenrollqueue',
+ text=>"Result"});
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Enrollment result',
+ 'Course_Self_Enrollment'));
+ $r->print(''.&mt('Enrollment request processing').'
'."\n");
+ &update_selfenroll_queue($r,$context,$permission,$cid,$cnum,$cdom);
+ }
+ $r->print(&Apache::loncommon::end_page());
} elsif ($env{'form.action'} eq 'changelogs') {
$r->print(&header());
&Apache::lonhtmlcommon::add_breadcrumb
@@ -3124,102 +3666,137 @@ sub print_main_menu {
listusers => 'Display Co-authors and Manage Multiple Users',
},
course => {
- upload => 'Upload a File of Course Users',
- singleuser => 'Add/Modify a Single Course User',
- listusers => 'Display Class Lists and Manage Multiple Users',
+ upload => 'File of Course Users',
+ singleuser => 'Single Course User',
+ listusers => 'Course User Lists',
},
);
- my @menu =
- (
- { text => $links{$context}{'upload'},
- help => 'Course_Create_Class_List',
- action => 'upload',
- permission => $permission->{'cusr'},
- },
- { text => $links{$context}{'singleuser'},
- help => 'Course_Change_Privileges',
- action => 'singleuser',
- permission => $permission->{'cusr'},
- },
- { text => $links{$context}{'listusers'},
- help => 'Course_View_Class_List',
- action => 'listusers',
- permission => ($permission->{'view'} || $permission->{'cusr'}),
- },
- );
- if ($context eq 'domain' || $context eq 'course') {
- my $customlink = { text => 'Edit Custom Roles',
- help => 'Course_Editing_Custom_Roles',
- action => 'custom',
- permission => $permission->{'custom'},
- };
- push(@menu,$customlink);
- }
- if ($context eq 'course') {
- my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
- my @courselinks =
- (
- { text => 'Enroll a Single Student',
- help => 'Course_Add_Student',
- action => 'singlestudent',
- permission => $permission->{'cusr'},
- },
- { text => 'Drop Students',
- help => 'Course_Drop_Student',
- action => 'drop',
- permission => $permission->{'cusr'},
- });
- if (!exists($permission->{'cusr_section'})) {
- push(@courselinks,
- { 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'},
- },);
+ my @menu = ( {categorytitle => 'Add Users',
+ items =>
+ [{
+ linktext => $links{$context}{'upload'},
+ icon => 'sctr.png',
+ #help => 'Course_Create_Class_List',
+ url => '/adm/createuser?action=upload',
+ permission => $permission->{'cusr'},
+ linktitle => 'Upload a CSV or a text file containing users.',
+ },
+ {
+ linktext => $links{$context}{'singleuser'},
+ icon => 'edit-redo.png',
+ #help => 'Course_Change_Privileges',
+ url => '/adm/createuser?action=singleuser',
+ permission => $permission->{'cusr'},
+ linktitle => 'Add a user with a certain role to this course.',
+ }]},
+ {categorytitle => 'Administration',
+ items =>
+ [{
+ linktext => $links{$context}{'listusers'},
+ icon => 'edit-find.png',
+ #help => 'Course_View_Class_List',
+ url => '/adm/createuser?action=listusers',
+ permission => ($permission->{'view'} || $permission->{'cusr'}),
+ linktitle => 'Show and manage users of this course.',
+ }]},
+ {categorytitle => 'Configuration',
+ items =>
+ [
+ ]},
+ );
+
+ if ($context eq 'domain'){
+
+ push(@{ $menu[1]->{items} },
+ { linktext => 'Custom Roles',
+ icon => 'emblem-photos.png',
+ #help => 'Course_Editing_Custom_Roles',
+ url => '/adm/createuser?action=custom',
+ permission => $permission->{'custom'},
+ linktitle => 'Configure a custom role.',
+ });
+
+ }elsif ($context eq 'course'){
+ my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
+
+ push(@{ $menu[0]->{items} },
+ { linktext => 'Single Student',
+ #help => 'Course_Add_Student',
+ icon => 'list-add.png',
+ url => '/adm/createuser?action=singlestudent',
+ permission => $permission->{'cusr'},
+ linktitle => 'Add a user with the role student to this course.',
+ });
+
+ push(@{ $menu[1]->{items} },
+ { linktext => 'Drop Students',
+ icon => 'edit-undo.png',
+ #help => 'Course_Drop_Student',
+ url => '/adm/createuser?action=drop',
+ permission => $permission->{'cusr'},
+ linktitle =>'Remove a student from this course.',
+ },
+ { linktext => 'Custom Roles',
+ icon => 'emblem-photos.png',
+ #help => 'Course_Editing_Custom_Roles',
+ url => '/adm/createuser?action=custom',
+ permission => $permission->{'custom'},
+ linktitle => 'Configure a custom role.',
+ });
+ if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
+ push(@{ $menu[1]->{items} },
+ { linktext => 'Enrollment Requests',
+ icon => 'selfenrl-queue.png',
+ #help => 'Course_Approve_Selfenroll',
+ url => '/adm/createuser?action=selfenrollqueue',
+ permission => $permission->{'cusr'},
+ linktitle =>'Approve or reject enrollment requests.',
+ });
+ }
+
+ if (!exists($permission->{'cusr_section'})){
+
+ push(@{ $menu[2]->{items} },
+ { linktext => 'Automated Enrollment',
+ icon => 'roles.png',
+ #help => 'Course_Automated_Enrollment',
+ permission => (&Apache::lonnet::auto_run($cnum,$cdom)
+ && $permission->{'cusr'}),
+ url => '/adm/populate',
+ linktitle => 'Automated enrollment manager.',
+ },
+ { linktext => 'User Self-Enrollment',
+ icon => 'cstr.png',
+ #help => 'Course_Self_Enrollment',
+ url => '/adm/createuser?action=selfenroll',
+ permission => $permission->{'cusr'},
+ linktitle => 'Configure user self enrollment.',
+ });
+
+ }
+
+ push(@{ $menu[2]->{items} },
+ { linktext => 'Course Groups',
+ icon => 'conf.png',
+ #help => 'Course_Manage_Group',
+ url => '/adm/coursegroups?refpage=cusr',
+ permission => $permission->{'grp_manage'},
+ linktitle => 'Manage course groups.',
+ },
+ { linktext => 'Change Logs',
+ icon => 'document-properties.png',
+ #help => 'Course_User_Logs',
+ url => '/adm/createuser?action=changelogs',
+ permission => $permission->{'cusr'},
+ linktitle => 'View change log.',
+ });
+ };
+return Apache::lonhtmlcommon::generate_menu(@menu);
# { text => 'View Log-in History',
# help => 'Course_User_Logins',
# action => 'logins',
# permission => $permission->{'cusr'},
# });
- push(@menu,@courselinks);
- }
- my $menu_html = '';
- foreach my $menu_item (@menu) {
- next if (! $menu_item->{'permission'});
- $menu_html.='
'.$visactions->{'yous'}.
+ $output .= '
'.$visactions->{'coca'};
if (ref($vismsgs) eq 'ARRAY') {
$output .= '
'.$visactions->{'make'}.'';
@@ -3577,18 +4155,380 @@ ENDSCRIPT
''."\n".
''."\n".
''."\n";
+ } elsif ($item eq 'approval') {
+ my ($appon,$appoff);
+ my $cid = $env{'request.course.id'};
+ my $currnotified = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
+ if ($env{'course.'.$cid.'.internal.selfenroll_approval'}) {
+ $appon = ' checked="checked" ';
+ $appoff = ' ';
+ } else {
+ $appon = ' ';
+ $appoff = ' checked="checked" ';
+ }
+ $output .= ' ';
+ my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
+ my (@ccs,%notified);
+ if ($advhash{'cc'}) {
+ @ccs = split(/,/,$advhash{'cc'});
+ }
+ if ($currnotified) {
+ foreach my $current (split(/,/,$currnotified)) {
+ $notified{$current} = 1;
+ if (!grep(/^\Q$current\E$/,@ccs)) {
+ push(@ccs,$current);
+ }
+ }
+ }
+ if (@ccs) {
+ $output .= '
'.
+ ''.
+ ''.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.&mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.&Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_row();
+ my $count = 0;
+ my $numcols = 4;
+ foreach my $cc (sort(@ccs)) {
+ my $notifyon;
+ my ($ccuname,$ccudom) = split(/:/,$cc);
+ if ($notified{$cc}) {
+ $notifyon = ' checked="checked" ';
+ }
+ if ($count && !$count%$numcols) {
+ $output .= &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::start_data_table_row()
+ }
+ $output .= '';
+ $count;
+ }
+ my $rem = $count%$numcols;
+ if ($rem) {
+ my $emptycols = $numcols - $rem;
+ for (my $i=0; $i<$emptycols; $i++) {
+ $output .= ' ';
+ }
+ }
+ $output .= &Apache::loncommon::end_data_table_row().
+ &Apache::loncommon::end_data_table();
+ }
+ } elsif ($item eq 'limit') {
+ my ($crslimit,$selflimit,$nolimit);
+ my $cid = $env{'request.course.id'};
+ my $currlim = $env{'course.'.$cid.'.internal.selfenroll_limit'};
+ my $currcap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
+ my $nolimit = ' checked="checked" ';
+ if ($currlim eq 'allstudents') {
+ $crslimit = ' checked="checked" ';
+ $selflimit = ' ';
+ $nolimit = ' ';
+ } elsif ($currlim eq 'selfenrolled') {
+ $crslimit = ' ';
+ $selflimit = ' checked="checked" ';
+ $nolimit = ' ';
+ } else {
+ $crslimit = ' ';
+ $selflimit = ' ';
+ }
+ $output .= '
';
}
$output .= &Apache::lonhtmlcommon::row_closure(1);
}
}
$output .= &Apache::lonhtmlcommon::end_pick_box().
''.
+ ' '.
+ (' 'x3).&mt('Maximum number allowed: ').
+ '
'
+ .&mt('Save').'" onclick="validate_types(this.form);" />'
.'';
$r->print($output);
return;
}
+sub display_selfenroll_queue {
+ my ($r,$context,$permission,$cnum,$cdom) = @_;
+ my $namespace = 'selfenrollrequests';
+ my ($output,%queue_by_date);
+ my %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
+ if (keys(%requesthash) > 0) {
+ $r->print(''.&mt('Action').' '.
+ ''.&mt('Requestor').' '.
+ ''.&mt('Section').' '.
+ ''.&mt('Date requested').' '.
+ &Apache::loncommon::end_data_table_header_row());
+ foreach my $item (keys(%requesthash)) {
+ my ($timestamp,$usec) = split(/:/,$requesthash{$item});
+ if (exists($queue_by_date{$timestamp})) {
+ if (ref($queue_by_date{$timestamp}) eq 'ARRAY') {
+ push(@{$queue_by_date{$timestamp}},$item.':'.$usec);
+ }
+ } else {
+ @{$queue_by_date{$timestamp}} = ($item.':'.$usec);
+ }
+ }
+ my @sortedtimes = sort {$a <=> $b} (keys(%queue_by_date));
+ my $count = 0;
+ foreach my $item (@sortedtimes) {
+ if (ref($queue_by_date{$item}) eq 'ARRAY') {
+ foreach my $request (sort(@{$queue_by_date{$item}})) {
+ my ($puname,$pudom,$pusec) = split(/:/,$request);
+ my $showsec = $pusec;
+ if ($showsec eq '') {
+ $showsec = &mt('none');
+ }
+ my $namelink = &Apache::loncommon::aboutmewrapper(
+ &Apache::loncommon::plainname($puname,$pudom),
+ $puname,$pudom);
+ $r->print(&Apache::loncommon::start_data_table_row().
+ ' '.
+ '
'.
+ ''.$namelink.' '.
+ ''.$showsec.' '.
+ ''.&Apache::lonlocal::locallocaltime($item).' '.
+ &Apache::loncommon::end_data_table_row());
+ $count ++;
+ }
+ }
+ }
+ $r->print(&Apache::loncommon::end_data_table().
+ '');
+ } else {
+ $r->print(&mt('There are currently no enrollment requests.'));
+ }
+ return;
+}
+
+sub update_selfenroll_queue {
+ my ($r,$context,$permission,$cid,$cnum,$cdom) = @_;
+ my @approvals = &Apache::loncommon::get_env_multiple('form.approvereq');
+ my @rejections = &Apache::loncommon::get_env_multiple('form.rejectreq');
+ my $access_start = $env{'course.'.$cid.'.internal.selfenroll_start_access'};
+ my $access_end = $env{'course.'.$cid.'.internal.selfenroll_end_access'};
+ my $limit = $env{'course.'.$cid.'.internal.selfenroll_limit'};
+ my $cap = $env{'course.'.$cid.'.internal.selfenroll_cap'};
+ my $notifylist = $env{'course.'.$cid.'.internal.selfenroll_notifylist'};
+ my $namespace = 'selfenrollrequests';
+ my ($stucounts,$idx,$classlist) = &get_student_counts($cdom,$cnum);
+ my %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
+ my $coursedesc = $env{'course.'.$cid.'.description'};
+ my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
+ my $hostname = &Apache::lonnet::hostname($chome);
+ my $protocol = $Apache::lonnet::protocol{$chome};
+ $protocol = 'http' if ($protocol ne 'https');
+ my (@existing,@missingreq,@invalidusers,@limitexceeded,@enrolled,
+ @enrollerrors,@warn_approves,@warn_rejects);
+ my $now = time;
+ my $sender = $env{'user.name'}.':'.$env{'user.domain'};
+ my $approvedmsg = [{
+ mt => 'Your request for enrollment has been approved.',
+ },
+ {
+ mt => 'Visit [_1], to log-in and access the course',
+ args => [$protocol.'://'.$hostname],
+ }];
+
+ my $rejectedmsg = [{
+ mt => 'Your request for enrollment has not been approved.',
+ }];
+ foreach my $item (sort {$a <=> $b} @approvals) {
+ my ($num,$uname,$udom,$usec) = split(/:/,$item);
+ my $uhome = &Apache::lonnet::homeserver($uname,$udom);
+ if ($uhome ne 'no_host') {
+ if (exists($requesthash{$uname.':'.$udom})) {
+
+ if (exists($classlist->{$uname.':'.$udom})) {
+ if (ref($classlist->{$uname.':'.$udom}) eq 'ARRAY') {
+ if (($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Active') ||
+ ($classlist->{$uname.':'.$udom}->[$idx->{'status'}] eq 'Future')) {
+ push(@existing,$uname.':'.$udom);
+ next;
+ }
+ }
+ }
+ } else {
+ push(@missingreq,$uname.':'.$udom);
+ next;
+ }
+ if (!grep(/^\Q$item\E$/,@rejections)) {
+ if ($limit eq 'allstudents') {
+ if ($stucounts->{$limit} >= $cap) {
+ push(@limitexceeded,$uname.':'.$udom);
+ last;
+ }
+ } elsif ($limit eq 'selfenrolled') {
+ if ($stucounts->{$limit} >= $cap) {
+ push(@limitexceeded,$uname.':'.$udom);
+ last;
+ }
+ }
+ my $result =
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$usec,$access_end,$access_start,'selfenroll',undef,$cdom.'_'.$cnum,1);
+ if ($result eq 'ok') {
+ push(@enrolled,$uname.':'.$udom);
+ $stucounts->{'allstudents'} ++;
+ $stucounts->{'selfenrolled'} ++;
+ &Apache::selfenroll::send_notification($uname.':'.$udom,$approvedmsg,$cid,
+ $coursedesc,$now,'enroller',$sender);
+ my %userrequest = (
+ $cdom.'_'.$cnum => {
+ timestamp => $now,
+ section => $usec,
+ adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
+ status => 'approved',
+ }
+ );
+ my $userresult =
+ &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
+ if ($userresult ne 'ok') {
+ push(@warn_approves,$uname.':'.$udom);
+ }
+ } else {
+ push(@enrollerrors,$uname.':'.$udom);
+ }
+ }
+ } else {
+ push(@invalidusers,$uname.':'.$udom);
+ }
+ }
+ my @changes = (@enrolled,@rejections);
+ if (@rejections) {
+ foreach my $user (@rejections) {
+ &Apache::selfenroll::send_notification($user,$rejectedmsg,$cid,
+ $coursedesc,$now,'enroller',$sender);
+ my ($uname,$udom) = split(/:/,$user);
+ my %userrequest = (
+ $cdom.'_'.$cnum => {
+ timestamp => $now,
+ adjudicator => $env{'user.name'}.':'.$env{'user.domain'},
+ status => 'rejected',
+ }
+ );
+ my $userresult =
+ &Apache::lonnet::put($namespace,\%userrequest,$udom,$uname);
+ if ($userresult ne 'ok') {
+ push(@warn_rejects,$user);
+ }
+ }
+ }
+ if (@changes) {
+ my $delresult = &Apache::lonnet::del($namespace,\@changes,$cdom,$cnum);
+ if ($delresult eq 'ok') {
+ my $namelink =
+ &Apache::loncommon::plainname($env{'user.name'},$env{'user.domain'}).' ('.$env{'user.name'}.':'.$env{'user.domain'}.')';
+ my $chgmsg = "'Action was taken on the following enrollment requests by [_1].',$namelink";
+ my ($approvedlist,$rejectedlist);
+ if (@enrolled) {
+ $approvedlist = join("\n",@enrolled);
+ $r->print('');
+ foreach my $user (@enrolled) {
+ my ($uname,$udom) = split(/:/,$user);
+ my $userlink =
+ &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom);
+ $r->print('
'.&mt('The following enrollment requests were rejected:').'
'.&mt('The following enrollment requests were deleted because the user is already enrolled in the course:').'
'.&mt('The following enrollment requests were ignored because the request is no longer in the enrollment queue:').'
'.&mt('The following enrollment requests were deleted because the requestor does not have a LON-CAPA account:').'
'.&mt('The following enrollment requests were skipped because the enrollment limit has been reached for the course:').'
'.&mt('The following enrollment requests could not be processed because an error occurred:').'
'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'
'.&mt("For the following users, an error occurred when updating the user's own self-enroll requests record:").'