--- loncom/interface/loncommon.pm 2013/04/30 13:25:45 1.1075.2.34
+++ loncom/interface/loncommon.pm 2012/12/03 14:47:30 1.1099
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1075.2.34 2013/04/30 13:25:45 raeburn Exp $
+# $Id: loncommon.pm,v 1.1099 2012/12/03 14:47:30 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -67,11 +67,10 @@ use Apache::lonhtmlcommon();
use Apache::loncoursedata();
use Apache::lontexconvert();
use Apache::lonclonecourse();
-use Apache::lonuserutils();
-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 +157,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 +192,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 +529,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 +592,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 +662,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 +750,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 +845,6 @@ function setRole(crstype) {
}
|;
}
- if ($credits_element) {
- $setsections .= qq|
-function setCredits(defaultcredits) {
- document.$formname.$credits_element.value = defaultcredits;
- return;
-}
-|;
- }
return $setsections;
}
@@ -899,12 +890,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 +999,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 +1057,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));
}
@@ -8207,19 +8141,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();
@@ -8246,9 +8168,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; }
@@ -9046,10 +8965,7 @@ sub user_rule_formats {
my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
if (@{$ruleorder} > 0) {
- $output = ' '.
- &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
- '','',$domdesc).
- '
';
+ $output = ' '.&mt("$text{$check} with the following format(s) may only be used for verified users at [_1]:",$domdesc).'
';
foreach my $rule (@{$ruleorder}) {
if (ref($curr_rules) eq 'ARRAY') {
if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
@@ -9567,13 +9483,13 @@ 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'};
@@ -9761,7 +9677,7 @@ sub ask_for_embedded_content {
($args->{'context'} eq 'paste')) {
$counter = scalar(keys(%existing));
$numpathchg = scalar(keys(%pathchanges));
- return ($output,$counter,$numpathchg,\%existing);
+ return ($output,$counter,$numpathchg,\%existing);
}
foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
if ($actionurl eq '/adm/dependencies') {
@@ -10105,7 +10021,7 @@ sub upload_embedded {
$output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).' ';
next;
} elsif ($fname=~/\.(\d+)\.(\w+)$/) {
- $output .= &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).' ';
+ $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).' ';
next;
}
$env{'form.embedded_item_'.$i.'.filename'}=$fname;
@@ -10807,8 +10723,8 @@ sub process_decompression {
my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
my ($dir,$error,$warning,$output);
if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
- $error = &mt('Filename not a supported archive file type.').
- ' '.&mt('Filename should end with one of: [_1].',
+ $error = &mt('File name not a supported archive file type.').
+ ' '.&mt('File name should end with one of: [_1].',
'.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
} else {
my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
@@ -11384,7 +11300,7 @@ sub process_extracted_files {
$folders{'0'} = $items[-2];
if ($env{'form.folderpath'} =~ /\:1$/) {
$containers{'0'}='page';
- } else {
+ } else {
$containers{'0'}='sequence';
}
}
@@ -11504,7 +11420,7 @@ sub process_extracted_files {
}
}
} else {
- $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).' ';
+ $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).' ';
}
}
for (my $i=1; $i<=$numitems; $i++) {
@@ -11526,7 +11442,7 @@ sub process_extracted_files {
}
if ($itemidx eq '') {
$itemidx = 0;
- }
+ }
if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
if ($mapinner{$referrer{$i}}) {
$fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
@@ -11573,12 +11489,12 @@ sub process_extracted_files {
$showpath = "$relpath/$title";
} else {
$showpath = "/$title";
- }
+ }
$result .= '
'.&mt('[_1] included as a dependency',$showpath).'
'."\n";
- }
+ }
unless ($ishome) {
my $fetch = "$fullpath/$title";
- $fetch =~ s/^\Q$prefix$dir\E//;
+ $fetch =~ s/^\Q$prefix$dir\E//;
$prompttofetch{$fetch} = 1;
}
}
@@ -11588,7 +11504,7 @@ sub process_extracted_files {
$path,$env{'form.archive_content_'.$referrer{$i}}).' ';
}
} else {
- $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).' ';
+ $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).' ';
}
}
if (keys(%todelete)) {
@@ -11647,7 +11563,7 @@ sub cleanup_empty_dirs {
my $numitems = 0;
foreach my $item (@dircontents) {
if (-d "$path/$item") {
- &cleanup_empty_dirs("$path/$item");
+ &recurse_dirs("$path/$item");
if (-e "$path/$item") {
$numitems ++;
}
@@ -13196,7 +13112,7 @@ sub commit_customrole {
}
sub commit_standardrole {
- my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
+ my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
my ($output,$logmsg,$linefeed);
if ($context eq 'auto') {
$linefeed = "\n";
@@ -13205,7 +13121,7 @@ sub commit_standardrole {
}
if ($three eq 'st') {
my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
- $one,$two,$sec,$context,$credits);
+ $one,$two,$sec,$context);
if (($result =~ /^error/) || ($result eq 'not_in_class') ||
($result eq 'unknown_course') || ($result eq 'refused')) {
$output = $logmsg.' '.&mt('Error: ').$result."\n";
@@ -13236,8 +13152,7 @@ sub commit_standardrole {
}
sub commit_studentrole {
- my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
- $credits) = @_;
+ my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
my ($result,$linefeed,$oldsecurl,$newsecurl);
if ($context eq 'auto') {
$linefeed = "\n";
@@ -13284,11 +13199,7 @@ sub commit_studentrole {
}
}
if (($expire_role_result eq 'ok') || ($secchange == 0)) {
- $modify_section_result =
- &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
- undef,undef,undef,$sec,
- $end,$start,'','',$cid,
- '',$context,$credits);
+ $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
if ($modify_section_result =~ /^ok/) {
if ($secchange == 1) {
if ($sec eq '') {
@@ -13319,7 +13230,7 @@ sub commit_studentrole {
$result = $modify_section_result;
} elsif ($secchange == 1) {
if ($oldsec eq '') {
- $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_2] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
+ $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
} else {
$$logmsg .= &mt('Error when attempting to expire existing role for [_1] in section [_2] in course [_3] -error: ',$uname,$oldsec,$cid).' '.$expire_role_result.$linefeed;
}
@@ -13345,26 +13256,6 @@ sub commit_studentrole {
return $result;
}
-sub show_role_extent {
- my ($scope,$context,$role) = @_;
- $scope =~ s{^/}{};
- my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
- push(@courseroles,'co');
- my @authorroles = &Apache::lonuserutils::roles_by_context('author');
- if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
- $scope =~ s{/}{_};
- return ''.$env{'course.'.$scope.'.description'}.'';
- } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
- my ($audom,$auname) = split(/\//,$scope);
- return &mt('[_1] Author Space',''.
- &Apache::loncommon::plainname($auname,$audom).'');
- } else {
- $scope =~ s{/$}{};
- return &mt('Domain: [_1]',''.
- &Apache::lonnet::domain($scope,'description').'');
- }
-}
-
############################################################
############################################################
@@ -13557,9 +13448,6 @@ sub construct_course {
} else {
$cenv{'internal.courseowner'} = $args->{'curruser'};
}
- if ($args->{'defaultcredits'}) {
- $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
- }
my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
if ($args->{'crssections'}) {
$cenv{'internal.sectionnums'} = '';
@@ -14016,7 +13904,7 @@ sub init_user_environment {
my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
$domain,$username);
my $reqstatus = $reqauthor{'author_status'};
- if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
+ if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
if (ref($reqauthor{'author'}) eq 'HASH') {
$userenv{'requestauthorqueued'} = $reqstatus.':'.
$reqauthor{'author'}{'timestamp'};
@@ -14174,32 +14062,6 @@ sub update_content_constraints {
return;
}
-sub allmaps_incourse {
- my ($cdom,$cnum,$chome,$cid) = @_;
- if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
- $cid = $env{'request.course.id'};
- $cdom = $env{'course.'.$cid.'.domain'};
- $cnum = $env{'course.'.$cid.'.num'};
- $chome = $env{'course.'.$cid.'.home'};
- }
- my %allmaps = ();
- my $lastchange =
- &Apache::lonnet::get_coursechange($cdom,$cnum);
- if ($lastchange > $env{'request.course.tied'}) {
- my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
- unless ($ferr) {
- &update_content_constraints($cdom,$cnum,$chome,$cid);
- }
- }
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (defined($navmap)) {
- foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
- $allmaps{$res->src()} = 1;
- }
- }
- return \%allmaps;
-}
-
sub parse_supplemental_title {
my ($title) = @_;
@@ -14223,74 +14085,6 @@ sub parse_supplemental_title {
return $title;
}
-sub symb_to_docspath {
- my ($symb) = @_;
- return unless ($symb);
- my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
- if ($resurl=~/\.(sequence|page)$/) {
- $mapurl=$resurl;
- } elsif ($resurl eq 'adm/navmaps') {
- $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
- }
- my $mapresobj;
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (ref($navmap)) {
- $mapresobj = $navmap->getResourceByUrl($mapurl);
- }
- $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
- my $type=$2;
- my $path;
- if (ref($mapresobj)) {
- my $pcslist = $mapresobj->map_hierarchy();
- if ($pcslist ne '') {
- foreach my $pc (split(/,/,$pcslist)) {
- next if ($pc <= 1);
- my $res = $navmap->getByMapPc($pc);
- if (ref($res)) {
- my $thisurl = $res->src();
- $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
- my $thistitle = $res->title();
- $path .= '&'.
- &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($thistitle).
- ':'.$res->randompick().
- ':'.$res->randomout().
- ':'.$res->encrypted().
- ':'.$res->randomorder().
- ':'.$res->is_page();
- }
- }
- }
- $path =~ s/^\&//;
- my $maptitle = $mapresobj->title();
- if ($mapurl eq 'default') {
- $maptitle = 'Main Course Documents';
- }
- $path .= (($path ne '')? '&' : '').
- &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($maptitle).
- ':'.$mapresobj->randompick().
- ':'.$mapresobj->randomout().
- ':'.$mapresobj->encrypted().
- ':'.$mapresobj->randomorder().
- ':'.$mapresobj->is_page();
- } else {
- my $maptitle = &Apache::lonnet::gettitle($mapurl);
- my $ispage = (($type eq 'page')? 1 : '');
- if ($mapurl eq 'default') {
- $maptitle = 'Main Course Documents';
- }
- $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
- &Apache::lonhtmlcommon::entity_encode($maptitle).':::::'.$ispage;
- }
- unless ($mapurl eq 'default') {
- $path = 'default&'.
- &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
- ':::::&'.$path;
- }
- return $path;
-}
-
sub captcha_display {
my ($context,$lonhost) = @_;
my ($output,$error);
@@ -14298,12 +14092,12 @@ sub captcha_display {
if ($captcha eq 'original') {
$output = &create_captcha();
unless ($output) {
- $error = 'captcha';
+ $error = 'captcha';
}
} elsif ($captcha eq 'recaptcha') {
$output = &create_recaptcha($pubkey);
unless ($output) {
- $error = 'recaptcha';
+ $error = 'recaptcha';
}
}
return ($output,$error);
@@ -14409,7 +14203,7 @@ sub check_captcha {
output_folder => $captcha_params{'output_dir'},
data_folder => $captcha_params{'db_dir'},
);
- $captcha_chk = $captcha->check_code($code,$md5sum);
+ my $captcha_chk = $captcha->check_code($code,$md5sum);
my %captcha_hash = (
0 => 'Code not checked (file error)',
-1 => 'Failed: code expired',