Annotation of loncom/interface/portfolio.pm, revision 1.51

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

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