--- loncom/interface/lonuserutils.pm 2008/08/27 16:54:49 1.63
+++ loncom/interface/lonuserutils.pm 2010/01/20 21:31:08 1.97.2.11
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.63 2008/08/27 16:54:49 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.97.2.11 2010/01/20 21:31:08 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -86,12 +86,12 @@ 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;
$scope =~ s/\_/\//g;
- if ($role ne 'cc' && $sec ne '') {
+ if (($role ne 'cc') && ($role ne 'co') && ($sec ne '')) {
$scope .='/'.$sec;
}
} elsif ($context eq 'domain') {
@@ -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;
@@ -235,7 +235,7 @@ sub domain_roles_select {
# domain context
#
# Role types
- my @roletypes = ('domain','author','course');
+ my @roletypes = ('domain','author','course','community');
my %lt = &role_type_names();
#
# build up the menu information to be passed to
@@ -247,6 +247,10 @@ sub domain_roles_select {
foreach my $roletype (@roletypes) {
# set up the text for this domain
$select_menus{$roletype}->{'text'}= $lt{$roletype};
+ my $crstype;
+ if ($roletype eq 'community') {
+ $crstype = 'Community';
+ }
# we want a choice of 'default' as the default in the second menu
if ($env{'form.roletype'} ne '') {
$select_menus{$roletype}->{'default'} = $env{'form.showrole'};
@@ -261,7 +265,7 @@ sub domain_roles_select {
@roles = &construction_space_roles();
} else {
my $custom = 1;
- @roles = &course_roles('domain',undef,$custom);
+ @roles = &course_roles('domain',undef,$custom,$roletype);
}
my $order = ['Any',@roles];
$select_menus{$roletype}->{'order'} = $order;
@@ -271,14 +275,15 @@ sub domain_roles_select {
&mt('Custom role');
} else {
$select_menus{$roletype}->{'select2'}->{$role} =
- &Apache::lonnet::plaintext($role);
+ &Apache::lonnet::plaintext($role,$crstype);
}
}
$select_menus{$roletype}->{'select2'}->{'Any'} = &mt('Any');
}
my $result = &Apache::loncommon::linked_select_forms
('studentform',(' 'x3).&mt('Role: '),$env{'form.roletype'},
- 'roletype','showrole',\%select_menus,['domain','author','course']);
+ 'roletype','showrole',\%select_menus,
+ ['domain','author','course','community']);
return $result;
}
@@ -290,7 +295,7 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -327,10 +332,12 @@ sub print_upload_manager_header {
my $javascript_validations =
&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");
+ $groupslist,$crstype);
+ 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,21 +348,24 @@ 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('
\n".
'');
+ '// '."\n".
+ '');
}
###############################################################
###############################################################
sub javascript_validations {
my ($mode,$krbdefdom,$curr_authtype,$curr_authfield,$domain,
- $context,$groupslist)=@_;
+ $context,$groupslist,$crstype)=@_;
my %param = (
kerb_def_dom => $krbdefdom,
curr_authtype => $curr_authtype,
@@ -376,10 +386,10 @@ sub javascript_validations {
if (($context eq 'course') || ($context eq 'domain')) {
if ($context eq 'course') {
if ($env{'request.course.sec'} eq '') {
- $setsection_call = 'setSections(document.'.$param{'formname'}.');';
+ $setsection_call = 'setSections(document.'.$param{'formname'}.",'$crstype'".');';
$setsections_js =
&setsections_javascript($param{'formname'},$groupslist,
- $mode);
+ $mode,'',$crstype);
} else {
$setsection_call = "'ok'";
}
@@ -401,17 +411,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 email address 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 +551,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 .= "
'."\n".
- &mt('Pick the action to take on roles for these users:').' ';
- }
- 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:').' '
+ .''
+ .' '
+ .' '
+ .'';
+ } 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.'
'
+ .$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('Students selected from this list can be dropped.').'
'."\n";
+ $permission,$context,'upload',$crstype);
+ $Str .= $secbox
+ .&Apache::lonhtmlcommon::row_closure();
+ my %lt;
+ if ($crstype eq 'Community') {
+ %lt = &Apache::lonlocal::texthash (
+ disp => 'Display members with current/future access who are not in the uploaded file',
+ stus => 'Members selected from this list can be dropped.'
+ );
+ } else {
+ %lt = &Apache::lonlocal::texthash (
+ disp => 'Display students with current/future access who are not in the uploaded file',
+ stus => 'Students selected from this list can be dropped.'
+ );
+ }
+ $Str .= &Apache::lonhtmlcommon::row_title(&mt('Full Update'))
+ .' '
+ .$lt{'stus'}
+ .&Apache::lonhtmlcommon::row_closure();
}
if ($context eq 'course' || $context eq 'domain') {
$Str .= &forceid_change($context);
}
- $Str .= '
';
+
+ # Footer
+ $Str .= '';
$r->print($Str);
return;
}
@@ -811,25 +914,25 @@ sub print_upload_manager_footer {
sub forceid_change {
my ($context) = @_;
my $output =
- "
".&mt('Student/Employee ID')."
\n".
- "
\n".' '."\n".
- &mt('(only do if you know what you are doing.)')."\n";
+ &Apache::lonhtmlcommon::row_title(&mt('Student/Employee ID'))
+ .' '."\n"
+ .&mt('(only do if you know what you are doing.)')."\n";
if ($context eq 'domain') {
$output .= ' '."\n";
}
- $output .= '
';
+ $output .= &Apache::lonhtmlcommon::row_closure(1); # last row in pick_box
return $output;
}
###############################################################
###############################################################
sub print_upload_manager_form {
- my ($r,$context,$permission) = @_;
+ my ($r,$context,$permission,$crstype) = @_;
my $firstLine;
my $datatoken;
if (!$env{'form.datatoken'}) {
@@ -860,6 +963,7 @@ sub print_upload_manager_form {
'email_choice' => 'scalar',
'role_choice' => 'scalar',
'domain_choice' => 'scalar',
+ 'inststatus_choice' => 'scalar',
};
my $defdom = $env{'request.role.domain'};
if ($context eq 'course') {
@@ -875,7 +979,7 @@ sub print_upload_manager_form {
&Apache::loncommon::get_kerberos_defaults($defdom);
#
&print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom,$context,
- $permission);
+ $permission,$crstype);
my $i;
my $keyfields;
if ($total>=0) {
@@ -891,7 +995,8 @@ sub print_upload_manager_form {
['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
['email',&mt('E-mail Address'), $env{'form.email_choice'}],
['role',&mt('Role'), $env{'form.role_choice'}],
- ['domain',&mt('Domain'), $env{'form.domain_choice'}]);
+ ['domain',&mt('Domain'), $env{'form.domain_choice'}],
+ ['inststatus',&mt('Affiliation'), $env{'form.inststatus_choice'}]);
if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($r,\@records);
$i=&Apache::loncommon::csv_print_select_table($r,\@records,
@@ -910,7 +1015,7 @@ sub print_upload_manager_form {
}
$r->print('');
&print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
- $context,$permission);
+ $context,$permission,$crstype);
}
sub setup_date_selectors {
@@ -984,7 +1089,7 @@ sub get_dates_from_form {
}
sub date_setting_table {
- my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission) = @_;
+ my ($starttime,$endtime,$mode,$bulkaction,$formname,$permission,$crstype) = @_;
my $nolink;
if ($bulkaction) {
$nolink = 1;
@@ -1001,15 +1106,19 @@ sub date_setting_table {
($env{'form.action'} eq 'upload')) {
if ($env{'request.course.sec'} eq '') {
$dateDefault = ''.
- '';
+ '';
}
}
}
my $perpetual = '';
if ($mode eq 'create_enrolldates') {
@@ -1032,7 +1141,7 @@ sub date_setting_table {
}
sub make_dates_default {
- my ($startdate,$enddate,$context) = @_;
+ my ($startdate,$enddate,$context,$crstype = @_;
my $result = '';
if ($context eq 'course') {
my ($cnum,$cdom) = &get_course_identity();
@@ -1040,26 +1149,34 @@ sub make_dates_default {
{'default_enrollment_start_date'=>$startdate,
'default_enrollment_end_date' =>$enddate},$cdom,$cnum);
if ($put_result eq 'ok') {
- $result .= &mt('Set default start and end access dates for course.').
- ' '."\n";
+ if ($crstype eq 'Community') {
+ $result .= &mt('Set default start and end access dates for community.');
+ } else {
+ $result .= &mt('Set default start and end access dates for course.');
+ }
+ $result .= ' '."\n";
#
# Refresh the course environment
&Apache::lonnet::coursedescription($env{'request.course.id'},
{'freshen_cache' => 1});
} else {
- $result .= &mt('Unable to set default access dates for course.').":".$put_result.
- ' ';
+ if ($crstype eq 'Community') {
+ $result .= &mt('Unable to set default access dates for community');
+ } else {
+ $result .= &mt('Unable to set default access dates for course');
+ }
+ $result .= ':'.$put_result.' ';
}
}
return $result;
}
sub default_role_selector {
- my ($context,$checkpriv) = @_;
+ my ($context,$checkpriv,$crstype) = @_;
my %customroles;
my ($options,$coursepick,$cb_jscript);
if ($context ne 'author') {
- %customroles = &my_custom_roles();
+ %customroles = &my_custom_roles($crstype);
}
my %lt=&Apache::lonlocal::texthash(
@@ -1071,7 +1188,7 @@ sub default_role_selector {
$options = '