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

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

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