--- loncom/interface/lonmenu.pm 2001/12/19 17:17:46 1.11 +++ loncom/interface/lonmenu.pm 2002/08/19 21:14:08 1.26 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.11 2001/12/19 17:17:46 albertel Exp $ +# $Id: lonmenu.pm,v 1.26 2002/08/19 21:14:08 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -30,6 +30,7 @@ # 05/29/00,05/30 Gerd Kortemeyer) # # 10/05,05/28,05/30,06/01,06/08,06/09,07/04,08/07 Gerd Kortemeyer +# 02/15/02 Matthew Hall package Apache::lonmenu; @@ -41,22 +42,31 @@ use vars qw(@desklines $readdesk); # =============================================================== Open the menu sub open { - return(< -window.status='MenuControl:nologout'; -menu=window.open("/res/adm/pages/menu.html","LONCAPAmenu", - "height=350,width=150,scrollbars=no,menubar=no"); - + my $returnval=''; + unless (shift eq 'unix') { +# resizing does not work on linux because of virtual desktop sizes + $returnval.=(<'.$returnval.''; } # ============================================================ Switch Menu Item sub switchmenu { my ($row,$col,$imgsrc,$texttop,$textbot,$action)=@_; + my $openwin=&openmenu(); return(< - swmenu=window.open('','LONCAPAmenu'); + var swmenu=$openwin swmenu.switchbutton($row,$col,"$imgsrc","$texttop","$textbot","$action"); ENDSMENU @@ -69,6 +79,8 @@ sub clear { return qq(swmenu.clearbut($row,$col);); } +# Switch acts on the javascript that is executed when a button is clicked. +# The javascript is usually similar to "go('/adm/roles')" or "cstrgo(..)". sub switch { my ($uname,$udom,$row,$col,$img,$top,$bot,$act)=@_; $act=~s/\$uname/$uname/g; @@ -91,8 +103,17 @@ sub secondlevel { return $output; } +sub openmenu { + if ($ENV{'browser.type'} eq 'explorer') { + return "window.open('javascript:void(0);','LONCAPAmenu');"; + } else { + return "window.open('','LONCAPAmenu');"; + } +} + sub rawconfig { - my $output="swmenu=window.open('','LONCAPAmenu');"; + my $r = shift; + my $output="var swmenu=".&openmenu(); my $uname=$ENV{'user.name'}; my $udom=$ENV{'user.domain'}; my $adv=$ENV{'user.adv'}; @@ -108,11 +129,13 @@ sub rawconfig { my $pub=($ENV{'request.state'} eq 'published'); my $con=($ENV{'request.state'} eq 'construct'); my $rol=$ENV{'request.role'}; - map { + my $requested_domain = $ENV{'request.role.domain'}; + foreach (@desklines) { my ($row,$col,$pro,$prt,$img,$top,$bot,$act)=split(/\:/,$_); $prt=~s/\$uname/$uname/g; $prt=~s/\$udom/$udom/g; $prt=~s/\$crs/$crs/g; + $prt=~s/\$requested_domain/$requested_domain/g; if ($pro eq 'clear') { $output.=&clear($row,$col); } elsif ($pro eq 'any') { @@ -132,20 +155,34 @@ sub rawconfig { if (&Apache::lonnet::allowed($1,$prt)) { $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act); } + } elsif ($pro eq 'course') { + if ($ENV{'request.course.fn'}) { + $output.=switch($uname,$udom,$row,$col,$img,$top,$bot,$act); + } } elsif ($pro eq 'author') { if ($author) { if (($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) { + # Check that we are on the correct machine my ($cadom,$caname)= ($ENV{'request.role'}=~/(\w+)\/(\w+)$/); - $output.=switch($caname,$cadom, - $row,$col,$img,$top,$bot,$act); + my $home = &Apache::lonnet::homeserver($caname,$cadom); + if ($home eq $r->dir_config('lonHostID')) { + $output.=switch($caname,$cadom, + $row,$col,$img,$top,$bot,$act); + } } elsif ($prt eq 'any') { - $output.=switch($ENV{'user.name'},$ENV{'user.domain'}, - $row,$col,$img,$top,$bot,$act); + my $home = &Apache::lonnet::homeserver + ($ENV{'user.name'},$ENV{'user.domain'}); + if ($home eq $r->dir_config('lonHostID')) { + $output.=switch + ($ENV{'user.name'},$ENV{'user.domain'}, + $row,$col,$img,$top,$bot,$act); + } } } } - } @desklines; + } + $output.="swmenu.syncclock(1000*".time.");"; return $output; } @@ -154,7 +191,6 @@ sub rawconfig { sub close { return(< -window.status='MenuControl:nologout'; menu=window.open("/adm/rat/empty.html","LONCAPAmenu", "height=350,width=150,scrollbars=no,menubar=no"); menu.close(); @@ -170,18 +206,23 @@ sub footer { # ================================================================ Main Program -sub BEGIN { - unless ($readdesk) { - { +BEGIN { + if (! defined($readdesk)) { + { my $config=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}. '/mydesk.tab'); while (my $configline=<$config>) { + $configline=(split(/\#/,$configline))[0]; + $configline=~s/^\s+//; chomp($configline); - $desklines[$#desklines+1]=$configline; + if ($configline) { + $desklines[$#desklines+1]=$configline; + } } + } + $readdesk='done'; } } -} 1; __END__