Diff for /loncom/lonnet/perl/lonnet.pm between versions 1.1192 and 1.1193

version 1.1192, 2012/10/29 17:39:02 version 1.1193, 2012/10/31 12:54:23
Line 2645  sub allowuploaded { Line 2645  sub allowuploaded {
     &Apache::lonnet::appenv(\%httpref);      &Apache::lonnet::appenv(\%httpref);
 }  }
   
   #
   # Determine if the current user should be able to edit a particular resource,
   # when viewing in course context.
   # (a) When viewing resource used to determine if "Edit" item is included in 
   #     Functions.
   # (b) When displaying folder contents in course editor, used to determine if
   #     "Edit" link will be displayed alongside resource.
   #
   #  input: 3 args -- filename (decluttered), course number and course domain.
   #  output: array of four scalars -- 
   #          $cfile -- url for file editing if editable on current server
   #          $home -- homeserver of resource (i.e., for author if published,
   #                                           or course if uploaded.).
   #          $switchserver --  1 if server switch will be needed.
   #          $uploaded -- 1 if resource is a file uploaded to a course.
   #
   
   sub can_edit_resource {
       my ($file,$cnum,$cdom) = @_;
       my ($cfile,$home,$switchserver,$uploaded);
       if ($file ne '') {
           if (($cnum =~ /$match_courseid/) && ($cdom =~ /$match_domain/)) {
               $uploaded = &is_course_upload($file,$cnum,$cdom);
               if ($uploaded) {
                   $home=&homeserver($cnum,$cdom);
                   if ($file =~/\.(htm|html|css|js|txt)$/) {
                       $cfile = &hreflocation('',$file);
                   }
               }
           }
           unless ($uploaded) {
               $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
               my $setpriv = 1;
               my ($cfuname,$cfudom)=&constructaccess($file,$setpriv);
               if (defined($cfudom)) {
                   $home=&homeserver($cfuname,$cfudom);
                   $cfile=$file;
               }
           }
           if (($cfile ne '') && (($home ne '') && ($home ne 'no_host'))) {
               my @ids=&current_machine_ids();
               unless (grep(/^\Q$home\E$/,@ids)) {
                   $switchserver=1;
               }
           }
       }
       return ($cfile,$home,$switchserver,$uploaded);
   }
   
   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;
   }
   
 # --------- File operations in /home/httpd/html/userfiles/$domain/1/2/3/$course  # --------- File operations in /home/httpd/html/userfiles/$domain/1/2/3/$course
 # input: action, courseID, current domain, intended  # input: action, courseID, current domain, intended
 #        path to file, source of file, instruction to parse file for objects,  #        path to file, source of file, instruction to parse file for objects,

Removed from v.1.1192  
changed lines
  Added in v.1.1193


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>