Diff for /loncom/interface/portfolio.pm between versions 1.10 and 1.18

version 1.10, 2004/07/01 18:59:33 version 1.18, 2004/07/28 19:00:19
Line 18 Line 18
 #  #
 # /home/httpd/html/adm/gpl.txt  # /home/httpd/html/adm/gpl.txt
 #  #
   
   
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
   
   
 package Apache::portfolio;  package Apache::portfolio;
 use strict;  use strict;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
Line 32  use Apache::lonnet; Line 29  use Apache::lonnet;
 use Apache::lontexconvert;  use Apache::lontexconvert;
 use Apache::lonfeedback;  use Apache::lonfeedback;
 use Apache::lonlocal;  use Apache::lonlocal;
   
   # receives a file name and path stub from username/userfiles/portfolio/
   # returns an anchor tag consisting encoding filename and currentpath
 sub makeAnchor{  sub makeAnchor{
     # receives a file name and path stub from username/userfiles/portfolio/  
     # returns an anchor tag consisting encoding filename and currentpath  
     my ($fileName, $currentPath) = @_;      my ($fileName, $currentPath) = @_;
     my $anchor = '<a href="/adm/portfolio?selectfile='.$fileName.'&currentpath='.$currentPath.'">'.$fileName.'</a>';      my $anchor = '<a href="/adm/portfolio?selectfile='.$fileName.'&currentpath='.$currentPath.'">'.$fileName.'</a>';
     return $anchor;      return $anchor;
 }  }
   
   # returns html with <br /> separated contents of the directory
   # returns a <strong>currentFile</strong> (bolds the selected file/dir)
 sub displayDirectory {  sub displayDirectory {
     # returns html with <br /> separated contents of the directory      my ($currentPath, $currentFile, @dirList,) = @_;
     # returns a <strong>currentFile</strong> (bolds the selected file/dir)  
     my ($currentPath, $currentFile, $isDir, @dirList,) = @_;  
     my $displayOut='';        my $displayOut='';  
     my $fileName;      my $fileName;
     my $upPath;      my $upPath;
Line 57  sub displayDirectory { Line 56  sub displayDirectory {
             $upPath = $1;              $upPath = $1;
         }          }
                   
         $displayOut = $displayOut.'<a href="/adm/portfolio?selectfile='.$upPath.'&currentpath='.$upPath.'">..</a><br />';          # $displayOut = $displayOut.'<a href="/adm/portfolio?selectfile='.$upPath.'&currentpath='.$upPath.'">..</a><br />';
     } else {      } else {
         $displayOut = $displayOut.'at root '.$currentPath.'<br />';          # $displayOut = $displayOut.'at root '.$currentPath.'<br />';
     }      }
     foreach my $line (@dirList) {      foreach my $line (@dirList) {
     #$strip holds directory/file name      #$strip holds directory/file name
Line 69  sub displayDirectory { Line 68  sub displayDirectory {
             if ($testdir =~ m:^1:){              if ($testdir =~ m:^1:){
                 # handle directories different from files                  # handle directories different from files
                 if ($fileName eq $currentFile){ #checks to bold the selected file                  if ($fileName eq $currentFile){ #checks to bold the selected file
                     $displayOut.= '<strong>'.(makeAnchor($fileName.'/', $currentPath.$fileName.'/').'</strong><br />');                      $displayOut.= '<strong>'.(makeAnchor($fileName.'/', $fileName.'/').'</strong><br />'."\n");
                 }else{                  }else{
                     $displayOut.= (makeAnchor($fileName.'/', $currentPath.$fileName.'/').'<br />');                      $displayOut.= (makeAnchor($fileName.'/', $fileName.'/').'<br />'."\n");
                 }                  }
             }else{              }else{
                 if ($fileName eq $currentFile){ #checks to bold the selected file                  if ($fileName eq $currentFile){ #checks to bold the selected file
                     $displayOut.='<strong>'.(makeAnchor($fileName, $currentPath).'</strong><br />');                      $displayOut.='<strong>'.(makeAnchor($fileName, $currentPath).'</strong><br />'."\n");
                 }else{                  }else{
                     $displayOut.=(makeAnchor($fileName, $currentPath).'<br />');                      $displayOut.=(makeAnchor($fileName, $currentPath).'<br />'."\n");
                 }                  }
             }              }
               
         }          }
         
     }      }
