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

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 {
1.57      banghart   36:     my ($filename, $current_path, $current_mode, $field_name) = @_;
                     37:     my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'&currentpath='.$current_path.'&mode='.$current_mode.'&fieldname='.$field_name.'">'.$filename.'</a>';
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.57      banghart   51:         '<input type="hidden" name="mode" value="'.$ENV{"form.mode"}.'" />'. 
1.20      banghart   52:         '<input type="submit" name="storeupl" value="Upload" />'.
                     53:         '</form>';
                     54:     $r->print($displayOut);
1.22      albertel   55:     $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
1.24      albertel   56:     $displayOut = '<form method="post">';
                     57:     $displayOut .= '<input name="newdir" type="input" />'.
                     58:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.50      banghart   59:         '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
                     60:         '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
1.57      banghart   61:         '<input type="hidden" name="mode" value="'.$ENV{"form.mode"}.'" />'. 
1.22      albertel   62:         '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
                     63:         '</form>';
                     64:     $r->print($displayOut);
                     65:     $r->print('</td></tr></table>');
1.24      albertel   66:     my @tree = split (/\//,$current_path);
1.57      banghart   67:     $r->print('<font size="+2">'.&make_anchor('portfolio','/',$ENV{"form.mode"},$ENV{"form.fieldname"}).'/');
1.19      banghart   68:     if (@tree > 1){
                     69:         my $newCurrentPath = '';
                     70:         for (my $i = 1; $i< @tree; $i++){
                     71:             $newCurrentPath .= $tree[$i].'/';
1.57      banghart   72:             $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $ENV{"form.mode"},$ENV{"form.fieldname"}).'/');
1.19      banghart   73:         }
                     74:     }
                     75:     $r->print('</font>');
1.24      albertel   76:     &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
1.58      banghart   77:     $r->print('<br /><form method=post action="/adm/portfolio?mode='.$ENV{"form.mode"}.'&fieldname='.$ENV{"form.fieldname"}.'">'.
1.22      albertel   78: 	      &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
                     79: 						    'this.form.submit();'));
