--- loncom/interface/loncommon.pm 2013/06/05 13:25:41 1.1075.2.39
+++ loncom/interface/loncommon.pm 2013/01/09 03:56:27 1.1110
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1075.2.39 2013/06/05 13:25:41 raeburn Exp $
+# $Id: loncommon.pm,v 1.1110 2013/01/09 03:56:27 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);
@@ -528,8 +531,7 @@ ENDAUTHORBRW
}
sub coursebrowser_javascript {
- my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
- $credits_element) = @_;
+ my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
my $wintitle = 'Course_Browser';
if ($crstype eq 'Community') {
$wintitle = 'Community_Browser';
@@ -592,9 +594,8 @@ sub coursebrowser_javascript {
}
$id_functions
ENDSTDBRW
- if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
- $output .= &setsec_javascript($sec_element,$formname,$role_element,
- $credits_element);
+ if (($sec_element ne '') || ($role_element ne '')) {
+ $output .= &setsec_javascript($sec_element,$formname,$role_element);
}
$output .= '
// ]]>
@@ -663,7 +664,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));
@@ -751,7 +752,7 @@ ENDUSERBRW
}
sub setsec_javascript {
- my ($sec_element,$formname,$role_element,$credits_element) = @_;
+ my ($sec_element,$formname,$role_element) = @_;
my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
$communityrolestr);
if ($role_element ne '') {
@@ -846,14 +847,6 @@ function setRole(crstype) {
}
|;
}
- if ($credits_element) {
- $setsections .= qq|
-function setCredits(defaultcredits) {
- document.$formname.$credits_element.value = defaultcredits;
- return;
-}
-|;
- }
return $setsections;
}
@@ -899,12 +892,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;
}
}
@@ -1008,12 +1001,38 @@ sub select_language {
$langchoices{$code} = &plainlanguagedescription($id);
}
}
- %langchoices = &Apache::lonlocal::texthash(%langchoices);
return &select_form($selected,$name,\%langchoices);
}
=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
@@ -1040,12 +1059,6 @@ linked_select_forms takes the following
=item * $menuorder, the order of values in the first menu
-=item * $onchangefirst, additional javascript call to execute for an onchange
- event for the first
ENDPROGBAR
&r_print($r,$content.&LCprogressbar_script($LCcurrentid));
}
@@ -8222,19 +8201,7 @@ sub get_sections {
my %sectioncount;
my $now = time;
- my $check_students = 1;
- my $only_students = 0;
- if (ref($possible_roles) eq 'ARRAY') {
- if (grep(/^st$/,@{$possible_roles})) {
- if (@{$possible_roles} == 1) {
- $only_students = 1;
- }
- } else {
- $check_students = 0;
- }
- }
-
- if ($check_students) {
+ if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
my $sec_index = &Apache::loncoursedata::CL_SECTION();
my $status_index = &Apache::loncoursedata::CL_STATUS();
@@ -8261,9 +8228,6 @@ sub get_sections {
}
}
}
- if ($only_students) {
- return %sectioncount;
- }
my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
foreach my $user (sort(keys(%courseroles))) {
if ($user !~ /^(\w{2})/) { next; }
@@ -8411,7 +8375,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'})) {
@@ -8421,10 +8385,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;
@@ -8460,7 +8420,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;
}
@@ -9551,23 +9511,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'};
@@ -9591,50 +9546,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;
@@ -9672,8 +9609,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') {
@@ -9689,15 +9625,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,'/');
@@ -9745,8 +9675,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') {
@@ -9762,8 +9691,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 '') {
@@ -9798,14 +9726,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;
}
@@ -9814,38 +9740,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";
}
}
@@ -9971,7 +9886,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').'