--- loncom/interface/lonuserutils.pm 2009/02/17 10:12:37 1.80
+++ loncom/interface/lonuserutils.pm 2009/09/07 13:49:49 1.97.2.2
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.80 2009/02/17 10:12:37 weissno Exp $
+# $Id: lonuserutils.pm,v 1.97.2.2 2009/09/07 13:49:49 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -86,7 +86,7 @@ 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;
@@ -124,7 +124,7 @@ 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;
@@ -328,9 +328,11 @@ sub print_upload_manager_header {
&javascript_validations('upload',$krbdefdom,$password_choice,undef,
$env{'request.role.domain'},$context,
$groupslist);
- my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':'');
- $r->print(&mt('Total number of records found in file: [_1]',''.$distotal.' ').
- " \n");
+ my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
+ $r->print('
'
+ .&mt('Total number of records found in file: [_1]'
+ ,''.$distotal.' ')
+ ."
\n");
$r->print(''.
&mt('Identify fields in uploaded list')." \n");
$r->print(&mt('Enter as many fields as you can.
The system will inform you and bring you back to this page,
if the data selected are insufficient to add users.')."
\n");
@@ -341,14 +343,17 @@ 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('
'.
+ $r->print(' '.
&mt('Ignore First Line').' ');
$r->print(' ');
+ 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
$r->print(" \n".
'');
+ '// '."\n".
+ '');
}
###############################################################
@@ -401,17 +406,20 @@ sub javascript_validations {
krb => 'You need to specify the Kerberos domain.',
ipass => 'You need to specify the initial password.',
name => 'The optional name field was not specified.',
- snum => 'The optional ID number field was not specified.',
+ snum => 'The optional student/employee ID field was not specified.',
section => 'The optional section field was not specified.',
email => 'The optional e-mail 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?',
);
+ if (($mode eq 'upload') && ($context eq 'domain')) {
+ $alert{'inststatus'} = &mt('The optional affiliation field was not specified');
+ }
my $function_name = <<"END";
$setsections_js
-function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain) {
+function verify_message (vf,founduname,foundpwd,foundname,foundid,foundsec,foundemail,foundrole,founddomain,foundinststatus) {
END
my ($authnum,%can_assign) = &Apache::loncommon::get_assignable_auth($domain);
my $auth_checks;
@@ -538,6 +546,20 @@ END
}
message+='$alert{'domain'}';
}
+END
+ if (($mode eq 'upload') && ($context eq 'domain')) {
+ $optional_checks .= (<';
$Str .= &hidden_input('nfields',$i);
$Str .= &hidden_input('keyfields',$keyfields);
- $Str .= "".&mt('Login Type')." \n";
+
+ $Str .= ''.&mt('Options').' '
+ .&Apache::lonhtmlcommon::start_pick_box();
+
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Login Type'));
if ($context eq 'domain') {
- $Str .= ''.&mt('Change authentication for existing users in domain "[_1]" to these settings?',$defdom).' '.&mt('No').' '.&mt('Yes').'
';
+ $Str .= ''
+ .&mt('Change authentication for existing users in domain "[_1]" to these settings?'
+ ,$defdom)
+ .' '
+ .' '
+ .&mt('No').' '
+ .' '
+ .' '
+ .&mt('Yes').' '
+ .'
';
} 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 .= ''.&mt('LON-CAPA Home Server for New Users')." \n".
- &mt('LON-CAPA domain: [_1] with home server: [_2]',$defdom,
- $home_server_pick).' ';
- } else {
- $Str .= $home_server_pick;
- }
- $Str .= ''.&mt('Default domain').' '."\n".
- &Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1);
- $Str .= ''.&mt('Starting and Ending Dates').
- " \n";
- $Str .= "\n".$date_table."
\n";
+ $Str .= &Apache::lonhtmlcommon::row_closure()
+ .&Apache::lonhtmlcommon::row_title(
+ &mt('LON-CAPA Home Server for New Users'))
+ .&mt('LON-CAPA domain: [_1] with home server:','"'.$defdom.'"')
+ .$home_server_pick
+ .&Apache::lonhtmlcommon::row_closure();
+ } else {
+ $Str .= $home_server_pick.
+ &Apache::lonhtmlcommon::row_closure();
+ }
+
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
+ .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1)
+ .&Apache::lonhtmlcommon::row_closure();
+
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
+ ."\n".$date_table."
\n"
+ .&Apache::lonhtmlcommon::row_closure();
+
if ($context eq 'domain') {
- $Str .= ''.&mt('Settings for assigning roles:').' '."\n".
- &mt('Pick the action to take on roles for these users:').' '.&mt('No role changes').' '.&mt('Add a domain role').' '.&mt('Add a course role').' ';
- }
- if ($context eq 'author') {
- $Str .= ''.&mt('Default role')." \n".
- &mt('Choose the role to assign to users without a value specified in the uploaded file');
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Settings for assigning roles'))
+ .&mt('Pick the action to take on roles for these users:').' '
+ .''
+ .' '
+ .' '.&mt('No role changes').' '
+ .' '
+ .' '
+ .' '.&mt('Add a domain role').' '
+ .' '
+ .' '
+ .' '.&mt('Add a course role').' '
+ .' ';
+ } elsif ($context eq 'author') {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role'))
+ .&mt('Choose the role to assign to users without a value specified in the uploaded file.')
} elsif ($context eq 'course') {
- $Str .= ''.&mt('Default role and section')." \n".
- &mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file');
- } else {
- $Str .= ''.&mt('Default role and/or section(s)')." \n".
- &mt('Role and/or section(s) for users without values specified in the uploaded file.');
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role and section'))
+ .&mt('Choose the role and/or section(s) to assign to users without values specified in the uploaded file.');
+ } else {
+ $Str .= &Apache::lonhtmlcommon::row_title(
+ &mt('Default role and/or section(s)'))
+ .&mt('Role and/or section(s) for users without values specified in the uploaded file.');
}
- $Str .= ' ';
if (($context eq 'domain') || ($context eq 'author')) {
+ $Str .= ' ';
my ($options,$cb_script,$coursepick) = &default_role_selector($context,1);
if ($context eq 'domain') {
- $Str .= ''.&mt('Domain Level').' '.$options.''.&mt('Course Level').' '.$cb_script.$coursepick;
+ $Str .= ''
+ .''.&mt('Domain Level').' '
+ .$options
+ .'
'
+ .''.&mt('Course Level').' '
+ .'
'
+ .$cb_script.$coursepick
+ .&Apache::lonhtmlcommon::row_closure();
} elsif ($context eq 'author') {
- $Str .= $options;
+ $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');
- $Str .= $secbox."".&mt('Full Update')." \n".
- ' '.
- ' '.&mt('Display students with current/future access who are not in the uploaded file.').' '.&mt('Students selected from this list can be dropped.').'
'."\n";
+ $Str .= $secbox
+ .&Apache::lonhtmlcommon::row_closure();
+
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
+ .' '.
+ ' '.&mt('Display students with current/future access who are not in the uploaded file.')
+ .' '
+ .&mt('Students selected from this list can be dropped.')
+ .&Apache::lonhtmlcommon::row_closure();
}
if ($context eq 'course' || $context eq 'domain') {
$Str .= &forceid_change($context);
}
+
+ $Str .= &Apache::lonhtmlcommon::end_pick_box();
$Str .= ' ';
- $Str .= '';
}
$output .= "\n".''."\n".
&Apache::loncommon::start_data_table().
@@ -2309,6 +2415,11 @@ END
$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})) {
@@ -2508,7 +2619,7 @@ END
}
}
$r->print(' ');
+ 'actionlist" value="'.$checkval.'" />');
} else {
$r->print(' ');
}
@@ -2521,6 +2632,12 @@ END
$r->print(''.&print_username_link($mode,\%in).' ');
} elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {
$r->print(''.$in{$item}.' '."\n");
+ } elsif ($item eq 'status') {
+ my $showitem = $in{$item};
+ if (defined($ltstatus{$in{$item}})) {
+ $showitem = $ltstatus{$in{$item}};
+ }
+ $r->print(''.$showitem.' '."\n");
} else {
$r->print(''.$in{$item}.' '."\n");
}
@@ -2537,7 +2654,7 @@ END
}
if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
- $r->print(' ');
+ $r->print(' ');
} else {
$r->print(' ');
}
@@ -2824,8 +2941,8 @@ sub select_actions {
}
}
if ($choices{'sections'}) {
- $output .= ' '."\n".
- ' '."\n";
+ $output .= ' '."\n".
+ ' '."\n";
}
}
return $output;
@@ -2839,9 +2956,9 @@ sub date_section_javascript {
delete => "Check the boxes for any users for whom roles are to be deleted, and click 'Proceed'",
none => "Choose an action to take for selected users",
);
- my $output = '
-
ENDTWO
return $output;
@@ -2877,6 +2995,7 @@ sub date_section_selector {
my $sec_js = &setsections_javascript($formname,$groupslist);
my $output = <<"END";
ENDJS
my %lt = &Apache::lonlocal::texthash (
@@ -3003,7 +3123,7 @@ ENDJS
$output .= $info.$secbox;
}
$output .= ''.
-'
'."\n".
+' '."\n".
'';
return $output;
}
@@ -3221,10 +3341,12 @@ sub show_drop_list {
-
+
END
my ($indexhash,$keylist) = &make_keylist_array();
my $studentcount = 0;
@@ -3342,7 +3464,7 @@ END
#
$r->print(&Apache::loncommon::start_data_table_row());
$r->print(<<"END");
-
+
$username
$domain
$id
@@ -3361,10 +3483,14 @@ END
'ua' => "uncheck all",
);
$r->print(<<"END");
-
-
-
-
+
+
+
+
+
+
+
+
END
return;
}
@@ -3375,24 +3501,42 @@ END
sub print_first_users_upload_form {
my ($r,$context) = @_;
my $str;
- $str = ' ';
+ $str = ' ';
$str .= ' ';
$str .= ' ';
- $str .= "".&mt('Upload a file containing information about users')." \n";
- $str .= &Apache::loncommon::upfile_select_html();
- $str .= '';
- $str .= &Apache::loncommon::help_open_topic("Course_Create_Class_List",
- &mt("How do I create a users list from a spreadsheet")).
- " \n";
- $str .= &Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
- &mt("How do I create a CSV file from a spreadsheet"));
- $str .= "
\n";
- $str .= "\n";
- $str .= ' '.
- &mt('Ignore First Line')."
\n";
- $str .= ' '." \n";
+
+ $str .= ''.&mt('Upload a file containing information about users').' '."\n";
+
+ # Excel and CSV Help
+ $str .= ''
+ .&Apache::loncommon::help_open_topic("Course_Create_Class_List",
+ &mt("How do I create a users list from a spreadsheet"))
+ ." \n"
+ .&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
+ &mt("How do I create a CSV file from a spreadsheet"))
+ ."
\n";
+
+ $str .= &Apache::lonhtmlcommon::start_pick_box()
+ .&Apache::lonhtmlcommon::row_title(&mt('File'))
+ .''."\n"
+ .&mt('Please upload an UTF8 encoded file to ensure a correct character encoding in your classlist.')."\n"
+ .'
'."\n"
+ .&Apache::loncommon::upfile_select_html()
+ .&Apache::lonhtmlcommon::row_closure()
+ .&Apache::lonhtmlcommon::row_title(
+ ''
+ .&mt('Ignore First Line')
+ .' ')
+ .' '
+ .&Apache::lonhtmlcommon::row_closure(1)
+ .&Apache::lonhtmlcommon::end_pick_box();
+
+ $str .= ''
+ .' '
+ .'
';
+
$str .= &Apache::loncommon::end_page();
+
$r->print($str);
return;
}
@@ -3436,7 +3580,8 @@ sub upfile_drop_add {
'ipwd_choice' => 'scalar',
'email_choice' => 'scalar',
'role_choice' => 'scalar',
- 'domain_choice' => 'scalar'});
+ 'domain_choice' => 'scalar',
+ 'inststatus_choice' => 'scalar'});
#
my ($startdate,$enddate) = &get_dates_from_form();
if ($env{'form.makedatesdefault'}) {
@@ -3519,6 +3664,7 @@ sub upfile_drop_add {
'permanentemail','id');
my %canmodify;
if (&Apache::lonnet::allowed('mau',$domain)) {
+ push(@userinfo,'inststatus');
foreach my $field (@userinfo) {
$canmodify{$field} = 1;
}
@@ -3567,6 +3713,8 @@ sub upfile_drop_add {
} else {
$r->print(''.&mt('Adding/Modifying Users')." \n\n");
}
+ $r->rflush;
+
my %counts = (
user => 0,
auth => 0,
@@ -3706,7 +3854,15 @@ sub upfile_drop_add {
if (defined($fields{'email'})) {
if (defined($entries{$fields{'email'}})) {
$email=$entries{$fields{'email'}};
- unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; } }
+ unless ($email=~/^[^\@]+\@[^\@]+$/) { $email=''; }
+ }
+ }
+ # determine affiliation
+ my $inststatus='';
+ if (defined($fields{'inststatus'})) {
+ if (defined($entries{$fields{'inststatus'}})) {
+ $inststatus=$entries{$fields{'inststatus'}};
+ }
}
# determine user password
my $password = $genpwd;
@@ -3789,7 +3945,7 @@ sub upfile_drop_add {
}
}
my @newinfo = (\$fname,\$mname,\$lname,\$gen,\$email,\$id);
- for (my $i=0; $i<@userinfo; $i++) {
+ for (my $i=0; $i<@newinfo; $i++) {
if (${$newinfo[$i]} ne '') {
if (!$canmodify{$userinfo[$i]}) {
${$newinfo[$i]} = '';
@@ -3838,7 +3994,7 @@ sub upfile_drop_add {
$fname,$mname,$lname,$gen,$sec,$enddate,
$startdate,$env{'form.forceid'},
$desiredhost,$email,'manual','',$cid,
- '',$context);
+ '',$context,$inststatus);
$userresult = $roleresult;
} else {
if ($role ne '') {
@@ -3858,7 +4014,7 @@ sub upfile_drop_add {
$mname,$lname,$gen,$sec,
$env{'form.forceid'},$desiredhost,
$email,$role,$enddate,
- $startdate,$checkid);
+ $startdate,$checkid,$inststatus);
}
} elsif (@secs > 0) {
$singlesec = $secs[0];
@@ -3873,7 +4029,8 @@ sub upfile_drop_add {
$id,$amode,$password,$fname,
$mname,$lname,$gen,$singlesec,
$env{'form.forceid'},$desiredhost,
- $email,$role,$enddate,$startdate,$checkid);
+ $email,$role,$enddate,$startdate,
+ $checkid,$inststatus);
}
}
if ($multiple) {
@@ -4388,7 +4545,7 @@ sub course_sections {
my $output = '';
my @sections = (sort {$a <=> $b} keys %{$sections_count});
my $numsec = scalar(@sections);
- my $is_selected = ' selected="selected" ';
+ my $is_selected = ' selected="selected"';
if ($numsec <= 1) {
$output = ''."\n".
' '.&mt('Select').' '."\n";
@@ -4688,14 +4845,18 @@ sub roles_by_context {
my ($context,$custom) = @_;
my @allroles;
if ($context eq 'course') {
- @allroles = ('st','ad','ta','ep','in','cc');
+ @allroles = ('st');
+ if ($env{'request.role'} =~ m{^dc\./}) {
+ push(@allroles,'ad');
+ }
+ push(@allroles,('ta','ep','in','cc'));
if ($custom) {
push(@allroles,'cr');
}
} elsif ($context eq 'author') {
@allroles = ('ca','aa');
} elsif ($context eq 'domain') {
- @allroles = ('li','dg','sc','au','dc');
+ @allroles = ('li','ad','dg','sc','au','dc');
}
return @allroles;
}