version 1.10, 2004/07/01 18:59:33
|
version 1.16, 2004/07/23 01:25:56
|
Line 18
|
Line 18
|
# |
# |
# /home/httpd/html/adm/gpl.txt |
# /home/httpd/html/adm/gpl.txt |
# |
# |
|
|
|
|
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
|
|
|
|
package Apache::portfolio; |
package Apache::portfolio; |
use strict; |
use strict; |
use Apache::Constants qw(:common :http); |
use Apache::Constants qw(:common :http); |
Line 32 use Apache::lonnet;
|
Line 29 use Apache::lonnet;
|
use Apache::lontexconvert; |
use Apache::lontexconvert; |
use Apache::lonfeedback; |
use Apache::lonfeedback; |
use Apache::lonlocal; |
use Apache::lonlocal; |
|
|
|
# receives a file name and path stub from username/userfiles/portfolio/ |
|
# returns an anchor tag consisting encoding filename and currentpath |
sub makeAnchor{ |
sub makeAnchor{ |
# receives a file name and path stub from username/userfiles/portfolio/ |
|
# returns an anchor tag consisting encoding filename and currentpath |
|
my ($fileName, $currentPath) = @_; |
my ($fileName, $currentPath) = @_; |
my $anchor = '<a href="/adm/portfolio?selectfile='.$fileName.'¤tpath='.$currentPath.'">'.$fileName.'</a>'; |
my $anchor = '<a href="/adm/portfolio?selectfile='.$fileName.'¤tpath='.$currentPath.'">'.$fileName.'</a>'; |
return $anchor; |
return $anchor; |
} |
} |
|
|
|
# returns html with <br /> separated contents of the directory |
|
# returns a <strong>currentFile</strong> (bolds the selected file/dir) |
sub displayDirectory { |
sub displayDirectory { |
# returns html with <br /> separated contents of the directory |
my ($currentPath, $currentFile, @dirList,) = @_; |
# returns a <strong>currentFile</strong> (bolds the selected file/dir) |
|
my ($currentPath, $currentFile, $isDir, @dirList,) = @_; |
|
my $displayOut=''; |
my $displayOut=''; |
my $fileName; |
my $fileName; |
my $upPath; |
my $upPath; |
Line 64 sub displayDirectory {
|
Line 63 sub displayDirectory {
|
foreach my $line (@dirList) { |
foreach my $line (@dirList) { |
#$strip holds directory/file name |
#$strip holds directory/file name |
#$dom |
#$dom |
my ($fileName,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); |
my ($fileName,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef,$path)=split(/\&/,$line,17); |
|
$path =~ m:/:; |
|
my $dirDepth = @-; |
if (($fileName ne '.') && ($fileName ne '..')){ |
if (($fileName ne '.') && ($fileName ne '..')){ |
|
for (my $i = 0; $i <= $dirDepth; $i += 1){ |
|
$displayOut.='<blockquote>'; |
|
} |
if ($testdir =~ m:^1:){ |
if ($testdir =~ m:^1:){ |
# handle directories different from files |
# handle directories different from files |
if ($fileName eq $currentFile){ #checks to bold the selected file |
if ($fileName eq $currentFile){ #checks to bold the selected file |
$displayOut.= '<strong>'.(makeAnchor($fileName.'/', $currentPath.$fileName.'/').'</strong><br />'); |
$displayOut.= '<strong>'.(makeAnchor($fileName.'/', $path.$fileName.'/').'</strong><br />'."\n"); |
}else{ |
}else{ |
$displayOut.= (makeAnchor($fileName.'/', $currentPath.$fileName.'/').'<br />'); |
$displayOut.= (makeAnchor($fileName.'/', $path.$fileName.'/').'<br />'."\n"); |
} |
} |
}else{ |
}else{ |
if ($fileName eq $currentFile){ #checks to bold the selected file |
if ($fileName eq $currentFile){ #checks to bold the selected file |
$displayOut.='<strong>'.(makeAnchor($fileName, $currentPath).'</strong><br />'); |
$displayOut.='<strong>'.(makeAnchor($fileName, $currentPath).'</strong><br />'."\n"); |
}else{ |
}else{ |
$displayOut.=(makeAnchor($fileName, $currentPath).'<br />'); |
$displayOut.=(makeAnchor($fileName, $currentPath).'<br />'."\n"); |
} |
} |
} |
} |
|
for (my $i = 0; $i <= $dirDepth; $i += 1){ |
|
$displayOut.='</blockquote>'; |
|
} |
|
|
} |
} |
|
|
} |
} |
Line 88 sub displayDirectory {
|
Line 96 sub displayDirectory {
|
sub displayActions { |
sub displayActions { |
# returns html to offer user appropriate actions depending on selected file/directory |
# returns html to offer user appropriate actions depending on selected file/directory |
my $displayOut; |
my $displayOut; |
my ($currentPath, $currentFile, $isDir, $isEmpty) = @_; |
my ($currentPath, $currentFile, $isEmpty) = @_; |
# $displayOut = 'here are actions for '.$currentFile; |
# $displayOut = 'here are actions for '.$currentFile; |
if ($currentFile =~ m:/$:){ |
if ($currentFile =~ m:/$:){ |
# if the selected file is a directory, these are the options |
# if the selected file is a directory, these are the options |
Line 165 sub handler {
|
Line 173 sub handler {
|
my $action; # delete, rename, makedirectory, removedirectory, |
my $action; # delete, rename, makedirectory, removedirectory, |
my $filenewname; # for rename action (guess what we do with it!) |
my $filenewname; # for rename action (guess what we do with it!) |
my $isFile; |
my $isFile; |
my $isDir; |
|
my $isEmpty; |
my $isEmpty; |
# send header |
|
# FIXME need to start using |
|
&Apache::loncommon::no_cache($r); |
&Apache::loncommon::no_cache($r); |
&Apache::loncommon::content_type($r, 'text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::loncommon::bodytag('Portfolio Managment', 'bgcolor="dogfood"'); |
|
# |
|
# $r->content_type('text/html'); |
|
$r->send_http_header; |
$r->send_http_header; |
# $r->print('<html><head><title>'. |
# Give the LON-CAPA page header |
# 'Portfolio Management'. |
$r->print('<html><head><title>'. |
# "</title></head>\n"); |
&mt('Portfolio Manager'). |
# |
"</title></head>\n". |
# FIXME need to start using |
&Apache::loncommon::bodytag('Portfolio Manager')); |
# $r->print(' |
$r->rflush(); |
# <body bgcolor="dogfood"> |
|
# <blockquote>'); |
|
|
|
# $r->content_type('text/html'); |
|
# $r->send_http_header; |
|
# $r->print('<html><head><title>'. |
|
# 'Portfolio Management'. |
|
# "</title></head>\n"); |
|
# |
|
# $r->print (' |
|
# <body bgcolor="dogfood"> |
|
# <blockquote>'); |
|
#grab stuff that was sent |
|
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
['selectfile','currentpath', 'currentfile']); |
['selectfile','currentpath', 'currentfile']); |
# $r->print ('<br />CP= '.$ENV{'form.currentpath'}.'<br />'); |
|
# currentPath and currentFile need to be set for the rest of things to happen |
# currentPath and currentFile need to be set for the rest of things to happen |
# sometimes, currentFile will be passed by a form field, selectedfile |
# sometimes, currentFile will be passed by a form field, selectedfile |
# if there is no 'form.selectedfile' then the current directory is |
# if there is no 'form.selectedfile' then the current directory is |
# considered as selected |
# considered as selected |
if ($ENV{'form.currentpath'}){ |
if ($ENV{'form.currentpath'}) { |
$currentPath = $ENV{'form.currentpath'}; |
$currentPath = $ENV{'form.currentpath'}; |
}else{ |
} else { |
$currentPath = '/'; |
$currentPath = '/'; |
} |
} |
if ($ENV{'form.selectfile'}){ |
if ($ENV{'form.selectfile'}) { |
$r->print('<br />found selectfile'.$ENV{'form.selectfile'} .'<br />'); |
|
# have to check if the selected file is a subdirectory |
# have to check if the selected file is a subdirectory |
if ($ENV{'form.selectfile'} =~ /-\(Dir\)/){ |
if ($ENV{'form.selectfile'} =~ /-\(Dir\)/){ |
# $currentPath =~ /\-\(Dir\)/; |
# $currentPath =~ /\-\(Dir\)/; |
Line 215 sub handler {
|
Line 202 sub handler {
|
$r->print('<br />'.$currentPath.'<br />'); |
$r->print('<br />'.$currentPath.'<br />'); |
} |
} |
$currentFile = $ENV{'form.selectfile'}; |
$currentFile = $ENV{'form.selectfile'}; |
}else{ |
} else { |
$currentFile = ''; |
$currentFile = ''; |
} |
} |
# if we're uploading a file, we need to do it early so it will show in the directory list |
# 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'}){ |
if ($ENV{'form.uploaddoc.filename'}) { |
$r->print ($ENV{'form.storeupl'}.'<br />'); |
$r->print($ENV{'form.storeupl'}.'<br />'); |
$r->print (&Apache::lonnet::userfileupload('uploaddoc','','portfolio'.$currentPath).'<br />'); |
$r->print(&Apache::lonnet::userfileupload('uploaddoc','','portfolio'.$currentPath).'<br />'); |
} |
} |
# similarly, we need to delete or rename files before getting directory list |
# similarly, we need to delete or rename files before getting directory list |
if ($ENV{'form.selectfile'}){ |
if ($ENV{'form.selectfile'}){ |
if ($ENV{'form.fileaction'} eq 'delete'){ |
if ($ENV{'form.fileaction'} eq 'delete') { |
$r->print('<br />trying to delete '.$currentPath.$ENV{'form.selectfile'}.'<br />'); |
$r->print('<br />trying to delete '.$currentPath.$ENV{'form.selectfile'}.'<br />'); |
$r->print(&Apache::lonnet::removeuserfile($ENV{'user.name'}, $ENV{'user.domain'},'portfolio'.$currentPath.$ENV{'form.selectfile'})); |
$r->print(&Apache::lonnet::removeuserfile($ENV{'user.name'}, $ENV{'user.domain'},'portfolio'.$currentPath.$ENV{'form.selectfile'})); |
$currentFile = ''; |
$currentFile = ''; |
}elsif($ENV{'form.fileaction'} eq 'rename') { |
} elsif ($ENV{'form.fileaction'} eq 'rename') { |
&Apache::lonnet::portfoliomanage($currentPath.$ENV{'form.selectfile'}, 'rename', $currentPath.$ENV{'form.filenewname'} ); |
&Apache::lonnet::portfoliomanage($currentPath.$ENV{'form.selectfile'}, 'rename', $currentPath.$ENV{'form.filenewname'} ); |
# $r->print ('We will rename your file'); |
|
} |
} |
} |
} |
# we always need $dirList, plus this will return information about the current file |
# we always need $dirList, plus this will return information about the current file |
# as well as information about he home server directory structure, specifically |
# as well as information about he home server directory structure, specifically |
# the path to the users userfiles directory. |
# the path to the users userfiles directory. |
# $r->print('dir list follows<br />'.&Apache::lonnet::portfoliolist($currentPath, $currentFile).'<br />'); |
# |
my $list = &Apache::lonnet::portfoliolist($currentPath, $currentFile); |
my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'}, |
@dirList = split(/:/,$list); |
$ENV{'user.name'}). |
# foreach my $line (@dirlist) { |
'/userfiles/portfolio'; |
# |
my $done = 0; |
# #$strip holds directory/file name |
my $subdir = ''; |
# #$dom |
my @workinglist; # intermediate array, holds directory listing lines (dirlist), and path information |
# my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); |
my $readDirectory = 1; # flag for directory |
# $r->print ($strip.' '.$testdir.'<br />'); |
my $loopCounter = 0; # needed only for development to prevent run away program (or maybe more?) |
# } |
while (!$done){ |
# @dirList = split /<br\s\/>/, (&Apache::lonnet::portfoliolist($currentPath, $currentFile)); |
# Needed while developing. Later, too? |
|
$loopCounter += 1; |
# portfoliolist returns isdir, isfile and udir as the final array elements |
if ($loopCounter > 50) { |
# we'll pop them off the bottom of the array, and put them where they belong |
$r->print('<br />stop runaway'); |
|
return OK; |
|
} |
|
# --- |
|
if ($readDirectory){ # is true the first time through, then true if dirlist line is a subdir |
|
# $r->print('<br />reading '.$portfolio_root.$subdir); |
|
my @list = &Apache::lonnet::dirlist($currentPath, $ENV{'user.domain'}, $ENV{'user.name'}, $portfolio_root.$subdir); |
|
foreach my $line(@list){ |
|
$line = $line.'&'.$subdir; # append the subdirectory information |
|
my ($fileName,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef,$subpath)=split(/\&/,$line,17); |
|
if (($fileName ne '.') && ($fileName ne '..')){ # we throw away the current and parent directories |
|
$r->print('<br />'.$line); |
|
# should this be shift? |
|
push @workinglist, $line; # add the line to the working list array |
|
} |
|
} |
|
} |
|
my $line = shift @workinglist; #take one off the working list |
|
if ($line eq '') { # if the working list is empty |
|
$done = 1; |
|
}else{ |
|
push @dirList, $line; # and put it in the display list |
|
my ($fileName,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef,$subpath)=split(/\&/,$line,17); |
|
if ($testdir =~ m:^1:) { # true if this is a directory |
|
# $r->print('<br />added subdir '.$fileName); |
|
$subdir = $subpath.'/'.$fileName; |
|
$readDirectory = 1; |
|
}else{ |
|
$readDirectory = 0; |
|
} |
|
} |
|
} |
|
# if item is directory { get the next level down |
|
# my @list = &Apache::lonnet::dirlist($currentPath, $ENV{'user.domain'}, $ENV{'user.name'}, $portfolio_root.$); |
|
|
# $londcall added to help debug, contains the command sent to lond |
if (@dirList == 2) { # need to know if directory is empty so it can be removed if desired |
# my $londcall = pop @dirList; |
|
# $r->print ('<br />udir '.$londcall.'<br />'); |
|
# $udir = pop @dirList; |
|
# $r->print ('<br />path returned '.$udir.'<br />'); |
|
# $isFile = pop @dirList; |
|
# $r->print ('<br />isfile '.$isFile.'<br />'); |
|
# $isDir = pop @dirList; |
|
if (@dirList == 2){ # need to know if directory is empty to it can be removed if desired |
|
$isEmpty = 1; |
$isEmpty = 1; |
}else{ |
} else { |
$isEmpty = 0; |
$isEmpty = 0; |
} |
} |
# $r->print ('<br />lines left ind dirlist '.@dirList.'<br />'); |
|
# return OK if $r->header_only; |
if ($ENV{'form.selectfile'}) { |
# Stuff to maintain proper setting for selected file |
if ($ENV{'form.fileaction'} eq 'delete') { |
if ($ENV{'form.selectfile'}){ |
|
if ($ENV{'form.fileaction'} eq 'delete'){ |
|
&Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef ); |
&Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef ); |
$ENV{'portfolio.file'} = 'Selected File Deleted'; |
$ENV{'portfolio.file'} = 'Selected File Deleted'; |
}elsif($ENV{'form.fileaction'} eq 'rename') { |
} elsif ($ENV{'form.fileaction'} eq 'rename') { |
&Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'} ); |
&Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'}); |
# $r->print ('We will rename your file'); |
} else { |
}else{ |
|
|
|
# Remember user's file selection for later |
# Remember user's file selection for later |
$ENV{'portfolio.file'} = $ENV{'form.selectfile'}; |
$ENV{'portfolio.file'} = $ENV{'form.selectfile'}; |
# offer things user can do with selected file |
# offer things user can do with selected file |
Line 291 sub handler {
|
Line 298 sub handler {
|
# Display begins here |
# Display begins here |
# |
# |
############################## |
############################## |
$r->print ('<hr /> start '); |
$r->print('<table border=1><tr><td>'); |
$r->print ($udir); |
$r->print(displayDirectory($currentPath, $currentFile, @dirList)); |
$r->print ('<table border=1><tr><td>'); |
$r->print('</td>><td>'); |
$r->print (displayDirectory ($currentPath, $currentFile, $isDir, @dirList)); |
$r->print(displayActions($currentPath, $currentFile, $isEmpty)); |
$r->print ('</td>><td>'); |
$r->print('</td>></tr></table>'); |
$r->print (displayActions ($currentPath, $currentFile, $isDir, $isEmpty)); |
$r->print('</blockquote>'); |
$r->print ('</td>></tr></table>'); |
$r->print("</body>\n</html>\n"); |
$r->print ('<br />end display<br /><hr />'); |
$r->rflush(); |
$r->print ('</blockquote></body>'); |
|
return OK; |
return OK; |
} |
} |
|
|