1.21      banghart   80:     $r->print("</form>");
1.48      banghart   81: }
                     82: sub display_directory {
                     83:     my ($r,$current_path,$is_empty,$dir_list)=@_;
                     84:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
                     85:     my $display_out;
1.77      banghart   86:     my $select_mode;
                     87:     my $checked_files;
1.64      banghart   88:     my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($ENV{'user.domain'},$ENV{'user.name'});
1.77      banghart   89:     if ($ENV{"form.mode"} eq 'selectfile'){
                     90: 	&select_files($r);
                     91: 	$checked_files =&Apache::lonnet::files_in_path($ENV{'user.name'},$ENV{'form.currentpath'});
                     92: 	$select_mode = 'true';
                     93:     } 
1.45      banghart   94:     if ($is_empty && ($current_path ne '/')) {
1.48      banghart   95:         $display_out = '<form method="post" action="/adm/portfolio">'.
1.30      banghart   96:         '<input type="hidden" name="action" value="deletedir" />'.
                     97:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
                     98:         '<input type="hidden" name="selectfile" value="" />'.
                     99:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
                    100:         '</form>';
                    101:         
1.48      banghart  102:         $r->print($display_out);
1.31      albertel  103: 	return;
                    104:     }
1.77      banghart  105:     if ($select_mode eq 'true') {
                    106:         $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
                    107:             '<tr><th>Select</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
                    108:         $r->print('<form method="post" name="checkselect" action="/adm/portfolio">');
                    109:     } else {
                    110:         $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
1.70      banghart  111:             '<tr><th colspan="2">Actions</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
1.77      banghart  112:         $r->print('<form method="post" action="/adm/portfolio">');
                    113:     }
1.39      banghart  114:     my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
1.80      banghart  115:     my $href_edit_location="/editupload/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
1.26      albertel  116:     foreach my $line (sort 
                    117: 		      { 
                    118: 			  my ($afile)=split('&',$a,2);
                    119: 			  my ($bfile)=split('&',$b,2);
                    120: 			  return (lc($afile) cmp lc($bfile));
                    121: 		      } (@$dir_list)) {
1.18      banghart  122:     	#$strip holds directory/file name
                    123:     	#$dom 
1.23      albertel  124:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
1.77      banghart  125:     	$filename =~ s/\s+$//;
1.78      banghart  126:     	if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ )) {
1.23      albertel  127:             if ($dirptr&$testdir) {
1.77      banghart  128:                 if ($select_mode eq 'true'){
                    129:                     $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
1.64      banghart  130:                 } else {
1.77      banghart  131:                     $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
1.64      banghart  132:                 }
1.47      banghart  133:                 $r->print('<td>Go to ...</td>');
1.57      banghart  134:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$ENV{'form.mode'},$ENV{"form.fieldname"}).'</td>'); 
1.47      banghart  135:                 $r->print('</tr>'); 
                    136:             } else {
                    137:                 $r->print('<tr bgcolor="#CCCCFF">');
1.77      banghart  138:                 if ($select_mode eq 'true'){
                    139:                     $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'"'); 
                    140:                     if ($$checked_files{$filename} eq 'selected') {
                    141:                         $r->print("CHECKED");
                    142:                     }
                    143:                     $r->print('></td>');
                    144:                 } else {
                    145:                     if (exists $locked_files{$current_path.$filename}){
1.80      banghart  146:                         $r->print('<td colspan="2"><a href="portfolio?lockinfo='.$current_path.$filename.'">Locked</a></td>');
1.77      banghart  147:                     } else {
                    148:                         $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
                    149:                             <a href="/adm/portfolio?rename='.$filename.'&amp;currentpath='.$current_path.'">Rename</a></td>
1.80      banghart  150:                             <td><a href="'.$href_edit_location.$filename.'.meta">Meta</a>
1.77      banghart  151:                             </td>');
                    152:                     }
1.61      banghart  153:                 }
1.47      banghart  154:                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
                    155:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
                    156: 			    $filename.'</a></td>'); 
                    157:                 $r->print('<td>'.$size.'</td>');
                    158:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
                    159:                 $r->print('</tr>'); 
                    160:             }
                    161:         }
                    162:     }
