File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.55: download - view: text, annotated - select for diffs
Tue Nov 9 21:51:14 2004 UTC (19 years, 8 months ago) by banghart
Branches: MAIN
CVS tags: HEAD
	Cannot rename or delete locked files. (Still need to improve
	user interface to remove delete and rename options for locked
	files.)

    1: # Copyright Michigan State University Board of Trustees
    2: #
    3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    4: #
    5: # LON-CAPA is free software; you can redistribute it and/or modify
    6: # it under the terms of the GNU General Public License as published by
    7: # the Free Software Foundation; either version 2 of the License, or 
    8: # (at your option) any later version.
    9: #
   10: # LON-CAPA is distributed in the hope that it will be useful,
   11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13: # GNU General Public License for more details.
   14: #
   15: # You should have received a copy of the GNU General Public License
   16: # along with LON-CAPA; if not, write to the Free Software
   17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18: #
   19: # /home/httpd/html/adm/gpl.txt
   20: #
   21: # http://www.lon-capa.org/
   22: #
   23: 
   24: package Apache::portfolio;
   25: use strict;
   26: use Apache::Constants qw(:common :http);
   27: use Apache::loncommon;
   28: use Apache::lonnet;
   29: use Apache::lontexconvert;
   30: use Apache::lonfeedback;
   31: use Apache::lonlocal;
   32: 
   33: # receives a file name and path stub from username/userfiles/portfolio/
   34: # returns an anchor tag consisting encoding filename and currentpath
   35: sub make_anchor {
   36:     my ($filename, $current_path) = @_;
   37:     my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'&currentpath='.$current_path.'">'.$filename.'</a>';
   38:     return $anchor;
   39: }
   40: my $dirptr=16384;
   41: sub display_common {
   42:     my ($r,$current_path,$is_empty,$dir_list)=@_;
   43:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   44:     $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">');
   45:     $r->print('<td bgcolor="#ccddaa" align="center">');
   46:     my $displayOut = '<form method="post" enctype="multipart/form-data">';
   47:     $displayOut .= '<input name="uploaddoc" type="file" />'.
   48:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
   49:         '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
   50:         '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
   51:         '<input type="submit" name="storeupl" value="Upload" />'.
   52:         '</form>';
   53:     $r->print($displayOut);
   54:     $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
   55:     $displayOut = '<form method="post">';
   56:     $displayOut .= '<input name="newdir" type="input" />'.
   57:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
   58:         '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
   59:         '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
   60:         '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
   61:         '</form>';
   62:     $r->print($displayOut);
   63:     $r->print('</td></tr></table>');
   64:     my @tree = split (/\//,$current_path);
   65:     $r->print('<font size="+2">'.&make_anchor('portfolio','/').'/');
   66:     if (@tree > 1){
   67:         my $newCurrentPath = '';
   68:         for (my $i = 1; $i< @tree; $i++){
   69:             $newCurrentPath .= $tree[$i].'/';
   70:             $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath).'/');
   71:         }
   72:     }
   73:     $r->print('</font>');
   74:     &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
   75:     $r->print('<br /><form method=post action="/adm/portfolio">'.
   76: 	      &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
   77: 						    'this.form.submit();'));
   78:     $r->print("</form>");
   79: }
   80: sub display_directory {
   81:     my ($r,$current_path,$is_empty,$dir_list)=@_;
   82:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   83:     my $display_out;
   84:     my %locked_files=&Apache::lonnet::dump('file_permissions',
   85:                                   $ENV{'user.domain'},$ENV{'user.name'});
   86:     my $locked_file;
   87:     foreach my $key (keys %locked_files) {
   88:         $locked_file .= $locked_files{$key}.':';
   89:     }
   90:     if ($is_empty && ($current_path ne '/')) {
   91:         $display_out = '<form method="post" action="/adm/portfolio">'.
   92:         '<input type="hidden" name="action" value="deletedir" />'.
   93:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
   94:         '<input type="hidden" name="selectfile" value="" />'.
   95:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
   96:         '</form>';
   97:         
   98:         $r->print($display_out);
   99: 	return;
  100:     }
  101:     $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
  102:             '<tr><th>Actions</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
  103:     my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
  104:     foreach my $line (sort 
  105: 		      { 
  106: 			  my ($afile)=split('&',$a,2);
  107: 			  my ($bfile)=split('&',$b,2);
  108: 			  return (lc($afile) cmp lc($bfile));
  109: 		      } (@$dir_list)) {
  110:     	#$strip holds directory/file name
  111:     	#$dom 
  112:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
  113:     	if ($Apache::lonhomework::results{"resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename"}eq'true'){
  114:     	    &Apache::lonnet::logthis("found submitted file");
  115:     	    &Apache::lonnet::logthis("resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename");
  116:     	} else {
  117:     	    &Apache::lonnet::logthis("$filename not found submitted file");
  118:     	    &Apache::lonnet::logthis("resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename");
  119:     	}
  120:     	if (($filename ne '.') && ($filename ne '..')) {
  121:             if ($dirptr&$testdir) {
  122:                 $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
  123:                 $r->print('<td>Go to ...</td>');
  124:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/').'</td>'); 
  125:                 $r->print('</tr>'); 
  126:             } else {
  127:                 $r->print('<tr bgcolor="#CCCCFF">');
  128:                 $r->print('<td>
  129:                     <form method="post" action="/adm/portfolio">
  130:                     <select name="action">
  131:                         <option value=""></option>
  132:                         <option value="delete">'.&mt("Delete").'</option>
  133:                         <option value="rename">'.&mt("Rename").'</option>
  134:                     </select>
  135:                     <input type="submit" name="doit" value="Go" />
  136:                     <input type="hidden" name="selectfile" value="'.$filename.'" />
  137:                     <input type="hidden" name="currentpath" value="'.$current_path.'" />
  138:                     </form>
  139:                     </td>');
  140:                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
  141:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
  142: 			    $filename.'</a></td>'); 
  143:                 $r->print('<td>'.$size.'</td>');
  144:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
  145:                 $r->print('</tr>'); 
  146:             }
  147:         }
  148:     }
  149: #   <tr bgcolor="#FFAA99"> pink bg 
  150: #   <tr bgcolor="#CCCCFF"> blue bg            
  151: #   $r->print(&display_directory($current_path, $currentFile, @dir_list));
  152: #    $r->print('</td>><td>');
  153: #   $r->print(&display_actions($current_path, $currentFile, $isEmpty));
  154:     $r->print('</table></form>');
  155: }
  156: sub display_file_select {
  157:     my ($r,$current_path,$is_empty,$dir_list)=@_;
  158:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
  159:     my $display_out;
  160:     if ($is_empty && ($current_path ne '/')) {
  161:         $display_out = '<form method="post" action="/adm/portfolio">'.
  162:         '<input type="hidden" name="action" value="deletedir" />'.
  163:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
  164:         '<input type="hidden" name="selectfile" value="" />'.
  165:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
  166: 
  167:         '</form>';
  168:         
  169:         $r->print($display_out);
  170: 	return;
  171:     }
  172:     $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
  173:             '<tr><th>Select</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
  174:     my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
  175:     $r->print('<form method="post" name="checkselect" action="/adm/portfolio">');
  176:     foreach my $line (sort 
  177: 		      { 
  178: 			  my ($afile)=split('&',$a,2);
  179: 			  my ($bfile)=split('&',$b,2);
  180: 			  return (lc($afile) cmp lc($bfile));
  181: 		      } (@$dir_list)) {
  182:     	#$strip holds directory/file name
  183:     	#$dom 
  184:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
  185:     	if (($filename ne '.') && ($filename ne '..')) {
  186:             if ($dirptr&$testdir) {
  187:                 $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
  188:                 $r->print('<td>Go to ...</td>');
  189:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/').'</td>'); 
  190:                 $r->print('</tr>'); 
  191:             } else {
  192:                 $r->print('<tr bgcolor="#CCCCFF">');
  193:                 $r->print('<td>
  194:                         <input type="checkbox" name="selectedfile" value="'.$filename.'" >
  195:                     </td>');
  196:                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
  197:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
  198: 			    $filename.'</a></td>'); 
  199:                 $r->print('<td>'.$size.'</td>');
  200:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
  201:                 $r->print('</tr>'); 
  202:             }
  203:         }
  204:     }
  205:     $r->print('</table>
  206:             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
  207:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
  208:     </form>');
  209: }
  210: 
  211: sub open_form {
  212:     my ($r)=@_;
  213:     $r->print('<form method="post" action="/adm/portfolio">');
  214:     $r->print('<input type="hidden" name="action" value="'.
  215: 	      $ENV{'form.action'}.'" />');
  216:     $r->print('<input type="hidden" name="confirmed" value="1" />');
  217:     $r->print('<input type="hidden" name="selectfile" value="'.
  218: 	      $ENV{'form.selectfile'}.'" />');
  219:     $r->print('<input type="hidden" name="currentpath" value="'.
  220: 	      $ENV{'form.currentpath'}.'" />');
  221: }
  222: 
  223: sub close_form {
  224:     my ($r)=@_;
  225:     $r->print('<p><input type="submit" value="'.&mt('Continue').
  226: 	      '" /></p></form>');
  227:     $r->print('<form action="/adm/portfolio" method="POST">
  228:                <p>
  229:               <input type="hidden" name="currentpath" value="'.
  230: 	      $ENV{'form.currentpath'}.'" />
  231:                  <input type="submit" value="'.&mt('Cancel').'" />
  232:                </p></form>');
  233: 
  234: }
  235: 
  236: sub display_file {
  237:     my ($path,$filename)=@_;
  238:     if (!defined($path)) { $path=$ENV{'form.currentpath'}; }
  239:     if (!defined($filename)) { $filename=$ENV{'form.selectfile'}; }
  240:     return '<tt>'.$path.$filename.'</tt>';
  241: }
  242: 
  243: sub done {
  244:     return ('<h3><a href="/adm/portfolio?currentpath='.
  245: 	    $ENV{'form.currentpath'}.
  246: 	    '&fieldname='.$ENV{'form.fieldname'}.
  247: 	    '">'.&mt('Done').'</a></h3>');
  248: }
  249: 
  250: sub delete {
  251:     my ($r)=@_;
  252:     my @check;
  253:     my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'};
  254:     push @check, $file_name;
  255:     my %locked = &Apache::lonnet::get('file_permissions',\@check,
  256:                                         $ENV{'user.domain'},$ENV{'user.name'});
  257:     if (ref($locked{$file_name}) eq 'ARRAY') {
  258:         $r->print ("The file is locked and cannot be deleted.<br />");
  259:         $r->print(&done());
  260:     } else {
  261:         &open_form($r);
  262:         $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
  263:         &close_form($r);
  264:     }
  265: } 
  266: 
  267: sub delete_confirmed {
  268:     my ($r)=@_;
  269:     my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
  270: 					       $ENV{'user.domain'},'portfolio'.
  271: 					       $ENV{'form.currentpath'}.
  272: 					       $ENV{'form.selectfile'});
  273:     if ($result ne 'ok') {
  274: 	$r->print('<font color="red"> An error occured ('.$result.
  275: 		  ') while trying to delete '.&display_file().'</font><br />');
  276:     }
  277:     $r->print(&done());
  278: }
  279: 
  280: sub delete_dir {
  281:     my ($r)=@_;
  282:     &open_form($r);
  283:     $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
  284:     &close_form($r);
  285: } 
  286: 
  287: sub delete_dir_confirmed {
  288:     my ($r)=@_;
  289:     my $directory_name = $ENV{'form.currentpath'};
  290:     $directory_name =~ m/\/$/;
  291:     $directory_name = $`;
  292:     my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
  293: 					       $ENV{'user.domain'},'portfolio'.
  294: 					       $directory_name);
  295: 					       
  296:     if ($result ne 'ok') {
  297: 	$r->print('<font color="red"> An error occured (dir) ('.$result.
  298: 		  ') while trying to delete '.$directory_name.'</font><br />');
  299:     } else {
  300:         # now remove from recent
  301: #        $r->print('<br /> removing '.$directory_name.'<br /');
  302:         &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
  303:         my @dirs = split m!/!, $directory_name;
  304:         
  305: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
  306:         $directory_name='/';
  307:         for (my $i=1; $i < (@dirs - 1); $i ++){
  308:             $directory_name .= $dirs[$i].'/';
  309:         }
  310:         $ENV{'form.currentpath'} = $directory_name;
  311:     }
  312:     $r->print(&done());
  313: }
  314: 
  315: sub rename {
  316:     my ($r)=@_;
  317:     my @check;
  318:     my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'};
  319:     push @check, $file_name;
  320:     my %locked = &Apache::lonnet::get('file_permissions',\@check,
  321:                                         $ENV{'user.domain'},$ENV{'user.name'});
  322:     if (ref($locked{$file_name}) eq 'ARRAY') {
  323:         $r->print ("The file is locked and cannot be renamed.<br />");
  324:         $r->print(&done());
  325:     } else {
  326:         &open_form($r);
  327:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
  328:                    <input name="filenewname" type="input" size="50" />?</p>');
  329:         &close_form($r);
  330:     }
  331: }
  332: 
  333: sub rename_confirmed {
  334:     my ($r)=@_;
  335:     my $filenewname=&Apache::lonnet::clean_filename($ENV{'form.filenewname'});
  336:     if ($filenewname eq '') {
  337: 	$r->print('<font color="red">'.
  338: 		  &mt("Error: no valid filename was provided to rename to.").
  339: 		  '</font><br />');
  340: 	$r->print(&done());
  341: 	return;
  342:     } 
  343:     my $result=
  344: 	&Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'},
  345:             'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'},
  346:             'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.filenewname'});
  347:     if ($result ne 'ok') {
  348: 	$r->print('<font color="red"> An errror occured ('.$result.
  349: 		  ') while trying to rename '.&display_file().' to '.
  350: 		  &display_file(undef,$filenewname).'</font><br />');
  351:     }
  352:     $r->print(&done());
  353: }
  354: sub select_files {
  355:     my ($r)=@_;
  356:     my $java_script =(<<ENDSMP);
  357:         <script language='javascript'>
  358:         function finishSelect() {
  359:             fileList = "";
  360:             for (i=0;i<document.forms.checkselect.length;i++) { 
  361:                 if (document.forms.checkselect[i].checked){
  362:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
  363:                 }
  364:             }
  365:             opener.document.forms.lonhomework.
  366: ENDSMP
  367:     $java_script .= $ENV{'form.fieldname'};
  368:     $java_script .= (<<ENDSMP);
  369:         .value=fileList;
  370:             self.close();
  371:         }
  372:         </script>
  373: ENDSMP
  374:     $r->print($java_script);
  375:     $r->print("<h1>Select portfolio files</h1>
  376:                 Check as many as you wish in response to the essay problem.<br />");
  377: }
  378: sub upload {
  379:     my ($r)=@_;
  380:     my $fname=$ENV{'form.uploaddoc.filename'};
  381:     my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?)
  382:     my $disk_quota = 20000; # expressed in k
  383:     $fname=&Apache::lonnet::clean_filename($fname);
  384:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
  385: 						 $ENV{'user.name'}).
  386: 						'/userfiles/portfolio';
  387:     # Fixme --- Move the checking for existing file to LOND error return
  388:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
  389: 					  $ENV{'user.domain'},
  390: 					  $ENV{'user.name'},$portfolio_root);
  391:     my $found_file = 0;
  392:     foreach my $line (@dir_list) {
  393:         my ($filename)=split(/\&/,$line,2);
  394:         if ($filename eq $fname){
  395:             $found_file = 1;
  396:         }
  397:     }
  398:     my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);
  399:     if (($current_disk_usage + $filesize) > $disk_quota){
  400:         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
  401:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
  402:     } 
  403:     elsif ($found_file){   
  404:         $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$ENV{'form.currentpath'}.'</strong></font>'.
  405:                   '<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'});
  406:     } else {
  407:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
  408: 	        	 'portfolio'.$ENV{'form.currentpath'});
  409:         if ($result !~ m|^/uploaded/|) {
  410:             $r->print('<font color="red"> An errror occured ('.$result.
  411: 	              ') while trying to upload '.&display_file().'</font><br />');
  412:         }
  413:     }
  414:     $r->print(&done());
  415: }
  416: 
  417: sub createdir {
  418:     my ($r)=@_;
  419:     my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'});
  420:     if ($newdir eq '') {
  421:     	$r->print('<font color="red">'.
  422: 	    	  &mt("Error: no directory name was provided.").
  423: 		      '</font><br />');
  424: 	    $r->print(&done());
  425: 	    return;
  426:     } 
  427:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
  428: 						 $ENV{'user.name'}).
  429: 						'/userfiles/portfolio';
  430:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
  431: 					  $ENV{'user.domain'},
  432: 					  $ENV{'user.name'},$portfolio_root);
  433:     my $found_file = 0;
  434:     foreach my $line (@dir_list) {
  435:         my ($filename)=split(/\&/,$line,2);
  436:         if ($filename eq $newdir){
  437:             $found_file = 1;
  438:         }
  439:     }
  440:     if ($found_file){
  441:     	    $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
  442:     	            ' </strong>a file or directory by that name already exists.</font><br />');
  443:     } else {
  444:         my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'},
  445: 	         $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir);
  446:         if ($result ne 'ok') {
  447:     	    $r->print('<font color="red"> An errror occured ('.$result.
  448: 	    	      ') while trying to create a new directory '.&display_file().'</font><br />');
  449:         }
  450:     }
  451:     $r->print(&done());
  452: }
  453: 
  454: sub handler {
  455:     # this handles file management
  456:     my $r = shift;
  457:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
  458: 							 $ENV{'user.name'}).
  459: 							'/userfiles/portfolio';
  460:     &Apache::loncommon::no_cache($r);
  461:     &Apache::loncommon::content_type($r,'text/html');
  462:     $r->send_http_header;
  463:     # Give the LON-CAPA page header
  464:     $r->print('<html><head><title>'.
  465:               &mt('Portfolio Manager').
  466:               "</title></head>\n".
  467:               &Apache::loncommon::bodytag('Portfolio Manager'));
  468:     $r->rflush();
  469:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  470:                                             ['selectfile','currentpath',
  471: 					     'currentfile','action','fieldname','mode']);
  472: 	if (($ENV{'form.storeupl'} eq 'Upload') & (!$ENV{'form.uploaddoc.filename'})){
  473:    	    $r->print('<font color="red"> No file was selected to upload.'.
  474:    	            'To upload a file, click <strong>Browse...</strong>'.
  475:    	            ', select a file, then click <strong>Upload</strong>,</font>');
  476: 	}
  477:     if ($ENV{'form.uploaddoc.filename'}) {
  478: 	&upload($r);
  479:     } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) {
  480: 	&delete_confirmed($r);
  481:     } elsif ($ENV{'form.action'} eq 'delete') {
  482: 	&delete($r);
  483:     } elsif ($ENV{'form.action'} eq 'deletedir' && $ENV{'form.confirmed'}) {
  484: 	&delete_dir_confirmed($r);
  485:     } elsif ($ENV{'form.action'} eq 'deletedir'){
  486: 	&delete_dir($r);
  487:     } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) {
  488: 	&rename_confirmed($r);
  489:     } elsif ($ENV{'form.action'} eq 'rename') {
  490: 	&rename($r);
  491:     } elsif ($ENV{'form.createdir'}) {
  492: 	&createdir($r);
  493:     } else {
  494: 	my $current_path='/';
  495: 	if ($ENV{'form.currentpath'}) {
  496: 	    $current_path = $ENV{'form.currentpath'};
  497: 	}
  498: 	my @dir_list=&Apache::lonnet::dirlist($current_path,
  499: 					    $ENV{'user.domain'},
  500: 					    $ENV{'user.name'},$portfolio_root);
  501: 	if ($dir_list[0] eq 'no_such_dir'){
  502: 	    # two main reasons for this:
  503:             #    1) never been here, so directory structure not created
  504: 	    #    2) back-button navigation after deleting a directory
  505: 	    if ($current_path eq '/'){
  506: 	        &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
  507: 					       $ENV{'user.domain'},'portfolio');
  508: 	    } else {
  509:                 # some directory that snuck in get rid of the directory
  510:                 # from the recent pulldown, just in case
  511: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
  512: 						      [$current_path]);
  513: 		$current_path = '/'; # force it back to the root        
  514: 	    }
  515: 	    # now grab the directory list again, for the first time
  516: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
  517: 					    $ENV{'user.domain'},
  518: 					    $ENV{'user.name'},$portfolio_root);
  519:         }
  520: 	# need to know if directory is empty so it can be removed if desired
  521: 	my $is_empty=(@dir_list == 2);
  522: 	&display_common($r,$current_path,$is_empty,\@dir_list);
  523: 	if ($ENV{"form.mode"} eq 'selectfile'){
  524: 	    &select_files($r);
  525:             &display_file_select($r,$current_path,$is_empty,\@dir_list);
  526: 	} else {
  527: 	    &display_directory($r,$current_path,$is_empty,\@dir_list);
  528: 	}
  529: 	$r->print("</body>\n</html>\n");
  530: 	return OK;
  531:     }
  532: }
  533: 1;
  534: __END__

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