[LON-CAPA-cvs] cvs: loncom /interface lonuserutils.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Sun, 23 Dec 2007 03:16:32 -0000


This is a MIME encoded message

--raeburn1198379792
Content-Type: text/plain

raeburn		Sat Dec 22 22:16:32 2007 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm 
  Log:
  &show_drop_list()
  - check classlist hash first to see if there are any students who can be dropped.
     - if not show "No students to drop" message instead of table.
  - eliminate $keylist from &show_drop_list args. Use call to &make_keylist_array() instead to get $indexhash and $keylist within show_drop_list.
  
  
--raeburn1198379792
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071222221632.txt"

Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.29 loncom/interface/lonuserutils.pm:1.30
--- loncom/interface/lonuserutils.pm:1.29	Sat Dec 22 17:42:58 2007
+++ loncom/interface/lonuserutils.pm	Sat Dec 22 22:16:30 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.29 2007/12/22 22:42:58 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.30 2007/12/23 03:16:30 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2841,7 +2841,7 @@
 #################################################
 #################################################
 sub show_drop_list {
-    my ($r,$classlist,$keylist,$nosort,$permission) = @_;
+    my ($r,$classlist,$nosort,$permission) = @_;
     my $cid = $env{'request.course.id'};
     my ($cnum,$cdom) = &get_course_identity($cid);
     if (! exists($env{'form.sortby'})) {
@@ -2852,9 +2852,6 @@
     if ($sortby !~ /^(username|domain|section|groups|fullname|id|start|end)$/) {
         $sortby = 'username';
     }
-    my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
-                                              $classlist,$keylist,$cdom,$cnum);
-    #
     my $action = "drop";
     my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
     $r->print(<<END);
@@ -2867,15 +2864,40 @@
 <p>
 <input type="hidden" name="phase" value="four">
 END
-
-my %lt=&Apache::lonlocal::texthash('usrn'   => "username",
-                                   'dom'    => "domain",
-                                   'sn'     => "student name",
-                                   'sec'    => "section",
-                                   'start'  => "start date",
-                                   'end'    => "end date",
-                                   'groups' => "active groups",
-                                   );
+    my ($indexhash,$keylist) = &make_keylist_array();
+    my $studentcount = 0;
+    if (ref($classlist) eq 'HASH') {
+        foreach my $student (keys(%{$classlist})) {
+            my $sdata = $classlist->{$student}; 
+            my $status = $sdata->[$indexhash->{'status'}];
+            my $section = $sdata->[$indexhash->{'section'}];
+            if ($status ne 'Active') {
+                delete($classlist->{$student});
+                next;
+            }
+            if ($env{'request.course.sec'} ne '') {
+                if ($section ne $env{'request.course.sec'}) {
+                    delete($classlist->{$student});
+                    next;
+                }
+            }
+            $studentcount ++;
+        }
+    }
+    if (!$studentcount) {
+        $r->print(&mt('There are no students to drop.'));
+        return;
+    }
+    my ($classgroups) = &Apache::loncoursedata::get_group_memberships(
+                                              $classlist,$keylist,$cdom,$cnum);
+    my %lt=&Apache::lonlocal::texthash('usrn'   => "username",
+                                       'dom'    => "domain",
+                                       'sn'     => "student name",
+                                       'sec'    => "section",
+                                       'start'  => "start date",
+                                       'end'    => "end date",
+                                       'groups' => "active groups",
+                                      );
     if ($nosort) {
         $r->print(&Apache::loncommon::start_data_table().
                   &Apache::loncommon::start_data_table_header_row());
@@ -2918,32 +2940,26 @@
     }
     #
     # Sort the students
-    my %index;
-    my $i;
-    foreach (@$keylist) {
-        $index{$_} = $i++;
-    }
-    $index{'groups'} = scalar(@$keylist);
-    my $index  = $index{$sortby};
-    my $second = $index{'username'};
-    my $third  = $index{'domain'};
+    my $index  = $indexhash->{$sortby};
+    my $second = $indexhash->{'username'};
+    my $third  = $indexhash->{'domain'};
     my @Sorted_Students = sort {
         lc($classlist->{$a}->[$index])  cmp lc($classlist->{$b}->[$index])
             ||
         lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
             ||
         lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
-        } (keys(%$classlist));
+        } (keys(%{$classlist}));
     foreach my $student (@Sorted_Students) {
         my $error;
         my $sdata = $classlist->{$student};
-        my $username = $sdata->[$index{'username'}];
-        my $domain   = $sdata->[$index{'domain'}];
-        my $section  = $sdata->[$index{'section'}];
-        my $name     = $sdata->[$index{'fullname'}];
-        my $id       = $sdata->[$index{'id'}];
-        my $start    = $sdata->[$index{'start'}];
-        my $end      = $sdata->[$index{'end'}];
+        my $username = $sdata->[$indexhash->{'username'}];
+        my $domain   = $sdata->[$indexhash->{'domain'}];
+        my $section  = $sdata->[$indexhash->{'section'}];
+        my $name     = $sdata->[$indexhash->{'fullname'}];
+        my $id       = $sdata->[$indexhash->{'id'}];
+        my $start    = $sdata->[$indexhash->{'start'}];
+        my $end      = $sdata->[$indexhash->{'end'}];
         my $groups = $classgroups->{$student};
         my $active_groups;
         if (ref($groups->{active}) eq 'HASH') {
@@ -2959,15 +2975,8 @@
         } else {
             $end = &Apache::lonlocal::locallocaltime($end);
         }
-        my $status   = $sdata->[$index{'status'}];
-        next if ($status ne 'Active');
-        if ($env{'request.course.sec'} ne '') {
-            if ($section ne $env{'request.course.sec'}) {
-                next;
-            }
-        }
         my $studentkey = $student.':'.$section;
-        my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$index{'start'}].'" />';
+        my $startitem = '<input type="hidden" name="'.$studentkey.'_start" value="'.$sdata->[$indexhash->{'start'}].'" />';
         #
         $r->print(&Apache::loncommon::start_data_table_row());
         $r->print(<<"END");
