File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.47: download - view: text, annotated - select for diffs
Mon Oct 11 22:52:20 2004 UTC (19 years, 7 months ago) by banghart
Branches: MAIN
CVS tags: HEAD
	Nowhere near ready, but saving work in progress.

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

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