[LON-CAPA-cvs] cvs: loncom /interface londocs.pm portfolio.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 29 Jan 2007 21:18:53 -0000
This is a MIME encoded message
--albertel1170105533
Content-Type: text/plain
albertel Mon Jan 29 16:18:53 2007 EDT
Modified files:
/loncom/interface londocs.pm portfolio.pm
Log:
- on upload of a .html file parse and prompt for embedded content
--albertel1170105533
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20070129161853.txt"
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.270 loncom/interface/londocs.pm:1.271
--- loncom/interface/londocs.pm:1.270 Fri Jan 26 18:37:53 2007
+++ loncom/interface/londocs.pm Mon Jan 29 16:18:53 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Documents
#
-# $Id: londocs.pm,v 1.270 2007/01/26 23:37:53 albertel Exp $
+# $Id: londocs.pm,v 1.271 2007/01/29 21:18:53 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1448,7 +1448,7 @@
foreach (@LONCAPA::map::order) {
my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$_]);
$name=&LONCAPA::map::qtescape($name);
- $url =&LONCAPA::map::qtescape($url);
+ $url=&LONCAPA::map::qtescape($url);
unless ($name) { $name=(split(/\//,$url))[-1]; }
unless ($name) { $idx++; next; }
$r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
@@ -1574,34 +1574,42 @@
}
sub ask_for_embedded_content {
- my ($actionurl,$state,$allfiles,$codebase)=@_;
+ my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
my $upload_output = '
<form name="upload_embedded" action="'.$actionurl.'"
method="post" enctype="multipart/form-data">';
$upload_output .= $state;
- $upload_output .= '<b>Upload embedded files</b>:<br />
- <table>';
+ $upload_output .= '<b>Upload embedded files</b>:<br />'.
+ &Apache::loncommon::start_data_table();
my $num = 0;
foreach my $embed_file (keys(%{$allfiles})) {
- $upload_output .= '<tr><td>'.$embed_file.'</td><td>
+ $upload_output .= &Apache::loncommon::start_data_table_row().
+ '<td>'.$embed_file.'</td><td>';
+ if ($args->{'error_on_invalid_names'}
+ && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
+
+ $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
+ } else {
+ $upload_output .='
<input name="embedded_item_'.$num.'" type="file" value="bob" />
<input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
- my $attrib = join(':',@{$$allfiles{$embed_file}});
- $upload_output .=
- "\n\t\t".
- '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
- $attrib.'" />';
- if (exists($$codebase{$embed_file})) {
- $upload_output .=
+ my $attrib = join(':',@{$$allfiles{$embed_file}});
+ $upload_output .=
"\n\t\t".
- '<input name="codebase_'.$num.'" type="hidden" value="'.
- &escape($$codebase{$embed_file}).'" />';
+ '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
+ $attrib.'" />';
+ if (exists($$codebase{$embed_file})) {
+ $upload_output .=
+ "\n\t\t".
+ '<input name="codebase_'.$num.'" type="hidden" value="'.
+ &escape($$codebase{$embed_file}).'" />';
+ }
}
- $upload_output .= '</td></tr>';
+ $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
$num++;
}
- $upload_output .= '</table><br />
+ $upload_output .= &Apache::loncommon::end_data_table().'<br />
<input type ="hidden" name="number_embedded_items" value="'.$num.'" />
<input type ="submit" value="Complete upload" />
</form>';
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.175 loncom/interface/portfolio.pm:1.176
--- loncom/interface/portfolio.pm:1.175 Sun Dec 10 22:43:15 2006
+++ loncom/interface/portfolio.pm Mon Jan 29 16:18:53 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network
# portfolio browser
#
-# $Id: portfolio.pm,v 1.175 2006/12/11 03:43:15 raeburn Exp $
+# $Id: portfolio.pm,v 1.176 2007/01/29 21:18:53 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -147,12 +147,12 @@
);
$r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
if (@tree > 1){
- my $newCurrentPath = '';
+ my $newCurrentPath = '/';
for (my $i = 1; $i< @tree; $i++){
$newCurrentPath .= $tree[$i].'/';
my %anchor_fields = (
'selectfile' => $tree[$i],
- 'currentpath' => '/',
+ 'currentpath' => $newCurrentPath,
'mode' => $env{"form.mode"},
'fieldname' => $env{"form.fieldname"},
'continue' => $env{"form.continue"}
@@ -1750,24 +1750,23 @@
}
}
-sub upload {
- my ($r,$url,$group)=@_;
- my $fname=$env{'form.uploaddoc.filename'};
- my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
+
+sub check_for_upload {
+ my ($path,$fname,$group,$element) = @_;
my $disk_quota = &get_quota($group);
- $fname=&Apache::lonnet::clean_filename($fname);
+ my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
- my $portfolio_root=&get_portfolio_root();
- my ($uname,$udom) = &get_name_dom();
+ my $portfolio_root = &get_portfolio_root();
my $port_path = &get_port_path();
+ my ($uname,$udom) = &get_name_dom();
# Fixme --- Move the checking for existing file to LOND error return
- my @dir_list=&get_dir_list($portfolio_root);
+ my @dir_list=&get_dir_list($portfolio_root,$path);
my $found_file = 0;
my $locked_file = 0;
foreach my $line (@dir_list) {
my ($file_name)=split(/\&/,$line,2);
if ($file_name eq $fname){
- $file_name = $env{'form.currentpath'}.$file_name;
+ $file_name = $path.$file_name;
$file_name = &prepend_group($file_name);
$found_file = 1;
if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
@@ -1776,34 +1775,110 @@
}
}
my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
+
if (($current_disk_usage + $filesize) > $disk_quota){
- $r->print('<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
- '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
- $r->print(&done('Back',$url));
- }
- elsif ($found_file){
- if ($locked_file){
- $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
- '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
- $r->print(&done('Back',$url));
- } else {
- $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
- '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
- $r->print(&done('Back',$url));
- }
- } else {
- my $result=&Apache::lonnet::userfileupload('uploaddoc','',
- $port_path.$env{'form.currentpath'});
- if ($result !~ m|^/uploaded/|) {
- $r->print('<span class="LC_error">'.'An errror occured ('.$result.
- ') while trying to upload '.&display_file().'</span><br />');
- $r->print(&done('Back',$url));
- } else {
- $r->print(&done(undef,$url));
- }
+ my $msg = '<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
+ '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.';
+ return ('will_exceed_quota',$msg);
+ } elsif ($found_file) {
+ if ($locked_file) {
+ my $msg = '<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$path.'</strong></span>'.
+ '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.';
+ return ('file_locked',$msg);
+ } else {
+ my $msg = '<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$path.'</strong></span>'.
+ '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$path;
+ return ('file_exists',$msg);
+ }
+ }
+}
+
+sub upload {
+ my ($r,$url,$group)=@_;
+ my $fname=&Apache::lonnet::clean_filename($env{'form.uploaddoc.filename'});
+
+ my ($state,$msg) = &check_for_upload($env{'form.currentpath'},
+ $fname,$group,'uploaddoc');
+
+ if ($state eq 'will_exceed_quota'
+ || $state eq 'file_locked'
+ || $state eq 'file_exists' ) {
+ $r->print($msg.&done('Back',$url));
+ return;
+ }
+
+ my $port_path = &get_port_path();
+ my (%allfiles,%codebase,$mode);
+ if ($env{'form.uploaddoc.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) {
+ $mode = 'parse';
+
+ }
+ my $result=
+ &Apache::lonnet::userfileupload('uploaddoc','',
+ $port_path.$env{'form.currentpath'},
+ $mode,\%allfiles,\%codebase);
+ if ($result !~ m|^/uploaded/|) {
+ $r->print('<span class="LC_error">'.'An errror occured ('.$result.
+ ') while trying to upload '.&display_file().'</span><br />');
+ $r->print(&done('Back',$url));
+ } else {
+ if (%allfiles) {
+ my $state = <<STATE;
+ <input type="hidden" name="action" value="upload_embedded" />
+ <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
+ <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
+ <input type="hidden" name="mode" value="$env{'form.mode'}" />
+STATE
+ $r->print("<p>Completed upload of the file. This file contained references to other files. You can upload these now: </p>");
+ $r->print(&Apache::londocs::ask_for_embedded_content('/adm/portfolio',$state,\%allfiles,\%codebase,{'error_on_invalid_names' => 1}));
+ $r->print('<p>Or '.&done('Return to directory listing',$url).'</p>');
+ } else {
+ $r->print(&done(undef,$url));
+ }
}
}
+sub upload_embedded {
+ my ($r,$url,$group)=@_;
+ for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
+ next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
+
+ $env{'form.embedded_orig_'.$i} =
+ &unescape($env{'form.embedded_orig_'.$i});
+ my ($path,$fname) =
+ ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
+ $path = $env{'form.currentpath'}.$path;
+ $fname = &Apache::lonnet::clean_filename($fname);
+
+ my ($state,$msg) = &check_for_upload($path,$fname,$group,
+ 'embedded_item_'.$i);
+
+ if ($state eq 'will_exceed_quota'
+ || $state eq 'file_locked'
+ || $state eq 'file_exists' ) {
+ $r->print($msg);
+ next;
+ }
+
+ my $port_path = &get_port_path();
+ my $src_path = $env{'form.embedded_orig_'.$i};
+ $env{'form.embedded_item_'.$i.'.filename'}=$fname;
+
+ my $result=
+ &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
+ $port_path.$path);
+ if ($result !~ m|^/uploaded/|) {
+ $r->print('<span class="LC_error">'.'An errror occured ('.$result.
+ ') while trying to upload '.&display_file($path,$fname).'</span><br />');
+ next;
+ } else {
+ $r->print("<p> Uploaded ".
+ &display_file($port_path.$path,$fname).'</p>');
+ }
+ }
+ $r->print(&done(undef,$url));
+}
+
sub lock_info {
my ($r,$url,$group) = @_;
my ($uname,$udom) = &get_name_dom();
@@ -1921,10 +1996,10 @@
}
sub get_dir_list {
- my ($portfolio_root) = @_;
+ my ($portfolio_root,$path) = @_;
+ $path ||= $env{'form.currentpath'};
my ($uname,$udom) = &get_name_dom();
- return &Apache::lonnet::dirlist($env{'form.currentpath'},
- $udom,$uname,$portfolio_root);
+ return &Apache::lonnet::dirlist($path,$udom,$uname,$portfolio_root);
}
sub get_name_dom {
@@ -2162,6 +2237,12 @@
} else {
&missing_priv($r,$url,'upload');
}
+ } elsif ($env{'form.action'} eq 'upload_embedded') {
+ if ($can_upload) {
+ &upload_embedded($r,$url,$group);
+ } else {
+ &missing_priv($r,$url,'upload');
+ }
} elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
if ($can_delete) {
&delete_confirmed($r,$url,$group);
--albertel1170105533--