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

raeburn raeburn@source.lon-capa.org
Wed, 20 May 2009 20:11:35 -0000


This is a MIME encoded message

--raeburn1242850295
Content-Type: text/plain

raeburn		Wed May 20 20:11:35 2009 EDT

  Modified files:              (Branch: version_2_9_X)
    /loncom/interface	lonmenu.pm 
  Log:
  - Backport 1.248, 1.249, 1.251, 1.252, 1.255, 1.257, 1.258, 1.259,
             1.261, 1.262, 1.264, 1.266
  
  
--raeburn1242850295
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090520201135.txt"

Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.244 loncom/interface/lonmenu.pm:1.244.2.1
--- loncom/interface/lonmenu.pm:1.244	Wed Nov 19 19:43:08 2008
+++ loncom/interface/lonmenu.pm	Wed May 20 20:11:35 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.244 2008/11/19 19:43:08 jms Exp $
+# $Id: lonmenu.pm,v 1.244.2.1 2009/05/20 20:11:35 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -170,11 +170,11 @@
     return &Apache::lonlocal::texthash('ret' => 'Return to Last Location',
 				       'nav' => 'Navigate Contents',
 				       'main' => 'Main Menu',
-                                       'roles' => (&show_course()?
+                                       'roles' => (&Apache::loncommon::show_course()?
                                                     'Courses':'Roles'),
                                        'other' => 'Other Roles',
                                        'docs' => 'Edit Course',
-                                       'exit' => 'Exit',
+                                       'exit' => 'Logout',
                                        'login' => 'Log In',
 				       'launch' => 'Launch Remote Control',
                                        'groups' => 'Groups',
@@ -493,7 +493,7 @@
         if ($env{'request.symb'} ne '' &&
 	    $env{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form|task)$/) {
 	    if (&Apache::lonnet::allowed('mgr',$crs)) {
-		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_3]',
+		$hwkadd.=&switch('','',7,2,'pgrd.gif','problem[_1]','grades[_4]',
                        "gocmd('/adm/grades','gradingmenu')",
                        'Modify user grades for this assessment resource');
             } elsif (&Apache::lonnet::allowed('vgr',$crs)) {
@@ -514,6 +514,12 @@
         ### resource
         ###
         my $editbutton = '';
+        my $noeditbutton = 1;
+        my ($cnum,$cdom);
+        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)/) {
                 # Set defaults for authors
@@ -541,6 +547,7 @@
 		foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 		if (!$allowed) {
 		    $editbutton=&switch('','',6,1,$top,,$bottom,$action,$desc);
+                    $noeditbutton = 0;
                 }
             }
             ##
@@ -549,6 +556,7 @@
             my $cfile='';
             my $cfuname='';
             my $cfudom='';
+            my $uploaded;
             if ($env{'request.filename'}) {
                 my $file=&Apache::lonnet::declutter($env{'request.filename'});
                 $file=~s/^($match_domain)\/($match_username)/\/priv\/$2/;
@@ -569,10 +577,27 @@
                 $editbutton=&switch
                     ('','',6,1,'pcstr.gif','edit[_1]','resource[_2]',
                      "go('".$cfile."');","Edit this resource");
+                $noeditbutton = 0;
             } elsif ($editbutton eq '') {
                 $editbutton=&clear(6,1);
             }
         }
+        if (($noeditbutton) && ($env{'request.filename'})) {
+            if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
+                my $file=&Apache::lonnet::declutter($env{'request.filename'});
+                if (defined($cnum) && defined($cdom)) {
+                    if (&is_course_upload($file,$cnum,$cdom)) {
+                        my $cfile = &edit_course_upload($file,$cnum,$cdom);
+                        if ($cfile) {
+                            $editbutton=&switch
+                                        ('','',6,1,'pcstr.gif','edit[_1]',
+                                         'resource[_2]',"go('".$cfile."');",
+                                         'Edit this resource');
+                        }
+                    }
+                }
+            }
+        }
         ###
         ###
 # Prepare the rest of the buttons
@@ -590,7 +615,7 @@
                 $menuitems=(<<ENDMENUITEMS);
 s&6&1&list.gif&list[_1]&dir[_1]&golist('$esc_currdir')&List current directory
 s&6&2&rtrv.gif&retrieve[_1]&version[_1]&gocstr('/adm/retrieve','/~$uname/$cleandisfn')&Retrieve old version
-s&6&3&pub.gif&publish[_1]&resource[_1]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
+s&6&3&pub.gif&publish[_1]&resource[_3]&gocstr('/adm/publish','/~$uname/$cleandisfn')&Publish this resource
 s&7&1&del.gif&delete[_1]&resource[_2]&gocstr('/adm/cfile?action=delete','/~$uname/$cleandisfn')&Delete this resource
 s&7&2&prt.gif&prepare[_1]&printout[_1]&gocstr('/adm/printout','/~$uname/$cleandisfn')&Prepare a printable document
 ENDMENUITEMS
