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

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;
                     41: sub display_directory {
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">';
                     47:     $displayOut = $displayOut.'<input name="uploaddoc" type="file" />'.
1.24      albertel   48:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.20      banghart   49:         '<input type="submit" name="storeupl" value="Upload" />'.
                     50:         '</form>';
                     51:     $r->print($displayOut);
1.22      albertel   52:     $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
1.24      albertel   53:     $displayOut = '<form method="post">';
                     54:     $displayOut .= '<input name="newdir" type="input" />'.
                     55:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.22      albertel   56:         '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
                     57:         '</form>';
                     58:     $r->print($displayOut);
                     59:     $r->print('</td></tr></table>');
1.24      albertel   60:     my @tree = split (/\//,$current_path);
1.29      albertel   61:     $r->print('<font size="+2">'.&make_anchor('portfolio','/').'/');
1.19      banghart   62:     if (@tree > 1){
                     63:         my $newCurrentPath = '';
                     64:         for (my $i = 1; $i< @tree; $i++){
                     65:             $newCurrentPath .= $tree[$i].'/';
1.23      albertel   66:             $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath).'/');
1.19      banghart   67:         }
                     68:     }
                     69:     $r->print('</font>');
1.24      albertel   70:     &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
1.39      banghart   71:     #Fixme -- remove from recent those paths that are deleted
1.22      albertel   72:     $r->print('<br /><form method=post action="/adm/portfolio">'.
                     73: 	      &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
                     74: 						    'this.form.submit();'));
1.21      banghart   75:     $r->print("</form>");
1.45      banghart   76:     if ($is_empty && ($current_path ne '/')) {
1.30      banghart   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);
1.31      albertel   85: 	return;
                     86:     }
1.18      banghart   87:     $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
1.22      albertel   88:             '<tr><th>Actions</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
1.39      banghart   89:     my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
1.26      albertel   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)) {
1.18      banghart   96:     	#$strip holds directory/file name
                     97:     	#$dom 
1.23      albertel   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) {
1.19      banghart  101:                 $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
                    102:                 $r->print('<td>Go to ...</td>');
1.24      albertel  103:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/').'</td>'); 
1.19      banghart  104:                 $r->print('</tr>'); 
1.23      albertel  105:             } else {
1.22      albertel  106:                 $r->print('<tr bgcolor="#CCCCFF">');
                    107:                 $r->print('<td>
1.39      banghart  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>');
1.22      albertel  119:                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
1.23      albertel  120:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
1.39      banghart  121: 			    $filename.'</a></td>'); 
1.22      albertel  122:                 $r->print('<td>'.$size.'</td>');
                    123:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
1.19      banghart  124:                 $r->print('</tr>'); 
                    125:             }
1.18      banghart  126:         }
                    127:     }
                    128: #   <tr bgcolor="#FFAA99"> pink bg 
                    129: #   <tr bgcolor="#CCCCFF"> blue bg            
1.24      albertel  130: #   $r->print(&display_directory($current_path, $currentFile, @dir_list));
1.18      banghart  131: #    $r->print('</td>><td>');
1.24      albertel  132: #   $r->print(&display_actions($current_path, $currentFile, $isEmpty));
1.22      albertel  133:     $r->print('</table></form>');
1.24      albertel  134: }
1.47    ! banghart  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: }
1.24      albertel  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 {
1.27      albertel  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>';
1.24      albertel  256: }
                    257: 
                    258: sub done {
1.25      albertel  259:     return ('<h3><a href="/adm/portfolio?currentpath='.
1.24      albertel  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') {
1.30      banghart  277: 	$r->print('<font color="red"> An error occured ('.$result.
1.25      albertel  278: 		  ') while trying to delete '.&display_file().'</font><br />');
1.24      albertel  279:     }
                    280:     $r->print(&done());
                    281: }
                    282: 
1.30      banghart  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);
1.32      banghart  298: 					       
1.30      banghart  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 />');
1.32      banghart  302:     } else {
1.41      banghart  303:         # now remove from recent
                    304: #        $r->print('<br /> removing '.$directory_name.'<br /');
1.42      banghart  305:         &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
1.32      banghart  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;
1.30      banghart  314:     }
                    315:     $r->print(&done());
                    316: }
                    317: 
