[LON-CAPA-cvs] cvs: loncom(version_2_10_X) /interface lonmenu.pm

raeburn raeburn@source.lon-capa.org
Sat, 14 Aug 2010 21:38:08 -0000


raeburn		Sat Aug 14 21:38:08 2010 EDT

  Modified files:              (Branch: version_2_10_X)
    /loncom/interface	lonmenu.pm 
  Log:
  - Backport 1.328, 1.329, 1.330, 1.331.
  
  
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.315.2.1 loncom/interface/lonmenu.pm:1.315.2.2
--- loncom/interface/lonmenu.pm:1.315.2.1	Wed May 26 19:50:46 2010
+++ loncom/interface/lonmenu.pm	Sat Aug 14 21:38:08 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.315.2.1 2010/05/26 19:50:46 raeburn Exp $
+# $Id: lonmenu.pm,v 1.315.2.2 2010/08/14 21:38:08 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -256,15 +256,43 @@
     return "<ol class=\"LC_primary_menu LC_right\">$menu</ol>";
 }
 
+#returns hashref {user=>'',dom=>''} containing:
+#   own name, domain if user is au
+#   name, domain of parent author if user is ca or aa
+#empty return if user is not an author or not on homeserver
+#
+#TODO this should probably be moved somewhere more central
+#since it can be used by different parts of the system
+sub getauthor{
+    return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author
+
+                        #co- or assistent author?
+    my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/)
+                       ? ($1, $2) #domain, username of the parent author
+                       : @env{ ('request.role.domain', 'user.name') }; #own domain, username
+
+    # current server == home server?
+    my $home =  &Apache::lonnet::homeserver($user,$dom);
+    foreach (&Apache::lonnet::current_machine_ids()){
+        return {user => $user, dom => $dom} if $_ eq $home;
+    }
+
+    # if wrong server
+    return;
+}
+
 
 sub secondary_menu {
     my $menu;
 
     my $crstype = &Apache::loncommon::course_type();
-    my $canedit = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
-    my $canviewgrps = &Apache::lonnet::allowed('vcg', $env{'request.course.id'}
-                   . ($env{'request.course.sec'} ? "/$env{'request.course.sec'}"
-                                                 : '')); 
+    my $crs_sec = $env{'request.course.id'} . ($env{'request.course.sec'}
+                                               ? "/$env{'request.course.sec'}"
+                                               : '');
+    my $canedit       = &Apache::lonnet::allowed('mdc', $env{'request.course.id'});
+    my $canviewgrps   = &Apache::lonnet::allowed('vcg', $crs_sec);
+    my $author        = getauthor();
+
     my $showlink = &show_return_link();
     my %groups = &Apache::lonnet::get_active_groups(
                      $env{'user.domain'}, $env{'user.name'},
@@ -274,6 +302,7 @@
         # evaluate conditions 
         next if    ref($menuitem)  ne 'ARRAY';
         next if    $$menuitem[4]   ne 'always'
+                && $$menuitem[4]   ne 'author'
                 && !$env{'request.course.id'};
         next if    $$menuitem[4]   eq 'showreturn'
                 && !$showlink
@@ -295,6 +324,8 @@
         next if    $$menuitem[4]   =~ /showgroups$/
                 && !$canviewgrps
                 && !%groups;
+        next if    $$menuitem[4]    eq 'author'
+                && !$author;
 
         if ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
             # special treatment for role selector
@@ -336,6 +367,8 @@
         $menu =~ s/\[url\]/$escurl/g;
         $menu =~ s/\[symb\]/$escsymb/g;
     }
+    $menu =~ s/\[uname\]/$$author{user}/g;
+    $menu =~ s/\[udom\]/$$author{dom}/g;
 
     return "<ul id=\"LC_secondary_menu\">$menu</ul>";
 }
@@ -446,6 +479,7 @@
 
         &Apache::lonhtmlcommon::clear_breadcrumbs();
         &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
+
         #$breadcrumb .= &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
 	unless (($env{'request.state'} eq 'edit') || ($newmail) ||
 		($env{'request.state'} eq 'construct') ||
@@ -453,6 +487,11 @@
             $separator = &Apache::loncommon::head_subbox();
         }
         #
+    } elsif (!$const_space){
+        #a situation when we're looking at a resource outside of context of a
+        #course or construction space (e.g. with cumulative rights)
+        &Apache::lonhtmlcommon::clear_breadcrumbs();
+        &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
     }
     if ($env{'request.state'} eq 'construct') {
         $newmail = $titletable;
@@ -546,6 +585,8 @@
             my $cfuname='';
             my $cfudom='';
             my $uploaded;
+            my $switchserver='';
+            my $home;
             if ($env{'request.filename'}) {
                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                 if (defined($cnum) && defined($cdom)) {
@@ -556,18 +597,20 @@
                     # Check that the user has permission to edit this resource
                     ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
                     if (defined($cfudom)) {
-		        my $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
+		        $home=&Apache::lonnet::homeserver($cfuname,$cfudom);
 		        my $allowed=0;
 		        my @ids=&Apache::lonnet::current_machine_ids();
 		        foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 		        if ($allowed) {
                             $cfile=$file;
+                        } else {
+                            $switchserver=$file;
                         }
                     }
                 }
             }
             # Finally, turn the button on or off
-            if ($cfile && !$const_space) {
+            if (($cfile || $switchserver) && !$const_space) {
                 my $nocrsedit;
                 # Suppress display where CC has switched to student role.
                 if ($env{'request.course.id'}) {
@@ -579,6 +622,12 @@
                 if ($nocrsedit) {
                     $editbutton=&clear(6,1);
                 } else {
+                    if ($switchserver) {
+                        if ( $env{'request.symb'} && $env{'request.course.id'} ) {
+                            my ($mapurl,$rid,$resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
+                            $cfile = '/adm/switchserver?otherserver='.$home.'&amp;role='.$env{'request.role'}.'&amp;symb='.$env{'request.symb'}.'&amp;origurl='.$resurl;
+                        }
+                    }
                     $editbutton=&switch
                        ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
                      "go('".$cfile."');","Edit this resource");