[LON-CAPA-cvs] cvs: loncom /html/res/adm/pages menu.html /interface lonmenu.pm mydesk.tab /xml lonxml.pm

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 06 Dec 2002 17:49:49 -0000


This is a MIME encoded message

--matthew1039196989
Content-Type: text/plain

matthew		Fri Dec  6 12:49:49 2002 EDT

  Modified files:              
    /loncom/html/res/adm/pages	menu.html 
    /loncom/xml	lonxml.pm 
    /loncom/interface	mydesk.tab lonmenu.pm 
  Log:
  Fix bug 262.  lonxml.pm now checks to see if you have permissions to edit
  the currently view resource.  mydesk.tab no longer calls cstrgo in menu.html
  so cstrgo and is_editable_resource (javascript functions) have been 
  removed from menu.html.  lonmenu.pm was cleaned up.
  This has been tested for authors and co-authors and across domains.
  
  
--matthew1039196989
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20021206124949.txt"

Index: loncom/html/res/adm/pages/menu.html
diff -u loncom/html/res/adm/pages/menu.html:1.78 loncom/html/res/adm/pages/menu.html:1.79
--- loncom/html/res/adm/pages/menu.html:1.78	Wed Nov 13 13:22:55 2002
+++ loncom/html/res/adm/pages/menu.html	Fri Dec  6 12:49:48 2002
@@ -4,7 +4,7 @@
 Remote Control
 
 //
-// $Id: menu.html,v 1.78 2002/11/13 18:22:55 www Exp $
+// $Id: menu.html,v 1.79 2002/12/06 17:49:48 matthew Exp $
 //
 // Copyright Michigan State University Board of Trustees
 //
@@ -241,42 +241,6 @@
    statusbot=bt;
    statuslocked=1;
    defdis();
-}
-
-function is_editable_resource (url) {
-// figure out if this a specific resource version
-   var Chunks = url.split('.');
-   var tmp = Chunks[Chunks.length-1];
-   if ((Chunks.length > 1) && (Math.floor(tmp) == tmp)) {
-       return false;
-   }
-// see if this is actually in resource space
-   var SlashChunks=url.split('/');
-   if (SlashChunks[1]!='res') { return false; } 
-   return true;
-}
-
-function cstrgo(currenturl,defaulturl) {
-   windowcheck();
-   var url;
-   if ((currenturl == null) || 
-       (currenturl == '')   || 
-       (! is_editable_resource(currenturl))) {
-      url = defaulturl;
-   } else {
-      var SlashChunks=currenturl.split('/');
-      SlashChunks[1]='priv';
-      var i;
-      for (i=2;i<SlashChunks.length;i++) {
-          SlashChunks[i]=SlashChunks[i+1];
-      }
-      SlashChunks.length--;
-      url=SlashChunks.join('/');
-   }
-   this.document['led'].src="ledsend.gif";
-   if (url != '') {
-       clientwindow.window.location.href="http://"+clienthost+url;
-   }
 }
 
 function go(url) {
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.216 loncom/xml/lonxml.pm:1.217
--- loncom/xml/lonxml.pm:1.216	Tue Dec  3 17:04:43 2002
+++ loncom/xml/lonxml.pm	Fri Dec  6 12:49:48 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.216 2002/12/03 22:04:43 sakharuk Exp $
+# $Id: lonxml.pm,v 1.217 2002/12/06 17:49:48 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -101,6 +101,8 @@
 use Apache::loncommon();
 use Apache::lonfeedback();
 use Apache::lonmsg();
+use Apache::lonmenu();
+use Apache::loncacc();
 
 #==================================================   Main subroutine: xmlparse  
 #debugging control, to turn on debugging modify the correct handler
@@ -373,6 +375,18 @@
     return $headerstring;
 }
 
+
+##
+## switchmenu - modeled on lonmenu::switchmenu, but better. 
+## Helper function for registerurl
+##
+sub switchmenu {
+    my ($row,$col,$imgsrc,$texttop,$textbot,$action,$description)=@_;
+    return(<<ENDSMENU);
+    menu.switchbutton($row,$col,'$imgsrc','$texttop','$textbot','$action','$description');
+ENDSMENU
+}
+
 sub registerurl {
     my $forcereg=shift;
     my $target = shift;
@@ -421,6 +435,62 @@
 ENDPARM
             }
 	}
