version 1.637, 2005/06/11 13:38:47
|
version 1.638, 2005/06/13 20:23:54
|
Line 1132 sub allowuploaded {
|
Line 1132 sub allowuploaded {
|
} |
} |
|
|
# --------- File operations in /home/httpd/html/userfiles/$domain/1/2/3/$course |
# --------- File operations in /home/httpd/html/userfiles/$domain/1/2/3/$course |
# input: action, courseID, current domain, home server for course, intended |
# input: action, courseID, current domain, intended |
# path to file, source of file, instruction to parse file for objects, |
# path to file, source of file, instruction to parse file for objects, |
# ref to hash for embedded objects, |
# ref to hash for embedded objects, |
# ref to hash for codebase of java objects. |
# ref to hash for codebase of java objects. |
Line 1162 sub allowuploaded {
|
Line 1162 sub allowuploaded {
|
# |
# |
|
|
sub process_coursefile { |
sub process_coursefile { |
my ($action,$docuname,$docudom,$docuhome,$file,$source,$parser,$allfiles,$codebase)=@_; |
my ($action,$docuname,$docudom,$file,$source,$parser,$allfiles,$codebase)=@_; |
my $fetchresult; |
my $fetchresult; |
|
my $home=&homeserver($docuname,$docudom); |
if ($action eq 'propagate') { |
if ($action eq 'propagate') { |
$fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$file |
$fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$file, |
,$docuhome); |
$home); |
} else { |
} else { |
my $fetchresult = ''; |
my $fetchresult = ''; |
my $fpath = ''; |
my $fpath = ''; |
Line 1182 sub process_coursefile {
|
Line 1183 sub process_coursefile {
|
my $destination = $filepath.'/'.$fname; |
my $destination = $filepath.'/'.$fname; |
rename($source,$destination); |
rename($source,$destination); |
$fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$file, |
$fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$file, |
$docuhome); |
$home); |
} |
} |
} elsif ($action eq 'uploaddoc') { |
} elsif ($action eq 'uploaddoc') { |
open(my $fh,'>'.$filepath.'/'.$fname); |
open(my $fh,'>'.$filepath.'/'.$fname); |
Line 1195 sub process_coursefile {
|
Line 1196 sub process_coursefile {
|
} |
} |
} |
} |
$fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$file, |
$fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$file, |
$docuhome); |
$home); |
if ($fetchresult eq 'ok') { |
if ($fetchresult eq 'ok') { |
return '/uploaded/'.$fpath.'/'.$fname; |
return '/uploaded/'.$fpath.'/'.$fname; |
} else { |
} else { |
&logthis('Failed to transfer '.$docudom.'/'.$docuname.'/'.$file. |
&logthis('Failed to transfer '.$docudom.'/'.$docuname.'/'.$file. |
' to host '.$docuhome.': '.$fetchresult); |
' to host '.$home.': '.$fetchresult); |
return '/adm/notfound.html'; |
return '/adm/notfound.html'; |
} |
} |
} |
} |
} |
} |
unless ( $fetchresult eq 'ok') { |
unless ( $fetchresult eq 'ok') { |
&logthis('Failed to transfer '.$docudom.'/'.$docuname.'/'.$file. |
&logthis('Failed to transfer '.$docudom.'/'.$docuname.'/'.$file. |
' to host '.$docuhome.': '.$fetchresult); |
' to host '.$home.': '.$fetchresult); |
} |
} |
return $fetchresult; |
return $fetchresult; |
} |
} |
Line 1228 sub build_filepath {
|
Line 1229 sub build_filepath {
|
} |
} |
|
|
sub store_edited_file { |
sub store_edited_file { |
my ($primary_url,$content,$docudom,$docuname,$docuhome,$fetchresult) = @_; |
my ($primary_url,$content,$docudom,$docuname,$fetchresult) = @_; |
my $file = $primary_url; |
my $file = $primary_url; |
$file =~ s#^/uploaded/$docudom/$docuname/##; |
$file =~ s#^/uploaded/$docudom/$docuname/##; |
my $fpath = ''; |
my $fpath = ''; |
Line 1239 sub store_edited_file {
|
Line 1240 sub store_edited_file {
|
open(my $fh,'>'.$filepath.'/'.$fname); |
open(my $fh,'>'.$filepath.'/'.$fname); |
print $fh $content; |
print $fh $content; |
close($fh); |
close($fh); |
|
my $home=&homeserver($docuname,$docudom); |
$$fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$file, |
$$fetchresult= &reply('fetchuserfile:'.$docudom.'/'.$docuname.'/'.$file, |
$docuhome); |
$home); |
if ($$fetchresult eq 'ok') { |
if ($$fetchresult eq 'ok') { |
return '/uploaded/'.$fpath.'/'.$fname; |
return '/uploaded/'.$fpath.'/'.$fname; |
} else { |
} else { |
&logthis('Failed to transfer '.$docudom.'/'.$docuname.'/'.$file. ' to host '.$docuhome.': '.$$fetchresult); |
&logthis('Failed to transfer '.$docudom.'/'.$docuname.'/'.$file. |
|
' to host '.$home.': '.$$fetchresult); |
return '/adm/notfound.html'; |
return '/adm/notfound.html'; |
} |
} |
} |
} |
Line 1295 sub userfileupload {
|
Line 1298 sub userfileupload {
|
return $fullpath.'/'.$fname; |
return $fullpath.'/'.$fname; |
} |
} |
# Create the directory if not present |
# Create the directory if not present |
my $docuname=''; |
|
my $docudom=''; |
|
my $docuhome=''; |
|
$fname="$subdir/$fname"; |
$fname="$subdir/$fname"; |
if ($coursedoc) { |
if ($coursedoc) { |
$docuname=$env{'course.'.$env{'request.course.id'}.'.num'}; |
my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'}; |
$docudom=$env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'}; |
$docuhome=$env{'course.'.$env{'request.course.id'}.'.home'}; |
|
if ($env{'form.folder'} =~ m/^default/) { |
if ($env{'form.folder'} =~ m/^default/) { |
return &finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname,$parser,$allfiles,$codebase); |
return &finishuserfileupload($docuname,$docudom, |
|
$formname,$fname,$parser,$allfiles, |
|
$codebase); |
} else { |
} else { |
$fname=$env{'form.folder'}.'/'.$fname; |
$fname=$env{'form.folder'}.'/'.$fname; |
return &process_coursefile('uploaddoc',$docuname,$docudom,$docuhome,$fname,$formname,$parser,$allfiles,$codebase); |
return &process_coursefile('uploaddoc',$docuname,$docudom, |
|
$fname,$formname,$parser, |
|
$allfiles,$codebase); |
} |
} |
} else { |
} else { |
$docuname=$env{'user.name'}; |
my $docuname=$env{'user.name'}; |
$docudom=$env{'user.domain'}; |
my $docudom=$env{'user.domain'}; |
$docuhome=$env{'user.home'}; |
return &finishuserfileupload($docuname,$docudom,$formname, |
return &finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname,$parser,$allfiles,$codebase); |
$fname,$parser,$allfiles,$codebase); |
} |
} |
} |
} |
|
|
sub finishuserfileupload { |
sub finishuserfileupload { |
my ($docuname,$docudom,$docuhome,$formname,$fname,$parser,$allfiles,$codebase) = @_; |
my ($docuname,$docudom,$formname,$fname,$parser,$allfiles,$codebase) = @_; |
my $path=$docudom.'/'.$docuname.'/'; |
my $path=$docudom.'/'.$docuname.'/'; |
my $filepath=$perlvar{'lonDocRoot'}; |
my $filepath=$perlvar{'lonDocRoot'}; |
my ($fnamepath,$file); |
my ($fnamepath,$file); |
Line 1342 sub finishuserfileupload {
|
Line 1345 sub finishuserfileupload {
|
close(FH); |
close(FH); |
} |
} |
if ($parser eq 'parse') { |
if ($parser eq 'parse') { |
my $parse_result = &extract_embedded_items($filepath,$file,$allfiles,$codebase); |
my $parse_result = &extract_embedded_items($filepath,$file,$allfiles, |
|
$codebase); |
unless ($parse_result eq 'ok') { |
unless ($parse_result eq 'ok') { |
&logthis('Failed to parse '.$filepath.$file.' for embedded media: '.$parse_result); |
&logthis('Failed to parse '.$filepath.$file. |
|
' for embedded media: '.$parse_result); |
} |
} |
} |
} |
# Notify homeserver to grep it |
# Notify homeserver to grep it |
# |
# |
|
my $docuhome=&homeserver($docuname,$docudom); |
my $fetchresult= &reply('fetchuserfile:'.$path.$file,$docuhome); |
my $fetchresult= &reply('fetchuserfile:'.$path.$file,$docuhome); |
if ($fetchresult eq 'ok') { |
if ($fetchresult eq 'ok') { |
# |
# |
Line 1471 sub extract_embedded_items {
|
Line 1477 sub extract_embedded_items {
|
|
|
sub extract_java_items { |
sub extract_java_items { |
my ($javafiles,$allfiles,$codebase) = @_; |
my ($javafiles,$allfiles,$codebase) = @_; |
foreach my $item (keys (%{$javafiles})) { |
foreach my $item (keys(%{$javafiles})) { |
unless ($item eq 'codebase') { |
if ($item ne 'codebase') { |
if ($$javafiles{$item} ne '') { |
if ($$javafiles{$item} ne '') { |
if (exists($$allfiles{$$javafiles{'codebase'}.$$javafiles{$item}})) { |
my $file=$javafiles->{'codebase'}.$javafiles->{$item}; |
unless (grep/^$item$/,@{$$allfiles{$$javafiles{'codebase'}.$$javafiles{$item}}}) { |
if (exists($allfiles->{$file})) { |
push(@{$$allfiles{$$javafiles{'codebase'}.$$javafiles{$item}}},&escape($item)); |
unless (scalar(grep(/^$item$/, @{$allfiles->{$file}}))) { |
} |
push(@{$allfiles->{$file}}, &escape($item)); |
} else { |
} |
@{$$allfiles{$$javafiles{'codebase'}.$$javafiles{$item}}} = (&escape($item)); |
} else { |
$$codebase{$$javafiles{'codebase'}.$$javafiles{$item}} = $$javafiles{'codebase'}; |
@{$allfiles->{$file}} = (&escape($item)); |
|
$codebase->{$file} = $javafiles->{'codebase'}; |
} |
} |
} |
} |
} |
} |
Line 3875 sub createcourse {
|
Line 3881 sub createcourse {
|
</map> |
</map> |
ENDINITMAP |
ENDINITMAP |
$topurl=&declutter( |
$topurl=&declutter( |
&finishuserfileupload($uname,$udom,$uhome,'initmap','default.sequence') |
&finishuserfileupload($uname,$udom,'initmap','default.sequence') |
); |
); |
} |
} |
# ----------------------------------------------------------- Write preferences |
# ----------------------------------------------------------- Write preferences |
Line 6798 userspace, probably shouldn't be called
|
Line 6804 userspace, probably shouldn't be called
|
|
|
docuname: username or courseid of destination for the file |
docuname: username or courseid of destination for the file |
docudom: domain of user/course of destination for the file |
docudom: domain of user/course of destination for the file |
docuhome: loncapa id of the library server that is getting the file |
|
formname: same as for userfileupload() |
formname: same as for userfileupload() |
fname: filename (inculding subdirectories) for the file |
fname: filename (inculding subdirectories) for the file |
|
|