1.77      banghart  163:     if ($select_mode eq 'true') {
                    164:         $r->print('</table>
1.60      banghart  165:             <input type="hidden" name="continue" value="true">
                    166:             <input type="hidden" name="fieldname" value="'.$ENV{'form.fieldname'}.'">
                    167:             <input type="hidden" name="mode" value="selectfile">
                    168:             <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
1.48      banghart  169:             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
                    170:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.77      banghart  171:         </form>');        
                    172:     } else {
                    173:         $r->print('</table>
                    174:         <input type="submit" name="doit" value="Delete Checked Files" />
                    175:         <input type="hidden" name="action" value="delete" />
                    176:         <input type="hidden" name="currentpath" value="'.$current_path.'" />
                    177:         </form>');
                    178:     }
1.47      banghart  179: }
1.72      banghart  180: 
1.24      albertel  181: sub open_form {
                    182:     my ($r)=@_;
1.65      banghart  183:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.24      albertel  184:     $r->print('<form method="post" action="/adm/portfolio">');
                    185:     $r->print('<input type="hidden" name="action" value="'.
                    186: 	      $ENV{'form.action'}.'" />');
                    187:     $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65      banghart  188:     foreach (@files) {
                    189:         $r->print('<input type="hidden" name="selectfile" value="'.
                    190: 	      $_.'" />');
                    191:     }
1.24      albertel  192:     $r->print('<input type="hidden" name="currentpath" value="'.
                    193: 	      $ENV{'form.currentpath'}.'" />');
                    194: }
                    195: 
                    196: sub close_form {
                    197:     my ($r)=@_;
                    198:     $r->print('<p><input type="submit" value="'.&mt('Continue').
                    199: 	      '" /></p></form>');
                    200:     $r->print('<form action="/adm/portfolio" method="POST">
                    201:                <p>
                    202:               <input type="hidden" name="currentpath" value="'.
                    203: 	      $ENV{'form.currentpath'}.'" />
                    204:                  <input type="submit" value="'.&mt('Cancel').'" />
                    205:                </p></form>');
                    206: 
                    207: }
                    208: 
                    209: sub display_file {
1.27      albertel  210:     my ($path,$filename)=@_;
1.65      banghart  211:     my $display_file_text;
1.27      albertel  212:     if (!defined($path)) { $path=$ENV{'form.currentpath'}; }
1.65      banghart  213:     if (!defined($filename)) { 
                    214:         $filename=$ENV{'form.selectfile'};
                    215:         $display_file_text = '<tt>'.$path.$filename.'</tt>';
                    216:     } elsif (ref($filename) eq "ARRAY") {
                    217:         foreach (@$filename) {
1.66      banghart  218:             $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
1.65      banghart  219:         }
                    220:     } elsif (ref($filename) eq "SCALAR") {
                    221:         $display_file_text = '<tt>'.$path.$filename.'</tt>';        
                    222:     }
                    223:     return $display_file_text;
1.24      albertel  224: }
                    225: 
                    226: sub done {
1.76      banghart  227:     my ($message)=@_;
                    228:     unless (defined $message) {
                    229:         $message='Done';
                    230:     }
1.25      albertel  231:     return ('<h3><a href="/adm/portfolio?currentpath='.
1.50      banghart  232: 	    $ENV{'form.currentpath'}.
                    233: 	    '&fieldname='.$ENV{'form.fieldname'}.
1.57      banghart  234: 	    '&mode='.$ENV{'form.mode'}.
1.76      banghart  235: 	    '">'.&mt($message).'</a></h3>');
1.24      albertel  236: }
                    237: 
                    238: sub delete {
                    239:     my ($r)=@_;
1.55      banghart  240:     my @check;
                    241:     my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'};
1.65      banghart  242:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.66      banghart  243: 
1.56      banghart  244:     if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'} ) eq 'true') {
1.55      banghart  245:         $r->print ("The file is locked and cannot be deleted.<br />");
1.76      banghart  246:         $r->print(&done('Back'));
1.55      banghart  247:     } else {
1.66      banghart  248:         if (scalar(@files)) {
                    249:             &open_form($r);
                    250:             $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
                    251:             &close_form($r);
                    252:         } else {
                    253:             $r->print("No file was checked to delete.<br />");
                    254:             $r->print(&done());
                    255:         }
1.55      banghart  256:     }
1.24      albertel  257: } 
                    258: 
                    259: sub delete_confirmed {
                    260:     my ($r)=@_;
1.65      banghart  261:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
                    262:     my $result;
                    263:     foreach my $delete_file (@files) {
                    264:         $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
1.24      albertel  265: 					       $ENV{'user.domain'},'portfolio'.
                    266: 					       $ENV{'form.currentpath'}.
1.65      banghart  267: 					       $delete_file);
                    268:         if ($result ne 'ok') {
1.30      banghart  269: 	$r->print('<font color="red"> An error occured ('.$result.
1.65      banghart  270: 		  ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
                    271:         }
1.24      albertel  272:     }
                    273:     $r->print(&done());
                    274: }
                    275: 
1.30      banghart  276: sub delete_dir {
                    277:     my ($r)=@_;
                    278:     &open_form($r);
                    279:     $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
                    280:     &close_form($r);
                    281: } 
                    282: 
                    283: sub delete_dir_confirmed {
                    284:     my ($r)=@_;
                    285:     my $directory_name = $ENV{'form.currentpath'};
1.81    ! albertel  286:     $directory_name =~ s|/$||; # remove any trailing slash
1.30      banghart  287:     my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
                    288: 					       $ENV{'user.domain'},'portfolio'.
                    289: 					       $directory_name);
1.32      banghart  290: 					       
1.30      banghart  291:     if ($result ne 'ok') {
                    292: 	$r->print('<font color="red"> An error occured (dir) ('.$result.
                    293: 		  ') while trying to delete '.$directory_name.'</font><br />');
1.32      banghart  294:     } else {
1.41      banghart  295:         # now remove from recent
                    296: #        $r->print('<br /> removing '.$directory_name.'<br /');
1.42      banghart  297:         &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
1.32      banghart  298:         my @dirs = split m!/!, $directory_name;
                    299:         
                    300: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
                    301:         $directory_name='/';
                    302:         for (my $i=1; $i < (@dirs - 1); $i ++){
                    303:             $directory_name .= $dirs[$i].'/';
                    304:         }
                    305:         $ENV{'form.currentpath'} = $directory_name;
1.30      banghart  306:     }
                    307:     $r->print(&done());
                    308: }
                    309: 
