File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.48: download - view: text, annotated - select for diffs
Tue Oct 12 00:44:05 2004 UTC (19 years, 8 months ago) by banghart
Branches: MAIN
CVS tags: HEAD
	Added beginning of javascript sending selected files
	back to opener.

	Still not working.

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

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