--- loncom/interface/lonmenu.pm 2003/04/18 00:02:34 1.62
+++ loncom/interface/lonmenu.pm 2023/10/08 15:21:48 1.369.2.83.2.12
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.62 2003/04/18 00:02:34 www Exp $
+# $Id: lonmenu.pm,v 1.369.2.83.2.12 2023/10/08 15:21:48 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,389 +26,1542 @@
# http://www.lon-capa.org/
#
#
-# There are two parameters controlling the action of this module:
-#
-# browser.interface - if this is 'textual', it overrides the second parameter
-# and goes to screen reader PDA mode
-#
-# environment.remote - if this is 'on', the routines controll the remote
-# control, otherwise they render the main window controls; ignored it
-# browser.interface is 'textual'
-#
+
+=head1 NAME
+
+Apache::lonmenu
+
+=head1 SYNOPSIS
+
+Loads contents of /home/httpd/lonTabs/mydesk.tab,
+used to generate inline menu, and Main Menu page.
+
+This is part of the LearningOnline Network with CAPA project
+described at http://www.lon-capa.org.
+
+=head1 GLOBAL VARIABLES
+
+=over
+
+=item @desklines
+
+Each element of this array contains a line of mydesk.tab that doesn't start with
+cat, prim or scnd.
+It gets filled in the BEGIN block of this module.
+
+=item %category_names
+
+The keys of this hash are the abbreviations used in mydesk.tab in those lines that
+start with cat, the values are strings representing titles.
+It gets filled in the BEGIN block of this module.
+
+=item %category_members
+
+TODO
+
+=item %category_positions
+
+The keys of this hash are the abbreviations used in mydesk.tab in those lines that
+start with cat, its values are position vectors (column, row).
+It gets filled in the BEGIN block of this module.
+
+=item $readdesk
+
+Indicates that mydesk.tab has been read.
+It is set to 'done' in the BEGIN block of this module.
+
+=item @primary_menu
+
+The elements of this array reference arrays that are made up of the components
+of those lines of mydesk.tab that start with prim:.
+It is used by primary_menu() to generate the corresponding menu.
+It gets filled in the BEGIN block of this module.
+
+=item %primary_sub_menu
+
+The keys of this hash reference are the names of items in the primary_menu array
+which have sub-menus. For each key, the corresponding value is a reference to
+an array containing components extracted from lines in mydesk.tab which begin
+with primsub:.
+This hash, which is used by primary_menu to generate sub-menus, is populated in
+the BEGIN block.
+
+=item @secondary_menu
+
+The elements of this array reference arrays that are made up of the components
+of those lines of mydesk.tab that start with scnd.
+It is used by secondary_menu() to generate the corresponding menu.
+It gets filled in the BEGIN block of this module.
+
+=back
+
+=head1 SUBROUTINES
+
+=over
+
+=item prep_menuitems(\@menuitem,$target,$listclass,$linkattr)
+
+This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
+secondary_menu().
+
+=item primary_menu()
+
+This routine evaluates @primary_menu and returns a two item array,
+with the array elements containing XHTML for the left and right sides of
+the menu that contains the following links: About, Message, Roles, Help, Logout
+@primary_menu is filled within the BEGIN block of this module with
+entries from mydesk.tab
+
+=item secondary_menu()
+
+Same as primary_menu() but operates on @secondary_menu.
+
+=item create_submenu()
+
+Creates XHTML for unordered list of sub-menu items which belong to a
+particular top-level menu item. Uses hover pseudo class in css to display
+dropdown list when mouse hovers over top-level item. Support for IE6
+(no hover psuedo class) via LC_hoverable class for
tag for top-
+level item, which employs jQuery to handle behavior on mouseover.
+
+Inputs: 6 - (a) link and (b) target for anchor href in top level item,
+ (c) title for text wrapped by anchor tag in top level item.
+ (d) reference to array of arrays of sub-menu items.
+ (e) boolean to indicate whether to call &mt() to translate
+ name of menu item,
+ (f) optional class for
element in primary menu, for which
+ sub menu is being generated.
+
+The underlying datastructure used in (d) contains data from mydesk.tab.
+It consists of an array which has an array for each item appearing in
+the menu (e.g. [["link", "title", "condition"]] for a single-item menu).
+create_submenu() supports also the creation of XHTML for nested dropdown
+menus represented by unordered lists. This is done by replacing the
+scalar used for the link with an arrayreference containing the menuitems
+for the nested menu. This can be done recursively so that the next menu
+may also contain nested submenus.
+
+ Example:
+ [ # begin of datastructure
+ ["/home/", "Home", "condition1"], # 1st item of the 1st layer menu
+ [ # 2nd item of the 1st layer menu
+ [ # anon. array for nested menu
+ ["/path1", "Path1", undef], # 1st item of the 2nd layer menu
+ ["/path2", "Path2", undef], # 2nd item of the 2nd layer menu
+ [ # 3rd item of the 2nd layer menu
+ [[...], [...], ..., [...]], # containing another menu layer
+ "Sub-Sub-Menu", # title for this container
+ undef
+ ]
+ ], # end of array/nested menu
+ "Sub-Menu", # title for the container item
+ undef
+ ] # end of 2nd item of the 1st layer menu
+]
+
+
+=item innerregister()
+
+This gets called in order to register a URL in the body of the document
+
+=item loadevents()
+
+=item unloadevents()
+
+=item startupremote()
+
+=item setflags()
+
+=item maincall()
+
+=item load_remote_msg()
+
+=item get_menu_name()
+
+=item reopenmenu()
+
+=item open()
+
+Open the menu
+
+=item clear()
+
+=item switch()
+
+Switch a button or create a link
+Switch acts on the javascript that is executed when a button is clicked.
+The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)".
+
+=item secondlevel()
+
+=item openmenu()
+
+=item inlinemenu()
+
+=item rawconfig()
+
+=item utilityfunctions()
+
+Output from this routine is a number of javascript functions called by
+items in the inline menu, and in some cases items in the Main Menu page.
+
+=item serverform()
+
+=item constspaceform()
+
+=item get_nav_status()
+
+=item hidden_button_check()
+
+=item roles_selector()
+
+=item jump_to_role()
+
+=back
+
+=cut
package Apache::lonmenu;
use strict;
use Apache::lonnet;
-use Apache::Constants qw(:common);
use Apache::lonhtmlcommon();
-use Apache::loncommon;
-use Apache::File;
-use vars qw(@desklines $readdesk);
+use Apache::loncommon();
+use Apache::lonenc();
+use Apache::lonlocal;
+use Apache::lonmsg();
+use LONCAPA qw(:DEFAULT :match);
+use HTML::Entities();
+use Apache::lonwishlist();
+
+use vars qw(@desklines %category_names %category_members %category_positions
+ $readdesk @primary_menu %primary_submenu @secondary_menu %secondary_submenu);
+
my @inlineremote;
-my $font;
-my $tabbg;
-my $pgbg;
-
-# ============================= This gets called at the top of the body section
-
-sub menubuttons {
- my $forcereg=shift;
- my $target =shift;
- my $registration=shift;
- my $navmaps='';
- my $reloadlink='';
- my $escurl=&Apache::lonnet::escape($ENV{'REQUEST_URI'});
- my $escsymb=&Apache::lonnet::escape($ENV{'request.symb'});
- if ($ENV{'browser.interface'} eq 'textual') {
-# Textual display only
- if ($ENV{'request.course.id'}) {
- $navmaps=(<Navigate Contents
-ENDNAV
- if (($ENV{'REQUEST_URI'}=~/^\/adm\//) &&
- ($ENV{'REQUEST_URI'}!~/^\/adm\/wrapper\//) &&
- ($ENV{'REQUEST_URI'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
- my $escreload=&Apache::lonnet::escape('return:');
- $reloadlink=(<Return to Last Location
-ENDRELOAD
+
+sub prep_menuitem {
+ my ($menuitem,$target,$listclass,$linkattr) = @_;
+ return '' unless(ref($menuitem) eq 'ARRAY');
+ my ($link,$targetattr);
+ if ($$menuitem[1]) { # graphical Link
+ $link = "";
+ } else { # textual Link
+ $link = &mt($$menuitem[3]);
+ }
+ if ($target ne '') {
+ $targetattr = ' target="'.$target.'"';
+ }
+ return ($listclass?'
|;
+}
+
+# primary_menu() evaluates @primary_menu and returns a two item array,
+# with the array elements containing XHTML for the left and right sides of
+# the menu that contains the following links:
+# Personal, About, Message, Roles, Help, Logout
+# @primary_menu is filled within the BEGIN block of this module with
+# entries from mydesk.tab
+sub primary_menu {
+ my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target) = @_;
+ my (%menu,%ltiexc,%menuopts);
+ # each element of @primary contains following array:
+ # (link url, icon path, alt text, link text, condition, position)
+ my $public;
+ if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
+ || (($env{'user.name'} eq '') && ($env{'user.domain'} eq ''))) {
+ $public = 1;
+ }
+ my $lti;
+ if ($env{'request.lti.login'}) {
+ $lti = 1;
+ if (ref($ltimenu) eq 'HASH') {
+ foreach my $item ('fullname','logout') {
+ unless ($ltimenu->{$item}) {
+ $ltiexc{$item} = 1;
+ }
}
}
- my $output=(<
-// BEGIN LON-CAPA Internal
-
-Main Menu
-$reloadlink $navmaps
-
-ENDMAINMENU
- if ($registration) { $output.=&innerregister($forcereg,$target); }
- return $output."";
- } elsif ($ENV{'environment.remote'} eq 'off') {
-# Remote Control is switched off
-# figure out colors
- my $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 $domain=&Apache::loncommon::determinedomain();
- $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain);
- $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain);
- $font=&Apache::loncommon::designparm($function.'.font',$domain);
- my $link=&Apache::loncommon::designparm($function.'.link',$domain);
- my $alink=&Apache::loncommon::designparm($function.'.alink',$domain);
- my $vlink=&Apache::loncommon::designparm($function.'.vlink',$domain);
- my $sidebg=&Apache::loncommon::designparm($function.'.sidebg',$domain);
-# Do we have a NAV link?
- if ($ENV{'request.course.id'}) {
- $navmaps=(<
-Navigate Contents
-ENDNAVREM
- if (($ENV{'REQUEST_URI'}=~/^\/adm\//) &&
- ($ENV{'REQUEST_URI'}!~/^\/adm\/wrapper\//) &&
- ($ENV{'REQUEST_URI'}!~/^\/adm\/.*\/(smppg|bulletinboard|aboutme)(\?|$)/)) {
- my $escreload=&Apache::lonnet::escape('return:');
- $reloadlink=(<
-Return to Last Location
-ENDRELOAD
- }
- }
- my $reg='';
- if ($registration) {
- $reg=&innerregister($forcereg,$target);
+ }
+ my ($listclass,$linkattr,$target);
+ if ($links_disabled) {
+ $listclass = 'LCisDisabled';
+ $linkattr = 'aria-disabled="true"';
+ }
+ if ($links_target ne '') {
+ $target = $links_target;
+ } else {
+ my ($ltitarget,$deeplinktarget);
+ if ($env{'request.lti.login'}) {
+ $ltitarget = $env{'request.lti.target'};
}
- return (<
-// BEGIN LON-CAPA Internal
-
-
';
+
+ # $link and $title are only used in the initial string written in $menu
+ # as seen above, not needed for nested submenus
+ $menu .= &build_submenu($target, $submenu, $translate, '1', $listclass, $linkattr);
+ $menu .= '
';
+
+ return $menu;
+}
+
+# helper routine for create_submenu
+# build the dropdown (and nested submenus) recursively
+# see perldoc create_submenu documentation for further information
+sub build_submenu {
+ my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_;
+ unless (@{$submenu}) {
+ return '';
+ }
+
+ my $menu = '';
+ my $count = 0;
+ my $numsub = scalar(@{$submenu});
+ foreach my $item (@{$submenu}) {
+ $count ++;
+ if (ref($item) eq 'ARRAY') {
+ my $href = $item->[0];
+ my $bordertop;
+ my $borderbot;
+ my $title;
+
+ if ($translate) {
+ $title = &mt($item->[1]);
+ } else {
+ $title = $item->[1];
+ }
+
+ if ($count == 1 && !$first_level) {
+ $bordertop = 'border-top: 1px solid black;';
+ }
+ if ($count == $numsub) {
+ $borderbot = 'border-bottom: 1px solid black;';
+ }
+
+ # href is a reference to another submenu
+ if (ref($href) eq 'ARRAY') {
+ $menu .= '
';
+ }
+ } else {
+# Inline Menu
+ my @tools = (93,91,81,82,83);
+ unless ($env{'request.state'} eq 'construct') {
+ push(@tools,63);
+ }
+ if ((($env{'environment.icons'} eq 'iconsonly') ||
+ ($env{'environment.icons'} eq '') && ($env{'request.lti.login'})) &&
+ (grep(/^$idx$/,@tools))) {
+ $inlineremote[$idx] =
+ ''.$pic.'';
+ } else {
+ $inlineremote[$idx] =
+ ''.$pic.
+ ''.$top.' ';
+ }
+ }
return '';
}
sub secondlevel {
my $output='';
my
- ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc)=@_;
+ ($uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat)=@_;
if ($prt eq 'any') {
- $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
} elsif ($prt=~/^r(\w+)/) {
if ($rol eq $1) {
- $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
}
}
return $output;
}
sub openmenu {
- my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
- if (($ENV{'browser.interface'} eq 'textual') ||
- ($ENV{'environment.remote'} eq 'off')) { return ''; }
+ my $menuname = &get_menu_name();
+ unless ($env{'environment.remote'} eq 'on') { return ''; }
my $nothing = &Apache::lonhtmlcommon::javascript_nothing();
return "window.open(".$nothing.",'".$menuname."');";
}
sub inlinemenu {
- @inlineremote=();
- undef @inlineremote;
+ undef(@inlineremote);
+ undef(%category_members);
+# calling rawconfig with "1" will evaluate mydesk.tab, even if there is no active remote control
&rawconfig(1);
- return join('',map { (defined($_)?$_:'') } @inlineremote);
+ my $output='
';
+ for (my $col=1; $col<=2; $col++) {
+ $output.='
';
+ for (my $row=1; $row<=8; $row++) {
+ foreach my $cat (keys(%category_members)) {
+ if ($category_positions{$cat} ne "$col,$row") { next; }
+ #$output.='
'.&mt($category_names{$cat}).'
';
+ $output.='
';
+ $output.='
'.&mt($category_names{$cat}).'
';
+ $output.='
';
+ my %active=();
+ foreach my $menu_item (split(/\:/,$category_members{$cat})) {
+ if ($inlineremote[$menu_item]) {
+ $active{$menu_item}=1;
+ }
+ }
+ foreach my $item (sort(keys(%active))) {
+ $output.=$inlineremote[$item];
+ }
+ $output.='
';
+ $output.='
';
+ }
+ }
+ $output.="";
+ }
+ $output.="
";
+ return $output;
}
sub rawconfig {
+#
+# This evaluates mydesk.tab
+# Need to add more positions and more privileges to deal with all
+# menu items.
+#
my $textualoverride=shift;
my $output='';
- unless (($ENV{'browser.interface'} eq 'textual') ||
- ($ENV{'environment.remote'} eq 'off')) {
+ if ($env{'environment.remote'} eq 'on') {
$output.=
"window.status='Opening Remote Control';var swmenu=".&openmenu().
"\nwindow.status='Configuring Remote Control ';";
} else {
- unless ($textualoverride) { return ''; }
+ unless ($textualoverride) { return ''; }
}
- my $uname=$ENV{'user.name'};
- my $udom=$ENV{'user.domain'};
- my $adv=$ENV{'user.adv'};
- my $author=$ENV{'user.author'};
+ my $uname=$env{'user.name'};
+ my $udom=$env{'user.domain'};
+ my $adv=$env{'user.adv'};
+ my $show_course=&Apache::loncommon::show_course();
+ my $author=$env{'user.author'};
my $crs='';
- if ($ENV{'request.course.id'}) {
- $crs='/'.$ENV{'request.course.id'};
- if ($ENV{'request.course.sec'}) {
- $crs.='_'.$ENV{'request.course.sec'};
+ my $crstype='';
+ if ($env{'request.course.id'}) {
+ $crs='/'.$env{'request.course.id'};
+ if ($env{'request.course.sec'}) {
+ $crs.='_'.$env{'request.course.sec'};
}
$crs=~s/\_/\//g;
+ $crstype = &Apache::loncommon::course_type();
}
- my $pub=($ENV{'request.state'} eq 'published');
- my $con=($ENV{'request.state'} eq 'construct');
- my $rol=$ENV{'request.role'};
- my $requested_domain = $ENV{'request.role.domain'};
- foreach (@desklines) {
- my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc)=split(/\:/,$_);
+ my $pub=($env{'request.state'} eq 'published');
+ my $con=($env{'request.state'} eq 'construct');
+ my $rol=$env{'request.role'};
+ my $requested_domain;
+ if ($rol) {
+ $requested_domain = $env{'request.role.domain'};
+ }
+ foreach my $line (@desklines) {
+ my ($row,$col,$pro,$prt,$img,$top,$bot,$act,$desc,$cat)=split(/\:/,$line);
$prt=~s/\$uname/$uname/g;
$prt=~s/\$udom/$udom/g;
- $prt=~s/\$crs/$crs/g;
- $prt=~s/\$requested_domain/$requested_domain/g;
+ if ($prt =~ /\$crs/) {
+ next unless ($env{'request.course.id'});
+ next if ($crstype eq 'Community');
+ $prt=~s/\$crs/$crs/g;
+ } elsif ($prt =~ /\$cmty/) {
+ next unless ($env{'request.course.id'});
+ next if ($crstype ne 'Community');
+ $prt=~s/\$cmty/$crs/g;
+ }
+ if ($prt =~ m/\$requested_domain/) {
+ if ((!$requested_domain) && ($pro eq 'pbre') && ($env{'user.adv'})) {
+ $prt=~s/\$requested_domain/$env{'user.domain'}/g;
+ } else {
+ $prt=~s/\$requested_domain/$requested_domain/g;
+ }
+ }
+ if ($category_names{$cat}!~/\w/) { $cat='oth'; }
if ($pro eq 'clear') {
$output.=&clear($row,$col);
} elsif ($pro eq 'any') {
$output.=&secondlevel(
- $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
} elsif ($pro eq 'smp') {
unless ($adv) {
$output.=&secondlevel(
- $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
}
} elsif ($pro eq 'adv') {
if ($adv) {
$output.=&secondlevel(
- $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc);
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif ($pro eq 'shc') {
+ if ($show_course) {
+ $output.=&secondlevel(
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif ($pro eq 'nsc') {
+ if (!$show_course) {
+ $output.=&secondlevel(
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif (($pro=~/^p(\w+)/) && ($prt)) {
+ my $priv = $1;
+ if ($priv =~ /^mdc(Course|Community)/) {
+ if ($crstype eq $1) {
+ $priv = 'mdc';
+ } else {
+ next;
+ }
+ }
+ if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) ||
+ (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
}
- } elsif (($pro=~/p(\w+)/) && ($prt)) {
- if (&Apache::lonnet::allowed($1,$prt)) {
- $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
- }
- } elsif ($pro eq 'course') {
- if ($ENV{'request.course.fn'}) {
- $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc);
+ } elsif ($pro eq 'course') {
+ if (($env{'request.course.fn'}) && ($crstype ne 'Community')) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
}
+ } elsif ($pro eq 'community') {
+ if (($env{'request.course.fn'}) && ($crstype eq 'Community')) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif ($pro =~ /^courseenv_(.*)$/) {
+ my $key = $1;
+ if ($crstype ne 'Community') {
+ my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
+ if ($key eq 'canuse_pdfforms') {
+ if ($env{'request.course.id'} && $coursepref eq '') {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+ $coursepref = $domdefs{'canuse_pdfforms'};
+ }
+ }
+ if ($coursepref) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
+ }
+ } elsif ($pro =~ /^communityenv_(.*)$/) {
+ my $key = $1;
+ if ($crstype eq 'Community') {
+ my $coursepref = $env{'course.'.$env{'request.course.id'}.'.'.$key};
+ if ($key eq 'canuse_pdfforms') {
+ if ($env{'request.course.id'} && $coursepref eq '') {
+ my %domdefs = &Apache::lonnet::get_domain_defaults($env{'course.'.$env{'request.course.id'}.'.domain'});
+ $coursepref = $domdefs{'canuse_pdfforms'};
+ }
+ }
+ if ($coursepref) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
+ }
+ } elsif ($pro =~ /^course_(.*)$/) {
+ # Check for permissions inside of a course
+ if (($env{'request.course.id'}) && ($crstype ne 'Community') &&
+ (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
+ )) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
+ } elsif ($pro =~ /^community_(.*)$/) {
+ # Check for permissions inside of a community
+ if (($env{'request.course.id'}) && ($crstype eq 'Community') &&
+ (&Apache::lonnet::allowed($1,$env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))
+ )) {
+ $output.=&switch($uname,$udom,$row,$col,$img,$top,$bot,$act,$desc,$cat);
+ }
} elsif ($pro eq 'author') {
if ($author) {
- if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
- (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
+ if ((($prt eq 'rca') && ($env{'request.role'}=~/^ca/)) ||
+ (($prt eq 'raa') && ($env{'request.role'}=~/^aa/)) ||
+ (($prt eq 'rau') && ($env{'request.role'}=~/^au/))) {
# Check that we are on the correct machine
my $cadom=$requested_domain;
- my $caname=$ENV{'user.name'};
- if ($prt eq 'rca') {
+ my $caname=$env{'user.name'};
+ if (($prt eq 'rca') || ($prt eq 'raa')) {
($cadom,$caname)=
- ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
+ ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
}
$act =~ s/\$caname/$caname/g;
+ $act =~ s/\$cadom/$cadom/g;
my $home = &Apache::lonnet::homeserver($caname,$cadom);
- if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
- $output.=switch($caname,$cadom,
- $row,$col,$img,$top,$bot,$act,$desc);
+ my $allowed=0;
+ my @ids=&Apache::lonnet::current_machine_ids();
+ foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
+ if ($allowed) {
+ $output.=&switch($caname,$cadom,
+ $row,$col,$img,$top,$bot,$act,$desc,$cat);
}
}
}
+ } elsif ($pro eq 'tools') {
+ my @tools = ('aboutme','blog','portfolio');
+ if (grep(/^\Q$prt\E$/,@tools)) {
+ if (!&Apache::lonnet::usertools_access($env{'user.name'},
+ $env{'user.domain'},
+ $prt,undef,'tools')) {
+ $output.=&clear($row,$col);
+ next;
+ }
+ } elsif (($prt eq 'reqcrsnsc') || ($prt eq 'reqcrsshc')) {
+ if (($prt eq 'reqcrsnsc') && ($show_course)) {
+ next;
+ }
+ if (($prt eq 'reqcrsshc') && (!$show_course)) {
+ next;
+ }
+ my $showreqcrs = &check_for_rcrs();
+ if (!$showreqcrs) {
+ $output.=&clear($row,$col);
+ next;
+ }
+ }
+ $prt='any';
+ $output.=&secondlevel(
+ $uname,$udom,$rol,$crs,$pub,$con,$row,$col,$prt,$img,$top,$bot,$act,$desc,$cat);
}
}
- unless (($ENV{'browser.interface'} eq 'textual') ||
- ($ENV{'environment.remote'} eq 'off')) {
- $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
+ if ($env{'environment.remote'} eq 'on') {
+ $output.="\nwindow.status='Synchronizing Time';swmenu.syncclock(1000*".time.");\nwindow.status='Remote Control Configured.';";
+ if (&Apache::lonmsg::newmail()) {
+ $output.='swmenu.setstatus("you have","messages");';
+ }
}
return $output;
}
+sub check_for_rcrs {
+ my $showreqcrs = 0;
+ my @reqtypes = ('official','unofficial','community','textbook');
+ foreach my $type (@reqtypes) {
+ if (&Apache::lonnet::usertools_access($env{'user.name'},
+ $env{'user.domain'},
+ $type,undef,'requestcourses')) {
+ $showreqcrs = 1;
+ last;
+ }
+ }
+ if (!$showreqcrs) {
+ foreach my $type (@reqtypes) {
+ if ($env{'environment.reqcrsotherdom.'.$type} ne '') {
+ $showreqcrs = 1;
+ last;
+ }
+ }
+ }
+ return $showreqcrs;
+}
+
# ======================================================================= Close
sub close {
- if (($ENV{'browser.interface'} eq 'textual') ||
- ($ENV{'environment.remote'} eq 'off')) { return ''; }
- my $menuname='LCmenu'.$Apache::lonnet::perlvar{'lonHostID'};
+ unless ($env{'environment.remote'} eq 'on') { return ''; }
+ my $menuname = &get_menu_name();
return(<
+
ENDCLOSE
}
-# ====================================================================== Footer
+sub dc_popup_js {
+ my %lt = &Apache::lonlocal::texthash(
+ more => '(More ...)',
+ less => '(Less ...)',
+ );
+ return <<"END";
+
+function showCourseID() {
+ document.getElementById('dccid').style.display='block';
+ document.getElementById('dccid').style.textAlign='left';
+ document.getElementById('dccid').style.textFace='normal';
+ document.getElementById('dccidtext').innerHTML ='$lt{'less'}';
+ return;
+}
+
+function hideCourseID() {
+ document.getElementById('dccid').style.display='none';
+ document.getElementById('dccidtext').innerHTML ='$lt{'more'}';
+ return;
+}
+
+END
+
+}
+
+sub countdown_toggle_js {
+ return <<"END";
+
+function toggleCountdown() {
+ var countdownid = document.getElementById('duedatecountdown');
+ var currstyle = countdownid.style.display;
+ if (currstyle == 'inline') {
+ countdownid.style.display = 'none';
+ document.getElementById('ddcountcollapse').innerHTML='';
+ document.getElementById('ddcountexpand').innerHTML='◄ ';
+ } else {
+ countdownid.style.display = 'inline';
+ document.getElementById('ddcountcollapse').innerHTML='► ';
+ document.getElementById('ddcountexpand').innerHTML='';
+ }
+ return;
+}
+
+END
+}
-sub footer {
+# This creates a "done button" for timed events. The confirmation box is a jQuery
+# dialog widget. If the interval parameter requires a proctor key for the timed
+# event to be marked done, there will also be a textbox where that can be entered.
+# Clicking OK will set the value of LC_interval_done to 'true', and, if needed will
+# set the value of LC_interval_done_proctorpass to the text entered in that box,
+# and submit the corresponding form.
+#
+# The &zero_time() routine in lonhomework.pm is called when a page is rendered if
+# LC_interval_done is true.
+#
+sub done_button_js {
+ my ($type,$width,$height,$proctor,$donebuttontext) = @_;
+ return unless (($type eq 'map') || ($type eq 'resource'));
+ my %lt = &Apache::lonlocal::texthash(
+ title => 'WARNING!',
+ preamble => 'You are trying to end this timed event early.',
+ map => 'Confirming that you are done will cause the time to expire and prevent you from changing any answers in the current folder.',
+ resource => 'Confirming that you are done will cause the time to expire for this question, and prevent you from changing your answer(s).',
+ okdone => 'Click "OK" if you are completely finished.',
+ cancel => 'Click "Cancel" to continue working.',
+ proctor => 'Ask a proctor to enter the key, then click "OK" if you are completely finished.',
+ ok => 'OK',
+ exit => 'Cancel',
+ key => 'Key:',
+ nokey => 'A proctor key is required',
+ );
+ my $shownsymb = &HTML::Entities::encode(&Apache::lonenc::check_encrypt($env{'request.symb'}));
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ my ($missing,$tried) = (0,0);
+ if (ref($navmap)) {
+ my @resources=();
+ if ($type eq 'map') {
+ my ($mapurl,$rid,$resurl)=&Apache::lonnet::decode_symb($env{'request.symb'});
+ if ($env{'request.symb'} =~ /\.page$/) {
+ @resources=$navmap->retrieveResources($resurl,sub { $_[0]->is_problem() });
+ } else {
+ @resources=$navmap->retrieveResources($mapurl,sub { $_[0]->is_problem() });
+ }
+ } else {
+ my $res = $navmap->getBySymb($env{'request.symb'});
+ if (ref($res)) {
+ if ($res->is_problem()) {
+ push(@resources,$res);
+ }
+ }
+ }
+ foreach my $res (@resources) {
+ if (ref($res->parts()) eq 'ARRAY') {
+ foreach my $part (@{$res->parts()}) {
+ if (!$res->tries($part)) {
+ $missing++;
+ } else {
+ $tried++;
+ }
+ }
+ }
+ }
+ }
+ if ($missing) {
+ $lt{'miss'} .= '
';
+ if ($type eq 'map') {
+ $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,question part,question parts] in this folder.',$missing);
+ } else {
+ $lt{'miss'} .= &mt('Submissions are missing for [quant,_1,part] in this question.',$missing);
+ }
+ if ($missing > 1) {
+ $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit answers for them.').'';
+ } else {
+ $lt{'miss'} .= ' '.&mt('If you confirm you are done you will be unable to submit an answer for it.').'