--- loncom/interface/loncommon.pm 2003/10/29 16:20:14 1.139
+++ loncom/interface/loncommon.pm 2012/04/08 22:34:57 1.1067
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.139 2003/10/29 16:20:14 matthew Exp $
+# $Id: loncommon.pm,v 1.1067 2012/04/08 22:34:57 raeburn 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
@@ -62,79 +55,126 @@ redundancy from other modules and increa
package Apache::loncommon;
use strict;
-use Apache::lonnet();
+use Apache::lonnet;
use GDBM_File;
use POSIX qw(strftime mktime);
-use Apache::Constants qw(:common :http :methods);
-use Apache::lonmsg();
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;
-=pod
-=head1 Global Variables
+##
+## Global Variables
+##
-=cut
-# ----------------------------------------------- Filetypes/Languages/Copyright
-my %language;
-my %supported_language;
-my %cprtag;
-my %fe; my %fd;
-my %category_extensions;
+# ----------------------------------------------- SSI with retries:
+#
-# ---------------------------------------------- Designs
+=pod
-my %designhash;
+=head1 Server Side include with retries:
-# ---------------------------------------------- Thesaurus variables
+=over 4
-# FIXME: I don't think it's necessary to document these things;
-# they're privately used - Jeremy
+=item * &ssi_with_retries(resource,retries form)
-=pod
+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
-=item * %Keywords
+resource - Identifies the resource to insert.
+
+retries - Count of the number of retries allowed.
+
+form - Hash that identifies the rendering options.
+
+=back
+
+Returns:
-A hash used by &keyword to determine if a word is considered a keyword.
+=over 4
+
+content - The content of the response. If retries were exhausted this is empty.
-=item * $thesaurus_db_file
+response - The response from the last attempt (which may or may not have been successful.
-Scalar containing the full path to the thesaurus database.
+=back
=back
=cut
-my %Keywords;
-my $thesaurus_db_file;
+sub ssi_with_retries {
+ my ($resource, $retries, %form) = @_;
-# ----------------------------------------------------------------------- BEGIN
-# FIXME: I don't think this needs to be documented, it prepares
-# private data structures - Jeremy
-=pod
+ my $ok = 0; # True if we got a good response.
+ my $content;
+ my $response;
-=head1 General Subroutines
+ # Try to get the ssi done. within the retries count:
-=over 4
+ 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);
-=item * BEGIN()
+}
-Initialize values from language.tab, copyright.tab, filetypes.tab,
-thesaurus.tab, and filecategories.tab.
-=back
-=cut
+# ----------------------------------------------- Filetypes/Languages/Copyright
+my %language;
+my %supported_language;
+my %latex_language; # For choosing hyphenation in
+my %latex_language_bykey; # for choosing hyphenation from metadata
+my %cprtag;
+my %scprtag;
+my %fe; my %fd; my %fm;
+my %category_extensions;
-# ----------------------------------------------------------------------- BEGIN
+# ---------------------------------------------- Thesaurus variables
+#
+# %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;
+
+#
+# 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";
@@ -142,88 +182,102 @@ 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 (my $line = <$fh>) {
+ next if ($line=~/^\#/);
+ chomp($line);
+ my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
+ $language{$key}=$val.' - '.$enc;
+ if ($sup) {
+ $supported_language{$key}=$sup;
+ }
+ if ($latex) {
+ $latex_language_bykey{$key} = $latex;
+ $latex_language{$two} = $latex;
}
- }
- }
+ }
+ 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 (my $line = <$fh>) {
+ next if ($line=~/^\#/);
+ chomp($line);
+ my ($key,$val)=(split(/\s+/,$line,2));
+ $cprtag{$key}=$val;
+ }
+ close($fh);
+ }
}
-
-# -------------------------------------------------------------- domain designs
-
- my $filename;
- my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
- opendir(DIR,$designdir);
- while ($filename=readdir(DIR)) {
- my ($domain)=($filename=~/^(\w+)\./);
+# ----------------------------------------------------------- source copyrights
{
- 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 $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
+ '/source_copyright.tab';
+ if ( open (my $fh,"<$sourcecopyrightfile") ) {
+ while (my $line = <$fh>) {
+ next if ($line =~ /^\#/);
+ chomp($line);
+ my ($key,$val)=(split(/\s+/,$line,2));
+ $scprtag{$key}=$val;
+ }
+ close($fh);
+ }
}
+# -------------------------------------------------------------- default domain designs
+ my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
+ 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
{
- 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 (my $line = <$fh>) {
+ next if ($line =~ /^\#/);
+ chomp($line);
+ my ($extension,$category)=(split(/\s+/,$line,2));
+ push @{$category_extensions{lc($category)}},$extension;
+ }
+ close($fh);
+ }
+
}
# ------------------------------------------------------------------ file types
{
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
- '/filetypes.tab');
- if ($fh) {
- while (<$fh>) {
- next if (/^\#/);
- chomp;
- my ($ending,$emb,$descr)=split(/\s+/,$_,3);
- if ($descr ne '') {
- $fe{$ending}=lc($emb);
- $fd{$ending}=$descr;
- }
- }
- }
+ my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
+ '/filetypes.tab';
+ if ( open (my $fh,"<$typesfile") ) {
+ while (my $line = <$fh>) {
+ next if ($line =~ /^\#/);
+ chomp($line);
+ my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
+ if ($descr ne '') {
+ $fe{$ending}=lc($emb);
+ $fd{$ending}=$descr;
+ if ($mime ne 'unk') { $fm{$ending}=$mime; }
+ }
+ }
+ close($fh);
+ }
}
&Apache::lonnet::logthis(
- "INFO: Read file types ");
+ "INFO: Read file types ");
$readit=1;
} # end of unless($readit)
@@ -239,16 +293,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.
-=over 4
-
-=item * openbrowser(formname,elementname,only,omit) [javascript]
+=item * &openbrowser(formname,elementname,only,omit) [javascript]
inputs: formname, elementname, only, omit
@@ -256,45 +308,54 @@ formname and elementname indicate the na
the element that the results of the browsing selection are to be placed in.
Specifying 'only' will restrict the browser to displaying only files
-with the given extension. Can be a comma seperated list.
+with the given extension. Can be a comma separated list.
Specifying 'omit' will restrict the browser to NOT displaying files
-with the given extension. Can be a comma seperated list.
+with the given extension. Can be a comma separated list.
-=item * opensearcher(formname, elementname) [javascript]
+=item * &opensearcher(formname,elementname) [javascript]
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 {
+ my ($mode)=@_;
+ if (!defined($mode)) { $mode='edit'; }
+ my $resurl=&escape_single(&lastresurl());
return <
END
}
+sub lastresurl {
+ if ($env{'environment.lastresurl'}) {
+ return $env{'environment.lastresurl'}
+ } else {
+ return '/res';
+ }
+}
+
+sub storeresurl {
+ my $resurl=&Apache::lonnet::clutter(shift);
+ unless ($resurl=~/^\/res/) { return 0; }
+ $resurl=~s/\/$//;
+ &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
+ &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
+ return 1;
+}
+
sub studentbrowser_javascript {
unless (
- (($ENV{'request.course.id'}) &&
- (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})))
- || ($ENV{'request.role'}=~/^(au|dc|su)/)
+ (($env{'request.course.id'}) &&
+ (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
+ || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ '/'.$env{'request.course.sec'})
+ ))
+ || ($env{'request.role'}=~/^(au|dc|su)/)
) { return ''; }
return (<<'ENDSTDBRW');
-
ENDSTDBRW
}
+sub resourcebrowser_javascript {
+ unless ($env{'request.course.id'}) { return ''; }
+ return (<<'ENDRESBRW');
+
+ENDRESBRW
+}
+
sub selectstudent_link {
- my ($form,$unameele,$udomele)=@_;
- if ($ENV{'request.course.id'}) {
- unless (&Apache::lonnet::allowed('srm',$ENV{'request.course.id'})) {
+ my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
+ my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
+ &Apache::lonhtmlcommon::entity_encode($unameele)."','".
+ &Apache::lonhtmlcommon::entity_encode($udomele)."'";
+ if ($env{'request.course.id'}) {
+ if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
+ && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
+ '/'.$env{'request.course.sec'})) {
return '';
}
- return "".&mt('Select User')." ";
+ $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
+ if ($courseadvonly) {
+ $callargs .= ",'',1,1";
+ }
+ return ''.
+ ''.
+ &mt('Select User').' ';
}
- if ($ENV{'request.role'}=~/^(au|dc|su)/) {
- return "".&mt('Select User')." ";
+ if ($env{'request.role'}=~/^(au|dc|su)/) {
+ $callargs .= ",'',1";
+ return ''.
+ ''.
+ &mt('Select User').' ';
}
return '';
}
+sub selectresource_link {
+ my ($form,$reslink,$arg)=@_;
+
+ my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
+ &Apache::lonhtmlcommon::entity_encode($reslink)."'";
+ unless ($env{'request.course.id'}) { return $arg; }
+ return ''.
+ ''.
+ $arg.' ';
+}
+
+
+
+sub authorbrowser_javascript {
+ return <<"ENDAUTHORBRW";
+
+ENDAUTHORBRW
+}
+
sub coursebrowser_javascript {
- my ($domainfilter)=@_;
- return (<
- var stdeditbrowser;
- function opencrsbrowser(formname,uname,udom) {
+ my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
+ my $wintitle = 'Course_Browser';
+ if ($crstype eq 'Community') {
+ $wintitle = 'Community_Browser';
+ }
+ my $id_functions = &javascript_index_functions();
+ my $output = '
+
+$id_functions
ENDSTDBRW
+ if (($sec_element ne '') || ($role_element ne '')) {
+ $output .= &setsec_javascript($sec_element,$formname,$role_element);
+ }
+ $output .= '
+// ]]>
+';
+ return $output;
+}
+
+sub javascript_index_functions {
+ return <<"ENDJS";
+
+function getFormIdByName(formname) {
+ for (var i=0;i -1) {
+ var domid = getIndexByName(formid,udom);
+ if (domid > -1) {
+ if (document.forms[formid].elements[domid].type == 'select-one') {
+ userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
+ }
+ if (document.forms[formid].elements[domid].type == 'hidden') {
+ userdom=document.forms[formid].elements[domid].value;
+ }
+ }
+ }
+ return userdom;
+}
+
+ENDJS
+
+}
+
+sub javascript_array_indexof {
+ return <
+// >> 0;
+ if (len === 0) {
+ return -1;
+ }
+ var n = 0;
+ if (arguments.length > 0) {
+ n = Number(arguments[1]);
+ if (n !== n) { // shortcut for verifying if it's NaN
+ n = 0;
+ } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
+ }
+ }
+ if (n >= len) {
+ return -1;
+ }
+ var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
+ for (; k < len; k++) {
+ if (k in t && t[k] === searchElement) {
+ return k;
+ }
+ }
+ return -1;
+ }
+}
+
+// ]]>
+
+
+ENDJS
+
+}
+
+sub userbrowser_javascript {
+ my $id_functions = &javascript_index_functions();
+ return <<"ENDUSERBRW";
+
+function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
+ var url = '/adm/pickuser?';
+ var userdom = getDomainFromSelectbox(formname,udom);
+ if (userdom != null) {
+ if (userdom != '') {
+ url += 'srchdom='+userdom+'&';
+ }
+ }
+ url += 'form=' + formname + '&unameelement='+uname+
+ '&udomelement='+udom+
+ '&ulastelement='+ulast+
+ '&ufirstelement='+ufirst+
+ '&uemailelement='+uemail+
+ '&hideudomelement='+hideudom+
+ '&coursedom='+crsdom;
+ if ((caller != null) && (caller != undefined)) {
+ url += '&caller='+caller;
+ }
+ var title = 'User_Browser';
+ var options = 'scrollbars=1,resizable=1,menubar=0';
+ options += ',width=700,height=600';
+ var stdeditbrowser = open(url,title,options,'1');
+ stdeditbrowser.focus();
+}
+
+function fix_domain (formname,udom,origdom,uname) {
+ var formid = getFormIdByName(formname);
+ if (formid > -1) {
+ var unameid = getIndexByName(formid,uname);
+ var domid = getIndexByName(formid,udom);
+ var hidedomid = getIndexByName(formid,origdom);
+ if (hidedomid > -1) {
+ var fixeddom = document.forms[formid].elements[hidedomid].value;
+ var unameval = document.forms[formid].elements[unameid].value;
+ if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
+ if (domid > -1) {
+ var slct = document.forms[formid].elements[domid];
+ if (slct.type == 'select-one') {
+ var i;
+ for (i=0;i".&mt('Select Course')."";
+ my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
+ $typeelement) = @_;
+ my $type = $selecttype;
+ my $linktext = &mt('Select Course');
+ if ($selecttype eq 'Community') {
+ $linktext = &mt('Select Community');
+ } elsif ($selecttype eq 'Course/Community') {
+ $linktext = &mt('Select Course/Community');
+ $type = '';
+ } elsif ($selecttype eq 'Select') {
+ $linktext = &mt('Select');
+ $type = '';
+ }
+ return ''
+ ."".$linktext.' '
+ .' ';
+}
+
+sub selectauthor_link {
+ my ($form,$udom)=@_;
+ return ''.
+ &mt('Select Author').' ';
+}
+
+sub selectuser_link {
+ my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
+ $coursedom,$linktext,$caller) = @_;
+ return ''.$linktext.' ';
+}
+
+sub check_uncheck_jscript {
+ my $jscript = <<"ENDSCRT";
+function checkAll(field) {
+ if (field.length > 0) {
+ for (i = 0; i < field.length; i++) {
+ field[i].checked = true ;
+ }
+ } else {
+ field.checked = true
+ }
+}
+
+function uncheckAll(field) {
+ if (field.length > 0) {
+ for (i = 0; i < field.length; i++) {
+ field[i].checked = false ;
+ }
+ } else {
+ field.checked = false ;
+ }
+}
+ENDSCRT
+ return $jscript;
+}
+
+sub select_timezone {
+ my ($name,$selected,$onchange,$includeempty)=@_;
+ my $output=''."\n";
+ if ($includeempty) {
+ $output .= 'all_names;
+ foreach my $tzone (@timezones) {
+ $output.= ' $tzone \n";
+ }
+ $output.=" ";
+ return $output;
+}
+
+sub select_datelocale {
+ my ($name,$selected,$onchange,$includeempty)=@_;
+ my $output=''."\n";
+ if ($includeempty) {
+ $output .= '{'id'};
+ if ($id ne '') {
+ my $en_terr = $locale->{'en_territory'};
+ my $native_terr = $locale->{'native_territory'};
+ my @languages = &Apache::lonlocal::preferred_languages();
+ if (grep(/^en$/,@languages) || !@languages) {
+ if ($en_terr ne '') {
+ $locale_names{$id} = '('.$en_terr.')';
+ } elsif ($native_terr ne '') {
+ $locale_names{$id} = $native_terr;
+ }
+ } else {
+ if ($native_terr ne '') {
+ $locale_names{$id} = $native_terr.' ';
+ } elsif ($en_terr ne '') {
+ $locale_names{$id} = '('.$en_terr.')';
+ }
+ }
+ push (@possibles,$id);
+ }
+ }
+ }
+ foreach my $item (sort(@possibles)) {
+ $output.= ' $item";
+ if ($locale_names{$item} ne '') {
+ $output.=" $locale_names{$item} \n";
+ }
+ $output.="\n";
+ }
+ $output.=" ";
+ return $output;
+}
+
+sub select_language {
+ my ($name,$selected,$includeempty) = @_;
+ my %langchoices;
+ if ($includeempty) {
+ %langchoices = ('' => 'No language preference');
+ }
+ foreach my $id (&languageids()) {
+ my $code = &supportedlanguagecode($id);
+ if ($code) {
+ $langchoices{$code} = &plainlanguagedescription($id);
+ }
+ }
+ return &select_form($selected,$name,\%langchoices);
}
=pod
-=item * linked_select_forms(...)
+=item * &linked_select_forms(...)
linked_select_forms returns a string containing a block
and html for two menus. The select menus will be linked in that
changing the value of the first menu will result in new values being placed
in the second menu. The values in the select menu will appear in alphabetical
-order.
+order unless a defined order is provided.
linked_select_forms takes the following ordered inputs:
@@ -431,6 +1019,8 @@ linked_select_forms takes the following
=item * $hashref, a reference to a hash containing the data for the menus.
+=item * $menuorder, the order of values in the first menu
+
=back
Below is an example of such a hash. Only the 'text', 'default', and
@@ -447,7 +1037,8 @@ $menu{$choice1}->{'select2'}.
B2 => "Choice B2",
B3 => "Choice B3",
B4 => "Choice B4"
- }
+ },
+ order => ['B4','B3','B1','B2'],
},
A2 => { text =>"Choice A2" ,
default => "C2",
@@ -455,7 +1046,8 @@ $menu{$choice1}->{'select2'}.
C1 => "Choice C1",
C2 => "Choice C2",
C3 => "Choice C3"
- }
+ },
+ order => ['C2','C1','C3'],
},
A3 => { text =>"Choice A3" ,
default => "D6",
@@ -467,7 +1059,8 @@ $menu{$choice1}->{'select2'}.
D5 => "Choice D5",
D6 => "Choice D6",
D7 => "Choice D7"
- }
+ },
+ order => ['D4','D3','D2','D1','D7','D6','D5'],
}
);
@@ -479,13 +1072,15 @@ sub linked_select_forms {
$firstdefault,
$firstselectname,
$secondselectname,
- $hashref
+ $hashref,
+ $menuorder,
) = @_;
my $second = "document.$formname.$secondselectname";
my $first = "document.$formname.$firstselectname";
# output the javascript to do the changing
my $result = '';
- $result.="
END
# output the initial values for the selection lists
$result .= "\n";
- foreach my $value (sort(keys(%$hashref))) {
+ my @order = sort(keys(%{$hashref}));
+ if (ref($menuorder) eq 'ARRAY') {
+ @order = @{$menuorder};
+ }
+ foreach my $value (@order) {
$result.=" ".&mt($hashref->{$value}->{'text'})." \n";
}
$result .= " \n";
@@ -541,9 +1145,14 @@ END
$result .= $middletext;
$result .= "\n";
my $seconddefault = $hashref->{$firstdefault}->{'default'};
- foreach my $value (sort(keys(%select2))) {
+
+ my @secondorder = sort(keys(%select2));
+ if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
+ @secondorder = @{$hashref->{$firstdefault}->{'order'}};
+ }
+ foreach my $value (@secondorder) {
$result.=" ".&mt($select2{$value})." \n";
}
$result .= " \n";
@@ -553,7 +1162,7 @@ END
=pod
-=item * help_open_topic($topic, $text, $stayOnPage, $width, $height)
+=item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
Returns a string corresponding to an HTML link to the given help
$topic, where $topic corresponds to the name of a .tex file in
@@ -571,91 +1180,299 @@ a new window using Javascript. (Default
$width and $height are optional numerical parameters that will
override the width and height of the popped up window, which may
-be useful for certain help topics with big pictures included.
+be useful for certain help topics with big pictures included.
+
+$imgid is the id of the img tag used for the help icon. This may be
+used in a javascript call to switch the image src. See
+lonhtmlcommon::htmlareaselectactive() for an example.
=cut
sub help_open_topic {
- my ($topic, $text, $stayOnPage, $width, $height) = @_;
+ my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
$text = "" if (not defined $text);
$stayOnPage = 0 if (not defined $stayOnPage);
- if ($ENV{'browser.interface'} eq 'textual' ||
- $ENV{'environment.remote'} eq 'off' ) {
- $stayOnPage=1;
- }
- $width = 350 if (not defined $width);
+ $width = 500 if (not defined $width);
$height = 400 if (not defined $height);
my $filename = $topic;
$filename =~ s/ /_/g;
my $template = "";
my $link;
+
+ $topic=~s/\W/\_/g;
+
+ if (!$stayOnPage) {
+ $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
+ } elsif ($stayOnPage eq 'popup') {
+ $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
+ } else {
+ $link = "/adm/help/${filename}.hlp";
+ }
+
+ # Add the text
+ if ($text ne "") {
+ $template.=''
+ .''
+ .$text.' ';
+ }
+
+ # (Always) Add the graphic
+ my $title = &mt('Online Help');
+ my $helpicon=&lonhttpdurl("/adm/help/help.png");
+ if ($imgid ne '') {
+ $imgid = ' id="'.$imgid.'"';
+ }
+ $template.=' '
+ .' ';
+ if ($text ne "") {
+ $template.=' ';
+ }
+ return $template;
+
+}
+
+# This is a quicky function for Latex cheatsheet editing, since it
+# appears in at least four places
+sub helpLatexCheatsheet {
+ my ($topic,$text,$not_author,$stayOnPage) = @_;
+ my $out;
+ my $addOther = '';
+ if ($topic) {
+ $addOther = ''.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).' ';
+ }
+ $out = '' # Start cheatsheet
+ .$addOther
+ .''
+ .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
+ .' '
+ .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
+ .' ';
+ unless ($not_author) {
+ $out .= ' '
+ .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
+ .' ';
+ }
+ $out .= ' '; # End cheatsheet
+ return $out;
+}
+
+sub general_help {
+ my $helptopic='Student_Intro';
+ if ($env{'request.role'}=~/^(ca|au)/) {
+ $helptopic='Authoring_Intro';
+ } elsif ($env{'request.role'}=~/^(cc|co)/) {
+ $helptopic='Course_Coordination_Intro';
+ } elsif ($env{'request.role'}=~/^dc/) {
+ $helptopic='Domain_Coordination_Intro';
+ }
+ return $helptopic;
+}
+
+sub update_help_link {
+ my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
+ my $origurl = $ENV{'REQUEST_URI'};
+ $origurl=~s|^/~|/priv/|;
+ my $timestamp = time;
+ foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
+ $$datum = &escape($$datum);
+ }
+
+ my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
+ my $output .= <<"ENDOUTPUT";
+
+ENDOUTPUT
+ return $output;
+}
+
+# now just updates the help link and generates a blue icon
+sub help_open_menu {
+ my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
+ = @_;
+ $stayOnPage = 1;
+ my $output;
+ if ($component_help) {
+ if (!$text) {
+ $output=&help_open_topic($component_help,undef,$stayOnPage,
+ $width,$height);
+ } else {
+ my $help_text;
+ $help_text=&unescape($topic);
+ $output=''.
+ &help_open_topic($component_help,$help_text,$stayOnPage,
+ $width,$height).'
';
+ }
+ }
+ my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
+ return $output.$banner_link;
+}
+
+sub top_nav_help {
+ my ($text) = @_;
+ $text = &mt($text);
+ my $stay_on_page = 1;
+
+ my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
+ : "javascript:helpMenu('open')";
+ my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
+
+ my $title = &mt('Get help');
+
+ return <<"END";
+$banner_link
+ $text
+END
+}
+
+sub help_menu_js {
+ my ($text) = @_;
+ my $stayOnPage = 1;
+ my $width = 620;
+ my $height = 600;
+ my $helptopic=&general_help();
+ my $details_link = '/adm/help/'.$helptopic.'.hlp';
+ my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
+ my $start_page =
+ &Apache::loncommon::start_page('Help Menu', undef,
+ {'frameset' => 1,
+ 'js_ready' => 1,
+ 'add_entries' => {
+ 'border' => '0',
+ 'rows' => "110,*",},});
+ my $end_page =
+ &Apache::loncommon::end_page({'frameset' => 1,
+ 'js_ready' => 1,});
+
+ my $template .= <<"ENDTEMPLATE";
+
+ENDTEMPLATE
+ return $template;
+}
+
+sub help_open_bug {
+ my ($topic, $text, $stayOnPage, $width, $height) = @_;
+ unless ($env{'user.adv'}) { return ''; }
+ unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
+ $text = "" if (not defined $text);
+ $stayOnPage=1;
+ $width = 600 if (not defined $width);
+ $height = 600 if (not defined $height);
+ $topic=~s/\W+/\+/g;
+ my $link='';
+ my $template='';
+ my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
+ &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
if (!$stayOnPage)
{
- $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
+ $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
}
else
{
- $link = "/adm/help/${filename}.hlp";
+ $link = $url;
}
-
# Add the text
if ($text ne "")
{
$template .=
- "".
- "$text ";
+ "".
+ "$text ";
}
# Add the graphic
+ my $title = &mt('Report a Bug');
+ my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
$template .= <<"ENDTEMPLATE";
-
+
ENDTEMPLATE
if ($text ne '') { $template.='
' };
return $template;
}
-# This is a quicky function for Latex cheatsheet editing, since it
-# appears in at least four places
-sub helpLatexCheatsheet {
- my $other = shift;
- my $addOther = '';
- if ($other) {
- $addOther = Apache::loncommon::help_open_topic($other, shift,
- undef, undef, 600) .
- '';
- }
- return ''.
- $addOther .
- &Apache::loncommon::help_open_topic("Greek_Symbols",'Greek Symbols',
- undef,undef,600)
- .' '.
- &Apache::loncommon::help_open_topic("Other_Symbols",'Other Symbols',
- undef,undef,600)
- .'
';
-}
-
-=pod
+sub help_open_faq {
+ my ($topic, $text, $stayOnPage, $width, $height) = @_;
+ unless ($env{'user.adv'}) { return ''; }
+ unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
+ $text = "" if (not defined $text);
+ $stayOnPage=1;
+ $width = 350 if (not defined $width);
+ $height = 400 if (not defined $height);
-=item * csv_translate($text)
+ $topic=~s/\W+/\+/g;
+ my $link='';
+ my $template='';
+ my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
+ if (!$stayOnPage)
+ {
+ $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
+ }
+ else
+ {
+ $link = $url;
+ }
-Translate $text to allow it to be output as a 'comma seperated values'
-format.
+ # Add the text
+ if ($text ne "")
+ {
+ $template .=
+ "".
+ "$text ";
+ }
-=cut
+ # Add the graphic
+ my $title = &mt('View the FAQ');
+ my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
+ $template .= <<"ENDTEMPLATE";
+
+ENDTEMPLATE
+ if ($text ne '') { $template.='
' };
+ return $template;
-sub csv_translate {
- my $text = shift;
- $text =~ s/\"/\"\"/g;
- $text =~ s/\n//g;
- return $text;
}
+###############################################################
+###############################################################
+
=pod
-=item * change_content_javascript():
+=item * &change_content_javascript():
This and the next function allow you to create small sections of an
otherwise static HTML page that you can update on the fly with
@@ -685,8 +1502,8 @@ pretty much any HTML.
sub change_content_javascript {
# If we're on Netscape 4, we need to use Layer-based code
- if ($ENV{'browser.type'} eq 'netscape' &&
- $ENV{'browser.version'} =~ /^4\./) {
+ if ($env{'browser.type'} eq 'netscape' &&
+ $env{'browser.version'} =~ /^4\./) {
return (<. $name is
@@ -723,8 +1540,8 @@ the area will originally contain, which
sub changable_area {
my ($name, $origContent) = @_;
- if ($ENV{'browser.type'} eq 'netscape' &&
- $ENV{'browser.version'} =~ /^4\./) {
+ if ($env{'browser.type'} eq 'netscape' &&
+ $env{'browser.version'} =~ /^4\./) {
# If this is netscape 4, we need to use the Layer tag
return "$origContent ";
} else {
@@ -734,6 +1551,315 @@ sub changable_area {
=pod
+=item * &viewport_geometry_js
+
+Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
+
+=cut
+
+
+sub viewport_geometry_js {
+ return <<"GEOMETRY";
+var Geometry = {};
+function init_geometry() {
+ if (Geometry.init) { return };
+ Geometry.init=1;
+ if (window.innerHeight) {
+ Geometry.getViewportHeight = function() { return window.innerHeight; };
+ Geometry.getViewportWidth = function() { return window.innerWidth; };
+ Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
+ Geometry.getVerticalScroll = function() { return window.pageYOffset; };
+ }
+ else if (document.documentElement && document.documentElement.clientHeight) {
+ Geometry.getViewportHeight =
+ function() { return document.documentElement.clientHeight; };
+ Geometry.getViewportWidth =
+ function() { return document.documentElement.clientWidth; };
+
+ Geometry.getHorizontalScroll =
+ function() { return document.documentElement.scrollLeft; };
+ Geometry.getVerticalScroll =
+ function() { return document.documentElement.scrollTop; };
+ }
+ else if (document.body.clientHeight) {
+ Geometry.getViewportHeight =
+ function() { return document.body.clientHeight; };
+ Geometry.getViewportWidth =
+ function() { return document.body.clientWidth; };
+ Geometry.getHorizontalScroll =
+ function() { return document.body.scrollLeft; };
+ Geometry.getVerticalScroll =
+ function() { return document.body.scrollTop; };
+ }
+}
+
+GEOMETRY
+}
+
+=pod
+
+=item * &viewport_size_js()
+
+Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
+
+=cut
+
+sub viewport_size_js {
+ my $geometry = &viewport_geometry_js();
+ return <<"DIMS";
+
+$geometry
+
+function getViewportDims(width,height) {
+ init_geometry();
+ width.value = Geometry.getViewportWidth();
+ height.value = Geometry.getViewportHeight();
+ return;
+}
+
+DIMS
+}
+
+=pod
+
+=item * &resize_textarea_js()
+
+emits the needed javascript to resize a textarea to be as big as possible
+
+creates a function resize_textrea that takes two IDs first should be
+the id of the element to resize, second should be the id of a div that
+surrounds everything that comes after the textarea, this routine needs
+to be attached to the for the onload and onresize events.
+
+=back
+
+=cut
+
+sub resize_textarea_js {
+ my $geometry = &viewport_geometry_js();
+ return <<"RESIZE";
+
+RESIZE
+
+}
+
+=pod
+
+=head1 Excel and CSV file utility routines
+
+=over 4
+
+=cut
+
+###############################################################
+###############################################################
+
+=pod
+
+=item * &csv_translate($text)
+
+Translate $text to allow it to be output as a 'comma separated values'
+format.
+
+=cut
+
+###############################################################
+###############################################################
+sub csv_translate {
+ my $text = shift;
+ $text =~ s/\"/\"\"/g;
+ $text =~ s/\n/ /g;
+ return $text;
+}
+
+###############################################################
+###############################################################
+
+=pod
+
+=item * &define_excel_formats()
+
+Define some commonly used Excel cell formats.
+
+Currently supported formats:
+
+=over 4
+
+=item header
+
+=item bold
+
+=item h1
+
+=item h2
+
+=item h3
+
+=item h4
+
+=item i
+
+=item date
+
+=back
+
+Inputs: $workbook
+
+Returns: $format, a hash reference.
+
+
+=cut
+
+###############################################################
+###############################################################
+sub define_excel_formats {
+ my ($workbook) = @_;
+ my $format;
+ $format->{'header'} = $workbook->add_format(bold => 1,
+ bottom => 1,
+ align => 'center');
+ $format->{'bold'} = $workbook->add_format(bold=>1);
+ $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
+ $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
+ $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
+ $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
+ $format->{'i'} = $workbook->add_format(italic=>1);
+ $format->{'date'} = $workbook->add_format(num_format=>
+ 'mm/dd/yyyy hh:mm:ss');
+ return $format;
+}
+
+###############################################################
+###############################################################
+
+=pod
+
+=item * &create_workbook()
+
+Create an Excel worksheet. If it fails, output message on the
+request object and return undefs.
+
+Inputs: Apache request object
+
+Returns (undef) on failure,
+ Excel worksheet object, scalar with filename, and formats
+ from &Apache::loncommon::define_excel_formats on success
+
+=cut
+
+###############################################################
+###############################################################
+sub create_workbook {
+ my ($r) = @_;
+ #
+ # Create the excel spreadsheet
+ my $filename = '/prtspool/'.
+ $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
+ time.'_'.rand(1000000000).'.xls';
+ my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
+ if (! defined($workbook)) {
+ $r->log_error("Error creating excel spreadsheet $filename: $!");
+ $r->print(
+ ''
+ .&mt('Problems occurred in creating the new Excel file.')
+ .' '.&mt('This error has been logged.')
+ .' '.&mt('Please alert your LON-CAPA administrator.')
+ .'
'
+ );
+ return (undef);
+ }
+ #
+ $workbook->set_tempdir(LONCAPA::tempdir());
+ #
+ my $format = &Apache::loncommon::define_excel_formats($workbook);
+ return ($workbook,$filename,$format);
+}
+
+###############################################################
+###############################################################
+
+=pod
+
+=item * &create_text_file()
+
+Create a file to write to and eventually make available to the user.
+If file creation fails, outputs an error message on the request object and
+return undefs.
+
+Inputs: Apache request object, and file suffix
+
+Returns (undef) on failure,
+ Filehandle and filename on success.
+
+=cut
+
+###############################################################
+###############################################################
+sub create_text_file {
+ my ($r,$suffix) = @_;
+ if (! defined($suffix)) { $suffix = 'txt'; };
+ my $fh;
+ my $filename = '/prtspool/'.
+ $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
+ time.'_'.rand(1000000000).'.'.$suffix;
+ $fh = Apache::File->new('>/home/httpd'.$filename);
+ if (! defined($fh)) {
+ $r->log_error("Couldn't open $filename for output $!");
+ $r->print(
+ ''
+ .&mt('Problems occurred in creating the output file.')
+ .' '.&mt('This error has been logged.')
+ .' '.&mt('Please alert your LON-CAPA administrator.')
+ .'
'
+ );
+ }
+ return ($fh,$filename)
+}
+
+
+=pod
+
=back
=cut
@@ -742,67 +1868,176 @@ sub changable_area {
## Home server list generating code ##
###############################################################
+# ------------------------------------------
+
+sub domain_select {
+ my ($name,$value,$multiple)=@_;
+ my %domains=map {
+ $_ => $_.' '. &Apache::lonnet::domain($_,'description')
+ } &Apache::lonnet::all_domains();
+ if ($multiple) {
+ $domains{''}=&mt('Any domain');
+ $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
+ return &multiple_select_form($name,$value,4,\%domains);
+ } else {
+ $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
+ return &select_form($name,$value,\%domains);
+ }
+}
+
+#-------------------------------------------
+
=pod
-=head1 Home Server option list generating code
+=head1 Routines for form select boxes
=over 4
-=item * get_domains()
+=item * &multiple_select_form($name,$value,$size,$hash,$order)
-Returns an array containing each of the domains listed in the hosts.tab
-file.
+Returns a string containing a element int multiple mode
+
+
+Args:
+ $name - name of the element
+ $value - scalar or array ref of values that should already be selected
+ $size - number of rows long the select element is
+ $hash - the elements should be 'option' => 'shown text'
+ (shown text should already have been &mt())
+ $order - (optional) array ref of the order to show the elements in
=cut
#-------------------------------------------
-sub get_domains {
- # The code below was stolen from "The Perl Cookbook", p 102, 1st ed.
- my @domains;
- my %seen;
- foreach (sort values(%Apache::lonnet::hostdom)) {
- push (@domains,$_) unless $seen{$_}++;
+sub multiple_select_form {
+ my ($name,$value,$size,$hash,$order)=@_;
+ my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
+ my $output='';
+ if (! defined($size)) {
+ $size = 4;
+ if (scalar(keys(%$hash))<4) {
+ $size = scalar(keys(%$hash));
+ }
+ }
+ $output.="\n".'';
+ my @order;
+ if (ref($order) eq 'ARRAY') {
+ @order = @{$order};
+ } else {
+ @order = sort(keys(%$hash));
}
- return @domains;
+ if (exists($$hash{'select_form_order'})) {
+ @order = @{$$hash{'select_form_order'}};
+ }
+
+ foreach my $key (@order) {
+ $output.='&').'" ';
+ $output.='selected="selected" ' if ($selected{$key});
+ $output.='>'.$hash->{$key}." \n";
+ }
+ $output.=" \n";
+ return $output;
}
#-------------------------------------------
=pod
-=item * select_form($defdom,$name,%hash)
+=item * &select_form($defdom,$name,$hashref,$onchange)
Returns a string containing a form to
-allow a user to select options from a hash option_name => displayed text.
+allow a user to select options from a ref to a hash containing:
+option_name => displayed text. An optional $onchange can include
+a javascript onchange item, e.g., onchange="this.form.submit();"
+
See lonrights.pm for an example invocation and use.
=cut
#-------------------------------------------
sub select_form {
- my ($def,$name,%hash) = @_;
- my $selectform = "\n";
+ my ($def,$name,$hashref,$onchange) = @_;
+ return unless (ref($hashref) eq 'HASH');
+ if ($onchange) {
+ $onchange = ' onchange="'.$onchange.'"';
+ }
+ my $selectform = "\n";
my @keys;
- if (exists($hash{'select_form_order'})) {
- @keys=@{$hash{'select_form_order'}};
+ if (exists($hashref->{'select_form_order'})) {
+ @keys=@{$hashref->{'select_form_order'}};
} else {
- @keys=sort(keys(%hash));
+ @keys=sort(keys(%{$hashref}));
}
- foreach (@keys) {
- $selectform.="".&mt($hash{$_})." \n";
+ foreach my $key (@keys) {
+ $selectform.=
+ '&').'" '.
+ ($key eq $def ? 'selected="selected" ' : '').
+ ">".$hashref->{$key}." \n";
}
$selectform.=" ";
return $selectform;
}
+# For display filters
+
+sub display_filter {
+ if (!$env{'form.show'}) { $env{'form.show'}=10; }
+ if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
+ return ''.&mt('Records [_1]',
+ &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
+ (&mt('all'),10,20,50,100,1000,10000))).
+ ' '.
+ &mt('Filter [_1]',
+ &select_form($env{'form.displayfilter'},
+ 'displayfilter',
+ {'currentfolder' => 'Current folder/page',
+ 'containing' => 'Containing phrase',
+ 'none' => 'None'})).
+ ' ';
+}
+
+sub gradeleveldescription {
+ my $gradelevel=shift;
+ my %gradelevels=(0 => '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');
+ return &mt($gradelevels{$gradelevel});
+}
+
+sub select_level_form {
+ my ($deflevel,$name)=@_;
+ unless ($deflevel) { $deflevel=0; }
+ my $selectform = "\n";
+ for (my $i=0; $i<=18; $i++) {
+ $selectform.="".&gradeleveldescription($i)." \n";
+ }
+ $selectform.=" ";
+ return $selectform;
+}
#-------------------------------------------
=pod
-=item * select_dom_form($defdom,$name,$includeempty)
+=item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
Returns a string containing a form to
allow a user to select the domain to preform an operation in.
@@ -811,18 +2046,40 @@ See loncreateuser.pm for an example invo
If the $includeempty flag is set, it also includes an empty choice ("no domain
selected");
+If the $showdomdesc flag is set, the domain name is followed by the domain description.
+
+The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
+
+The optional $incdoms is a reference to an array of domains which will be the only available options.
+
=cut
#-------------------------------------------
sub select_dom_form {
- my ($defdom,$name,$includeempty) = @_;
- my @domains = get_domains();
+ my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
+ if ($onchange) {
+ $onchange = ' onchange="'.$onchange.'"';
+ }
+ my @domains;
+ if (ref($incdoms) eq 'ARRAY') {
+ @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
+ } else {
+ @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
+ }
if ($includeempty) { @domains=('',@domains); }
- my $selectdomain = "\n";
- foreach (@domains) {
- $selectdomain.="$_ \n";
+ my $selectdomain = "\n";
+ foreach my $dom (@domains) {
+ $selectdomain.="'.$dom;
+ if ($showdomdesc) {
+ if ($dom ne '') {
+ my $domdesc = &Apache::lonnet::domain($dom,'description');
+ if ($domdesc ne '') {
+ $selectdomain .= ' ('.$domdesc.')';
+ }
+ }
+ }
+ $selectdomain .= " \n";
}
$selectdomain.=" ";
return $selectdomain;
@@ -832,52 +2089,73 @@ sub select_dom_form {
=pod
-=item * get_library_servers($domain)
-
-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.
+=item * &home_server_form_item($domain,$name,$defaultflag)
-=cut
+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)
+ $hostid $servers{$hostid}
+ $hostid $servers{$hostid}
+
+ form item if there are multiple library servers in $domain, or
+ (ii) an form item
+ if there is only one library server in $domain.
-#-------------------------------------------
-sub get_library_servers {
- my $domain = shift;
- my %library_servers;
- foreach (keys(%Apache::lonnet::libserv)) {
- if ($Apache::lonnet::hostdom{$_} eq $domain) {
- $library_servers{$_} = $Apache::lonnet::hostname{$_};
- }
- }
- return %library_servers;
-}
+(b) number of library servers found.
-#-------------------------------------------
-
-=pod
-
-=item * home_server_option_list($domain)
-
-returns a string which contains an list to be used in a
- form input. See loncreateuser.pm for an example.
+See loncreateuser.pm for example of use.
=cut
#-------------------------------------------
-sub home_server_option_list {
- my $domain = shift;
- my %servers = &get_library_servers($domain);
- my $result = '';
- foreach (sort keys(%servers)) {
- $result.=
- ''.$_.' '.$servers{$_}." \n";
+sub home_server_form_item {
+ my ($domain,$name,$default,$hide) = @_;
+ my %servers = &Apache::lonnet::get_servers($domain,'library');
+ my $result;
+ my $numlib = keys(%servers);
+ if ($numlib > 1) {
+ $result .= ' '."\n";
+ if ($default) {
+ $result .= ''.&mt('default').
+ ' '."\n";
+ }
+ foreach my $hostid (sort(keys(%servers))) {
+ $result.= ''.
+ $hostid.' '.$servers{$hostid}." \n";
+ }
+ $result .= ' '."\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
@@ -913,14 +2191,18 @@ Outputs:
=back
+=back
+
=cut
###############################################################
###############################################################
sub decode_user_agent {
+ my ($r)=@_;
my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
+ if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
my $clientbrowser='unknown';
my $clientversion='0';
my $clientmathml='';
@@ -951,12 +2233,6 @@ sub decode_user_agent {
$clientunicode,$clientos,);
}
-=pod
-
-=back
-
-=cut
-
###############################################################
## Authentication changing form generation subroutines ##
###############################################################
@@ -973,14 +2249,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
@@ -997,6 +2271,8 @@ See loncreateuser.pm for invocation and
=back
+See loncreateuser.pm for invocation and use examples.
+
=cut
#-------------------------------------------
@@ -1024,10 +2300,27 @@ END
$Javascript_toUpperCase = "";
}
+ my $radioval = "'nochange'";
+ if (defined($in{'curr_authtype'})) {
+ if ($in{'curr_authtype'} ne '') {
+ $radioval = "'".$in{'curr_authtype'}."arg'";
+ }
+ }
+ my $argfield = 'null';
+ if (defined($in{'mode'})) {
+ if ($in{'mode'} eq 'modifycourse') {
+ if (defined($in{'curr_autharg'})) {
+ if ($in{'curr_autharg'} ne '') {
+ $argfield = "'$in{'curr_autharg'}'";
+ }
+ }
+ }
+ }
+
$result.=<<"END";
var current = new Object();
-current.radiovalue = 'nochange';
-current.argfield = null;
+current.radiovalue = $radioval;
+current.argfield = $argfield;
function changed_radio(choice,currentform) {
var choicearg = choice + 'arg';
@@ -1069,12 +2362,16 @@ function changed_text(choice,currentform
}
function set_auth_radio_buttons(newvalue,currentform) {
+ var numauthchoices = currentform.login.length;
+ if (typeof numauthchoices == "undefined") {
+ return;
+ }
var i=0;
- while (i < currentform.login.length) {
+ while (i < numauthchoices) {
if (currentform.login[i].value == newvalue) { break; }
i++;
}
- if (i == currentform.login.length) {
+ if (i == numauthchoices) {
return;
}
current.radiovalue = newvalue;
@@ -1087,10 +2384,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;
}
@@ -1100,58 +2397,181 @@ sub authform_nochange{
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $result='';
- $result.=<<"END";
-
-Do not change login data
-END
+ my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
+ my $result;
+ if (keys(%can_assign) == 0) {
+ $result = &mt('Under you current role you are not permitted to change login settings for this user');
+ } else {
+ $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 $result='';
- my $check4;
- my $check5;
+ 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'};
+ 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 = ' ';
+ }
+ }
+ 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,
+ ' ',
+ ' ',
+ ' ');
}
- $result.=<<"END";
-
-Kerberos authenticated with domain
-
- Version 4
- Version 5
-END
return $result;
}
sub authform_internal{
- my %args = (
+ my %in = (
formname => 'document.cu',
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $result='';
- $result.=<<"END";
-
-Internally authenticated (with initial password
- )
-END
+ 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 = ' ';
+ }
+ }
+ 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;
}
@@ -1161,15 +2581,51 @@ sub authform_local{
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $result='';
- $result.=<<"END";
-
-Local Authentication with argument
-
-END
+ 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') {
+ 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 = ' ';
+ }
+ }
+ 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;
}
@@ -1179,57 +2635,96 @@ sub authform_filesystem{
kerb_def_dom => 'MSU.EDU',
@_,
);
- my $result='';
- $result.=<<"END";
-
-Filesystem authenticated (with initial password
- )
-END
+ 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;
}
-=pod
-
-=back
-
-=cut
-
-###############################################################
-## 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 ##
@@ -1243,22 +2738,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/;
@@ -1267,11 +2771,6 @@ sub get_kerberos_defaults {
return ($krbdef,$krbdefdom);
}
-=pod
-
-=back
-
-=cut
###############################################################
## Thesaurus Functions ##
@@ -1283,7 +2782,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.
@@ -1318,9 +2817,9 @@ sub initialize_keywords {
}
untie %thesaurus_db;
# Remove special values from %Keywords.
- foreach ('total.count','average.count') {
- delete($Keywords{$_}) if (exists($Keywords{$_}));
- }
+ foreach my $value ('total.count','average.count') {
+ delete($Keywords{$value}) if (exists($Keywords{$value}));
+ }
return 1;
}
@@ -1328,7 +2827,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
@@ -1349,15 +2848,16 @@ sub keyword {
=pod
-=item * get_related_words
+=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.
Uses global $thesaurus_db_file.
+
=cut
###############################################################
@@ -1374,12 +2874,20 @@ sub get_related_words {
return ();
}
my @Words=();
+ my $count=0;
if (exists($thesaurus_db{$keyword})) {
- $_ = $thesaurus_db{$keyword};
- (undef,@Words) = split/:/; # The first element is the number of times
- # the word appears. We do not need it now.
- for (my $i=0;$i<=$#Words;$i++) {
- ($Words[$i],undef)= split/\,/,$Words[$i];
+ # The first element is the number of times
+ # the word appears. We do not need it now.
+ my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
+ my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
+ my $threshold=$mostfrequentcount/10;
+ foreach my $possibleword (@RelatedWords) {
+ my ($word,$wordcount)=split(/\,/,$possibleword);
+ if ($wordcount>$threshold) {
+ push(@Words,$word);
+ $count++;
+ if ($count>10) { last; }
+ }
}
}
untie %thesaurus_db;
@@ -1399,30 +2907,36 @@ sub get_related_words {
=over 4
-=item * plainname($uname,$udom)
+=item * &plainname($uname,$udom,$first)
Takes a users logon name and returns it as a string in
-"first middle last generation" form
+"first middle last generation" form
+if $first is set to 'lastname' then it returns it as
+'lastname generation, firstname middlename' if their is a lastname
=cut
+
###############################################################
sub plainname {
- my ($uname,$udom)=@_;
- my %names=&Apache::lonnet::get('environment',
- ['firstname','middlename','lastname','generation'],
- $udom,$uname);
- my $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
- $names{'lastname'}.' '.$names{'generation'};
+ 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'},
+ $names{'lastname'},
+ $names{'generation'},$first);
+ $name=~s/^\s+//;
$name=~s/\s+$//;
$name=~s/\s+/ /g;
+ if ($name !~ /\S/) { $name=$uname.':'.$udom; }
return $name;
}
# -------------------------------------------------------------------- Nickname
=pod
-=item * nickname($uname,$udom)
+=item * &nickname($uname,$udom)
Gets a users name and returns it as a string as
@@ -1438,8 +2952,8 @@ if the user does not
sub nickname {
my ($uname,$udom)=@_;
- my %names=&Apache::lonnet::get('environment',
- ['nickname','firstname','middlename','lastname','generation'],$udom,$uname);
+ return if (!defined($uname) || !defined($udom));
+ my %names=&getnames($uname,$udom);
my $name=$names{'nickname'};
if ($name) {
$name='"'.$name.'"';
@@ -1452,12 +2966,113 @@ sub nickname {
return $name;
}
+sub getnames {
+ my ($uname,$udom)=@_;
+ return if (!defined($uname) || !defined($udom));
+ if ($udom eq 'public' && $uname eq 'public') {
+ return ('lastname' => &mt('Public'));
+ }
+ my $id=$uname.':'.$udom;
+ my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
+ if ($cached) {
+ return %{$names};
+ } else {
+ my %loadnames=&Apache::lonnet::get('environment',
+ ['firstname','middlename','lastname','generation','nickname'],
+ $udom,$uname);
+ &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
+ return %loadnames;
+ }
+}
+
+# -------------------------------------------------------------------- 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') {
+ return;
+ }
+ if (!$udom) { $udom=$env{'user.domain'}; }
+ if (!$uname) { $uname=$env{'user.name'}; }
+ my $id=$uname.':'.$udom;
+ my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
+ if ($cached) {
+ return %{$names};
+ } else {
+ my %loadnames=&Apache::lonnet::get('environment',
+ ['notification','critnotification',
+ 'permanentemail'],
+ $udom,$uname);
+ &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
+ return %loadnames;
+ }
+}
+
+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
@@ -1465,41 +3080,126 @@ Gets a users screenname and returns it a
sub screenname {
my ($uname,$udom)=@_;
- my %names=
- &Apache::lonnet::get('environment',['screenname'],$udom,$uname);
+ if ($uname eq $env{'user.name'} &&
+ $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
+ my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
return $names{'screenname'};
}
+
+# ------------------------------------------------------------- Confirm Wrapper
+=pod
+
+=item confirmwrapper
+
+Wrap messages about completion of operation in box
+
+=cut
+
+sub confirmwrapper {
+ my ($message)=@_;
+ if ($message) {
+ return "\n".''."\n"
+ .$message."\n"
+ .'
'."\n";
+ } else {
+ return $message;
+ }
+}
+
# ------------------------------------------------------------- Message Wrapper
sub messagewrapper {
- my ($link,$un,$do)=@_;
+ my ($link,$username,$domain,$subject,$text)=@_;
return
-"$link ";
+ ''.$link.' ';
}
+
# --------------------------------------------------------------- Notes Wrapper
sub noteswrapper {
my ($link,$un,$do)=@_;
return
-"$link ";
+"$link ";
}
+
# ------------------------------------------------------------- Aboutme Wrapper
sub aboutmewrapper {
- my ($link,$username,$domain)=@_;
- return "$link ";
+ my ($link,$username,$domain,$target)=@_;
+ if (!defined($username) && !defined($domain)) {
+ return;
+ }
+ return ''.$link.' ';
}
# ------------------------------------------------------------ Syllabus Wrapper
-
sub syllabuswrapper {
- my ($linktext,$coursedir,$domain,$fontcolor)=@_;
- if ($fontcolor) {
- $linktext=''.$linktext.' ';
+ my ($linktext,$coursedir,$domain)=@_;
+ return qq{$linktext };
+}
+
+# -----------------------------------------------------------------------------
+
+sub track_student_link {
+ my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
+ my $link ="/adm/trackstudent?";
+ my $title = 'View recent activity';
+ if (defined($sname) && $sname !~ /^\s*$/ &&
+ defined($sdom) && $sdom !~ /^\s*$/) {
+ $link .= "selected_student=$sname:$sdom";
+ $title .= ' of this student';
+ }
+ if (defined($target) && $target !~ /^\s*$/) {
+ $target = qq{target="$target"};
+ } else {
+ $target = '';
+ }
+ if ($start) { $link.='&start='.$start; }
+ if ($only_body) { $link .= '&only_body=1'; }
+ $title = &mt($title);
+ $linktext = &mt($linktext);
+ return qq{$linktext }.
+ &help_open_topic('View_recent_activity');
+}
+
+sub slot_reservations_link {
+ my ($linktext,$sname,$sdom,$target) = @_;
+ my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
+ my $title = 'View slot reservation history';
+ if (defined($sname) && $sname !~ /^\s*$/ &&
+ defined($sdom) && $sdom !~ /^\s*$/) {
+ $link .= "&uname=$sname&udom=$sdom";
+ $title .= ' of this student';
+ }
+ if (defined($target) && $target !~ /^\s*$/) {
+ $target = qq{target="$target"};
+ } else {
+ $target = '';
+ }
+ $title = &mt($title);
+ $linktext = &mt($linktext);
+ return qq{$linktext };
+# FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
+
+}
+
+# ===================================================== Display a student photo
+
+
+sub student_image_tag {
+ my ($domain,$user)=@_;
+ my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
+ if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
+ return ' ';
+ } else {
+ return '';
}
- return "$linktext ";
}
=pod
@@ -1510,7 +3210,7 @@ sub syllabuswrapper {
=over 4
-=item * languageids()
+=item * &languageids()
returns list of all language ids
@@ -1522,7 +3222,7 @@ sub languageids {
=pod
-=item * languagedescription()
+=item * &languagedescription()
returns description of a specified language id
@@ -1537,7 +3237,64 @@ sub languagedescription {
=pod
-=item * copyrightids()
+=item * &plainlanguagedescription
+
+Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
+and the language character encoding (e.g. ISO) separated by a ' - ' string.
+
+=cut
+
+sub plainlanguagedescription {
+ my $code=shift;
+ return $language{$code};
+}
+
+=pod
+
+=item * &supportedlanguagecode
+
+Returns the supported language code (e.g. sptutf maps to pt) given a language
+code.
+
+=cut
+
+sub supportedlanguagecode {
+ my $code=shift;
+ return $supported_language{$code};
+}
+
+=pod
+
+=item * &latexlanguage()
+
+Given a language key code returns the correspondnig language to use
+to select the correct hyphenation on LaTeX printouts. This is undef if there
+is no supported hyphenation for the language code.
+
+=cut
+
+sub latexlanguage {
+ my $code = shift;
+ return $latex_language{$code};
+}
+
+=pod
+
+=item * &latexhyphenation()
+
+Same as above but what's supplied is the language as it might be stored
+in the metadata.
+
+=cut
+
+sub latexhyphenation {
+ my $key = shift;
+ return $latex_language_bykey{$key};
+}
+
+=pod
+
+=item * ©rightids()
returns list of all copyrights
@@ -1549,19 +3306,43 @@ sub copyrightids {
=pod
-=item * copyrightdescription()
+=item * ©rightdescription()
returns description of a specified copyright id
=cut
sub copyrightdescription {
- return $cprtag{shift(@_)};
+ return &mt($cprtag{shift(@_)});
}
=pod
-=item * filecategories()
+=item * &source_copyrightids()
+
+returns list of all source copyrights
+
+=cut
+
+sub source_copyrightids {
+ return sort(keys(%scprtag));
+}
+
+=pod
+
+=item * &source_copyrightdescription()
+
+returns description of a specified source copyright id
+
+=cut
+
+sub source_copyrightdescription {
+ return &mt($scprtag{shift(@_)});
+}
+
+=pod
+
+=item * &filecategories()
returns list of all file categories
@@ -1573,7 +3354,7 @@ sub filecategories {
=pod
-=item * filecategorytypes()
+=item * &filecategorytypes()
returns list of file types belonging to a given file
category
@@ -1581,12 +3362,13 @@ category
=cut
sub filecategorytypes {
- return @{$category_extensions{lc($_[0])}};
+ my ($cat) = @_;
+ return @{$category_extensions{lc($cat)}};
}
=pod
-=item * fileembstyle()
+=item * &fileembstyle()
returns embedding style for a specified file type
@@ -1596,21 +3378,34 @@ sub fileembstyle {
return $fe{lc(shift(@_))};
}
+sub filemimetype {
+ return $fm{lc(shift(@_))};
+}
+
+
+sub filecategoryselect {
+ my ($name,$value)=@_;
+ return &select_form($value,$name,
+ {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
+}
+
=pod
-=item * filedescription()
+=item * &filedescription()
returns description for a specified file type
=cut
sub filedescription {
- return $fd{lc(shift(@_))};
+ my $file_description = $fd{lc(shift())};
+ $file_description =~ s:([\[\]]):~$1:g;
+ return &mt($file_description);
}
=pod
-=item * filedescriptionex()
+=item * &filedescriptionex()
returns description for a specified file type with
extra formatting
@@ -1619,7 +3414,9 @@ extra formatting
sub filedescriptionex {
my $ex=shift;
- return '.'.$ex.' '.$fd{lc($ex)};
+ my $file_description = $fd{lc($ex)};
+ $file_description =~ s:([\[\]]):~$1:g;
+ return '.'.$ex.' '.&mt($file_description);
}
# End of .tab access
@@ -1640,57 +3437,64 @@ sub fileextensions {
sub display_languages {
my %languages=();
- foreach (&preferred_languages()) {
- $languages{$_}=1;
+ foreach my $lang (&Apache::lonlocal::preferred_languages()) {
+ $languages{$lang}=1;
}
&get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
- if ($ENV{'form.displaylanguage'}) {
- foreach (split(/\s*(\,|\;|\:)\s*/,$ENV{'form.displaylanguage'})) {
- $languages{$_}=1;
+ if ($env{'form.displaylanguage'}) {
+ foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
+ $languages{$lang}=1;
}
}
return %languages;
}
-sub preferred_languages {
- my @languages=();
- if ($ENV{'environment.languages'}) {
- @languages=split(/\s*(\,|\;|\:)\s*/,$ENV{'environment.languages'});
- }
- if ($ENV{'course.'.$ENV{'request.course.id'}.'.languages'}) {
- @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,
- $ENV{'course.'.$ENV{'request.course.id'}.'.languages'}));
- }
- my $browser=(split(/\;/,$ENV{'HTTP_ACCEPT_LANGUAGE'}))[0];
- if ($browser) {
- @languages=(@languages,split(/\s*(\,|\;|\:)\s*/,$browser));
- }
- if ($Apache::lonnet::domain_lang_def{$ENV{'user.domain'}}) {
- @languages=(@languages,
- $Apache::lonnet::domain_lang_def{$ENV{'user.domain'}});
- }
- if ($Apache::lonnet::domain_lang_def{$ENV{'request.role.domain'}}) {
- @languages=(@languages,
- $Apache::lonnet::domain_lang_def{$ENV{'request.role.domain'}});
- }
- if ($Apache::lonnet::domain_lang_def{
- $Apache::lonnet::perlvar{'lonDefDomain'}}) {
- @languages=(@languages,
- $Apache::lonnet::domain_lang_def{
- $Apache::lonnet::perlvar{'lonDefDomain'}});
- }
-# turn "en-ca" into "en-ca,en"
- my @genlanguages;
- foreach (@languages) {
- unless ($_=~/\w/) { next; }
- push (@genlanguages,$_);
- if ($_=~/(\-|\_)/) {
- push (@genlanguages,(split(/(\-|\_)/,$_))[0]);
+sub languages {
+ my ($possible_langs) = @_;
+ my @preferred_langs = &Apache::lonlocal::preferred_languages();
+ if (!ref($possible_langs)) {
+ if( wantarray ) {
+ return @preferred_langs;
+ } else {
+ return $preferred_langs[0];
+ }
+ }
+ my %possibilities = map { $_ => 1 } (@$possible_langs);
+ my @preferred_possibilities;
+ foreach my $preferred_lang (@preferred_langs) {
+ if (exists($possibilities{$preferred_lang})) {
+ push(@preferred_possibilities, $preferred_lang);
}
}
- return @genlanguages;
+ if( wantarray ) {
+ return @preferred_possibilities;
+ }
+ return $preferred_possibilities[0];
+}
+
+sub user_lang {
+ my ($touname,$toudom,$fromcid) = @_;
+ my @userlangs;
+ if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
+ @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
+ $env{'course.'.$fromcid.'.languages'}));
+ } else {
+ my %langhash = &getlangs($touname,$toudom);
+ if ($langhash{'languages'} ne '') {
+ @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
+ } else {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
+ if ($domdefs{'lang_def'} ne '') {
+ @userlangs = ($domdefs{'lang_def'});
+ }
+ }
+ }
+ my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
+ my $user_lh = Apache::localize->get_handle(@languages);
+ return $user_lh;
}
+
###############################################################
## Student Answer Attempts ##
###############################################################
@@ -1701,7 +3505,7 @@ sub preferred_languages {
=over 4
-=item * get_previous_attempt($symb, $username, $domain, $course,
+=item * &get_previous_attempt($symb, $username, $domain, $course,
$getattempt, $regexp, $gradesub)
Return string with previous attempt on problem. Arguments:
@@ -1741,18 +3545,30 @@ sub get_previous_attempt {
my %lasthash=();
my $version;
for ($version=1;$version<=$returnhash{'version'};$version++) {
- foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
- $lasthash{$_}=$returnhash{$version.':'.$_};
+ foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
+ $lasthash{$key}=$returnhash{$version.':'.$key};
}
}
- $prevattempts='';
- $prevattempts.='History ';
- foreach (sort(keys %lasthash)) {
- my ($ign,@parts) = split(/\./,$_);
+ $prevattempts=&start_data_table().&start_data_table_header_row();
+ $prevattempts.=''.&mt('History').' ';
+ my (%typeparts,%lasthidden);
+ my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
+ foreach my $key (sort(keys(%lasthash))) {
+ my ($ign,@parts) = split(/\./,$key);
if ($#parts > 0) {
my $data=$parts[-1];
+ next if ($data eq 'foilorder');
pop(@parts);
- $prevattempts.='Part '.join('.',@parts).' '.$data.' ';
+ $prevattempts.=''.&mt('Part ').join('.',@parts).' '.$data.' ';
+ if ($data eq 'type') {
+ unless ($showsurv) {
+ my $id = join(',',@parts);
+ $typeparts{$ign.'.'.$id} = $lasthash{$key};
+ if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
+ $lasthidden{$ign.'.'.$id} = 1;
+ }
+ }
+ }
} else {
if ($#parts == 0) {
$prevattempts.=''.$parts[0].' ';
@@ -1761,40 +3577,148 @@ sub get_previous_attempt {
}
}
}
+ $prevattempts.=&end_data_table_header_row();
if ($getattempt eq '') {
for ($version=1;$version<=$returnhash{'version'};$version++) {
- $prevattempts.='Transaction '.$version.' ';
- foreach (sort(keys %lasthash)) {
- my $value;
- if ($_ =~ /timestamp/) {
- $value=scalar(localtime($returnhash{$version.':'.$_}));
- } else {
- $value=$returnhash{$version.':'.$_};
- }
- $prevattempts.=''.$value.' ';
- }
+ my @hidden;
+ if (%typeparts) {
+ foreach my $id (keys(%typeparts)) {
+ if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
+ push(@hidden,$id);
+ }
+ }
+ }
+ $prevattempts.=&start_data_table_row().
+ ''.&mt('Transaction [_1]',$version).' ';
+ if (@hidden) {
+ foreach my $key (sort(keys(%lasthash))) {
+ next if ($key =~ /\.foilorder$/);
+ my $hide;
+ foreach my $id (@hidden) {
+ if ($key =~ /^\Q$id\E/) {
+ $hide = 1;
+ last;
+ }
+ }
+ if ($hide) {
+ my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
+ if (($data eq 'award') || ($data eq 'awarddetail')) {
+ my $value = &format_previous_attempt_value($key,
+ $returnhash{$version.':'.$key});
+ $prevattempts.=''.$value.' ';
+ } else {
+ $prevattempts.=' ';
+ }
+ } else {
+ if ($key =~ /\./) {
+ my $value = &format_previous_attempt_value($key,
+ $returnhash{$version.':'.$key});
+ $prevattempts.=''.$value.' ';
+ } else {
+ $prevattempts.=' ';
+ }
+ }
+ }
+ } else {
+ foreach my $key (sort(keys(%lasthash))) {
+ next if ($key =~ /\.foilorder$/);
+ my $value = &format_previous_attempt_value($key,
+ $returnhash{$version.':'.$key});
+ $prevattempts.=''.$value.' ';
+ }
+ }
+ $prevattempts.=&end_data_table_row();
}
}
- $prevattempts.='Current ';
- foreach (sort(keys %lasthash)) {
- my $value;
- if ($_ =~ /timestamp/) {
- $value=scalar(localtime($lasthash{$_}));
- } else {
- $value=$lasthash{$_};
- }
- if ($_ =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
- $prevattempts.=''.$value.' ';
+ my @currhidden = keys(%lasthidden);
+ $prevattempts.=&start_data_table_row().''.&mt('Current').' ';
+ foreach my $key (sort(keys(%lasthash))) {
+ next if ($key =~ /\.foilorder$/);
+ if (%typeparts) {
+ my $hidden;
+ foreach my $id (@currhidden) {
+ if ($key =~ /^\Q$id\E/) {
+ $hidden = 1;
+ last;
+ }
+ }
+ if ($hidden) {
+ my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
+ if (($data eq 'award') || ($data eq 'awarddetail')) {
+ my $value = &format_previous_attempt_value($key,$lasthash{$key});
+ if ($key =~/$regexp$/ && (defined &$gradesub)) {
+ $value = &$gradesub($value);
+ }
+ $prevattempts.=''.$value.' ';
+ } else {
+ $prevattempts.=' ';
+ }
+ } else {
+ my $value = &format_previous_attempt_value($key,$lasthash{$key});
+ if ($key =~/$regexp$/ && (defined &$gradesub)) {
+ $value = &$gradesub($value);
+ }
+ $prevattempts.=''.$value.' ';
+ }
+ } else {
+ my $value = &format_previous_attempt_value($key,$lasthash{$key});
+ if ($key =~/$regexp$/ && (defined &$gradesub)) {
+ $value = &$gradesub($value);
+ }
+ $prevattempts.=''.$value.' ';
+ }
}
- $prevattempts.='
';
+ $prevattempts.= &end_data_table_row().&end_data_table();
} else {
- $prevattempts='Nothing submitted - no attempts.';
+ $prevattempts=
+ &start_data_table().&start_data_table_row().
+ ''.&mt('Nothing submitted - no attempts.').' '.
+ &end_data_table_row().&end_data_table();
}
} else {
- $prevattempts='No data.';
+ $prevattempts=
+ &start_data_table().&start_data_table_row().
+ ''.&mt('No data.').' '.
+ &end_data_table_row().&end_data_table();
}
}
+sub format_previous_attempt_value {
+ my ($key,$value) = @_;
+ if (($key =~ /timestamp/) || ($key=~/duedate/)) {
+ $value = &Apache::lonlocal::locallocaltime($value);
+ } elsif (ref($value) eq 'ARRAY') {
+ $value = '('.join(', ', @{ $value }).')';
+ } elsif ($key =~ /answerstring$/) {
+ my %answers = &Apache::lonnet::str2hash($value);
+ my @anskeys = sort(keys(%answers));
+ if (@anskeys == 1) {
+ my $answer = $answers{$anskeys[0]};
+ if ($answer =~ m{\0}) {
+ $answer =~ s{\0}{,}g;
+ }
+ my $tag_internal_answer_name = 'INTERNAL';
+ if ($anskeys[0] eq $tag_internal_answer_name) {
+ $value = $answer;
+ } else {
+ $value = $anskeys[0].'='.$answer;
+ }
+ } else {
+ foreach my $ans (@anskeys) {
+ my $answer = $answers{$ans};
+ if ($answer =~ m{\0}) {
+ $answer =~ s{\0}{,}g;
+ }
+ $value .= $ans.'='.$answer.' ';;
+ }
+ }
+ } else {
+ $value = &unescape($value);
+ }
+ return $value;
+}
+
+
sub relative_to_absolute {
my ($url,$output)=@_;
my $parser=HTML::TokeParser->new(\$output);
@@ -1815,14 +3739,14 @@ sub relative_to_absolute {
}
}
$thisdir=~s-/[^/]*$--;
- foreach (@rlinks) {
- unless (($_=~/^http:\/\//i) ||
- ($_=~/^\//) ||
- ($_=~/^javascript:/i) ||
- ($_=~/^mailto:/i) ||
- ($_=~/^\#/)) {
- my $newlocation=&Apache::lonnet::hreflocation($thisdir,$_);
- $output=~s/(\"|\'|\=\s*)$_(\"|\'|\s|\>)/$1$newlocation$2/;
+ foreach my $link (@rlinks) {
+ unless (($link=~/^https?\:\/\//i) ||
+ ($link=~/^\//) ||
+ ($link=~/^javascript:/i) ||
+ ($link=~/^mailto:/i) ||
+ ($link=~/^\#/)) {
+ my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
+ $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
}
}
# -------------------------------------------------- Deal with Applet codebases
@@ -1832,29 +3756,26 @@ sub relative_to_absolute {
=pod
-=item * get_student_view
+=item * &get_student_view()
show a snapshot of what student was looking at
=cut
sub get_student_view {
- my ($symb,$username,$domain,$courseid,$target) = @_;
+ my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
- my (%old,%moreenv);
+ my (%form);
my @elements=('symb','courseid','domain','username');
foreach my $element (@elements) {
- $old{$element}=$ENV{'form.grade_'.$element};
- $moreenv{'form.grade_'.$element}=eval '$'.$element #'
+ $form{'grade_'.$element}=eval '$'.$element #'
}
- if ($target eq 'tex') {$moreenv{'form.grade_target'} = 'tex';}
- &Apache::lonnet::appenv(%moreenv);
- $feedurl=&Apache::lonnet::clutter($feedurl);
- my $userview=&Apache::lonnet::ssi_body($feedurl);
- &Apache::lonnet::delenv('form.grade_');
- foreach my $element (@elements) {
- $ENV{'form.grade_'.$element}=$old{$element};
+ if (defined($moreenv)) {
+ %form=(%form,%{$moreenv});
}
+ if (defined($target)) { $form{'grade_target'} = $target; }
+ $feedurl=&Apache::lonnet::clutter($feedurl);
+ my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
$userview=~s/\]*\>//gi;
$userview=~s/\<\/body\>//gi;
$userview=~s/\//gi;
@@ -1863,12 +3784,44 @@ sub get_student_view {
$userview=~s/\<\/head\>//gi;
$userview=~s/action\s*\=/would_be_action\=/gi;
$userview=&relative_to_absolute($feedurl,$userview);
- return $userview;
+ if (wantarray) {
+ return ($userview,$response);
+ } else {
+ return $userview;
+ }
+}
+
+sub get_student_view_with_retries {
+ my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
+
+ my $ok = 0; # True if we got a good response.
+ my $content;
+ my $response;
+
+ # Try to get the student_view done. within the retries count:
+
+ do {
+ ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
+ $ok = $response->is_success;
+ if (!$ok) {
+ &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
+ }
+ $retries--;
+ } while (!$ok && ($retries > 0));
+
+ if (!$ok) {
+ $content = ''; # On error return an empty content.
+ }
+ if (wantarray) {
+ return ($content, $response);
+ } else {
+ return $content;
+ }
}
=pod
-=item * get_student_answers()
+=item * &get_student_answers()
show a snapshot of how student was answering problem
@@ -1877,19 +3830,15 @@ show a snapshot of how student was answe
sub get_student_answers {
my ($symb,$username,$domain,$courseid,%form) = @_;
my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
- my (%old,%moreenv);
+ my (%moreenv);
my @elements=('symb','courseid','domain','username');
foreach my $element (@elements) {
- $old{$element}=$ENV{'form.grade_'.$element};
- $moreenv{'form.grade_'.$element}=eval '$'.$element #'
- }
- $moreenv{'form.grade_target'}='answer';
- &Apache::lonnet::appenv(%moreenv);
- my $userview=&Apache::lonnet::ssi('/res/'.$feedurl,%form);
- &Apache::lonnet::delenv('form.grade_');
- foreach my $element (@elements) {
- $ENV{'form.grade_'.$element}=$old{$element};
+ $moreenv{'grade_'.$element}=eval '$'.$element #'
}
+ $moreenv{'grade_target'}='answer';
+ %moreenv=(%form,%moreenv);
+ $feedurl = &Apache::lonnet::clutter($feedurl);
+ my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
return $userview;
}
@@ -1897,7 +3846,7 @@ sub get_student_answers {
=item * &submlink()
-Inputs: $text $uname $udom $symb
+Inputs: $text $uname $udom $symb $target
Returns: A link to grades.pm such as to see the SUBM view of a student
@@ -1905,15 +3854,67 @@ Returns: A link to grades.pm such as to
###############################################
sub submlink {
- my ($text,$uname,$udom,$symb)=@_;
+ my ($text,$uname,$udom,$symb,$target)=@_;
if (!($uname && $udom)) {
(my $cursymb, my $courseid,$udom,$uname)=
- &Apache::lonxml::whichuser($symb);
+ &Apache::lonnet::whichuser($symb);
if (!$symb) { $symb=$cursymb; }
}
- if (!$symb) { $symb=&symbread(); }
- return ''.$text.' ';
+ if (!$symb) { $symb=&Apache::lonnet::symbread(); }
+ $symb=&escape($symb);
+ if ($target) { $target=" target=\"$target\""; }
+ return
+ ''.$text.' ';
+}
+##############################################
+
+=pod
+
+=item * &pgrdlink()
+
+Inputs: $text $uname $udom $symb $target
+
+Returns: A link to grades.pm such as to see the PGRD view of a student
+
+=cut
+
+###############################################
+sub pgrdlink {
+ my $link=&submlink(@_);
+ $link=~s/(&command=submission)/$1&showgrading=yes/;
+ return $link;
+}
+##############################################
+
+=pod
+
+=item * &pprmlink()
+
+Inputs: $text $uname $udom $symb $target
+
+Returns: A link to parmset.pm such as to see the PPRM view of a
+student and a specific resource
+
+=cut
+
+###############################################
+sub pprmlink {
+ my ($text,$uname,$udom,$symb,$target)=@_;
+ if (!($uname && $udom)) {
+ (my $cursymb, my $courseid,$udom,$uname)=
+ &Apache::lonnet::whichuser($symb);
+ if (!$symb) { $symb=$cursymb; }
+ }
+ if (!$symb) { $symb=&Apache::lonnet::symbread(); }
+ $symb=&escape($symb);
+ if ($target) { $target="target=\"$target\""; }
+ return ''.$text.' ';
}
##############################################
@@ -1927,62 +3928,555 @@ sub submlink {
sub timehash {
- my @ltime=localtime(shift);
- return ( 'seconds' => $ltime[0],
- 'minutes' => $ltime[1],
- 'hours' => $ltime[2],
- 'day' => $ltime[3],
- 'month' => $ltime[4]+1,
- 'year' => $ltime[5]+1900,
- 'weekday' => $ltime[6],
- 'dayyear' => $ltime[7]+1,
- 'dlsav' => $ltime[8] );
+ my ($thistime) = @_;
+ my $timezone = &Apache::lonlocal::gettimezone();
+ my $dt = DateTime->from_epoch(epoch => $thistime)
+ ->set_time_zone($timezone);
+ my $wday = $dt->day_of_week();
+ if ($wday == 7) { $wday = 0; }
+ return ( 'second' => $dt->second(),
+ 'minute' => $dt->minute(),
+ 'hour' => $dt->hour(),
+ 'day' => $dt->day_of_month(),
+ 'month' => $dt->month(),
+ 'year' => $dt->year(),
+ 'weekday' => $wday,
+ 'dayyear' => $dt->day_of_year(),
+ 'dlsav' => $dt->is_dst() );
+}
+
+sub utc_string {
+ my ($date)=@_;
+ return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
}
sub maketime {
my %th=@_;
+ my ($epoch_time,$timezone,$dt);
+ $timezone = &Apache::lonlocal::gettimezone();
+ eval {
+ $dt = DateTime->new( year => $th{'year'},
+ month => $th{'month'},
+ day => $th{'day'},
+ hour => $th{'hour'},
+ minute => $th{'minute'},
+ second => $th{'second'},
+ time_zone => $timezone,
+ );
+ };
+ if (!$@) {
+ $epoch_time = $dt->epoch;
+ if ($epoch_time) {
+ return $epoch_time;
+ }
+ }
return POSIX::mktime(
($th{'seconds'},$th{'minutes'},$th{'hours'},
- $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,$th{'dlsav'}));
+ $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
}
-
#########################################
-#
-# Retro-fixing of un-backward-compatible time format
-sub unsqltime {
- my $timestamp=shift;
- if ($timestamp=~/^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/) {
- $timestamp=&maketime(
- 'year'=>$1,'month'=>$2,'day'=>$3,
- 'hours'=>$4,'minutes'=>$5,'seconds'=>$6);
+sub findallcourses {
+ my ($roles,$uname,$udom) = @_;
+ my %roles;
+ if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
+ my %courses;
+ my $now=time;
+ if (!defined($uname)) {
+ $uname = $env{'user.name'};
+ }
+ if (!defined($udom)) {
+ $udom = $env{'user.domain'};
+ }
+ if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
+ my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
+ my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
+ $extra);
+ if (!%roles) {
+ %roles = (
+ cc => 1,
+ co => 1,
+ in => 1,
+ ep => 1,
+ ta => 1,
+ cr => 1,
+ st => 1,
+ );
+ }
+ foreach my $entry (keys(%roleshash)) {
+ my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
+ if ($trole =~ /^cr/) {
+ next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
+ } else {
+ next if (!exists($roles{$trole}));
+ }
+ if ($tend) {
+ next if ($tend < $now);
+ }
+ if ($tstart) {
+ next if ($tstart > $now);
+ }
+ my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
+ (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
+ my $value = $trole.'/'.$cdom.'/';
+ if ($secpart eq '') {
+ ($cnum,$role) = split(/_/,$cnumpart);
+ $sec = 'none';
+ $value .= $cnum.'/';
+ } else {
+ $cnum = $cnumpart;
+ ($sec,$role) = split(/_/,$secpart);
+ $value .= $cnum.'/'.$sec;
+ }
+ if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
+ unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
+ push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
+ }
+ } else {
+ @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
+ }
+ }
+ } else {
+ foreach my $key (keys(%env)) {
+ if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
+ $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
+ my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
+ next if ($role eq 'ca' || $role eq 'aa');
+ next if (%roles && !exists($roles{$role}));
+ my ($starttime,$endtime)=split(/\./,$env{$key});
+ my $active=1;
+ if ($starttime) {
+ if ($now<$starttime) { $active=0; }
+ }
+ if ($endtime) {
+ if ($now>$endtime) { $active=0; }
+ }
+ if ($active) {
+ my $value = $role.'/'.$cdom.'/'.$cnum.'/';
+ if ($sec eq '') {
+ $sec = 'none';
+ } else {
+ $value .= $sec;
+ }
+ if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
+ unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
+ push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
+ }
+ } else {
+ @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
+ }
+ }
+ }
+ }
}
- return $timestamp;
+ return %courses;
}
-#########################################
+###############################################
-sub findallcourses {
- my %courses=();
- my $now=time;
- foreach (keys %ENV) {
- if ($_=~/^user\.role\.\w+\.\/(\w+)\/(\w+)/) {
- my ($starttime,$endtime)=$ENV{$_};
- my $active=1;
- if ($starttime) {
- if ($now<$starttime) { $active=0; }
+sub blockcheck {
+ my ($setters,$activity,$uname,$udom,$url) = @_;
+
+ if (!defined($udom)) {
+ $udom = $env{'user.domain'};
+ }
+ if (!defined($uname)) {
+ $uname = $env{'user.name'};
+ }
+
+ # If uname and udom are for a course, check for blocks in the course.
+
+ if (&Apache::lonnet::is_course($udom,$uname)) {
+ my ($startblock,$endblock,$triggerblock) =
+ &get_blocks($setters,$activity,$udom,$uname,$url);
+ return ($startblock,$endblock,$triggerblock);
+ }
+
+ my $startblock = 0;
+ my $endblock = 0;
+ my $triggerblock = '';
+ my %live_courses = &findallcourses(undef,$uname,$udom);
+
+ # If uname is for a user, and activity is course-specific, i.e.,
+ # boards, chat or groups, check for blocking in current course only.
+
+ if (($activity eq 'boards' || $activity eq 'chat' ||
+ $activity eq 'groups') && ($env{'request.course.id'})) {
+ foreach my $key (keys(%live_courses)) {
+ if ($key ne $env{'request.course.id'}) {
+ delete($live_courses{$key});
+ }
+ }
+ }
+
+ my $otheruser = 0;
+ my %own_courses;
+ if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
+ # Resource belongs to user other than current user.
+ $otheruser = 1;
+ # Gather courses for current user
+ %own_courses =
+ &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
+ }
+
+ # Gather active course roles - course coordinator, instructor,
+ # exam proctor, ta, student, or custom role.
+
+ foreach my $course (keys(%live_courses)) {
+ my ($cdom,$cnum);
+ if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
+ $cdom = $env{'course.'.$course.'.domain'};
+ $cnum = $env{'course.'.$course.'.num'};
+ } else {
+ ($cdom,$cnum) = split(/_/,$course);
+ }
+ my $no_ownblock = 0;
+ my $no_userblock = 0;
+ if ($otheruser && $activity ne 'com') {
+ # Check if current user has 'evb' priv for this
+ if (defined($own_courses{$course})) {
+ foreach my $sec (keys(%{$own_courses{$course}})) {
+ my $checkrole = 'cm./'.$cdom.'/'.$cnum;
+ if ($sec ne 'none') {
+ $checkrole .= '/'.$sec;
+ }
+ if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
+ $no_ownblock = 1;
+ last;
+ }
+ }
+ }
+ # if they have 'evb' priv and are currently not playing student
+ next if (($no_ownblock) &&
+ ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
+ }
+ foreach my $sec (keys(%{$live_courses{$course}})) {
+ my $checkrole = 'cm./'.$cdom.'/'.$cnum;
+ if ($sec ne 'none') {
+ $checkrole .= '/'.$sec;
+ }
+ if ($otheruser) {
+ # Resource belongs to user other than current user.
+ # Assemble privs for that user, and check for 'evb' priv.
+ my (%allroles,%userroles);
+ if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
+ foreach my $entry (@{$live_courses{$course}{$sec}}) {
+ my ($trole,$tdom,$tnum,$tsec);
+ if ($entry =~ /^cr/) {
+ ($trole,$tdom,$tnum,$tsec) =
+ ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
+ } else {
+ ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
+ }
+ my ($spec,$area,$trest);
+ $area = '/'.$tdom.'/'.$tnum;
+ $trest = $tnum;
+ if ($tsec ne '') {
+ $area .= '/'.$tsec;
+ $trest .= '/'.$tsec;
+ }
+ $spec = $trole.'.'.$area;
+ if ($trole =~ /^cr/) {
+ &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
+ $tdom,$spec,$trest,$area);
+ } else {
+ &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
+ $tdom,$spec,$trest,$area);
+ }
+ }
+ my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
+ if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
+ if ($1) {
+ $no_userblock = 1;
+ last;
+ }
+ }
+ }
+ } else {
+ # Resource belongs to current user
+ # Check for 'evb' priv via lonnet::allowed().
+ if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
+ $no_ownblock = 1;
+ last;
+ }
+ }
+ }
+ # if they have the evb priv and are currently not playing student
+ next if (($no_ownblock) &&
+ ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
+ next if ($no_userblock);
+
+ # Retrieve blocking times and identity of locker for course
+ # of specified user, unless user has 'evb' privilege.
+
+ my ($start,$end,$trigger) =
+ &get_blocks($setters,$activity,$cdom,$cnum,$url);
+ if (($start != 0) &&
+ (($startblock == 0) || ($startblock > $start))) {
+ $startblock = $start;
+ if ($trigger ne '') {
+ $triggerblock = $trigger;
+ }
+ }
+ if (($end != 0) &&
+ (($endblock == 0) || ($endblock < $end))) {
+ $endblock = $end;
+ if ($trigger ne '') {
+ $triggerblock = $trigger;
+ }
+ }
+ }
+ return ($startblock,$endblock,$triggerblock);
+}
+
+sub get_blocks {
+ my ($setters,$activity,$cdom,$cnum,$url) = @_;
+ my $startblock = 0;
+ my $endblock = 0;
+ my $triggerblock = '';
+ my $course = $cdom.'_'.$cnum;
+ $setters->{$course} = {};
+ $setters->{$course}{'staff'} = [];
+ $setters->{$course}{'times'} = [];
+ $setters->{$course}{'triggers'} = [];
+ my (@blockers,%triggered);
+ my $now = time;
+ my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
+ if ($activity eq 'docs') {
+ @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
+ foreach my $block (@blockers) {
+ if ($block =~ /^firstaccess____(.+)$/) {
+ my $item = $1;
+ my $type = 'map';
+ my $timersymb = $item;
+ if ($item eq 'course') {
+ $type = 'course';
+ } elsif ($item =~ /___\d+___/) {
+ $type = 'resource';
+ } else {
+ $timersymb = &Apache::lonnet::symbread($item);
+ }
+ my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
+ my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
+ $triggered{$block} = {
+ start => $start,
+ end => $end,
+ type => $type,
+ };
+ }
+ }
+ } else {
+ foreach my $block (keys(%commblocks)) {
+ if ($block =~ m/^(\d+)____(\d+)$/) {
+ my ($start,$end) = ($1,$2);
+ if ($start <= time && $end >= time) {
+ if (ref($commblocks{$block}) eq 'HASH') {
+ if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
+ if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
+ unless(grep(/^\Q$block\E$/,@blockers)) {
+ push(@blockers,$block);
+ }
+ }
+ }
+ }
+ }
+ } elsif ($block =~ /^firstaccess____(.+)$/) {
+ my $item = $1;
+ my $timersymb = $item;
+ my $type = 'map';
+ if ($item eq 'course') {
+ $type = 'course';
+ } elsif ($item =~ /___\d+___/) {
+ $type = 'resource';
+ } else {
+ $timersymb = &Apache::lonnet::symbread($item);
+ }
+ my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
+ my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
+ if ($start && $end) {
+ if (($start <= time) && ($end >= time)) {
+ unless (grep(/^\Q$block\E$/,@blockers)) {
+ push(@blockers,$block);
+ $triggered{$block} = {
+ start => $start,
+ end => $end,
+ type => $type,
+ };
+ }
+ }
+ }
}
- if ($endtime) {
- if ($now>$endtime) { $active=0; }
+ }
+ }
+ foreach my $blocker (@blockers) {
+ my ($staff_name,$staff_dom,$title,$blocks) =
+ &parse_block_record($commblocks{$blocker});
+ push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
+ my ($start,$end,$triggertype);
+ if ($blocker =~ m/^(\d+)____(\d+)$/) {
+ ($start,$end) = ($1,$2);
+ } elsif (ref($triggered{$blocker}) eq 'HASH') {
+ $start = $triggered{$blocker}{'start'};
+ $end = $triggered{$blocker}{'end'};
+ $triggertype = $triggered{$blocker}{'type'};
+ }
+ if ($start) {
+ push(@{$$setters{$course}{'times'}}, [$start,$end]);
+ if ($triggertype) {
+ push(@{$$setters{$course}{'triggers'}},$triggertype);
+ } else {
+ push(@{$$setters{$course}{'triggers'}},0);
}
- if ($active) { $courses{$1.'_'.$2}=1; }
+ if ( ($startblock == 0) || ($startblock > $start) ) {
+ $startblock = $start;
+ if ($triggertype) {
+ $triggerblock = $blocker;
+ }
+ }
+ if ( ($endblock == 0) || ($endblock < $end) ) {
+ $endblock = $end;
+ if ($triggertype) {
+ $triggerblock = $blocker;
+ }
+ }
+ }
+ }
+ return ($startblock,$endblock,$triggerblock);
+}
+
+sub parse_block_record {
+ my ($record) = @_;
+ my ($setuname,$setudom,$title,$blocks);
+ if (ref($record) eq 'HASH') {
+ ($setuname,$setudom) = split(/:/,$record->{'setter'});
+ $title = &unescape($record->{'event'});
+ $blocks = $record->{'blocks'};
+ } else {
+ my @data = split(/:/,$record,3);
+ if (scalar(@data) eq 2) {
+ $title = $data[1];
+ ($setuname,$setudom) = split(/@/,$data[0]);
+ } else {
+ ($setuname,$setudom,$title) = @data;
}
+ $blocks = { 'com' => 'on' };
}
- return keys %courses;
+ return ($setuname,$setudom,$title,$blocks);
+}
+
+sub blocking_status {
+ my ($activity,$uname,$udom,$url) = @_;
+ my %setters;
+
+# check for active blocking
+ my ($startblock,$endblock,$triggerblock) =
+ &blockcheck(\%setters,$activity,$uname,$udom,$url);
+ my $blocked = 0;
+ if ($startblock && $endblock) {
+ $blocked = 1;
+ }
+
+# caller just wants to know whether a block is active
+ if (!wantarray) { return $blocked; }
+
+# build a link to a popup window containing the details
+ my $querystring = "?activity=$activity";
+# $uname and $udom decide whose portfolio the user is trying to look at
+ if ($activity eq 'port') {
+ $querystring .= "&udom=$udom" if $udom;
+ $querystring .= "&uname=$uname" if $uname;
+ } elsif ($activity eq 'docs') {
+ $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
+ }
+
+ my $output .= <<'END_MYBLOCK';
+function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
+ var options = "width=" + w + ",height=" + h + ",";
+ options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
+ options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
+ var newWin = window.open(url, wdwName, options);
+ newWin.focus();
+}
+END_MYBLOCK
+
+ $output = Apache::lonhtmlcommon::scripttag($output);
+
+ my $popupUrl = "/adm/blockingstatus/$querystring";
+ my $text = &mt('Communication Blocked');
+ if ($activity eq 'docs') {
+ $text = &mt('Content Access Blocked');
+ } elsif ($activity eq 'printout') {
+ $text = &mt('Printing Blocked');
+ }
+ $output .= <<"END_BLOCK";
+
+
+END_BLOCK
+
+ return ($blocked, $output);
}
###############################################
+
+sub check_ip_acc {
+ my ($acc)=@_;
+ &Apache::lonxml::debug("acc is $acc");
+ if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
+ return 1;
+ }
+ my $allowed=0;
+ my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
+
+ my $name;
+ foreach my $pattern (split(',',$acc)) {
+ $pattern =~ s/^\s*//;
+ $pattern =~ s/\s*$//;
+ if ($pattern =~ /\*$/) {
+ #35.8.*
+ $pattern=~s/\*//;
+ if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
+ } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
+ #35.8.3.[34-56]
+ my $low=$2;
+ my $high=$3;
+ $pattern=$1;
+ if ($ip =~ /^\Q$pattern\E/) {
+ my $last=(split(/\./,$ip))[3];
+ if ($last <=$high && $last >=$low) { $allowed=1; }
+ }
+ } elsif ($pattern =~ /^\*/) {
+ #*.msu.edu
+ $pattern=~s/\*//;
+ if (!defined($name)) {
+ use Socket;
+ my $netaddr=inet_aton($ip);
+ ($name)=gethostbyaddr($netaddr,AF_INET);
+ }
+ if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
+ } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
+ #127.0.0.1
+ if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
+ } else {
+ #some.name.com
+ if (!defined($name)) {
+ use Socket;
+ my $netaddr=inet_aton($ip);
+ ($name)=gethostbyaddr($netaddr,AF_INET);
+ }
+ if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
+ }
+ if ($allowed) { last; }
+ }
+ return $allowed;
+}
+
###############################################
=pod
@@ -2002,17 +4496,138 @@ Returns: Determines which domain should
###############################################
sub determinedomain {
my $domain=shift;
- if (! $domain) {
+ if (! $domain) {
# Determine domain if we have not been given one
- $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
- if ($ENV{'user.domain'}) { $domain=$ENV{'user.domain'}; }
- if ($ENV{'request.role.domain'}) {
- $domain=$ENV{'request.role.domain'};
+ $domain = &Apache::lonnet::default_login_domain();
+ if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
+ if ($env{'request.role.domain'}) {
+ $domain=$env{'request.role.domain'};
}
}
return $domain;
}
###############################################
+
+sub devalidate_domconfig_cache {
+ my ($udom)=@_;
+ &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
+}
+
+# ---------------------- Get domain configuration for a domain
+sub get_domainconf {
+ my ($udom) = @_;
+ my $cachetime=1800;
+ my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
+ if (defined($cached)) { return %{$result}; }
+
+ my %domconfig = &Apache::lonnet::get_dom('configuration',
+ ['login','rolecolors','autoenroll'],$udom);
+ my (%designhash,%legacy);
+ if (keys(%domconfig) > 0) {
+ if (ref($domconfig{'login'}) eq 'HASH') {
+ if (keys(%{$domconfig{'login'}})) {
+ foreach my $key (keys(%{$domconfig{'login'}})) {
+ if (ref($domconfig{'login'}{$key}) eq 'HASH') {
+ if ($key eq 'loginvia') {
+ if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
+ foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
+ if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
+ if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
+ my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
+ $designhash{$udom.'.login.loginvia'} = $server;
+ if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
+
+ $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
+ } else {
+ $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
+ }
+ if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
+ $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
+ }
+ }
+ }
+ }
+ }
+ } else {
+ foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
+ $designhash{$udom.'.login.'.$key.'_'.$img} =
+ $domconfig{'login'}{$key}{$img};
+ }
+ }
+ } else {
+ $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
+ }
+ }
+ } else {
+ $legacy{'login'} = 1;
+ }
+ } else {
+ $legacy{'login'} = 1;
+ }
+ if (ref($domconfig{'rolecolors'}) eq 'HASH') {
+ if (keys(%{$domconfig{'rolecolors'}})) {
+ foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
+ if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
+ foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
+ $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
+ }
+ }
+ }
+ } else {
+ $legacy{'rolecolors'} = 1;
+ }
+ } else {
+ $legacy{'rolecolors'} = 1;
+ }
+ if (ref($domconfig{'autoenroll'}) eq 'HASH') {
+ if ($domconfig{'autoenroll'}{'co-owners'}) {
+ $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
+ }
+ }
+ if (keys(%legacy) > 0) {
+ my %legacyhash = &get_legacy_domconf($udom);
+ foreach my $item (keys(%legacyhash)) {
+ if ($item =~ /^\Q$udom\E\.login/) {
+ if ($legacy{'login'}) {
+ $designhash{$item} = $legacyhash{$item};
+ }
+ } else {
+ if ($legacy{'rolecolors'}) {
+ $designhash{$item} = $legacyhash{$item};
+ }
+ }
+ }
+ }
+ } else {
+ %designhash = &get_legacy_domconf($udom);
+ }
+ &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
+ $cachetime);
+ return %designhash;
+}
+
+sub get_legacy_domconf {
+ my ($udom) = @_;
+ my %legacyhash;
+ my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
+ my $designfile = $designdir.'/'.$udom.'.tab';
+ if (-e $designfile) {
+ if ( open (my $fh,"<$designfile") ) {
+ while (my $line = <$fh>) {
+ next if ($line =~ /^\#/);
+ chomp($line);
+ my ($key,$val)=(split(/\=/,$line));
+ if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
+ }
+ close($fh);
+ }
+ }
+ if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
+ $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
+ }
+ return %legacyhash;
+}
+
=pod
=item * &domainlogo()
@@ -2026,15 +4641,21 @@ If the domain logo does not exist, a des
###############################################
sub domainlogo {
- my $domain = &determinedomain(shift);
- # See if there is a logo
- if (-e '/home/httpd/html/adm/lonDomLogos/'.$domain.'.gif') {
- my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
- if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
- return ' ';
- } elsif(exists($Apache::lonnet::domaindescription{$domain})) {
- return $Apache::lonnet::domaindescription{$domain};
+ my $domain = &determinedomain(shift);
+ my %designhash = &get_domainconf($domain);
+ # See if there is a logo
+ if ($designhash{$domain.'.login.domlogo'} ne '') {
+ my $imgsrc = $designhash{$domain.'.login.domlogo'};
+ if ($imgsrc =~ m{^/(adm|res)/}) {
+ if ($imgsrc =~ m{^/res/}) {
+ my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
+ &Apache::lonnet::repcopy($local_name);
+ }
+ $imgsrc = &lonhttpdurl($imgsrc);
+ }
+ return ' ';
+ } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
+ return &Apache::lonnet::domain($domain,'description');
} else {
return '';
}
@@ -2051,29 +4672,158 @@ Returns: value of designparamter $which
=cut
+
##############################################
sub designparm {
my ($which,$domain)=@_;
- if ($ENV{'browser.blackwhite'} eq 'on') {
- if ($which=~/\.(font|alink|vlink|link)$/) {
- return '#000000';
- }
- if ($which=~/\.(pgbg|sidebg)$/) {
- return '#FFFFFF';
- }
- if ($which=~/\.tabbg$/) {
- return '#CCCCCC';
- }
- }
- if ($ENV{'environment.color.'.$which}) {
- return $ENV{'environment.color.'.$which};
+ if (exists($env{'environment.color.'.$which})) {
+ return $env{'environment.color.'.$which};
}
$domain=&determinedomain($domain);
- if ($designhash{$domain.'.'.$which}) {
- return $designhash{$domain.'.'.$which};
+ my %domdesign;
+ unless ($domain eq 'public') {
+ %domdesign = &get_domainconf($domain);
+ }
+ my $output;
+ if ($domdesign{$domain.'.'.$which} ne '') {
+ $output = $domdesign{$domain.'.'.$which};
+ } else {
+ $output = $defaultdesign{$which};
+ }
+ if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
+ ($which =~ /login\.(img|logo|domlogo|login)/)) {
+ if ($output =~ m{^/(adm|res)/}) {
+ if ($output =~ m{^/res/}) {
+ my $local_name = &Apache::lonnet::filelocation('',$output);
+ &Apache::lonnet::repcopy($local_name);
+ }
+ $output = &lonhttpdurl($output);
+ }
+ }
+ return $output;
+}
+
+##############################################
+=pod
+
+=item * &authorspace()
+
+Inputs: $url (usually will be undef).
+
+Returns: Path to Construction Space containing the resource or
+ directory being viewed (or for which action is being taken).
+ If $url is provided, and begins /priv//
+ the path will be that portion of the $context argument.
+ Otherwise the path will be for the author space of the current
+ user when the current role is author, or for that of the
+ co-author/assistant co-author space when the current role
+ is co-author or assistant co-author.
+
+=cut
+
+sub authorspace {
+ my ($url) = @_;
+ if ($url ne '') {
+ if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
+ return $1;
+ }
+ }
+ my $caname = '';
+ my $cadom = '';
+ if ($env{'request.role'} =~ /^(?:ca|aa)/) {
+ ($cadom,$caname) =
+ ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
+ } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
+ $caname = $env{'user.name'};
+ $cadom = $env{'user.domain'};
+ }
+ if (($caname ne '') && ($cadom ne '')) {
+ return "/priv/$cadom/$caname/";
+ }
+ return;
+}
+
+##############################################
+=pod
+
+=item * &head_subbox()
+
+Inputs: $content (contains HTML code with page functions, etc.)
+
+Returns: HTML div with $content
+ To be included in page header
+
+=cut
+
+sub head_subbox {
+ my ($content)=@_;
+ my $output =
+ ''
+ .$content
+ .'
'
+}
+
+##############################################
+=pod
+
+=item * &CSTR_pageheader()
+
+Input: (optional) filename from which breadcrumb trail is built.
+ In most cases no input as needed, as $env{'request.filename'}
+ is appropriate for use in building the breadcrumb trail.
+
+Returns: HTML div with CSTR path and recent box
+ To be included on Construction Space pages
+
+=cut
+
+sub CSTR_pageheader {
+ my ($trailfile) = @_;
+ if ($trailfile eq '') {
+ $trailfile = $env{'request.filename'};
+ }
+
+# this is for resources; directories have customtitle, and crumbs
+# and select recent are created in lonpubdir.pm
+
+ my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
+ my ($udom,$uname,$thisdisfn)=
+ ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)/(.*)$});
+ my $formaction = "/priv/$udom/$uname/$thisdisfn";
+ $formaction =~ s{/+}{/}g;
+
+ my $parentpath = '';
+ my $lastitem = '';
+ if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
+ $parentpath = $1;
+ $lastitem = $2;
} else {
- return $designhash{'default.'.$which};
+ $lastitem = $thisdisfn;
}
+
+ my $output =
+ ''
+ .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
+ .''.&mt('Construction Space:').' '
+ .''
+ .&Apache::lonmenu::constspaceform()
+ .'
';
+
+ return $output;
}
###############################################
@@ -2083,7 +4833,7 @@ sub designparm {
=back
-=head1 HTTP Helpers
+=head1 HTML Helpers
=over 4
@@ -2108,6 +4858,17 @@ Inputs:
=item * $forcereg, if page should register as content page (relevant for
text interface only)
+=item * $no_nav_bar, if true, keep the 'what is this' info but remove the
+ navigational links
+
+=item * $bgcolor, used to override the bgcolor on a webpage to a specific value
+
+=item * $args, optional argument valid values are
+ no_auto_mt_title -> prevents &mt()ing the title arg
+ inherit_jsmath -> when creating popup window in a page,
+ should it have jsmath forced on by the
+ current page
+
=back
Returns: A uniform header for LON-CAPA web pages.
@@ -2118,249 +4879,4242 @@ other decorations will be returned.
=cut
sub bodytag {
- my ($title,$function,$addentries,$bodyonly,$domain,$forcereg)=@_;
- $title=&mt($title);
- unless ($function) {
- $function='student';
- if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
- $function='coordinator';
- }
- if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
- $function='admin';
- }
- if (($ENV{'request.role'}=~/^(au|ca)/) ||
- ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
- $function='author';
- }
- }
- my $img=&designparm($function.'.img',$domain);
- my $pgbg=&designparm($function.'.pgbg',$domain);
- my $tabbg=&designparm($function.'.tabbg',$domain);
- my $font=&designparm($function.'.font',$domain);
- my $link=&designparm($function.'.link',$domain);
- my $alink=&designparm($function.'.alink',$domain);
- my $vlink=&designparm($function.'.vlink',$domain);
- my $sidebg=&designparm($function.'.sidebg',$domain);
-# Accessibility font enhance
- unless ($addentries) { $addentries=''; }
- if ($ENV{'browser.fontenhance'} eq 'on') {
- $addentries.=' style="font-size: x-large"';
- }
+ my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
+ $no_nav_bar,$bgcolor,$args)=@_;
+
+ my $public;
+ if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
+ || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
+ $public = 1;
+ }
+ if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
+
+ $function = &get_users_function() if (!$function);
+ my $img = &designparm($function.'.img',$domain);
+ my $font = &designparm($function.'.font',$domain);
+ my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
+
+ my %design = ( 'style' => 'margin-top: 0',
+ 'bgcolor' => $pgbg,
+ 'text' => $font,
+ 'alink' => &designparm($function.'.alink',$domain),
+ 'vlink' => &designparm($function.'.vlink',$domain),
+ 'link' => &designparm($function.'.link',$domain),);
+ @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
+
# role and realm
- my ($role,$realm)
- =&Apache::lonnet::plaintext((split(/\./,$ENV{'request.role'}))[0]);
+ my ($role,$realm) = split(/\./,$env{'request.role'},2);
+ if ($role eq 'ca') {
+ my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
+ $realm = &plainname($rname,$rdom);
+ }
# realm
- if ($ENV{'request.course.id'}) {
- $realm=
- $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
- }
- unless ($realm) { $realm=' '; }
-# Set messages
- my $messages=&domainlogo($domain);
-# Port for miniserver
- my $lonhttpdPort=$Apache::lonnet::perlvar{'lonhttpdPort'};
- if (!defined($lonhttpdPort)) { $lonhttpdPort='8080'; }
+ if ($env{'request.course.id'}) {
+ if ($env{'request.role'} !~ /^cr/) {
+ $role = &Apache::lonnet::plaintext($role,&course_type());
+ }
+ if ($env{'request.course.sec'}) {
+ $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
+ }
+ $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
+ } else {
+ $role = &Apache::lonnet::plaintext($role);
+ }
+
+ if (!$realm) { $realm=' '; }
+
+ my $extra_body_attr = &make_attr_string($forcereg,\%design);
+
# construct main body tag
- my $bodytag = <
-END
- my $upperleft=' ';
+ my $bodytag = "".
+ &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
+
if ($bodyonly) {
return $bodytag;
- } elsif ($ENV{'browser.interface'} eq 'textual') {
-# Accessibility
- return $bodytag.&Apache::lonmenu::menubuttons($forcereg,'web',
- $forcereg).
- 'LON-CAPA: '.$title.' ';
- } elsif ($ENV{'environment.remote'} eq 'off') {
-# No Remote
- return $bodytag.&Apache::lonmenu::menubuttons($forcereg,'web',
- $forcereg).
- '';
+ }
+
+ my $name = &plainname($env{'user.name'},$env{'user.domain'});
+ if ($public) {
+ undef($role);
+ } else {
+ $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
+ }
+
+ my $titleinfo = ''.$title.' ';
+ #
+ # Extra info if you are the DC
+ my $dc_info = '';
+ if ($env{'user.adv'} && exists($env{'user.role.dc./'.
+ $env{'course.'.$env{'request.course.id'}.
+ '.domain'}.'/'})) {
+ my $cid = $env{'request.course.id'};
+ $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
+ $dc_info =~ s/\s+$//;
}
-#
-# Top frame rendering, Remote is up
-#
- return(<
-
-$upperleft
-$messages
-
-
-
- $title
-
-
- $ENV{'environment.firstname'}
- $ENV{'environment.middlename'}
- $ENV{'environment.lastname'}
- $ENV{'environment.generation'}
-
-
-
-
-$role
-
-
-$realm
-
-ENDBODY
+ $role = '('.$role.') ' if $role;
+ &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
+
+ if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') {
+ return $bodytag;
+ }
+
+ if ($env{'request.state'} eq 'construct') { $forcereg=1; }
+
+ # if ($env{'request.state'} eq 'construct') {
+ # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
+ # }
+
+
+
+ if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
+ if ($dc_info) {
+ $dc_info = qq|$dc_info |;
+ }
+ $bodytag .= qq|$name $role
+ $realm $dc_info
|;
+ return $bodytag;
+ }
+
+ unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
+ $bodytag .= qq|$name $role
|;
+ }
+
+ $bodytag .= Apache::lonhtmlcommon::scripttag(
+ Apache::lonmenu::utilityfunctions(), 'start');
+
+ $bodytag .= Apache::lonmenu::primary_menu();
+
+ if ($dc_info) {
+ $dc_info = &dc_courseid_toggle($dc_info);
+ }
+ $bodytag .= qq|$realm $dc_info
|;
+
+ #don't show menus for public users
+ if (!$public){
+ $bodytag .= Apache::lonmenu::secondary_menu();
+ $bodytag .= Apache::lonmenu::serverform();
+ $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
+ if ($env{'request.state'} eq 'construct') {
+ $bodytag .= &Apache::lonmenu::innerregister($forcereg,
+ $args->{'bread_crumbs'});
+ } elsif ($forcereg) {
+ $bodytag .= &Apache::lonmenu::innerregister($forcereg);
+ }
+ }else{
+ # this is to seperate menu from content when there's no secondary
+ # menu. Especially needed for public accessible ressources.
+ $bodytag .= ' ';
+ $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
+ }
+
+ return $bodytag;
+}
+
+sub dc_courseid_toggle {
+ my ($dc_info) = @_;
+ return ' '.
+ ''.
+ &mt('(More ...)').' '.
+ ''.$dc_info.'
';
+}
+
+sub make_attr_string {
+ my ($register,$attr_ref) = @_;
+
+ if ($attr_ref && !ref($attr_ref)) {
+ die("addentries Must be a hash ref ".
+ join(':',caller(1))." ".
+ join(':',caller(0))." ");
+ }
+
+ if ($register) {
+ my ($on_load,$on_unload);
+ foreach my $key (keys(%{$attr_ref})) {
+ if (lc($key) eq 'onload') {
+ $on_load.=$attr_ref->{$key}.';';
+ delete($attr_ref->{$key});
+
+ } elsif (lc($key) eq 'onunload') {
+ $on_unload.=$attr_ref->{$key}.';';
+ delete($attr_ref->{$key});
+ }
+ }
+ $attr_ref->{'onload'} = $on_load;
+ $attr_ref->{'onunload'}= $on_unload;
+ }
+
+ my $attr_string;
+ foreach my $attr (keys(%$attr_ref)) {
+ $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
+ }
+ return $attr_string;
}
+
+###############################################
###############################################
-sub get_posted_cgi {
- my $r=shift;
+=pod
+
+=item * &endbodytag()
+
+Returns a uniform footer for LON-CAPA web pages.
+
+Inputs: 1 - optional reference to an args hash
+If in the hash, key for noredirectlink has a value which evaluates to true,
+a 'Continue' link is not displayed if the page contains an
+internal redirect in the section,
+i.e., $env{'internal.head.redirect'} exists
+
+=cut
+
+sub endbodytag {
+ my ($args) = @_;
+ my $endbodytag='';
+ $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
+ if ( exists( $env{'internal.head.redirect'} ) ) {
+ if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
+ $endbodytag=
+ "".
+ &mt('Continue').' '.
+ $endbodytag;
+ }
+ }
+ return $endbodytag;
+}
+
+=pod
+
+=item * &standard_css()
+
+Returns a style sheet
+
+Inputs: (all optional)
+ domain -> force to color decorate a page for a specific
+ domain
+ function -> force usage of a specific rolish color scheme
+ bgcolor -> override the default page bgcolor
+
+=cut
+
+sub standard_css {
+ my ($function,$domain,$bgcolor) = @_;
+ $function = &get_users_function() if (!$function);
+ my $img = &designparm($function.'.img', $domain);
+ my $tabbg = &designparm($function.'.tabbg', $domain);
+ my $font = &designparm($function.'.font', $domain);
+ my $fontmenu = &designparm($function.'.fontmenu', $domain);
+#second colour for later usage
+ my $sidebg = &designparm($function.'.sidebg',$domain);
+ my $pgbg_or_bgcolor =
+ $bgcolor ||
+ &designparm($function.'.pgbg', $domain);
+ my $pgbg = &designparm($function.'.pgbg', $domain);
+ my $alink = &designparm($function.'.alink', $domain);
+ my $vlink = &designparm($function.'.vlink', $domain);
+ my $link = &designparm($function.'.link', $domain);
+
+ my $sans = 'Verdana,Arial,Helvetica,sans-serif';
+ my $mono = 'monospace';
+ my $data_table_head = $sidebg;
+ my $data_table_light = '#FAFAFA';
+ my $data_table_dark = '#E0E0E0';
+ my $data_table_darker = '#CCCCCC';
+ my $data_table_highlight = '#FFFF00';
+ my $mail_new = '#FFBB77';
+ my $mail_new_hover = '#DD9955';
+ my $mail_read = '#BBBB77';
+ my $mail_read_hover = '#999944';
+ my $mail_replied = '#AAAA88';
+ my $mail_replied_hover = '#888855';
+ my $mail_other = '#99BBBB';
+ my $mail_other_hover = '#669999';
+ my $table_header = '#DDDDDD';
+ my $feedback_link_bg = '#BBBBBB';
+ my $lg_border_color = '#C8C8C8';
+ my $button_hover = '#BF2317';
+
+ my $border = ($env{'browser.type'} eq 'explorer' ||
+ $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
+ : '0 3px 0 4px';
+
+
+ return < td {
+ background-color: #CCCCCC;
+ font-weight: bold;
+ text-align: left;
+}
+
+table.LC_data_table tr.LC_odd_row > td {
+ background-color: $data_table_light;
+ padding: 2px;
+ vertical-align: top;
+}
+
+table.LC_pick_box tr > td.LC_odd_row {
+ background-color: $data_table_light;
+ vertical-align: top;
+}
+
+table.LC_data_table tr.LC_even_row > td {
+ background-color: $data_table_dark;
+ padding: 2px;
+ vertical-align: top;
+}
+
+table.LC_pick_box tr > td.LC_even_row {
+ background-color: $data_table_dark;
+ vertical-align: top;
+}
+
+table.LC_data_table tr.LC_data_table_highlight td {
+ background-color: $data_table_darker;
+}
+
+table.LC_data_table tr td.LC_leftcol_header {
+ background-color: $data_table_head;
+ font-weight: bold;
+}
+
+table.LC_data_table tr.LC_empty_row td,
+table.LC_nested tr.LC_empty_row td {
+ font-weight: bold;
+ font-style: italic;
+ text-align: center;
+ padding: 8px;
+}
+
+table.LC_data_table tr.LC_empty_row td {
+ background-color: $sidebg;
+}
+
+table.LC_nested tr.LC_empty_row td {
+ background-color: #FFFFFF;
+}
+
+table.LC_caption {
+}
+
+table.LC_nested tr.LC_empty_row td {
+ padding: 4ex
+}
+
+table.LC_nested_outer tr th {
+ font-weight: bold;
+ color:$fontmenu;
+ background-color: $data_table_head;
+ font-size: small;
+ border-bottom: 1px solid #000000;
+}
+
+table.LC_nested_outer tr td.LC_subheader {
+ background-color: $data_table_head;
+ font-weight: bold;
+ font-size: small;
+ border-bottom: 1px solid #000000;
+ text-align: right;
+}
+
+table.LC_nested tr.LC_info_row td {
+ background-color: #CCCCCC;
+ font-weight: bold;
+ font-size: small;
+ text-align: center;
+}
+
+table.LC_nested tr.LC_info_row td.LC_left_item,
+table.LC_nested_outer tr th.LC_left_item {
+ text-align: left;
+}
+
+table.LC_nested td {
+ background-color: #FFFFFF;
+ font-size: small;
+}
+
+table.LC_nested_outer tr th.LC_right_item,
+table.LC_nested tr.LC_info_row td.LC_right_item,
+table.LC_nested tr.LC_odd_row td.LC_right_item,
+table.LC_nested tr td.LC_right_item {
+ text-align: right;
+}
+
+table.LC_nested tr.LC_odd_row td {
+ background-color: #EEEEEE;
+}
+
+table.LC_createuser {
+}
+
+table.LC_createuser tr.LC_section_row td {
+ font-size: small;
+}
+
+table.LC_createuser tr.LC_info_row td {
+ background-color: #CCCCCC;
+ font-weight: bold;
+ text-align: center;
+}
+
+table.LC_calendar {
+ border: 1px solid #000000;
+ border-collapse: collapse;
+ width: 98%;
+}
+
+table.LC_calendar_pickdate {
+ font-size: xx-small;
+}
+
+table.LC_calendar tr td {
+ border: 1px solid #000000;
+ vertical-align: top;
+ width: 14%;
+}
+
+table.LC_calendar tr td.LC_calendar_day_empty {
+ background-color: $data_table_dark;
+}
+
+table.LC_calendar tr td.LC_calendar_day_current {
+ background-color: $data_table_highlight;
+}
+
+table.LC_data_table tr td.LC_mail_new {
+ background-color: $mail_new;
+}
+
+table.LC_data_table tr.LC_mail_new:hover {
+ background-color: $mail_new_hover;
+}
+
+table.LC_data_table tr td.LC_mail_read {
+ background-color: $mail_read;
+}
+
+/*
+table.LC_data_table tr.LC_mail_read:hover {
+ background-color: $mail_read_hover;
+}
+*/
+
+table.LC_data_table tr td.LC_mail_replied {
+ background-color: $mail_replied;
+}
+
+/*
+table.LC_data_table tr.LC_mail_replied:hover {
+ background-color: $mail_replied_hover;
+}
+*/
+
+table.LC_data_table tr td.LC_mail_other {
+ background-color: $mail_other;
+}
+
+/*
+table.LC_data_table tr.LC_mail_other:hover {
+ background-color: $mail_other_hover;
+}
+*/
+
+table.LC_data_table tr > td.LC_browser_file,
+table.LC_data_table tr > td.LC_browser_file_published {
+ background: #AAEE77;
+}
+
+table.LC_data_table tr > td.LC_browser_file_locked,
+table.LC_data_table tr > td.LC_browser_file_unpublished {
+ background: #FFAA99;
+}
+
+table.LC_data_table tr > td.LC_browser_file_obsolete {
+ background: #888888;
+}
+
+table.LC_data_table tr > td.LC_browser_file_modified,
+table.LC_data_table tr > td.LC_browser_file_metamodified {
+ background: #F8F866;
+}
+
+table.LC_data_table tr.LC_browser_folder > td {
+ background: #E0E8FF;
+}
+
+table.LC_data_table tr > td.LC_roles_is {
+ /* background: #77FF77; */
+}
+
+table.LC_data_table tr > td.LC_roles_future {
+ border-right: 8px solid #FFFF77;
+}
+
+table.LC_data_table tr > td.LC_roles_will {
+ border-right: 8px solid #FFAA77;
+}
+
+table.LC_data_table tr > td.LC_roles_expired {
+ border-right: 8px solid #FF7777;
+}
+
+table.LC_data_table tr > td.LC_roles_will_not {
+ border-right: 8px solid #AAFF77;
+}
+
+table.LC_data_table tr > td.LC_roles_selected {
+ border-right: 8px solid #11CC55;
+}
+
+span.LC_current_location {
+ font-size:larger;
+ background: $pgbg;
+}
+
+span.LC_current_nav_location {
+ font-weight:bold;
+ background: $sidebg;
+}
+
+span.LC_parm_menu_item {
+ font-size: larger;
+}
+
+span.LC_parm_scope_all {
+ color: red;
+}
+
+span.LC_parm_scope_folder {
+ color: green;
+}
+
+span.LC_parm_scope_resource {
+ color: orange;
+}
+
+span.LC_parm_part {
+ color: blue;
+}
+
+span.LC_parm_folder,
+span.LC_parm_symb {
+ font-size: x-small;
+ font-family: $mono;
+ color: #AAAAAA;
+}
+
+ul.LC_parm_parmlist li {
+ display: inline-block;
+ padding: 0.3em 0.8em;
+ vertical-align: top;
+ width: 150px;
+ border-top:1px solid $lg_border_color;
+}
+
+td.LC_parm_overview_level_menu,
+td.LC_parm_overview_map_menu,
+td.LC_parm_overview_parm_selectors,
+td.LC_parm_overview_restrictions {
+ border: 1px solid black;
+ border-collapse: collapse;
+}
+
+table.LC_parm_overview_restrictions td {
+ border-width: 1px 4px 1px 4px;
+ border-style: solid;
+ border-color: $pgbg;
+ text-align: center;
+}
+
+table.LC_parm_overview_restrictions th {
+ background: $tabbg;
+ border-width: 1px 4px 1px 4px;
+ border-style: solid;
+ border-color: $pgbg;
+}
+
+table#LC_helpmenu {
+ border: none;
+ height: 55px;
+ border-spacing: 0;
+}
+
+table#LC_helpmenu fieldset legend {
+ font-size: larger;
+}
+
+table#LC_helpmenu_links {
+ width: 100%;
+ border: 1px solid black;
+ background: $pgbg;
+ padding: 0;
+ border-spacing: 1px;
+}
+
+table#LC_helpmenu_links tr td {
+ padding: 1px;
+ background: $tabbg;
+ text-align: center;
+ font-weight: bold;
+}
+
+table#LC_helpmenu_links a:link,
+table#LC_helpmenu_links a:visited,
+table#LC_helpmenu_links a:active {
+ text-decoration: none;
+ color: $font;
+}
+
+table#LC_helpmenu_links a:hover {
+ text-decoration: underline;
+ color: $vlink;
+}
+
+.LC_chrt_popup_exists {
+ border: 1px solid #339933;
+ margin: -1px;
+}
+
+.LC_chrt_popup_up {
+ border: 1px solid yellow;
+ margin: -1px;
+}
+
+.LC_chrt_popup {
+ border: 1px solid #8888FF;
+ background: #CCCCFF;
+}
+
+table.LC_pick_box {
+ border-collapse: separate;
+ background: white;
+ border: 1px solid black;
+ border-spacing: 1px;
+}
+
+table.LC_pick_box td.LC_pick_box_title {
+ background: $sidebg;
+ font-weight: bold;
+ text-align: left;
+ vertical-align: top;
+ width: 184px;
+ padding: 8px;
+}
+
+table.LC_pick_box td.LC_pick_box_value {
+ text-align: left;
+ padding: 8px;
+}
+
+table.LC_pick_box td.LC_pick_box_select {
+ text-align: left;
+ padding: 8px;
+}
+
+table.LC_pick_box td.LC_pick_box_separator {
+ padding: 0;
+ height: 1px;
+ background: black;
+}
+
+table.LC_pick_box td.LC_pick_box_submit {
+ text-align: right;
+}
+
+table.LC_pick_box td.LC_evenrow_value {
+ text-align: left;
+ padding: 8px;
+ background-color: $data_table_light;
+}
+
+table.LC_pick_box td.LC_oddrow_value {
+ text-align: left;
+ padding: 8px;
+ background-color: $data_table_light;
+}
+
+span.LC_helpform_receipt_cat {
+ font-weight: bold;
+}
+
+table.LC_group_priv_box {
+ background: white;
+ border: 1px solid black;
+ border-spacing: 1px;
+}
+
+table.LC_group_priv_box td.LC_pick_box_title {
+ background: $tabbg;
+ font-weight: bold;
+ text-align: right;
+ width: 184px;
+}
+
+table.LC_group_priv_box td.LC_groups_fixed {
+ background: $data_table_light;
+ text-align: center;
+}
+
+table.LC_group_priv_box td.LC_groups_optional {
+ background: $data_table_dark;
+ text-align: center;
+}
+
+table.LC_group_priv_box td.LC_groups_functionality {
+ background: $data_table_darker;
+ text-align: center;
+ font-weight: bold;
+}
+
+table.LC_group_priv td {
+ text-align: left;
+ padding: 0;
+}
+
+.LC_navbuttons {
+ margin: 2ex 0ex 2ex 0ex;
+}
+
+.LC_topic_bar {
+ font-weight: bold;
+ background: $tabbg;
+ margin: 1em 0em 1em 2em;
+ padding: 3px;
+ font-size: 1.2em;
+}
+
+.LC_topic_bar span {
+ left: 0.5em;
+ position: absolute;
+ vertical-align: middle;
+ font-size: 1.2em;
+}
+
+table.LC_course_group_status {
+ margin: 20px;
+}
+
+table.LC_status_selector td {
+ vertical-align: top;
+ text-align: center;
+ padding: 4px;
+}
+
+div.LC_feedback_link {
+ clear: both;
+ background: $sidebg;
+ width: 100%;
+ padding-bottom: 10px;
+ border: 1px $tabbg solid;
+ height: 22px;
+ line-height: 22px;
+ padding-top: 5px;
+}
+
+div.LC_feedback_link img {
+ height: 22px;
+ vertical-align:middle;
+}
+
+div.LC_feedback_link a {
+ text-decoration: none;
+}
+
+div.LC_comblock {
+ display:inline;
+ color:$font;
+ font-size:90%;
+}
+
+div.LC_feedback_link div.LC_comblock {
+ padding-left:5px;
+}
+
+div.LC_feedback_link div.LC_comblock a {
+ color:$font;
+}
+
+span.LC_feedback_link {
+ /* background: $feedback_link_bg; */
+ font-size: larger;
+}
+
+span.LC_message_link {
+ /* background: $feedback_link_bg; */
+ font-size: larger;
+ position: absolute;
+ right: 1em;
+}
+
+table.LC_prior_tries {
+ border: 1px solid #000000;
+ border-collapse: separate;
+ border-spacing: 1px;
+}
+
+table.LC_prior_tries td {
+ padding: 2px;
+}
+
+.LC_answer_correct {
+ background: lightgreen;
+ color: darkgreen;
+ padding: 6px;
+}
+
+.LC_answer_charged_try {
+ background: #FFAAAA;
+ color: darkred;
+ padding: 6px;
+}
+
+.LC_answer_not_charged_try,
+.LC_answer_no_grade,
+.LC_answer_late {
+ background: lightyellow;
+ color: black;
+ padding: 6px;
+}
+
+.LC_answer_previous {
+ background: lightblue;
+ color: darkblue;
+ padding: 6px;
+}
+
+.LC_answer_no_message {
+ background: #FFFFFF;
+ color: black;
+ padding: 6px;
+}
+
+.LC_answer_unknown {
+ background: orange;
+ color: black;
+ padding: 6px;
+}
+
+span.LC_prior_numerical,
+span.LC_prior_string,
+span.LC_prior_custom,
+span.LC_prior_reaction,
+span.LC_prior_math {
+ font-family: $mono;
+ white-space: pre;
+}
+
+span.LC_prior_string {
+ font-family: $mono;
+ white-space: pre;
+}
+
+table.LC_prior_option {
+ width: 100%;
+ border-collapse: collapse;
+}
+
+table.LC_prior_rank,
+table.LC_prior_match {
+ border-collapse: collapse;
+}
+
+table.LC_prior_option tr td,
+table.LC_prior_rank tr td,
+table.LC_prior_match tr td {
+ border: 1px solid #000000;
+}
+
+.LC_nobreak {
+ white-space: nowrap;
+}
+
+span.LC_cusr_emph {
+ font-style: italic;
+}
+
+span.LC_cusr_subheading {
+ font-weight: normal;
+ font-size: 85%;
+}
+
+div.LC_docs_entry_move {
+ border: 1px solid #BBBBBB;
+ background: #DDDDDD;
+ width: 22px;
+ padding: 1px;
+ margin: 0;
+}
+
+table.LC_data_table tr > td.LC_docs_entry_commands,
+table.LC_data_table tr > td.LC_docs_entry_parameter {
+ background: #DDDDDD;
+ font-size: x-small;
+}
+
+.LC_docs_entry_parameter {
+ white-space: nowrap;
+}
+
+.LC_docs_copy {
+ color: #000099;
+}
+
+.LC_docs_cut {
+ color: #550044;
+}
+
+.LC_docs_rename {
+ color: #009900;
+}
+
+.LC_docs_remove {
+ color: #990000;
+}
+
+.LC_docs_reinit_warn,
+.LC_docs_ext_edit {
+ font-size: x-small;
+}
+
+table.LC_docs_adddocs td,
+table.LC_docs_adddocs th {
+ border: 1px solid #BBBBBB;
+ padding: 4px;
+ background: #DDDDDD;
+}
+
+table.LC_sty_begin {
+ background: #BBFFBB;
+}
+
+table.LC_sty_end {
+ background: #FFBBBB;
+}
+
+table.LC_double_column {
+ border-width: 0;
+ border-collapse: collapse;
+ width: 100%;
+ padding: 2px;
+}
+
+table.LC_double_column tr td.LC_left_col {
+ top: 2px;
+ left: 2px;
+ width: 47%;
+ vertical-align: top;
+}
+
+table.LC_double_column tr td.LC_right_col {
+ top: 2px;
+ right: 2px;
+ width: 47%;
+ vertical-align: top;
+}
+
+div.LC_left_float {
+ float: left;
+ padding-right: 5%;
+ padding-bottom: 4px;
+}
+
+div.LC_clear_float_header {
+ padding-bottom: 2px;
+}
+
+div.LC_clear_float_footer {
+ padding-top: 10px;
+ clear: both;
+}
+
+div.LC_grade_show_user {
+/* border-left: 5px solid $sidebg; */
+ border-top: 5px solid #000000;
+ margin: 50px 0 0 0;
+ padding: 15px 0 5px 10px;
+}
+
+div.LC_grade_show_user_odd_row {
+/* border-left: 5px solid #000000; */
+}
+
+div.LC_grade_show_user div.LC_Box {
+ margin-right: 50px;
+}
+
+div.LC_grade_submissions,
+div.LC_grade_message_center,
+div.LC_grade_info_links {
+ margin: 5px;
+ width: 99%;
+ background: #FFFFFF;
+}
+
+div.LC_grade_submissions_header,
+div.LC_grade_message_center_header {
+ font-weight: bold;
+ font-size: large;
+}
+
+div.LC_grade_submissions_body,
+div.LC_grade_message_center_body {
+ border: 1px solid black;
+ width: 99%;
+ background: #FFFFFF;
+}
+
+table.LC_scantron_action {
+ width: 100%;
+}
+
+table.LC_scantron_action tr th {
+ font-weight:bold;
+ font-style:normal;
+}
+
+.LC_edit_problem_header,
+div.LC_edit_problem_footer {
+ font-weight: normal;
+ font-size: medium;
+ margin: 2px;
+ background-color: $sidebg;
+}
+
+div.LC_edit_problem_header,
+div.LC_edit_problem_header div,
+div.LC_edit_problem_footer,
+div.LC_edit_problem_footer div,
+div.LC_edit_problem_editxml_header,
+div.LC_edit_problem_editxml_header div {
+ margin-top: 5px;
+}
+
+div.LC_edit_problem_header_title {
+ font-weight: bold;
+ font-size: larger;
+ background: $tabbg;
+ padding: 3px;
+ margin: 0 0 5px 0;
+}
+
+table.LC_edit_problem_header_title {
+ width: 100%;
+ background: $tabbg;
+}
+
+div.LC_edit_problem_discards {
+ float: left;
+ padding-bottom: 5px;
+}
+
+div.LC_edit_problem_saves {
+ float: right;
+ padding-bottom: 5px;
+}
+
+img.stift {
+ border-width: 0;
+ vertical-align: middle;
+}
+
+table td.LC_mainmenu_col_fieldset {
+ vertical-align: top;
+}
+
+div.LC_createcourse {
+ margin: 10px 10px 10px 10px;
+}
+
+.LC_dccid {
+ margin: 0.2em 0 0 0;
+ padding: 0;
+ font-size: 90%;
+ display:none;
+}
+
+ol.LC_primary_menu a:hover,
+ol#LC_MenuBreadcrumbs a:hover,
+ol#LC_PathBreadcrumbs a:hover,
+ul#LC_secondary_menu a:hover,
+.LC_FormSectionClearButton input:hover
+ul.LC_TabContent li:hover a {
+ color:$button_hover;
+ text-decoration:none;
+}
+
+h1 {
+ padding: 0;
+ line-height:130%;
+}
+
+h2,
+h3,
+h4,
+h5,
+h6 {
+ margin: 5px 0 5px 0;
+ padding: 0;
+ line-height:130%;
+}
+
+.LC_hcell {
+ padding:3px 15px 3px 15px;
+ margin: 0;
+ background-color:$tabbg;
+ color:$fontmenu;
+ border-bottom:solid 1px $lg_border_color;
+}
+
+.LC_Box > .LC_hcell {
+ margin: 0 -10px 10px -10px;
+}
+
+.LC_noBorder {
+ border: 0;
+}
+
+.LC_FormSectionClearButton input {
+ background-color:transparent;
+ border: none;
+ cursor:pointer;
+ text-decoration:underline;
+}
+
+.LC_help_open_topic {
+ color: #FFFFFF;
+ background-color: #EEEEFF;
+ margin: 1px;
+ padding: 4px;
+ border: 1px solid #000033;
+ white-space: nowrap;
+ /* vertical-align: middle; */
+}
+
+dl,
+ul,
+div,
+fieldset {
+ margin: 10px 10px 10px 0;
+ /* overflow: hidden; */
+}
+
+fieldset > legend {
+ font-weight: bold;
+ padding: 0 5px 0 5px;
+}
+
+#LC_nav_bar {
+ float: left;
+ background-color: $pgbg_or_bgcolor;
+ margin: 0 0 2px 0;
+}
+
+#LC_realm {
+ margin: 0.2em 0 0 0;
+ padding: 0;
+ font-weight: bold;
+ text-align: center;
+ background-color: $pgbg_or_bgcolor;
+}
+
+#LC_nav_bar em {
+ font-weight: bold;
+ font-style: normal;
+}
+
+ol.LC_primary_menu {
+ float: right;
+ margin: 0;
+ background-color: $pgbg_or_bgcolor;
+}
+
+ol#LC_PathBreadcrumbs {
+ margin: 0;
+}
+
+ol.LC_primary_menu li {
+ display: inline;
+ padding: 5px 5px 0 10px;
+ vertical-align: top;
+}
+
+ol.LC_primary_menu li img {
+ vertical-align: bottom;
+ height: 1.1em;
+}
- my $buffer;
+ol.LC_primary_menu a {
+ color: RGB(80, 80, 80);
+ text-decoration: none;
+}
+
+ol.LC_primary_menu a.LC_new_message {
+ font-weight:bold;
+ color: darkred;
+}
+
+ol.LC_docs_parameters {
+ margin-left: 0;
+ padding: 0;
+ list-style: none;
+}
+
+ol.LC_docs_parameters li {
+ margin: 0;
+ padding-right: 20px;
+ display: inline;
+}
+
+ol.LC_docs_parameters li:before {
+ content: "\\002022 \\0020";
+}
+
+li.LC_docs_parameters_title {
+ font-weight: bold;
+}
+
+ol.LC_docs_parameters li.LC_docs_parameters_title:before {
+ content: "";
+}
+
+ul#LC_secondary_menu {
+ clear: both;
+ color: $fontmenu;
+ background: $tabbg;
+ list-style: none;
+ padding: 0;
+ margin: 0;
+ width: 100%;
+ text-align: left;
+}
+
+ul#LC_secondary_menu li {
+ font-weight: bold;
+ line-height: 1.8em;
+ padding: 0 0.8em;
+ border-right: 1px solid black;
+ display: inline;
+ vertical-align: middle;
+}
+
+ul.LC_TabContent {
+ display:block;
+ background: $sidebg;
+ border-bottom: solid 1px $lg_border_color;
+ list-style:none;
+ margin: -1px -10px 0 -10px;
+ padding: 0;
+}
+
+ul.LC_TabContent li,
+ul.LC_TabContentBigger li {
+ float:left;
+}
+
+ul#LC_secondary_menu li a {
+ color: $fontmenu;
+ text-decoration: none;
+}
+
+ul.LC_TabContent {
+ min-height:20px;
+}
+
+ul.LC_TabContent li {
+ vertical-align:middle;
+ padding: 0 16px 0 10px;
+ background-color:$tabbg;
+ border-bottom:solid 1px $lg_border_color;
+ border-left: solid 1px $font;
+}
+
+ul.LC_TabContent .right {
+ float:right;
+}
+
+ul.LC_TabContent li a,
+ul.LC_TabContent li {
+ color:rgb(47,47,47);
+ text-decoration:none;
+ font-size:95%;
+ font-weight:bold;
+ min-height:20px;
+}
+
+ul.LC_TabContent li a:hover,
+ul.LC_TabContent li a:focus {
+ color: $button_hover;
+ background:none;
+ outline:none;
+}
+
+ul.LC_TabContent li:hover {
+ color: $button_hover;
+ cursor:pointer;
+}
+
+ul.LC_TabContent li.active {
+ color: $font;
+ background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
+ border-bottom:solid 1px #FFFFFF;
+ cursor: default;
+}
+
+ul.LC_TabContent li.active a {
+ color:$font;
+ background:#FFFFFF;
+ outline: none;
+}
+
+ul.LC_TabContent li.goback {
+ float: left;
+ border-left: none;
+}
+
+#maincoursedoc {
+ clear:both;
+}
+
+ul.LC_TabContentBigger {
+ display:block;
+ list-style:none;
+ padding: 0;
+}
+
+ul.LC_TabContentBigger li {
+ vertical-align:bottom;
+ height: 30px;
+ font-size:110%;
+ font-weight:bold;
+ color: #737373;
+}
+
+ul.LC_TabContentBigger li.active {
+ position: relative;
+ top: 1px;
+}
+
+ul.LC_TabContentBigger li a {
+ background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
+ height: 30px;
+ line-height: 30px;
+ text-align: center;
+ display: block;
+ text-decoration: none;
+ outline: none;
+}
+
+ul.LC_TabContentBigger li.active a {
+ background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
+ color:$font;
+}
+
+ul.LC_TabContentBigger li b {
+ background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
+ display: block;
+ float: left;
+ padding: 0 30px;
+ border-bottom: 1px solid $lg_border_color;
+}
+
+ul.LC_TabContentBigger li:hover b {
+ color:$button_hover;
+}
+
+ul.LC_TabContentBigger li.active b {
+ background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
+ color:$font;
+ border: 0;
+}
+
+
+ul.LC_CourseBreadcrumbs {
+ background: $sidebg;
+ height: 2em;
+ padding-left: 10px;
+ margin: 0;
+ list-style-position: inside;
+}
+
+ol#LC_MenuBreadcrumbs,
+ol#LC_PathBreadcrumbs {
+ padding-left: 10px;
+ margin: 0;
+ height: 2.5em; /* equal to #LC_breadcrumbs line-height */
+}
+
+ol#LC_MenuBreadcrumbs li,
+ol#LC_PathBreadcrumbs li,
+ul.LC_CourseBreadcrumbs li {
+ display: inline;
+ white-space: normal;
+}
+
+ol#LC_MenuBreadcrumbs li a,
+ul.LC_CourseBreadcrumbs li a {
+ text-decoration: none;
+ font-size:90%;
+}
+
+ol#LC_MenuBreadcrumbs h1 {
+ display: inline;
+ font-size: 90%;
+ line-height: 2.5em;
+ margin: 0;
+ padding: 0;
+}
+
+ol#LC_PathBreadcrumbs li a {
+ text-decoration:none;
+ font-size:100%;
+ font-weight:bold;
+}
+
+.LC_Box {
+ border: solid 1px $lg_border_color;
+ padding: 0 10px 10px 10px;
+}
+
+.LC_DocsBox {
+ border: solid 1px $lg_border_color;
+ padding: 0 0 10px 10px;
+}
+
+.LC_AboutMe_Image {
+ float:left;
+ margin-right:10px;
+}
+
+.LC_Clear_AboutMe_Image {
+ clear:left;
+}
+
+dl.LC_ListStyleClean dt {
+ padding-right: 5px;
+ display: table-header-group;
+}
+
+dl.LC_ListStyleClean dd {
+ display: table-row;
+}
+
+.LC_ListStyleClean,
+.LC_ListStyleSimple,
+.LC_ListStyleNormal,
+.LC_ListStyleSpecial {
+ /* display:block; */
+ list-style-position: inside;
+ list-style-type: none;
+ overflow: hidden;
+ padding: 0;
+}
+
+.LC_ListStyleSimple li,
+.LC_ListStyleSimple dd,
+.LC_ListStyleNormal li,
+.LC_ListStyleNormal dd,
+.LC_ListStyleSpecial li,
+.LC_ListStyleSpecial dd {
+ margin: 0;
+ padding: 5px 5px 5px 10px;
+ clear: both;
+}
+
+.LC_ListStyleClean li,
+.LC_ListStyleClean dd {
+ padding-top: 0;
+ padding-bottom: 0;
+}
+
+.LC_ListStyleSimple dd,
+.LC_ListStyleSimple li {
+ border-bottom: solid 1px $lg_border_color;
+}
+
+.LC_ListStyleSpecial li,
+.LC_ListStyleSpecial dd {
+ list-style-type: none;
+ background-color: RGB(220, 220, 220);
+ margin-bottom: 4px;
+}
+
+table.LC_SimpleTable {
+ margin:5px;
+ border:solid 1px $lg_border_color;
+}
+
+table.LC_SimpleTable tr {
+ padding: 0;
+ border:solid 1px $lg_border_color;
+}
+
+table.LC_SimpleTable thead {
+ background:rgb(220,220,220);
+}
+
+div.LC_columnSection {
+ display: block;
+ clear: both;
+ overflow: hidden;
+ margin: 0;
+}
+
+div.LC_columnSection>* {
+ float: left;
+ margin: 10px 20px 10px 0;
+ overflow:hidden;
+}
+
+table em {
+ font-weight: bold;
+ font-style: normal;
+}
+
+table.LC_tableBrowseRes,
+table.LC_tableOfContent {
+ border:none;
+ border-spacing: 1px;
+ padding: 3px;
+ background-color: #FFFFFF;
+ font-size: 90%;
+}
+
+table.LC_tableOfContent {
+ border-collapse: collapse;
+}
+
+table.LC_tableBrowseRes a,
+table.LC_tableOfContent a {
+ background-color: transparent;
+ text-decoration: none;
+}
+
+table.LC_tableOfContent img {
+ border: none;
+ height: 1.3em;
+ vertical-align: text-bottom;
+ margin-right: 0.3em;
+}
+
+a#LC_content_toolbar_firsthomework {
+ background-image:url(/res/adm/pages/open-first-problem.gif);
+}
+
+a#LC_content_toolbar_everything {
+ background-image:url(/res/adm/pages/show-all.gif);
+}
+
+a#LC_content_toolbar_uncompleted {
+ background-image:url(/res/adm/pages/show-incomplete-problems.gif);
+}
+
+#LC_content_toolbar_clearbubbles {
+ background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
+}
+
+a#LC_content_toolbar_changefolder {
+ background : url(/res/adm/pages/close-all-folders.gif) top center ;
+}
+
+a#LC_content_toolbar_changefolder_toggled {
+ background-image:url(/res/adm/pages/open-all-folders.gif);
+}
+
+a#LC_content_toolbar_edittoplevel {
+ background-image:url(/res/adm/pages/edittoplevel.gif);
+}
+
+ul#LC_toolbar li a:hover {
+ background-position: bottom center;
+}
+
+ul#LC_toolbar {
+ padding: 0;
+ margin: 2px;
+ list-style:none;
+ position:relative;
+ background-color:white;
+}
+
+ul#LC_toolbar li {
+ border:1px solid white;
+ padding: 0;
+ margin: 0;
+ float: left;
+ display:inline;
+ vertical-align:middle;
+}
+
+
+a.LC_toolbarItem {
+ display:block;
+ padding: 0;
+ margin: 0;
+ height: 32px;
+ width: 32px;
+ color:white;
+ border: none;
+ background-repeat:no-repeat;
+ background-color:transparent;
+}
+
+ul.LC_funclist {
+ margin: 0;
+ padding: 0.5em 1em 0.5em 0;
+}
+
+ul.LC_funclist > li:first-child {
+ font-weight:bold;
+ margin-left:0.8em;
+}
+
+ul.LC_funclist + ul.LC_funclist {
+ /*
+ left border as a seperator if we have more than
+ one list
+ */
+ border-left: 1px solid $sidebg;
+ /*
+ this hides the left border behind the border of the
+ outer box if element is wrapped to the next 'line'
+ */
+ margin-left: -1px;
+}
+
+ul.LC_funclist li {
+ display: inline;
+ white-space: nowrap;
+ margin: 0 0 0 25px;
+ line-height: 150%;
+}
+
+.LC_hidden {
+ display: none;
+}
+
+.LCmodal-overlay {
+ position:fixed;
+ top:0;
+ right:0;
+ bottom:0;
+ left:0;
+ height:100%;
+ width:100%;
+ margin:0;
+ padding:0;
+ background:#999;
+ opacity:.75;
+ filter: alpha(opacity=75);
+ -moz-opacity: 0.75;
+ z-index:101;
+}
+
+* html .LCmodal-overlay {
+ position: absolute;
+ height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
+}
+
+.LCmodal-window {
+ position:fixed;
+ top:50%;
+ left:50%;
+ margin:0;
+ padding:0;
+ z-index:102;
+ }
+
+* html .LCmodal-window {
+ position:absolute;
+}
+
+.LCclose-window {
+ position:absolute;
+ width:32px;
+ height:32px;
+ right:8px;
+ top:8px;
+ background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
+ text-indent:-99999px;
+ overflow:hidden;
+ cursor:pointer;
+}
+
+END
+}
+
+=pod
+
+=item * &headtag()
+
+Returns a uniform footer for LON-CAPA web pages.
+
+Inputs: $title - optional title for the head
+ $head_extra - optional extra HTML to put inside the
+ $args - optional arguments
+ force_register - if is true call registerurl so the remote is
+ informed
+ redirect -> array ref of
+ 1- seconds before redirect occurs
+ 2- url to redirect to
+ 3- whether the side effect should occur
+ (side effect of setting
+ $env{'internal.head.redirect'} to the url
+ redirected too)
+ domain -> force to color decorate a page for a specific
+ domain
+ function -> force usage of a specific rolish color scheme
+ bgcolor -> override the default page bgcolor
+ no_auto_mt_title
+ -> prevent &mt()ing the title arg
+
+=cut
+
+sub headtag {
+ my ($title,$head_extra,$args) = @_;
- $r->read($buffer,$r->header_in('Content-length'),0);
- unless ($buffer=~/^(\-+\w+)\s+Content\-Disposition\:\s*form\-data/si) {
- my @pairs=split(/&/,$buffer);
- my $pair;
- foreach $pair (@pairs) {
- my ($name,$value) = split(/=/,$pair);
- $value =~ tr/+/ /;
- $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
- $name =~ tr/+/ /;
- $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
- &add_to_env("form.$name",$value);
- }
- } else {
- my $contentsep=$1;
- my @lines = split (/\n/,$buffer);
- my $name='';
- my $value='';
- my $fname='';
- my $fmime='';
- my $i;
- for ($i=0;$i<=$#lines;$i++) {
- if ($lines[$i]=~/^$contentsep/) {
- if ($name) {
- chomp($value);
- if ($fname) {
- $ENV{"form.$name.filename"}=$fname;
- $ENV{"form.$name.mimetype"}=$fmime;
- } else {
- $value=~s/\s+$//s;
- }
- &add_to_env("form.$name",$value);
+ my $function = $args->{'function'} || &get_users_function();
+ my $domain = $args->{'domain'} || &determinedomain();
+ my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
+ my $url = join(':',$env{'user.name'},$env{'user.domain'},
+ $Apache::lonnet::perlvar{'lonVersion'},
+ #time(),
+ $env{'environment.color.timestamp'},
+ $function,$domain,$bgcolor);
+
+ $url = '/adm/css/'.&escape($url).'.css';
+
+ my $result =
+ ''.
+ &font_settings();
+
+ my $inhibitprint = &print_suppression();
+
+ if (!$args->{'frameset'}) {
+ $result .= &Apache::lonhtmlcommon::htmlareaheaders();
+ }
+ if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
+ $result .= Apache::lonxml::display_title();
+ }
+ if (!$args->{'no_nav_bar'}
+ && !$args->{'only_body'}
+ && !$args->{'frameset'}) {
+ $result .= &help_menu_js();
+ $result.=&modal_window();
+ $result.=&togglebox_script();
+ $result.=&wishlist_window();
+ $result.=&LCprogressbarUpdate_script();
+ } else {
+ if ($args->{'add_modal'}) {
+ $result.=&modal_window();
+ }
+ if ($args->{'add_wishlist'}) {
+ $result.=&wishlist_window();
+ }
+ if ($args->{'add_togglebox'}) {
+ $result.=&togglebox_script();
+ }
+ if ($args->{'add_progressbar'}) {
+ $result.=&LCprogressbarUpdate_script();
+ }
+ }
+ if (ref($args->{'redirect'})) {
+ my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
+ $url = &Apache::lonenc::check_encrypt($url);
+ if (!$inhibit_continue) {
+ $env{'internal.head.redirect'} = $url;
+ }
+ $result.=<
+
+ADDMETA
+ }
+ if (!defined($title)) {
+ $title = 'The LearningOnline Network with CAPA';
+ }
+ if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
+ $result .= ' LON-CAPA '.$title.' '
+ .' '
+ .$inhibitprint
+ .$head_extra;
+ return $result.'';
+}
+
+=pod
+
+=item * &font_settings()
+
+Returns neccessary to set the proper encoding
+
+Inputs: none
+
+=cut
+
+sub font_settings {
+ my $headerstring='';
+ if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
+ $headerstring.=
+ ' ';
+ }
+ return $headerstring;
+}
+
+=pod
+
+=item * &print_suppression()
+
+In course context returns css which causes the body to be blank when media="print",
+if printout generation is unavailable for the current resource.
+
+This could be because:
+
+(a) printstartdate is in the future
+
+(b) printenddate is in the past
+
+(c) there is an active exam block with "printout"
+functionality blocked
+
+Users with pav, pfo or evb privileges are exempt.
+
+Inputs: none
+
+=cut
+
+
+sub print_suppression {
+ my $noprint;
+ if ($env{'request.course.id'}) {
+ my $scope = $env{'request.course.id'};
+ if ((&Apache::lonnet::allowed('pav',$scope)) ||
+ (&Apache::lonnet::allowed('pfo',$scope))) {
+ return;
+ }
+ if ($env{'request.course.sec'} ne '') {
+ $scope .= "/$env{'request.course.sec'}";
+ if ((&Apache::lonnet::allowed('pav',$scope)) ||
+ (&Apache::lonnet::allowed('pfo',$scope))) {
+ return;
+ }
+ }
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $blocked = &blocking_status('printout',$cnum,$cdom);
+ if ($blocked) {
+ my $checkrole = "cm./$cdom/$cnum";
+ if ($env{'request.course.sec'} ne '') {
+ $checkrole .= "/$env{'request.course.sec'}";
+ }
+ unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
+ ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
+ $noprint = 1;
+ }
+ }
+ unless ($noprint) {
+ my $symb = &Apache::lonnet::symbread();
+ if ($symb ne '') {
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ my $res = $navmap->getBySymb($symb);
+ if (ref($res)) {
+ if (!$res->resprintable()) {
+ $noprint = 1;
+ }
+ }
+ }
+ }
+ }
+ if ($noprint) {
+ return <<"ENDSTYLE";
+
+ENDSTYLE
+ }
+ }
+ return;
+}
+
+=pod
+
+=item * &xml_begin()
+
+Returns the needed doctype and
+
+Inputs: none
+
+=cut
+
+sub xml_begin {
+ my $output='';
+
+ if ($env{'browser.mathml'}) {
+ $output=''
+ #.''."\n"
+# .'] >'
+ .''
+ .'';
+ } else {
+ $output=''
+ .'';
+ }
+ return $output;
+}
+
+=pod
+
+=item * &start_page()
+
+Returns a complete .. section for LON-CAPA web pages.
+
+Inputs:
+
+=over 4
+
+$title - optional title for the page
+
+$head_extra - optional extra HTML to incude inside the
+
+$args - additional optional args supported are:
+
+=over 8
+
+ only_body -> is true will set &bodytag() onlybodytag
+ arg on
+ no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
+ add_entries -> additional attributes to add to the
+ domain -> force to color decorate a page for a
+ specific domain
+ function -> force usage of a specific rolish color
+ scheme
+ redirect -> see &headtag()
+ bgcolor -> override the default page bg color
+ js_ready -> return a string ready for being used in
+ a javascript writeln
+ html_encode -> return a string ready for being used in
+ a html attribute
+ force_register -> if is true will turn on the &bodytag()
+ $forcereg arg
+ frameset -> if true will start with a
+ rather than
+ skip_phases -> hash ref of
+ head -> skip the generation
+ body -> skip all generation
+ no_auto_mt_title -> prevent &mt()ing the title arg
+ inherit_jsmath -> when creating popup window in a page,
+ should it have jsmath forced on by the
+ current page
+ bread_crumbs -> Array containing breadcrumbs
+ bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
+
+=back
+
+=back
+
+=cut
+
+sub start_page {
+ my ($title,$head_extra,$args) = @_;
+ #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
+
+ $env{'internal.start_page'}++;
+ my $result;
+
+ if (! exists($args->{'skip_phases'}{'head'}) ) {
+ $result .= &xml_begin() . &headtag($title, $head_extra, $args);
+ }
+
+ if (! exists($args->{'skip_phases'}{'body'}) ) {
+ if ($args->{'frameset'}) {
+ my $attr_string = &make_attr_string($args->{'force_register'},
+ $args->{'add_entries'});
+ $result .= "\n\n";
+ } else {
+ $result .=
+ &bodytag($title,
+ $args->{'function'}, $args->{'add_entries'},
+ $args->{'only_body'}, $args->{'domain'},
+ $args->{'force_register'}, $args->{'no_nav_bar'},
+ $args->{'bgcolor'}, $args);
+ }
+ }
+
+ if ($args->{'js_ready'}) {
+ $result = &js_ready($result);
+ }
+ if ($args->{'html_encode'}) {
+ $result = &html_encode($result);
+ }
+
+ # Preparation for new and consistent functionlist at top of screen
+ # if ($args->{'functionlist'}) {
+ # $result .= &build_functionlist();
+ #}
+
+ # Don't add anything more if only_body wanted or in const space
+ return $result if $args->{'only_body'}
+ || $env{'request.state'} eq 'construct';
+
+ #Breadcrumbs
+ if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ #if any br links exists, add them to the breadcrumbs
+ if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
+ foreach my $crumb (@{$args->{'bread_crumbs'}}){
+ &Apache::lonhtmlcommon::add_breadcrumb($crumb);
+ }
}
- if ($i<$#lines) {
- $i++;
- $lines[$i]=~
- /Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
- $name=$1;
- $value='';
- if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
- $fname=$1;
- if
- ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
- $fmime=$1;
- $i++;
- } else {
- $fmime='';
- }
- } else {
- $fname='';
- $fmime='';
- }
- $i++;
+
+ #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
+ if(exists($args->{'bread_crumbs_component'})){
+ $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
+ }else{
+ $result .= &Apache::lonhtmlcommon::breadcrumbs();
}
- } else {
- $value.=$lines[$i]."\n";
+ }
+ return $result;
+}
+
+sub end_page {
+ my ($args) = @_;
+ $env{'internal.end_page'}++;
+ my $result;
+ if ($args->{'discussion'}) {
+ my ($target,$parser);
+ if (ref($args->{'discussion'})) {
+ ($target,$parser) =($args->{'discussion'}{'target'},
+ $args->{'discussion'}{'parser'});
+ }
+ $result .= &Apache::lonxml::xmlend($target,$parser);
+ }
+ if ($args->{'frameset'}) {
+ $result .= ' ';
+ } else {
+ $result .= &endbodytag($args);
+ }
+ $result .= "\n";
+
+ if ($args->{'js_ready'}) {
+ $result = &js_ready($result);
+ }
+
+ if ($args->{'html_encode'}) {
+ $result = &html_encode($result);
+ }
+
+ return $result;
+}
+
+sub wishlist_window {
+ return(<<'ENDWISHLIST');
+
+ENDWISHLIST
+}
+
+sub modal_window {
+ return(<<'ENDMODAL');
+
+ENDMODAL
+}
+
+sub modal_link {
+ my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
+ unless ($width) { $width=480; }
+ unless ($height) { $height=400; }
+ unless ($scrolling) { $scrolling='yes'; }
+ return ''.
+ $linktext.' ';
+}
+
+sub modal_adhoc_script {
+ my ($funcname,$width,$height,$content)=@_;
+ return (<
+//
+
+ENDADHOC
+}
+
+sub modal_adhoc_inner {
+ my ($funcname,$width,$height,$content)=@_;
+ my $innerwidth=$width-20;
+ $content=&js_ready(
+ &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
+ &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
+ $content.
+ &end_scrollbox().
+ &end_page()
+ );
+ return &modal_adhoc_script($funcname,$width,$height,$content);
+}
+
+sub modal_adhoc_window {
+ my ($funcname,$width,$height,$content,$linktext)=@_;
+ return &modal_adhoc_inner($funcname,$width,$height,$content).
+ "".$linktext." ";
+}
+
+sub modal_adhoc_launch {
+ my ($funcname,$width,$height,$content)=@_;
+ return &modal_adhoc_inner($funcname,$width,$height,$content).(<
+//
+
+ENDLAUNCH
+}
+
+sub modal_adhoc_close {
+ return (<
+//
+
+ENDCLOSE
+}
+
+sub togglebox_script {
+ return(<
+//
+
+ENDTOGGLE
+}
+
+sub start_togglebox {
+ my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
+ unless ($heading) { $heading=''; } else { $heading.=' '; }
+ unless ($showtext) { $showtext=&mt('show'); }
+ unless ($hidetext) { $hidetext=&mt('hide'); }
+ unless ($headerbg) { $headerbg='#FFFFFF'; }
+ return &start_data_table().
+ &start_data_table_header_row().
+ ''.$heading.
+ '['.$showtext.' ] '.
+ &end_data_table_header_row().
+ '';
+}
+
+sub end_togglebox {
+ return ' '.&end_data_table();
+}
+
+sub LCprogressbar_script {
+ my ($id)=@_;
+ return(<
+//
+
+ENDPROGRESS
+}
+
+sub LCprogressbarUpdate_script {
+ return(<
+.ui-progressbar { position:relative; }
+.pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
+
+
+ENDPROGRESSUPDATE
+}
+
+my $LClastpercent;
+my $LCidcnt;
+my $LCcurrentid;
+
+sub LCprogressbar {
+ my ($r)=(@_);
+ $LClastpercent=0;
+ $LCidcnt++;
+ $LCcurrentid=$$.'_'.$LCidcnt;
+ my $starting=&mt('Starting');
+ my $content=(<
+
+ $starting
+
+
+ENDPROGBAR
+ &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
+}
+
+sub LCprogressbarUpdate {
+ my ($r,$val,$text)=@_;
+ unless ($val) {
+ if ($LClastpercent) {
+ $val=$LClastpercent;
+ } else {
+ $val=0;
+ }
+ }
+ if ($val<0) { $val=0; }
+ if ($val>100) { $val=0; }
+ $LClastpercent=$val;
+ unless ($text) { $text=$val.'%'; }
+ $text=&js_ready($text);
+ &r_print($r,<
+//
+
+ENDUPDATE
+}
+
+sub LCprogressbarClose {
+ my ($r)=@_;
+ $LClastpercent=0;
+ &r_print($r,<
+//
+
+ENDCLOSE
+}
+
+sub r_print {
+ my ($r,$to_print)=@_;
+ if ($r) {
+ $r->print($to_print);
+ $r->rflush();
+ } else {
+ print($to_print);
+ }
+}
+
+sub html_encode {
+ my ($result) = @_;
+
+ $result = &HTML::Entities::encode($result,'<>&"');
+
+ return $result;
+}
+
+sub js_ready {
+ my ($result) = @_;
+
+ $result =~ s/[\n\r]/ /xmsg;
+ $result =~ s/\\/\\\\/xmsg;
+ $result =~ s/'/\\'/xmsg;
+ $result =~ s{}{<\\/}xmsg;
+
+ return $result;
+}
+
+sub validate_page {
+ if ( exists($env{'internal.start_page'})
+ && $env{'internal.start_page'} > 1) {
+ &Apache::lonnet::logthis('start_page called multiple times '.
+ $env{'internal.start_page'}.' '.
+ $ENV{'request.filename'});
+ }
+ if ( exists($env{'internal.end_page'})
+ && $env{'internal.end_page'} > 1) {
+ &Apache::lonnet::logthis('end_page called multiple times '.
+ $env{'internal.end_page'}.' '.
+ $env{'request.filename'});
+ }
+ if ( exists($env{'internal.start_page'})
+ && ! exists($env{'internal.end_page'})) {
+ &Apache::lonnet::logthis('start_page called without end_page '.
+ $env{'request.filename'});
+ }
+ if ( ! exists($env{'internal.start_page'})
+ && exists($env{'internal.end_page'})) {
+ &Apache::lonnet::logthis('end_page called without start_page'.
+ $env{'request.filename'});
+ }
+}
+
+
+sub start_scrollbox {
+ my ($outerwidth,$width,$height,$id)=@_;
+ unless ($outerwidth) { $outerwidth='520px'; }
+ unless ($width) { $width='500px'; }
+ unless ($height) { $height='200px'; }
+ my ($table_id,$div_id);
+ if ($id ne '') {
+ $table_id = " id='table_$id'";
+ $div_id = " id='div_$id'";
+ }
+ return "";
+}
+
+sub end_scrollbox {
+ return '
';
+}
+
+sub simple_error_page {
+ my ($r,$title,$msg) = @_;
+ my $page =
+ &Apache::loncommon::start_page($title).
+ &mt($msg).
+ &Apache::loncommon::end_page();
+ if (ref($r)) {
+ $r->print($page);
+ return;
+ }
+ return $page;
+}
+
+{
+ my @row_count;
+
+ sub start_data_table_count {
+ unshift(@row_count, 0);
+ return;
+ }
+
+ sub end_data_table_count {
+ shift(@row_count);
+ return;
+ }
+
+ sub start_data_table {
+ my ($add_class,$id) = @_;
+ my $css_class = (join(' ','LC_data_table',$add_class));
+ my $table_id;
+ if (defined($id)) {
+ $table_id = ' id="'.$id.'"';
+ }
+ &start_data_table_count();
+ return ''."\n";
+ }
+
+ sub end_data_table {
+ &end_data_table_count();
+ return '
'."\n";;
+ }
+
+ sub start_data_table_row {
+ my ($add_class, $id) = @_;
+ $row_count[0]++;
+ my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
+ $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
+ $id = (' id="'.$id.'"') unless ($id eq '');
+ return ''."\n";
+ }
+
+ sub continue_data_table_row {
+ my ($add_class, $id) = @_;
+ my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
+ $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
+ $id = (' id="'.$id.'"') unless ($id eq '');
+ return ' '."\n";
+ }
+
+ sub end_data_table_row {
+ return ' '."\n";;
+ }
+
+ sub start_data_table_empty_row {
+# $row_count[0]++;
+ return ''."\n";;
+ }
+
+ sub end_data_table_empty_row {
+ return ' '."\n";;
+ }
+
+ sub start_data_table_header_row {
+ return ''."\n";;
+ }
+
+ sub data_table_caption {
+ my $caption = shift;
+ return "$caption ";
+ }
+}
+
+=pod
+
+=item * &inhibit_menu_check($arg)
+
+Checks for a inhibitmenu state and generates output to preserve it
+
+Inputs: $arg - can be any of
+ - undef - in which case the return value is a string
+ to add into arguments list of a uri
+ - 'input' - in which case the return value is a HTML
+