[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonmenu.pm mydesk.tab

droeschl droeschl@source.lon-capa.org
Sun, 04 Oct 2009 17:47:21 -0000


This is a MIME encoded message

--droeschl1254678441
Content-Type: text/plain

droeschl		Sun Oct  4 17:47:21 2009 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonmenu.pm mydesk.tab 
  Log:
  Saving my work, this isn't finished yet.
  Refactoring of lonmenu::menubuttons such that data needed to display primary and secondary menu is now stored in mydesk.tab instead of code.
  There should be only slight visual changes and no functional changes.
  
  
--droeschl1254678441
Content-Type: text/plain
Content-Disposition: attachment; filename="droeschl-20091004174721.txt"

Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.893 loncom/interface/loncommon.pm:1.894
--- loncom/interface/loncommon.pm:1.893	Thu Oct  1 17:25:17 2009
+++ loncom/interface/loncommon.pm	Sun Oct  4 17:47:21 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.893 2009/10/01 17:25:17 raeburn Exp $
+# $Id: loncommon.pm,v 1.894 2009/10/04 17:47:21 droeschl Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4440,29 +4440,47 @@
 
     if ($env{'environment.remote'} eq 'off') {
         # No Remote
-	if ($env{'request.state'} eq 'construct') {
-	    $forcereg=1;
-	}
+        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.state'} eq 'construct') {
+    #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
+    #    }
 
         my $titletable = '<table id="LC_title_bar">'
-                        ."<tr><td> $titleinfo $dc_info</td>"
-                        .'</tr></table>';
+                            ."<tr><td> $titleinfo $dc_info</td>"
+                            .'</tr></table>';
 
-	if ($no_nav_bar) {
-	    $bodytag .= $titletable;
-	} else {
-        $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
-            <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
+        if ($no_nav_bar) {
+            $bodytag .= $titletable;
+        } else {
+            $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
+                <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
 
-	    if ($env{'request.state'} eq 'construct') {
-                $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
-            } else {
-                $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
-            }
+#SD $titletable is obsolete
+#SD            if ($env{'request.state'} eq 'construct') {
+#SD                $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
+#SD            } else {
+#SD                $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
+#SD            }
+               if (   $env{'form.inhibitmenu'} eq 'yes' 
+                   || $ENV{'REQUEST_URI'} eq '/adm/logout'
+                   || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
+                   
+                   return $bodytag;
+               }
+
+               $bodytag .= Apache::lonhtmlcommon::scripttag(
+                                Apache::lonmenu::utilityfunctions(),
+                                'start');
+               $bodytag .= Apache::lonmenu::primary_menu();
+               $bodytag .= Apache::lonmenu::secondary_menu();
+               #SD remove next line
+               #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
+               $bodytag .= Apache::lonmenu::serverform();
+               $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
+               $bodytag .= Apache::lonmenu::innerregister($forcereg) if $forcereg;
         }
         return $bodytag;
     }
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.282 loncom/interface/lonmenu.pm:1.283
--- loncom/interface/lonmenu.pm:1.282	Sun Sep 27 11:05:06 2009
+++ loncom/interface/lonmenu.pm	Sun Oct  4 17:47:21 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.282 2009/09/27 11:05:06 amueller Exp $
+# $Id: lonmenu.pm,v 1.283 2009/10/04 17:47:21 droeschl Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -139,15 +139,135 @@
 use LONCAPA qw(:DEFAULT :match);
 use HTML::Entities();
 
-use vars qw(@desklines %category_names %category_members %category_positions $readdesk);
+use vars qw(@desklines %category_names %category_members %category_positions 
+            $readdesk @primary_menu @secondary_menu);
 
 
 my @inlineremote;
 
+sub prep_menuitem {
+    my $menuitem = shift;
+    return '' unless ref $menuitem eq 'ARRAY';
+    my $link;
+    if ($$menuitem[1]) { # graphical Link
+        $link = "<img class=\"LC_noBorder\""
+              . " src=\"" . Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
+              . " alt=\"" . mt($$menuitem[2]) . "\" />";
+    } else {             # textual Link
+        $link = mt($$menuitem[3]);
+    }     
+    return "<li><a href=\"javascript:$$menuitem[0]\">$link</a></li>";
+}
+
+# primary_menu() evaluates @primary_menu and returns XHTML for the menu
+# that contains following links:
+# 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 $menu;
+    # each element of @primary contains following array:
+    # (link url, icon path, alt text, link text, condition)
+    foreach my $menuitem (@primary_menu) {
+        # evaluate conditions 
+        next if    $$menuitem[4]        eq 'nonewmsg'  # show links depending on
+                && Apache::lonmsg::mynewmail();        # whether a new msg 
+        next if    $$menuitem[4]        eq 'newmsg'    # arrived or not
+                && !Apache::lonmsg::mynewmail();       # 
+        next if    $$menuitem[4]        !~ /public/    ##we've a public user, 
+                && $env{'user.name'}    eq 'public'    ##who should not see all 
+                && $env{'user.domain'}  eq 'public';   ##links
+        next if    $$menuitem[4]        eq 'onlypublic'# hide links which are 
+                && $env{'user.name'}    ne 'public'    # only visible to public
+                && $env{'user.domain'}  ne 'public';   # users
+        next if    $$menuitem[4]        eq 'roles'     ##show links depending on
+                && Apache::loncommon::show_course();   ##term 'Courses' or 
+        next if    $$menuitem[4]        eq 'courses'   ##'Roles' wanted
+                && !Apache::loncommon::show_course();  ##
+
+
+        if ($$menuitem[3] eq 'Help') { # special treatment for helplink
+            $menu .= Apache::loncommon::top_nav_help('Help');
+        } else {
+            $menu .= prep_menuitem(\@$menuitem);
+        }
+     }
+
+     return "<ol class=\"LC_smallMenu LC_right\">$menu</ol>";
+}
+
+
+sub secondary_menu {
+    my $menu;
+
+    foreach my $menuitem (@secondary_menu) {
+        # evaluate conditions 
+        next if    $$menuitem[4]   ne 'always'
+                && !$env{'request.course.id'};
+        next if    $$menuitem[4]   eq 'showreturn'
+                && !show_return_link() 
+                && !($env{'request.state'} eq 'construct');
+        next if    $$menuitem[4]   =~ /^mdc/
+                && !Apache::lonnet::allowed('mdc', $env{'request.course.id'});
+        next if    $$menuitem[4]   =~ /nogrp$/
+                && Apache::loncommon::course_type() eq 'Group';
+        next if    $$menuitem[4]   =~ /group$/
+                && Apache::loncommon::course_type() ne 'Group';
+        next if    $$menuitem[4]   eq 'remotenav'
+                && $env{'environment.remotenavmap'} ne 'on';
+        next if    $$menuitem[4]   eq 'noremotenav'
+                && $env{'environment.remotenavmap'} eq 'on';
+        next if    $$menuitem[4]   =~ /showgroups$/
+                && !Apache::lonnet::allowed('vcg', $env{'request.course.id'}
+                   . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
+                                                 : ''))
+                && !Apache::lonnet::get_active_groups(
+                   $env{'user.domain'}, $env{'user.name'},
+                   $env{'course.' . $env{'request.course.id'} . '.domain'},
+                   $env{'course.' . $env{'request.course.id'} . '.num'});
+
+
+        if($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) { 
+            # special treatment for role selector
+            my $roles_selector = roles_selector(
+                        $env{'course.' . $env{'request.course.id'} . '.domain'},
+                        $env{'course.' . $env{'request.course.id'} . '.num'}  );
+
+            $menu .= $roles_selector ? "<li>$roles_selector</li>"
+                                     : '';
+        } else {
+            $menu .= prep_menuitem(\@$menuitem);
+        }
+    }
+    if ($menu =~ /\[url\].*\[symb\]/) {
+        my $escurl  = escape( Apache::lonenc::check_encrypt(
+                            $env{'request.noversionuri'}));
+
+        my $escsymb = escape( Apache::lonenc::check_encrypt(
+                            $env{'request.symb'})); 
+
+        if (    $env{'request.state'} eq 'construct'
+            and (   $env{'request.noversionuri'} eq '' 
+                 || !defined($env{'request.noversionuri'}))) 
+        {
+            ($escurl = $env{'request.filename'}) =~ 
+                s{^/home/([^/]+)/public_html/(.*)$}{/priv/$1/$2};
+
+            $escurl  = escape($escurl);
+        }    
+        $menu =~ s/\[url\]/$escurl/g;
+        $menu =~ s/\[symb\]/$escsymb/g;
+    }
+
+    return "<ul id=\"LC_TabMainMenuContent\">$menu</ul>";
+}
+
+
 #
 # This routine returns a translated hash for the menu items in the top inline menu row
 # Probably should be in mydesk.tab
 