+        ###
+        ### Determine whether or not to display the 'cstr' button for this
+        ### resource
+        ###
+        my $editbutton = '';
+        if ($ENV{'user.author'}) {
+            if ($ENV{'request.role'}=~/^(ca|au)/) {
+                # Set defaults for authors
+                my ($top,$bottom) = ('con-','struct');
+                my $action = "go('/priv/".$ENV{'user.name'}."');";
+                my $cadom  = $ENV{'request.role.domain'};
+                my $caname = $ENV{'user.name'};
+                my $desc = "Enter my resource construction space";
+                # Set defaults for co-authors
+                if ($ENV{'request.role'} =~ /^ca/) { 
+                    ($cadom,$caname)=($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
+                    ($top,$bottom) = ('co con-','struct');
+                    $action = 'go("/priv/'.$caname.'");';
+                    $desc = "Enter construction space as co-author";
+                }
+                # Check that we are on the correct machine
+                my $home = &Apache::lonnet::homeserver($caname,$cadom);
+                if ($home eq $Apache::lonnet::perlvar{'lonHostID'}) {
+                    $editbutton=&switchmenu
+                        (6,1,$top,,$bottom,$action,$desc);
+                }
+            }
+            ##
+            ## Determine if user can edit url.
+            ##
+            my $cfile='';
+            my $cfuname='';
+            my $cfudom='';
+            if ($ENV{'request.filename'}) {
+                my $file=&Apache::lonnet::declutter($ENV{'request.filename'});
+                $file=~s/^(\w+)\/(\w+)/\/priv\/$2/;
+                # Chech that the user has permission to edit this resource
+                ($cfuname,$cfudom)=&Apache::loncacc::constructaccess($file,$1);
+                if (defined($cfudom)) {
+                    if (&Apache::lonnet::homeserver($cfuname,$cfudom) 
+                        eq $Apache::lonnet::perlvar{'lonHostID'}) {
+                        $cfile=$file;
+                    }
+                }
+            }        
+            # Finally, turn the button on or off
+            if ($cfile) {
+                $editbutton=&switchmenu
+                    (6,1,'cstr.gif','edit','resource',
+                     'go("'.$cfile.'");',"Edit this resource");
+            } elsif ($editbutton eq '') {
+                $editbutton = '    menu.clearbut(6,1);';
+            }
+        }
+        ###
+        ###
 	$result = (<<ENDREGTHIS);
      
 <script language="JavaScript">
@@ -456,6 +526,7 @@
           menu.switchbutton
                                (9,3,'anot.gif','anno-','tations','annotate()','Make notes and annotations about this resource');
           $hwkadd
+          $editbutton
     }
 
     function LONCAPAstale() {
Index: loncom/interface/mydesk.tab
diff -u loncom/interface/mydesk.tab:1.36 loncom/interface/mydesk.tab:1.37
--- loncom/interface/mydesk.tab:1.36	Fri Dec  6 10:10:19 2002
+++ loncom/interface/mydesk.tab	Fri Dec  6 12:49:49 2002
@@ -40,8 +40,8 @@
 5:3:pccc:$requested_domain:ccrs.gif:create:course:go('/adm/createcourse');:Create a new course
 5:3:popa:$crs:parm.gif:course:parms:go('/adm/parmset');:Set deadlines and other assessment parameters, as well as modify course environment 
 6:1:clear
-6:1:author:any:cstr.gif:con-:struct:cstrgo(currentURL,'/priv/$uname/');:Enter my resource construction space
-6:1:author:rca:cstr.gif:co con-:struct:cstrgo(currentURL,'/priv/$uname/');:Enter construction space as a co-author
+6:1:author:rau:cstr.gif:con-:struct:go('/priv/$uname/');:Enter my resource construction space
+6:1:author:rca:cstr.gif:co con-:struct:go('/priv/$caname/');:Enter construction space as a co-author
 6:2:clear
 6:2:author:any:res.gif:resource:space:go('/res/$udom/$uname/?launch=1');:Browse published resources
 6:2:author:rca:res.gif:co res:space:go('/res/$udom/$uname/?launch=1');:Browse published resources
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.28 loncom/interface/lonmenu.pm:1.29
--- loncom/interface/lonmenu.pm:1.28	Mon Nov 18 10:23:32 2002
+++ loncom/interface/lonmenu.pm	Fri Dec  6 12:49:49 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.28 2002/11/18 15:23:32 www Exp $
+# $Id: lonmenu.pm,v 1.29 2002/12/06 17:49:49 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -161,22 +161,20 @@
 	    }
         } elsif ($pro eq 'author') {
             if ($author) {
-                if (($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) {
+                if ((($prt eq 'rca') && ($ENV{'request.role'}=~/^ca/)) ||
+                    (($prt eq 'rau') && ($ENV{'request.role'}=~/^au/))) {
                     # Check that we are on the correct machine
-		    my ($cadom,$caname)=
+                    my $cadom=$requested_domain;
+                    my $caname=$ENV{'user.name'};
+                    if ($prt eq 'rca') {
+		       ($cadom,$caname)=
                                ($ENV{'request.role'}=~/(\w+)\/(\w+)$/);
+                    }                       
+                    $act =~ s/\$caname/$caname/g;
                     my $home = &Apache::lonnet::homeserver($caname,$cadom);
                     if ($home eq $r->dir_config('lonHostID')) {
                         $output.=switch($caname,$cadom,
                                         $row,$col,$img,$top,$bot,$act,$desc);
-                    }
-                } elsif ($prt eq 'any') {
-                    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,$desc);
                     }
                 }
             }

--matthew1039196989--