version 1.9, 2004/06/28 16:12:06
|
version 1.93, 2006/01/25 22:56:11
|
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; |
|
use Apache::lonnet; |
|
|
# receives a file name assumed to reside in username/userfiles/portfolio/ |
# receives a file name and path stub from username/userfiles/portfolio/ |
# returns a form consisting of a single submit button labeled with the filename |
# returns an anchor tag consisting encoding filename and currentpath |
sub makeAnchor { |
sub make_anchor { |
my ($fileName, $currentPath) = @_; |
my ($filename, $current_path, $current_mode, $field_name, $continue_select) = @_; |
my $anchor = '<a href="/adm/portfolio?selectfile='.$fileName.'¤tpath='.$currentPath.'">'.$fileName.'</a>'; |
if ($continue_select ne 'true') {$continue_select = 'false'}; |
# my $button = ' |
my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'¤tpath='.$current_path.'&mode='.$current_mode.'&continue='.$continue_select.'&fieldname='.$field_name.'">'.$filename.'</a>'; |
# <form method="POST" action="/adm/portfolio"> |
|
# <input type="hidden" name="selectfile" value="'.$fileName.'" /> |
|
# <input type="submit" value="'.$fileName.'" name="storeupl" /> |
|
# </form> |
|
# '; |
|
return $anchor; |
return $anchor; |
} |
} |
|
my $dirptr=16384; |
|
sub display_common { |
|
my ($r,$current_path,$is_empty,$dir_list)=@_; |
|
my $iconpath= $r->dir_config('lonIconsURL') . "/"; |
|
my %text=&Apache::lonlocal::texthash('upload' => 'Upload', |
|
'upload_label' => |
|
'Upload file to current directory:', |
|
'createdir' => 'Create Subdirectory', |
|
'createdir_label' => |
|
'Create subdirectory in current directory:'); |
|
$r->print(<<"TABLE"); |
|
<table border="0" cellspacing="2" cellpadding="2"> |
|
<form method="post" enctype="multipart/form-data"> |
|
<tr valign="middle"> |
|
<td bgcolor="#ccddaa" align="right"> |
|
$text{'upload_label'} |
|
</td> |
|
<td bgcolor="#ccddaa" align="left"> |
|
<input name="uploaddoc" type="file" /> |
|
<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"}" /> |
|
<input type="hidden" name="mode" value="$env{"form.mode"}" /> |
|
<input type="submit" name="storeupl" value="$text{'upload'}" /> |
|
</td> |
|
</tr> |
|
</form> |
|
<form method="post"> |
|
<tr> |
|
<td bgcolor="#ccddaa" align="right"> |
|
$text{'createdir_label'} |
|
</td> |
|
<td bgcolor="#ccddaa" align="left"> |
|
<input name="newdir" type="input" /> |
|
<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"}" /> |
|
<input type="hidden" name="mode" value="$env{"form.mode"}" /> |
|
<input type="submit" name="createdir" value="$text{'createdir'}" /> |
|
</td> |
|
</tr> |
|
</form> |
|
</table> |
|
TABLE |
|
my @tree = split (/\//,$current_path); |
|
$r->print('<font size="+2">'.&make_anchor('portfolio','/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"}).'/'); |
|
if (@tree > 1){ |
|
my $newCurrentPath = ''; |
|
for (my $i = 1; $i< @tree; $i++){ |
|
$newCurrentPath .= $tree[$i].'/'; |
|
$r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"}).'/'); |
|
} |
|
} |
|
$r->print('</font>'); |
|
&Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path); |
|
$r->print('<br /><form method=post action="/adm/portfolio?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.'">'. |
|
&Apache::lonhtmlcommon::select_recent('portfolio','currentpath', |
|
'this.form.submit();')); |
|
$r->print("</form>"); |
|
} |
|
sub display_directory { |
|
my ($r,$current_path,$is_empty,$dir_list)=@_; |
|
my $iconpath= $r->dir_config('lonIconsURL') . "/"; |
|
my $display_out; |
|
my $select_mode; |
|
my $checked_files; |
|
my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($env{'user.domain'},$env{'user.name'}); |
|
if ($env{"form.mode"} eq 'selectfile'){ |
|
&select_files($r); |
|
$checked_files =&Apache::lonnet::files_in_path($env{'user.name'},$env{'form.currentpath'}); |
|
$select_mode = 'true'; |
|
} |
|
if ($is_empty && ($current_path ne '/')) { |
|
$display_out = '<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($display_out); |
|
return; |
|
} |
|
if ($select_mode eq 'true') { |
|
$r->print('<table border="0" cellspacing="2" cellpadding="2">'. |
|
'<tr><th>Select</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>'); |
|
$r->print('<form method="post" name="checkselect" action="/adm/portfolio">'); |
|
} else { |
|
$r->print('<table border="0" cellspacing="2" cellpadding="2">'. |
|
'<tr><th colspan="2">Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>'); |
|
$r->print('<form method="post" action="/adm/portfolio">'); |
|
} |
|
my $href_location="/uploaded/$env{'user.domain'}/$env{'user.name'}/portfolio$current_path"; |
|
my $href_edit_location="/editupload/$env{'user.domain'}/$env{'user.name'}/portfolio$current_path"; |
|
foreach my $line (sort |
|
{ |
|
my ($afile)=split('&',$a,2); |
|
my ($bfile)=split('&',$b,2); |
|
return (lc($afile) cmp lc($bfile)); |
|
} (@$dir_list)) { |
|
#$strip holds directory/file name |
|
#$dom |
|
my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); |
|
$filename =~ s/\s+$//; |
|
if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) { |
|
if ($dirptr&$testdir) { |
|
if ($select_mode eq 'true'){ |
|
$r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>'); |
|
} else { |
|
$r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>'); |
|
} |
|
$r->print('<td>Go to ...</td>'); |
|
$r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'}).'</td>'); |
|
$r->print('</tr>'); |
|
} else { |
|
$r->print('<tr bgcolor="#CCCCFF">'); |
|
if ($select_mode eq 'true'){ |
|
$r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"'); |
|
if ($$checked_files{$filename} eq 'selected') { |
|
$r->print("CHECKED"); |
|
} |
|
$r->print('></td>'); |
|
} else { |
|
if (exists $locked_files{$current_path.$filename}){ |
|
$r->print('<td colspan="2"><a href="portfolio?lockinfo='.$current_path.$filename.'">Locked</a></td>'); |
|
} else { |
|
my $cat='<img alt="'.&mt('Catalog Information'). |
|
'" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />'; |
|
$r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" /> |
|
<a href="/adm/portfolio?rename='.$filename.'&currentpath='.$current_path.'">Rename</a></td> |
|
<td><a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a> |
|
</td>'); |
|
} |
|
} |
|
$r->print('<td><img src="'.&Apache::loncommon::icon($filename).'"></td>'); |
|
$r->print('<td><a href="'.$href_location.$filename.'">'. |
|
$filename.'</a></td>'); |
|
$r->print('<td>'.$size.'</td>'); |
|
$r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>'); |
|
$r->print('</tr>'); |
|
} |
|
} |
|
} |
|
if ($select_mode eq 'true') { |
|
$r->print('</table> |
|
<input type="hidden" name="continue" value="true"> |
|
<input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'"> |
|
<input type="hidden" name="mode" value="selectfile"> |
|
<input type="submit" name="submit" value="Select checked files, and continue selecting." /><br /> |
|
<input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" /> |
|
<input type="hidden" name="currentpath" value="'.$current_path.'" /> |
|
</form>'); |
|
} else { |
|
$r->print('</table> |
|
<input type="submit" name="doit" value="Delete Checked Files" /> |
|
<input type="hidden" name="action" value="delete" /> |
|
<input type="hidden" name="currentpath" value="'.$current_path.'" /> |
|
</form>'); |
|
} |
|
} |
|
|
# returns html with <br /> separated contents of the directory |
sub open_form { |
# returns a <strong>currentFile</strong> (bolds the selected file/dir) |
my ($r)=@_; |
sub displayDirectory { |
my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); |
my ($currentPath, $currentFile, $isDir, @dirList,) = @_; |
$r->print('<form method="post" action="/adm/portfolio">'); |
my $displayOut=''; |
$r->print('<input type="hidden" name="action" value="'. |
my $fileName; |
$env{'form.action'}.'" />'); |
my $upPath; |
$r->print('<input type="hidden" name="confirmed" value="1" />'); |
if ($currentPath ne '/') { |
foreach (@files) { |
$displayOut = 'Listing of '.$currentPath.'<br /><hr />'. |
$r->print('<input type="hidden" name="selectfile" value="'. |
# provides the "up one directory level" function |
$_.'" />'); |
# it means shortening the currentpath to the parent directory |
} |
$currentPath =~ m:(^/.*)(/.*/$ ):; |
$r->print('<input type="hidden" name="currentpath" value="'. |
if ($1 ne '/') { |
$env{'form.currentpath'}.'" />'); |
$upPath = $1.'/'; |
} |
} else { |
|
$upPath = $1; |
sub close_form { |
} |
my ($r)=@_; |
|
$r->print('<p><input type="submit" value="'.&mt('Continue'). |
$displayOut = $displayOut.'<a href="/adm/portfolio?selectfile=updir¤tpath='.$upPath.'">..</a><br />'; |
'" /></p></form>'); |
|
$r->print('<form action="/adm/portfolio" method="POST"> |
|
<p> |
|
<input type="hidden" name="currentpath" value="'. |
|
$env{'form.currentpath'}.'" /> |
|
<input type="submit" value="'.&mt('Cancel').'" /> |
|
</p></form>'); |
|
|
|
} |
|
|
|
sub display_file { |
|
my ($path,$filename)=@_; |
|
my $display_file_text; |
|
if (!defined($path)) { $path=$env{'form.currentpath'}; } |
|
if (!defined($filename)) { |
|
$filename=$env{'form.selectfile'}; |
|
$display_file_text = '<tt>'.$path.$filename.'</tt>'; |
|
} elsif (ref($filename) eq "ARRAY") { |
|
foreach (@$filename) { |
|
$display_file_text .= '<tt>'.$path.$_.'</tt><br />'; |
|
} |
|
} elsif (ref($filename) eq "SCALAR") { |
|
$display_file_text = '<tt>'.$path.$filename.'</tt>'; |
|
} |
|
return $display_file_text; |
|
} |
|
|
|
sub done { |
|
my ($message)=@_; |
|
unless (defined $message) { |
|
$message='Done'; |
|
} |
|
return ('<h3><a href="/adm/portfolio?currentpath='. |
|
$env{'form.currentpath'}. |
|
'&fieldname='.$env{'form.fieldname'}. |
|
'&mode='.$env{'form.mode'}. |
|
'">'.&mt($message).'</a></h3>'); |
|
} |
|
|
|
sub delete { |
|
my ($r)=@_; |
|
my @check; |
|
my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'}; |
|
my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); |
|
|
|
if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') { |
|
$r->print ("The file is locked and cannot be deleted.<br />"); |
|
$r->print(&done('Back')); |
} else { |
} else { |
$displayOut = $displayOut.'at root '.$currentPath.'<br />'; |
if (scalar(@files)) { |
|
&open_form($r); |
|
$r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>'); |
|
&close_form($r); |
|
} else { |
|
$r->print("No file was checked to delete.<br />"); |
|
$r->print(&done()); |
|
} |
} |
} |
while ($fileName = shift @dirList) { |
} |
if (($fileName ne './') && ($fileName ne '../')) { |
|
if ($fileName =~ m:/$:) { |
sub delete_confirmed { |
# handle directories different from files |
my ($r)=@_; |
if ($fileName eq $currentFile) { |
my @files=&Apache::loncommon::get_env_multiple('form.selectfile'); |
#checks to bold the selected file |
my $result; |
$displayOut = $displayOut.'<strong>'.(&makeAnchor($fileName, $currentPath.$fileName).'</strong><br />'); |
foreach my $delete_file (@files) { |
} else { |
$result=&Apache::lonnet::removeuserfile($env{'user.name'}, |
$displayOut = $displayOut.(&makeAnchor($fileName, $currentPath.$fileName).'<br />'); |
$env{'user.domain'},'portfolio'. |
} |
$env{'form.currentpath'}. |
} else { |
$delete_file); |
if ($fileName eq $currentFile) { |
if ($result ne 'ok') { |
#checks to bold the selected file |
$r->print('<font color="red"> An error occured ('.$result. |
$displayOut = $displayOut.'<strong>'.(&makeAnchor($fileName, $currentPath).'</strong><br />'); |
') while trying to delete '.&display_file(undef, $delete_file).'</font><br />'); |
} else { |
} |
$displayOut = $displayOut.(&makeAnchor($fileName, $currentPath).'<br />'); |
|
} |
|
} |
|
} |
|
} |
} |
#$displayOut = $displayOut. |
$r->print(&done()); |
return $displayOut; |
|
} |
} |
|
|
# returns html to offer user appropriate actions depending on selected |
sub delete_dir { |
# file/directory |
my ($r)=@_; |
sub displayActions { |
&open_form($r); |
my $displayOut; |
$r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>'); |
my ($currentPath, $currentFile, $isDir, $isFile) = @_; |
&close_form($r); |
# $displayOut = 'here are actions for '.$currentFile; |
} |
if ($isDir){ |
|
$displayOut = 'Directory'; |
sub delete_dir_confirmed { |
} |
my ($r)=@_; |
if ($isFile){ |
my $directory_name = $env{'form.currentpath'}; |
$displayOut = 'File'; |
$directory_name =~ s|/$||; # remove any trailing slash |
} |
my $result=&Apache::lonnet::removeuserfile($env{'user.name'}, |
|
$env{'user.domain'},'portfolio'. |
$displayOut = $displayOut.'<form method="POST"> |
$directory_name); |
<input type="hidden" name="selectfile" |
|
value="'.$currentFile.'" /> |
if ($result ne 'ok') { |
<input type="hidden" name="fileaction" value="delete" /> |
$r->print('<font color="red"> An error occured (dir) ('.$result. |
<center> |
') while trying to delete '.$directory_name.'</font><br />'); |
<input type="submit" |
} else { |
|
# now remove from recent |
value="Delete '.$currentFile.'" /> |
# $r->print('<br /> removing '.$directory_name.'<br /'); |
</center> |
&Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']); |
</form> |
my @dirs = split m!/!, $directory_name; |
<hr /> |
|
<form method="POST"> |
# $directory_name =~ m/^(\/*\/)(\/*.)$/; |
<input type="hidden" name="selectfile" |
$directory_name='/'; |
value="'.$currentFile.'" /> |
for (my $i=1; $i < (@dirs - 1); $i ++){ |
<input type="hidden" name="fileaction" value="rename" /> |
$directory_name .= $dirs[$i].'/'; |
<input type="input" name="filenewname" value="Type new name here" /> |
} |
<input type="submit" |
$env{'form.currentpath'} = $directory_name; |
value="Rename '.$currentFile.'" /> |
} |
</form> |
$r->print(&done()); |
<hr />'; |
} |
$displayOut = $displayOut.'<hr />Add a file to your portfolio'; |
|
# file upload form |
sub rename { |
$displayOut = $displayOut.'<form method="post" enctype="multipart/form-data">'; |
my ($r)=@_; |
$displayOut = $displayOut.'<input name="uploaddoc" type="file" />'. |
my $file_name = $env{'form.currentpath'}.$env{'form.rename'}; |
'<input type="hidden" name="currentpath" value="'.$currentPath.'" />'. |
if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'}) eq 'true') { |
'<input type="submit" name="storeupl" value="Upload" />'. |
$r->print ("The file is locked and cannot be renamed.<br />"); |
'</form><hr>'; |
$r->print(&done()); |
$displayOut = $displayOut.'<form method="POST"> |
} else { |
<input name="subdir" type="text" /> |
&open_form($r); |
<input type="submit" value="Create Subdirectory" /> |
$r->print('<p>'.&mt('Rename').' '.&display_file().' to |
</form> |
<input name="filenewname" type="input" size="50" />?</p>'); |
'; |
&close_form($r); |
return $displayOut; |
} |
|
} |
|
|
|
sub rename_confirmed { |
|
my ($r)=@_; |
|
my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'}); |
|
if ($filenewname eq '') { |
|
$r->print('<font color="red">'. |
|
&mt("Error: no valid filename was provided to rename to."). |
|
'</font><br />'); |
|
$r->print(&done()); |
|
return; |
|
} |
|
my $result= |
|
&Apache::lonnet::renameuserfile($env{'user.name'},$env{'user.domain'}, |
|
'portfolio'.$env{'form.currentpath'}.$env{'form.selectfile'}, |
|
'portfolio'.$env{'form.currentpath'}.$filenewname); |
|
if ($result ne 'ok') { |
|
$r->print('<font color="red"> An errror occured ('.$result. |
|
') while trying to rename '.&display_file().' to '. |
|
&display_file(undef,$filenewname).'</font><br />'); |
|
} |
|
if ($filenewname ne $env{'form.filenewname'}) { |
|
$r->print("The new file name was changed from:<br /><strong>".$env{'form.filenewname'}."</strong> to <strong>$filenewname </strong>"); |
|
} |
|
$r->print(&done()); |
|
} |
|
sub select_files { |
|
my ($r)=@_; |
|
if ($env{'form.continue'} eq 'true') { |
|
# here we update the selections for the currentpath |
|
# eventually, have to handle removing those not checked, but . . . |
|
my @items=&Apache::loncommon::get_env_multiple('form.checkfile'); |
|
if (scalar(@items)){ |
|
&Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items); |
|
} |
|
} else { |
|
#empty the file for a fresh start |
|
&Apache::lonnet::clear_selected_files($env{'user.name'}); |
|
} |
|
my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'}); |
|
my $java_files = join ",", @files; |
|
if ($java_files) { |
|
$java_files.=','; |
|
} |
|
my $javascript =(<<ENDSMP); |
|
<script language='javascript'> |
|
function finishSelect() { |
|
ENDSMP |
|
$javascript .= 'fileList = "'.$java_files.'";'; |
|
$javascript .= (<<ENDSMP); |
|
for (i=0;i<document.forms.checkselect.length;i++) { |
|
if (document.forms.checkselect[i].checked){ |
|
fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ; |
|
} |
|
} |
|
opener.document.forms.lonhomework. |
|
ENDSMP |
|
$javascript .= $env{'form.fieldname'}; |
|
$javascript .= (<<ENDSMP); |
|
.value=fileList; |
|
self.close(); |
|
} |
|
</script> |
|
ENDSMP |
|
$r->print($javascript); |
|
$r->print("<h1>Select portfolio files</h1> |
|
Check as many as you wish in response to the problem.<br />"); |
|
my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'}); |
|
if (@otherfiles) { |
|
$r->print("<strong>Files selected from other directories:</strong><br />"); |
|
foreach my $file (@otherfiles) { |
|
$r->print($file."<br />"); |
|
} |
|
} |
|
} |
|
sub upload { |
|
my ($r)=@_; |
|
my $fname=$env{'form.uploaddoc.filename'}; |
|
my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?) |
|
my $disk_quota = 20000; # expressed in k |
|
$fname=&Apache::lonnet::clean_filename($fname); |
|
my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'}, |
|
$env{'user.name'}). |
|
'/userfiles/portfolio'; |
|
# Fixme --- Move the checking for existing file to LOND error return |
|
my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'}, |
|
$env{'user.domain'}, |
|
$env{'user.name'},$portfolio_root); |
|
my $found_file = 0; |
|
my $locked_file = 0; |
|
foreach my $line (@dir_list) { |
|
my ($file_name)=split(/\&/,$line,2); |
|
if ($file_name eq $fname){ |
|
$found_file = 1; |
|
if (&Apache::lonnet::is_locked($env{'form.currentpath'}.$file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') { |
|
$locked_file = 1; |
|
} |
|
} |
|
} |
|
my $current_disk_usage = &Apache::lonnet::diskusage($env{'user.domain'}, $env{'user.name'},$portfolio_root); |
|
if (($current_disk_usage + $filesize) > $disk_quota){ |
|
$r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.'. |
|
'<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.'); |
|
$r->print(&done('Back')); |
|
} |
|
elsif ($found_file){ |
|
if ($locked_file){ |
|
$r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>portfolio'.$env{'form.currentpath'}.'</strong></font>'. |
|
'<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.'); |
|
$r->print(&done('Back')); |
|
} else { |
|
$r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>portfolio'.$env{'form.currentpath'}.'</strong></font>'. |
|
'<br />To upload, rename or delete existing '.$fname.' in portfolio'.$env{'form.currentpath'}); |
|
$r->print(&done('Back')); |
|
} |
|
} else { |
|
my $result=&Apache::lonnet::userfileupload('uploaddoc','', |
|
'portfolio'.$env{'form.currentpath'}); |
|
if ($result !~ m|^/uploaded/|) { |
|
$r->print('<font color="red"> An errror occured ('.$result. |
|
') while trying to upload '.&display_file().'</font><br />'); |
|
$r->print(&done('Back')); |
|
} else { |
|
$r->print(&done()); |
|
} |
|
} |
|
} |
|
sub lock_info { |
|
my ($r) = @_; |
|
my %current_permissions = &Apache::lonnet::dump('file_permissions',$env{'user.domain'},$env{'user.name'}); |
|
my $file_name = $env{'form.lockinfo'}; |
|
foreach my $key(keys(%current_permissions)) { |
|
if ($file_name eq $key) { |
|
foreach my $array_item (@{$current_permissions{$key}}) { |
|
if (ref($array_item)) { |
|
$r->print('<strong>'.$key.'</strong> was submitted in response to problem: <strong>'. |
|
&Apache::lonnet::gettitle($$array_item[0]).'</strong><br />'); |
|
my %course_description = &Apache::lonnet::coursedescription($$array_item[1]); |
|
$r->print('In the course: <strong>'.$course_description{'description'}.'</strong><br />'); |
|
# $r->print('the third is '.$$array_item[2].'<br>'); |
|
# $r->print("item is $$array_item[0]<br> and $$array_item[0]"); |
|
} |
|
} |
|
} |
|
} |
|
$r->print(&done('Back')); |
|
return 'ok'; |
|
} |
|
sub createdir { |
|
my ($r)=@_; |
|
my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'}); |
|
if ($newdir eq '') { |
|
$r->print('<font color="red">'. |
|
&mt("Error: no directory name was provided."). |
|
'</font><br />'); |
|
$r->print(&done()); |
|
return; |
|
} |
|
my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'}, |
|
$env{'user.name'}). |
|
'/userfiles/portfolio'; |
|
my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'}, |
|
$env{'user.domain'}, |
|
$env{'user.name'},$portfolio_root); |
|
my $found_file = 0; |
|
foreach my $line (@dir_list) { |
|
my ($filename)=split(/\&/,$line,2); |
|
if ($filename eq $newdir){ |
|
$found_file = 1; |
|
} |
|
} |
|
if ($found_file){ |
|
$r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir. |
|
' </strong>a file or directory by that name already exists.</font><br />'); |
|
} else { |
|
my $result=&Apache::lonnet::mkdiruserfile($env{'user.name'}, |
|
$env{'user.domain'},'portfolio'.$env{'form.currentpath'}.$newdir); |
|
if ($result ne 'ok') { |
|
$r->print('<font color="red"> An errror occured ('.$result. |
|
') while trying to create a new directory '.&display_file().'</font><br />'); |
|
} |
|
} |
|
if ($newdir ne $env{'form.newdir'}) { |
|
$r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>"); |
|
} |
|
$r->print(&done()); |
} |
} |
|
|
sub handler { |
sub handler { |
# this handles file management |
# this handles file management |
my ($r)=@_; |
my $r = shift; |
my @dirList; # will hold directory listing as array |
my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'}, |
my $udir; # returned from home server |
$env{'user.name'}). |
my $currentPath; # path assuming /userfiles/portfolio/ as root |
'/userfiles/portfolio'; |
my $currentFile; # directory or file contained in $pathToRoot.$currentPath |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
my $action; # delete, rename, makedirectory, removedirectory, |
['selectfile','currentpath','meta','lockinfo', |
my $filenewname; # for rename action (guess what we do with it!) |
'currentfile','action','fieldname','mode','rename','continue']); |
my $isFile; |
&Apache::loncommon::no_cache($r); |
my $isDir; |
&Apache::loncommon::content_type($r,'text/html'); |
# send header |
|
# FIXME need to start using |
|
# &Apache::loncommon::content_type() |
|
$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'. |
my $html=&Apache::lonxml::xmlbegin(); |
|
$r->print($html.'<head><title>'. |
|
&mt('Portfolio Manager'). |
"</title></head>\n"); |
"</title></head>\n"); |
|
if ($env{"form.mode"} eq 'selectfile'){ |
# FIXME need to start using |
$r->print(&Apache::loncommon::bodytag('Portfolio Manager',undef,undef,1)); |
# &Apache::loncommon::bodytag() |
|
$r->print(' |
|
<body bgcolor="dogfood"> |
|
<blockquote>'); |
|
#grab stuff that was sent |
|
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
|
['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 |
|
# sometimes, currentFile will be passed by a form field, selectedfile |
|
# if there is no 'form.selectedfile' then the current directory is |
|
# considered as selected |
|
if ($ENV{'form.currentpath'}) { |
|
$currentPath = $ENV{'form.currentpath'}; |
|
} else { |
|
$currentPath = '/'; |
|
} |
|
if ($ENV{'form.selectfile'}) { |
|
$r->print('<br />found selectfile'.$ENV{'form.selectfile'} .'<br />'); |
|
# have to check if the selected file is a subdirectory |
|
if ($ENV{'form.selectfile'} =~ /-\(Dir\)/) { |
|
# $currentPath =~ /\-\(Dir\)/; |
|
$currentPath = $`.'/'; |
|
$r->print('<br />'.$currentPath.'<br />'); |
|
} |
|
$currentFile = $ENV{'form.selectfile'}; |
|
} else { |
} else { |
$currentFile = ''; |
$r->print(&Apache::loncommon::bodytag('Portfolio Manager')); |
} |
} |
# if we're uploading a file, we need to do it early so it will show in the directory list |
$r->rflush(); |
if ($ENV{'form.uploaddoc.filename'}) { |
if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){ |
$r->print($ENV{'form.storeupl'}.'<br />'); |
$r->print('<font color="red"> No file was selected to upload.'. |
$r->print(&Apache::lonnet::userfileupload('uploaddoc','','portfolio'.$currentPath).'<br />'); |
'To upload a file, click <strong>Browse...</strong>'. |
} |
', select a file, then click <strong>Upload</strong>,</font>'); |
# similarly, we need to delete or rename files before getting directory list |
|
if ($ENV{'form.selectfile'}) { |
|
if ($ENV{'form.fileaction'} eq 'delete') { |
|
&Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef ); |
|
$currentFile = ''; |
|
} elsif($ENV{'form.fileaction'} eq 'rename') { |
|
&Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'} ); |
|
# $r->print('We will rename your file'); |
|
} |
} |
|
if ($env{'form.meta'}) { |
|
&open_form($r); |
|
# $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'})); |
|
$r->print('Edit the meta data<br />'); |
|
&close_form($r); |
} |
} |
# we always need $dirList, plus this will return information about the current file |
if ($env{'form.store'}) { |
# as well as information about he home server directory structure, specifically |
} |
# the path to the users userfiles directory. |
|
@dirList = split /<br\s\/>/, (&Apache::lonnet::portfoliolist($currentPath, $currentFile)); |
if ($env{'form.uploaddoc.filename'}) { |
# portfoliolist returns isdir, isfile and udir as the final array elements |
&upload($r); |
# we'll pop them off the bottom of the array, and put them where they belong |
} elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) { |
|
&delete_confirmed($r); |
# $londcall added to help debug |
} elsif ($env{'form.action'} eq 'delete') { |
my $londcall = pop(@dirList); |
&delete($r); |
$r->print('<br />udir '.$londcall.'<br />'); |
} elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) { |
$udir = pop(@dirList); |
&delete_dir_confirmed($r); |
$r->print('<br />path returned '.$udir.'<br />'); |
} elsif ($env{'form.action'} eq 'deletedir'){ |
$isFile = pop(@dirList); |
&delete_dir($r); |
# $r->print('<br />isfile '.$isFile.'<br />'); |
} elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) { |
$isDir = pop(@dirList); |
&rename_confirmed($r); |
# $r->print('<br />isdir '.$isDir.'<br />'); |
} elsif ($env{'form.rename'}) { |
# return OK if $r->header_only; |
$env{'form.selectfile'} = $env{'form.rename'}; |
# Stuff to maintain proper setting for selected file |
$env{'form.action'} = 'rename'; |
if ($ENV{'form.selectfile'}) { |
&rename($r); |
if ($ENV{'form.fileaction'} eq 'delete') { |
} elsif ($env{'form.createdir'}) { |
&Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef ); |
&createdir($r); |
$ENV{'portfolio.file'} = 'Selected File Deleted'; |
} elsif ($env{'form.lockinfo'}) { |
} elsif($ENV{'form.fileaction'} eq 'rename') { |
&lock_info($r); |
&Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'} ); |
|
# $r->print('We will rename your file'); |
|
} else { |
|
|
|
# Remember user's file selection for later |
|
$ENV{'portfolio.file'} = $ENV{'form.selectfile'}; |
|
# offer things user can do with selected file |
|
} |
|
} else { |
} else { |
unless ($ENV{'portfolio.file'}) { |
my $current_path='/'; |
$ENV{'portfolio.file'} = 'No File Selected'; |
if ($env{'form.currentpath'}) { |
|
$current_path = $env{'form.currentpath'}; |
} |
} |
|
my @dir_list=&Apache::lonnet::dirlist($current_path, |
|
$env{'user.domain'}, |
|
$env{'user.name'},$portfolio_root); |
|
if ($dir_list[0] eq 'no_such_dir'){ |
|
# two main reasons for this: |
|
# 1) never been here, so directory structure not created |
|
# 2) back-button navigation after deleting a directory |
|
if ($current_path eq '/'){ |
|
&Apache::lonnet::mkdiruserfile($env{'user.name'}, |
|
$env{'user.domain'},'portfolio'); |
|
} else { |
|
# some directory that snuck in get rid of the directory |
|
# from the recent pulldown, just in case |
|
&Apache::lonhtmlcommon::remove_recent('portfolio', |
|
[$current_path]); |
|
$current_path = '/'; # force it back to the root |
|
} |
|
# now grab the directory list again, for the first time |
|
@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_common($r,$current_path,$is_empty,\@dir_list); |
|
&display_directory($r,$current_path,$is_empty,\@dir_list); |
|
$r->print("</body>\n</html>\n"); |
} |
} |
############################## |
|
# |
|
# Display begins here |
|
# |
|
############################## |
|
$r->print('<hr /> start '); |
|
$r->print($udir); |
|
$r->print('<table border="1"><tr><td>'); |
|
$r->print(&displayDirectory($currentPath, $currentFile, $isDir, @dirList)); |
|
$r->print('</td><td>'); |
|
$r->print(&displayActions($currentPath, $currentFile, $isDir, $isFile)); |
|
$r->print('</td></tr></table>'); |
|
$r->print('<br />end display<br /><hr />'); |
|
$r->print('</blockquote></body>'); |
|
return OK; |
return OK; |
} |
} |
|
|
1; |
1; |
__END__ |
__END__ |