--- loncom/interface/lonuserutils.pm 2007/12/12 23:59:41 1.15 +++ loncom/interface/lonuserutils.pm 2007/12/14 00:20:53 1.16 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.15 2007/12/12 23:59:41 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.16 2007/12/14 00:20:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1764,16 +1764,19 @@ sub show_users_list { $cnum = $env{'course.'.$cid.'.num'}; ($classgroups) = &Apache::loncoursedata::get_group_memberships( $userlist,$keylist,$cdom,$cnum); - if (! exists($env{'form.displayphotos'})) { - $env{'form.displayphotos'} = 'off'; - } - $displayphotos = $env{'form.displayphotos'}; - if (! exists($env{'form.displayclickers'})) { - $env{'form.displayclickers'} = 'off'; - } - $displayclickers = $env{'form.displayclickers'}; - if ($env{'course.'.$cid.'.internal.showphoto'}) { - $r->print(' + if ($mode eq 'autoenroll') { + $env{'form.showrole'} = 'st'; + } else { + if (! exists($env{'form.displayphotos'})) { + $env{'form.displayphotos'} = 'off'; + } + $displayphotos = $env{'form.displayphotos'}; + if (! exists($env{'form.displayclickers'})) { + $env{'form.displayclickers'} = 'off'; + } + $displayclickers = $env{'form.displayclickers'}; + if ($env{'course.'.$cid.'.internal.showphoto'}) { + $r->print(' - '); - } - $r->print(<print(< END + } } - unless ($mode eq 'autoenroll') { + 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'); @@ -1919,49 +1923,52 @@ END } elsif ($env{'form.showrole'} ne 'Any') { $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'}); } - my $results_description = &results_header_row($rolefilter,$statusmode, - $context,$permission); - $r->print(''.$results_description.'
'); + my $results_description; + if ($mode ne 'autoenroll') { + $results_description = &results_header_row($rolefilter,$statusmode, + $context,$permission); + $r->print(''.$results_description.'
'); + } my ($output,$actionselect); - if ($mode eq 'html' || $mode eq 'view') { - if ($permission->{'cusr'}) { - $actionselect = &select_actions($context,$setting,$statusmode); - } - $r->print(<{'cusr'}) { + $actionselect = &select_actions($context,$setting,$statusmode); + } + $r->print(< END - if ($mode ne 'autoenroll') { - $output = '

'; - my @linkdests = ('aboutme'); - if ($permission->{'cusr'}) { - push (@linkdests,'modify'); - $output .= ''.$lt{'link'}.': '; - my $usernamelink = $env{'form.usernamelink'}; - if ($usernamelink eq '') { - $usernamelink = 'aboutme'; - } - foreach my $item (@linkdests) { - my $checkedstr = ''; - if ($item eq $usernamelink) { - $checkedstr = ' checked="checked" '; - } - $output .= '  '; - } - $output .= '
'; - } else { - $output .= &mt("Click on a username to view the user's personal page.").'
'; - } - if ($actionselect) { - $output .= <<"END"; + $output = '

'; + my @linkdests = ('aboutme'); + if ($permission->{'cusr'}) { + push (@linkdests,'modify'); + $output .= ''.$lt{'link'}.': '; + my $usernamelink = $env{'form.usernamelink'}; + if ($usernamelink eq '') { + $usernamelink = 'aboutme'; + } + foreach my $item (@linkdests) { + my $checkedstr = ''; + if ($item eq $usernamelink) { + $checkedstr = ' checked="checked" '; + } + $output .= '  '; + } + $output .= '
'; + } else { + $output .= &mt("Click on a username to view the user's personal page.").'
'; + } + if ($actionselect) { + $output .= <<"END"; $lt{'ac'}: $actionselect

  END - } + } } $output .= "\n

