--- loncom/interface/lonuserutils.pm 2009/10/30 03:57:35 1.101 +++ 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.101 2009/10/30 03:57:35 raeburn 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') { @@ -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'}; @@ -271,7 +275,7 @@ 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'); @@ -291,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'})) { @@ -305,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 @@ -328,7 +333,7 @@ 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]'
@@ -361,7 +366,7 @@ sub print_upload_manager_header {
###############################################################
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,
@@ -382,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'";
}
@@ -581,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(< '
- .&mt('Note: For large courses, this operation may be time consuming.')
+ .&mt('Note: This operation may be time consuming when adding several users.')
.' =0) {
@@ -1172,7 +1211,7 @@ sub default_role_selector {
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(
@@ -1198,16 +1237,16 @@ sub default_role_selector {
$options .= ' ';
}
my $courseform = &Apache::loncommon::selectcourse_link
- ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course');
+ ('studentform','dccourse','dcdomain','coursedesc',"$env{'request.role.domain'}",undef,'Course/Community');
$cb_jscript =
- &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform');
+ &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'},'currsec','studentform','courserole','Course/Community');
$coursepick = &Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row().
'
';
if ($context eq 'course') {
$Str .= ''.$courseform.' '.$lt{'rol'}.' '.
''.$lt{'grs'}.' '.
&Apache::loncommon::end_data_table_header_row().
&Apache::loncommon::start_data_table_row()."\n".
- ''."\n".
+ ' '."\n".
' '.
@@ -1225,6 +1264,7 @@ sub default_role_selector {
$env{'request.role.domain'}.'" />'.
''.
''.
+ ''.
' '.
&Apache::loncommon::end_data_table_row().
&Apache::loncommon::end_data_table()."\n";
@@ -1290,7 +1330,13 @@ sub domain_roles {
sub course_roles {
my ($context,$checkpriv,$custom,$roletype) = @_;
- my @allroles = &roles_by_context('course',$custom,$roletype);
+ my $crstype;
+ if ($roletype eq 'community') {
+ $crstype = 'Community' ;
+ } else {
+ $crstype = 'Course';
+ }
+ my @allroles = &roles_by_context('course',$custom,$crstype);
my @roles;
if ($context eq 'domain') {
@roles = @allroles;
@@ -1339,10 +1385,14 @@ sub curr_role_permissions {
# ======================================================= Existing Custom Roles
sub my_custom_roles {
+ my ($crstype) = @_;
my %returnhash=();
my %rolehash=&Apache::lonnet::dump('roles');
- foreach my $key (keys %rolehash) {
+ foreach my $key (keys(%rolehash)) {
if ($key=~/^rolesdef\_(\w+)$/) {
+ if ($crstype eq 'Community') {
+ next if ($rolehash{$key} =~ /bre\&S/);
+ }
$returnhash{$1}=$1;
}
}
@@ -1431,26 +1481,52 @@ sub print_userlist {
'');
return;
}
- if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) {
- $r->print(' '.&list_submit_button(&mt('Update Display')).
- "\n
' + .&list_submit_button(&mt('Update Display')) + ."
\n" + ); } my ($indexhash,$keylist) = &make_keylist_array(); - my (%userlist,%userinfo); - if ($context eq 'domain' && $env{'form.roletype'} eq 'course') { + my (%userlist,%userinfo,$clearcoursepick); + if (($context eq 'domain') && + ($env{'form.roletype'} eq 'course') || + ($env{'form.roletype'} eq 'community')) { + my ($crstype,$numcodes,$title,$warning); + if ($env{'form.roletype'} eq 'course') { + $crstype = 'Course'; + $numcodes = $totcodes; + $title = &mt('Select Courses'); + $warning = &mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.'); + } elsif ($env{'form.roletype'} eq 'community') { + $crstype = 'Community'; + $numcodes = 0; + $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,$totcodes, - $codetitles,$idlist,$idlist_titles); + &Apache::lonhtmlcommon::course_selection($formname,$numcodes, + $codetitles,$idlist,$idlist_titles,$crstype, + \@standardnames); $r->print(''.&Apache::lonhtmlcommon::start_pick_box()."\n". &Apache::lonhtmlcommon::start_pick_box()."\n". - &Apache::lonhtmlcommon::row_title(&mt('Select Course(s)'), - 'LC_oddrow_value')."\n". + &Apache::lonhtmlcommon::row_title($title,'LC_oddrow_value')."\n". $courseform."\n". &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::end_pick_box().'
'. - ''.&list_submit_button(&mt('Update Display')). - "\n".'
'.&mt('Warning: data retrieval for multiple courses can take considerable time, as this operation is not currently optimized.').''."\n"); - if ($env{'form.coursepick'}) { + ''. + &list_submit_button(&mt('Update Display')). + "\n".'
'.$warning.''."\n"); + $clearcoursepick = 0; + if (($env{'form.origroletype'} ne '') && + ($env{'form.origroletype'} ne $env{'form.roletype'})) { + $clearcoursepick = 1; + } + if (($env{'form.coursepick'}) && (!$clearcoursepick)) { $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; } # @@ -2486,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 { @@ -2593,7 +2693,7 @@ END if ($clickers!~/\w/) { $clickers='-'; } $in{'clicker'} = $clickers; my $role = $in{'role'}; - $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype); + $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype); if (! defined($in{'start'}) || $in{'start'} == 0) { $in{'start'} = &mt('none'); } else { @@ -2880,7 +2980,7 @@ sub print_username_link { $output = $in->{'username'}; } else { $output = '{'username'}','$in->{'domain'}'".')" />'. + "'$in->{'username'}','$in->{'domain'}'".')">'. $in->{'username'}.''; } return $output; @@ -3053,7 +3153,7 @@ END } else { opener.document.$callingform.retainsec.value = formname.retainsec.value; } - setSections(formname); + setSections(formname,'$crstype'); if (seccheck == 'ok') { opener.document.$callingform.newsecs.value = formname.sections.value; } @@ -3110,10 +3210,10 @@ 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') { @@ -3130,11 +3230,15 @@ ENDJS $permission,$crstype); } $output .= '