--- loncom/interface/loncommon.pm 2003/10/24 13:35:37 1.134
+++ loncom/interface/loncommon.pm 2003/12/26 16:27:20 1.163
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.134 2003/10/24 13:35:37 matthew Exp $
+# $Id: loncommon.pm,v 1.163 2003/12/26 16:27:20 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,13 +25,6 @@
#
# http://www.lon-capa.org/
#
-# YEAR=2001
-# 2/13-12/7 Guy Albertelli
-# 12/21 Gerd Kortemeyer
-# 12/25,12/28 Gerd Kortemeyer
-# YEAR=2002
-# 1/4 Gerd Kortemeyer
-# 6/24,7/2 H. K. Ng
# Makes a table out of the previous attempts
# Inputs result_from_symbread, user, domain, course_id
@@ -69,14 +62,13 @@ use Apache::Constants qw(:common :http :
use Apache::lonmsg();
use Apache::lonmenu();
use Apache::lonlocal;
+use HTML::Entities;
my $readit;
-=pod
-
-=head1 Global Variables
-
-=cut
+##
+## Global Variables
+##
# ----------------------------------------------- Filetypes/Languages/Copyright
my %language;
@@ -90,50 +82,19 @@ my %category_extensions;
my %designhash;
# ---------------------------------------------- Thesaurus variables
-
-# FIXME: I don't think it's necessary to document these things;
-# they're privately used - Jeremy
-
-=pod
-
-=over 4
-
-=item * %Keywords
-
-A hash used by &keyword to determine if a word is considered a keyword.
-
-=item * $thesaurus_db_file
-
-Scalar containing the full path to the thesaurus database.
-
-=back
-
-=cut
+#
+# %Keywords:
+# A hash used by &keyword to determine if a word is considered a keyword.
+# $thesaurus_db_file
+# Scalar containing the full path to the thesaurus database.
my %Keywords;
my $thesaurus_db_file;
-# ----------------------------------------------------------------------- BEGIN
-
-# FIXME: I don't think this needs to be documented, it prepares
-# private data structures - Jeremy
-=pod
-
-=head1 General Subroutines
-
-=over 4
-
-=item * BEGIN()
-
-Initialize values from language.tab, copyright.tab, filetypes.tab,
-thesaurus.tab, and filecategories.tab.
-
-=back
-
-=cut
-
-# ----------------------------------------------------------------------- BEGIN
-
+#
+# Initialize values from language.tab, copyright.tab, filetypes.tab,
+# thesaurus.tab, and filecategories.tab.
+#
BEGIN {
# Variable initialization
$thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
@@ -141,32 +102,34 @@ BEGIN {
unless ($readit) {
# ------------------------------------------------------------------- languages
{
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
- '/language.tab');
- if ($fh) {
- while (<$fh>) {
- next if /^\#/;
- chomp;
- my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$_));
- $language{$key}=$val.' - '.$enc;
- if ($sup) {
- $supported_language{$key}=$sup;
- }
- }
- }
+ my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
+ '/language.tab';
+ if ( open(my $fh,"<$langtabfile") ) {
+ while (<$fh>) {
+ next if /^\#/;
+ chomp;
+ my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$_));
+ $language{$key}=$val.' - '.$enc;
+ if ($sup) {
+ $supported_language{$key}=$sup;
+ }
+ }
+ close($fh);
+ }
}
# ------------------------------------------------------------------ copyrights
{
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}.
- '/copyright.tab');
- if ($fh) {
- while (<$fh>) {
- next if /^\#/;
- chomp;
- my ($key,$val)=(split(/\s+/,$_,2));
- $cprtag{$key}=$val;
- }
- }
+ my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
+ '/copyright.tab';
+ if ( open (my $fh,"<$copyrightfile") ) {
+ while (<$fh>) {
+ next if /^\#/;
+ chomp;
+ my ($key,$val)=(split(/\s+/,$_,2));
+ $cprtag{$key}=$val;
+ }
+ close($fh);
+ }
}
# -------------------------------------------------------------- domain designs
@@ -177,15 +140,16 @@ BEGIN {
while ($filename=readdir(DIR)) {
my ($domain)=($filename=~/^(\w+)\./);
{
- my $fh=Apache::File->new($designdir.'/'.$filename);
- if ($fh) {
- while (<$fh>) {
- next if /^\#/;
- chomp;
- my ($key,$val)=(split(/\=/,$_));
- if ($val) { $designhash{$domain.'.'.$key}=$val; }
- }
- }
+ my $designfile = $designdir.'/'.$filename;
+ if ( open (my $fh,"<$designfile") ) {
+ while (<$fh>) {
+ next if /^\#/;
+ chomp;
+ my ($key,$val)=(split(/\=/,$_));
+ if ($val) { $designhash{$domain.'.'.$key}=$val; }
+ }
+ close($fh);
+ }
}
}
@@ -194,32 +158,35 @@ BEGIN {
# ------------------------------------------------------------- file categories
{
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
- '/filecategories.tab');
- if ($fh) {
- while (<$fh>) {
- next if /^\#/;
- chomp;
- my ($extension,$category)=(split(/\s+/,$_,2));
- push @{$category_extensions{lc($category)}},$extension;
- }
- }
+ my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
+ '/filecategories.tab';
+ if ( open (my $fh,"<$categoryfile") ) {
+ while (<$fh>) {
+ next if /^\#/;
+ chomp;
+ my ($extension,$category)=(split(/\s+/,$_,2));
+ push @{$category_extensions{lc($category)}},$extension;
+ }
+ close($fh);
+ }
+
}
# ------------------------------------------------------------------ file types
{
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
- '/filetypes.tab');
- if ($fh) {
+ my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
+ '/filetypes.tab';
+ if ( open (my $fh,"<$typesfile") ) {
while (<$fh>) {
- next if (/^\#/);
- chomp;
- my ($ending,$emb,$descr)=split(/\s+/,$_,3);
- if ($descr ne '') {
- $fe{$ending}=lc($emb);
- $fd{$ending}=$descr;
- }
- }
- }
+ next if (/^\#/);
+ chomp;
+ my ($ending,$emb,$descr)=split(/\s+/,$_,3);
+ if ($descr ne '') {
+ $fe{$ending}=lc($emb);
+ $fd{$ending}=$descr;
+ }
+ }
+ close($fh);
+ }
}
&Apache::lonnet::logthis(
"INFO: Read file types");
@@ -245,8 +212,6 @@ containing javascript with two functions
C. Returned string does not contain EscriptE
tags.
-=over 4
-
=item * openbrowser(formname,elementname,only,omit) [javascript]
inputs: formname, elementname, only, omit
@@ -267,14 +232,12 @@ Inputs: formname, elementname
formname and elementname specify the name of the html form and the name
of the element the selection from the search results will be placed in.
-=back
-
=cut
sub browser_and_searcher_javascript {
return < 'Not specified',
+ 1 => 'Grade 1',
+ 2 => 'Grade 2',
+ 3 => 'Grade 3',
+ 4 => 'Grade 4',
+ 5 => 'Grade 5',
+ 6 => 'Grade 6',
+ 7 => 'Grade 7',
+ 8 => 'Grade 8',
+ 9 => 'Grade 9',
+ 10 => 'Grade 10',
+ 11 => 'Grade 11',
+ 12 => 'Grade 12',
+ 13 => 'Grade 13',
+ 14 => '100 Level',
+ 15 => '200 Level',
+ 16 => '300 Level',
+ 17 => '400 Level',
+ 18 => 'Graduate Level'));
+}
#-------------------------------------------
=pod
@@ -906,6 +901,8 @@ Outputs:
=back
+=back
+
=cut
###############################################################
@@ -944,12 +941,6 @@ sub decode_user_agent {
$clientunicode,$clientos,);
}
-=pod
-
-=back
-
-=cut
-
###############################################################
## Authentication changing form generation subroutines ##
###############################################################
@@ -990,6 +981,8 @@ See loncreateuser.pm for invocation and
=back
+=back
+
=cut
#-------------------------------------------
@@ -1080,10 +1073,10 @@ END
sub authform_authorwarning{
my $result='';
- $result=<<"END";
-As a general rule, only authors or co-authors should be filesystem
-authenticated (which allows access to the server filesystem).
-END
+ $result=''.
+ &mt('As a general rule, only authors or co-authors should be '.
+ 'filesystem authenticated '.
+ '(which allows access to the server filesystem).')."\n";
return $result;
}
@@ -1093,12 +1086,10 @@ sub authform_nochange{
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $result='';
- $result.=<<"END";
-
-Do not change login data
-END
+ my $result = &mt('[_1] Do not change login data',
+ '');
return $result;
}
@@ -1109,24 +1100,23 @@ sub authform_kerberos{
kerb_def_auth => 'krb4',
@_,
);
- my $result='';
- my $check4;
- my $check5;
+ my ($check4,$check5);
if ($in{'kerb_def_auth'} eq 'krb5') {
$check5 = " checked=\"on\"";
} else {
$check4 = " checked=\"on\"";
}
- $result.=<<"END";
-
-Kerberos authenticated with domain
-
-Version 4
-Version 5
-END
+ my $jscall = "javascript:changed_radio('krb',$in{'formname'});";
+ my $result .= &mt
+ ('[_1] Kerberos authenticated with domain [_2] '.
+ '[_3] Version 4 [_4] Version 5',
+ '',
+ '',
+ '',
+ '');
return $result;
}
@@ -1136,15 +1126,13 @@ sub authform_internal{
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $result='';
- $result.=<<"END";
-
-Internally authenticated (with initial password
-)
-END
+ my $jscall = "javascript:changed_radio('int',$args{'formname'});";
+ my $result.=&mt
+ ('[_1] Internally authenticated (with initial password [_2])',
+ '',
+ '');
return $result;
}
@@ -1154,15 +1142,12 @@ sub authform_local{
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $result='';
- $result.=<<"END";
-
-Local Authentication with argument
-
-END
+ my $jscall = "javascript:changed_radio('loc',$in{'formname'});";
+ my $result.=&mt('[_1] Local Authentication with argument [_2]',
+ '',
+ '');
return $result;
}
@@ -1172,24 +1157,16 @@ sub authform_filesystem{
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $result='';
- $result.=<<"END";
-
-Filesystem authenticated (with initial password
-)
-END
+ my $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
+ my $result.= &mt
+ ('[_1] Filesystem Authenticated (with initial password [_2])',
+ '',
+ '');
return $result;
}
-=pod
-
-=back
-
-=cut
-
###############################################################
## Get Authentication Defaults for Domain ##
###############################################################
@@ -1344,7 +1321,7 @@ sub keyword {
=item * get_related_words
-Look up a word in the thesaurus. Takes a scalar arguement and returns
+Look up a word in the thesaurus. Takes a scalar argument and returns
an array of words. If the keyword is not in the thesaurus, an empty array
will be returned. The order of the words returned is determined by the
database which holds them.
@@ -1528,6 +1505,16 @@ sub languagedescription {
($supported_language{$code}?' ('.&mt('interface available').')':'');
}
+sub plainlanguagedescription {
+ my $code=shift;
+ return $language{$code};
+}
+
+sub supportedlanguagecode {
+ my $code=shift;
+ return $supported_language{$code};
+}
+
=pod
=item * copyrightids()
@@ -1764,7 +1751,7 @@ sub get_previous_attempt {
} else {
$value=$returnhash{$version.':'.$_};
}
- $prevattempts.='
');
foreach my $hash (\%sone,\%stwo,\%sthree) {
$r->print('
');
@@ -2553,23 +2592,31 @@ sub csv_print_samples {
$r->print('
'."\n");
}
+######################################################
+######################################################
+
=pod
=item * csv_print_select_table($r,$records,$d)
Prints a table to create associations between values and table columns.
+
$r is an Apache Request ref,
$records is an arrayref from &Apache::loncommon::upfile_record_sep,
$d is an array of 2 element arrays (internal name, displayed name)
=cut
+######################################################
+######################################################
sub csv_print_select_table {
my ($r,$records,$d) = @_;
my $i=0;my %sone;
%sone=&record_sep($$records[0]);
- $r->print('Associate columns with student attributes.'."\n".
- '
Attribute
Column
'."\n");
+ $r->print(&mt('Associate columns with student attributes.')."\n".
+ '
'.
+ '
'.&mt('Attribute').'
'.
+ '
'.&mt('Column').'
'."\n");
foreach (@$d) {
my ($value,$display)=@{ $_ };
$r->print('
'.$display.'
');
@@ -2587,6 +2634,9 @@ sub csv_print_select_table {
return $i;
}
+######################################################
+######################################################
+
=pod
=item * csv_samples_select_table($r,$records,$d)
@@ -2599,22 +2649,25 @@ $d is an array of 2 element arrays (inte
=cut
+######################################################
+######################################################
sub csv_samples_select_table {
my ($r,$records,$d) = @_;
my %sone; my %stwo; my %sthree;
my $i=0;
-
- $r->print('
Field
Samples
');
+ #
+ $r->print('
'.
+ &mt('Field').'
'.&mt('Samples').'
');
%sone=&record_sep($$records[0]);
if (defined($$records[1])) {%stwo=&record_sep($$records[1]);}
if (defined($$records[2])) {%sthree=&record_sep($$records[2]);}
-
+ #
foreach (sort keys %sone) {
- $r->print('