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

raeburn raeburn at source.lon-capa.org
Mon Dec 9 16:33:32 EST 2013


raeburn		Mon Dec  9 21:33:32 2013 EDT

  Modified files:              
    /loncom/interface	lonuserutils.pm loncreateuser.pm loncoursedata.pm 
  Log:
  - Columns for disk usage (%) and disk quota (MB) available for selection 
    when listing users with Author roles (domain context).
  - User listing can be sorted by disk usage or disk quota (sorts numerically),
    whereas lexical sort used for other sortable fields. 
  
  
-------------- next part --------------
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.158 loncom/interface/lonuserutils.pm:1.159
--- loncom/interface/lonuserutils.pm:1.158	Mon Dec  9 18:47:18 2013
+++ loncom/interface/lonuserutils.pm	Mon Dec  9 21:33:32 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.158 2013/12/09 18:47:18 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.159 2013/12/09 21:33:32 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1637,7 +1637,7 @@
          return;
     }
     my ($indexhash,$keylist) = &make_keylist_array();
-    my (%userlist,%userinfo,$clearcoursepick);
+    my (%userlist,%userinfo,$clearcoursepick,$needauthorquota,$needauthorusage);
     if (($context eq 'domain') && 
         ($env{'form.roletype'} eq 'course') || 
         ($env{'form.roletype'} eq 'community')) {
@@ -1709,6 +1709,12 @@
                              \%cstr_roles,$permission);
         } elsif ($context eq 'domain') {
             if ($env{'form.roletype'} eq 'domain') {
+                if (grep(/^authorusage$/, at cols)) {
+                    $needauthorusage = 1;
+                }
+                if (grep(/^authorquota$/, at cols)) {
+                    $needauthorquota = 1;
+                }
                 %dom_roles = &Apache::lonnet::get_domain_roles($env{'request.role.domain'});
                 foreach my $key (keys(%dom_roles)) {
                     if (ref($dom_roles{$key}) eq 'HASH') {
@@ -1821,7 +1827,7 @@
         } else {
             ($usercount) = &show_users_list($r,$context,$env{'form.output'},
                                $permission,$env{'form.Status'},\%userlist,
-                               $keylist,'',$showcredits);
+                               $keylist,'',$showcredits,$needauthorquota,$needauthorusage);
         }
         if (!$usercount) {
             $r->print('<br /><span class="LC_info">'
@@ -1991,7 +1997,7 @@
             push(@cols,'photo');
         }
         if ($context eq 'domain') {
-            push (@cols,'extent');
+            push (@cols,('authorusage','authorquota','extent'));
         }
     }
     return @cols;
@@ -2027,6 +2033,8 @@
             if (($env{'form.roletype'} eq 'course') || 
                 ($env{'form.roletype'} eq 'community')) {
                 $disabledchk{'status'} = 1;
+                $disabledchk{'authorusage'} = 1;
+                $disabledchk{'authorquota'} = 1;
             } elsif ($env{'form.roletype'} eq 'domain') {
                 $disabledchk{'extent'} = 1; 
             }
@@ -2078,7 +2086,11 @@
             if (($env{'form.roletype'} eq 'domain') || ($env{'form.roletype'} eq '')) {
                 $style = ' style="display: none;"';
             } 
-        } 
+        } elsif (($cols[$i] eq 'authorusage') || ($cols[$i] eq 'authorquota')) {
+            if ($env{'form.roletype'} ne 'domain') {
+                $style = ' style="display: none;"';
+            }
+        }
         $output .= '<span id="show'.$cols[$i].'"'.$style.'><label>'.
                    '<input id="showcol'.$cols[$i].'" type="checkbox" name="showcol" value="'.$cols[$i].'"'.$checked.' /><span id="showcoltext'.$cols[$i].'">'.
                    $lt{$cols[$i]}.'</span>'.
@@ -2112,6 +2124,8 @@
         'photo'      => "photo",
         'lastlogin'  => "last login",
         'extent'     => "extent",
+        'authorusage' => "disk usage (%)",
+        'authorquota' => "disk quota (MB)",
         'ca'         => "check all",
         'ua'         => "uncheck all",
         'clicker'    => "clicker-ID",