+#SD this sub is deprecated - don't use it
 sub initlittle {
     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
 				       'nav' => 'Course Contents',
@@ -164,6 +284,8 @@
                                        );
 }
 
+#SD this sub is deprecated - don't use it
+#SD functionality is covered by new loncommon::bodytag and primary_menu(), secondary_menu()
 sub menubuttons {
     my $forcereg=shift;
     my $titletable=shift;
@@ -1867,34 +1989,34 @@
 
 BEGIN {
     if (! defined($readdesk)) {
-	{
-	    my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
-	    if ( CORE::open( my $config,"<$tabfile") ) {
-		while (my $configline=<$config>) {
-		    $configline=(split(/\#/,$configline))[0];
-		    $configline=~s/^\s+//;
-		    chomp($configline);
+        {
+            my $tabfile = $Apache::lonnet::perlvar{'lonTabDir'}.'/mydesk.tab';
+            if ( CORE::open( my $config,"<$tabfile") ) {
+                while (my $configline=<$config>) {
+                    $configline=(split(/\#/,$configline))[0];
+                    $configline=~s/^\s+//;
+                    chomp($configline);
                     if ($configline=~/^cat\:/) {
-                       my @entries=split(/\:/,$configline);
-                       $category_positions{$entries[2]}=$entries[1];
-                       $category_names{$entries[2]}=$entries[3];
-		    } elsif ($configline) {
-			push(@desklines,$configline);
-		    }
-		}
-		CORE::close($config);
-	    }
-	}
-	$readdesk='done';
+                        my @entries=split(/\:/,$configline);
+                        $category_positions{$entries[2]}=$entries[1];
+                        $category_names{$entries[2]}=$entries[3];
+                    } elsif ($configline=~/^prim\:/) {
+                        my @entries = (split(/\:/, $configline))[1..5];
+                        push @primary_menu, \@entries;
+                    } elsif ($configline=~/^scnd\:/) {
+                        my @entries = (split(/\:/, $configline))[1..5];
+                        push @secondary_menu, \@entries; 
+                    } elsif ($configline) {
+                        push(@desklines,$configline);
+                    }
+                }
+                CORE::close($config);
+            }
+        }
+        $readdesk='done';
     }
 }
 
 1;
 __END__
 
-
-
-
-
-
-
Index: loncom/interface/mydesk.tab
diff -u loncom/interface/mydesk.tab:1.113 loncom/interface/mydesk.tab:1.114
--- loncom/interface/mydesk.tab:1.113	Thu Oct  1 20:20:55 2009
+++ loncom/interface/mydesk.tab	Sun Oct  4 17:47:21 2009
@@ -1,3 +1,57 @@
+# primary menu links
+# Apache::lonmenu::primary_menu() generates a menu from these elements
+# prim: item belongs to primary menu
+# link: references the url
+# icon: icon to show in case of a graphical item
+# alt:  alt-text only if icon is not empty
+# text: link text
+# condition: when to show link, primary_menu will act upon this
+#   possible conditions:
+#   - empty: link is displayed if user is authenticated
+#   - public: display link if user is public or authenticated 
+#   - onlypublic: only show this link to public users
+#   - newmsg: only display if there are new messages 
+#   - nonewmsg: only display if there aren't any new messages
+#   - roles: show Roles instead of Courses
+#   - courses: show Courses instead of Roles
+# prim:link:icon:alt:text:condition
+prim:go('/adm/about.html'):/adm/lonIcons/minilogo.gif:LON-CAPA Logo:About:public
+prim:go('/adm/communicate'):::Message:nonewmsg
+prim:go('/adm/communicate'):::Message (new):newmsg
+prim:go('/adm/roles'):::Roles:roles
+prim:go('/adm/roles'):::Courses:courses
+prim:go('/adm/roles'):::Log In:onlypublic
+prim::::Help:
+prim:go('/adm/logout'):::Logout:
+
+# secondary menu links
+# Apache::lonmenu::secondary_menu() generates a menu from these elements
+# scnd: item belongs to secondary menu
+# link: references the url
+# icon: icon to show in case of a graphical item
+# alt:  alt-text only if icon is not empty
+# text: link text
+# condition: when to show link, secondary_menu will act upon this
+#   possible conditions:
+#   - empty: 
+#   - showreturn: link is displayed if return link is wanted
+#   - mdcgroup: mdc from below and course is of type Group
+#   - mdcnogrp: mdc from below and course is a regular course
+#   - showgroups: user is member of a group
+#   - always: show this link even if user hasn't selected a role
+#   - remotenav: remote navmap is activated
+#   - noremotenav: remote navmap is _not_ activated
+# prim:link:icon:alt:text:condition
+scnd:go('/adm/menu'):::Main Menu:always
+scnd:go('/adm/flip?postdata=return%3a'):::Return to Last Location:showreturn
+scnd:go('/adm/navmaps?postdata=[url]&amp;postsymb=[symb]'):::Course Contents:noremotenav
+scnd:gonav('/adm/navmaps?postdata=[url]&amp;postsymb=[symb]'):::Course Contents:remotenav
+scnd:go('/adm/coursedocs'):::Edit Course:mdcnogrp
+scnd:go('/adm/coursedocs'):::Group Documents:mdcgroup
+scnd:go('/adm/coursegroups'):::Groups:showgroups
+scnd:go(''):::Roles:
+
+
 # Categories
 # cat:column,row:title
 cat:0,0:none:No category, inline menu

--droeschl1254678441--