1.24      albertel  310: sub rename {
                    311:     my ($r)=@_;
1.64      banghart  312:     my $file_name = $ENV{'form.currentpath'}.$ENV{'form.rename'};
1.56      banghart  313:     if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'}) eq 'true') {
1.55      banghart  314:         $r->print ("The file is locked and cannot be renamed.<br />");
                    315:         $r->print(&done());
                    316:     } else {
                    317:         &open_form($r);
                    318:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
                    319:                    <input name="filenewname" type="input" size="50" />?</p>');
                    320:         &close_form($r);
                    321:     }
1.24      albertel  322: }
                    323: 
                    324: sub rename_confirmed {
                    325:     my ($r)=@_;
1.27      albertel  326:     my $filenewname=&Apache::lonnet::clean_filename($ENV{'form.filenewname'});
                    327:     if ($filenewname eq '') {
                    328: 	$r->print('<font color="red">'.
                    329: 		  &mt("Error: no valid filename was provided to rename to.").
                    330: 		  '</font><br />');
                    331: 	$r->print(&done());
                    332: 	return;
                    333:     } 
                    334:     my $result=
                    335: 	&Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'},
                    336:             'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'},
1.59      banghart  337:             'portfolio'.$ENV{'form.currentpath'}.$filenewname);
1.27      albertel  338:     if ($result ne 'ok') {
                    339: 	$r->print('<font color="red"> An errror occured ('.$result.
                    340: 		  ') while trying to rename '.&display_file().' to '.
                    341: 		  &display_file(undef,$filenewname).'</font><br />');
                    342:     }
1.66      banghart  343:     if ($filenewname ne $ENV{'form.filenewname'}) {
                    344:         $r->print("The new file name was changed from:<br /><strong>".$ENV{'form.filenewname'}."</strong> to <strong>$filenewname </strong>");
                    345:     }
1.27      albertel  346:     $r->print(&done());
                    347: }