@@ -623,7 +648,7 @@
             unless ($env{'request.noversionuri'}=~/\/(bulletinboard|smppg|navmaps|syllabus|aboutme)(\?|$)/) {
 		if (!$env{'request.enc'}) {
 		    $menuitems.=(<<ENDREALRES);
-s&6&3&catalog.gif&catalog[_1]&info[_1]&catalog_info()&Show catalog information
+s&6&3&catalog.gif&catalog[_2]&info[_1]&catalog_info()&Show Metadata
 ENDREALRES
                 }
 	        $menuitems.=(<<ENDREALRES);
@@ -807,6 +832,42 @@
     return $result;
 }
 
+sub is_course_upload {
+    my ($file,$cnum,$cdom) = @_;
+    my $uploadpath = &LONCAPA::propath($cdom,$cnum);
+    $uploadpath =~ s{^\/}{};
+    if (($file =~ m{^\Q$uploadpath\E/userfiles/docs/}) ||
+        ($file =~ m{^userfiles/\Q$cdom\E/\Q$cnum\E/docs/})) {
+        return 1;
+    }
+    return;
+}
+
+sub edit_course_upload {
+    my ($file,$cnum,$cdom) = @_;
+    my $cfile;
+    if ($file =~/\.(htm|html|css|js|txt)$/) {
+        my $ext = $1;
+        my $url = &Apache::lonnet::hreflocation('',$file);
+        my $home = &Apache::lonnet::homeserver($cnum,$cdom);
+        my @ids=&Apache::lonnet::current_machine_ids();
+        my $dest;
+        if ($home && grep(/^\Q$home\E$/,@ids)) {
+            $dest = $url.'?forceedit=1';
+        } else {
+            unless (&Apache::lonnet::get_locks()) {
+                $dest = '/adm/switchserver?otherserver='.
+                        $home.'&role='.$env{'request.role'}.
+                        '&url='.$url.'&forceedit=1';
+            }
+        }
+        if ($dest) {
+            $cfile = &HTML::Entities::encode($dest,'"<>&');
+        }
+    }
+    return $cfile;
+}
+
 sub loadevents() {
     if ($env{'request.state'} eq 'construct' ||
 	$env{'request.noversionuri'} =~ m{^/res/adm/pages/}) { return ''; }
@@ -914,8 +975,9 @@
         ($env{'environment.remote'} eq 'off')) { return ''; }
 
     my $esclowerurl=&escape($lowerurl);
-    my $link=&mt('<a href="[_1]">Continue</a> on in Inline Menu mode',
-		 "/adm/remote?action=collapse&amp;url=$esclowerurl");
+    my $link=&mt('[_1]Continue[_2] on in Inline Menu mode',
+		 '<a href="/adm/remote?action=collapse&amp;url='.$esclowerurl.'">',
+                 '</a>');
     return(<<ENDREMOTEFORM);
 <p>
 <form name="wheel">
@@ -1132,7 +1194,7 @@
     my $uname=$env{'user.name'};
     my $udom=$env{'user.domain'};
     my $adv=$env{'user.adv'};
-    my $show_course=&show_course();
+    my $show_course=&Apache::loncommon::show_course();
     my $author=$env{'user.author'};
     my $crs='';
     if ($env{'request.course.id'}) {
@@ -1226,6 +1288,34 @@
                     }
                 }
             }
+        } 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 'reqcrs') {
+                my $showreqcrs = 0;
+                foreach my $type ('official','unofficial') {
+                    if (&Apache::lonnet::usertools_access($env{'user.name'},
+                                                    $env{'user.domain'},
+                                                    $type,undef,'requestcourses')) {
+                        $showreqcrs = 1;
+                        last;
+                    }
+                }
+                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') ||
@@ -1442,16 +1532,16 @@
    bmquery=window.open('','bmquery','width=365,height=165,scrollbars=0');
    bmquery.document.write(
    '$start_page_bookmark'
-   +"<center><form method='post'"
-   +" name='newlink' action='/adm/bookmarks' target='bmquery' "
-   +">\\n <table width=340 height=150 "
-   +"bgcolor='ffffff' align=center><tr><td>Link Name:<br /><input "
-   +"type='text' name='title' size=45 value='"+clienttitle+"' />"
-   +"<br />Address:<br /><input type='text' name='address' size='45' "
-   +"value='"+clienthref+"' /><br /><center><input type='submit' "
-   +"value='Save' /> <input type='button' value='Close (no save)' "
-   +"onclick='javascript:window.close();' /><\\/center><\\/td>"
-   +"<\\/tr><\\/table><\\/form><\\/center>"
+   +'<center><form method="post"'
+   +' name="newlink" action="/adm/bookmarks" target="bmquery" '
+   +'> <table width="340" height="150" '
+   +'bgcolor="ffffff" align="center"><tr><td>Link Name:<br /><input '
+   +'type="text" name="title" size="45" value="'+clienttitle+'" />'
+   +'<br />Address:<br /><input type="text" name="address" size="45" '
+   +'value="'+clienthref+'" /><br /><center><input type="submit" '
+   +'value="Save" /> <input type="button" value="Close" '
+   +'onclick="javascript:window.close();" /></center></td>'
+   +'</tr></table></form></center>'
    +'$end_page_bookmark' );
    bmquery.document.close();
 }
