--- loncom/interface/portfolio.pm 2004/06/21 14:10:05 1.5
+++ loncom/interface/portfolio.pm 2004/08/24 06:51:11 1.26
@@ -18,12 +18,9 @@
#
# /home/httpd/html/adm/gpl.txt
#
-
-
# http://www.lon-capa.org/
#
-
package Apache::portfolio;
use strict;
use Apache::Constants qw(:common :http);
@@ -33,40 +30,372 @@ use Apache::lontexconvert;
use Apache::lonfeedback;
use Apache::lonlocal;
+# receives a file name and path stub from username/userfiles/portfolio/
+# returns an anchor tag consisting encoding filename and currentpath
+sub make_anchor {
+ my ($filename, $current_path) = @_;
+ my $anchor = ''.$filename.'';
+ return $anchor;
+}
+
+# returns html with
separated contents of the directory
+# returns a currentFile (bolds the selected file/dir)
+sub display_directory_old {
+ my ($currentPath, $currentFile, @dirList,) = @_;
+ my $displayOut='';
+ my $filename;
+ my $upPath;
+ if ($currentPath ne '/') {
+ $displayOut = 'Listing of '.$currentPath.'
'); + my $displayOut = ''; + $r->print($displayOut); + $r->print(' |
'); + $displayOut = ''; + $r->print($displayOut); + $r->print(' |
Actions | Name | Size | Last Modified | |
---|---|---|---|---|
'); + $r->print(' | Go to ... | '); + $r->print(''.&make_anchor($filename.'/',$current_path.$filename.'/').' | '); + $r->print('||
+ + | '); + $r->print(''); + $r->print(' | '. + $filename.' | '); + $r->print(''.$size.' | '); + $r->print(''.&Apache::lonlocal::locallocaltime($mtime).' | '); + $r->print('
'); +# $r->print(&display_actions($current_path, $currentFile, $isEmpty)); + $r->print(' |
'.&mt('Delete').' '.&display_file().'?
'); + &close_form($r); +} + +sub delete_confirmed { + my ($r)=@_; + my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'}, + $ENV{'user.domain'},'portfolio'. + $ENV{'form.currentpath'}. + $ENV{'form.selectfile'}); + if ($result ne 'ok') { + $r->print(' An errror occured ('.$result. + ') while trying to delete '.&display_file().''.&mt('Rename').' '.&display_file().'?
'); + &close_form($r); +} + +sub rename_confirmed { + my ($r)=@_; + &Apache::lonnet::renameuserfile($ENV{'form.currentpath'}.$ENV{'form.selectfile'}, 'rename', $ENV{'form.currentpath'}.$ENV{'form.filenewname'} ); +} + +sub upload { + my ($r)=@_; + #FIXME if the file already exists we need to do a confirmation pass + #before overwriting + my $result=&Apache::lonnet::userfileupload('uploaddoc','', + 'portfolio'.$ENV{'form.currentpath'}); + if ($result !~ m|^/uploaded/|) { + $r->print(' An errror occured ('.$result. + ') while trying to upload '.&display_file().''); - - if ($ENV{'form.uploaddoc.filename'}){ - $r->print (&Apache::lonnet::userfileupload('uploaddoc',undef,'portfolio').'- '); - - return OK; + my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'}, + $ENV{'user.name'}). + '/userfiles/portfolio'; + @dir_list=&Apache::lonnet::dirlist($current_path,$ENV{'user.domain'}, + $ENV{'user.name'},$portfolio_root); + + # 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); + + } + + $r->print("\n
'); + # this handles file management + my $r = shift; + my @dir_list; # will hold directory listing as array + my $udir; # returned from home server + my $currentFile; # directory or file contained in $pathToRoot.$current_path + my $action; # delete, rename, makedirectory, removedirectory, + my $filenewname; # for rename action (guess what we do with it!) + my $isFile; + &Apache::loncommon::no_cache($r); + &Apache::loncommon::content_type($r,'text/html'); + $r->send_http_header; + # Give the LON-CAPA page header + $r->print(''. + &mt('Portfolio Manager'). + " \n". + &Apache::loncommon::bodytag('Portfolio Manager')); + $r->rflush(); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, + ['selectfile','currentpath', + 'currentfile']); + + # if we're uploading a file, we need to do it early so it will + # show in the directory list + + if ($ENV{'form.uploaddoc.filename'}) { + &upload($r); + } elsif ($ENV{'form.action'} eq 'delete') { + if ($ENV{'form.confirmed'}) { + &delete_confirmed($r); + } else { + &delete($r); + } + } elsif ($ENV{'form.action'} eq 'rename') { + # similarly, we need to delete or rename files before getting + # directory list + &rename($r); + } elsif ($ENV{'form.createdir'}) { + &createdir($r); + } else { + my $current_path='/'; + if ($ENV{'form.currentpath'}) { + $current_path = $ENV{'form.currentpath'}; } - $r->print ('
Current contents of your portfolio directory:
'); - $r->print (&Apache::lonnet::portfoliolist($r->uri, $ENV{'user.domain'}, $ENV{'user.name'}, undef )); - $r->print ('
'); -# $r->print ($ENV{'form.uploaddoc.filename'}.'
'); -# $r->print ($ENV{'form.storeupl'}.'
'); -# $r->print ($ENV{'form.saywhat'}.'
'); - - $r->print("Upload files to your portfolio
"); - # file upload form - $r->print(' -