--- loncom/interface/lonuserutils.pm 2007/12/22 00:39:52 1.22 +++ loncom/interface/lonuserutils.pm 2007/12/22 04:58:45 1.26 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.22 2007/12/22 00:39:52 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.26 2007/12/22 04:58:45 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -738,13 +738,13 @@ sub print_upload_manager_footer { } if ($context eq 'author') { $Str .= '

'.&mt('Default role')."

\n". - &mt('Choose the role to assign to users without one specified in the uploaded file'); + &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 to assign to users without one specified in the uploaded file'); + &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')."
\n". - &mt('Role and/or section for users without one in the uploaded file.'); + $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 .= '
'; if (($context eq 'domain') || ($context eq 'author')) { @@ -786,13 +786,14 @@ sub forceid_change { "

\n".'
'."\n". - &mt('(only do if you know what you are doing.)')."

\n"; + &mt('(only do if you know what you are doing.)')."\n"; if ($context eq 'domain') { - $output .= '

'."\n"; + ''."\n"; } + $output .= '

'; return $output; } @@ -962,7 +963,7 @@ sub date_setting_table { ($env{'form.action'} eq 'upload')) { if ($env{'request.course.sec'} eq '') { $dateDefault = ''. - ''; } @@ -1001,14 +1002,14 @@ 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 dates for course'). + $result .= &mt('Set default start and end access dates for course.'). '
'."\n"; # # Refresh the course environment &Apache::lonnet::coursedescription($env{'request.course.id'}, {'freshen_cache' => 1}); } else { - $result .= &mt('Unable to set default dates for course').":".$put_result. + $result .= &mt('Unable to set default access dates for course.').":".$put_result. '
'; } } @@ -1289,7 +1290,8 @@ sub print_userlist { $r->print(''); } if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) { - $r->print(&list_submit_button(&mt('Update Display'))."\n

\n"); + $r->print(' '.&list_submit_button(&mt('Update Display')). + "\n

