Diff for /loncom/interface/lonuserutils.pm between versions 1.109.2.2 and 1.109.2.3

version 1.109.2.2, 2010/01/05 22:08:48 version 1.109.2.3, 2010/08/09 23:39:43
Line 36  use Apache::loncommon(); Line 36  use Apache::loncommon();
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::longroup;  use Apache::longroup;
   use Apache::lonnavmaps;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
   
 ###############################################################  ###############################################################
Line 2095  sub process_date_info { Line 2096  sub process_date_info {
   
 sub show_users_list {  sub show_users_list {
     my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;      my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname)=@_;
       my $custommenu; 
     if ($formname eq '') {      if ($formname eq '') {
         $formname = 'studentform';          $formname = 'studentform';
     }      }
Line 2119  sub show_users_list { Line 2121  sub show_users_list {
         $sortby = 'username';          $sortby = 'username';
     }      }
     my $setting = $env{'form.roletype'};      my $setting = $env{'form.roletype'};
     my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers,$crstype);      my ($cid,$cdom,$cnum,$classgroups,$displayphotos,$displayclickers,$crstype,
           $clickersupport,$displaygroups);
     if ($context eq 'course') {      if ($context eq 'course') {
         $cid = $env{'request.course.id'};          $cid = $env{'request.course.id'};
         $crstype = &Apache::loncommon::course_type();          $crstype = &Apache::loncommon::course_type();
         ($cnum,$cdom) = &get_course_identity($cid);          ($cnum,$cdom) = &get_course_identity($cid);
           $custommenu = &Apache::loncommon::needs_gci_custom();
           unless ($custommenu) {
               $clickersupport = 1;
               $displaygroups = 1;
           }
         ($classgroups) = &Apache::loncoursedata::get_group_memberships(          ($classgroups) = &Apache::loncoursedata::get_group_memberships(
                                      $userlist,$keylist,$cdom,$cnum);                                       $userlist,$keylist,$cdom,$cnum);
         if ($mode eq 'autoenroll') {          if ($mode eq 'autoenroll') {
Line 2244  END Line 2252  END
                        'role'       => "role",                         'role'       => "role",
                        'type'       => "enroll type/action",                         'type'       => "enroll type/action",
                        'email'      => "e-mail address",                         'email'      => "e-mail address",
                          'lastlogin'  => "last login",
                          'submissions' => "test status",
                        'photo'      => "photo",                         'photo'      => "photo",
                        'extent'     => "extent",                         'extent'     => "extent",
                        'pr'         => "Proceed",                         'pr'         => "Proceed",
Line 2290  END Line 2300  END
             push(@cols,'status');              push(@cols,'status');
         }          }
         if ($context eq 'course') {          if ($context eq 'course') {
             push(@cols,'groups');              if ($displaygroups) {
                   push(@cols,'groups');
               }
         }          }
         push(@cols,'email');          push(@cols,'email');
           if ($context eq 'course') {
               if ($custommenu) {
                   push(@cols,'lastlogin');
                   if (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'st')) {
                       push(@cols,'submissions');
                   }
               }
           }
     }      }
   
     my $rolefilter = $env{'form.showrole'};      my $rolefilter = $env{'form.showrole'};
Line 2415  END Line 2435  END
             }              }
         }          }
         foreach my $item (@cols) {          foreach my $item (@cols) {
             $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";              if (grep(/^\Q$item\E$/,@sortable)) {
                   $output .= "<th><a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a></th>\n";
               } else {
                   $output .= "<th>$lt{$item}</th>\n";
               }
         }          }
         my %role_types = &role_type_names();          my %role_types = &role_type_names();
         if ($context eq 'course' && $mode ne 'autoenroll') {          if ($context eq 'course' && $mode ne 'autoenroll') {
             if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {              if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
                 # Clicker display on or off?                  # Clicker display on or off?
                 my %clicker_options = (                  if ($clickersupport) {
                                         'on' => 'Show',                      my %clicker_options = (
                                         'off' => 'Hide',                                              'on' => 'Show',
                                       );                                              'off' => 'Hide',
                 my $clickerchg = 'on';                                            );
                 if ($displayclickers eq 'on') {                      my $clickerchg = 'on';
                     $clickerchg = 'off';                      if ($displayclickers eq 'on') {
                 }                          $clickerchg = 'off';
                 $output .= '    <th>'."\n".'     '                      }
                         .&mt('[_1]'.$clicker_options{$clickerchg}.'[_2] clicker id'                      $output .= '    <th>'."\n".'     '
                          .&mt('[_1]'.$clicker_options{$clickerchg}.'[_2] clicker id'
                             ,'<a href="javascript:document.'.$formname.'.displayclickers.value='                              ,'<a href="javascript:document.'.$formname.'.displayclickers.value='
                              ."'".$clickerchg."'".';document.'.$formname.'.submit();">'                               ."'".$clickerchg."'".';document.'.$formname.'.submit();">'
                             ,'</a>')                              ,'</a>')
                         ."\n".'    </th>'."\n";                          ."\n".'    </th>'."\n";
                   }
                 # Photo display on or off?                  # Photo display on or off?
                 if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {                  if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
                     my %photo_options = &Apache::lonlocal::texthash(                      my %photo_options = &Apache::lonlocal::texthash(
Line 2474  END Line 2499  END
             $CSVfile = undef;              $CSVfile = undef;
         }          }
         #          #
         push @cols,'clicker';          if ($clickersupport) {
               push @cols,'clicker';
           }
         # Write headers and data to file          # Write headers and data to file
         print $CSVfile '"'.$results_description.'"'."\n";           print $CSVfile '"'.$results_description.'"'."\n"; 
         print $CSVfile '"'.join('","',map {          print $CSVfile '"'.join('","',map {
             &Apache::loncommon::csv_translate($lt{$_})              &Apache::loncommon::csv_translate($lt{$_})
             } (@cols))."\"\n";              } (@cols))."\"\n";
     } elsif ($mode eq 'excel') {      } elsif ($mode eq 'excel') {
         push @cols,'clicker';          if ($clickersupport) {
               push @cols,'clicker';
           }
         # Create the excel spreadsheet          # Create the excel spreadsheet
         ($excel_workbook,$excel_filename,$format) =          ($excel_workbook,$excel_filename,$format) =
             &Apache::loncommon::create_workbook($r);              &Apache::loncommon::create_workbook($r);
Line 2517  END Line 2546  END
                                                 Future  => 'Future',                                                  Future  => 'Future',
                                                 Expired => 'Expired',                                                  Expired => 'Expired',
                                                );                                                 );
       # If this is for a single course get last course "log-in" and submissions.
       my (%crslogins,%stusubmissions,%elapsed,$numparts,%nummultipart,$multipart);
       my $now = time;
       if ($context eq 'course') {
           if ($custommenu) {
               %crslogins=&Apache::lonnet::dump('nohist_crslastlogin',$cdom,$cnum);
               %stusubmissions=&Apache::lonnet::dump('nohist_submissiontracker',$cdom,$cnum);
               %elapsed = &Apache::lonlocal::texthash(    
                                            -1 => 'more than a month ago',
                                       2592000 => 'within last 30 days',
                                        604800 => 'within last 7 days',
                                         86400 => 'within last 24 hours',
                                      );
               my $navmap = Apache::lonnavmaps::navmap->new();
               if (defined($navmap)) {
                   my @allres=$navmap->retrieveResources('/uploaded/'.$cdom.'/'.$cnum.'/default_1261144274.sequence',sub { $_[0]->is_problem() },0);
                   foreach my $resource (@allres) {
                       my @parts = $resource->parts();
                       my $count = scalar(@parts);
                       if ($count > 1) {
                           $nummultipart{$count} ++;
                       }
                       $numparts += $count;
                   }
                   if (keys(%nummultipart) > 0) {
                      $multipart = '<br />'.'contains';
                      foreach my $key (sort {$a <=> $b} keys(%nummultipart)) {
                          $multipart .= " nummultipart{$key} multipart questions (with $key parts)";
                      }
                   }
               }
           }
       }
   
     # Get groups, role, permanent e-mail so we can sort on them if      # Get groups, role, permanent e-mail so we can sort on them if
     # necessary.      # necessary.
     foreach my $user (keys(%{$userlist})) {      foreach my $user (keys(%{$userlist})) {
Line 2663  END Line 2726  END
         } else {          } else {
             $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});              $in{'end'} = &Apache::lonlocal::locallocaltime($in{'end'});
         }          }
           if ($context eq 'course') {
               if ($custommenu) {
                   my $lastlogin = $crslogins{$in{'username'}.':'.$in{'domain'}.':'.$in{'section'}.':'.$role};
                   if ($lastlogin ne '') {
                       my $sincelogin = $now - $lastlogin;
                       if ($sincelogin < 86400) {
                           $in{'lastlogin'} = $elapsed{'86400'};
                       } elsif ($sincelogin < 604800) {
                           $in{'lastlogin'} = $elapsed{'604800'};
                       } elsif ($sincelogin < 2592000 ) {
                           $in{'lastlogin'} = $elapsed{'2592000'};
                       } else {
                           $in{'lastlogin'} = $elapsed{'-1'};
                       }
                   }
               }
               if ($role eq 'st') {
                   my $numsub = $stusubmissions{$in{'username'}.':'.$in{'domain'}."\0attempts"} + 
                                $stusubmissions{$in{'username'}.':'.$in{'domain'}."\0pilotsubs"};
                   if (!$numsub) {
                       $in{'submissions'} = 'unattempted';
                   } elsif ($numsub < $numparts) {
                       $in{'submissions'} = 'incomplete ('.$numsub.'/'.$numparts.')';
                   } else {
                       $in{'submissions'} = 'completed';
                   }
               }
           }
         if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {          if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll' || $mode eq 'pickauthor') {
             $r->print(&Apache::loncommon::start_data_table_row());              $r->print(&Apache::loncommon::start_data_table_row());
             my $checkval;              my $checkval;
Line 2736  END Line 2827  END
                         $showitem = $ltstatus{$in{$item}};                          $showitem = $ltstatus{$in{$item}};
                     }                      }
                     $r->print('<td>'.$showitem.'</td>'."\n");                      $r->print('<td>'.$showitem.'</td>'."\n");
                   } elsif ($item eq 'submissions') {
                       if ($in{$item} =~ /^incomplete/) { 
                           $r->print('<td>'.$in{$item}.$multipart.'</td>');
                       } else {
                           $r->print('<td>'.$in{$item}.'</td>'."\n");
                       }
                 } else {                  } else {
                     $r->print('<td>'.$in{$item}.'</td>'."\n");                      $r->print('<td>'.$in{$item}.'</td>'."\n");
                 }                  }
             }              }
             if (($context eq 'course') && ($mode ne 'autoenroll')) {              if (($context eq 'course') && ($mode ne 'autoenroll')) {
                 if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {                  if ($env{'form.showrole'} eq 'st' || $env{'form.showrole'} eq 'Any') {
                     if ($displayclickers eq 'on') {                      if ($clickersupport) {
                         my $clickers =                          if ($displayclickers eq 'on') {
                               my $clickers =
                    (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];                     (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
                         if ($clickers!~/\w/) { $clickers='-'; }                              if ($clickers!~/\w/) { $clickers='-'; }
                         $r->print('<td>'.$clickers.'</td>');                              $r->print('<td>'.$clickers.'</td>');
                     } else {                          } else {
                         $r->print('    <td>&nbsp;</td>  ');                              $r->print('    <td>&nbsp;</td>  ');
                           }
                     }                      }
                     if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {                      if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
                         if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {                          if ($displayphotos eq 'on' && $role eq 'st' && $in{'photo'} ne '') {
Line 3464  sub show_drop_list { Line 3563  sub show_drop_list {
     my ($r,$classlist,$nosort,$permission,$crstype) = @_;      my ($r,$classlist,$nosort,$permission,$crstype) = @_;
     my $cid = $env{'request.course.id'};      my $cid = $env{'request.course.id'};
     my ($cnum,$cdom) = &get_course_identity($cid);      my ($cnum,$cdom) = &get_course_identity($cid);
       my $displaygroups;
       unless (&Apache::loncommon::needs_gci_custom()) {
           $displaygroups = 1;
       }
     if (! exists($env{'form.sortby'})) {      if (! exists($env{'form.sortby'})) {
         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                                 ['sortby']);                                                  ['sortby']);
Line 3541  END Line 3644  END
     <th>$lt{'sec'}</th>      <th>$lt{'sec'}</th>
     <th>$lt{'start'}</th>      <th>$lt{'start'}</th>
     <th>$lt{'end'}</th>      <th>$lt{'end'}</th>
     <th>$lt{'groups'}</th>  
 END  END
           if ($displaygroups) {
               $r->print("    <th>$lt{'groups'}</th>\n");
           }
         $r->print(&Apache::loncommon::end_data_table_header_row());          $r->print(&Apache::loncommon::end_data_table_header_row());
     } else  {      } else  {
         $r->print(&Apache::loncommon::start_data_table().          $r->print(&Apache::loncommon::start_data_table().
Line 3563  END Line 3668  END
        <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>         <a href="/adm/createuser?action=$action&sortby=start">$lt{'start'}</a>
     </th><th>      </th><th>
        <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>         <a href="/adm/createuser?action=$action&sortby=end">$lt{'end'}</a>
     </th><th>  
        <a href="/adm/createuser?action=$action&sortby=groups">$lt{'groups'}</a>  
     </th>      </th>
 END  END
          if ($displaygroups) {
              $r->print("<th>
          <a href=\"/adm/createuser?action=$action&sortby=groups\">$lt{'groups'}</a>
       </th>\n");
           }
         $r->print(&Apache::loncommon::end_data_table_header_row());          $r->print(&Apache::loncommon::end_data_table_header_row());
     }      }
     #      #
Line 3619  END Line 3727  END
     <td>$section</td>      <td>$section</td>
     <td>$start $startitem</td>      <td>$start $startitem</td>
     <td>$end</td>      <td>$end</td>
     <td>$active_groups</td>  
 END  END
           if ($displaygroups) {
               $r->print("    <td>$active_groups</td>\n");
           }
         $r->print(&Apache::loncommon::end_data_table_row());          $r->print(&Apache::loncommon::end_data_table_row());
     }      }
     $r->print(&Apache::loncommon::end_data_table().'<br />');      $r->print(&Apache::loncommon::end_data_table().'<br />');

Removed from v.1.109.2.2  
changed lines
  Added in v.1.109.2.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>