Line 88  sub displayDirectory { Line 88  sub displayDirectory {
 sub displayActions {  sub displayActions {
     # returns html to offer user appropriate actions depending on selected file/directory      # returns html to offer user appropriate actions depending on selected file/directory
     my $displayOut;      my $displayOut;
     my ($currentPath, $currentFile, $isDir, $isEmpty) = @_;      my ($currentPath, $currentFile, $isEmpty) = @_;
 #   $displayOut = 'here are actions for '.$currentFile;  #   $displayOut = 'here are actions for '.$currentFile;
     if ($currentFile =~ m:/$:){      if ($currentFile =~ m:/$:){
         # if the selected file is a directory, these are the options          # if the selected file is a directory, these are the options
Line 158  sub displayActions { Line 158  sub displayActions {
 sub handler {  sub handler {
     # this handles file management      # this handles file management
     my $r = shift;      my $r = shift;
       my $iconpath= $r->dir_config('lonIconsURL') . "/";
     my @dirList; # will hold directory listing as array      my @dirList; # will hold directory listing as array
     my $udir; # returned from home server      my $udir; # returned from home server
     my $currentPath; # path assuming /userfiles/portfolio/ as root      my $currentPath; # path assuming /userfiles/portfolio/ as root
Line 165  sub handler { Line 166  sub handler {
     my $action; # delete, rename, makedirectory, removedirectory,      my $action; # delete, rename, makedirectory, removedirectory,
     my $filenewname; # for rename action (guess what we do with it!)      my $filenewname; # for rename action (guess what we do with it!)
     my $isFile;      my $isFile;
     my $isDir;  
     my $isEmpty;      my $isEmpty;
     # send header      my $dirptr=16384;
     # FIXME need to start using  
     &Apache::loncommon::no_cache($r);      &Apache::loncommon::no_cache($r);
     &Apache::loncommon::content_type($r, 'text/html');      &Apache::loncommon::content_type($r,'text/html');
     &Apache::loncommon::bodytag('Portfolio Managment', 'bgcolor="dogfood"');  
 #  
 #    $r->content_type('text/html');  
     $r->send_http_header;      $r->send_http_header;
 #    $r->print('<html><head><title>'.      # Give the LON-CAPA page header
 #               'Portfolio Management'.      $r->print('<html><head><title>'.
 #               "</title></head>\n");                &mt('Portfolio Manager').
 #                 "</title></head>\n".
     # FIXME need to start using                &Apache::loncommon::bodytag('Portfolio Manager'));
 #    $r->print('      $r->rflush();
 # <body bgcolor="dogfood">  
 # <blockquote>');  
   
 #    $r->content_type('text/html');  
 #    $r->send_http_header;  
 #    $r->print('<html><head><title>'.  
 #              'Portfolio Management'.  
 #              "</title></head>\n");  
 #  
 #    $r->print ('  
 #    <body bgcolor="dogfood">  
 #    <blockquote>');  
     #grab stuff that was sent  
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['selectfile','currentpath', 'currentfile']);                                              ['selectfile','currentpath', 'currentfile']);
 #   $r->print ('<br />CP= '.$ENV{'form.currentpath'}.'<br />');  
     # currentPath and currentFile need to be set for the rest of things to happen      # currentPath and currentFile need to be set for the rest of things to happen
     # sometimes, currentFile will be passed by a form field, selectedfile      # sometimes, currentFile will be passed by a form field, selectedfile
     # if there is no 'form.selectedfile' then the current directory is       # if there is no 'form.selectedfile' then the current directory is 
     # considered as selected       # considered as selected 
     if ($ENV{'form.currentpath'}){      if ($ENV{'form.currentpath'}) {
         $currentPath = $ENV{'form.currentpath'};          $currentPath = $ENV{'form.currentpath'};
     }else{      } else {
         $currentPath = '/';          $currentPath = '/';
     }      }
     if ($ENV{'form.selectfile'}){      if ($ENV{'form.selectfile'}) {
         $r->print('<br />found selectfile'.$ENV{'form.selectfile'} .'<br />');  
         # have to check if the selected file is a subdirectory          # have to check if the selected file is a subdirectory
         if ($ENV{'form.selectfile'} =~ /-\(Dir\)/){          if ($ENV{'form.selectfile'} =~ /-\(Dir\)/){
             # $currentPath =~ /\-\(Dir\)/;              # $currentPath =~ /\-\(Dir\)/;
Line 215  sub handler { Line 196  sub handler {
             $r->print('<br />'.$currentPath.'<br />');              $r->print('<br />'.$currentPath.'<br />');
         }          }
         $currentFile = $ENV{'form.selectfile'};          $currentFile = $ENV{'form.selectfile'};
     }else{      } else {
         $currentFile = '';          $currentFile = '';
     }      }
     # if we're uploading a file, we need to do it early so it will show in the directory list      # if we're uploading a file, we need to do it early so it will show in the directory list
     if ($ENV{'form.uploaddoc.filename'}){      if ($ENV{'form.uploaddoc.filename'}) {
         $r->print ($ENV{'form.storeupl'}.'<br />');          $r->print($ENV{'form.storeupl'}.'<br />');
         $r->print (&Apache::lonnet::userfileupload('uploaddoc','','portfolio'.$currentPath).'<br />');            $r->print(&Apache::lonnet::userfileupload('uploaddoc','','portfolio'.$currentPath).'<br />');  
     }      }
     # similarly, we need to delete or rename files before getting directory list      # similarly, we need to delete or rename files before getting directory list
     if ($ENV{'form.selectfile'}){      if ($ENV{'form.selectfile'}){
         if ($ENV{'form.fileaction'} eq 'delete'){          if ($ENV{'form.fileaction'} eq 'delete') {
             $r->print('<br />trying to delete '.$currentPath.$ENV{'form.selectfile'}.'<br />');              $r->print('<br />trying to delete '.$currentPath.$ENV{'form.selectfile'}.'<br />');
             $r->print(&Apache::lonnet::removeuserfile($ENV{'user.name'}, $ENV{'user.domain'},'portfolio'.$currentPath.$ENV{'form.selectfile'}));              $r->print(&Apache::lonnet::removeuserfile($ENV{'user.name'}, $ENV{'user.domain'},'portfolio'.$currentPath.$ENV{'form.selectfile'}));
             $currentFile = '';              $currentFile = '';
         }elsif($ENV{'form.fileaction'} eq 'rename')  {          } elsif ($ENV{'form.fileaction'} eq 'rename') {
             &Apache::lonnet::portfoliomanage($currentPath.$ENV{'form.selectfile'}, 'rename', $currentPath.$ENV{'form.filenewname'} );              &Apache::lonnet::portfoliomanage($currentPath.$ENV{'form.selectfile'}, 'rename', $currentPath.$ENV{'form.filenewname'} );
             # $r->print ('We will rename your file');  
         }          }
     }      }
     # we always need $dirList, plus this will return information about the current file      # we always need $dirList, plus this will return information about the current file
     # as well as information about he home server directory structure, specifically      # as well as information about the home server directory structure, specifically
     # the path to the users userfiles directory.          # the path to the users userfiles directory.    
 #    $r->print('dir list follows<br />'.&Apache::lonnet::portfoliolist($currentPath, $currentFile).'<br />');      # 
  my $list = &Apache::lonnet::portfoliolist($currentPath, $currentFile);      my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
  @dirList = split(/:/,$list);       $ENV{'user.name'}).
 #    foreach my $line (@dirlist) {         '/userfiles/portfolio'.$currentPath;
 #       @dirList = &Apache::lonnet::dirlist($currentPath,  $ENV{'user.domain'}, $ENV{'user.name'}, $portfolio_root);
 #     #$strip holds directory/file name  
 #     #$dom   
 #     my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);   
 #     $r->print ($strip.' '.$testdir.'<br />');  
 #    }  
 #    @dirList = split /<br\s\/>/, (&Apache::lonnet::portfoliolist($currentPath, $currentFile));  
           
     # portfoliolist returns isdir, isfile and udir as the final array elements      if (@dirList == 2) { # need to know if directory is empty so it can be removed if desired
     # we'll pop them off the bottom of the array, and put them where they belong  
       
     # $londcall added to help debug, contains the command sent to lond  
  #   my $londcall = pop @dirList;  
  #   $r->print ('<br />udir '.$londcall.'<br />');  
  #   $udir = pop @dirList;  
  #   $r->print ('<br />path returned '.$udir.'<br />');  
  #   $isFile = pop @dirList;  
 #   $r->print ('<br />isfile '.$isFile.'<br />');  
 #    $isDir = pop @dirList;  
     if (@dirList == 2){ # need to know if directory is empty to it can be removed if desired  
         $isEmpty = 1;          $isEmpty = 1;
     }else{      } else {
         $isEmpty = 0;          $isEmpty = 0;
     }      }
 #   $r->print ('<br />lines left ind dirlist '.@dirList.'<br />');     
 #   return OK if $r->header_only;      if ($ENV{'form.selectfile'}) {
     # Stuff to maintain proper setting for selected file          if ($ENV{'form.fileaction'} eq 'delete') {
     if ($ENV{'form.selectfile'}){  
         if ($ENV{'form.fileaction'} eq 'delete'){  
             &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef );              &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef );
             $ENV{'portfolio.file'} = 'Selected File Deleted';              $ENV{'portfolio.file'} = 'Selected File Deleted';
         }elsif($ENV{'form.fileaction'} eq 'rename')  {          } elsif ($ENV{'form.fileaction'} eq 'rename') {
             &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'} );              &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'});
 #           $r->print ('We will rename your file');          } else {
         }else{  
       
         # Remember user's file selection for later          # Remember user's file selection for later
         $ENV{'portfolio.file'} = $ENV{'form.selectfile'};          $ENV{'portfolio.file'} = $ENV{'form.selectfile'};
         # offer things user can do with selected file          # offer things user can do with selected file
Line 291  sub handler { Line 250  sub handler {
     # Display begins here      # Display begins here
     #      #
     ##############################      ##############################
     $r->print ('<hr /> start ');      $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
     $r->print ($udir);              '<tr><th>&nbsp;</th><th>Actions</th><th>Name</th><th>Title</th><th>Status</th><th>Last Modified</th></tr>');
     $r->print ('<table border=1><tr><td>');      foreach my $line (@dirList) {
     $r->print (displayDirectory ($currentPath, $currentFile, $isDir, @dirList));      #$strip holds directory/file name
     $r->print ('</td>><td>');      #$dom 
     $r->print (displayActions ($currentPath, $currentFile, $isDir, $isEmpty));      my ($fileName,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
     $r->print ('</td>></tr></table>');          if ($dirptr&$testdir){
     $r->print ('<br />end display<br /><hr />');              $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td></tr>'); 
     $r->print ('</blockquote></body>');          }else{
               $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'doc.gif"></td></tr>');
           }
       }
   #   <tr bgcolor="#FFAA99"> pink bg 
   #   <tr bgcolor="#CCCCFF"> blue bg            
   #   $r->print(displayDirectory($currentPath, $currentFile, @dirList));
   #    $r->print('</td>><td>');
   #   $r->print(displayActions($currentPath, $currentFile, $isEmpty));
       $r->print('</table>');
       $r->print('</blockquote>');
       $r->print("</body>\n</html>\n");
       $r->rflush();
     return OK;      return OK;
 }  }
   

Removed from v.1.10  
changed lines
  Added in v.1.18


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