@@ -3534,7 +3543,7 @@
         if ($env{'form.fullup'} eq 'yes') {
             $r->print('<h3>'.&mt('Students to Drop')."</h3>\n");
             #  Get current classlist
-            my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+            my $classlist = &Apache::loncoursedata::get_classlist();
             if (! defined($classlist)) {
                 $r->print('<form name="studentform" method="post" action="/adm/createuser" />'.
                           '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
@@ -3542,8 +3551,8 @@
                           '</form>'."\n");
             } else {
                 # Remove the students we just added from the list of students.
-                foreach (@userdata) {
-                    my %entries=&Apache::loncommon::record_sep($_);
+                foreach my $line (@userdata) {
+                    my %entries=&Apache::loncommon::record_sep($line);
                     unless (($entries{$fields{'username'}} eq '') ||
                             (!defined($entries{$fields{'username'}}))) {
                         delete($classlist->{$entries{$fields{'username'}}.
@@ -3551,7 +3560,7 @@
                     }
                 }
                 # Print out list of dropped students.
-                &show_drop_list($r,$classlist,$keylist,'nosort',$permission);
+                &show_drop_list($r,$classlist,'nosort',$permission);
             }
         }
     } # end of unless
@@ -3654,14 +3663,12 @@
     my ($r,$context,$permission) = @_;
     $r->print('<h3>'.&mt("Drop Students").'</h3>'."\n".
               '<form name="studentform" method="post">'."\n");
-    my $cid=$env{'request.course.id'};
-    my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
+    my $classlist = &Apache::loncoursedata::get_classlist();
     if (! defined($classlist)) {
         $r->print(&mt('There are no students currently enrolled.')."\n");
-        return;
+    } else {
+        &show_drop_list($r,$classlist,'nosort',$permission);
     }
-    # Print out the available choices
-    &show_drop_list($r,$classlist,$keylist,$permission);
     $r->print('</form>'. &Apache::loncommon::end_page());
     return;
 }

--raeburn1198379792--