1.47      banghart  348: sub select_files {
                    349:     my ($r)=@_;
1.60      banghart  350:     if ($ENV{'form.continue'} eq 'true') {
                    351:         # here we update the selections for the currentpath
                    352:         # eventually, have to handle removing those not checked, but . . . 
1.65      banghart  353:         my @items=&Apache::loncommon::get_env_multiple('form.selectfile');
1.60      banghart  354:         &Apache::lonnet::save_selected_files($ENV{'user.name'}, $ENV{'form.currentpath'}, @items);
1.62      banghart  355:     } else {
                    356:         if ($ENV{'form.currentpath'} eq '/') {
                    357:             #empty the file for a fresh start
                    358:             # &Apache::lonnet::clear_selected_files($ENV{'user.name'});
                    359:         }
                    360:     }
                    361:     my @files = &Apache::lonnet::files_not_in_path($ENV{'user.name'}, $ENV{'form.currentpath'});
                    362:     my $java_files = join ",", @files;
                    363:     if ($java_files) {
                    364:         $java_files.=',';
1.60      banghart  365:     }
1.63      banghart  366:     my $javascript =(<<ENDSMP);
1.48      banghart  367:         <script language='javascript'>
                    368:         function finishSelect() {
1.62      banghart  369: ENDSMP
1.63      banghart  370:     $javascript .= 'fileList = "'.$java_files.'";';
                    371:     $javascript .= (<<ENDSMP);
1.49      banghart  372:             for (i=0;i<document.forms.checkselect.length;i++) { 
                    373:                 if (document.forms.checkselect[i].checked){
1.54      banghart  374:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49      banghart  375:                 }
                    376:             }
                    377:             opener.document.forms.lonhomework.
                    378: ENDSMP
1.63      banghart  379:     $javascript .= $ENV{'form.fieldname'};
                    380:     $javascript .= (<<ENDSMP);
1.49      banghart  381:         .value=fileList;
1.48      banghart  382:             self.close();
                    383:         }
                    384:         </script>
                    385: ENDSMP
1.63      banghart  386:     $r->print($javascript);
1.47      banghart  387:     $r->print("<h1>Select portfolio files</h1>
                    388:                 Check as many as you wish in response to the essay problem.<br />");
1.61      banghart  389:     $r->print("<strong>Files selected from other directories:</strong><br />");
1.60      banghart  390:     foreach (&Apache::lonnet::files_not_in_path($ENV{'user.name'}, $ENV{'form.currentpath'})) {
                    391:         $r->print($_."<br />");
                    392:     }
1.47      banghart  393: }
1.24      albertel  394: sub upload {
                    395:     my ($r)=@_;
1.33      banghart  396:     my $fname=$ENV{'form.uploaddoc.filename'};
1.38      banghart  397:     my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?)
                    398:     my $disk_quota = 20000; # expressed in k
1.34      banghart  399:     $fname=&Apache::lonnet::clean_filename($fname);
                    400:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  401: 						 $ENV{'user.name'}).
                    402: 						'/userfiles/portfolio';
1.38      banghart  403:     # Fixme --- Move the checking for existing file to LOND error return
1.34      banghart  404:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
                    405: 					  $ENV{'user.domain'},
                    406: 					  $ENV{'user.name'},$portfolio_root);
                    407:     my $found_file = 0;
1.76      banghart  408:     my $locked_file = 0;
1.33      banghart  409:     foreach my $line (@dir_list) {
1.76      banghart  410:         my ($file_name)=split(/\&/,$line,2);
                    411:         if ($file_name eq $fname){
1.33      banghart  412:             $found_file = 1;
1.76      banghart  413:             if (&Apache::lonnet::is_locked($ENV{'form.currentpath'}.$file_name,$ENV{'user.domain'},$ENV{'user.name'} ) eq 'true') {
                    414:                 $locked_file = 1;
                    415:             } 
1.33      banghart  416:         }
                    417:     }
1.38      banghart  418:     my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);
1.69      banghart  419:     if ((($current_disk_usage/1000) + $filesize) > $disk_quota){
1.38      banghart  420:         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
                    421:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1.76      banghart  422:         $r->print(&done('Back'));
1.38      banghart  423:     } 
1.76      banghart  424:     elsif ($found_file){
                    425:         if ($locked_file){
                    426:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>portfolio'.$ENV{'form.currentpath'}.'</strong></font>'.
                    427:                   '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
                    428:             $r->print(&done('Back'));      
                    429:         } else {   
                    430:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>portfolio'.$ENV{'form.currentpath'}.'</strong></font>'.
                    431:                   '<br />To upload, rename or delete existing '.$fname.' in portfolio'.$ENV{'form.currentpath'});
                    432:             $r->print(&done('Back'));
                    433:         }