\n". &Apache::loncommon::start_data_table(). @@ -1980,7 +1987,7 @@ END $output .= "$lt{$item}\n"; } my %role_types = &role_type_names(); - if ($context eq 'course') { + if ($context eq 'course' && $mode ne 'autoenroll') { if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') { # Clicker display on or off? my %clicker_options = &Apache::lonlocal::texthash( @@ -2014,8 +2021,8 @@ END ' '."\n"; } } - $output .= &Apache::loncommon::end_data_table_header_row(); } + $output .= &Apache::loncommon::end_data_table_header_row(); # Done with the HTML header line } elsif ($mode eq 'csv') { # @@ -2151,32 +2158,54 @@ END } if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') { $r->print(&Apache::loncommon::start_data_table_row()); - $r->print("$rowcount\n"); my $checkval; - if ($mode ne 'autoenroll' && $actionselect) { - $checkval = $user; - if ($context eq 'course') { - if ($role eq 'st') { - $checkval .= ':st'; - } - $checkval .= ':'.$in{'section'}; - if ($role eq 'st') { - $checkval .= ':'.$in{'type'}.':'.$in{'lockedtype'}; + if ($mode eq 'autoenroll') { + my $cellentry; + if ($in{'type'} eq 'auto') { + $cellentry = ''.&mt('auto').' '; + $autocount ++; + } else { + $cellentry = '
'.&mt('manual').'
'; + $manualcount ++; + if ($in{'lockedtype'}) { + $cellentry .= ''; + $unlockcount ++; + } else { + $cellentry .= ''; + $lockcount ++; } + $cellentry .= '
'; + } + $r->print("$cellentry\n"); + } else { + $r->print("$rowcount\n"); + $checkval; + if ($actionselect) { + $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(''); } - $r->print(''); } foreach my $item (@cols) { if ($item eq 'username') { - $r->print(''.&print_username_link($permission,\%in).''); - } elsif (($item eq 'start' || $item eq 'end') && ($mode ne 'autoeroll') && ($actionselect)) { + $r->print(''.&print_username_link($mode,$permission, + \%in).''); + } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) { $r->print(''.$in{$item}.''."\n"); } else { $r->print(''.$in{$item}.''."\n"); } } - if ($context eq 'course') { + if (($context eq 'course') && ($mode ne 'autoenroll')) { if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') { if ($displayclickers eq 'on') { my $clickers = @@ -2256,9 +2285,11 @@ END } sub print_username_link { - my ($permission,$in) = @_; + my ($mode,$permission,$in) = @_; my $output; - if (!$permission->{'cusr'}) { + if ($mode eq 'autoenroll') { + $output = $in->{'username'}; + } elsif (!$permission->{'cusr'}) { $output = &Apache::loncommon::aboutmewrapper($in->{'username'}, $in->{'username'}, $in->{'domain'}); @@ -3723,5 +3754,67 @@ sub can_create_user { return $cancreate; } +sub get_permission { + my ($context) = @_; + my %permission; + if ($context eq 'course') { + if ((&Apache::lonnet::allowed('cta',$env{'request.course.id'})) || + (&Apache::lonnet::allowed('cin',$env{'request.course.id'})) || + (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) || + (&Apache::lonnet::allowed('cep',$env{'request.course.id'})) || + (&Apache::lonnet::allowed('cst',$env{'request.course.id'}))) { + $permission{'cusr'} = 1; + $permission{'view'} = + &Apache::lonnet::allowed('vcl',$env{'request.course.id'}); + + } + if (&Apache::lonnet::allowed('ccr',$env{'request.course.id'})) { + $permission{'custom'} = 1; + } + if (&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) { + $permission{'view'} = 1; + } + if (!$permission{'view'}) { + my $scope = $env{'request.course.id'}.'/'.$env{'request.course.sec'}; + $permission{'view'} = &Apache::lonnet::allowed('vcl',$scope); + if ($permission{'view'}) { + $permission{'view_section'} = $env{'request.course.sec'}; + } + } + if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) { + $permission{'grp_manage'} = 1; + } + } elsif ($context eq 'author') { + $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'}); + $permission{'view'} = $permission{'cusr'}; + } else { + if ((&Apache::lonnet::allowed('cad',$env{'request.role.domain'})) || + (&Apache::lonnet::allowed('cli',$env{'request.role.domain'})) || + (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) || + (&Apache::lonnet::allowed('csc',$env{'request.role.domain'})) || + (&Apache::lonnet::allowed('cdg',$env{'request.role.domain'})) || + (&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))) { + $permission{'cusr'} = 1; + } + if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) { + $permission{'custom'} = 1; + } + $permission{'view'} = $permission{'cusr'}; + } + my $allowed = 0; + foreach my $perm (values(%permission)) { + if ($perm) { $allowed=1; last; } + } + return (\%permission,$allowed); +} + +# ==================================================== Figure out author access + +sub authorpriv { + my ($auname,$audom)=@_; + unless ((&Apache::lonnet::allowed('cca',$audom.'/'.$auname)) + || (&Apache::lonnet::allowed('caa',$audom.'/'.$auname))) { return ''; } return 1; +} + 1;