--- loncom/interface/lonuserutils.pm 2007/11/06 18:23:14 1.3 +++ loncom/interface/lonuserutils.pm 2007/11/10 22:18:09 1.4 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility functions for managing LON-CAPA user accounts # -# $Id: lonuserutils.pm,v 1.3 2007/11/06 18:23:14 raeburn Exp $ +# $Id: lonuserutils.pm,v 1.4 2007/11/10 22:18:09 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1281,12 +1281,16 @@ sub print_userlist { } } else { # Print out the available choices + my $usercount; if ($env{'form.action'} eq 'modifystudent') { - &show_users_list($r,$context,'view','modify', - $env{'form.Status'},\%userlist,$keylist); + ($usercount) = &show_users_list($r,$context,'view','modify', + $env{'form.Status'},\%userlist,$keylist); } else { - &show_users_list($r,$context,$env{'form.output'},'aboutme', - $env{'form.Status'},\%userlist,$keylist); + ($usercount) = &show_users_list($r,$context,$env{'form.output'}, + 'aboutme',$env{'form.Status'},\%userlist,$keylist); + } + if (!$usercount) { + $r->print('
'.&mt('There are no users matching the search criteria.')); } } $r->print(''); @@ -1699,73 +1703,76 @@ END } push(@cols,'email'); - my $rolefilter; + my $rolefilter = $env{'form.showrole'}; if ($env{'form.showrole'} ne 'Any') { $rolefilter = &Apache::lonnet::plaintext($env{'form.showrole'}); } my $results_description = &results_header_row($rolefilter,$statusmode, $context); $r->print(''.$results_description.'
'); + my $output; if ($mode eq 'html' || $mode eq 'view') { - if ($linkto eq 'aboutme') { - $r->print(&mt("Select a user name to view the user's personal page.")); - } elsif ($linkto eq 'modify') { - $r->print(&mt("Select a user name to modify the user's information")); - } $r->print(< END - $r->print("\n

\n". + if ($linkto eq 'aboutme') { + $output = &mt("Select a user name to view the user's personal page."); + } elsif ($linkto eq 'modify') { + $output = &mt("Select a user name to modify the user's information"); + } + $output .= "\n

\n". &Apache::loncommon::start_data_table(). - &Apache::loncommon::start_data_table_header_row()); + &Apache::loncommon::start_data_table_header_row(); if ($mode eq 'autoenroll') { - $r->print(" + $output .= " $lt{'type'} - "); + "; } else { - $r->print(" + $output .= " Count - "); + "; } foreach my $item (@cols) { - $r->print("$lt{$item}\n"); + $output .= "$lt{$item}\n"; } my %role_types = &role_type_names(); if ($context eq 'course') { - # Clicker display on or off? - my %clicker_options = &Apache::lonlocal::texthash( - 'on' => 'Show', - 'off' => 'Hide', - ); - my $clickerchg = 'on'; - if ($displayclickers eq 'on') { - $clickerchg = 'off'; - } - $r->print(' '."\n".' '. - ''. $clicker_options{$clickerchg}.' '.$lt{'clicker'}."\n". - ' '."\n"); + ' '."\n"; - # Photo display on or off? - if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) { - my %photo_options = &Apache::lonlocal::texthash( - 'on' => 'Show', - 'off' => 'Hide', - ); - my $photochg = 'on'; - if ($displayphotos eq 'on') { - $photochg = 'off'; - } - $r->print(' '."\n".' '. - ''. $photo_options{$photochg}.' '.$lt{'photo'}."\n". - ' '."\n"); + ' '."\n"; + } } - $r->print(&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') { # @@ -1805,10 +1812,13 @@ END foreach my $idx (@$keylist) { $index{$idx} = $i++; } + my $usercount = 0; # Get groups, role, permanent e-mail so we can sort on them if # necessary. foreach my $user (keys(%{$userlist})) { my ($uname,$udom,$role,$groups,$email); + next if (($statusmode ne 'Any') && + ($userlist->{$user}->[$index{'status'}] ne $statusmode)); if ($context eq 'domain') { if ($env{'form.roletype'} eq 'domain') { ($role,$uname,$udom) = split(/:/,$user); @@ -1839,8 +1849,21 @@ END if ($emails{'permanentemail'} =~ /\S/) { $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'}; } + $usercount ++; + } + my $autocount = 0; + my $manualcount = 0; + my $lockcount = 0; + my $unlockcount = 0; + if ($usercount) { + $r->print($output); + } else { + if ($mode eq 'autoenroll') { + return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount); + } else { + return; + } } - # # Sort the users my $index = $index{$sortby}; @@ -1852,18 +1875,14 @@ END lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) || lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third]) } (keys(%$userlist)); - my $usercount = 0; - my $autocount = 0; - my $manualcount = 0; - my $lockcount = 0; - my $unlockcount = 0; + my $rowcount = 0; foreach my $user (@sorted_users) { - my $sdata = $userlist->{$user}; my %in; + my $sdata = $userlist->{$user}; + $rowcount ++; foreach my $item (@{$keylist}) { $in{$item} = $sdata->[$index{$item}]; } - next if (($statusmode ne 'Any') && ($in{'status'} ne $statusmode)); $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}]); if (! defined($in{'start'}) || $in{'start'} == 0) { $in{'start'} = &mt('none'); @@ -1875,10 +1894,9 @@ END } else { $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'}); } - $usercount ++; if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') { $r->print(&Apache::loncommon::start_data_table_row()); - $r->print("$usercount\n"); + $r->print("$rowcount\n"); if ($linkto eq 'aboutme') { $in{'username'} = &Apache::loncommon::aboutmewrapper($in{'username'}, @@ -1897,23 +1915,25 @@ END $r->print(''.$in{$item}.''."\n"); } if ($context eq 'course') { - if ($displayclickers eq 'on') { - my $clickers = + if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') { + if ($displayclickers eq 'on') { + my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1]; - if ($clickers!~/\w/) { $clickers='-'; } - $r->print(''.$clickers.''); - } else { - $r->print('   '); - } - if ($displayphotos eq 'on') { - if ($env{'course.'.$env{'request.course.id'}. - '.internal.showphoto'}) { - my $imgurl = - &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'},'gif','thumbnail'); - $r->print(' '); + if ($clickers!~/\w/) { $clickers='-'; } + $r->print(''.$clickers.''); } else { $r->print('   '); } + if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) { + if ($displayphotos eq 'on' && $sdata->[$index{'role'}] eq 'st') { + my $imgurl = + &Apache::lonnet::retrievestudentphoto($in{'domain'},$in{'username'}, + 'gif','thumbnail'); + $r->print(' '); + } else { + $r->print('   '); + } + } } } $r->print(&Apache::loncommon::end_data_table_row()); @@ -1968,8 +1988,9 @@ END } if ($mode eq 'autoenroll') { return ($usercount,$autocount,$manualcount,$lockcount,$unlockcount); + } else { + return ($usercount); } - return; } sub role_type_names {