--- loncom/interface/lonuserutils.pm 2008/04/30 23:16:19 1.52
+++ loncom/interface/lonuserutils.pm 2008/10/07 19:40:39 1.71
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.52 2008/04/30 23:16:19 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.71 2008/10/07 19:40:39 droeschl Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -169,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'},
@@ -180,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].':';
}
@@ -319,8 +341,8 @@ sub print_upload_manager_header {
&hidden_input('fileupload',$env{'form.fileupload'}).
&hidden_input('upfiletype',$env{'form.upfiletype'}).
&hidden_input('upfile_associate',$env{'form.upfile_associate'}));
- $r->print(' print(' ');
$r->print('');
@@ -383,12 +405,13 @@ sub javascript_validations {
section => 'The optional section field was not specified.',
email => 'The optional email address field was not specified.',
role => 'The optional role field was not specified.',
+ domain => 'The optional domain field was not specified.',
continue => 'Continue adding users?',
);
my $function_name = <<"END";
$setsections_js
-function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail) {
+function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain) {
END
my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
my $auth_checks;
@@ -503,6 +526,18 @@ END
}
message+='$alert{'email'}';
}
+ if (foundrole==0) {
+ if (message!='') {
+ message+='\\n';
+ }
+ message+='$alert{'role'}';
+ }
+ if (founddomain==0) {
+ if (message!='') {
+ message+='\\n';
+ }
+ message+='$alert{'domain'}';
+ }
if (message!='') {
message+= '\\n$alert{'continue'}';
if (confirm(message)) {
@@ -532,6 +567,7 @@ function verify(vf,sec_caller) {
var foundsec=0;
var foundemail=0;
var foundrole=0;
+ var founddomain=0;
var tw;
for (i=0;i<=vf.nfields.value;i++) {
tw=eval('vf.f'+i+'.selectedIndex');
@@ -542,8 +578,9 @@ function verify(vf,sec_caller) {
if (tw==9) { foundpwd=1; }
if (tw==10) { foundemail=1; }
if (tw==11) { foundrole=1; }
+ if (tw==12) { founddomain=1; }
}
- verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole);
+ verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain);
}
//
@@ -564,6 +601,7 @@ function verify(vf,sec_caller) {
// 9 = ipwd (password)
// 10 = email address
// 11 = role
+// 12 = domain
function flip(vf,tf) {
var nw=eval('vf.f'+tf+'.selectedIndex');
@@ -627,6 +665,7 @@ function verify(vf,sec_caller) {
var foundid=0;
var foundsec=0;
var foundrole=0;
+ var founddomain=0;
var tw;
for (i=0;i<=vf.nfields.value;i++) {
tw=eval('vf.f'+i+'.selectedIndex');
@@ -636,8 +675,9 @@ function verify(vf,sec_caller) {
if (i==7 && tw!=0) { foundsec=1; }
if (i==8 && tw!=0) { foundpwd=1; }
if (i==9 && tw!=0) { foundrole=1; }
+ if (i==10 && tw!=0) { founddomain=1; }
}
- verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole);
+ verify_message(vf,founduname,foundpwd,foundname,foundid,foundsec,foundrole,founddomain);
}
function flip(vf,tf) {
@@ -700,7 +740,7 @@ sub print_upload_manager_footer {
$Str .= &hidden_input('keyfields',$keyfields);
$Str .= "
".&mt('Login Type')."
\n";
if ($context eq 'domain') {
- $Str .= '
'.&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').
@@ -718,6 +758,8 @@ sub print_upload_manager_footer {
} else {
$Str .= $home_server_pick;
}
+ $Str .= '
\n";
@@ -757,10 +799,9 @@ sub print_upload_manager_footer {
}
$Str .= '';
$r->print($Str);
@@ -770,15 +811,15 @@ sub print_upload_manager_footer {
sub forceid_change {
my ($context) = @_;
my $output =
- "
".&mt('ID/Student Number')."
\n".
+ "
".&mt('Student/Employee ID')."
\n".
"
\n".' '."\n".
+ &mt('Disable Student/Employee ID Safeguard and force change of conflicting IDs').
+ ' '."\n".
&mt('(only do if you know what you are doing.)')."\n";
if ($context eq 'domain') {
$output .= ' '."\n";
}
$output .= '
';
@@ -818,6 +859,7 @@ sub print_upload_manager_form {
'ipwd_choice' => 'scalar',
'email_choice' => 'scalar',
'role_choice' => 'scalar',
+ 'domain_choice' => 'scalar',
};
my $defdom = $env{'request.role.domain'};
if ($context eq 'course') {
@@ -844,11 +886,12 @@ sub print_upload_manager_form {
['mname',&mt('Middle Names/Initials'),$env{'form.mname_choice'}],
['lname',&mt('Last Name'), $env{'form.lname_choice'}],
['gen', &mt('Generation'), $env{'form.gen_choice'}],
- ['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
+ ['id', &mt('Student/Employee ID'),$env{'form.id_choice'}],
['sec', &mt('Section'), $env{'form.sec_choice'}],
['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
['email',&mt('E-mail Address'), $env{'form.email_choice'}],
- ['role',&mt('Role'), $env{'form.role_choice'}]);
+ ['role',&mt('Role'), $env{'form.role_choice'}],
+ ['domain',&mt('Domain'), $env{'form.domain_choice'}]);
if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,
@@ -925,8 +968,15 @@ sub setup_date_selectors {
sub get_dates_from_form {
- my $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate');
- my $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate');
+ my ($startname,$endname) = @_;
+ if ($startname eq '') {
+ $startname = 'startdate';
+ }
+ if ($endname eq '') {
+ $endname = 'enddate';
+ }
+ my $startdate = &Apache::lonhtmlcommon::get_date_from_form($startname);
+ my $enddate = &Apache::lonhtmlcommon::get_date_from_form($endname);
if ($env{'form.no_end_date'}) {
$enddate = 0;
}
@@ -959,7 +1009,7 @@ sub date_setting_table {
}
my $perpetual = '';
if ($mode eq 'create_enrolldates') {
@@ -1245,41 +1295,22 @@ sub print_userlist {
$output_selector .= "\n".$option;
}
$output_selector .= '';
- $r->print(''.(' 'x3));
- }
- $r->print(''.(' 'x3)."\n");
+ $r->print(''.(' 'x3));
+ }
+ $r->print(''.(' 'x3)."\n");
my $roleselected = '';
if ($env{'form.showrole'} eq 'Any') {
$roleselected = ' selected="selected" ';
}
- my ($role_select,$cnum,$cdom);
- if ($context eq 'domain') {
- $role_select = &domain_roles_select();
- $r->print('');
- } else {
- $role_select = '';
- $r->print('');
- if ($context eq 'course') {
- ($cnum,$cdom) = &get_course_identity();
- $r->print(§ion_group_filter($cnum,$cdom));
- }
+ my ($cnum,$cdom);
+ $r->print(&role_filter($context));
+ if ($context eq 'course') {
+ ($cnum,$cdom) = &get_course_identity();
+ $r->print(§ion_group_filter($cnum,$cdom));
}
if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
$r->print(' '.&list_submit_button(&mt('Update Display')).
@@ -1310,7 +1341,9 @@ sub print_userlist {
if ($context eq 'course') {
if (($env{'form.showrole'} eq 'st') || ($env{'form.showrole'} eq 'Any')) {
my $classlist = &Apache::loncoursedata::get_classlist();
- %userlist = %{$classlist};
+ if (ref($classlist) eq 'HASH') {
+ %userlist = %{$classlist};
+ }
}
if ($env{'form.showrole'} ne 'st') {
my $showroles;
@@ -1451,6 +1484,45 @@ sub print_userlist {
$env{'form.phase'}.'" />');
}
+sub role_filter {
+ my ($context) = @_;
+ my $output;
+ my $roleselected = '';
+ if ($env{'form.showrole'} eq 'Any') {
+ $roleselected = ' selected="selected" ';
+ }
+ my ($role_select);
+ if ($context eq 'domain') {
+ $role_select = &domain_roles_select();
+ $output = '';
+ } else {
+ $role_select = '';
+ $output = '';
+ }
+ return $output;
+}
+
sub section_group_filter {
my ($cnum,$cdom) = @_;
my @filters;
@@ -1844,7 +1916,10 @@ sub process_date_info {
}
sub show_users_list {
- my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist)=@_;
+ my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;
+ if ($formname eq '') {
+ $formname = 'studentform';
+ }
#
# Variables for excel output
my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
@@ -1859,6 +1934,9 @@ sub show_users_list {
} else {
push(@sortable,'extent');
}
+ if ($mode eq 'pickauthor') {
+ @sortable = ('username','fullname','email','status');
+ }
if (!grep(/^\Q$sortby\E$/,@sortable)) {
$sortby = 'username';
}
@@ -1899,121 +1977,41 @@ function photowindow(photolink) {
END
}
}
- if ($mode ne 'autoenroll') {
+ if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
- my $alert = &mt("You must select at least one user by checking a user's 'Select' checkbox");
- my $singconfirm = &mt(' for a single user?');
- my $multconfirm = &mt(' for multiple users?');
my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode);
- 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 $verify_action_js = &bulkaction_javascript($formname);
$r->print(<
$check_uncheck_js
-function verify_action (field) {
- var numchecked = 0;
- var singconf = '$singconfirm';
- var multconf = '$multconfirm';
- if (field.length > 0) {
- for (i = 0; i < field.length; i++) {
- if (field[i].checked == true) {
- numchecked ++;
- }
- }
- } else {
- if (field.checked == true) {
- numchecked ++;
- }
- }
- if (numchecked == 0) {
- alert("$alert");
- }
- else {
- var message = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].text;
- var choice = document.studentform.bulkaction[document.studentform.bulkaction.selectedIndex].value;
- if (numchecked == 1) {
- message += singconf;
- }
- else {
- message += multconf;
- }
- if (choice == 'chgdates' || choice == 'reenable' || choice == 'activate') {
- var datemsg = '';
- if ((document.studentform.startdate_month.value == '') &&
- (document.studentform.startdate_day.value == '') &&
- (document.studentform.startdate_year.value == '')) {
- datemsg = "\\n$lt{'acwi'},\\n$lt{'asyo'}.\\n";
- }
- if ((document.studentform.enddate_month.value == '') &&
- (document.studentform.enddate_day.value == '') &&
- (document.studentform.enddate_year.value == '')) {
- datemsg += "\\n$lt{'accw'},\\n$lt{'asyd'}.\\n";
- }
- if (datemsg != '') {
- message += "\\n"+datemsg;
- }
- }
- if (choice == 'chgsec') {
- var rolefilter = document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value;
- var retained = document.studentform.retainsec.value;
- var secshow = document.studentform.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)) {
- document.studentform.phase.value = 'bulkchange';
- document.studentform.submit();
- }
- }
-}
+$verify_action_js
function username_display_launch(username,domain) {
var target;
- for (var i=0; i "role",
'type' => "enroll type/action",
'email' => "email address",
- 'clicker' => "clicker id",
'photo' => "photo",
'extent' => "extent",
- 'go' => "go",
'pr' => "Proceed",
'ca' => "check all",
'ua' => "uncheck all",
'ac' => "Action to take for selected users",
- 'link' => "Behavior of username links",
+ 'link' => "Behavior of clickable username link for each user",
'aboutme' => "Display a user's personal page",
'owin' => "Open in a new window",
'modify' => "Modify a user's information",
+ 'clicker' => "Clicker-ID",
);
if ($context eq 'domain' && $env{'form.roletype'} eq 'course') {
$lt{'extent'} = &mt('Course(s): description, section(s), status');
} elsif ($context eq 'author') {
$lt{'extent'} = &mt('Author');
}
- my @cols = ('username','domain','id','fullname');
- if ($context eq 'course') {
- push(@cols,'section');
- }
- if (!($context eq 'domain' && $env{'form.roletype'} eq 'course')) {
- 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')) {
- push (@cols,'extent');
- }
- if (($statusmode eq 'Any') &&
- (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
- push(@cols,'status');
- }
- if ($context eq 'course') {
- push(@cols,'groups');
+ 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')) {
+ 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')) {
+ push (@cols,'extent');
+ }
+ if (($statusmode eq 'Any') &&
+ (!($context eq 'domain' && $env{'form.roletype'} eq 'course'))) {
+ push(@cols,'status');
+ }
+ if ($context eq 'course') {
+ push(@cols,'groups');
+ }
+ push(@cols,'email');
}
- push(@cols,'email');
my $rolefilter = $env{'form.showrole'};
if ($env{'form.showrole'} eq 'cr') {
@@ -2097,13 +2099,13 @@ END
if ($mode ne 'autoenroll') {
$results_description = &results_header_row($rolefilter,$statusmode,
$context,$permission,$mode);
- $r->print(''.$results_description.' ');
+ $r->print(''.$results_description.'
');
}
my ($output,$actionselect,%canchange,%canchangesec);
- if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') {
- if ($mode ne 'autoenroll') {
+ if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
+ if ($mode ne 'autoenroll' && $mode ne 'pickauthor') {
if ($permission->{'cusr'}) {
- $actionselect = &select_actions($context,$setting,$statusmode);
+ $actionselect = &select_actions($context,$setting,$statusmode,$formname);
}
$r->print(<
@@ -2112,33 +2114,12 @@ END
END
- $output = '
';
- my @linkdests = ('aboutme');
- if ($permission->{'cusr'}) {
- unshift (@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 .= ' ';
- }
- my $checkwin;
- if ($env{'form.userwin'}) {
- $checkwin = 'checked = "checked"';
- }
- $output .= ' '.$lt{'owin'}.' ';
if ($actionselect) {
$output .= <<"END";
-$lt{'ac'}: $actionselect
-
-
+
END
my @allroles;
if ($env{'form.showrole'} eq 'Any') {
@@ -2180,40 +2161,68 @@ END
}
}
}
+ $output .= '';
}
- $output .= "\n