File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.58: download - view: text, annotated - select for diffs
Thu Nov 25 23:56:19 2004 UTC (19 years, 6 months ago) by banghart
Branches: MAIN
CVS tags: HEAD
	Navigating using the recent dropdown now retains select mode and
	parent field information.

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

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