--- loncom/interface/loncommon.pm 2007/01/20 22:04:57 1.502
+++ loncom/interface/loncommon.pm 2009/05/07 16:25:02 1.806
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.502 2007/01/20 22:04:57 raeburn Exp $
+# $Id: loncommon.pm,v 1.806 2009/05/07 16:25:02 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -61,19 +61,96 @@ use POSIX qw(strftime mktime);
use Apache::lonmenu();
use Apache::lonenc();
use Apache::lonlocal;
+use Apache::lonnet();
use HTML::Entities;
use Apache::lonhtmlcommon();
use Apache::loncoursedata();
use Apache::lontexconvert();
use Apache::lonclonecourse();
use LONCAPA qw(:DEFAULT :match);
+use DateTime::TimeZone;
+use DateTime::Locale::Catalog;
+
+# ---------------------------------------------- Designs
+use vars qw(%defaultdesign);
my $readit;
+
##
## Global Variables
##
+
+# ----------------------------------------------- SSI with retries:
+#
+
+=pod
+
+=head1 Server Side include with retries:
+
+=over 4
+
+=item * &ssi_with_retries(resource,retries form)
+
+Performs an ssi with some number of retries. Retries continue either
+until the result is ok or until the retry count supplied by the
+caller is exhausted.
+
+Inputs:
+
+=over 4
+
+resource - Identifies the resource to insert.
+
+retries - Count of the number of retries allowed.
+
+form - Hash that identifies the rendering options.
+
+=back
+
+Returns:
+
+=over 4
+
+content - The content of the response. If retries were exhausted this is empty.
+
+response - The response from the last attempt (which may or may not have been successful.
+
+=back
+
+=back
+
+=cut
+
+sub ssi_with_retries {
+ my ($resource, $retries, %form) = @_;
+
+
+ my $ok = 0; # True if we got a good response.
+ my $content;
+ my $response;
+
+ # Try to get the ssi done. within the retries count:
+
+ do {
+ ($content, $response) = &Apache::lonnet::ssi($resource, %form);
+ $ok = $response->is_success;
+ if (!$ok) {
+ &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
+ }
+ $retries--;
+ } while (!$ok && ($retries > 0));
+
+ if (!$ok) {
+ $content = ''; # On error return an empty content.
+ }
+ return ($content, $response);
+
+}
+
+
+
# ----------------------------------------------- Filetypes/Languages/Copyright
my %language;
my %supported_language;
@@ -82,10 +159,6 @@ my %scprtag;
my %fe; my %fd; my %fm;
my %category_extensions;
-# ---------------------------------------------- Designs
-
-my %designhash;
-
# ---------------------------------------------- Thesaurus variables
#
# %Keywords:
@@ -151,30 +224,18 @@ BEGIN {
}
}
-# -------------------------------------------------------------- domain designs
-
- my $filename;
+# -------------------------------------------------------------- default domain designs
my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
- opendir(DIR,$designdir);
- while ($filename=readdir(DIR)) {
- if ($filename!~/\.tab$/) { next; }
- my ($domain)=($filename=~/^($match_domain)\./);
- {
- my $designfile = $designdir.'/'.$filename;
- if ( open (my $fh,"<$designfile") ) {
- while (my $line = <$fh>) {
- next if ($line =~ /^\#/);
- chomp($line);
- my ($key,$val)=(split(/\=/,$line));
- if ($val) { $designhash{$domain.'.'.$key}=$val; }
- }
- close($fh);
- }
- }
-
+ my $designfile = $designdir.'/default.tab';
+ if ( open (my $fh,"<$designfile") ) {
+ while (my $line = <$fh>) {
+ next if ($line =~ /^\#/);
+ chomp($line);
+ my ($key,$val)=(split(/\=/,$line));
+ if ($val) { $defaultdesign{$key}=$val; }
+ }
+ close($fh);
}
- closedir(DIR);
-
# ------------------------------------------------------------- file categories
{
@@ -210,7 +271,7 @@ BEGIN {
}
}
&Apache::lonnet::logthis(
- "INFO: Read file types");
+ "INFO: Read file types");
$readit=1;
} # end of unless($readit)
@@ -226,14 +287,14 @@ BEGIN {
=over 4
-=item * browser_and_searcher_javascript ()
+=item * &browser_and_searcher_javascript()
XXReturns a string
containing javascript with two functions, C and
C. Returned string does not contain EscriptE
tags.
-=item * openbrowser(formname,elementname,only,omit) [javascript]
+=item * &openbrowser(formname,elementname,only,omit) [javascript]
inputs: formname, elementname, only, omit
@@ -246,7 +307,7 @@ with the given extension. Can be a comm
Specifying 'omit' will restrict the browser to NOT displaying files
with the given extension. Can be a comma separated list.
-=item * opensearcher(formname, elementname) [javascript]
+=item * &opensearcher(formname,elementname) [javascript]
Inputs: formname, elementname
@@ -269,6 +330,7 @@ sub browser_and_searcher_javascript {
}
url += 'catalogmode=interactive&';
url += 'mode=$mode&';
+ url += 'inhibitmenu=yes&';
url += 'form=' + formname + '&';
if (only != null) {
url += 'only=' + only + '&';
@@ -330,7 +392,7 @@ sub storeresurl {
unless ($resurl=~/^\/res/) { return 0; }
$resurl=~s/\/$//;
&Apache::lonnet::put('environment',{'lastresurl' => $resurl});
- &Apache::lonnet::appenv('environment.lastresurl' => $resurl);
+ &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
return 1;
}
@@ -344,12 +406,14 @@ sub studentbrowser_javascript {
|| ($env{'request.role'}=~/^(au|dc|su)/)
) { return ''; }
return (<<'ENDSTDBRW');
-
+ENDAUTHORBRW
+}
+
sub coursebrowser_javascript {
my ($domainfilter,$sec_element,$formname)=@_;
my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
my $output = '
- block
and html for two ";
return $selectdomain;
@@ -1474,53 +1821,73 @@ sub select_dom_form {
=pod
-=item * get_library_servers($domain)
+=item * &home_server_form_item($domain,$name,$defaultflag)
-Returns a hash which contains keys like '103l3' and values like
-'kirk.lite.msu.edu'. All of the keys will be for machines in the
-given $domain.
+input: 4 arguments (two required, two optional) -
+ $domain - domain of new user
+ $name - name of form element
+ $default - Value of 'default' causes a default item to be first
+ option, and selected by default.
+ $hide - Value of 'hide' causes hiding of the name of the server,
+ if 1 server found, or default, if 0 found.
+output: returns 2 items:
+(a) form element which contains either:
+ (i)
+ form item if there are multiple library servers in $domain, or
+ (ii) an form item
+ if there is only one library server in $domain.
-=cut
+(b) number of library servers found.
-#-------------------------------------------
-sub get_library_servers {
- my $domain = shift;
- my %library_servers;
- foreach my $hostid (keys(%Apache::lonnet::libserv)) {
- if ($Apache::lonnet::hostdom{$hostid} eq $domain) {
- $library_servers{$hostid} = $Apache::lonnet::hostname{$hostid};
- }
- }
- return %library_servers;
-}
-
-#-------------------------------------------
-
-=pod
-
-=item * home_server_option_list($domain)
-
-returns a string which contains an
list to be used in a
-'."\n";
+ } elsif ($numlib == 1) {
+ my $hostid;
+ foreach my $item (keys(%servers)) {
+ $hostid = $item;
+ }
+ $result .= '';
+ if (!$hide) {
+ $result .= $hostid.' '.$servers{$hostid};
+ }
+ $result .= "\n";
+ } elsif ($default) {
+ $result .= '';
+ if (!$hide) {
+ $result .= &mt('default');
+ }
+ $result .= "\n";
}
- return $result;
+ return ($result,$numlib);
}
=pod
-=back
+=back
=cut
@@ -1614,14 +1981,12 @@ sub decode_user_agent {
=over 4
-=item * authform_xxxxxx
+=item * &authform_xxxxxx()
The authform_xxxxxx subroutines provide javascript and html forms which
handle some of the conveniences required for authentication forms.
This is not an optimal method, but it works.
-See loncreateuser.pm for invocation and use examples.
-
=over 4
=item * authform_header
@@ -1638,7 +2003,7 @@ See loncreateuser.pm for invocation and
=back
-=back
+See loncreateuser.pm for invocation and use examples.
=cut
@@ -1668,19 +2033,16 @@ END
}
my $radioval = "'nochange'";
- if (exists($in{'curr_authtype'}) &&
- defined($in{'curr_authtype'}) &&
- $in{'curr_authtype'} ne '') {
- $radioval = "'$in{'curr_authtype'}arg'";
+ if (defined($in{'curr_authtype'})) {
+ if ($in{'curr_authtype'} ne '') {
+ $radioval = "'".$in{'curr_authtype'}."arg'";
+ }
}
my $argfield = 'null';
- if ( grep/^mode$/,(keys %in) ) {
+ if (defined($in{'mode'})) {
if ($in{'mode'} eq 'modifycourse') {
- if ( grep/^curr_authtype$/,(keys %in) ) {
- $radioval = "'$in{'curr_authtype'}'";
- }
- if ( grep/^curr_autharg$/,(keys %in) ) {
- unless ($in{'curr_autharg'} eq '') {
+ if (defined($in{'curr_autharg'})) {
+ if ($in{'curr_autharg'} ne '') {
$argfield = "'$in{'curr_autharg'}'";
}
}
@@ -1763,79 +2125,181 @@ sub authform_nochange{
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $result = ''.&mt('[_1] Do not change login data',
- '').
'';
+ }
return $result;
}
-sub authform_kerberos{
+sub authform_kerberos {
my %in = (
formname => 'document.cu',
kerb_def_dom => 'MSU.EDU',
kerb_def_auth => 'krb4',
@_,
);
- my ($check4,$check5,$krbarg);
+ my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
+ $autharg,$jscall);
+ my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
if ($in{'kerb_def_auth'} eq 'krb5') {
- $check5 = " checked=\"on\"";
+ $check5 = ' checked="checked"';
} else {
- $check4 = " checked=\"on\"";
+ $check4 = ' checked="checked"';
}
$krbarg = $in{'kerb_def_dom'};
-
- my $krbcheck = "";
- if ( grep/^curr_authtype$/,(keys %in) ) {
- if ($in{'curr_authtype'} =~ m/^krb/) {
- $krbcheck = " checked=\"on\"";
- if ( grep/^curr_autharg$/,(keys %in) ) {
+ if (defined($in{'curr_authtype'})) {
+ if ($in{'curr_authtype'} eq 'krb') {
+ $krbcheck = ' checked="checked"';
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifyuser') {
+ $krbcheck = '';
+ }
+ }
+ if (defined($in{'curr_kerb_ver'})) {
+ if ($in{'curr_krb_ver'} eq '5') {
+ $check5 = ' checked="checked"';
+ $check4 = '';
+ } else {
+ $check4 = ' checked="checked"';
+ $check5 = '';
+ }
+ }
+ if (defined($in{'curr_autharg'})) {
$krbarg = $in{'curr_autharg'};
}
+ if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
+ if (defined($in{'curr_autharg'})) {
+ $result =
+ &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
+ $in{'curr_autharg'},$krbver);
+ } else {
+ $result =
+ &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
+ }
+ return $result;
+ }
+ }
+ } else {
+ if ($authnum == 1) {
+ $authtype = '';
}
}
-
- my $jscall = "javascript:changed_radio('krb',$in{'formname'});";
- my $result .= &mt
+ if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
+ return;
+ } elsif ($authtype eq '') {
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifycourse') {
+ if ($authnum == 1) {
+ $authtype = '';
+ }
+ }
+ }
+ }
+ $jscall = "javascript:changed_radio('krb',$in{'formname'});";
+ if ($authtype eq '') {
+ $authtype = '';
+ }
+ if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
+ ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
+ $in{'curr_authtype'} eq 'krb5') ||
+ (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
+ $in{'curr_authtype'} eq 'krb4')) {
+ $result .= &mt
('[_1] Kerberos authenticated with domain [_2] '.
'[_3] Version 4 [_4] Version 5 [_5]',
- '',
+ ''.$authtype,
'',
'',
'',
'');
+ } elsif ($can_assign{'krb4'}) {
+ $result .= &mt
+ ('[_1] Kerberos authenticated with domain [_2] '.
+ '[_3] Version 4 [_4]',
+ ''.$authtype,
+ '',
+ '',
+ '');
+ } elsif ($can_assign{'krb5'}) {
+ $result .= &mt
+ ('[_1] Kerberos authenticated with domain [_2] '.
+ '[_3] Version 5 [_4]',
+ ''.$authtype,
+ '',
+ '',
+ '');
+ }
return $result;
}
sub authform_internal{
- my %args = (
+ my %in = (
formname => 'document.cu',
kerb_def_dom => 'MSU.EDU',
@_,
);
-
- my $intcheck = "";
- my $intarg = 'value=""';
- if ( grep/^curr_authtype$/,(keys %args) ) {
- if ($args{'curr_authtype'} eq 'int') {
- $intcheck = " checked=\"on\"";
- if ( grep/^curr_autharg$/,(keys %args) ) {
- $intarg = "value=\"$args{'curr_autharg'}\"";
+ my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
+ my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
+ if (defined($in{'curr_authtype'})) {
+ if ($in{'curr_authtype'} eq 'int') {
+ if ($can_assign{'int'}) {
+ $intcheck = 'checked="checked" ';
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifyuser') {
+ $intcheck = '';
+ }
+ }
+ if (defined($in{'curr_autharg'})) {
+ $intarg = $in{'curr_autharg'};
+ }
+ } else {
+ $result = &mt('Currently internally authenticated.');
+ return $result;
}
}
+ } else {
+ if ($authnum == 1) {
+ $authtype = '';
+ }
}
-
- my $jscall = "javascript:changed_radio('int',$args{'formname'});";
- my $result.=&mt
+ if (!$can_assign{'int'}) {
+ return;
+ } elsif ($authtype eq '') {
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifycourse') {
+ if ($authnum == 1) {
+ $authtype = '';
+ }
+ }
+ }
+ }
+ $jscall = "javascript:changed_radio('int',$in{'formname'});";
+ if ($authtype eq '') {
+ $authtype = '';
+ }
+ $autharg = '';
+ $result = &mt
('[_1] Internally authenticated (with initial password [_2])',
- '',
- '');
+ ''.$authtype,''.$autharg);
+ $result.="".&mt('Visible input').'';
return $result;
}
@@ -1845,24 +2309,51 @@ sub authform_local{
kerb_def_dom => 'MSU.EDU',
@_,
);
-
- my $loccheck = "";
- my $locarg = 'value=""';
- if ( grep/^curr_authtype$/,(keys %in) ) {
+ my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
+ my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
+ if (defined($in{'curr_authtype'})) {
if ($in{'curr_authtype'} eq 'loc') {
- $loccheck = " checked=\"on\"";
- if ( grep/^curr_autharg$/,(keys %in) ) {
- $locarg = "value=\"$in{'curr_autharg'}\"";
+ if ($can_assign{'loc'}) {
+ $loccheck = 'checked="checked" ';
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifyuser') {
+ $loccheck = '';
+ }
+ }
+ if (defined($in{'curr_autharg'})) {
+ $locarg = $in{'curr_autharg'};
+ }
+ } else {
+ $result = &mt('Currently using local (institutional) authentication.');
+ return $result;
}
}
+ } else {
+ if ($authnum == 1) {
+ $authtype = '';
+ }
}
-
- my $jscall = "javascript:changed_radio('loc',$in{'formname'});";
- my $result.=&mt('[_1] Local Authentication with argument [_2]',
- '',
- '');
+ if (!$can_assign{'loc'}) {
+ return;
+ } elsif ($authtype eq '') {
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifycourse') {
+ if ($authnum == 1) {
+ $authtype = '';
+ }
+ }
+ }
+ }
+ $jscall = "javascript:changed_radio('loc',$in{'formname'});";
+ if ($authtype eq '') {
+ $authtype = '';
+ }
+ $autharg = '';
+ $result = &mt('[_1] Local Authentication with argument [_2]',
+ ''.$authtype,''.$autharg);
return $result;
}
@@ -1872,49 +2363,96 @@ sub authform_filesystem{
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
- my $result.= &mt
+ my ($fsyscheck,$result,$authtype,$autharg,$jscall);
+ my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
+ if (defined($in{'curr_authtype'})) {
+ if ($in{'curr_authtype'} eq 'fsys') {
+ if ($can_assign{'fsys'}) {
+ $fsyscheck = 'checked="checked" ';
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifyuser') {
+ $fsyscheck = '';
+ }
+ }
+ } else {
+ $result = &mt('Currently Filesystem Authenticated.');
+ return $result;
+ }
+ }
+ } else {
+ if ($authnum == 1) {
+ $authtype = '';
+ }
+ }
+ if (!$can_assign{'fsys'}) {
+ return;
+ } elsif ($authtype eq '') {
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifycourse') {
+ if ($authnum == 1) {
+ $authtype = '';
+ }
+ }
+ }
+ }
+ $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
+ if ($authtype eq '') {
+ $authtype = '';
+ }
+ $autharg = '';
+ $result = &mt
('[_1] Filesystem Authenticated (with initial password [_2])',
'',
- '',
+ '');
return $result;
}
-###############################################################
-## Get Authentication Defaults for Domain ##
-###############################################################
-
-=pod
-
-=head1 Domains and Authentication
-
-Returns default authentication type and an associated argument as
-listed in file 'domain.tab'.
-
-=over 4
-
-=item * get_auth_defaults
-
-get_auth_defaults($target_domain) returns the default authentication
-type and an associated argument (initial password or a kerberos domain).
-These values are stored in lonTabs/domain.tab
-
-($def_auth, $def_arg) = &get_auth_defaults($target_domain);
-
-If target_domain is not found in domain.tab, returns nothing ('').
-
-=cut
-
-#-------------------------------------------
-sub get_auth_defaults {
- my $domain=shift;
- return ($Apache::lonnet::domain_auth_def{$domain},$Apache::lonnet::domain_auth_arg_def{$domain});
+sub get_assignable_auth {
+ my ($dom) = @_;
+ if ($dom eq '') {
+ $dom = $env{'request.role.domain'};
+ }
+ my %can_assign = (
+ krb4 => 1,
+ krb5 => 1,
+ int => 1,
+ loc => 1,
+ );
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
+ if (ref($domconfig{'usercreation'}) eq 'HASH') {
+ if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
+ my $authhash = $domconfig{'usercreation'}{'authtypes'};
+ my $context;
+ if ($env{'request.role'} =~ /^au/) {
+ $context = 'author';
+ } elsif ($env{'request.role'} =~ /^dc/) {
+ $context = 'domain';
+ } elsif ($env{'request.course.id'}) {
+ $context = 'course';
+ }
+ if ($context) {
+ if (ref($authhash->{$context}) eq 'HASH') {
+ %can_assign = %{$authhash->{$context}};
+ }
+ }
+ }
+ }
+ my $authnum = 0;
+ foreach my $key (keys(%can_assign)) {
+ if ($can_assign{$key}) {
+ $authnum ++;
+ }
+ }
+ if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
+ $authnum --;
+ }
+ return ($authnum,%can_assign);
}
-###############################################################
-## End Get Authentication Defaults for Domain ##
-###############################################################
###############################################################
## Get Kerberos Defaults for Domain ##
@@ -1928,22 +2466,31 @@ sub get_auth_defaults {
=pod
-=item * get_kerberos_defaults
+=item * &get_kerberos_defaults()
get_kerberos_defaults($target_domain) returns the default kerberos
-version and domain. If not found in domain.tabs, it defaults to
-version 4 and the domain of the server.
+version and domain. If not found, it defaults to version 4 and the
+domain of the server.
+
+=over 4
($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
+=back
+
+=back
+
=cut
#-------------------------------------------
sub get_kerberos_defaults {
my $domain=shift;
- my ($krbdef,$krbdefdom) =
- &Apache::loncommon::get_auth_defaults($domain);
- unless ($krbdef =~/^krb/ && $krbdefdom) {
+ my ($krbdef,$krbdefdom);
+ my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
+ if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
+ $krbdef = $domdefaults{'auth_def'};
+ $krbdefdom = $domdefaults{'auth_arg_def'};
+ } else {
$ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
my $krbdefdom=$1;
$krbdefdom=~tr/a-z/A-Z/;
@@ -1952,11 +2499,6 @@ sub get_kerberos_defaults {
return ($krbdef,$krbdefdom);
}
-=pod
-
-=back
-
-=cut
###############################################################
## Thesaurus Functions ##
@@ -1968,7 +2510,7 @@ sub get_kerberos_defaults {
=over 4
-=item * initialize_keywords
+=item * &initialize_keywords()
Initializes the package variable %Keywords if it is empty. Uses the
package variable $thesaurus_db_file.
@@ -2005,7 +2547,7 @@ sub initialize_keywords {
# Remove special values from %Keywords.
foreach my $value ('total.count','average.count') {
delete($Keywords{$value}) if (exists($Keywords{$value}));
- }
+ }
return 1;
}
@@ -2013,7 +2555,7 @@ sub initialize_keywords {
=pod
-=item * keyword($word)
+=item * &keyword($word)
Returns true if $word is a keyword. A keyword is a word that appears more
than the average number of times in the thesaurus database. Calls
@@ -2034,7 +2576,7 @@ sub keyword {
=pod
-=item * get_related_words
+=item * &get_related_words()
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
@@ -2092,7 +2634,7 @@ sub get_related_words {
=over 4
-=item * plainname($uname,$udom,$first)
+=item * &plainname($uname,$udom,$first)
Takes a users logon name and returns it as a string in
"first middle last generation" form
@@ -2105,6 +2647,7 @@ if $first is set to 'lastname' then it r
###############################################################
sub plainname {
my ($uname,$udom,$first)=@_;
+ return if (!defined($uname) || !defined($udom));
my %names=&getnames($uname,$udom);
my $name=&Apache::lonnet::format_name($names{'firstname'},
$names{'middlename'},
@@ -2120,7 +2663,7 @@ sub plainname {
# -------------------------------------------------------------------- Nickname
=pod
-=item * nickname($uname,$udom)
+=item * &nickname($uname,$udom)
Gets a users name and returns it as a string as
@@ -2136,6 +2679,7 @@ if the user does not
sub nickname {
my ($uname,$udom)=@_;
+ return if (!defined($uname) || !defined($udom));
my %names=&getnames($uname,$udom);
my $name=$names{'nickname'};
if ($name) {
@@ -2151,6 +2695,7 @@ sub nickname {
sub getnames {
my ($uname,$udom)=@_;
+ return if (!defined($uname) || !defined($udom));
if ($udom eq 'public' && $uname eq 'public') {
return ('lastname' => &mt('Public'));
}
@@ -2167,6 +2712,22 @@ sub getnames {
}
}
+# -------------------------------------------------------------------- getemails
+
+=pod
+
+=item * &getemails($uname,$udom)
+
+Gets a user's email information and returns it as a hash with keys:
+notification, critnotification, permanentemail
+
+For notification and critnotification, values are comma-separated lists
+of e-mail addresses; for permanentemail, value is a single e-mail address.
+
+
+=cut
+
+
sub getemails {
my ($uname,$udom)=@_;
if ($udom eq 'public' && $uname eq 'public') {
@@ -2188,11 +2749,57 @@ sub getemails {
}
}
+sub flush_email_cache {
+ my ($uname,$udom)=@_;
+ if (!$udom) { $udom =$env{'user.domain'}; }
+ if (!$uname) { $uname=$env{'user.name'}; }
+ return if ($udom eq 'public' && $uname eq 'public');
+ my $id=$uname.':'.$udom;
+ &Apache::lonnet::devalidate_cache_new('emailscache',$id);
+}
+
+# -------------------------------------------------------------------- getlangs
+
+=pod
+
+=item * &getlangs($uname,$udom)
+
+Gets a user's language preference and returns it as a hash with key:
+language.
+
+=cut
+
+
+sub getlangs {
+ my ($uname,$udom) = @_;
+ if (!$udom) { $udom =$env{'user.domain'}; }
+ if (!$uname) { $uname=$env{'user.name'}; }
+ my $id=$uname.':'.$udom;
+ my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
+ if ($cached) {
+ return %{$langs};
+ } else {
+ my %loadlangs=&Apache::lonnet::get('environment',['languages'],
+ $udom,$uname);
+ &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
+ return %loadlangs;
+ }
+}
+
+sub flush_langs_cache {
+ my ($uname,$udom)=@_;
+ if (!$udom) { $udom =$env{'user.domain'}; }
+ if (!$uname) { $uname=$env{'user.name'}; }
+ return if ($udom eq 'public' && $uname eq 'public');
+ my $id=$uname.':'.$udom;
+ &Apache::lonnet::devalidate_cache_new('userlangs',$id);
+}
+
# ------------------------------------------------------------------ Screenname
=pod
-=item * screenname($uname,$udom)
+=item * &screenname($uname,$udom)
Gets a users screenname and returns it as a string
@@ -2207,6 +2814,26 @@ sub screenname {
}
+# ------------------------------------------------------------- Confirm Wrapper
+=pod
+
+=item confirmwrapper
+
+Wrap messages about completion of operation in box
+
+=cut
+
+sub confirmwrapper {
+ my ($message)=@_;
+ if ($message) {
+ return "\n".'
';
foreach my $key (sort(keys(%lasthash))) {
my ($ign,@parts) = split(/\./,$key);
if ($#parts > 0) {
my $data=$parts[-1];
pop(@parts);
- $prevattempts.='
Part '.join('.',@parts).' '.$data.'
';
+ $prevattempts.='
'.&mt('Part ').join('.',@parts).' '.$data.'
';
} else {
if ($#parts == 0) {
$prevattempts.='
'.$parts[0].'
';
@@ -2577,41 +3245,53 @@ sub get_previous_attempt {
}
}
}
+ $prevattempts.=&end_data_table_header_row();
if ($getattempt eq '') {
for ($version=1;$version<=$returnhash{'version'};$version++) {
- $prevattempts.='
Transaction '.$version.'
';
+ $prevattempts.=&start_data_table_row().
+ '
'.&mt('Transaction [_1]',$version).'
';
foreach my $key (sort(keys(%lasthash))) {
- my $value;
- if ($key =~ /timestamp/) {
- $value=scalar(localtime($returnhash{$version.':'.$key}));
- } else {
- $value=$returnhash{$version.':'.$key};
- }
- $prevattempts.='
'.&unescape($value).'
';
+ my $value = &format_previous_attempt_value($key,
+ $returnhash{$version.':'.$key});
+ $prevattempts.='