';
if ($numremref) {
$output .= '- '.&mt('reference is to a URL which points to another server').'
'."\n";
@@ -8696,7 +8644,7 @@ sub ask_for_embedded_content {
$embed_file,\%mapping,
$allfiles,$codebase);
} else {
- $pathchange_output .=
+ $pathchange_output .=
&start_data_table_row().
' | '.
@@ -8715,7 +8663,7 @@ sub ask_for_embedded_content {
$output .= ''."\n";
}
- if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
+ if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
($actionurl eq '/adm/imsimport')) {
$output .= ''."\n";
} elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
@@ -8727,8 +8675,8 @@ sub ask_for_embedded_content {
my %pathchange = ();
$output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
- $output .= ''.&mt('or').'
';
- }
+ $output .= ''.&mt('or').'
';
+ }
}
return ($output,$num,$numpathchg);
}
@@ -8743,7 +8691,7 @@ sub embedded_file_element {
}
$output .= '';
- unless (($context eq 'upload_embedded') &&
+ unless (($context eq 'upload_embedded') &&
($mapping->{$embed_file} eq $embed_file)) {
$output .='
';
@@ -8844,7 +8792,7 @@ sub upload_embedded {
next;
} else {
$output .= &mt('Uploaded [_1]',''.
- $path.$fname.'').'
';
+ $path.$fname.'').'
';
}
}
} elsif ($context eq 'coursedoc') {
@@ -8951,7 +8899,7 @@ sub modify_html_form {
''.
&end_data_table_row();
- }
+ }
}
} else {
$modifyform = $pathchgtable;
@@ -8992,7 +8940,6 @@ sub modify_html_refs {
$container = $env{'form.primaryurl'};
} else {
$container = $env{'form.filename'};
- $container =~ s{^/priv/(\Q$uname\E)/(.*)}{/home/$1/public_html/$2};
}
my (%allfiles,%codebase,$output,$content);
my @changes = &get_env_multiple('form.namechange');
@@ -9002,7 +8949,7 @@ sub modify_html_refs {
$content = &Apache::lonnet::getfile($container);
return if ($content eq '-1');
} else {
- return unless ($container =~ /^\Q$dir_root\E/);
+ return unless ($container =~ /^\Q$dir_root\E/);
if (open(my $fh,"<$container")) {
$content = join('', <$fh>);
close($fh);
@@ -9014,7 +8961,7 @@ sub modify_html_refs {
my $mm = new File::MMagic;
my $mime_type = $mm->checktype_contents($content);
if ($mime_type eq 'text/html') {
- my $parse_result =
+ my $parse_result =
&Apache::lonnet::extract_embedded_items($container,\%allfiles,
\%codebase,\$content);
if ($parse_result eq 'ok') {
@@ -9024,7 +8971,7 @@ sub modify_html_refs {
if ($allfiles{$ref}) {
my $newname = $orig;
my ($attrib_regexp,$codebase);
- my $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
+ $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
if ($attrib_regexp =~ /:/) {
$attrib_regexp =~ s/\:/|/g;
}
@@ -9033,7 +8980,7 @@ sub modify_html_refs {
$count += $numchg;
}
if ($env{'form.embedded_codebase_'.$i} ne '') {
- my $codebase = &unescape($env{'form.embedded_codebase_'.$i});
+ $codebase = &unescape($env{'form.embedded_codebase_'.$i});
my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
$codebasecount ++;
}
@@ -9047,7 +8994,7 @@ sub modify_html_refs {
my ($fname) = ($container =~ m{/([^/]+)$});
$output = ''.&mt('Updated [quant,_1,reference] in [_2].',
$count,''.
- $fname.'').'
';
+ $fname.'').'';
} else {
$output = ''.
&mt('Error: update failed for: [_1].',
@@ -9099,17 +9046,17 @@ sub check_for_upload {
my $filesize = length($env{'form.'.$element});
if (!$filesize) {
my $msg = ''.
- &mt('Unable to upload [_1]. (size = [_2] bytes)',
+ &mt('Unable to upload [_1]. (size = [_2] bytes)',
''.$fname.'',
$filesize).'
'.
- &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'
';
+ &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'
'.
'';
return ('zero_bytes',$msg);
}
$filesize = $filesize/1000; #express in k (1024?)
my $getpropath = 1;
- my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
- $getpropath);
+ my ($dirlistref,$listerror) =
+ &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
my $found_file = 0;
my $locked_file = 0;
my @lockers;
@@ -9117,48 +9064,50 @@ sub check_for_upload {
if ($env{'request.course.id'}) {
$navmap = Apache::lonnavmaps::navmap->new();
}
- foreach my $line (@dir_list) {
- my ($file_name,$rest)=split(/\&/,$line,2);
- if ($file_name eq $fname){
- $file_name = $path.$file_name;
- if ($group ne '') {
- $file_name = $group.$file_name;
- }
- $found_file = 1;
- if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
- foreach my $lock (@lockers) {
- if (ref($lock) eq 'ARRAY') {
- my ($symb,$crsid) = @{$lock};
- if ($crsid eq $env{'request.course.id'}) {
- if (ref($navmap)) {
- my $res = $navmap->getBySymb($symb);
- foreach my $part (@{$res->parts()}) {
- my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
- unless (($slot_status == $res->RESERVED) ||
- ($slot_status == $res->RESERVED_LOCATION)) {
- $locked_file = 1;
+ if (ref($dirlistref) eq 'ARRAY') {
+ foreach my $line (@{$dirlistref}) {
+ my ($file_name,$rest)=split(/\&/,$line,2);
+ if ($file_name eq $fname){
+ $file_name = $path.$file_name;
+ if ($group ne '') {
+ $file_name = $group.$file_name;
+ }
+ $found_file = 1;
+ if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
+ foreach my $lock (@lockers) {
+ if (ref($lock) eq 'ARRAY') {
+ my ($symb,$crsid) = @{$lock};
+ if ($crsid eq $env{'request.course.id'}) {
+ if (ref($navmap)) {
+ my $res = $navmap->getBySymb($symb);
+ foreach my $part (@{$res->parts()}) {
+ my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
+ unless (($slot_status == $res->RESERVED) ||
+ ($slot_status == $res->RESERVED_LOCATION)) {
+ $locked_file = 1;
+ }
}
+ } else {
+ $locked_file = 1;
}
} else {
$locked_file = 1;
}
- } else {
- $locked_file = 1;
}
- }
- }
- } else {
- my @info = split(/\&/,$rest);
- my $currsize = $info[6]/1000;
- if ($currsize < $filesize) {
- my $extra = $filesize - $currsize;
- if (($current_disk_usage + $extra) > $disk_quota) {
- my $msg = ''.
- &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
- ''.$fname.'',$filesize,$currsize).''.
- '
'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
- $disk_quota,$current_disk_usage);
- return ('will_exceed_quota',$msg);
+ }
+ } else {
+ my @info = split(/\&/,$rest);
+ my $currsize = $info[6]/1000;
+ if ($currsize < $filesize) {
+ my $extra = $filesize - $currsize;
+ if (($current_disk_usage + $extra) > $disk_quota) {
+ my $msg = ''.
+ &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded if existing (smaller) file with same name (size = [_3] kilobytes) is replaced.',
+ ''.$fname.'',$filesize,$currsize).''.
+ '
'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
+ $disk_quota,$current_disk_usage);
+ return ('will_exceed_quota',$msg);
+ }
}
}
}
@@ -9230,6 +9179,113 @@ sub check_for_traversal {
=pod
+=item * &get_turnedin_filepath()
+
+Determines path in a user's portfolio file for storage of files uploaded
+to a specific essayresponse or dropbox item.
+
+Inputs: 3 required + 1 optional.
+$symb is symb for resource, $uname and $udom are for current user (required).
+$caller is optional (can be "submission", if routine is called when storing
+an upoaded file when "Submit Answer" button was pressed).
+
+Returns array containing $path and $multiresp.
+$path is path in portfolio. $multiresp is 1 if this resource contains more
+than one file upload item. Callers of routine should append partid as a
+subdirectory to $path in cases where $multiresp is 1.
+
+Called by: homework/essayresponse.pm and homework/structuretags.pm
+
+=cut
+
+sub get_turnedin_filepath {
+ my ($symb,$uname,$udom,$caller) = @_;
+ my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
+ my $turnindir;
+ my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
+ $turnindir = $userhash{'turnindir'};
+ my ($path,$multiresp);
+ if ($turnindir eq '') {
+ if ($caller eq 'submission') {
+ $turnindir = &mt('turned in');
+ $turnindir =~ s/\W+/_/g;
+ my %newhash = (
+ 'turnindir' => $turnindir,
+ );
+ &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
+ }
+ }
+ if ($turnindir ne '') {
+ $path = '/'.$turnindir.'/';
+ my ($multipart,$turnin,@pathitems);
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (defined($navmap)) {
+ my $mapres = $navmap->getResourceByUrl($map);
+ if (ref($mapres)) {
+ my $pcslist = $mapres->map_hierarchy();
+ if ($pcslist ne '') {
+ foreach my $pc (split(/,/,$pcslist)) {
+ my $res = $navmap->getByMapPc($pc);
+ if (ref($res)) {
+ my $title = $res->compTitle();
+ $title =~ s/\W+/_/g;
+ if ($title ne '') {
+ push(@pathitems,$title);
+ }
+ }
+ }
+ }
+ my $maptitle = $mapres->compTitle();
+ $maptitle =~ s/\W+/_/g;
+ if ($maptitle ne '') {
+ push(@pathitems,$maptitle);
+ }
+ unless ($env{'request.state'} eq 'construct') {
+ my $res = $navmap->getBySymb($symb);
+ if (ref($res)) {
+ my $partlist = $res->parts();
+ my $totaluploads = 0;
+ if (ref($partlist) eq 'ARRAY') {
+ foreach my $part (@{$partlist}) {
+ my @types = $res->responseType($part);
+ my @ids = $res->responseIds($part);
+ for (my $i=0; $i < scalar(@ids); $i++) {
+ if ($types[$i] eq 'essay') {
+ my $partid = $part.'_'.$ids[$i];
+ if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
+ $totaluploads ++;
+ }
+ }
+ }
+ }
+ if ($totaluploads > 1) {
+ $multiresp = 1;
+ }
+ }
+ }
+ }
+ } else {
+ return;
+ }
+ } else {
+ return;
+ }
+ my $restitle=&Apache::lonnet::gettitle($symb);
+ $restitle =~ s/\W+/_/g;
+ if ($restitle eq '') {
+ $restitle = ($resurl =~ m{/[^/]+$});
+ if ($restitle eq '') {
+ $restitle = time;
+ }
+ }
+ push(@pathitems,$restitle);
+ $path .= join('/',@pathitems);
+ }
+ return ($path,$multiresp);
+}
+
+=pod
+
=back
=head1 CSV Upload/Handling functions
@@ -11149,6 +11205,8 @@ sub construct_course {
############################################################
############################################################
+#SD
+# only Community and Course, or anything else?
sub course_type {
my ($cid) = @_;
if (!defined($cid)) {
@@ -11314,15 +11372,12 @@ sub init_user_environment {
my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
my ($tmp) = keys(%userenv);
if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
- # default remote control to off
- if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
} else {
undef(%userenv);
}
if (($userenv{'interface'}) && (!$form->{'interface'})) {
$form->{'interface'}=$userenv{'interface'};
}
- $env{'environment.remote'}=$userenv{'remote'};
if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
# --------------- Do not trust query string to be put directly into environment
@@ -11354,16 +11409,17 @@ sub init_user_environment {
$initial_env{"browser.localres"} = $form->{'localres'};
}
- if ($public) {
- $initial_env{"environment.remote"} = "off";
- }
if ($form->{'interface'}) {
$form->{'interface'}=~s/\W//gs;
$initial_env{"browser.interface"} = $form->{'interface'};
$env{'browser.interface'}=$form->{'interface'};
}
+
my %is_adv = ( is_adv => $env{'user.adv'} );
- my %domdef = &Apache::lonnet::get_domain_defaults($domain);
+ my %domdef;
+ unless ($domain eq 'public') {
+ %domdef = &Apache::lonnet::get_domain_defaults($domain);
+ }
foreach my $tool ('aboutme','blog','portfolio') {
$userenv{'availabletools.'.$tool} =