[LON-CAPA-cvs] cvs: loncom /interface lonaboutme.pm lonhtmlcommon.pm lonmenu.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Thu Nov 8 13:37:54 EST 2012


raeburn		Thu Nov  8 18:37:54 2012 EDT

  Modified files:              
    /loncom/interface	lonaboutme.pm lonhtmlcommon.pm lonmenu.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Consistent Interface for templated pages (bug 6128).
  - Functions for Templated "About Me" page moved into standard location. 
  
  
-------------- next part --------------
Index: loncom/interface/lonaboutme.pm
diff -u loncom/interface/lonaboutme.pm:1.149 loncom/interface/lonaboutme.pm:1.150
--- loncom/interface/lonaboutme.pm:1.149	Thu Oct  4 13:41:10 2012
+++ loncom/interface/lonaboutme.pm	Thu Nov  8 18:37:44 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Personal Information Page
 #
-# $Id: lonaboutme.pm,v 1.149 2012/10/04 13:41:10 bisitz Exp $
+# $Id: lonaboutme.pm,v 1.150 2012/11/08 18:37:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -50,8 +50,6 @@
 
 =item handler()
 
-=item in_course()
-
 =item aboutme_info()
 
 =item print_portfiles_link()
@@ -168,7 +166,7 @@
 
     if ($is_course) {
         if ($target ne 'tex') {
-            my $args = {'function'       => $env{'forcestudent'},
+            my $args = {'function'       => undef,
                         'domain'         => $cdom};
             if ($env{'form.register'}) {
                 $args->{'force_register'} = $env{'form.register'};
@@ -192,17 +190,24 @@
         return OK;
     }
 
-# --------------------------------------------------------------- Force Student
-    my $forcestudent='';
-    if ($env{'form.forcestudent'}) { $forcestudent='student'; };
-
 #------------Get rights
     my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum);
-     my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
-    my $allowed=0;
-      my $privleged=$allowed=(($env{'user.name'} eq $cnum) &&
-                   ($env{'user.domain'} eq $cdom));
-    if ($forcestudent or $target eq 'tex') { $allowed=0; }
+    my %syllabus=&Apache::lonnet::dump('aboutme',$cdom,$cnum);
+    my ($allowed,$coursedomain,$coursenum);
+    if ($env{'request.course.id'}) {
+        $coursedomain = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        $coursenum = $env{'course.'.$env{'request.course.id'}.'.num'};
+    }
+    my ($cfile) = 
+        &Apache::lonnet::can_edit_resource($env{'request.noversionuri'},
+                                           $coursenum,$coursedomain,
+                                           $env{'request.noversionuri'},
+                                           $env{'request.symb'});
+    if ($cfile ne '') {
+        $allowed = 1;
+    }
+
+    if (!$env{'form.forceedit'} or $target eq 'tex') { $allowed=0; }
 
 # --------------------------------------- There is such a user, get environment
 
@@ -222,53 +227,8 @@
         $r->print($start_page);
    }
 
-#----------------Print Functions
-    if ($target ne 'tex') {
-        my $functions=&Apache::lonhtmlcommon::start_funclist();
-        if ($allowed) {
-            my $query_string = &build_query_string(
-                                   {'forcestudent' => '1',
-                                    'popup' => $env{'form.popup'}});
-            $functions.=&Apache::lonhtmlcommon::add_item_funclist(
-                            '<a href="'.$r->uri.$query_string.'">'
-                           .&mt('Show Public View').'</a>'
-                           .&Apache::loncommon::help_open_topic(
-                                'Uploaded_Templates_PublicView'));
-        } elsif ($privleged) {
-            my $query_string = &build_query_string(
-                                   {'forceedit' => '1',
-                                    'popup' => $env{'form.popup'}});
-            $functions.=&Apache::lonhtmlcommon::add_item_funclist(
-                            '<a href="'.$r->uri.$query_string.'">'
-                            .&mt('Edit').'</a>');
-        }
-        $functions.=&Apache::lonhtmlcommon::add_item_funclist(
-                        &Apache::lontemplate::send_message($r,$cnum,$cdom));
-
-        if ($env{'request.course.id'} &&
-            &Apache::lonnet::allowed('srm',$env{'request.course.id'}) &&
-            &in_course($cdom,$cnum)) {
-            if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
-                &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
-                $functions.=&Apache::lonhtmlcommon::add_item_funclist(
-                     &Apache::loncommon::track_student_link(
-                         'View recent activity by this student',$cnum,$cdom));
-            }
-            if (&Apache::lonnet::allowed('vgr', $env{'request.course.id'}) ||
-                &Apache::lonnet::allowed('vgr', $env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
-                $functions.=&Apache::lonhtmlcommon::add_item_funclist(
-                    &Apache::loncommon::slot_reservations_link(
-                        'Slot reservation history',$cnum,$cdom));
-            }
-            $functions.=&Apache::lonhtmlcommon::add_item_funclist(
-                           &Apache::loncommon::noteswrapper(
-                               &mt('Add Records'),$cnum,$cdom));
-        }
-        $functions.=&Apache::lonhtmlcommon::end_funclist();
-        $r->print(&Apache::loncommon::head_subbox($functions));
-    }
+#----------------Print Privacy note (edit mode) or last modified date. 
 
-# Print Privacy Note
     if ($target ne 'tex') {
         #Print Privacy Note
         if ($allowed) {
@@ -277,36 +237,36 @@
                 .&mt('The information you submit can be viewed by anybody who is logged into LON-CAPA. Do not provide information that you are not ready to share publicly.')
                 .'</div>'
             );
-        }
-    }
-
-#Print last modified
-
-    if ($target ne 'tex') {
-        my $lastmod;
-        if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) {
-            $lastmod=$syllabus{'uploaded.lastmodified'};
+        } elsif ($syllabus{'uploaded.lastmodified'}) {
+        #Print last modified
+            my $lastmod=$syllabus{'uploaded.lastmodified'};
             $lastmod=($lastmod?&Apache::lonlocal::locallocaltime($lastmod):&mt('never'));
             $r->print('<div class="LC_info">');
-             $r->print(&mt('Last updated').': '.$lastmod . '');
+            $r->print(&mt('Last updated').': '.$lastmod . '');
             $r->print('</div>');
         }
     }
