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

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

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