--- loncom/interface/loncommon.pm 2013/05/12 03:36:46 1.1075.2.36
+++ loncom/interface/loncommon.pm 2013/03/20 01:26:15 1.1118
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1075.2.36 2013/05/12 03:36:46 raeburn Exp $
+# $Id: loncommon.pm,v 1.1118 2013/03/20 01:26:15 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -72,6 +72,7 @@ use Apache::lonuserstate();
use LONCAPA qw(:DEFAULT :match);
use DateTime::TimeZone;
use DateTime::Locale::Catalog;
+use Text::Aspell;
use Authen::Captcha;
use Captcha::reCAPTCHA;
@@ -158,6 +159,7 @@ sub ssi_with_retries {
# ----------------------------------------------- Filetypes/Languages/Copyright
my %language;
my %supported_language;
+my %supported_codes;
my %latex_language; # For choosing hyphenation in
my %latex_language_bykey; # for choosing hyphenation from metadata
my %cprtag;
@@ -192,14 +194,15 @@ BEGIN {
while (my $line = <$fh>) {
next if ($line=~/^\#/);
chomp($line);
- my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
+ my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
$language{$key}=$val.' - '.$enc;
if ($sup) {
$supported_language{$key}=$sup;
+ $supported_codes{$key} = $code;
}
if ($latex) {
$latex_language_bykey{$key} = $latex;
- $latex_language{$two} = $latex;
+ $latex_language{$code} = $latex;
}
}
close($fh);
@@ -663,7 +666,7 @@ if (!Array.prototype.indexOf) {
var n = 0;
if (arguments.length > 0) {
n = Number(arguments[1]);
- if (n !== n) { // shortcut for verifying if it's NaN
+ if (n !== n) { // shortcut for verifying if it is NaN
n = 0;
} else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
@@ -899,12 +902,12 @@ sub check_uncheck_jscript {
function checkAll(field) {
if (field.length > 0) {
for (i = 0; i < field.length; i++) {
- if (!field[i].disabled) {
+ if (!field[i].disabled) {
field[i].checked = true;
}
}
} else {
- if (!field.disabled) {
+ if (!field.disabled) {
field.checked = true;
}
}
@@ -1014,6 +1017,33 @@ sub select_language {
=pod
+
+=item * &list_languages()
+
+Returns an array reference that is suitable for use in language prompters.
+Each array element is itself a two element array. The first element
+is the language code. The second element a descsriptiuon of the
+language itself. This is suitable for use in e.g.
+&Apache::edit::select_arg (once dereferenced that is).
+
+=cut
+
+sub list_languages {
+ my @lang_choices;
+
+ foreach my $id (&languageids()) {
+ my $code = &supportedlanguagecode($id);
+ if ($code) {
+ my $selector = $supported_codes{$id};
+ my $description = &plainlanguagedescription($id);
+ push (@lang_choices, [$selector, $description]);
+ }
+ }
+ return \@lang_choices;
+}
+
+=pod
+
=item * &linked_select_forms(...)
linked_select_forms returns a string containing a block
@@ -2161,7 +2191,7 @@ sub select_level_form {
=pod
-=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoma,$excdoms)
+=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
Returns a string containing a
ENDPROGBAR
&r_print($r,$content.&LCprogressbar_script($LCcurrentid));
}
@@ -8225,7 +8237,7 @@ sub get_sections {
}
}
- if ($check_students) {
+ if ($check_students) {
my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
my $sec_index = &Apache::loncoursedata::CL_SECTION();
my $status_index = &Apache::loncoursedata::CL_STATUS();
@@ -8402,7 +8414,7 @@ sub get_course_users {
active => 'Active',
future => 'Future',
);
- my (%nothide,@possdoms);
+ my %nothide;
if ($hidepriv) {
my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
@@ -8412,10 +8424,6 @@ sub get_course_users {
$nothide{$user} = 1;
}
}
- my @possdoms = ($cdom);
- if ($coursehash{'checkforpriv'}) {
- push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
- }
}
foreach my $person (sort(keys(%coursepersonnel))) {
my $match = 0;
@@ -8451,7 +8459,7 @@ sub get_course_users {
}
if ($uname ne '' && $udom ne '') {
if ($hidepriv) {
- if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
+ if ((&Apache::lonnet::privileged($uname,$udom)) &&
(!$nothide{$uname.':'.$udom})) {
next;
}
@@ -9542,23 +9550,18 @@ sub ask_for_embedded_content {
my $heading = &mt('Upload embedded files');
my $buttontext = &mt('Upload');
- my ($navmap,$cdom,$cnum);
+ my $navmap;
if ($env{'request.course.id'}) {
- if ($actionurl eq '/adm/dependencies') {
- $navmap = Apache::lonnavmaps::navmap->new();
- }
- $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
- $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ $navmap = Apache::lonnavmaps::navmap->new();
}
- if (($actionurl eq '/adm/portfolio') ||
- ($actionurl eq '/adm/coursegrp_portfolio')) {
+ if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
my $current_path='/';
if ($env{'form.currentpath'}) {
$current_path = $env{'form.currentpath'};
}
if ($actionurl eq '/adm/coursegrp_portfolio') {
- $udom = $cdom;
- $uname = $cnum;
+ $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
$url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
} else {
$udom = $env{'user.domain'};
@@ -9582,51 +9585,32 @@ sub ask_for_embedded_content {
$toplevel = $url;
if ($args->{'context'} eq 'paste') {
($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
- ($path) =
+ ($path) =
($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
$fileloc = &Apache::lonnet::filelocation('',$toplevel);
$fileloc =~ s{^/}{};
}
}
- } elsif ($actionurl eq '/adm/dependencies') {
+ } elsif ($actionurl eq '/adm/dependencies') {
if ($env{'request.course.id'} ne '') {
+ $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
if (ref($args) eq 'HASH') {
$url = $args->{'docs_url'};
$title = $args->{'docs_title'};
- $toplevel = $url;
- unless ($toplevel =~ m{^/}) {
- $toplevel = "/$url";
- }
+ $toplevel = "/$url";
($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
- if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
- $path = $1;
- } else {
- ($path) =
- ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
- }
+ ($path) =
+ ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
$fileloc = &Apache::lonnet::filelocation('',$toplevel);
$fileloc =~ s{^/}{};
($filename) = ($fileloc =~ m{.+/([^/]+)$});
$heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
}
}
- } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
- $udom = $cdom;
- $uname = $cnum;
- $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
- $toplevel = $url;
- $path = $url;
- $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
- $fileloc =~ s{^/}{};
}
- }
- foreach my $file (keys(%{$allfiles})) {
- my $embed_file;
- if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
- $embed_file = $1;
- } else {
- $embed_file = $file;
- }
+ my $now = time();
+ foreach my $embed_file (keys(%{$allfiles})) {
my $absolutepath;
if ($embed_file =~ m{^\w+://}) {
$newfiles{$embed_file} = 1;
@@ -9664,8 +9648,7 @@ sub ask_for_embedded_content {
my $dirptr = 16384;
foreach my $path (keys(%subdependencies)) {
$currsubfile{$path} = {};
- if (($actionurl eq '/adm/portfolio') ||
- ($actionurl eq '/adm/coursegrp_portfolio')) {
+ if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
my ($sublistref,$listerror) =
&Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
if (ref($sublistref) eq 'ARRAY') {
@@ -9681,15 +9664,9 @@ sub ask_for_embedded_content {
}
} elsif (($actionurl eq '/adm/dependencies') ||
(($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
- ($args->{'context'} eq 'paste')) ||
- ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
+ ($args->{'context'} eq 'paste'))) {
if ($env{'request.course.id'} ne '') {
- my $dir;
- if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
- $dir = $fileloc;
- } else {
- ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
- }
+ my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
if ($dir ne '') {
my ($sublistref,$listerror) =
&Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
@@ -9737,8 +9714,7 @@ sub ask_for_embedded_content {
}
}
my %currfile;
- if (($actionurl eq '/adm/portfolio') ||
- ($actionurl eq '/adm/coursegrp_portfolio')) {
+ if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
my ($dirlistref,$listerror) =
&Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
if (ref($dirlistref) eq 'ARRAY') {
@@ -9754,8 +9730,7 @@ sub ask_for_embedded_content {
}
} elsif (($actionurl eq '/adm/dependencies') ||
(($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
- ($args->{'context'} eq 'paste')) ||
- ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
+ ($args->{'context'} eq 'paste'))) {
if ($env{'request.course.id'} ne '') {
my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
if ($dir ne '') {
@@ -9790,14 +9765,12 @@ sub ask_for_embedded_content {
($file eq $filename.'.bak') ||
($dependencies{$file})) {
if ($actionurl eq '/adm/dependencies') {
- unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
- next if (($rem ne '') &&
- (($env{"httpref.$rem".$file} ne '') ||
- (ref($navmap) &&
- (($navmap->getResourceByUrl($rem.$file) ne '') ||
- (($file =~ /^(.*\.s?html?)\.bak$/i) &&
- ($navmap->getResourceByUrl($rem.$1)))))));
- }
+ next if (($rem ne '') &&
+ (($env{"httpref.$rem".$file} ne '') ||
+ (ref($navmap) &&
+ (($navmap->getResourceByUrl($rem.$file) ne '') ||
+ (($file =~ /^(.*\.s?html?)\.bak$/i) &&
+ ($navmap->getResourceByUrl($rem.$1)))))));
}
$unused{$file} = 1;
}
@@ -9806,38 +9779,28 @@ sub ask_for_embedded_content {
($args->{'context'} eq 'paste')) {
$counter = scalar(keys(%existing));
$numpathchg = scalar(keys(%pathchanges));
- return ($output,$counter,$numpathchg,\%existing);
- } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
- (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
- $counter = scalar(keys(%existing));
- $numpathchg = scalar(keys(%pathchanges));
- return ($output,$counter,$numpathchg,\%existing,\%mapping);
+ return ($output,$counter,$numpathchg,\%existing);
}
foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
if ($actionurl eq '/adm/dependencies') {
next if ($embed_file =~ m{^\w+://});
}
$upload_output .= &start_data_table_row().
- '
'.
&Apache::loncommon::end_data_table_row()."\n";
}
}
@@ -9963,7 +9925,7 @@ sub ask_for_embedded_content {
$output = ''.&mt('Referenced files').': ';
if ($applies > 1) {
$output .=
- &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'
';
+ &mt('No files need to be uploaded, as one of the following applies to each reference:').'
';
if ($numremref) {
$output .= '
'.&mt('reference is to a URL which points to another server').'