--- loncom/interface/lonuserutils.pm 2009/06/05 12:49:50 1.94
+++ loncom/interface/lonuserutils.pm 2010/09/20 00:21:08 1.125
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Utility functions for managing LON-CAPA user accounts
#
-# $Id: lonuserutils.pm,v 1.94 2009/06/05 12:49:50 bisitz Exp $
+# $Id: lonuserutils.pm,v 1.125 2010/09/20 00:21:08 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -91,7 +91,7 @@ sub modifyuserrole {
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') {
@@ -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,8 @@ sub hidden_input {
}
sub print_upload_manager_header {
- my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission)=@_;
+ my ($r,$datatoken,$distotal,$krbdefdom,$context,$permission,$crstype,
+ $can_assign)=@_;
my $javascript;
#
if (! exists($env{'form.upfile_associate'})) {
@@ -304,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
@@ -327,10 +333,12 @@ sub print_upload_manager_header {
my $javascript_validations =
&javascript_validations('upload',$krbdefdom,$password_choice,undef,
$env{'request.role.domain'},$context,
- $groupslist);
+ $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('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");
@@ -345,17 +353,20 @@ sub print_upload_manager_header {
&mt('Ignore First Line').' ');
$r->print(' ');
+ 'onclick="javascript:this.form.associate.value=\'Reverse Association\';submit(this.form);" />');
$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 +387,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'";
}
@@ -575,6 +586,31 @@ END
###############################################################
###############################################################
sub upload_manager_javascript_forward_associate {
+ my ($can_assign) = @_;
+ my $auth_update;
+ if (ref($can_assign) eq 'HASH') {
+ if (keys(%{$can_assign}) > 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);
+END
+ }
+ if ($can_assign->{'krb4'} || $can_assign->{'krb5'}) {
+ $auth_update .= " vf.krbarg.value='';\n";
+ }
+ if ($can_assign->{'int'}) {
+ $auth_update .= " vf.intarg.value='';\n";
+ }
+ if ($can_assign->{'loc'}) {
+ $auth_update .= " vf.locarg.value='';\n";
+ }
+ $auth_update .= "
+ }\n";
+ }
+
return(< 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);
+END
+ }
+ if ($can_assign->{'krb'}) {
+ $auth_update .= " vf.krbarg.value='';\n";
+ }
+ if ($can_assign->{'int'}) {
+ $auth_update .= " vf.intarg.value='';\n";
+ }
+ if ($can_assign->{'loc'}) {
+ $auth_update .= " vf.locarg.value='';\n";
+ }
+ $auth_update .= "
+ }\n";
+ }
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) {
@@ -738,7 +782,7 @@ ENDPICK
###############################################################
###############################################################
sub print_upload_manager_footer {
- my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission) = @_;
+ my ($r,$i,$keyfields,$defdom,$today,$halfyear,$context,$permission,$crstype) = @_;
my $form = 'document.studentform';
my $formname = 'studentform';
my ($krbdef,$krbdefdom) =
@@ -756,79 +800,146 @@ sub print_upload_manager_footer {
my $intform = &Apache::loncommon::authform_internal(%param);
my $locform = &Apache::loncommon::authform_local(%param);
my $date_table = &date_setting_table(undef,undef,$context,undef,
- $formname,$permission);
+ $formname,$permission,$crstype);
+
my $Str = "\n".'
'."\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 .= &Apache::lonhtmlcommon::end_pick_box();
$Str .= '
';
- $Str .= '');
&print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
- $context,$permission);
+ $context,$permission,$crstype);
}
sub setup_date_selectors {
@@ -1012,7 +1124,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;
@@ -1029,9 +1141,13 @@ sub date_setting_table {
($env{'form.action'} eq 'upload')) {
if ($env{'request.course.sec'} eq '') {
$dateDefault = ''.
- '';
+ '';
}
}
}
@@ -1060,7 +1176,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();
@@ -1068,26 +1184,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(
@@ -1099,7 +1223,7 @@ sub default_role_selector {
$options = '
'."\n";
}
@@ -2289,9 +2505,13 @@ END
time.'_'.rand(1000000000).'.csv';
unless ($CSVfile = Apache::File->new('>/home/httpd'.$CSVfilename)) {
$r->log_error("Couldn't open $CSVfilename for output $!");
- $r->print(&mt('Problems occurred in writing the CSV file. '
- .'This error has been logged. '
- .'Please alert your LON-CAPA administrator.'));
+ $r->print(
+ '
'
+ .&mt('Problems occurred in writing the CSV file.')
+ .' '.&mt('This error has been logged.')
+ .' '.&mt('Please alert your LON-CAPA administrator.')
+ .'
'
+ );
$CSVfile = undef;
}
#
@@ -2365,7 +2585,8 @@ END
}
} elsif ($env{'form.roletype'} eq 'author') {
($uname,$udom,$role) = split(/:/,$user,-1);
- } elsif ($env{'form.roletype'} eq 'course') {
+ } elsif (($env{'form.roletype'} eq 'course') ||
+ ($env{'form.roletype'} eq 'community')) {
($uname,$udom,$role) = split(/:/,$user);
}
} else {
@@ -2472,7 +2693,7 @@ END
if ($clickers!~/\w/) { $clickers='-'; }
$in{'clicker'} = $clickers;
my $role = $in{'role'};
- $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]);
+ $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
if (! defined($in{'start'}) || $in{'start'} == 0) {
$in{'start'} = &mt('none');
} else {
@@ -2759,7 +2980,7 @@ sub print_username_link {
$output = $in->{'username'};
} else {
$output = '{'username'}','$in->{'domain'}'".')" />'.
+ "'$in->{'username'}','$in->{'domain'}'".')">'.
$in->{'username'}.'';
}
return $output;
@@ -2770,6 +2991,7 @@ sub role_type_names {
'domain' => 'Domain Roles',
'author' => 'Co-Author Roles',
'course' => 'Course Roles',
+ 'community' => 'Community Roles',
);
return %lt;
}
@@ -2874,9 +3096,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;
}
sub date_section_selector {
- my ($context,$permission) = @_;
+ my ($context,$permission,$crstype) = @_;
my $callingform = $env{'form.callingform'};
my $formname = 'dateselect';
my $groupslist = &get_groupslist();
my $sec_js = &setsections_javascript($formname,$groupslist);
my $output = <<"END";
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?",
- dnap => '(Does not apply to student roles).',
+ 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);
if ($env{'form.bulkaction'} eq 'chgsec') {
@@ -3002,13 +3227,18 @@ ENDJS
}
$date_items = &date_setting_table($starttime,undef,$context,
$env{'form.bulkaction'},$formname,
- $permission);
+ $permission,$crstype);
}
$output .= '