version 1.28, 2007/12/22 19:12:51
|
version 1.32, 2007/12/23 15:50:24
|
Line 2047 END
|
Line 2047 END
|
$env{'request.role.domain'})) { |
$env{'request.role.domain'})) { |
$canchange{$role} = 1; |
$canchange{$role} = 1; |
} |
} |
|
} elsif ($setting eq 'author') { |
|
if (&Apache::lonnet::allowed('c'.$role, |
|
$env{'request.role.domain'})) { |
|
$canchange{$role} = 1; |
|
} |
} |
} |
} elsif ($context eq 'author') { |
} elsif ($context eq 'author') { |
if (&Apache::lonnet::allowed('c'.$role, |
if (&Apache::lonnet::allowed('c'.$role, |
Line 2841 sub viewable_section {
|
Line 2846 sub viewable_section {
|
################################################# |
################################################# |
################################################# |
################################################# |
sub show_drop_list { |
sub show_drop_list { |
my ($r,$classlist,$keylist,$nosort,$permission)=@_; |
my ($r,$classlist,$nosort,$permission) = @_; |
my $cid=$env{'request.course.id'}; |
my $cid = $env{'request.course.id'}; |
my ($cnum,$cdom) = &get_course_identity($cid); |
my ($cnum,$cdom) = &get_course_identity($cid); |
if (! exists($env{'form.sortby'})) { |
if (! exists($env{'form.sortby'})) { |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
Line 2852 sub show_drop_list {
|
Line 2857 sub show_drop_list {
|
if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) { |
if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) { |
$sortby = 'username'; |
$sortby = 'username'; |
} |
} |
my ($classgroups) = &Apache::loncoursedata::get_group_memberships( |
|
$classlist,$keylist,$cdom,$cnum); |
|
# |
|
my $action = "drop"; |
my $action = "drop"; |
my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript(); |
my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript(); |
$r->print(<<END); |
$r->print(<<END); |
Line 2867 $check_uncheck_js
|
Line 2869 $check_uncheck_js
|
<p> |
<p> |
<input type="hidden" name="phase" value="four"> |
<input type="hidden" name="phase" value="four"> |
END |
END |
|
my ($indexhash,$keylist) = &make_keylist_array(); |
my %lt=&Apache::lonlocal::texthash('usrn' => "username", |
my $studentcount = 0; |
'dom' => "domain", |
if (ref($classlist) eq 'HASH') { |
'sn' => "student name", |
foreach my $student (keys(%{$classlist})) { |
'sec' => "section", |
my $sdata = $classlist->{$student}; |
'start' => "start date", |
my $status = $sdata->[$indexhash->{'status'}]; |
'end' => "end date", |
my $section = $sdata->[$indexhash->{'section'}]; |
'groups' => "active groups", |
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) { |
|
$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", |
|
'sec' => "section", |
|
'start' => "start date", |
|
'end' => "end date", |
|
'groups' => "active groups", |
|
); |
if ($nosort) { |
if ($nosort) { |
$r->print(&Apache::loncommon::start_data_table(). |
$r->print(&Apache::loncommon::start_data_table(). |
&Apache::loncommon::start_data_table_header_row()); |
&Apache::loncommon::start_data_table_header_row()); |
Line 2918 END
|
Line 2945 END
|
} |
} |
# |
# |
# Sort the students |
# Sort the students |
my %index; |
my $index = $indexhash->{$sortby}; |
my $i; |
my $second = $indexhash->{'username'}; |
foreach (@$keylist) { |
my $third = $indexhash->{'domain'}; |
$index{$_} = $i++; |
|
} |
|
$index{'groups'} = scalar(@$keylist); |
|
my $index = $index{$sortby}; |
|
my $second = $index{'username'}; |
|
my $third = $index{'domain'}; |
|
my @Sorted_Students = sort { |
my @Sorted_Students = sort { |
lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index]) |
lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index]) |
|| |
|| |
lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second]) |
lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second]) |
|| |
|| |
lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third]) |
lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third]) |
} (keys(%$classlist)); |
} (keys(%{$classlist})); |
foreach my $student (@Sorted_Students) { |
foreach my $student (@Sorted_Students) { |
my $error; |
my $error; |
my $sdata = $classlist->{$student}; |
my $sdata = $classlist->{$student}; |
my $username = $sdata->[$index{'username'}]; |
my $username = $sdata->[$indexhash->{'username'}]; |
my $domain = $sdata->[$index{'domain'}]; |
my $domain = $sdata->[$indexhash->{'domain'}]; |
my $section = $sdata->[$index{'section'}]; |
my $section = $sdata->[$indexhash->{'section'}]; |
my $name = $sdata->[$index{'fullname'}]; |
my $name = $sdata->[$indexhash->{'fullname'}]; |
my $id = $sdata->[$index{'id'}]; |
my $id = $sdata->[$indexhash->{'id'}]; |
my $start = $sdata->[$index{'start'}]; |
my $start = $sdata->[$indexhash->{'start'}]; |
my $end = $sdata->[$index{'end'}]; |
my $end = $sdata->[$indexhash->{'end'}]; |
my $groups = $classgroups->{$student}; |
my $groups = $classgroups->{$student}; |
my $active_groups; |
my $active_groups; |
if (ref($groups->{active}) eq 'HASH') { |
if (ref($groups->{active}) eq 'HASH') { |
Line 2959 END
|
Line 2980 END
|
} else { |
} else { |
$end = &Apache::lonlocal::locallocaltime($end); |
$end = &Apache::lonlocal::locallocaltime($end); |
} |
} |
my $status = $sdata->[$index{'status'}]; |
|
next if ($status ne 'Active'); |
|
if ($env{'request.course.sec'} ne '') { |
|
if ($section ne $env{'request.course.sec'}) { |
|
next; |
|
} |
|
} |
|
my $studentkey = $student.':'.$section; |
my $studentkey = $student.':'.$section; |
my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$index{'start'}].'" />'; |
my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />'; |
# |
# |
$r->print(&Apache::loncommon::start_data_table_row()); |
$r->print(&Apache::loncommon::start_data_table_row()); |
$r->print(<<"END"); |
$r->print(<<"END"); |
<td><input type="checkbox" name="droplist" value="$student"></td> |
<td><input type="checkbox" name="droplist" value="$studentkey"></td> |
<td>$username</td> |
<td>$username</td> |
<td>$domain</td> |
<td>$domain</td> |
<td>$id</td> |
<td>$id</td> |
<td>$name</td> |
<td>$name</td> |
<td>$section</td> |
<td>$section</td> |
<td>$start</td> |
<td>$start $startitem</td> |
<td>$end</td> |
<td>$end</td> |
<td>$active_groups</td> |
<td>$active_groups</td> |
END |
END |
Line 2985 END
|
Line 2999 END
|
} |
} |
$r->print(&Apache::loncommon::end_data_table().'<br />'); |
$r->print(&Apache::loncommon::end_data_table().'<br />'); |
%lt=&Apache::lonlocal::texthash( |
%lt=&Apache::lonlocal::texthash( |
'dp' => "Expire Users' Roles", |
'dp' => "Drop Students", |
'ca' => "check all", |
'ca' => "check all", |
'ua' => "uncheck all", |
'ua' => "uncheck all", |
); |
); |
Line 3042 sub upfile_drop_add {
|
Line 3056 sub upfile_drop_add {
|
$fields{$env{'form.f'.$i}}=$keyfields[$i]; |
$fields{$env{'form.f'.$i}}=$keyfields[$i]; |
} |
} |
} |
} |
|
if ($env{'form.fullup'} ne 'yes') { |
|
$r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n". |
|
'<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'); |
|
} |
# |
# |
# Store the field choices away |
# Store the field choices away |
foreach my $field (qw/username names |
foreach my $field (qw/username names |
Line 3488 sub upfile_drop_add {
|
Line 3506 sub upfile_drop_add {
|
$flushc = |
$flushc = |
&user_change_result($r,$userresult,$authresult, |
&user_change_result($r,$userresult,$authresult, |
$roleresult,$idresult,\%counts,$flushc, |
$roleresult,$idresult,\%counts,$flushc, |
$username,%userchg); |
$username,\%userchg); |
} |
} |
} else { |
} else { |
if ($context eq 'course') { |
if ($context eq 'course') { |
Line 3510 sub upfile_drop_add {
|
Line 3528 sub upfile_drop_add {
|
} # end of foreach (@userdata) |
} # end of foreach (@userdata) |
# Flush the course logs so reverse user roles immediately updated |
# Flush the course logs so reverse user roles immediately updated |
&Apache::lonnet::flushcourselogs(); |
&Apache::lonnet::flushcourselogs(); |
$r->print("</p>\n<p>\n".&mt('Processed [_1] user(s).',$counts{'user'}). |
$r->print("</p>\n<p>\n".&mt('Processed [quant,_1,user].',$counts{'user'}). |
"</p>\n"); |
"</p>\n"); |
if ($counts{'role'} > 0) { |
if ($counts{'role'} > 0) { |
$r->print("<p>\n". |
$r->print("<p>\n". |
&mt('Roles added for [_1] users. If user is active, the new role will be available when the user next logs in to LON-CAPA.',$counts{'role'})."</p>\n"); |
&mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.&mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.')."</p>\n"); |
|
} else { |
|
$r->print('<p>'.&mt('No roles added').'</p>'); |
} |
} |
if ($counts{'auth'} > 0) { |
if ($counts{'auth'} > 0) { |
$r->print("<p>\n". |
$r->print("<p>\n". |
Line 3522 sub upfile_drop_add {
|
Line 3542 sub upfile_drop_add {
|
$counts{'auth'})."</p>\n"); |
$counts{'auth'})."</p>\n"); |
} |
} |
$r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules)); |
$r->print(&print_namespacing_alerts($domain,\%alerts,\%curr_rules)); |
$r->print('<form name="uploadresult" action="/adm/createuser">'); |
|
$r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','prevphase','currstate'])); |
|
$r->print('</form>'); |
|
##################################### |
##################################### |
# Drop students # |
# Display list of students to drop # |
##################################### |
##################################### |
if ($env{'form.fullup'} eq 'yes') { |
if ($env{'form.fullup'} eq 'yes') { |
$r->print('<h3>'.&mt('Dropping Students')."</h3>\n"); |
$r->print('<h3>'.&mt('Students to Drop')."</h3>\n"); |
# Get current classlist |
# Get current classlist |
my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist(); |
my $classlist = &Apache::loncoursedata::get_classlist(); |
if (! defined($classlist)) { |
if (! defined($classlist)) { |
$r->print(&mt('There are no students currently enrolled.'). |
$r->print('<form name="studentform" method="post" action="/adm/createuser" />'. |
"\n"); |
'<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'. |
|
&mt('There are no students with current/future access to the course.'). |
|
'</form>'."\n"); |
} else { |
} else { |
# Remove the students we just added from the list of students. |
# Remove the students we just added from the list of students. |
foreach (@userdata) { |
foreach my $line (@userdata) { |
my %entries=&Apache::loncommon::record_sep($_); |
my %entries=&Apache::loncommon::record_sep($line); |
unless (($entries{$fields{'username'}} eq '') || |
unless (($entries{$fields{'username'}} eq '') || |
(!defined($entries{$fields{'username'}}))) { |
(!defined($entries{$fields{'username'}}))) { |
delete($classlist->{$entries{$fields{'username'}}. |
delete($classlist->{$entries{$fields{'username'}}. |
Line 3546 sub upfile_drop_add {
|
Line 3565 sub upfile_drop_add {
|
} |
} |
} |
} |
# Print out list of dropped students. |
# Print out list of dropped students. |
&show_drop_list($r,$classlist,$keylist,'nosort'); |
&show_drop_list($r,$classlist,'nosort',$permission); |
} |
} |
} |
} |
} # end of unless |
} # end of unless |
|
if ($env{'form.fullup'} ne 'yes') { |
|
$r->print('</form>'); |
|
} |
} |
} |
|
|
sub print_namespacing_alerts { |
sub print_namespacing_alerts { |
Line 3593 sub print_namespacing_alerts {
|
Line 3615 sub print_namespacing_alerts {
|
} |
} |
|
|
sub user_change_result { |
sub user_change_result { |
my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username, |
my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc, |
$userchg) = @_; |
$username,$userchg) = @_; |
my $okresult = 0; |
my $okresult = 0; |
if ($userresult ne 'ok') { |
if ($userresult ne 'ok') { |
if ($userresult =~ /^error:(.+)$/) { |
if ($userresult =~ /^error:(.+)$/) { |
Line 3635 sub user_change_result {
|
Line 3657 sub user_change_result {
|
$flushc=0; |
$flushc=0; |
} |
} |
} |
} |
|
if ($idresult) { |
|
$r->print($idresult); |
|
} |
return $flushc; |
return $flushc; |
} |
} |
|
|
Line 3643 sub print_drop_menu {
|
Line 3668 sub print_drop_menu {
|
my ($r,$context,$permission) = @_; |
my ($r,$context,$permission) = @_; |
$r->print('<h3>'.&mt("Drop Students").'</h3>'."\n". |
$r->print('<h3>'.&mt("Drop Students").'</h3>'."\n". |
'<form name="studentform" method="post">'."\n"); |
'<form name="studentform" method="post">'."\n"); |
my $cid=$env{'request.course.id'}; |
my $classlist = &Apache::loncoursedata::get_classlist(); |
my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist(); |
|
if (! defined($classlist)) { |
if (! defined($classlist)) { |
$r->print(&mt('There are no students currently enrolled.')."\n"); |
$r->print(&mt('There are no students currently enrolled.')."\n"); |
return; |
} else { |
|
&show_drop_list($r,$classlist,'nosort',$permission); |
} |
} |
# Print out the available choices |
|
&show_drop_list($r,$classlist,$keylist,$permission); |
|
$r->print('</form>'. &Apache::loncommon::end_page()); |
$r->print('</form>'. &Apache::loncommon::end_page()); |
return; |
return; |
} |
} |
Line 3662 sub update_user_list {
|
Line 3685 sub update_user_list {
|
my $now = time; |
my $now = time; |
my $count=0; |
my $count=0; |
my @changelist; |
my @changelist; |
if ($choice ne '') { |
if ($choice eq 'drop') { |
@changelist = &Apache::loncommon::get_env_multiple('form.actionlist'); |
|
} else { |
|
@changelist = &Apache::loncommon::get_env_multiple('form.droplist'); |
@changelist = &Apache::loncommon::get_env_multiple('form.droplist'); |
|
} else { |
|
@changelist = &Apache::loncommon::get_env_multiple('form.actionlist'); |
} |
} |
my %result_text = ( ok => { 'revoke' => 'Revoked', |
my %result_text = ( ok => { 'revoke' => 'Revoked', |
'delete' => 'Deleted', |
'delete' => 'Deleted', |
Line 3752 sub update_user_list {
|
Line 3775 sub update_user_list {
|
} |
} |
} elsif ($choice eq 'delete') { |
} elsif ($choice eq 'delete') { |
if ($role eq 'st') { |
if ($role eq 'st') { |
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid); |
&Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid); |
} else { |
} |
$result = |
$result = |
&Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now, |
&Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now, |
$start,1); |
$start,1); |
} |
|
} else { |
} else { |
#reenable, activate, change access dates or change section |
#reenable, activate, change access dates or change section |
if ($choice ne 'chgsec') { |
if ($choice ne 'chgsec') { |
Line 3862 sub update_user_list {
|
Line 3884 sub update_user_list {
|
$count++; |
$count++; |
} else { |
} else { |
$r->print( |
$r->print( |
&mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]:[_4]", |
&mt("Error $result_text{'error'}{$choice} [_1] in [_2] for [_3]: [_4].", |
$plrole,$extent,$uname.':'.$udom,$result).'<br />'); |
$plrole,$extent,$uname.':'.$udom,$result).'<br />'); |
} |
} |
} |
} |
$r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'</b></p>'); |
$r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n"); |
|
foreach my $item ('action','sortby','roletype','showrole','Status') { |
|
if ($env{'form.'.$item} ne '') { |
|
$r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n"); |
|
} |
|
} |
|
$r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,no users].",$count).'</b></p>'); |
if ($count > 0) { |
if ($count > 0) { |
if ($choice eq 'revoke' || $choice eq 'drop') { |
if ($choice eq 'revoke' || $choice eq 'drop') { |
$r->print('<p>'.&mt('Re-enabling will re-activate data for the role.</p>')); |
$r->print('<p>'.&mt('Re-enabling will re-activate data for the role.</p>')); |
Line 3876 sub update_user_list {
|
Line 3904 sub update_user_list {
|
} |
} |
if ($env{'form.makedatesdefault'}) { |
if ($env{'form.makedatesdefault'}) { |
if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') { |
if ($choice eq 'chgdates' || $choice eq 'reenable' || $choice eq 'activate') { |
$r->print(&make_dates_default($startdate,$enddate)); |
$r->print(&make_dates_default($startdate,$enddate,$context)); |
} |
} |
} |
} |
|
$r->print('<a href="javascript:document.studentform.submit()">'.&mt('Display User Lists').'</a></form>'."\n"); |
} |
} |
|
|
sub classlist_drop { |
sub classlist_drop { |
my ($scope,$uname,$udom,$now,$action) = @_; |
my ($scope,$uname,$udom,$now) = @_; |
my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)}); |
my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)}); |
my $cid=$cdom.'_'.$cnum; |
if (&Apache::lonnet::is_course($cdom,$cnum)) { |
my $user = $uname.':'.$udom; |
my $user = $uname.':'.$udom; |
if ($action eq 'drop') { |
|
if (!&active_student_roles($cnum,$cdom,$uname,$udom)) { |
if (!&active_student_roles($cnum,$cdom,$uname,$udom)) { |
my $result = |
my $result = |
&Apache::lonnet::cput('classlist', |
&Apache::lonnet::cput('classlist', |
{ $user => $now }, |
{ $user => $now },$cdom,$cnum); |
$env{'course.'.$cid.'.domain'}, |
|
$env{'course.'.$cid.'.num'}); |
|
return &mt('Drop from classlist: [_1]', |
return &mt('Drop from classlist: [_1]', |
'<b>'.$result.'</b>').'<br />'; |
'<b>'.$result.'</b>').'<br />'; |
} |
} |
Line 3962 sub course_sections {
|
Line 3988 sub course_sections {
|
my ($sections_count,$role) = @_; |
my ($sections_count,$role) = @_; |
my $output = ''; |
my $output = ''; |
my @sections = (sort {$a <=> $b} keys %{$sections_count}); |
my @sections = (sort {$a <=> $b} keys %{$sections_count}); |
if (scalar(@sections) == 1) { |
my $numsec = scalar(@sections); |
|
if ($numsec <= 1) { |
$output = '<select name="currsec_'.$role.'" >'."\n". |
$output = '<select name="currsec_'.$role.'" >'."\n". |
' <option value="">Select</option>'."\n". |
' <option value="">'.&mt('Select').'</option>'."\n". |
' <option value="">No section</option>'."\n". |
' <option value="">'.&mt('No section').'</option>'."\n"; |
|
if ($numsec == 1) { |
|
$output .= |
' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n"; |
' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n"; |
|
} |
} else { |
} else { |
$output = '<select name="currsec_'.$role.'" '; |
$output = '<select name="currsec_'.$role.'" '; |
my $multiple = 4; |
my $multiple = 4; |
if (scalar(@sections) < 4) { $multiple = scalar(@sections); } |
if (scalar(@sections) < 4) { $multiple = scalar(@sections); } |
$output .= 'multiple="multiple" size="'.$multiple.'">'."\n"; |
if ($role eq 'st') { |
|
$output .= '>'."\n". |
|
' <option value="">'.&mt('Select').'</option>'."\n". |
|
' <option value="">'.&mt('No section')."</option>\n"; |
|
} else { |
|
$output .= 'multiple="multiple" size="'.$multiple.'">'."\n"; |
|
} |
foreach my $sec (@sections) { |
foreach my $sec (@sections) { |
$output .= '<option value="'.$sec.'">'.$sec."</option>\n"; |
$output .= '<option value="'.$sec.'">'.$sec."</option>\n"; |
} |
} |