1.24      albertel  318: sub rename {
                    319:     my ($r)=@_;
                    320:     &open_form($r);
1.27      albertel  321:     $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
                    322:                <input name="filenewname" type="input" size="50" />?</p>');
1.24      albertel  323:     &close_form($r);
                    324: }
                    325: 
                    326: sub rename_confirmed {
                    327:     my ($r)=@_;
1.27      albertel  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: }
1.47    ! banghart  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: }
1.24      albertel  386: sub upload {
                    387:     my ($r)=@_;
1.33      banghart  388:     my $fname=$ENV{'form.uploaddoc.filename'};
1.38      banghart  389:     my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?)
                    390:     my $disk_quota = 20000; # expressed in k
1.34      banghart  391:     $fname=&Apache::lonnet::clean_filename($fname);
                    392:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  393: 						 $ENV{'user.name'}).
                    394: 						'/userfiles/portfolio';
1.38      banghart  395:     # Fixme --- Move the checking for existing file to LOND error return
1.34      banghart  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;
1.33      banghart  400:     foreach my $line (@dir_list) {
1.34      banghart  401:         my ($filename)=split(/\&/,$line,2);
1.33      banghart  402:         if ($filename eq $fname){
                    403:             $found_file = 1;
                    404:         }
                    405:     }
1.38      banghart  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){   
1.33      banghart  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/|) {
1.34      banghart  418:             $r->print('<font color="red"> An errror occured ('.$result.
                    419: 	              ') while trying to upload '.&display_file().'</font><br />');
1.33      banghart  420:         }
1.25      albertel  421:     }
                    422:     $r->print(&done());
                    423: }
                    424: 
                    425: sub createdir {
                    426:     my ($r)=@_;
1.28      albertel  427:     my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'});
                    428:     if ($newdir eq '') {
1.37      banghart  429:     	$r->print('<font color="red">'.
                    430: 	    	  &mt("Error: no directory name was provided.").
                    431: 		      '</font><br />');
                    432: 	    $r->print(&done());
                    433: 	    return;
1.28      albertel  434:     } 
1.37      banghart  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:         }
1.24      albertel  458:     }
                    459:     $r->print(&done());
                    460: }
                    461: 
                    462: sub handler {
                    463:     # this handles file management
                    464:     my $r = shift;
1.47    ! banghart  465:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  466: 							 $ENV{'user.name'}).
                    467: 							'/userfiles/portfolio';
1.24      albertel  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',
1.47    ! banghart  479: 					     'currentfile','action']);
1.40      banghart  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: 	}
1.24      albertel  485:     if ($ENV{'form.uploaddoc.filename'}) {
                    486: 	&upload($r);
1.47    ! banghart  487:     } elsif ($ENV{'form.action'} eq 'selectfile') {
        !           488:         &select_files($r);
1.27      albertel  489:     } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) {
                    490: 	&delete_confirmed($r);
1.24      albertel  491:     } elsif ($ENV{'form.action'} eq 'delete') {
1.27      albertel  492: 	&delete($r);
1.30      banghart  493:     } elsif ($ENV{'form.action'} eq 'deletedir' && $ENV{'form.confirmed'}) {
1.31      albertel  494: 	&delete_dir_confirmed($r);
1.30      banghart  495:     } elsif ($ENV{'form.action'} eq 'deletedir'){
1.31      albertel  496: 	&delete_dir($r);
1.27      albertel  497:     } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) {
                    498: 	&rename_confirmed($r);
1.24      albertel  499:     } elsif ($ENV{'form.action'} eq 'rename') {
                    500: 	&rename($r);
1.25      albertel  501:     } elsif ($ENV{'form.createdir'}) {
                    502: 	&createdir($r);
1.24      albertel  503:     } else {
                    504: 	my $current_path='/';
                    505: 	if ($ENV{'form.currentpath'}) {
                    506: 	    $current_path = $ENV{'form.currentpath'};
                    507: 	}
1.43      banghart  508: 	my @dir_list=&Apache::lonnet::dirlist($current_path,
1.27      albertel  509: 					    $ENV{'user.domain'},
                    510: 					    $ENV{'user.name'},$portfolio_root);
1.46      albertel  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 '/'){
1.43      banghart  516: 	        &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
1.46      albertel  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);
1.43      banghart  529:         }
1.46      albertel  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;
1.30      banghart  535:     }
1.2       banghart  536: }
1.1       banghart  537: 1;
                    538: __END__

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