[LON-CAPA-cvs] cvs: loncom(version_2_8_X) /interface portfolio.pm

raeburn raeburn@source.lon-capa.org
Sat, 03 Jan 2009 19:39:37 -0000


raeburn		Sat Jan  3 19:39:37 2009 EDT

  Modified files:              (Branch: version_2_8_X)
    /loncom/interface	portfolio.pm 
  Log:
  - Backport 1.204, 1.206 and part of 1.205.
  
  
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.196.2.1 loncom/interface/portfolio.pm:1.196.2.2
--- loncom/interface/portfolio.pm:1.196.2.1	Fri Dec 12 15:38:53 2008
+++ loncom/interface/portfolio.pm	Sat Jan  3 19:39:37 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # portfolio browser
 #
-# $Id: portfolio.pm,v 1.196.2.1 2008/12/12 15:38:53 raeburn Exp $
+# $Id: portfolio.pm,v 1.196.2.2 2009/01/03 19:39:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -80,7 +80,7 @@
 
 my $dirptr=16384;
 sub display_common {
-    my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload)=@_;
+    my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload,$group)=@_;
     my $namespace = &get_namespace();
     my $port_path = &get_port_path();
     if ($can_upload) {
@@ -99,10 +99,8 @@
         my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
 	my $help_fileupload = &Apache::loncommon::help_open_topic('Portfolio AddFiles');
 	my $help_createdir = &Apache::loncommon::help_open_topic('Portfolio CreateDirectory');
-		
-	# FIXME: This line should be deleted once Portfolio uses breadcrumbs
-	$r->print(&Apache::loncommon::help_open_topic('Portfolio About', &mt('Help on the portfolio')));
-
+        my $help_portfolio = &Apache::loncommon::help_open_topic('Portfolio About', &mt('Help on the portfolio'));
+        $r->print(&display_usage($group));
         my $parse_check;
         if (!&suppress_embed_prompt()) {
             $parse_check = <<"END";
@@ -114,7 +112,8 @@
         </span>
 END
         }
-        $r->print(<<"TABLE"); 
+        $r->print(<<"TABLE");
+$help_portfolio
 <table id="LC_portfolio_actions">
   <tr id="LC_portfolio_upload">
     <td class="LC_label">
@@ -140,7 +139,7 @@
     </td>
     <td class="LC_value">
       <form method="post" action="$escuri">
-        <input name="newdir" type="input" />$groupitem
+        <input name="newdir" type="text" />$groupitem
         <input type="hidden" name="currentpath" value="$current_path" />
         <input type="hidden" name="action" value="$env{"form.action"}" />
         <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
@@ -185,6 +184,48 @@
     $r->print("</form>");
 }
 
+sub display_usage {
+    my ($group) = @_;
+    my $disk_quota = &get_quota($group);
+    my $getpropath = 1;
+    my $portfolio_root = &get_portfolio_root();
+    my ($uname,$udom) = &get_name_dom($group);
+    my $current_disk_usage =
+         &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
+    my $usage = $current_disk_usage/1000;
+    my $quota = $disk_quota/1000;
+    my $percent;
+    if ($disk_quota == 0) {
+        $percent = 100.0;
+    } else {
+        $percent = 100*($current_disk_usage/$disk_quota);
+    }
+    $usage = sprintf("%.2f",$usage);
+    $quota = sprintf("%.2f",$quota);
+    $percent = sprintf("%.0f",$percent);
+    my ($color,$cssclass);
+    if ($percent <= 60) {
+        $color = '#00A000';
+    } elsif ($percent > 60 && $percent < 90) {
+        $color = '#FFD300';
+        $cssclass = 'class="LC_warning"';
+    } elsif( $percent >= 90) {
+        $color = '#FF0000';
+        $cssclass = 'class="LC_error"';
+    }
+    my $prog_width = $percent;
+    if ($prog_width > 100) {
+        $prog_width = 100;
+    }
+    my $disk_meter = '
+  <div align="left" '.$cssclass.'>'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB <span style="font-weight:bold;">('.$percent.'%)</span>',$quota.' MB')."\n".
+'   <div style="display:block; margin-top:5px; margin-bottom:5px; margin-left:0px; margin-right:0px; width:400px; border:1px solid #000000; height:10px;">'."\n".
+'    <div style="display:block; background-color:'.$color.'; width:'.$prog_width.'%; height:10px; color:#000000; margin:0px;"></div>'."\n".
+'   </div>'."\n".
+'  </div><br />';
+    return $disk_meter;
+}
+
 sub display_directory_line {
     my ($r,$select_mode, $filename, $mtime, $size, $css_class,
 	$line, $access_controls, $curr_access, $now, $version_flag,
@@ -668,7 +709,7 @@
     } else {
         &open_form($r,$url);
         $r->print('<p>'.&mt('Rename [_1] to [_2]?', &display_file()
-                  , '<input name="filenewname" type="input" size="50" />').'</p>');
+                  , '<input name="filenewname" type="text" size="50" />').'</p>');
         &close_form($r,$url);
     }
 }
@@ -2216,14 +2257,22 @@
         $r->print(&Apache::loncommon::start_page($title));
     }
     $r->rflush();
-    if (!&Apache::lonnet::usertools_access($uname,$udom,'portfolio')) {
-        $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
-                  &mt('This is a result of one of the following:').'<ul>'.
-                  '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
-                  '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
-                  '</ul>');
-        $r->print(&Apache::loncommon::end_page());
-        return OK;
+    if ($caller ne 'coursegrp_portfolio') {
+        &Apache::lonhtmlcommon::clear_breadcrumbs();
+        &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/portfolio",
+                                                text=>"Portfolio Manager"});
+        if (!&Apache::lonnet::usertools_access($uname,$udom,'portfolio')) {
+            $r->print(&Apache::lonhtmlcommon::breadcrumbs());
+            $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
+                      &mt('This is a result of one of the following:').'<ul>'.
+                      '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
+                      '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
+                      '</ul>');
+            $r->print(&Apache::loncommon::end_page());
+            return OK;
+        } else {
+            $r->print(&Apache::lonhtmlcommon::breadcrumbs('Portfolio Manager'));
+        }
     }
     my ($blocked,$blocktext) = 
         &Apache::loncommon::blocking_status('port',$uname,$udom);
@@ -2360,7 +2409,7 @@
 	# need to know if directory is empty so it can be removed if desired
 	my $is_empty=(@dir_list == 2);
 	&display_common($r,$url,$current_path,$is_empty,\@dir_list,
-			$can_upload);
+			$can_upload,$group);
         &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
                            $can_upload,$can_modify,$can_delete,$can_setacl);
 	$r->print(&Apache::loncommon::end_page());