@@ -2395,6 +2409,8 @@
     $index->{'photo'} = &Apache::loncoursedata::CL_PHOTO();
     $index->{'thumbnail'} = &Apache::loncoursedata::CL_THUMBNAIL();
     $index->{'credits'} = &Apache::loncoursedata::CL_CREDITS();
+    $index->{'authorquota'} = &Apache::loncoursedata::CL_AUTHORQUOTA();
+    $index->{'authorusage'} = &Apache::loncoursedata::CL_AUTHORUSAGE();
     foreach my $key (keys(%{$index})) {
         $keylist->[$index->{$key}] = $key;
     }
@@ -2444,10 +2460,11 @@
 
 sub show_users_list {
     my ($r,$context,$mode,$permission,$statusmode,$userlist,$keylist,$formname,
-        $showcredits)=@_;
+        $showcredits,$needauthorquota,$needauthorusage)=@_;
     if ($formname eq '') {
         $formname = 'studentform';
     }
+    my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
     #
     # Variables for excel output
     my ($excel_workbook, $excel_sheet, $excel_filename,$row,$format);
@@ -2464,6 +2481,10 @@
         }
     } else {
         push(@sortable,'extent');
+        if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') &&
+            (($env{'form.showrole'} eq 'Any') || ($env{'form.showrole'} eq 'au'))) {
+            push(@sortable,('authorusage','authorquota'));
+        }
     }
     if ($mode eq 'pickauthor') {
         @sortable = ('username','fullname','email','status');
@@ -2710,13 +2731,13 @@
         } else {
             $output .= "\n".'<th> </th>'."\n";
             if ($actionselect) {
-                $output .= '<th>'.&mt('Select').'</th>'."\n";
+                $output .= '<th class="LC_nobreak" valign="top">'.&mt('Select').'</th>'."\n";
             }
         }
         foreach my $item (@cols) {
-            $output .= "<th>";
+            $output .= '<th class="LC_nobreak" valign="top">';
             if ($is_sortable{$item}) {
-                $output .= "<a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\">$lt{$item}</a>";
+                $output .= "<a href=\"javascript:document.$formname.sortby.value='$item';document.$formname.submit();\" style=\"text-decoration:none;\">$lt{$item}<span class=\"LC_fontsize_small\"> ▼</span></a>";
             } else {
                 $output .= $lt{$item};
             }
@@ -2891,6 +2912,26 @@
         if ($emails{'permanentemail'} =~ /\S/) {
             $userlist->{$user}->[$index{'email'}] = $emails{'permanentemail'};
         }
+        if (($context eq 'domain') && ($env{'form.roletype'} eq 'domain') && 
+            ($role eq 'au')) {
+            my ($disk_quota,$current_disk_usage,$percent); 
+            if (($needauthorusage) || ($needauthorquota)) {
+                $disk_quota = &Apache::loncommon::get_user_quota($uname,$udom,'author');
+            }
+            if ($needauthorusage) {
+                $current_disk_usage =
+                    &Apache::lonnet::diskusage($udom,$uname,"$londocroot/priv/$udom/$uname");
+                if ($disk_quota == 0) {
+                    $percent = 100.0;
+                } else {
+                    $percent = $current_disk_usage/(10 * $disk_quota);
+                }
+                $userlist->{$user}->[$index{'authorusage'}] = sprintf("%.0f",$percent);
+            }
+            if ($needauthorquota) {
+                $userlist->{$user}->[$index{'authorquota'}] = sprintf("%.2f",$disk_quota);
+            }
+        }
         $usercount ++;
     }
     my $autocount = 0;
@@ -2911,12 +2952,20 @@
     my $index  = $index{$sortby};
     my $second = $index{'username'};
     my $third  = $index{'domain'};
