--- loncom/interface/lonuserutils.pm 2007/12/05 21:23:14 1.11
+++ loncom/interface/lonuserutils.pm 2010/09/20 00:10:29 1.124
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.11 2007/12/05 21:23:14 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.124 2010/09/20 00:10:29 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,12 +42,11 @@ use LONCAPA qw(:DEFAULT :match);
###############################################################
# Drop student from all sections of a course, except optional $csec
sub modifystudent {
- my ($udom,$unam,$courseid,$csec,$desiredhost)=@_;
+ my ($udom,$unam,$courseid,$csec,$desiredhost,$context)=@_;
# if $csec is undefined, drop the student from all the courses matching
# this one. If $csec is defined, drop them from all other sections of
# this course and add them to section $csec
- my $cdom = $env{'course.'.$courseid.'.domain'};
- my $cnum = $env{'course.'.$courseid.'.num'};
+ my ($cnum,$cdom) = &get_course_identity($courseid);
my %roles = &Apache::lonnet::dump('roles',$udom,$unam);
my ($tmp) = keys(%roles);
# Bail out if we were unable to get the students roles
@@ -69,14 +68,15 @@ sub modifystudent {
my $reply=&Apache::lonnet::modifystudent
# dom name id mode pass f m l g
($udom,$unam,'', '', '',undef,undef,undef,undef,
- $section,time,undef,undef,$desiredhost);
+ $section,time,undef,undef,$desiredhost,'','manual',
+ '',$courseid,'',$context);
$result .= $reply.':';
}
}
}
}
if ($result eq '') {
- $result = 'Unable to find section for this student';
+ $result = &mt('Unable to find section for this student');
} else {
$result =~ s/(ok:)+/ok/g;
}
@@ -86,17 +86,17 @@ sub modifystudent {
sub modifyuserrole {
my ($context,$setting,$changeauth,$cid,$udom,$uname,$uid,$umode,$upass,
$first,$middle,$last,$gene,$sec,$forceid,$desiredhome,$email,$role,
- $end,$start,$checkid) = @_;
+ $end,$start,$checkid,$inststatus) = @_;
my ($scope,$userresult,$authresult,$roleresult,$idresult);
if ($setting eq 'course' || $context eq 'course') {
$scope = '/'.$cid;
$scope =~ s/\_/\//g;
- if ($role ne 'cc' && $sec ne '') {
+ if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
$scope .='/'.$sec;
}
} elsif ($context eq 'domain') {
$scope = '/'.$env{'request.role.domain'}.'/';
- } elsif ($context eq 'construction_space') {
+ } elsif ($context eq 'author') {
$scope = '/'.$env{'user.domain'}.'/'.$env{'user.name'};
}
if ($context eq 'domain') {
@@ -124,11 +124,13 @@ sub modifyuserrole {
$userresult =
&Apache::lonnet::modifyuser($udom,$uname,$uid,$umode,$upass,$first,
$middle,$last,$gene,$forceid,$desiredhome,
- $email,$role,$start,$end);
+ $email,$inststatus);
if ($userresult eq 'ok') {
if ($role ne '') {
+ $role =~ s/_/\//g;
$roleresult = &Apache::lonnet::assignrole($udom,$uname,$scope,
- $role,$end,$start);
+ $role,$end,$start,'',
+ '',$context);
}
}
return ($userresult,$authresult,$roleresult,$idresult);
@@ -136,22 +138,30 @@ sub modifyuserrole {
sub propagate_id_change {
my ($uname,$udom,$user) = @_;
- my (@types,@roles,@cdoms);
+ my (@types,@roles);
@types = ('active','future');
@roles = ('st');
my $idresult;
my %roleshash = &Apache::lonnet::get_my_roles($uname,
- $udom,'userroles',\@types,\@roles,\@cdoms);
+ $udom,'userroles',\@types,\@roles);
+ my %args = (
+ one_time => 1,
+ );
foreach my $item (keys(%roleshash)) {
- my ($cnum,$cdom,$role) = split(/:/,$item);
+ my ($cnum,$cdom,$role) = split(/:/,$item,-1);
my ($start,$end) = split(/:/,$roleshash{$item});
if (&Apache::lonnet::is_course($cdom,$cnum)) {
- my %userupdate;
- my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%userupdate);
+ my $result = &update_classlist($cdom,$cnum,$udom,$uname,$user);
+ my %coursehash =
+ &Apache::lonnet::coursedescription($cdom.'_'.$cnum,\%args);
+ my $cdesc = $coursehash{'description'};
+ if ($cdesc eq '') {
+ $cdesc = $cdom.'_'.$cnum;
+ }
if ($result eq 'ok') {
- $idresult .= "Classlist change: $uname:$udom - class -> $cnum:$cdom\n";
+ $idresult .= &mt('Classlist update for "[_1]" in "[_2]".',$uname.':'.$udom,$cdesc).'
'."\n";
} else {
- $idresult .= "Error - $result -during classlist update for $uname:$udom in $cnum:$cdom\n";
+ $idresult .= &mt('Error: "[_1]" during classlist update for "[_2]" in "[_3]".',$result,$uname.':'.$udom,$cdesc).'
'."\n";
}
}
}
@@ -159,7 +169,7 @@ sub propagate_id_change {
}
sub update_classlist {
- my ($cdom,$cnum,$udom,$uname,$user) = @_;
+ my ($cdom,$cnum,$udom,$uname,$user,$newend) = @_;
my ($uid,$classlistentry);
my $fullname =
&Apache::lonnet::format_name($user->{'firstname'},$user->{'middlename'},
@@ -170,15 +180,37 @@ sub update_classlist {
my @classinfo = split(/:/,$classhash{$uname.':'.$udom});
my $ididx=&Apache::loncoursedata::CL_ID() - 2;
my $nameidx=&Apache::loncoursedata::CL_FULLNAME() - 2;
+ my $endidx = &Apache::loncoursedata::CL_END() - 2;
+ my $startidx = &Apache::loncoursedata::CL_START() - 2;
for (my $i=0; $i<@classinfo; $i++) {
- if ($i == $ididx) {
+ if ($i == $endidx) {
+ if ($newend ne '') {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $startidx) {
+ if ($newend ne '') {
+ if ($classinfo[$i] > $newend) {
+ $classlistentry .= $newend.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
+ } elsif ($i == $ididx) {
if (defined($user->{'id'})) {
$classlistentry .= $user->{'id'}.':';
} else {
$classlistentry .= $classinfo[$i].':';
}
} elsif ($i == $nameidx) {
- $classlistentry .= $fullname.':';
+ if (defined($user->{'lastname'})) {
+ $classlistentry .= $fullname.':';
+ } else {
+ $classlistentry .= $classinfo[$i].':';
+ }
} else {
$classlistentry .= $classinfo[$i].':';
}
@@ -203,7 +235,7 @@ sub domain_roles_select {
# domain context
#
# Role types
- my @roletypes = ('domain','construction_space','course');
+ my @roletypes = ('domain','author','course','community');
my %lt = &role_type_names();
#
# build up the menu information to be passed to
@@ -215,6 +247,10 @@ sub domain_roles_select {
foreach my $roletype (@roletypes) {
# set up the text for this domain
$select_menus{$roletype}->{'text'}= $lt{$roletype};
+ my $crstype;
+ if ($roletype eq 'community') {
+ $crstype = 'Community';
+ }
# we want a choice of 'default' as the default in the second menu
if ($env{'form.roletype'} ne '') {
$select_menus{$roletype}->{'default'} = $env{'form.showrole'};
@@ -225,11 +261,11 @@ sub domain_roles_select {
my @roles;
if ($roletype eq 'domain') {
@roles = &domain_roles();
- } elsif ($roletype eq 'construction_space') {
+ } elsif ($roletype eq 'author') {
@roles = &construction_space_roles();
} else {
- @roles = &course_roles('domain');
- unshift(@roles,'cr');
+ my $custom = 1;
+ @roles = &course_roles('domain',undef,$custom,$roletype);
}
my $order = ['Any',@roles];
$select_menus{$roletype}->{'order'} = $order;
@@ -239,14 +275,15 @@ sub domain_roles_select {
&mt('Custom role');
} else {
$select_menus{$roletype}->{'select2'}->{$role} =
- &Apache::lonnet::plaintext($role);
+ &Apache::lonnet::plaintext($role,$crstype);
}
}
$select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
}
my $result = &Apache::loncommon::linked_select_forms
('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
- 'roletype','showrole',\%select_menus,['domain','construction_space','course']);
+ 'roletype','showrole',\%select_menus,
+ ['domain','author','course','community']);
return $result;
}
@@ -258,7 +295,8 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
+ $can_assign)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -272,9 +310,9 @@ sub print_upload_manager_header {
}
}
if ($env{'form.upfile_associate'} eq 'reverse') {
- $javascript=&upload_manager_javascript_reverse_associate();
+ $javascript=&upload_manager_javascript_reverse_associate($can_assign);
} else {
- $javascript=&upload_manager_javascript_forward_associate();
+ $javascript=&upload_manager_javascript_forward_associate($can_assign);
}
#
# Deal with restored settings
@@ -288,12 +326,19 @@ sub print_upload_manager_header {
$password_choice = 'int';
}
#
+ my $groupslist;
+ if ($context eq 'course') {
+ $groupslist = &get_groupslist();
+ }
my $javascript_validations =
- &javascript_validations('auth',$krbdefdom,$password_choice,undef,
- $env{'request.role.domain'});
- my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
- $r->print(&mt('Total number of records found in file: [_1].',$distotal).
- "
\n");
+ &javascript_validations('upload',$krbdefdom,$password_choice,undef,
+ $env{'request.role.domain'},$context,
+ $groupslist,$crstype);
+ my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
+ $r->print('
' + .&mt('Total number of records found in file: [_1]' + ,''.$distotal.'') + ."
\n"); $r->print(''.&mt('Change authentication for existing users to these settings?').'
'; + $Str .= '' + .&mt('Change authentication for existing users in domain "[_1]" to these settings?' + ,$defdom) + .' ' + .' ' + .'
'; } else { - $Str .= "\n". - &mt('Note: this will not take effect if the user already exists'). + $Str .= '
'."\n". + &mt('This will not take effect if the user already exists.'). &Apache::loncommon::help_open_topic('Auth_Options'). "
\n"; } $Str .= &set_login($defdom,$krbform,$intform,$locform); + my ($home_server_pick,$numlib) = &Apache::loncommon::home_server_form_item($defdom,'lcserver', 'default','hide'); if ($numlib > 1) { - $Str .= '\n".$date_table."
\n"; - if ($context eq 'domain') { - $Str .= '\n".$date_table."
\n" + .&Apache::lonhtmlcommon::row_closure(); + if ($context eq 'domain') { - $Str .= ''.&mt('Domain Level').''.&mt('role').': '. - $options.' | '. - ''.&mt('section').': |
'
+ .''.&mt('Domain Level').'
'
+ .$options
+ .'
' + .''.&mt('Course Level').'' + .'
' + .$cb_script.$coursepick + .&Apache::lonhtmlcommon::row_closure(); + } elsif ($context eq 'author') { + $Str .= $options + .&Apache::lonhtmlcommon::row_closure(1); # last row in pick_box + } + } else { + my ($cnum,$cdom) = &get_course_identity(); + my $rowtitle = &mt('section'); + my $secbox = §ion_picker($cdom,$cnum,'Any',$rowtitle, + $permission,$context,'upload',$crstype); + $Str .= $secbox + .&Apache::lonhtmlcommon::row_closure(); + my %lt; + if ($crstype eq 'Community') { + %lt = &Apache::lonlocal::texthash ( + disp => 'Display members with current/future access who are not in the uploaded file', + stus => 'Members selected from this list can be dropped.' + ); + } else { + %lt = &Apache::lonlocal::texthash ( + disp => 'Display students with current/future access who are not in the uploaded file', + stus => 'Students selected from this list can be dropped.' + ); + } + $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update')) + .'\n".'
'."\n".
- &mt('(only do if you know what you are doing.)')."
\n";
+ &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
+ .'
'."\n"
+ .&mt('(only do if you know what you are doing.)')."\n";
if ($context eq 'domain') {
- $output .= '
' + .&list_submit_button(&mt('Update Display')) + ."
\n" + ); } my ($indexhash,$keylist) = &make_keylist_array(); - my (%userlist,%userinfo); - if ($context eq 'domain' && $env{'form.roletype'} eq 'course') { + my (%userlist,%userinfo,$clearcoursepick); + if (($context eq 'domain') && + ($env{'form.roletype'} eq 'course') || + ($env{'form.roletype'} eq 'community')) { + my ($crstype,$numcodes,$title,$warning); + if ($env{'form.roletype'} eq 'course') { + $crstype = 'Course'; + $numcodes = $totcodes; + $title = &mt('Select Courses'); + $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.'); + } elsif ($env{'form.roletype'} eq 'community') { + $crstype = 'Community'; + $numcodes = 0; + $title = &mt('Select Communities'); + $warning = &mt('Warning: data retrieval for multiple communities can take considerable time, as this operation is not currently optimized.'); + } + my @standardnames = &Apache::loncommon::get_standard_codeitems(); my $courseform = - &Apache::lonhtmlcommon::course_selection($formname,$totcodes, - $codetitles,$idlist,$idlist_titles); + &Apache::lonhtmlcommon::course_selection($formname,$numcodes, + $codetitles,$idlist,$idlist_titles,$crstype, + \@standardnames); $r->print(''.&Apache::lonhtmlcommon::start_pick_box()."\n". &Apache::lonhtmlcommon::start_pick_box()."\n". - &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'), - 'LC_oddrow_value')."\n". + &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n". $courseform."\n". &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::end_pick_box().'
'. - ''.&list_submit_button(&mt('Update Display')). - "\n
\n"); - if ($env{'form.coursepick'}) { + ''. + &list_submit_button(&mt('Update Display')). + "\n".'
'.$warning.''."\n"); + $clearcoursepick = 0; + if (($env{'form.origroletype'} ne '') && + ($env{'form.origroletype'} ne $env{'form.roletype'})) { + $clearcoursepick = 1; + } + if (($env{'form.coursepick'}) && (!$clearcoursepick)) { $r->print('';
- my @linkdests = ('aboutme');
- if ($permission->{'cusr'}) {
- push (@linkdests,'modify');
- $output .= ''.$lt{'link'}.': ';
- my $usernamelink = $env{'form.usernamelink'};
- if ($usernamelink eq '') {
- $usernamelink = 'aboutme';
- }
- foreach my $item (@linkdests) {
- my $checkedstr = '';
- if ($item eq $usernamelink) {
- $checkedstr = ' checked="checked" ';
- }
- $output .= ' ';
- }
- $output .= '
';
- } else {
- $output .= &mt("Click on a username to view the user's personal page.").'
';
- }
- if ($actionselect) {
- $output .= <<"END";
-$lt{'ac'}: $actionselect
- + if ($actionselect) { + $output .= <<"END"; +
END - } + my @allroles; + if ($env{'form.showrole'} eq 'Any') { + my $custom = 1; + if ($context eq 'domain') { + @allroles = &roles_by_context($setting,$custom,$crstype); + } else { + @allroles = &roles_by_context($context,$custom,$crstype); + } + } else { + @allroles = ($env{'form.showrole'}); + } + foreach my $role (@allroles) { + if ($context eq 'domain') { + if ($setting eq 'domain') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'request.role.domain'})) { + $canchange{$role} = 1; + } + } elsif ($setting eq 'author') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'request.role.domain'})) { + $canchange{$role} = 1; + } + } + } elsif ($context eq 'author') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'user.domain'}.'/'.$env{'user.name'})) { + $canchange{$role} = 1; + } + } elsif ($context eq 'course') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) { + $canchange{$role} = 1; + } elsif ($env{'request.course.sec'} ne '') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) { + $canchangesec{$role} = $env{'request.course.sec'}; + } + } + } + } + } + $output .= ''; } - $output .= "\n\n". + $output .= "\n".'
'."\n". &Apache::loncommon::start_data_table(). &Apache::loncommon::start_data_table_header_row(); if ($mode eq 'autoenroll') { $output .= " -' + .&mt('Problems occurred in writing the CSV file.') + .' '.&mt('This error has been logged.') + .' '.&mt('Please alert your LON-CAPA administrator.') + .'
' + ); $CSVfile = undef; } # + push @cols,'clicker'; # Write headers and data to file print $CSVfile '"'.$results_description.'"'."\n"; print $CSVfile '"'.join('","',map { &Apache::loncommon::csv_translate($lt{$_}) - } (@cols)).'"'."\n"; + } (@cols))."\"\n"; } elsif ($mode eq 'excel') { + push @cols,'clicker'; # Create the excel spreadsheet ($excel_workbook,$excel_filename,$format) = &Apache::loncommon::create_workbook($r); @@ -2033,20 +2531,40 @@ END $excel_sheet->write($row++,0,$results_description,$format->{'h2'}); # my @colnames = map {$lt{$_}} (@cols); + $excel_sheet->write($row++,0,\@colnames,$format->{'bold'}); } # Done with header lines in all formats - my %index; my $i; foreach my $idx (@$keylist) { $index{$idx} = $i++; } my $usercount = 0; + my ($secfilter,$grpfilter); + if ($context eq 'course') { + $secfilter = $env{'form.secfilter'}; + $grpfilter = $env{'form.grpfilter'}; + if ($secfilter eq '') { + $secfilter = 'all'; + } + if ($grpfilter eq '') { + $grpfilter = 'all'; + } + } + my %ltstatus = &Apache::lonlocal::texthash( + Active => 'Active', + Future => 'Future', + Expired => 'Expired', + ); # Get groups, role, permanent e-mail so we can sort on them if # necessary. foreach my $user (keys(%{$userlist})) { + if ($user eq '' ) { + delete($userlist->{$user}); + next; + } if ($context eq 'domain' && $user eq $env{'request.role.domain'}.'-domainconfig:'.$env{'request.role.domain'}) { delete($userlist->{$user}); next; @@ -2065,9 +2583,10 @@ END delete($userlist->{$user}); next; } - } elsif ($env{'form.roletype'} eq 'construction_space') { + } elsif ($env{'form.roletype'} eq 'author') { ($uname,$udom,$role) = split(/:/,$user,-1); - } elsif ($env{'form.roletype'} eq 'course') { + } elsif (($env{'form.roletype'} eq 'course') || + ($env{'form.roletype'} eq 'community')) { ($uname,$udom,$role) = split(/:/,$user); } } else { @@ -2081,11 +2600,56 @@ END delete($userlist->{$user}); next; } - if (ref($classgroups) eq 'HASH') { - $groups = $classgroups->{$user}; - } - if (ref($groups->{active}) eq 'HASH') { - $userlist->{$user}->[$index{'groups'}] = join(', ',keys(%{$groups->{'active'}})); + if ($context eq 'course') { + my @ac_groups; + if (ref($classgroups) eq 'HASH') { + $groups = $classgroups->{$user}; + } + if (ref($groups->{'active'}) eq 'HASH') { + @ac_groups = keys(%{$groups->{'active'}}); + $userlist->{$user}->[$index{'groups'}] = join(', ',@ac_groups); + } + if ($mode ne 'autoenroll') { + my $section = $userlist->{$user}->[$index{'section'}]; + if (($env{'request.course.sec'} ne '') && + ($section ne $env{'request.course.sec'})) { + if ($role eq 'st') { + delete($userlist->{$user}); + next; + } + } + if ($secfilter eq 'none') { + if ($section ne '') { + delete($userlist->{$user}); + next; + } + } elsif ($secfilter ne 'all') { + if ($section ne $secfilter) { + delete($userlist->{$user}); + next; + } + } + if ($grpfilter eq 'none') { + if (@ac_groups > 0) { + delete($userlist->{$user}); + next; + } + } elsif ($grpfilter ne 'all') { + if (!grep(/^\Q$grpfilter\E$/,@ac_groups)) { + delete($userlist->{$user}); + next; + } + } + if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) { + if (($displayphotos eq 'on') && ($role eq 'st')) { + $userlist->{$user}->[$index{'photo'}] = + &Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg'); + $userlist->{$user}->[$index{'thumbnail'}] = + &Apache::lonnet::retrievestudentphoto($udom,$uname, + 'gif','thumbnail'); + } + } + } } my %emails = &Apache::loncommon::getemails($uname,$udom); if ($emails{'permanentemail'} =~ /\S/) { @@ -2125,8 +2689,11 @@ END foreach my $item (@{$keylist}) { $in{$item} = $sdata->[$index{$item}]; } - my $role = $in{'role'}; - $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]); + my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1]; + if ($clickers!~/\w/) { $clickers='-'; } + $in{'clicker'} = $clickers; + my $role = $in{'role'}; + $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype); if (! defined($in{'start'}) || $in{'start'} == 0) { $in{'start'} = &mt('none'); } else { @@ -2137,34 +2704,84 @@ END } else { $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'}); } - if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') { + if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') { $r->print(&Apache::loncommon::start_data_table_row()); - $r->print("'.&mt('manual').' | |
'; + $manualcount ++; + if ($in{'lockedtype'}) { + $cellentry .= ''; + $unlockcount ++; + } else { + $cellentry .= ''; + $lockcount ++; } - $checkval .= ':'.$in{'section'}; - if ($role eq 'st') { - $checkval .= ':'.$in{'type'}.':'.$in{'lockedtype'}; + $cellentry .= ' |
'. - &mt('Your Excel spreadsheet').' '.&mt('is ready for download').'.
'."\n"); + $r->print(&mt('[_1]Your Excel spreadsheet[_2] is ready for download.', '','')."
\n"); } elsif ($mode eq 'csv') { close($CSVfile); - $r->print(''. - &mt('Your CSV file').' is ready for download.'. - "\n"); + $r->print(&mt('[_1]Your CSV file[_2] is ready for download.', '','')."
\n"); $r->rflush(); } if ($mode eq 'autoenroll') { @@ -2243,16 +2854,133 @@ END } } +sub bulkaction_javascript { + my ($formname,$caller) = @_; + my $docstart = 'document'; + if ($caller eq 'popup') { + $docstart = 'opener.document'; + } + my %lt = &Apache::lonlocal::texthash( + acwi => 'Access will be set to start immediately', + asyo => 'as you did not select an end date in the pop-up window', + accw => 'Access will be set to continue indefinitely', + asyd => 'as you did not select an end date in the pop-up window', + sewi => "Sections will be switched to 'No section'", + ayes => "as you either selected the 'No section' option", + oryo => 'or you did not select a section in the pop-up window', + arol => 'A role with no section will be added', + swbs => 'Sections will be switched to:', + rwba => 'Roles will be added for section(s):', + ); + my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox"); + my $noaction = &mt("You need to select an action to take for the user(s) you have selected"); + my $singconfirm = &mt(' for a single user?'); + my $multconfirm = &mt(' for multiple users?'); + my $output = <<"ENDJS"; +function verify_action (field) { + var numchecked = 0; + var singconf = '$singconfirm'; + var multconf = '$multconfirm'; + if ($docstart.$formname.elements[field].length > 0) { + for (i=0; i<$docstart.$formname.elements[field].length; i++) { + if ($docstart.$formname.elements[field][i].checked == true) { + numchecked ++; + } + } + } else { + if ($docstart.$formname.elements[field].checked == true) { + numchecked ++; + } + } + if (numchecked == 0) { + alert("$alert"); + return; + } else { + var message = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].text; + var choice = $docstart.$formname.bulkaction[$docstart.$formname.bulkaction.selectedIndex].value; + if (choice == '') { + alert("$noaction"); + return; + } else { + if (numchecked == 1) { + message += singconf; + } else { + message += multconf; + } +ENDJS + if ($caller ne 'popup') { + $output .= <<"NEWWIN"; + if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate' || choice == 'chgsec') { + opendatebrowser(document.$formname,'$formname','go'); + return; + + } else { + if (confirm(message)) { + document.$formname.phase.value = 'bulkchange'; + document.$formname.submit(); + return; + } + } +NEWWIN + } else { + $output .= <<"POPUP"; + if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') { + var datemsg = ''; + if (($docstart.$formname.startdate_month.value == '') && + ($docstart.$formname.startdate_day.value == '') && + ($docstart.$formname.startdate_year.value == '')) { + datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n"; + } + if (($docstart.$formname.enddate_month.value == '') && + ($docstart.$formname.enddate_day.value == '') && + ($docstart.$formname.enddate_year.value == '')) { + datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n"; + } + if (datemsg != '') { + message += "\\n"+datemsg; + } + } + if (choice == 'chgsec') { + var rolefilter = $docstart.$formname.showrole.options[$docstart.$formname.showrole.selectedIndex].value; + var retained = $docstart.$formname.retainsec.value; + var secshow = $docstart.$formname.newsecs.value; + if (secshow == '') { + if (rolefilter == 'st' || retained == 0 || retained == "") { + message += "\\n\\n$lt{'sewi'},\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; + } else { + message += "\\n\\n$lt{'arol'}\\n$lt{'ayes'},\\n$lt{'oryo'}.\\n"; + } + } else { + if (rolefilter == 'st' || retained == 0 || retained == "") { + message += "\\n\\n$lt{'swbs'} "+secshow+".\\n"; + } else { + message += "\\n\\n$lt{'rwba'} "+secshow+".\\n"; + } + } + } + if (confirm(message)) { + $docstart.$formname.phase.value = 'bulkchange'; + $docstart.$formname.submit(); + window.close(); + } +POPUP + } + $output .= ' + } + } +} +'; + return $output; +} + sub print_username_link { - my ($permission,$in) = @_; + my ($mode,$in) = @_; my $output; - if (!$permission->{'cusr'}) { - $output = &Apache::loncommon::aboutmewrapper($in->{'username'}, - $in->{'username'}, - $in->{'domain'}); + if ($mode eq 'autoenroll') { + $output = $in->{'username'}; } else { $output = '{'username'}','$in->{'domain'}'".')" />'. + "'$in->{'username'}','$in->{'domain'}'".')">'. $in->{'username'}.''; } return $output; @@ -2260,15 +2988,16 @@ sub print_username_link { sub role_type_names { my %lt = &Apache::lonlocal::texthash ( - 'domain' => 'Domain Roles', - 'construction_space' => 'Co-Author Roles', - 'course' => 'Course Roles', + 'domain' => 'Domain Roles', + 'author' => 'Co-Author Roles', + 'course' => 'Course Roles', + 'community' => 'Community Roles', ); return %lt; } sub select_actions { - my ($context,$setting,$statusmode) = @_; + my ($context,$setting,$statusmode,$formname) = @_; my %lt = &Apache::lonlocal::texthash( revoke => "Revoke user roles", delete => "Delete user roles", @@ -2278,15 +3007,29 @@ sub select_actions { chgsec => "Change section associated with user roles", ); my ($output,$options,%choices); + # FIXME Disable actions for now for roletype=course in domain context + if ($context eq 'domain' && $setting eq 'course') { + return; + } + if ($context eq 'course') { + if ($env{'form.showrole'} ne 'Any') { + if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'}, + $env{'request.course.id'})) { + if ($env{'request.course.sec'} eq '') { + return; + } else { + if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) { + return; + } + } + } + } + } if ($statusmode eq 'Any') { $options .= ' '; $choices{'dates'} = 1; } else { - if ($statusmode eq 'Active' || $statusmode eq 'Future') { - $options .= ' -'; - } if ($statusmode eq 'Future') { $options .= ' '; @@ -2296,20 +3039,26 @@ sub select_actions { '; $choices{'dates'} = 1; } + if ($statusmode eq 'Active' || $statusmode eq 'Future') { + $options .= ' + +'; + $choices{'dates'} = 1; + } } if ($context eq 'domain') { $options .= ' '; } if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) { - if ($statusmode ne 'Expired') { + if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) { $options .= ' '; $choices{'sections'} = 1; } } if ($options) { - $output = ''.&mt('Existing sections')."\n".
+ ' '.$sections_select.' | '.
+ &mt('New section').' '."\n". + ''."\n". + ''."\n". + ' |
-
+
END
-
-my %lt=&Apache::lonlocal::texthash('usrn' => "username",
- 'dom' => "domain",
- 'sn' => "student name",
- 'sec' => "section",
- 'start' => "start date",
- 'end' => "end date",
- 'groups' => "active groups",
- );
+ my ($indexhash,$keylist) = &make_keylist_array();
+ my $studentcount = 0;
+ if (ref($classlist) eq 'HASH') {
+ foreach my $student (keys(%{$classlist})) {
+ my $sdata = $classlist->{$student};
+ my $status = $sdata->[$indexhash->{'status'}];
+ my $section = $sdata->[$indexhash->{'section'}];
+ if ($status ne 'Active') {
+ delete($classlist->{$student});
+ next;
+ }
+ if ($env{'request.course.sec'} ne '') {
+ if ($section ne $env{'request.course.sec'}) {
+ delete($classlist->{$student});
+ next;
+ }
+ }
+ $studentcount ++;
+ }
+ }
+ if (!$studentcount) {
+ if ($crstype eq 'Community') {
+ $r->print(&mt('There are no members to drop.'));
+ } else {
+ $r->print(&mt('There are no students to drop.'));
+ }
+ return;
+ }
+ my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
+ $classlist,$keylist,$cdom,$cnum);
+ my %lt=&Apache::lonlocal::texthash('usrn' => "username",
+ 'dom' => "domain",
+ 'sn' => "student name",
+ 'mn' => "member name",
+ 'sec' => "section",
+ 'start' => "start date",
+ 'end' => "end date",
+ 'groups' => "active groups",
+ );
+ my $nametitle = $lt{'sn'};
+ if ($crstype eq 'Community') {
+ $nametitle = $lt{'mn'};
+ }
if ($nosort) {
- $r->print(&Apache::loncommon::start_data_table());
+ $r->print(&Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row());
$r->print(<
$lt{'usrn'}
$lt{'dom'}
ID
- $lt{'sn'}
+ $nametitle
$lt{'sec'}
$lt{'start'}
$lt{'end'}
$lt{'groups'}
-
END
-
+ $r->print(&Apache::loncommon::end_data_table_header_row());
} else {
- $r->print(&Apache::loncommon::start_data_table());
+ $r->print(&Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row());
$r->print(<
+
- $lt{'usrn'}
+ $lt{'usrn'}
- $lt{'dom'}
+ $lt{'dom'}
- ID
+ ID
- $lt{'sn'}
+ $nametitle
- $lt{'sec'}
+ $lt{'sec'}
- $lt{'start'}
+ $lt{'start'}
- $lt{'end'}
+ $lt{'end'}
- $lt{'groups'}
+ $lt{'groups'}
-
END
+ $r->print(&Apache::loncommon::end_data_table_header_row());
}
#
# Sort the students
- my %index;
- my $i;
- foreach (@$keylist) {
- $index{$_} = $i++;
- }
- $index{'groups'} = scalar(@$keylist);
- my $index = $index{$sortby};
- my $second = $index{'username'};
- my $third = $index{'domain'};
+ my $index = $indexhash->{$sortby};
+ my $second = $indexhash->{'username'};
+ my $third = $indexhash->{'domain'};
my @Sorted_Students = sort {
lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
||
lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
||
lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
- } (keys(%$classlist));
+ } (keys(%{$classlist}));
foreach my $student (@Sorted_Students) {
my $error;
my $sdata = $classlist->{$student};
- my $username = $sdata->[$index{'username'}];
- my $domain = $sdata->[$index{'domain'}];
- my $section = $sdata->[$index{'section'}];
- my $name = $sdata->[$index{'fullname'}];
- my $id = $sdata->[$index{'id'}];
- my $start = $sdata->[$index{'start'}];
- my $end = $sdata->[$index{'end'}];
+ my $username = $sdata->[$indexhash->{'username'}];
+ my $domain = $sdata->[$indexhash->{'domain'}];
+ my $section = $sdata->[$indexhash->{'section'}];
+ my $name = $sdata->[$indexhash->{'fullname'}];
+ my $id = $sdata->[$indexhash->{'id'}];
+ my $start = $sdata->[$indexhash->{'start'}];
+ my $end = $sdata->[$indexhash->{'end'}];
my $groups = $classgroups->{$student};
my $active_groups;
if (ref($groups->{active}) eq 'HASH') {
@@ -2743,18 +3646,18 @@ END
} else {
$end = &Apache::lonlocal::locallocaltime($end);
}
- my $status = $sdata->[$index{'status'}];
- next if ($status ne 'Active');
+ my $studentkey = $student.':'.$section;
+ my $startitem = '';
#
$r->print(&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
-
+
$username
$domain
$id
$name
$section
- $start
+ $start $startitem
$end
$active_groups
END
@@ -2762,15 +3665,24 @@ END
}
$r->print(&Apache::loncommon::end_data_table().'
');
%lt=&Apache::lonlocal::texthash(
- 'dp' => "Expire Users' Roles",
+ 'dp' => "Drop Students",
+ 'dm' => "Drop Members",
'ca' => "check all",
'ua' => "uncheck all",
);
+ my $btn = $lt{'dp'};
+ if ($crstype eq 'Community') {
+ $btn = $lt{'dm'};
+ }
$r->print(<<"END");
-
- - -
+ ++ + +
++ +
END return; } @@ -2781,30 +3693,50 @@ END sub print_first_users_upload_form { my ($r,$context) = @_; my $str; - $str = ''; + $str = ''; $str .= ''; - $str .= ''; - $str .= "\n"; - $str .= ''."\n"; - $str .= '
\n"; - $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List", - &mt("How do I create a users list from a spreadsheet")). - "'."\n" + .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n" + .'
'."\n"; + } + } + $str .= &Apache::loncommon::upfile_select_html() + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title( + '') + .'' + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box(); + + $str .= '' + .'' + .'
'; + $r->print($str); return; } # ================================================= Drop/Add from uploaded file sub upfile_drop_add { - my ($r,$context) = @_; + my ($r,$context,$permission) = @_; &Apache::loncommon::load_tmp_file($r); my @userdata=&Apache::loncommon::upfile_record_sep(); if($env{'form.noFirstLine'}){shift(@userdata);} @@ -2819,10 +3751,14 @@ sub upfile_drop_add { $fields{$env{'form.f'.$i}}=$keyfields[$i]; } } + if ($env{'form.fullup'} ne 'yes') { + $r->print(''); + $r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules)); ##################################### - # Drop students # + # Display list of students to drop # ##################################### if ($env{'form.fullup'} eq 'yes') { - $r->print(''.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'
'); + $r->print(''."\n"); +} + +sub dates_feedback { + my ($start,$end,$now) = @_; + my $dates; + if ($start < $now) { + if ($end == 0) { + $dates .= &mt('role(s) active now; no end date'); + } elsif ($end > $now) { + $dates = &mt('role(s) active now; ends [_1].',&Apache::lonlocal::locallocaltime($end)); + } else { + $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end)); + } + } else { + if ($end == 0 || $end > $now) { + $dates = &mt('future role(s); starts: [_1].',&Apache::lonlocal::locallocaltime($start)); + } else { + $dates = &mt('role(s) expired: [_1].',&Apache::lonlocal::locallocaltime($end)); } } + return $dates; } sub classlist_drop { - my ($scope,$uname,$udom,$now,$action) = @_; + my ($scope,$uname,$udom,$now) = @_; my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)}); - my $cid=$cdom.'_'.$cnum; - my $user = $uname.':'.$udom; - if ($action eq 'drop') { + if (&Apache::lonnet::is_course($cdom,$cnum)) { if (!&active_student_roles($cnum,$cdom,$uname,$udom)) { - my $result = - &Apache::lonnet::cput('classlist', - { $user => $now }, - $env{'course.'.$cid.'.domain'}, - $env{'course.'.$cid.'.num'}); + my %user; + my $result = &update_classlist($cdom,$cnum,$udom,$uname,\%user,$now); return &mt('Drop from classlist: [_1]', ''.$result.'').'