-#Print Help Text
-    if ($target ne 'tex') {
-        if($allowed){
-            $r->print(&Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')));
-        }
-    }
 
 #------Print Headtitle
      if ($target ne 'tex') {
-        $r->print('<div class="LC_Box">');
-        $r->print('<h2 class="LC_hcell">'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
-         if ($courseenv{'nickname'}) {
-               $r->print('<h2>"'.$courseenv{'nickname'}.'"</h2>');
-        }
-        $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
+         $r->print('<div class="LC_Box">'.
+                   '<h2 class="LC_hcell">'.&Apache::loncommon::plainname($cnum,$cdom).'</h2>');
+         if ($allowed) {
+             $r->print('<div style="margin: 0; float:left;">');
+             if ($courseenv{'nickname'}) {
+                 $r->print('<h2>"'.$courseenv{'nickname'}.'"</h2>');
+             }
+             $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3></div>');
+             #Print Help Text
+             $r->print('<div style="margin: 0; float:right;">'.
+                       &Apache::loncommon::help_open_topic('Uploaded_Templates_TextBoxes',&mt('Help with filling in text boxes')).
+                       '</div><br clear="all" />');
+         } else {
+             if ($courseenv{'nickname'}) {
+                 $r->print('<h2>"'.$courseenv{'nickname'}.'"</h2>');
+             }
+             $r->print('<h3>'.&Apache::lonnet::domain($cdom,'description').'</h3>');
+         }
      } else {
         $r->print('\noindent{\large\textbf{'.&Apache::loncommon::plainname($cnum,$cdom).'}}\\\\\\\\');
         $r->print('\textbf{'.&Apache::lonnet::domain($cdom,'description').'}\\\\');
@@ -414,7 +374,7 @@
 
     if ($env{'request.course.id'}
         && &Apache::lonnet::allowed('srm',$env{'request.course.id'})
-        && &in_course($cdom,$cnum)) {
+        && &Apache::lonnet::in_course($cdom,$cnum)) {
         if ($target ne 'tex') {
             $r->print('<a name="coursecomment" />');
             &Apache::lontemplate::print_start_template($r,&mt('User Notes, Records of Face-To-Face Discussions, and Critical Messages in Course'),'LC_Box');
@@ -444,31 +404,6 @@
     return OK;
 }
 
-sub in_course {
-    my ($udom,$uname,$cdom,$cnum,$type) = @_;
-    $type ||= 'any';
-    if (!defined($cdom) || !defined($cnum)) {
-        my $cid  = $env{'request.course.id'};
-        $cdom = $env{'course.'.$cid.'.domain'};
-        $cnum = $env{'course.'.$cid.'.num'};
-    }
-    my $typesref;
-    if ($type eq 'all') {
-        $typesref = ['active','previous','future'];
-    } elsif ($type eq 'previous' || $type eq 'future') {
-        $typesref = [$type];
-    }
-    my %roles = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
-                                             $typesref,undef,[$cdom]);
-    my ($tmp) = keys(%roles);
-    return 0 if ($tmp =~ /^(con_lost|error|no_such_host)/i);
-    my @course_roles = grep(/^\Q$cnum\E:\Q$cdom\E:/, keys(%roles));
-    if (@course_roles > 0) {
-        return 1;
-    }
-    return 0;
-}
-
 sub aboutme_info {
     my ($r,$is_course) = @_;
     my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
@@ -852,7 +787,7 @@
     }
     if ((&Apache::lonnet::allowed('srm',$privcheck)) ||
         (&Apache::lonnet::allowed('dff',$privcheck))) {
-        if (&in_course($uname,$udom,$cnum,$cdom)) {
+        if (&Apache::lonnet::in_course($uname,$udom,$cnum,$cdom)) {
             return 1;
         }
     }
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.329 loncom/interface/lonhtmlcommon.pm:1.330
--- loncom/interface/lonhtmlcommon.pm:1.329	Sat Nov  3 23:32:37 2012
+++ loncom/interface/lonhtmlcommon.pm	Thu Nov  8 18:37:44 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.329 2012/11/03 23:32:37 raeburn Exp $
+# $Id: lonhtmlcommon.pm,v 1.330 2012/11/08 18:37:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,7 +61,7 @@
 use Apache::lonlocal;
 use Apache::lonnet;
 use HTML::Entities();
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
 
 sub java_not_enabled {
    return "\n".'<span class="LC_error">'.
@@ -1651,6 +1651,14 @@
                 $description = 
                     $env{'course.'.$env{'request.course.id'}.'.description'};
                 $no_mt_descr = 1;
+                if ($env{'request.noversionuri'} =~ 
+                    m{^/public/($match_domain)/($match_courseid)/syllabus$}) {
+                    unless (($env{'course.'.$env{'request.course.id'}.'.domain'} eq $1) &&
+                            ($env{'course.'.$env{'request.course.id'}.'.num'} eq $2)) { 
+                        $description = 'Menu';
+                        $no_mt_descr = 0;
+                    }
+                }
             }
             $menulink =  {  href   =>'/adm/menu',
                             title  =>'Go to main menu',
@@ -1666,7 +1674,7 @@
             }
         }
         my $links;
-        if ((&show_return_link) && (!$CourseBreadcrumbs)) {
+        if ((&show_return_link) && (!$CourseBreadcrumbs) && (ref($last) eq 'HASH')) {
             my $alttext = &mt('Go Back');
             $links=&htmltag( 'a','<img src="/res/adm/pages/tolastloc.png" alt="'.$alttext.'" class="LC_icon" />',
                             { href => '/adm/flip?postdata=return:',
@@ -1701,8 +1709,10 @@
         # last breadcrumb is the first order heading of a page
         # for course breadcrumbs it's just bold
 
-        $links .= &htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',
-                $lasttext), {title => $lasttext});
+        if ($lasttext ne '') {
+            $links .= &htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1',
+                    $lasttext), {title => $lasttext});
+        }
 
         my $icons = '';
         $faq  = $last->{'faq'}  if (exists($last->{'faq'}));
@@ -1723,11 +1733,12 @@
         #
 
 		
-
-        unless ($CourseBreadcrumbs) {
-            $links = &htmltag('ol',  $links, { id => "LC_MenuBreadcrumbs"   });
-        } else {
-            $links = &htmltag('ul',  $links, { class => "LC_CourseBreadcrumbs" });
+        if ($links ne '') {
+            unless ($CourseBreadcrumbs) {
+                $links = &htmltag('ol',  $links, { id => "LC_MenuBreadcrumbs"   });
+            } else {
+                $links = &htmltag('ul',  $links, { class => "LC_CourseBreadcrumbs" });
+            }
         }
 
 
@@ -3018,21 +3029,32 @@
 }
 
 sub jump_to_editres {
-    my ($cfile,$home,$switchserver,$uploaded,$symb) = @_;
+    my ($cfile,$home,$switchserver,$forceedit,$forcereg,$symb) = @_;
     my $jscall;
     if ($switchserver) {
         if ($symb && $home) {
             $cfile = '/adm/switchserver?otherserver='.$home.'&role='.
-                     &HTML::Entities::encode($env{'request.role'},'"<>&').'&'.
-                    'symb='.&HTML::Entities::encode($env{'request.symb'},'"<>&');
-            if ($uploaded) {
+                     &HTML::Entities::encode($env{'request.role'},'"<>&').
+                    '&symb='.&HTML::Entities::encode($symb,'"<>&');
+            if ($forceedit) {
                 $cfile .= '&forceedit=1';
             }
+            if ($forcereg) {
+                $cfile .= '&register=1';
+            }
             $jscall = "need_switchserver('$cfile');";
         }
     } else {
-        if ($uploaded) {
-            $cfile .= '?forceedit=1';
+        unless ($cfile =~ m{^/priv/}) {
+            if ($symb) {
+                $cfile .= (($cfile=~/\?/)?'&':'?')."symb=$symb"; 
+            }
+            if ($forceedit) {
+                $cfile .= (($cfile=~/\?/)?'&':'?').'forceedit=1';
+            }
+            if ($forcereg) {
+                $cfile .= (($cfile=~/\?/)?'&':'?').'register=1';
+            }
         }
         $jscall = "go('$cfile')";
     }
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.389 loncom/interface/lonmenu.pm:1.390
--- loncom/interface/lonmenu.pm:1.389	Wed Oct 31 12:54:13 2012
+++ loncom/interface/lonmenu.pm	Thu Nov  8 18:37:44 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.389 2012/10/31 12:54:13 raeburn Exp $
+# $Id: lonmenu.pm,v 1.390 2012/11/08 18:37:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -431,7 +431,7 @@
 }
 
 sub innerregister {
-    my ($forcereg,$bread_crumbs) = @_;
+    my ($forcereg,$bread_crumbs,$group) = @_;
     my $const_space = ($env{'request.state'} eq 'construct');
     my $is_const_dir = 0;
 
@@ -441,7 +441,12 @@
 
     undef(@inlineremote);
 
-    my $resurl; 
+    my $resurl;
+
+    if ($env{'request.course.id'} && $env{'request.symb'} eq '') {
+        $resurl = $env{'request.noversionuri'};
+    }
+ 
     if ( $env{'request.symb'} && $env{'request.course.id'} ) {
 
         (my $mapurl, my $rid, $resurl) = &Apache::lonnet::decode_symb(&Apache::lonnet::symbread());
@@ -473,150 +478,90 @@
 
         &Apache::lonhtmlcommon::clear_breadcrumbs();
         &Apache::lonhtmlcommon::add_breadcrumb(@crumbs);
-    }elsif (! $const_space){
+    } 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'});
+        unless ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
+            &Apache::lonhtmlcommon::add_breadcrumb({text => 'View Resource'});
+        }
     }
 # =============================================================================
 # ============================ This is for URLs that actually can be registered
     return '' unless ( ($env{'request.noversionuri'}!~m{^/(res/)*adm/}) 
                        || $forcereg );
+    my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
+        $forceview,$editbutton);
+    if ($env{'request.noversionuri'} =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) {
+        ($cfile,$home,$switchserver,$forceedit,$forceview) =
+            &Apache::lonnet::can_edit_resource($env{'request.noversionuri'},$cnum,$cdom,
+                &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
+        if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
+            $editbutton = &get_editbutton($cfile,$home,$switchserver,
+                                          $forceedit,$forceview,$forcereg);
+        }
+    } elsif ($env{'request.role'} !~/^(aa|ca|au)/) {
+        $editbutton = &prepare_functions($resurl,$forcereg,$group);
+    }
+    if ($editbutton eq '') {
+        &clear(6,1);
+    }
 
-# -- This applies to homework problems for users with grading privileges
-	my $crs='/'.$env{'request.course.id'};
-	if ($env{'request.course.sec'}) {
-	    $crs.='_'.$env{'request.course.sec'};
-	}
-	$crs=~s/\_/\//g;
-
-        my $hwkadd='';
-        if ($env{'request.symb'} ne '' &&
-	    $env{'request.filename'}=~/$LONCAPA::assess_re/) {
-	    if (&Apache::lonnet::allowed('mgr',$crs)) {
-		$hwkadd.=&switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
-                       "gocmd('/adm/grades','gradingmenu')",
-                       'Content Grades');
-            } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
-		$hwkadd.=&switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
-                       "gocmd('/adm/grades','submission')",
-		       'Content Submissions');
-            }
-	}
-	if ($env{'request.symb'} ne '' &&
-	    &Apache::lonnet::allowed('opa',$crs)) {
-	    $hwkadd.=&switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
-			     "gocmd('/adm/parmset','set')",
-			     'Content Settings');
-	}
-        if ($env{'request.symb'}=~/^uploaded/ &&
-            &Apache::lonnet::allowed('mdc',$crs)) {
-            $hwkadd.=&switch('','',7,4,'docs.png','Folder/Page Content','parms[_2]',
-                             "gocmd('/adm/coursedocs','direct')",
-                             'Folder/Page Content');
-        }
-# -- End Homework
-        ###
-        ### Determine whether or not to display the 'cstr' button for this
-        ### resource
-        ###
-        my $editbutton = '';
-        my $noeditbutton = 1;
-        my ($cnum,$cdom,$cfile,$switchserver,$home,$uploaded);
-        if ($env{'request.course.id'}) {
-            $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-            $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-        }
-        if ($env{'user.author'}) {
-            if ($env{'request.role'}=~/^(aa|ca|au)/) {
-#
-# We have the role of an author
-#
-                # Set defaults for authors
-                my ($top,$bottom) = ('con-','struct');
-                my $action = "go('/priv/".$env{'user.domain'}.'/'.$env{'user.name'}."');";
-                my $cadom  = $env{'request.role.domain'};
-                my $caname = $env{'user.name'};
-                my $desc = "Enter my construction space";
-                # Set defaults for co-authors
-                if ($env{'request.role'} =~ /^ca/) { 
-                    ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
-                    ($top,$bottom) = ('co con-','struct');
-                    $action = "go('/priv/".$cadom.'/'.$caname."');";
-                    $desc = "Enter construction space as co-author";
-                } elsif ($env{'request.role'} =~ /^aa/) {
-                    ($cadom,$caname)=($env{'request.role'}=~/($match_domain)\/($match_username)$/);
-                    ($top,$bottom) = ('co con-','struct');
-                    $action = "go('/priv/".$cadom.'/'.$caname."');";
-                    $desc = "Enter construction space as assistant co-author";
-                }
-                # Check that we are on the correct machine
-                my $home = &Apache::lonnet::homeserver($caname,$cadom);
-		my $allowed=0;
-		my @ids=&Apache::lonnet::current_machine_ids();
-		if (($home ne 'no_host') && (grep(/^\Q$home\E$/, at ids))) {
-		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
-                }
-            } else {
 #
-# We are an author for some stuff, but currently do not have the role of author.
-# Figure out if we have authoring privileges for the resource we are looking at.
+# This applies in course context
 #
-                my ($cfile,$switchserver,$home,$uploaded);
-                if ($env{'request.filename'}) {
-                    my $file=&Apache::lonnet::declutter($env{'request.filename'});
-                    ##
-                    ## Determine if user can edit url.
-                    ##
-                    ($cfile,$home,$switchserver,$uploaded) =
-                        &Apache::lonnet::can_edit_resource($file,$cnum,$cdom);
-                }
-                # Turn the button on or off
-                if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
-                    my $nocrsedit;
-                    # Suppress display where CC has switched to student role.
-                    if ($env{'request.course.id'}) {
-                        unless(&Apache::lonnet::allowed('mdc',
-                                                        $env{'request.course.id'})) {
-                            $nocrsedit = 1;
-                        }
-                    }
-                    if ($nocrsedit) {
-                        $editbutton=&clear(6,1);
-                    } else {
-                        $editbutton = &get_editbutton($cfile,$home,$switchserver,$uploaded);
-                    }
-                } elsif ($editbutton eq '') {
-                    $editbutton=&clear(6,1);
-                }
-            }
-        } elsif (($env{'request.filename'}) && $env{'request.course.id'}) {
-            if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
-                my $file=&Apache::lonnet::declutter($env{'request.filename'});
-                if (($cnum =~ /$match_courseid/) && ($cdom =~ /$match_domain/)) {
-                    my ($cfile,$home,$switchserver,$uploaded) =
-                        &Apache::lonnet::can_edit_resource($file,$cnum,$cdom);
-                    if (($uploaded) && ($cfile ne '')) {
-                        $editbutton = &get_editbutton($cfile,$home,$switchserver,$uploaded);
-                    }
-                }
+    if ($env{'request.course.id'}) {
+        $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+        my @privs;
+        if ($env{'request.symb'} ne '') {
+             if ($env{'request.filename'}=~/$LONCAPA::assess_re/) {
+                 push(@privs,('mgr','vgr'));
+             }
+             push(@privs,'opa');
+        }
+        foreach my $priv (@privs) {
+            $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
+            if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
+                $perms{$priv} = 
+                    &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
             }
         }
-        if ($env{'request.course.id'}) {
-            if ($resurl eq "public/$cdom/$cnum/syllabus") {
-                if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) {
-                    if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
-                        $editbutton=&switch('','',6,1,'pcstr.png','Edit',
-                                            'resource[_2]',
-                                            "go('/adm/courseprefs?phase=display&actions=courseinfo')",
-                                            'Edit this resource');
-                    }
-                }
-            }
+#
+# Determine whether or not to show Grades and Submissions buttons
+#
+        if ($env{'request.symb'} ne '' &&
+            $env{'request.filename'}=~/$LONCAPA::assess_re/) {
+            if ($perms{'mgr'}) {
+                &switch('','',7,2,'pgrd.png','Content Grades','grades[_4]',
+                        "gocmd('/adm/grades','gradingmenu')",
+                        'Content Grades');
+            } elsif ($perms{'vgr'}) {
+                &switch('','',7,2,'subm.png','Content Submissions','missions[_1]',
+                        "gocmd('/adm/grades','submission')",
+                        'Content Submissions');
+             }
+        }
+        if (($env{'request.symb'} ne '') && ($perms{'opa'})) {
+            &switch('','',7,3,'pparm.png','Content Settings','parms[_2]',
+                    "gocmd('/adm/parmset','set')",
+                    'Content Settings');
+	}
+# End grades/submissions check 
+
+#
+# This applies to items inside a folder/page modifiable in the course. 
+#
+        if (($env{'request.symb'}=~/^uploaded/) && ($perms{'mdc'})) {
+            &switch('','',7,4,'docs-22x22.png','Folder/Page Content','parms[_2]',
+                    "gocmd('/adm/coursedocs','direct')",
+                    'Folder/Page Content');
         }