\n"); } my ($indexhash,$keylist) = &make_keylist_array(); my (%userlist,%userinfo); @@ -1479,7 +1481,8 @@ sub gather_userinfo { ($userdata{'username'},$userdata{'domain'},$userdata{'role'}) = split(/:/,$item); ($userdata{'start'},$userdata{'end'})=split(/:/,$rolehash->{$item}); - &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist); + &build_user_record($context,\%userdata,$userinfo,$indexhash, + $item,$userlist); } elsif ($context eq 'course') { my $viewablesec = &viewable_section($permission); ($userdata{'username'},$userdata{'domain'},$userdata{'role'}, @@ -1488,13 +1491,15 @@ sub gather_userinfo { if (($viewablesec ne '') && ($userdata{'section'} ne '')) { next if ($viewablesec ne $userdata{'section'}); } - &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist); + &build_user_record($context,\%userdata,$userinfo,$indexhash, + $item,$userlist); } elsif ($context eq 'domain') { if ($env{'form.roletype'} eq 'domain') { ($userdata{'role'},$userdata{'username'},$userdata{'domain'}) = split(/:/,$item); ($userdata{'end'},$userdata{'start'})=split(/:/,$rolehash->{$item}); - &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist); + &build_user_record($context,\%userdata,$userinfo,$indexhash, + $item,$userlist); } elsif ($env{'form.roletype'} eq 'author') { if (ref($rolehash->{$item}) eq 'HASH') { $userdata{'extent'} = $item; @@ -1503,7 +1508,8 @@ sub gather_userinfo { ($userdata{'start'},$userdata{'end'}) = split(/:/,$rolehash->{$item}{$key}); my $uniqid = $key.':'.$item; - &build_user_record(\%userdata,$userinfo,$indexhash,$uniqid,$userlist); + &build_user_record($context,\%userdata,$userinfo, + $indexhash,$uniqid,$userlist); } } } elsif ($env{'form.roletype'} eq 'course') { @@ -1518,13 +1524,14 @@ sub gather_userinfo { my $space = ', '; if ($format eq 'html' || $format eq 'view') { $spanstart = ''; - if ($permission->{'cusr'}) { - if ($numcids > 1) { - $spanstart .= ''; - } else { - $spanstart .= ''; - } - } + # FIXME: actions on courses disabled for now +# if ($permission->{'cusr'}) { +# if ($numcids > 1) { +# $spanstart .= ' '; +# } else { +# $spanstart .= ' '; +# } +# } $spanend = '
'; $space = ', '; } @@ -1532,13 +1539,20 @@ sub gather_userinfo { $rolehash->{$item}{$cid}{'desc'}.$space; if (ref($rolehash->{$item}{$cid}{'secs'}) eq 'HASH') { foreach my $sec (sort(keys(%{$rolehash->{$item}{$cid}{'secs'}}))) { - $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend; + if (($env{'form.Status'} eq 'Any') || + ($env{'form.Status'} eq $rolehash->{$item}{$cid}{'secs'}{$sec})) { + $userdata{'extent'} .= $sec.$space.$rolehash->{$item}{$cid}{'secs'}{$sec}.$spanend; + $userdata{'status'} = $rolehash->{$item}{$cid}{'secs'}{$sec}; + } } } } } } - &build_user_record(\%userdata,$userinfo,$indexhash,$item,$userlist); + if ($userdata{'status'} ne '') { + &build_user_record($context,\%userdata,$userinfo, + $indexhash,$item,$userlist); + } } } } @@ -1546,14 +1560,15 @@ sub gather_userinfo { } sub build_user_record { - my ($userdata,$userinfo,$indexhash,$record_key,$userlist) = @_; + my ($context,$userdata,$userinfo,$indexhash,$record_key,$userlist) = @_; next if ($userdata->{'start'} eq '-1' && $userdata->{'end'} eq '-1'); - &process_date_info($userdata); + if (!(($context eq 'domain') && ($env{'form.roletype'} eq 'course'))) { + &process_date_info($userdata); + } my $username = $userdata->{'username'}; my $domain = $userdata->{'domain'}; if (ref($userinfo->{$username.':'.$domain}) eq 'HASH') { - $userdata->{'fullname'} = - $userinfo->{$username.':'.$domain}{'fullname'}; + $userdata->{'fullname'} = $userinfo->{$username.':'.$domain}{'fullname'}; $userdata->{'id'} = $userinfo->{$username.':'.$domain}{'id'}; } else { &aggregate_user_info($domain,$username,$userinfo); @@ -1843,8 +1858,8 @@ END if ($mode ne 'autoenroll') { 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 $singconfirm = &mt(' for a single user?'); + my $multconfirm = &mt(' for multiple users?'); my $date_sec_selector = &date_section_javascript($context,$setting,$statusmode); $r->print(<print(''.$results_description.'
'); } - my ($output,$actionselect); + my ($output,$actionselect,%canchange,%canchangesec); if ($mode eq 'html' || $mode eq 'view' || $mode eq 'autoenroll') { if ($mode ne 'autoenroll') { if ($permission->{'cusr'}) { @@ -2014,6 +2029,40 @@ $lt{'ac'}: $actionselect   END + my @allroles; + if ($env{'form.showrole'} eq 'Any') { + my $custom = 1; + if ($context eq 'domain') { + @allroles = &roles_by_context($setting,$custom); + } else { + @allroles = &roles_by_context($context,$custom); + } + } else { + @allroles = ($env{'form.showrole'}); + } + foreach my $role (@allroles) { + if ($context eq 'domain') { + if ($setting eq 'domain') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'request.role.domain'})) { + $canchange{$role} = 1; + } + } + } elsif ($context eq 'author') { + if (&Apache::lonnet::allowed('c'.$role, + $env{'user.domain'}.'/'.$env{'user.name'})) { + $canchange{$role} = 1; + } + } elsif ($context eq 'course') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'})) { + $canchange{$role} = 1; + } elsif ($env{'request.course.sec'} ne '') { + if (&Apache::lonnet::allowed('c'.$role,$env{'request.course.id'}.'/'.$env{'request.course.sec'})) { + $canchangesec{$role} = $env{'request.course.sec'}; + } + } + } + } } } $output .= "\n

