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

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

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