--- loncom/interface/lonuserutils.pm 2010/01/14 17:02:49 1.110
+++ loncom/interface/lonuserutils.pm 2012/08/21 01:50:34 1.140
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.110 2010/01/14 17:02:49 bisitz Exp $
+# $Id: lonuserutils.pm,v 1.140 2012/08/21 01:50:34 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -295,7 +295,8 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
+ $can_assign)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -309,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
@@ -532,6 +533,7 @@ END
if (message!='') {
message+='\\n';
}
+ message+='$alert{'section'}';
}
if (foundemail==0) {
if (message!='') {
@@ -585,6 +587,46 @@ END
###############################################################
###############################################################
sub upload_manager_javascript_forward_associate {
+ my ($can_assign) = @_;
+ my ($auth_update,$numbuttons,$argreset);
+ if (ref($can_assign) eq 'HASH') {
+ if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
+ $argreset .= " vf.krbarg.value='';\n";
+ $numbuttons ++ ;
+ }
+ if ($can_assign->{'int'}) {
+ $argreset .= " vf.intarg.value='';\n";
+ $numbuttons ++;
+ }
+ if ($can_assign->{'loc'}) {
+ $argreset .= " vf.locarg.value='';\n";
+ $numbuttons ++;
+ }
+ if (!$can_assign->{'int'}) {
+ my $warning = &mt('You may not specify an initial password for each user, as this is only available when new users use LON-CAPA internal authentication.\n').
+ &mt('Your current role does not have rights to create users with that authentication type.');
+ $auth_update = <<"END";
+ // Currently the initial password field is only supported for internal auth
+ // (see bug 6368).
+ if (nw==9) {
+ eval('vf.f'+tf+'.selectedIndex=0;')
+ alert('$warning');
+ }
+END
+ } elsif ($numbuttons > 1) {
+ $auth_update = <<"END";
+ // If we set the password, make the password form below correspond to
+ // the new value.
+ if (nw==9) {
+ changed_radio('int',document.studentform);
+ set_auth_radio_buttons('int',document.studentform);
+$argreset
+ }
+
+END
+ }
+ }
+
return(<{'krb4'} || $can_assign->{'krb5'}) {
+ $argreset .= " vf.krbarg.value='';\n";
+ $numbuttons ++ ;
+ }
+ if ($can_assign->{'int'}) {
+ $argreset .= " vf.intarg.value='';\n";
+ $numbuttons ++;
+ }
+ if ($can_assign->{'loc'}) {
+ $argreset .= " vf.locarg.value='';\n";
+ $numbuttons ++;
+ }
+ if (!$can_assign->{'int'}) {
+ my $warning = &mt('You may not specify an initial password, as this is only available when new users use LON-CAPA internal authentication.\n').
+ &mt('Your current role does not have rights to create users with that authentication type.');
+ $auth_update = <<"END";
+ // Currently the initial password field is only supported for internal auth
+ // (see bug 6368).
+ if (tf==8 && nw!=0) {
+ eval('vf.f'+tf+'.selectedIndex=0;')
+ alert('$warning');
+ }
+END
+ } elsif ($numbuttons > 1) {
+ $auth_update = <<"END";
+ // initial password specified, pick internal authentication
+ if (tf==8 && nw!=0) {
+ changed_radio('int',document.studentform);
+ set_auth_radio_buttons('int',document.studentform);
+$argreset
+ }
+
+END
+ }
+ }
+
return(<=2) && (tf<=5) && (nw!=0)) {
eval('vf.f1.selectedIndex=0;')
}
- // intial password specified, pick internal authentication
- if (tf==8 && nw!=0) {
- changed_radio('int',document.studentform);
- set_auth_radio_buttons('int',document.studentform);
- vf.krbarg.value='';
- vf.intarg.value='';
- vf.locarg.value='';
- }
+ $auth_update
}
function clearpwd(vf) {
@@ -978,8 +1046,9 @@ sub print_upload_manager_form {
my ($krbdef,$krbdefdom) =
&Apache::loncommon::get_kerberos_defaults($defdom);
#
+ my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($defdom);
&print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
- $permission,$crstype);
+ $permission,$crstype,\%can_assign);
my $i;
my $keyfields;
if ($total>=0) {
@@ -1352,6 +1421,7 @@ sub curr_role_permissions {
sub my_custom_roles {
my ($crstype) = @_;
my %returnhash=();
+ my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
my %rolehash=&Apache::lonnet::dump('roles');
foreach my $key (keys(%rolehash)) {
if ($key=~/^rolesdef\_(\w+)$/) {
@@ -1374,8 +1444,9 @@ sub print_userlist {
if ($env{'form.Status'} !~ /^(Any|Expired|Active|Future)$/) {
$env{'form.Status'} = 'Active';
}
+ my $onchange = "javascript:updateCols('Status');";
my $status_select = &Apache::lonhtmlcommon::StatusOptions
- ($env{'form.Status'});
+ ($env{'form.Status'},undef,undef,$onchange);
if ($env{'form.showrole'} eq '') {
if ($context eq 'course') {
@@ -1408,12 +1479,12 @@ sub print_userlist {
$r->print('
\n".
+ $r->print(&list_submit_button(&mt('Display List of Users'))."\n".
' ');
return;
}
if (!(($context eq 'domain') &&
(($env{'form.roletype'} eq 'course') || ($env{'form.roletype'} eq 'community')))) {
- $r->print(' '.&list_submit_button(&mt('Update Display')).
- "\n\n");
+ $r->print(&list_submit_button(&mt('Update Display'))."\n");
+ }
+
+ my @cols = &infocolumns($context,$mode);
+ if (!@cols) {
+ $r->print(''.
+ &mt('No user information selected for display.').' '.
+ ' '."\n");
+ return;
}
my ($indexhash,$keylist) = &make_keylist_array();
my (%userlist,%userinfo,$clearcoursepick);
@@ -1468,9 +1548,11 @@ sub print_userlist {
$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,$numcodes,
- $codetitles,$idlist,$idlist_titles,$crstype);
+ $codetitles,$idlist,$idlist_titles,$crstype,
+ \@standardnames);
$r->print(''.&Apache::lonhtmlcommon::start_pick_box()."\n".
&Apache::lonhtmlcommon::start_pick_box()."\n".
&Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n".
@@ -1489,7 +1571,7 @@ sub print_userlist {
$r->print('
'.&mt('Searching').' ... ');
}
} else {
- $r->print(' '.&mt('Searching').' ... ');
+ $r->print(''.&mt('Searching').' ...
');
}
$r->rflush();
if ($context eq 'course') {
@@ -1643,6 +1725,7 @@ sub print_userlist {
}
$r->print(' ');
+ return;
}
sub role_filter {
@@ -1655,11 +1738,11 @@ sub role_filter {
my ($role_select);
if ($context eq 'domain') {
$role_select = &domain_roles_select();
- $output = ''
+ $output = ''
.&mt('Role Type: [_1]',$role_select)
- .' ';
+ .'';
} else {
- $role_select = ''."\n".
+ $role_select = ''."\n".
''.
&mt('Any role').' ';
my ($roletype,$crstype);
@@ -1686,9 +1769,9 @@ sub role_filter {
$role_select .= ''.$plrole.' ';
}
$role_select .= ' ';
- $output = ''
+ $output = ''
.&mt('Role: [_1]',$role_select)
- .' ';
+ .'';
}
return $output;
}
@@ -1728,7 +1811,7 @@ sub section_group_filter {
}
if (@options > 0) {
my $currsel;
- $markup = ' '."\n";
+ $markup = ''."\n";
foreach my $option ('all','none',@options) {
$currsel = '';
if ($env{'form.'.$name{$item}} eq $option) {
@@ -1743,17 +1826,175 @@ sub section_group_filter {
$markup .= ''."\n";
}
$markup .= ' '."\n";
- $output .= (' 'x3).''.$title{$item}.': '.$markup.' ';
+ $output .= (' 'x3).''
+ .''.$title{$item}.': '.$markup.' '
+ .' ';
}
}
return $output;
}
+sub infocolumns {
+ my ($context,$mode) = @_;
+ my @cols;
+ if (($mode eq 'pickauthor') || ($mode eq 'autoenroll')) {
+ @cols = &get_cols_array($context,$mode);
+ } else {
+ my @posscols = &get_cols_array($context,$mode);
+ if ($env{'form.phase'} ne '') {
+ my @checkedcols = &Apache::loncommon::get_env_multiple('form.showcol');
+ foreach my $col (@checkedcols) {
+ if (grep(/^$col$/,@posscols)) {
+ push(@cols,$col);
+ }
+ }
+ } else {
+ @cols = @posscols;
+ }
+ }
+ return @cols;
+}
+
+sub get_cols_array {
+ my ($context,$mode) = @_;
+ my @cols;
+ if ($mode eq 'pickauthor') {
+ @cols = ('username','fullname','status','email');
+ } else {
+ @cols = ('username','domain','id','fullname');
+ if ($context eq 'course') {
+ push(@cols,'section');
+ }
+ push(@cols,('start','end','role'));
+ if ($context eq 'domain') {
+ push (@cols,'extent');
+ }
+ unless (($mode eq 'autoenroll') && ($env{'form.Status'} ne 'Any')) {
+ push(@cols,'status');
+ }
+ if ($context eq 'course') {
+ push(@cols,'groups');
+ }
+ push(@cols,'email');
+ if (($context eq 'course') && ($mode ne 'autoenroll')) {
+ push(@cols,'lastlogin','clicker');
+ }
+ if (($context eq 'course') && ($mode ne 'autoenroll') &&
+ ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
+ push(@cols,'photos');
+ }
+ }
+ return @cols;
+}
+
+sub column_checkboxes {
+ my ($context,$mode,$formname) = @_;
+ my @cols = &get_cols_array($context,$mode);
+ my @showncols = &Apache::loncommon::get_env_multiple('form.showcol');
+ my (%disabledchk,%unchecked);
+ if ($env{'form.phase'} eq '') {
+ $disabledchk{'status'} = 1;
+ if ($context eq 'course') {
+ $disabledchk{'role'} = 1;
+ $unchecked{'photo'} = 1;
+ }
+ $unchecked{'clicker'} = 1;
+ $unchecked{'start'} = 1;
+ $unchecked{'end'} = 1;
+ } else {
+ if ($env{'form.Status'} ne 'Any') {
+ $disabledchk{'status'} = 1;
+ }
+ if ($env{'form.showrole'} ne 'Any') {
+ $disabledchk{'role'} = 1;
+ }
+ }
+ my $numposs = scalar(@cols);
+ my $numinrow = 8;
+ my %lt = &get_column_names($context);
+ my $output = ''.&mt('Information to show').' '."\n".''.
+ ' '.
+ (' 'x3).
+ ' '.
+ ' ';
+ return $output;
+}
+
sub list_submit_button {
my ($text) = @_;
return ' ';
}
+sub get_column_names {
+ my ($context) = @_;
+ my %lt = &Apache::lonlocal::texthash(
+ 'username' => "username",
+ 'domain' => "domain",
+ 'id' => 'ID',
+ 'fullname' => "name",
+ 'section' => "section",
+ 'groups' => "active groups",
+ 'start' => "start date",
+ 'end' => "end date",
+ 'status' => "status",
+ 'role' => "role",
+ 'type' => "enroll type/action",
+ 'email' => "e-mail address",
+ 'photo' => "photo",
+ 'lastlogin' => "last login",
+ 'extent' => "extent",
+ 'ca' => "check all",
+ 'ua' => "uncheck all",
+ 'clicker' => "clicker-ID",
+ );
+ if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
+ $lt{'extent'} = &mt('Course(s): description, section(s), status');
+ } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
+ $lt{'extent'} = &mt('Communities: description, section(s), status');
+ } elsif ($context eq 'author') {
+ $lt{'extent'} = &mt('Author');
+ }
+ return %lt;
+}
+
sub gather_userinfo {
my ($context,$format,$userlist,$indexhash,$userinfo,$rolehash,$permission) = @_;
my $viewablesec;
@@ -1917,7 +2158,7 @@ function setCourseCat(formname) {
if (formname.Year.options[formname.Year.selectedIndex].value == -1) {
return;
}
- courseSet('Year');
+ courseSet('$codetitles[0]');
for (var j=0; jprint('
');
}
- $r->print(<
-
-END
}
} elsif ($context eq 'domain') {
if ($setting eq 'community') {
@@ -2163,14 +2392,12 @@ END
}
}
if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
- my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
my $verify_action_js = &bulkaction_javascript($formname);
$r->print(<
// print(<
END
-
- my %lt=&Apache::lonlocal::texthash(
- 'username' => "username",
- 'domain' => "domain",
- 'id' => 'ID',
- 'fullname' => "name",
- 'section' => "section",
- 'groups' => "active groups",
- 'start' => "start date",
- 'end' => "end date",
- 'status' => "status",
- 'role' => "role",
- 'type' => "enroll type/action",
- 'email' => "e-mail address",
- 'photo' => "photo",
- 'extent' => "extent",
+ my @cols = &infocolumns($context,$mode);
+ my %coltxt = &get_column_names($context);
+ my %acttxt = &Apache::lonlocal::texthash(
'pr' => "Proceed",
- 'ca' => "check all",
- 'ua' => "uncheck all",
'ac' => "Action to take for selected users",
'link' => "Behavior of clickable username link for each user",
'aboutme' => "Display a user's personal information page",
'owin' => "Open in a new window",
'modify' => "Modify a user's information",
'track' => "View a user's recent activity",
- 'clicker' => "Clicker-ID",
);
- if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
- $lt{'extent'} = &mt('Course(s): description, section(s), status');
- } elsif ($context eq 'domain' && $env{'form.roletype'} eq 'community') {
- $lt{'extent'} = &mt('Communities: description, section(s), status');
- } elsif ($context eq 'author') {
- $lt{'extent'} = &mt('Author');
- }
- my @cols;
- if ($mode eq 'pickauthor') {
- @cols = ('username','fullname','status','email');
- } else {
- @cols = ('username','domain','id','fullname');
- if ($context eq 'course') {
- push(@cols,'section');
- }
- if (!($context eq 'domain' && ($env{'form.roletype'} eq 'course')
- && ($env{'form.roletype'} eq 'community'))) {
- push(@cols,('start','end'));
- }
- if ($env{'form.showrole'} eq 'Any' || $env{'form.showrole'} eq 'cr') {
- push(@cols,'role');
- }
- if ($context eq 'domain' && ($env{'form.roletype'} eq 'author' ||
- $env{'form.roletype'} eq 'course' ||
- $env{'form.roletype'} eq 'community')) {
- push (@cols,'extent');
- }
- if (($statusmode eq 'Any') &&
- (!($context eq 'domain' && (($env{'form.roletype'} eq 'course')
- || ($env{'form.roletype'} eq 'community'))))) {
- push(@cols,'status');
- }
- if ($context eq 'course') {
- push(@cols,'groups');
- }
- push(@cols,'email');
- }
-
+ my %lt = (%coltxt,%acttxt);
my $rolefilter = $env{'form.showrole'};
if ($env{'form.showrole'} eq 'cr') {
$rolefilter = &mt('custom');
@@ -2303,7 +2477,7 @@ END
if ($mode ne 'autoenroll') {
$results_description = &results_header_row($rolefilter,$statusmode,
$context,$permission,$mode,$crstype);
- $r->print(''.$results_description.' ');
+ $r->print(''.$results_description.' ');
}
my ($output,$actionselect,%canchange,%canchangesec);
if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
@@ -2399,7 +2573,7 @@ END
}
$output .= ' '.$lt{'owin'}.' ';
}
- $output .= "\n".''."\n".
+ $output .= "\n".' '."\n".
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row();
if ($mode eq 'autoenroll') {
@@ -2416,42 +2590,6 @@ END
$output .= "$lt{$item} \n";
}
my %role_types = &role_type_names();
- if ($context eq 'course' && $mode ne 'autoenroll') {
- if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
- # Clicker display on or off?
- my %clicker_options = (
- 'on' => 'Show',
- 'off' => 'Hide',
- );
- my $clickerchg = 'on';
- if ($displayclickers eq 'on') {
- $clickerchg = 'off';
- }
- $output .= ' '."\n".' '
- .&mt('[_1]'.$clicker_options{$clickerchg}.'[_2] clicker id'
- ,''
- ,' ')
- ."\n".' '."\n";
-
- # Photo display on or off?
- if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
- my %photo_options = &Apache::lonlocal::texthash(
- 'on' => 'Show',
- 'off' => 'Hide',
- );
- my $photochg = 'on';
- if ($displayphotos eq 'on') {
- $photochg = 'off';
- }
- $output .= ' '."\n".' '.
- ''.
- $photo_options{$photochg}.' '.$lt{'photo'}."\n".
- ' '."\n";
- }
- }
- }
$output .= &Apache::loncommon::end_data_table_header_row();
# Done with the HTML header line
} elsif ($mode eq 'csv') {
@@ -2472,14 +2610,12 @@ END
$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";
} elsif ($mode eq 'excel') {
- push @cols,'clicker';
# Create the excel spreadsheet
($excel_workbook,$excel_filename,$format) =
&Apache::loncommon::create_workbook($r);
@@ -2515,6 +2651,11 @@ END
Future => 'Future',
Expired => 'Expired',
);
+ # If this is for a single course get last course "log-in".
+ my %crslogins;
+ if ($context eq 'course') {
+ %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
+ }
# Get groups, role, permanent e-mail so we can sort on them if
# necessary.
foreach my $user (keys(%{$userlist})) {
@@ -2598,7 +2739,7 @@ END
}
}
if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
- if (($displayphotos eq 'on') && ($role eq 'st')) {
+ if ((grep/^photo$/,@cols) && ($role eq 'st')) {
$userlist->{$user}->[$index{'photo'}] =
&Apache::lonnet::retrievestudentphoto($udom,$uname,'jpg');
$userlist->{$user}->[$index{'thumbnail'}] =
@@ -2651,15 +2792,23 @@ END
$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 {
- $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
+ unless ($mode eq 'excel') {
+ if (! defined($in{'start'}) || $in{'start'} == 0) {
+ $in{'start'} = &mt('none');
+ } else {
+ $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
+ }
+ if (! defined($in{'end'}) || $in{'end'} == 0) {
+ $in{'end'} = &mt('none');
+ } else {
+ $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
+ }
}
- if (! defined($in{'end'}) || $in{'end'} == 0) {
- $in{'end'} = &mt('none');
- } else {
- $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
+ if ($context eq 'course') {
+ my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
+ if ($lastlogin ne '') {
+ $in{'lastlogin'} = &Apache::lonlocal::locallocaltime($lastlogin);
+ }
}
if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
$r->print(&Apache::loncommon::start_data_table_row());
@@ -2734,43 +2883,34 @@ END
$showitem = $ltstatus{$in{$item}};
}
$r->print(''.$showitem.' '."\n");
- } else {
- $r->print(''.$in{$item}.' '."\n");
- }
- }
- if (($context eq 'course') && ($mode ne 'autoenroll')) {
- if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
- if ($displayclickers eq 'on') {
- my $clickers =
+ } elsif ($item eq 'photo') {
+ if (($context eq 'course') && ($mode ne 'autoenroll') &&
+ ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'})) {
+ if ($role eq 'st') {
+ $r->print(' ');
+ } else {
+ $r->print(' ');
+ }
+ }
+ } elsif ($item eq 'clicker') {
+ if (($context eq 'course') && ($mode ne 'autoenroll')) {
+ if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
+ my $clickers =
(&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
- if ($clickers!~/\w/) { $clickers='-'; }
- $r->print(''.$clickers.' ');
- } else {
- $r->print(' ');
- }
- if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
- if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
- $r->print(' ');
+ if ($clickers!~/\w/) { $clickers='-'; }
+ $r->print(''.$clickers.' ');
} else {
- $r->print(' ');
- }
- }
+ $r->print(' '."\n");
+ }
+ }
+ } else {
+ $r->print(''.$in{$item}.' '."\n");
}
}
$r->print(&Apache::loncommon::end_data_table_row());
} elsif ($mode eq 'csv') {
next if (! defined($CSVfile));
# no need to bother with $linkto
- if (! defined($in{'start'}) || $in{'start'} == 0) {
- $in{'start'} = &mt('none');
- } else {
- $in{'start'} = &Apache::lonlocal::locallocaltime($in{'start'});
- }
- if (! defined($in{'end'}) || $in{'end'} == 0) {
- $in{'end'} = &mt('none');
- } else {
- $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
- }
my @line = ();
foreach my $item (@cols) {
push @line,&Apache::loncommon::csv_translate($in{$item});
@@ -2780,9 +2920,9 @@ END
my $col = 0;
foreach my $item (@cols) {
if ($item eq 'start' || $item eq 'end') {
- if (defined($item) && $item != 0) {
+ if ((defined($in{$item})) && ($in{$item} != 0)) {
$excel_sheet->write($row,$col++,
- &Apache::lonstathelpers::calc_serial($in{item}),
+ &Apache::lonstathelpers::calc_serial($in{$item}),
$format->{'date'});
} else {
$excel_sheet->write($row,$col++,'none');
@@ -2937,7 +3077,7 @@ sub print_username_link {
$output = $in->{'username'};
} else {
$output = '{'username'}','$in->{'domain'}'".')" />'.
+ "'$in->{'username'}','$in->{'domain'}'".')">'.
$in->{'username'}.' ';
}
return $output;
@@ -3167,9 +3307,9 @@ ENDJS
my %lt = &Apache::lonlocal::texthash (
chac => 'Access dates to apply for selected users',
chse => 'Changes in section affiliation to apply to selected users',
- fors => 'For student roles changing the section, will result in a section switch as students may only be in one section of a course at a time.',
- forn => 'For a role in a course that is not a student role, a user may have roles in more than one section of a course at a time.',
- reta => "Retain each user's current section affiliations?",
+ fors => 'For student roles, changing the section will result in a section switch as students may only be in one section of a course at a time.',
+ forn => 'For a course role that is not "student", users may have roles in more than one section at a time.',
+ reta => "Retain each user's current section affiliations?",
dnap => '(Does not apply to student roles).',
);
my ($date_items,$headertext);
@@ -3187,14 +3327,13 @@ ENDJS
$permission,$crstype);
}
$output .= ''.$headertext.' '.
- ''."\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) = @_;
my ($cdom,$cnum) = ($scope=~m{^/($match_domain)/($match_courseid)});
@@ -4819,7 +5121,7 @@ sub setsections_javascript {
accr => 'A course coordinator role will be added with access to all sections.',
acor => 'A coordinator role will be added with access to all sections',
inea => 'In each course, each user may only have one student role at a time.',
- inec => 'In each community, each user may only have on member role at a time.',
+ inco => 'In each community, each user may only have one member role at a time.',
youh => 'You had selected ',
secs => 'sections.',
plmo => 'Please modify your selections so they include no more than one section.',
@@ -4827,16 +5129,21 @@ sub setsections_javascript {
plch => 'Please choose a different section name.',
mnot => 'may not be used as a section name, as it is the name of a course group.',
secn => 'Section names and group names must be distinct. Please choose a different section name.',
+ nonw => 'Section names may only contain letters or numbers.',
);
$setsection_js .= <<"ENDSECCODE";
function setSections(formname,crstype) {
var re1 = /^currsec_/;
+ var re2 =/\\W/;
+ var trimleading = /^\\s+/;
+ var trimtrailing = /\\s+\$/;
var groups = new Array($groupslist);
for (var i=0;i 0) {
- if (formname.elements[i+1].value != "" && formname.elements[i+1].value != null) {
- sections = sections + "," + formname.elements[i+1].value;
- }
- }
- else {
- sections = formname.elements[i+1].value;
- }
- var newsecs = formname.elements[i+1].value;
- var numsplit;
+ var newsecs = formname.elements[num+1].value;
+ var validsecs = new Array();
+ var validsecstr = '';
+ var badsecs = new Array();
if (newsecs != null && newsecs != "") {
- numsplit = newsecs.split(/,/g);
- numsec = numsec + numsplit.length;
+ var numsplit;
+ if (newsecs.indexOf(',') == -1) {
+ numsplit = new Array(newsecs);
+ } else {
+ numsplit = newsecs.split(/,/g);
+ }
+ for (var m=0; m 0) {
+ alert("$alerts{'nonw'}\\n$alerts{'plch'}");
+ return;
+ }
+ numsec = numsec + validsecs.length;
}
-
if ((role == 'st') && (numsec > 1)) {
if (crstype == 'Community') {
alert("$alerts{'inea'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
@@ -4887,25 +5216,36 @@ function setSections(formname,crstype) {
alert("$alerts{'inco'} $alerts{'youh'} "+numsec+" $alerts{'secs'}\\n$alerts{'plmo'}");
}
return;
- }
- else {
- if (numsplit != null) {
- for (var j=0; j 0) {
- my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
- if (keys(%rule_check) > 0) {
- $usertype = 'unofficial';
- foreach my $item (keys(%rule_check)) {
- if ($rule_check{$item}) {
- $usertype = 'official';
- last;
+ if ((ref($got_rules) eq 'HASH') && (ref($curr_rules) eq 'HASH')) {
+ if (!$got_rules->{$dom}) {
+ my %domconfig = &Apache::lonnet::get_dom('configuration',
+ ['usercreation'],$dom);
+ if (ref($domconfig{'usercreation'}) eq 'HASH') {
+ foreach my $item ('username','id') {
+ if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
+ $curr_rules->{$dom}{$item} =
+ $domconfig{'usercreation'}{$item.'_rule'};
+ }
+ }
+ }
+ $got_rules->{$dom} = 1;
+ }
+ if (ref($rules) eq 'HASH') {
+ my @user_rules;
+ if (ref($curr_rules->{$dom}{'username'}) eq 'ARRAY') {
+ foreach my $rule (keys(%{$rules})) {
+ if (grep(/^\Q$rule\E/,@{$curr_rules->{$dom}{'username'}})) {
+ push(@user_rules,$rule);
+ }
+ }
+ }
+ if (@user_rules > 0) {
+ my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
+ if (keys(%rule_check) > 0) {
+ $usertype = 'unofficial';
+ foreach my $item (keys(%rule_check)) {
+ if ($rule_check{$item}) {
+ $usertype = 'official';
+ last;
+ }
}
}
}