\n". @@ -2227,18 +2276,38 @@ END $r->print("$rowcount\n"); $checkval; if ($actionselect) { - $checkval = $user; - if ($context eq 'course') { - if ($role eq 'st') { - $checkval .= ':st'; + my $showcheckbox; + if ($role =~ /^cr\//) { + $showcheckbox = $canchange{'cr'}; + } else { + $showcheckbox = $canchange{$role}; + } + if (!$showcheckbox) { + if ($context eq 'course') { + if ($canchangesec{$role} ne '') { + if ($canchangesec{$role} eq $in{'section'}) { + $showcheckbox = 1; + } + } } - $checkval .= ':'.$in{'section'}; - if ($role eq 'st') { - $checkval .= ':'.$in{'type'}.':'.$in{'lockedtype'}; + } + if ($showcheckbox) { + $checkval = $user; + if ($context eq 'course') { + if ($role eq 'st') { + $checkval .= ':st'; + } + $checkval .= ':'.$in{'section'}; + if ($role eq 'st') { + $checkval .= ':'.$in{'type'}.':'. + $in{'lockedtype'}; + } } + $r->print(''); + } else { + $r->print(' '); } - $r->print(''); } } foreach my $item (@cols) { @@ -2367,6 +2436,24 @@ sub select_actions { chgsec => "Change section associated with user roles", ); my ($output,$options,%choices); + # FIXME Disable actions for now for roletype=course in domain context + if ($context eq 'domain' && $setting eq 'course') { + return; + } + if ($context eq 'course') { + if ($env{'form.showrole'} ne 'Any') { + if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'}, + $env{'request.course.id'})) { + if ($env{'request.course.sec'} eq '') { + return; + } else { + if (!&Apache::lonnet::allowed('c'.$env{'form.showrole'},$env{'request.course.id'}.'/'.$env{'request.course.sec'})) { + return; + } + } + } + } + } if ($statusmode eq 'Any') { $options .= ' '; @@ -2393,7 +2480,7 @@ sub select_actions { '; } if (($context eq 'course') || ($context eq 'domain' && $setting eq 'course')) { - if ($statusmode ne 'Expired') { + if (($statusmode ne 'Expired') && ($env{'request.course.sec'} eq '')) { $options .= ' '; $choices{'sections'} = 1; @@ -2500,7 +2587,8 @@ END if (($env{'form.bulkaction'} eq 'reenable') || ($env{'form.bulkaction'} eq 'activate') || ($env{'form.bulkaction'} eq 'chgdates')) { - $output .= <<"END"; + if ($env{'request.course.sec'} eq '') { + $output .= <<"END"; if (formname.makedatesdefault.checked == true) { opener.document.$callingform.makedatesdefault.value = 1; @@ -2510,6 +2598,7 @@ END } END + } } } $output .= <<"END"; @@ -2559,12 +2648,10 @@ END $date_items; if ($context eq 'course' && $env{'form.bulkaction'} eq 'chgsec') { my ($cnum,$cdom) = &get_course_identity(); - my %sections_count = - &Apache::loncommon::get_sections($cdom,$cnum); my $info; if ($env{'form.showrole'} eq 'st') { $output .= '

'.$lt{'fors'}.'

'; - } elsif ($env{'form.shorole'} eq 'Any') { + } elsif ($env{'form.showrole'} eq 'Any') { $output .= '

'.$lt{'fors'}.'

'. '

'.$lt{'forn'}.' '; $info = $lt{'reta'}; @@ -2585,7 +2672,6 @@ END } else { $info = ''; } - my $sections_select .= &course_sections(\%sections_count,$env{'form.showrole'}); my $rowtitle = &mt('New section to assign'); my $secbox = §ion_picker($cdom,$cnum,$env{'form.showrole'},$rowtitle,$permission,$context); $output .= $info.$secbox; @@ -2628,13 +2714,15 @@ sub section_picker { } sub results_header_row { - my ($rolefilter,$statusmode,$context,$permission) = @_; + my ($rolefilter,$statusmode,$context,$permission,$mode) = @_; my ($description,$showfilter); if ($rolefilter ne 'Any') { $showfilter = $rolefilter; } if ($context eq 'course') { - $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': '; + if ($mode eq 'csv' || $mode eq 'excel') { + $description = &mt('Course - ').$env{'course.'.$env{'request.course.id'}.'.description'}.': '; + } if ($statusmode eq 'Expired') { $description .= &mt('Users in course with expired [_1] roles',$showfilter); } elsif ($statusmode eq 'Future') { @@ -2648,11 +2736,12 @@ sub results_header_row { $description .= &mt('All users in course with [_1] roles',$rolefilter); } } - if (exists($permission->{'view_section'})) { + my $viewablesec = &viewable_section($permission); + if ($viewablesec ne '') { if ($env{'form.showrole'} eq 'st') { - $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'}); - } elsif ($env{'form.showrole'} eq 'any') { - $description .= ' '.&mt('(section [_1] only)',$permission->{'view_section'}); + $description .= ' '.&mt('(section [_1] only)',$viewablesec); + } elsif ($env{'form.showrole'} ne 'cc') { + $description .= ' '.&mt('(only users affiliated with no section or section [_1])',$viewablesec); } } } elsif ($context eq 'author') {