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

banghart lon-capa-cvs@mail.lon-capa.org
Tue, 24 Aug 2004 20:57:12 -0000


banghart		Tue Aug 24 16:57:12 2004 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
  Log:
  
  	Now handles delete of empty subdirectory
  
  
  
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.29 loncom/interface/portfolio.pm:1.30
--- loncom/interface/portfolio.pm:1.29	Tue Aug 24 03:35:57 2004
+++ loncom/interface/portfolio.pm	Tue Aug 24 16:57:12 2004
@@ -161,7 +161,7 @@
 
 my $dirptr=16384;
 sub display_directory {
-    my ($r,$current_path,$dir_list)=@_;
+    my ($r,$current_path,$is_empty,$dir_list)=@_;
     my $iconpath= $r->dir_config('lonIconsURL') . "/";
     $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">');
     $r->print('<td bgcolor="#ccddaa" align="center">');
@@ -194,6 +194,16 @@
 	      &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
 						    'this.form.submit();'));
     $r->print("</form>");
+    if ($is_empty){
+        $displayOut = '<form method="post" action="/adm/portfolio">'.
+        '<input type="hidden" name="action" value="deletedir" />'.
+        '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
+        '<input type="hidden" name="selectfile" value="" />'.
+        '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
+        '</form>';
+        
+        $r->print($displayOut);
+    }else{
     $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
             '<tr><th>Actions</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
     my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio/$current_path/";
@@ -241,6 +251,7 @@
 #    $r->print('</td>><td>');
 #   $r->print(&display_actions($current_path, $currentFile, $isEmpty));
     $r->print('</table></form>');
+    }
 }
 
 sub open_form {
@@ -294,12 +305,36 @@
 					       $ENV{'form.currentpath'}.
 					       $ENV{'form.selectfile'});
     if ($result ne 'ok') {
-	$r->print('<font color="red"> An errror occured ('.$result.
+	$r->print('<font color="red"> An error occured ('.$result.
 		  ') while trying to delete '.&display_file().'</font><br />');
     }
     $r->print(&done());
 }
 
+sub delete_dir {
+    my ($r)=@_;
+    &open_form($r);
+    $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
+    &close_form($r);
+} 
+
+sub delete_dir_confirmed {
+    my ($r)=@_;
+    my $directory_name = $ENV{'form.currentpath'};
+    $r->print('<br />'.$directory_name.'<br />');
+    $directory_name =~ m/\/$/;
+    $directory_name = $`;
+    my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
+					       $ENV{'user.domain'},'portfolio'.
+					       $directory_name);
+    if ($result ne 'ok') {
+	$r->print('<font color="red"> An error occured (dir) ('.$result.
+#		  ') while trying to delete '.&display_file().'</font><br />');
+		  ') while trying to delete '.$directory_name.'</font><br />');
+    }
+    $r->print(&done());
+}
+
 sub rename {
     my ($r)=@_;
     &open_form($r);
@@ -385,6 +420,10 @@
 	&delete_confirmed($r);
     } elsif ($ENV{'form.action'} eq 'delete') {
 	&delete($r);
+    } elsif ($ENV{'form.action'} eq 'deletedir' && $ENV{'form.confirmed'}) {
+    &delete_dir_confirmed($r);
+    } elsif ($ENV{'form.action'} eq 'deletedir'){
+    &delete_dir($r);
     } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) {
 	&rename_confirmed($r);
     } elsif ($ENV{'form.action'} eq 'rename') {
@@ -406,15 +445,11 @@
     
 	# need to know if directory is empty so it can be removed if desired
 	my $is_empty=(@dir_list == 2);
-   
-	&display_directory($r,$current_path,\@dir_list);
-
-    }
-
+    &display_directory($r,$current_path,$is_empty,\@dir_list);
     $r->print("</body>\n</html>\n");
     $r->rflush();
     return OK;
+    }
 }
-
 1;
 __END__