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

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