@@ -1527,7 +1617,7 @@
 sub roles_selector {
     my ($cdom,$cnum) = @_;
     my $now = time;
-    my (%courseroles,%seccount,%gotnosection);
+    my (%courseroles,%seccount);
     my $is_cc;
     my $role_selector;
     if ($env{'user.role.cc./'.$cdom.'/'.$cnum}) {
@@ -1542,35 +1632,9 @@
         }
     }
     if ($is_cc) {
-        my %adv_roles =
-             &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
-        foreach my $role (keys(%adv_roles)) {
-            my ($urole,$usec) = split(/:/,$role);
-            if (!$gotnosection{$urole}) {
-                $seccount{$urole} ++;
-                $gotnosection{$urole} = 1;
-            }
-            if (ref($courseroles{$urole}) eq 'ARRAY') {
-                if ($usec ne '') {
-                    if (!grep(/^Q$usec\E$/,@{$courseroles{$urole}})) {
-                        push(@{$courseroles{$urole}},$usec);
-                        $seccount{$urole} ++;
-                    }
-                }
-            } else {
-                @{$courseroles{$urole}} = ();
-                if ($usec ne '') {
-                    $seccount{$urole} ++;
-                    push(@{$courseroles{$urole}},$usec);
-                }
-            }
-        }
-        my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
-        @{$courseroles{'st'}} = ();
-        if (keys(%sections_count) > 0) {
-            push(@{$courseroles{'st'}},keys(%sections_count));
-        }
+        &get_all_courseroles($cdom,$cnum,\%courseroles,\%seccount);
     } else {
+        my %gotnosection;
         foreach my $item (keys(%env)) {
             if ($item =~ m-^user\.role\.([^.]+)\./\Q$cdom\E/\Q$cnum\E/?(\w*)$-) {
                 my $role = $1;
@@ -1628,6 +1692,61 @@
     return $role_selector;
 }
 
+sub get_all_courseroles {
+    my ($cdom,$cnum,$courseroles,$seccount) = @_;
+    unless ((ref($courseroles) eq 'HASH') && (ref($seccount) eq 'HASH')) {
+        return;
+    }
+    my ($result,$cached) =
+        &Apache::lonnet::is_cached_new('getcourseroles',$cdom.'_'.$cnum);
+    if (defined($cached)) {
+        if (ref($result) eq 'HASH') {
+            if ((ref($result->{'roles'}) eq 'HASH') &&
+                (ref($result->{'seccount'}) eq 'HASH')) {
+                %{$courseroles} = %{$result->{'roles'}};
+                %{$seccount} = %{$result->{'seccount'}};
+                return;
+            }
+        }
+    }
+    my %gotnosection;
+    my %adv_roles =
+         &Apache::lonnet::get_course_adv_roles($env{'request.course.id'},1);
+    foreach my $role (keys(%adv_roles)) {
+        my ($urole,$usec) = split(/:/,$role);
+        if (!$gotnosection{$urole}) {
+            $seccount->{$urole} ++;
+            $gotnosection{$urole} = 1;
+        }
+        if (ref($courseroles->{$urole}) eq 'ARRAY') {
+            if ($usec ne '') {
+                if (!grep(/^\Q$usec\E$/,@{$courseroles->{$urole}})) {
+                    push(@{$courseroles->{$urole}},$usec);
+                    $seccount->{$urole} ++;
+                }
+            }
+        } else {
+            @{$courseroles->{$urole}} = ();
+            if ($usec ne '') {
+                $seccount->{$urole} ++;
+                push(@{$courseroles->{$urole}},$usec);
+            }
+        }
+    }
+    my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum,['st']);
+    @{$courseroles->{'st'}} = ();
+    if (keys(%sections_count) > 0) {
+        push(@{$courseroles->{'st'}},keys(%sections_count));
+        $seccount->{'st'} = scalar(keys(%sections_count));
+    }
+    my $rolehash = {
+                     'roles'    => $courseroles,
+                     'seccount' => $seccount,
+                   };
+    &Apache::lonnet::do_cache_new('getcourseroles',$cdom.'_'.$cnum,$rolehash);
+    return;
+}
+
 sub jump_to_role {
     my ($cdom,$cnum,$seccount,$courseroles) = @_;
     my %lt = &Apache::lonlocal::texthash(

--raeburn1242850295--