-        ###
-        ###
+# End modifiable folder/page container check
+    }
+# End course context
+
 # Prepare the rest of the buttons
         my ($menuitems,$got_prt,$got_wishlist);
         if ($const_space) {
@@ -771,11 +716,7 @@
                 &Apache::lonhtmlcommon::add_breadcrumb_tool(
                      'tools', $inlineremote[63]);
             }
-            
-            unless ($env{'request.noversionuri'}=~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
-                &Apache::lonhtmlcommon::add_breadcrumb_tool(
-                    'advtools', @inlineremote[61,71,72,73,74,92]);
-            }
+            &advtools_crumbs(@inlineremote);
         }
     }
 
@@ -785,12 +726,178 @@
 }
 
 sub get_editbutton {
-    my ($cfile,$home,$switchserver,$uploaded) = @_;
-    my $jscall = &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
-                                                         $uploaded,$env{'request.symb'});
+    my ($cfile,$home,$switchserver,$forceedit,$forceview,$forcereg) = @_;
+    my $jscall = 
+        &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,$switchserver,
+                                                $forceedit,$forcereg,$env{'request.symb'});
     if ($jscall) {
-        return &switch('','',6,1,'pcstr.png','Edit','resource[_2]',
-                       $jscall,"Edit this resource");
+        my $icon = 'pcstr.png';
+        my $label = 'Edit';
+        if ($forceview) {
+            $icon = 'tolastloc.png';
+            $label = 'Exit Editing';
+        }
+        &switch('','',6,1,$icon,$label,'resource[_2]',
+                $jscall,"Edit this resource");
+        return 1;
+    }
+    return;
+}
+
+sub prepare_functions {
+    my ($resurl,$forcereg,$group,$bread_crumbs,$advtools) = @_;
+    unless ($env{'request.registered'}) {
+        undef(@inlineremote);
+    }
+    my ($cdom,$cnum,%perms,$cfile,$switchserver,$home,$forceedit,
+        $forceview);
+
+    if ($env{'request.course.id'}) {
+        $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        $perms{'mdc'} = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+    }
+
+    my $editbutton = '';
+#
+# Determine whether or not to display 'Edit' icon/button
+#
+    if ($resurl =~ m{^/?adm/($match_domain)/($match_username)/aboutme$}) {
+#
+# This applies to a user's own about me page
+#
+        my ($sdom,$sname) = ($1,$2);
+        my $file=&Apache::lonnet::declutter($env{'request.filename'});
+        if (($sdom eq $env{'user.domain'}) && ($sname eq $env{'user.name'})) {
+            ($cfile,$home,$switchserver,$forceedit,$forceview) =
+                &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
+                    &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
+            $editbutton = &get_editbutton($cfile,$env{'user.home'},$switchserver,
+                                          $forceedit,$forceview,$forcereg);
+        }
+    } elsif ((!$editbutton) && (!$env{'request.course.id'}) &&
+             ($env{'user.author'}) && ($env{'request.filename'}) &&
+             ($env{'request.role'} !~/^(aa|ca|au)/)) {
+#
+# Currently do not have the role of author or co-author.
+# Do we have authoring privileges for the resource?
+#
+        my $file=&Apache::lonnet::declutter($env{'request.filename'});
+        ($cfile,$home,$switchserver,$forceedit,$forceview) =
+            &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
+                &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
+        # Turn the button on or off
+        if (($cfile) && ($home ne '') && ($home ne 'no_host')) {
+            $editbutton = &get_editbutton($cfile,$home,$switchserver,
+                                          $forceedit,$forceview,$forcereg);
+        }
+    } elsif ($env{'request.course.id'}) {
+#
+# This applies in course context
+#
+        if (($resurl eq "/public/$cdom/$cnum/syllabus") && ($perms{'mdc'})) {
+            if ($env{'course.'.$env{'request.course.id'}.'.externalsyllabus'} =~ /\w/) {
+                &switch('','',6,1,'pcstr.png','Edit',
+                        'resource[_2]',
+                        "go('/adm/courseprefs?phase=display&actions=courseinfo')",
+                        'Edit this resource');
+                $editbutton = 1;
+            } else {
+                $cfile = $resurl;
+                $home = &Apache::lonnet::homeserver($cnum,$cdom);
+                if ($env{'form.forceedit'}) {
+                    $forceview = 1;
+                } else {
+                    $forceedit = 1;
+                }
+                $editbutton = &get_editbutton($cfile,$home,$switchserver,
+                                              $forceedit,$forceview,$forcereg);
+            }
+        } elsif ($resurl !~ m{^adm/($match_domain)/($match_username)/aboutme$}) {
+            if ($env{'request.filename'}) {
+                my $file=&Apache::lonnet::declutter($env{'request.filename'});
+                ($cfile,$home,$switchserver,$forceedit,$forceview) =
+                    &Apache::lonnet::can_edit_resource($file,$cnum,$cdom,
+                        &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group);
+                if ($cfile ne '') {
+                    $editbutton = &get_editbutton($cfile,$home,$switchserver,
+                                                  $forceedit,$forceview,$forcereg);
+                }
+            }
+        }
+    }
+# End determination of 'Edit' icon/button display
+
+# This applies to about me page for users in a course
+    if ($env{'request.course.id'}) {
+        if ($resurl =~ m{^adm/($match_domain)/($match_username)/aboutme$}) {
+            my ($sdom,$sname) = ($1,$2);
+            unless (&Apache::lonnet::is_course($sdom,$sname)) {
+                &switch('','',6,4,'mail-message-new-22x22.png','Message to user',
+                        '',
+                        "go('/adm/email?compose=individual&recname=$sname&recdom=$sdom')",
+                            'Send message to specific user');
+            }
+            if (&Apache::lonnet::in_course($sdom,$sname,$cdom,$cnum)) {
+                foreach my $priv ('vsa','vgr','srm') {
+                    $perms{$priv} = &Apache::lonnet::allowed($priv,$env{'request.course.id'});
+                    if (!$perms{$priv} && $env{'request.course.sec'} ne '') {
+                        $perms{$priv} =
+                            &Apache::lonnet::allowed($priv,"$env{'request.course.id'}/$env{'request.course.sec'}");
+                    }
+                }
+                if ($perms{'vsa'}) {
+                    &switch('','',6,5,'trck-22x22.png','Activity',
+                            '',
+                            "go('/adm/trackstudent?selected_student=$sname:$sdom')",
+                            'View recent activity by this person');
+                }
+                if ($perms{'vgr'}) {
+                    &switch('','',6,6,'rsrv-22x22.png','Reservations',
+                            '',
+                            "go('/adm/slotrequest?command=showresv&origin=aboutme&uname=$sname&udom=$sdom')",
+                            'Slot reservation history');
+                }
+                if ($perms{'srm'}) {
+                    &switch('','',6,7,'contact-new-22x22.png','Records',
+                            '',
+                            "go('/adm/email?recordftf=retrieve&recname=$sname&recdom=$sdom')",
+                            'Add records');
+                }
+            }
+        }
+    }
+
+# End checking for items for about me page for users in a course
+ 
+    if ($env{'request.registered'}) {
+        return $editbutton;
+    } else {
+        if (ref($bread_crumbs) eq 'ARRAY') {
+            if (@inlineremote > 0) {
+                if (ref($advtools) eq 'ARRAY') {
+                    @{$advtools} = @inlineremote;
+                }
+            }
+            return;
+        } elsif (@inlineremote > 0) {
+            &Apache::lonhtmlcommon::clear_breadcrumb_tools();
+            &advtools_crumbs(@inlineremote);
+            return   &Apache::lonhtmlcommon::scripttag('', 'start')
+                   . &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0)
+                   . &Apache::lonhtmlcommon::scripttag('', 'end');
+        }
+    }
+}
+
+sub advtools_crumbs {
+    my @funcs = @_;
+    if ($env{'request.noversionuri'} =~ m{^/adm/$match_domain/$match_username/aboutme$}) {
+        &Apache::lonhtmlcommon::add_breadcrumb_tool(
+            'advtools', @funcs[61,64,65,66,67,74]);
+    } elsif ($env{'request.noversionuri'} !~ m{^/adm/(navmaps|viewclasslist)(\?|$)}) {
+        &Apache::lonhtmlcommon::add_breadcrumb_tool(
+            'advtools', @funcs[61,71,72,73,74,92]);
     }
 }
 
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1193 loncom/lonnet/perl/lonnet.pm:1.1194
--- loncom/lonnet/perl/lonnet.pm:1.1193	Wed Oct 31 12:54:23 2012
+++ loncom/lonnet/perl/lonnet.pm	Thu Nov  8 18:37:52 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1193 2012/10/31 12:54:23 raeburn Exp $
+# $Id: lonnet.pm,v 1.1194 2012/11/08 18:37:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2663,19 +2663,110 @@
 #
 
 sub can_edit_resource {
-    my ($file,$cnum,$cdom) = @_;
-    my ($cfile,$home,$switchserver,$uploaded);
+    my ($file,$cnum,$cdom,$resurl,$symb,$group) = @_;
+    my ($cfile,$home,$switchserver,$forceedit,$forceview,$uploaded,$incourse);
+#
+# For aboutme pages user can only edit his/her own.
+#
+    if ($resurl =~ m{^/adm/($match_domain)/($match_username)/aboutme$}) {
+        my ($sdom,$sname) = ($1,$2);
+        if (($sdom eq $env{'user.domain'}) && ($sname eq $env{'user.name'})) {
+            $home = $env{'user.home'};
+            $cfile = $resurl;
+            if ($env{'form.forceedit'}) {
+                $forceview = 1;
+            } else {
+                $forceedit = 1;
+            }
+            return ($cfile,$home,$switchserver,$forceedit,$forceview);
+        } else {
+            return;
+        }
+    }
+
+    if ($env{'request.course.id'}) {
+        my $crsedit = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+        if ($group ne '') {
+# if this is a group homepage or group bulletin board, check group privs
+            my $allowed = 0;
+            if ($resurl =~ m{^/adm/$cdom/$cnum/$group/smppg$}) {
+                if ((&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.
+                            ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''))) ||
+                        (&allowed('mgh',$env{'request.course.id'}.'/'.$group)) || $crsedit) {
+                    $allowed = 1;
+                }
+            } elsif ($resurl =~ m{^/adm/$cdom/$cnum/\d+/bulletinboard$}) {
+                unless ((&allowed(&Apache::lonnet::allowed('mdg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) ||
+                        (&allowed('cgb',$env{'request.course.id'}.$group)) || $crsedit) {
+                    $allowed = 1;
+                }
+            }
+            if ($allowed) {
+                $home=&homeserver($cnum,$cdom);
+                if ($env{'form.forceedit'}) {
+                    $forceview = 1;
+                } else {
+                    $forceedit = 1;
+                }
+                $cfile = $resurl;
+            } else {
+                return;
+            }
+        } else {
+#
+# No edit allowed where CC has switched to student role.
+#
+            unless ($crsedit) {
+                return;
+            }
+        }
+    }
+
     if ($file ne '') {
         if (($cnum =~ /$match_courseid/) && ($cdom =~ /$match_domain/)) {
-            $uploaded = &is_course_upload($file,$cnum,$cdom);
-            if ($uploaded) {
-                $home=&homeserver($cnum,$cdom);
+            if (&is_course_upload($file,$cnum,$cdom)) {
+                $uploaded = 1;
+                $incourse = 1;
                 if ($file =~/\.(htm|html|css|js|txt)$/) {
                     $cfile = &hreflocation('',$file);
+                    $forceedit = 1;
+                }
+            } elsif ($resurl =~ m{^/public/$cdom/$cnum/syllabus}) {
+                $incourse = 1;
+                if ($env{'form.forceedit'}) {
+                    $forceview = 1;
+                } else {
+                    $forceedit = 1;
+                }
+                $cfile = $resurl;
+            } elsif (($resurl ne '') && (&is_on_map($resurl))) { 
+                if ($resurl =~ m{^/adm/$match_domain/$match_username/\d+/smppg|bulletinboard$}) {
+                    $incourse = 1;
+                    if ($env{'form.forceedit'}) {
+                        $forceview = 1;
+                    } else {
+                        $forceedit = 1;
+                    }
+                    $cfile = $resurl;
+                } elsif (($resurl eq '/res/lib/templates/simpleproblem.problem')) {
+                    $incourse = 1;
+                    $cfile = $resurl.'/smpedit';
+                } elsif ($resurl =~ /ext/) {
+                    $incourse = 1;
+                    # is external
+                }
+            } elsif ($resurl eq '/res/lib/templates/simpleproblem.problem/smpedit') {
+                my $template = '/res/lib/templates/simpleproblem.problem';
+                if (&is_on_map($template)) { 
+                    $incourse = 1;
+                    $forceview = 1;
+                    $cfile = $template;
                 }
             }
         }
-        unless ($uploaded) {
+        if ($uploaded || $incourse) {
+            $home=&homeserver($cnum,$cdom);
+        } else {
             $file=~s{^(priv/$match_domain/$match_username)}{/$1};
             $file=~s{^($match_domain/$match_username)}{/priv/$1};
             # Check that the user has permission to edit this resource
@@ -2686,14 +2777,15 @@
                 $cfile=$file;
             }
         }
-        if (($cfile ne '') && (($home ne '') && ($home ne 'no_host'))) {
+        if (($cfile ne '') && (!$incourse || $uploaded) && 
+            (($home ne '') && ($home ne 'no_host'))) {
             my @ids=&current_machine_ids();
             unless (grep(/^\Q$home\E$/, at ids)) {
                 $switchserver=1;
             }
         }
     }
-    return ($cfile,$home,$switchserver,$uploaded);
+    return ($cfile,$home,$switchserver,$forceedit,$forceview);
 }
 
 sub is_course_upload {
@@ -2707,6 +2799,31 @@
     return;
 }
 
+sub in_course {
+    my ($udom,$uname,$cdom,$cnum,$type) = @_;
+    $type ||= 'any';
+    if (!defined($cdom) || !defined($cnum)) {
+        my $cid  = $env{'request.course.id'};
+        $cdom = $env{'course.'.$cid.'.domain'};
+        $cnum = $env{'course.'.$cid.'.num'};
+    }
+    my $typesref;
+    if ($type eq 'all') {
+        $typesref = ['active','previous','future'];
+    } elsif ($type eq 'previous' || $type eq 'future') {
+        $typesref = [$type];
+    }
+    my %roles = &get_my_roles($uname,$udom,'userroles',
+                              $typesref,undef,[$cdom]);
+    my ($tmp) = keys(%roles);
+    return 0 if ($tmp =~ /^(con_lost|error|no_such_host)/i);
+    my @course_roles = grep(/^\Q$cnum\E:\Q$cdom\E:/, keys(%roles));
+    if (@course_roles > 0) {
+        return 1;
+    }
+    return 0;
+}
+
 # --------- File operations in /home/httpd/html/userfiles/$domain/1/2/3/$course
 # input: action, courseID, current domain, intended
 #        path to file, source of file, instruction to parse file for objects,


More information about the LON-CAPA-cvs mailing list