-    my @sorted_users = sort {
-        lc($userlist->{$a}->[$index])  cmp lc($userlist->{$b}->[$index])
-            ||
-        lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second])            ||
-        lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
-        } (keys(%$userlist));
+    my @sorted_users;
+    if (($sortby eq 'authorquota') || ($sortby eq 'authorusage')) {  
+        @sorted_users = sort {
+            $userlist->{$b}->[$index] <=> $userlist->{$a}->[$index]           ||
+            lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
+            lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
+            } (keys(%$userlist));
+    } else {
+        @sorted_users = sort {
+            lc($userlist->{$a}->[$index]) cmp lc($userlist->{$b}->[$index])   ||
+            lc($userlist->{$a}->[$second]) cmp lc($userlist->{$b}->[$second]) ||
+            lc($userlist->{$a}->[$third]) cmp lc($userlist->{$b}->[$third])
+            } (keys(%$userlist));
+    }
     my $rowcount = 0;
     foreach my $user (@sorted_users) {
         my %in;
@@ -2927,7 +2976,7 @@
         }
         my $clickers = (&Apache::lonnet::userenvironment($in{'domain'},$in{'username'},'clickers'))[1];
         if ($clickers!~/\w/) { $clickers='-'; }
-        $in{'clicker'} = $clickers; 
+        $in{'clicker'} = $clickers;
 	my $role = $in{'role'};
         $in{'role'}=&Apache::lonnet::plaintext($sdata->[$index{'role'}],$crstype);
         unless ($mode eq 'excel') {
@@ -3051,6 +3100,8 @@
                              $r->print('<td> </td>'."\n");
                         } 
                     }
+                } elsif (($item eq 'authorquota') || ($item eq 'authorusage')) {
+                    $r->print('<td align="right">'.$in{$item}.'</td>'."\n");
                 } else {
                     $r->print('<td>'.$in{$item}.'</td>'."\n");
                 }
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.381 loncom/interface/loncreateuser.pm:1.382
--- loncom/interface/loncreateuser.pm:1.381	Fri Jul 19 18:24:17 2013
+++ loncom/interface/loncreateuser.pm	Mon Dec  9 21:33:32 2013
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.381 2013/07/19 18:24:17 bisitz Exp $
+# $Id: loncreateuser.pm,v 1.382 2013/12/09 21:33:32 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4804,6 +4804,7 @@
             document.getElementById('showcolrole').disabled = 'disabled';
         }
         if (context == 'domain') {
+            var quotausageshow = 0;
             if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
                 (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
                 document.getElementById('showcolstatus').checked = false;
@@ -4823,6 +4824,16 @@
                 document.getElementById('showcolextent').checked = 'false';
                 document.getElementById('showextent').style.display='none';
                 document.getElementById('showcoltextextent').innerHTML = '';
+                if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
+                    (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
+                    if (document.getElementById('showcolauthorusage')) {
+                        document.getElementById('showcolauthorusage').disabled = '';
+                    }
+                    if (document.getElementById('showcolauthorquota')) {
+                        document.getElementById('showcolauthorquota').disabled = '';
+                    }
+                    quotausageshow = 1;
+                }
             } else {
                 document.getElementById('showextent').style.display='block';
                 document.getElementById('showextent').style.textAlign='left';
@@ -4841,6 +4852,16 @@
                     }
                 }
             }
+            if (quotausageshow == 0)  {
+                if (document.getElementById('showcolauthorusage')) {
+                    document.getElementById('showcolauthorusage').checked = false;
+                    document.getElementById('showcolauthorusage').disabled = 'disabled';
+                }
+                if (document.getElementById('showcolauthorquota')) {
+                    document.getElementById('showcolauthorquota').checked = false;
+                    document.getElementById('showcolauthorquota').disabled = 'disabled';
+                }
+            }
         }
     }
     return;
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.194 loncom/interface/loncoursedata.pm:1.195
--- loncom/interface/loncoursedata.pm:1.194	Fri Mar  1 04:58:08 2013
+++ loncom/interface/loncoursedata.pm	Mon Dec  9 21:33:32 2013
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.194 2013/03/01 04:58:08 raeburn Exp $
+# $Id: loncoursedata.pm,v 1.195 2013/12/09 21:33:32 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2298,6 +2298,8 @@
 sub CL_EXTENT   { return 14; }
 sub CL_PHOTO   { return 15; }
 sub CL_THUMBNAIL { return 16; }
+sub CL_AUTHORQUOTA { return 17; }
+sub CL_AUTHORUSAGE { return 18; }
 
 sub get_classlist {
     my ($cdom,$cnum) = @_;


More information about the LON-CAPA-cvs mailing list