1.33      banghart  434:     } else {
                    435:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
                    436: 	        	 'portfolio'.$ENV{'form.currentpath'});
                    437:         if ($result !~ m|^/uploaded/|) {
1.34      banghart  438:             $r->print('<font color="red"> An errror occured ('.$result.
                    439: 	              ') while trying to upload '.&display_file().'</font><br />');
1.76      banghart  440: 	    $r->print(&done('Back'));
                    441:         } else {
                    442:             $r->print(&done());
1.33      banghart  443:         }
1.25      albertel  444:     }
                    445: }
1.80      banghart  446: sub lock_info {
                    447:     my ($r) = @_;
                    448:     $r->print("lock info here");
                    449:     return 'ok';
                    450: }
1.25      albertel  451: sub createdir {
                    452:     my ($r)=@_;
1.28      albertel  453:     my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'});
                    454:     if ($newdir eq '') {
1.37      banghart  455:     	$r->print('<font color="red">'.
                    456: 	    	  &mt("Error: no directory name was provided.").
                    457: 		      '</font><br />');
                    458: 	    $r->print(&done());
                    459: 	    return;
1.28      albertel  460:     } 
1.37      banghart  461:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
                    462: 						 $ENV{'user.name'}).
                    463: 						'/userfiles/portfolio';
                    464:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
                    465: 					  $ENV{'user.domain'},
                    466: 					  $ENV{'user.name'},$portfolio_root);
                    467:     my $found_file = 0;
                    468:     foreach my $line (@dir_list) {
                    469:         my ($filename)=split(/\&/,$line,2);
                    470:         if ($filename eq $newdir){
                    471:             $found_file = 1;
                    472:         }
                    473:     }
                    474:     if ($found_file){
                    475:     	    $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
                    476:     	            ' </strong>a file or directory by that name already exists.</font><br />');
                    477:     } else {
                    478:         my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'},
                    479: 	         $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir);
                    480:         if ($result ne 'ok') {
                    481:     	    $r->print('<font color="red"> An errror occured ('.$result.
                    482: 	    	      ') while trying to create a new directory '.&display_file().'</font><br />');
                    483:         }
1.24      albertel  484:     }
1.67      banghart  485:     if ($newdir ne $ENV{'form.newdir'}) {
                    486:         $r->print("The new directory name was changed from:<br /><strong>".$ENV{'form.newdir'}."</strong> to <strong>$newdir </strong>");  
                    487:     }
1.24      albertel  488:     $r->print(&done());
                    489: }
                    490: 
                    491: sub handler {
                    492:     # this handles file management
                    493:     my $r = shift;
1.47      banghart  494:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  495: 							 $ENV{'user.name'}).
                    496: 							'/userfiles/portfolio';
1.73      banghart  497:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.80      banghart  498:                                             ['selectfile','currentpath','meta','lockinfo',
1.73      banghart  499: 					     'currentfile','action','fieldname','mode','rename']);
1.24      albertel  500:     &Apache::loncommon::no_cache($r);
                    501:     &Apache::loncommon::content_type($r,'text/html');
                    502:     $r->send_http_header;
                    503:     # Give the LON-CAPA page header
1.75      albertel  504:     my $html=&Apache::lonxml::xmlbegin();
                    505:     $r->print($html.'<head><title>'.
1.24      albertel  506:               &mt('Portfolio Manager').
1.74      banghart  507:               "</title></head>\n");
                    508:     if ($ENV{"form.mode"} eq 'selectfile'){
                    509:         $r->print(&Apache::loncommon::bodytag('Portfolio Manager',undef,undef,1));
                    510:     } else {
                    511:         $r->print(&Apache::loncommon::bodytag('Portfolio Manager'));
                    512:     }
