[LON-CAPA-cvs] cvs: loncom /interface lonuserutils.pm
raeburn
lon-capa-cvs-allow@mail.lon-capa.org
Sat, 22 Dec 2007 22:42:58 -0000
This is a MIME encoded message
--raeburn1198363378
Content-Type: text/plain
raeburn Sat Dec 22 17:42:58 2007 EDT
Modified files:
/loncom/interface lonuserutils.pm
Log:
Drop students:
- value of droplist form element (the checkbox) includes section number (format - $uname:$udom:$usec
- Text of button on dropping page changed to "Drop Students"
File upload:
- form name and hidden action element included on results screen from file upload, unless full update requested, or no students to drop
(drop listing provides own <form></form> in full update case
- Use [quant,_1] in &mt() calls for singular/plural counts of affected users
- Display results of propagated changes in ID (if any)
&classlist_drop()
- validate cdom and cnum from provided $scope arg
- eliminated unneeded 5th arg ($action) and switch on value of $action
&course_sections()
- if $role is 'st' and more than 1 existing section currsec_st dropdown box is not "multiple".
--raeburn1198363378
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071222174258.txt"
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.28 loncom/interface/lonuserutils.pm:1.29
--- loncom/interface/lonuserutils.pm:1.28 Sat Dec 22 14:12:51 2007
+++ loncom/interface/lonuserutils.pm Sat Dec 22 17:42:58 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.28 2007/12/22 19:12:51 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.29 2007/12/22 22:42:58 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2841,8 +2841,8 @@
#################################################
#################################################
sub show_drop_list {
- my ($r,$classlist,$keylist,$nosort,$permission)=@_;
- my $cid=$env{'request.course.id'};
+ my ($r,$classlist,$keylist,$nosort,$permission) = @_;
+ my $cid = $env{'request.course.id'};
my ($cnum,$cdom) = &get_course_identity($cid);
if (! exists($env{'form.sortby'})) {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
@@ -2971,13 +2971,13 @@
#
$r->print(&Apache::loncommon::start_data_table_row());
$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>$domain</td>
<td>$id</td>
<td>$name</td>
<td>$section</td>
- <td>$start</td>
+ <td>$start $startitem</td>
<td>$end</td>
<td>$active_groups</td>
END
@@ -2985,7 +2985,7 @@
}
$r->print(&Apache::loncommon::end_data_table().'<br />');
%lt=&Apache::lonlocal::texthash(
- 'dp' => "Expire Users' Roles",
+ 'dp' => "Drop Students",
'ca' => "check all",
'ua' => "uncheck all",
);
@@ -3042,6 +3042,10 @@
$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
foreach my $field (qw/username names
@@ -3488,7 +3492,7 @@
$flushc =
&user_change_result($r,$userresult,$authresult,
$roleresult,$idresult,\%counts,$flushc,
- $username,%userchg);
+ $username,\%userchg);
}
} else {
if ($context eq 'course') {
@@ -3510,11 +3514,13 @@
} # end of foreach (@userdata)
# Flush the course logs so reverse user roles immediately updated
&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");
if ($counts{'role'} > 0) {
$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) {
$r->print("<p>\n".
@@ -3522,19 +3528,18 @@
$counts{'auth'})."</p>\n");
}
$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') {
- $r->print('<h3>'.&mt('Dropping Students')."</h3>\n");
+ $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
# Get current classlist
my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
if (! defined($classlist)) {
- $r->print(&mt('There are no students currently enrolled.').
- "\n");
+ $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.
+ '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
+ &mt('There are no students with current/future access to the course.').
+ '</form>'."\n");
} else {
# Remove the students we just added from the list of students.
foreach (@userdata) {
@@ -3546,10 +3551,13 @@
}
}
# Print out list of dropped students.
- &show_drop_list($r,$classlist,$keylist,'nosort');
+ &show_drop_list($r,$classlist,$keylist,'nosort',$permission);
}
}
} # end of unless
+ if ($env{'form.fullup'} ne 'yes') {
+ $r->print('</form>');
+ }
}
sub print_namespacing_alerts {
@@ -3593,8 +3601,8 @@
}
sub user_change_result {
- my ($r,$userresult,$authresult,$roleresult,$counts,$flushc,$username,
- $userchg) = @_;
+ my ($r,$userresult,$authresult,$roleresult,$idresult,$counts,$flushc,
+ $username,$userchg) = @_;
my $okresult = 0;
if ($userresult ne 'ok') {
if ($userresult =~ /^error:(.+)$/) {
@@ -3635,6 +3643,9 @@
$flushc=0;
}
}
+ if ($idresult) {
+ $r->print($idresult);
+ }
return $flushc;
}
@@ -3662,10 +3673,10 @@
my $now = time;
my $count=0;
my @changelist;
- if ($choice ne '') {
- @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
- } else {
+ if ($choice eq 'drop') {
@changelist = &Apache::loncommon::get_env_multiple('form.droplist');
+ } else {
+ @changelist = &Apache::loncommon::get_env_multiple('form.actionlist');
}
my %result_text = ( ok => { 'revoke' => 'Revoked',
'delete' => 'Deleted',
@@ -3752,12 +3763,11 @@
}
} elsif ($choice eq 'delete') {
if ($role eq 'st') {
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,$type,$locktype,$cid);
- } else {
- $result =
- &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
- $start,1);
- }
+ &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$now,$start,$type,$locktype,$cid);
+ }
+ $result =
+ &Apache::lonnet::assignrole($udom,$uname,$scope,$role,$now,
+ $start,1);
} else {
#reenable, activate, change access dates or change section
if ($choice ne 'chgsec') {
@@ -3862,11 +3872,11 @@
$count++;
} else {
$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 />');
}
}
- $r->print('<p><b>'.&mt("$result_text{'ok'}{$choice} role(s) for [quant,_1,user,users,users].",$count).'</b></p>');
+ $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 ($choice eq 'revoke' || $choice eq 'drop') {
$r->print('<p>'.&mt('Re-enabling will re-activate data for the role.</p>'));
@@ -3876,23 +3886,20 @@
}
if ($env{'form.makedatesdefault'}) {
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));
}
}
}
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)) {
+ my $user = $uname.':'.$udom;
if (!&active_student_roles($cnum,$cdom,$uname,$udom)) {
my $result =
&Apache::lonnet::cput('classlist',
- { $user => $now },
- $env{'course.'.$cid.'.domain'},
- $env{'course.'.$cid.'.num'});
+ { $user => $now },$cdom,$cnum);
return &mt('Drop from classlist: [_1]',
'<b>'.$result.'</b>').'<br />';
}
@@ -3962,16 +3969,26 @@
my ($sections_count,$role) = @_;
my $output = '';
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".
- ' <option value="">Select</option>'."\n".
- ' <option value="">No section</option>'."\n".
+ ' <option value="">'.&mt('Select').'</option>'."\n".
+ ' <option value="">'.&mt('No section').'</option>'."\n";
+ if ($numsec == 1) {
+ $output .=
' <option value="'.$sections[0].'" >'.$sections[0].'</option>'."\n";
+ }
} else {
$output = '<select name="currsec_'.$role.'" ';
my $multiple = 4;
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) {
$output .= '<option value="'.$sec.'">'.$sec."</option>\n";
}
--raeburn1198363378--