--- loncom/interface/loncommon.pm 2011/10/03 12:39:41 1.948.2.31
+++ loncom/interface/loncommon.pm 2010/03/17 20:00:02 1.955
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.948.2.31 2011/10/03 12:39:41 raeburn Exp $
+# $Id: loncommon.pm,v 1.955 2010/03/17 20:00:02 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -452,7 +452,7 @@ sub selectstudent_link {
&mt('Select User').'';
}
if ($env{'request.role'}=~/^(au|dc|su)/) {
- $callargs .= ",'',1";
+ $callargs .= ",1";
return ''.
''.
&mt('Select User').'';
@@ -596,51 +596,6 @@ ENDJS
}
-sub javascript_array_indexof {
- return <
-// >> 0;
- if (len === 0) {
- return -1;
- }
- var n = 0;
- if (arguments.length > 0) {
- n = Number(arguments[1]);
- if (n !== n) { // shortcut for verifying if it's NaN
- n = 0;
- } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
- n = (n > 0 || -1) * Math.floor(Math.abs(n));
- }
- }
- if (n >= len) {
- return -1;
- }
- var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
- for (; k < len; k++) {
- if (k in t && t[k] === searchElement) {
- return k;
- }
- }
- return -1;
- }
-}
-
-// ]]>
-
-
-ENDJS
-
-}
-
sub userbrowser_javascript {
my $id_functions = &javascript_index_functions();
return <<"ENDUSERBRW";
@@ -811,9 +766,6 @@ sub selectcourse_link {
} elsif ($selecttype eq 'Course/Community') {
$linktext = &mt('Select Course/Community');
$type = '';
- } elsif ($selecttype eq 'Select') {
- $linktext = &mt('Select');
- $type = '';
}
return ''
."'
.'';
- if ($text ne "") {
+ if ($text ne "") {
$template.='';
}
return $template;
@@ -1253,12 +1202,7 @@ ENDOUTPUT
sub help_open_menu {
my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
= @_;
- $stayOnPage = 0 if (not defined $stayOnPage);
- # only use pop-up help (stayOnPage == 0)
- # if environment.remote is on (using remote control UI)
- if ($env{'environment.remote'} eq 'off' ) {
- $stayOnPage=1;
- }
+ $stayOnPage = 1;
my $output;
if ($component_help) {
if (!$text) {
@@ -1279,8 +1223,8 @@ sub help_open_menu {
sub top_nav_help {
my ($text) = @_;
$text = &mt($text);
- my $stay_on_page =
- ($env{'environment.remote'} eq 'off' );
+ my $stay_on_page = 1;
+
my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
: "javascript:helpMenu('open')";
my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
@@ -1295,10 +1239,7 @@ END
sub help_menu_js {
my ($text) = @_;
-
- my $stayOnPage =
- ($env{'environment.remote'} eq 'off' );
-
+ my $stayOnPage = 1;
my $width = 620;
my $height = 600;
my $helptopic=&general_help();
@@ -1355,10 +1296,7 @@ sub help_open_bug {
unless ($env{'user.adv'}) { return ''; }
unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
$text = "" if (not defined $text);
- $stayOnPage = 0 if (not defined $stayOnPage);
- if ($env{'environment.remote'} eq 'off' ) {
$stayOnPage=1;
- }
$width = 600 if (not defined $width);
$height = 600 if (not defined $height);
@@ -1399,10 +1337,7 @@ sub help_open_faq {
unless ($env{'user.adv'}) { return ''; }
unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
$text = "" if (not defined $text);
- $stayOnPage = 0 if (not defined $stayOnPage);
- if ($env{'environment.remote'} eq 'off' ) {
$stayOnPage=1;
- }
$width = 350 if (not defined $width);
$height = 400 if (not defined $height);
@@ -1851,7 +1786,7 @@ sub domain_select {
return &multiple_select_form($name,$value,4,\%domains);
} else {
$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
- return &select_form($name,$value,\%domains);
+ return &select_form($name,$value,%domains);
}
}
@@ -1913,36 +1848,29 @@ sub multiple_select_form {
=pod
-=item * &select_form($defdom,$name,$hashref,$onchange)
+=item * &select_form($defdom,$name,%hash)
Returns a string containing a
'."\n".''.
- &mt('LON-CAPA can make the required changes to your HTML file.').'
'."\n".
- ''."\n";
- }
- return;
-}
-
-sub modify_html_refs {
- my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
- my $container;
- if ($context eq 'portfolio') {
- $container = $env{'form.container'};
- } elsif ($context eq 'coursedoc') {
- $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');
- return unless (@changes > 0);
- if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
- return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
- $content = &Apache::lonnet::getfile($container);
- return if ($content eq '-1');
- } else {
- return unless ($container =~ /^\Q$dir_root\E/);
- if (open(my $fh,"<$container")) {
- $content = join('', <$fh>);
- close($fh);
- } else {
- return;
- }
- }
- my ($count,$codebasecount) = (0,0);
- my $mm = new File::MMagic;
- my $mime_type = $mm->checktype_contents($content);
- if ($mime_type eq 'text/html') {
- my $parse_result =
- &Apache::lonnet::extract_embedded_items($container,\%allfiles,
- \%codebase,\$content);
- if ($parse_result eq 'ok') {
- foreach my $i (@changes) {
- my $orig = &unescape($env{'form.embedded_orig_'.$i});
- my $ref = &unescape($env{'form.embedded_ref_'.$i});
- if ($allfiles{$ref}) {
- my $newname = $orig;
- my ($attrib_regexp,$codebase);
- $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
- if ($attrib_regexp =~ /:/) {
- $attrib_regexp =~ s/\:/|/g;
- }
- if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
- my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
- $count += $numchg;
- }
- if ($env{'form.embedded_codebase_'.$i} ne '') {
- $codebase = &unescape($env{'form.embedded_codebase_'.$i});
- my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
- $codebasecount ++;
- }
- }
- }
- if ($count || $codebasecount) {
- my $saveresult;
- if ($context eq 'portfolio' || $context eq 'coursedoc') {
- my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
- if ($url eq $container) {
- my ($fname) = ($container =~ m{/([^/]+)$});
- $output = ''.&mt('Updated [quant,_1,reference] in [_2].',
- $count,''.
- $fname.'').'
';
- } else {
- $output = ''.
- &mt('Error: update failed for: [_1].',
- ''.
- $container.'').'
';
- }
- } else {
- if (open(my $fh,">$container")) {
- print $fh $content;
- close($fh);
- $output = ''.&mt('Updated [quant,_1,reference] in [_2].',
- $count,''.
- $container.'').'
';
+ if ($context eq 'testbank') {
+ $output .= &mt('Embedded file uploaded successfully:').
+ ' '.
+ $orig_uploaded_filename.'
';
} else {
- $output = ''.
- &mt('Error: could not update [_1].',
- ''.
- $container.'').'
';
+ $output .= ''.
+ &mt('View embedded file: [_1]',''.
+ $orig_uploaded_filename.'').'
';
}
}
+ close($fh);
}
- } else {
- &logthis('Failed to parse '.$container.
- ' to modify references: '.$parse_result);
}
}
return $output;
@@ -9150,71 +8512,22 @@ sub check_for_existing {
sub check_for_upload {
my ($path,$fname,$group,$element,$portfolio_root,$port_path,
$disk_quota,$current_disk_usage,$uname,$udom) = @_;
- my $filesize = length($env{'form.'.$element});
- if (!$filesize) {
- my $msg = ''.
- &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.').'
'.
- '';
- return ('zero_bytes',$msg);
- }
- $filesize = $filesize/1000; #express in k (1024?)
+ my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
my $getpropath = 1;
my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
$getpropath);
my $found_file = 0;
my $locked_file = 0;
- my @lockers;
- my $navmap;
- if ($env{'request.course.id'}) {
- $navmap = Apache::lonnavmaps::navmap->new();
- }
foreach my $line (@dir_list) {
- my ($file_name,$rest)=split(/\&/,$line,2);
+ my ($file_name)=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 {
- 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);
- }
- }
+ if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
+ $locked_file = 1;
}
}
}
@@ -9232,55 +8545,15 @@ sub check_for_upload {
return ('file_locked',$msg);
} else {
my $msg = '';
- $msg .= &mt(' A file by that name: [_1] was found in [_2].',''.$fname.'',$port_path.$env{'form.currentpath'});
+ $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].',''.$fname.'',$port_path.$env{'form.currentpath'});
$msg .= '';
- return ('existingfile',$msg);
+ $msg .= '
';
+ $msg .= &mt('To upload, rename or delete existing [_1] in [_2].',''.$fname.'', $port_path.$env{'form.currentpath'});
+ return ('file_exists',$msg);
}
}
}
-sub check_for_traversal {
- my ($path,$url,$toplevel) = @_;
- my @parts=split(/\//,$path);
- my $cleanpath;
- my $fullpath = $url;
- for (my $i=0;$i<@parts;$i++) {
- next if ($parts[$i] eq '.');
- if ($parts[$i] eq '..') {
- $fullpath =~ s{([^/]+/)$}{};
- } else {
- $fullpath .= $parts[$i].'/';
- }
- }
- if ($fullpath =~ /^\Q$url\E(.*)$/) {
- $cleanpath = $1;
- } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
- my $curr_toprel = $1;
- my @parts = split(/\//,$curr_toprel);
- my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
- my @urlparts = split(/\//,$url_toprel);
- my $doubledots;
- my $startdiff = -1;
- for (my $i=0; $i<@urlparts; $i++) {
- if ($startdiff == -1) {
- unless ($urlparts[$i] eq $parts[$i]) {
- $startdiff = $i;
- $doubledots .= '../';
- }
- } else {
- $doubledots .= '../';
- }
- }
- if ($startdiff > -1) {
- $cleanpath = $doubledots;
- for (my $i=$startdiff; $i<@parts; $i++) {
- $cleanpath .= $parts[$i].'/';
- }
- }
- }
- $cleanpath =~ s{(/)$}{};
- return $cleanpath;
-}
=pod
@@ -11186,7 +10459,7 @@ sub construct_course {
$title=&mt('Syllabus');
$url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
} else {
- $title=&mt('Table of Contents');
+ $title=&mt('Navigate Contents');
$url='/adm/navmaps';
}
@@ -11203,6 +10476,8 @@ sub construct_course {
############################################################
############################################################
+#SD
+# only Community and Course, or anything else?
sub course_type {
my ($cid) = @_;
if (!defined($cid)) {
@@ -11368,15 +10643,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
@@ -11408,31 +10680,21 @@ 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;
- unless ($domain eq 'public') {
- %domdef = &Apache::lonnet::get_domain_defaults($domain);
- }
foreach my $tool ('aboutme','blog','portfolio') {
$userenv{'availabletools.'.$tool} =
- &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
- undef,\%userenv,\%domdef,\%is_adv);
+ &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
}
foreach my $crstype ('official','unofficial','community') {
$userenv{'canrequest.'.$crstype} =
&Apache::lonnet::usertools_access($username,$domain,$crstype,
- 'reload','requestcourses',
- \%userenv,\%domdef,\%is_adv);
+ 'reload','requestcourses');
}
$env{'user.environment'} = "$lonids/$cookie.id";
@@ -11511,36 +10773,6 @@ sub clean_symb {
return ($symb,$enc);
}
-sub build_release_hashes {
- my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
- return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
- (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
- (ref($randomizetry) eq 'HASH'));
- foreach my $key (keys(%Apache::lonnet::needsrelease)) {
- my ($item,$name,$value) = split(/:/,$key);
- if ($item eq 'parameter') {
- if (ref($checkparms->{$name}) eq 'ARRAY') {
- unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
- push(@{$checkparms->{$name}},$value);
- }
- } else {
- push(@{$checkparms->{$name}},$value);
- }
- } elsif ($item eq 'resourcetag') {
- if ($name eq 'responsetype') {
- $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
- }
- } elsif ($item eq 'course') {
- if ($name eq 'crstype') {
- $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
- }
- }
- }
- ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
- ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
- return;
-}
-
=pod
=back