1.24      albertel  513:     $r->rflush();
1.40      banghart  514: 	if (($ENV{'form.storeupl'} eq 'Upload') & (!$ENV{'form.uploaddoc.filename'})){
                    515:    	    $r->print('<font color="red"> No file was selected to upload.'.
                    516:    	            'To upload a file, click <strong>Browse...</strong>'.
                    517:    	            ', select a file, then click <strong>Upload</strong>,</font>');
                    518: 	}
1.70      banghart  519:     if ($ENV{'form.meta'}) {
                    520:         &open_form($r);
1.72      banghart  521: #        $r->print(&edit_meta_data($r, $ENV{'form.currentpath'}.$ENV{'form.selectfile'}));
1.70      banghart  522:         $r->print('Edit the meta data<br />');
                    523:         &close_form($r);
                    524:     }
                    525:     if ($ENV{'form.store'}) {
                    526:     }
                    527: 
1.24      albertel  528:     if ($ENV{'form.uploaddoc.filename'}) {
                    529: 	&upload($r);
1.27      albertel  530:     } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) {
                    531: 	&delete_confirmed($r);
1.24      albertel  532:     } elsif ($ENV{'form.action'} eq 'delete') {
1.27      albertel  533: 	&delete($r);
1.30      banghart  534:     } elsif ($ENV{'form.action'} eq 'deletedir' && $ENV{'form.confirmed'}) {
1.31      albertel  535: 	&delete_dir_confirmed($r);
1.30      banghart  536:     } elsif ($ENV{'form.action'} eq 'deletedir'){
1.31      albertel  537: 	&delete_dir($r);
1.27      albertel  538:     } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) {
                    539: 	&rename_confirmed($r);
1.64      banghart  540:     } elsif ($ENV{'form.rename'}) {
                    541:         $ENV{'form.selectfile'} = $ENV{'form.rename'};
                    542:         $ENV{'form.action'} = 'rename';
1.24      albertel  543: 	&rename($r);
1.25      albertel  544:     } elsif ($ENV{'form.createdir'}) {
                    545: 	&createdir($r);
1.80      banghart  546:     } elsif ($ENV{'form.lockinfo'}) {
                    547:         &lock_info($r);
1.24      albertel  548:     } else {
                    549: 	my $current_path='/';
                    550: 	if ($ENV{'form.currentpath'}) {
                    551: 	    $current_path = $ENV{'form.currentpath'};
                    552: 	}
1.43      banghart  553: 	my @dir_list=&Apache::lonnet::dirlist($current_path,
1.27      albertel  554: 					    $ENV{'user.domain'},
                    555: 					    $ENV{'user.name'},$portfolio_root);
1.46      albertel  556: 	if ($dir_list[0] eq 'no_such_dir'){
                    557: 	    # two main reasons for this:
                    558:             #    1) never been here, so directory structure not created
                    559: 	    #    2) back-button navigation after deleting a directory
                    560: 	    if ($current_path eq '/'){
1.43      banghart  561: 	        &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
1.46      albertel  562: 					       $ENV{'user.domain'},'portfolio');
                    563: 	    } else {
                    564:                 # some directory that snuck in get rid of the directory
                    565:                 # from the recent pulldown, just in case
                    566: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
                    567: 						      [$current_path]);
                    568: 		$current_path = '/'; # force it back to the root        
                    569: 	    }
                    570: 	    # now grab the directory list again, for the first time
                    571: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
                    572: 					    $ENV{'user.domain'},
                    573: 					    $ENV{'user.name'},$portfolio_root);
1.43      banghart  574:         }
1.46      albertel  575: 	# need to know if directory is empty so it can be removed if desired
                    576: 	my $is_empty=(@dir_list == 2);
1.48      banghart  577: 	&display_common($r,$current_path,$is_empty,\@dir_list);
1.77      banghart  578:         &display_directory($r,$current_path,$is_empty,\@dir_list);
1.46      albertel  579: 	$r->print("</body>\n</html>\n");
                    580: 	return OK;
1.30      banghart  581:     }
1.2       banghart  582: }
1.1       banghart  583: 1;
                    584: __END__

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