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

1.3       banghart    1: # Copyright Michigan State University Board of Trustees
                      2: #
                      3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      4: #
                      5: # LON-CAPA is free software; you can redistribute it and/or modify
                      6: # it under the terms of the GNU General Public License as published by
                      7: # the Free Software Foundation; either version 2 of the License, or 
                      8: # (at your option) any later version.
                      9: #
                     10: # LON-CAPA is distributed in the hope that it will be useful,
                     11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     13: # GNU General Public License for more details.
                     14: #
                     15: # You should have received a copy of the GNU General Public License
                     16: # along with LON-CAPA; if not, write to the Free Software
                     17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     18: #
                     19: # /home/httpd/html/adm/gpl.txt
                     20: #
                     21: # http://www.lon-capa.org/
                     22: #
                     23: 
1.1       banghart   24: package Apache::portfolio;
                     25: use strict;
                     26: use Apache::Constants qw(:common :http);
1.2       banghart   27: use Apache::loncommon;
1.1       banghart   28: use Apache::lonnet;
1.2       banghart   29: use Apache::lontexconvert;
                     30: use Apache::lonfeedback;
                     31: use Apache::lonlocal;
1.16      banghart   32: 
                     33: # receives a file name and path stub from username/userfiles/portfolio/
                     34: # returns an anchor tag consisting encoding filename and currentpath
1.23      albertel   35: sub make_anchor {
                     36:     my ($filename, $current_path) = @_;
                     37:     my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'&currentpath='.$current_path.'">'.$filename.'</a>';
1.8       albertel   38:     return $anchor;
1.6       banghart   39: }
1.24      albertel   40: my $dirptr=16384;
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.20      banghart   51:         '<input type="submit" name="storeupl" value="Upload" />'.
                     52:         '</form>';
                     53:     $r->print($displayOut);
1.22      albertel   54:     $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
1.24      albertel   55:     $displayOut = '<form method="post">';
                     56:     $displayOut .= '<input name="newdir" type="input" />'.
                     57:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.50      banghart   58:         '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
                     59:         '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
1.22      albertel   60:         '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
                     61:         '</form>';
                     62:     $r->print($displayOut);
                     63:     $r->print('</td></tr></table>');
1.24      albertel   64:     my @tree = split (/\//,$current_path);
1.29      albertel   65:     $r->print('<font size="+2">'.&make_anchor('portfolio','/').'/');
1.19      banghart   66:     if (@tree > 1){
                     67:         my $newCurrentPath = '';
                     68:         for (my $i = 1; $i< @tree; $i++){
                     69:             $newCurrentPath .= $tree[$i].'/';
1.23      albertel   70:             $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath).'/');
1.19      banghart   71:         }
                     72:     }
                     73:     $r->print('</font>');
1.24      albertel   74:     &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
1.22      albertel   75:     $r->print('<br /><form method=post action="/adm/portfolio">'.
                     76: 	      &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
                     77: 						    'this.form.submit();'));
1.21      banghart   78:     $r->print("</form>");
1.48      banghart   79: }
                     80: sub display_directory {
                     81:     my ($r,$current_path,$is_empty,$dir_list)=@_;
                     82:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
                     83:     my $display_out;
1.53      banghart   84:     my %locked_files=&Apache::lonnet::dump('file_permissions',
                     85:                                   $ENV{'user.domain'},$ENV{'user.name'});
                     86:     my $locked_file;
                     87:     foreach my $key (keys %locked_files) {
                     88:         $locked_file .= $locked_files{$key}.':';
                     89:     }
1.45      banghart   90:     if ($is_empty && ($current_path ne '/')) {
1.48      banghart   91:         $display_out = '<form method="post" action="/adm/portfolio">'.
1.30      banghart   92:         '<input type="hidden" name="action" value="deletedir" />'.
                     93:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
                     94:         '<input type="hidden" name="selectfile" value="" />'.
                     95:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
                     96:         '</form>';
                     97:         
1.48      banghart   98:         $r->print($display_out);
1.31      albertel   99: 	return;
                    100:     }
1.18      banghart  101:     $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
1.22      albertel  102:             '<tr><th>Actions</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
1.39      banghart  103:     my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
1.26      albertel  104:     foreach my $line (sort 
                    105: 		      { 
                    106: 			  my ($afile)=split('&',$a,2);
                    107: 			  my ($bfile)=split('&',$b,2);
                    108: 			  return (lc($afile) cmp lc($bfile));
                    109: 		      } (@$dir_list)) {
1.18      banghart  110:     	#$strip holds directory/file name
                    111:     	#$dom 
1.23      albertel  112:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
1.53      banghart  113:     	if ($Apache::lonhomework::results{"resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename"}eq'true'){
                    114:     	    &Apache::lonnet::logthis("found submitted file");
                    115:     	    &Apache::lonnet::logthis("resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename");
                    116:     	} else {
                    117:     	    &Apache::lonnet::logthis("$filename not found submitted file");
                    118:     	    &Apache::lonnet::logthis("resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename");
                    119:     	}
1.23      albertel  120:     	if (($filename ne '.') && ($filename ne '..')) {
                    121:             if ($dirptr&$testdir) {
1.19      banghart  122:                 $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
                    123:                 $r->print('<td>Go to ...</td>');
1.24      albertel  124:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/').'</td>'); 
1.19      banghart  125:                 $r->print('</tr>'); 
1.23      albertel  126:             } else {
1.22      albertel  127:                 $r->print('<tr bgcolor="#CCCCFF">');
                    128:                 $r->print('<td>
1.39      banghart  129:                     <form method="post" action="/adm/portfolio">
                    130:                     <select name="action">
                    131:                         <option value=""></option>
                    132:                         <option value="delete">'.&mt("Delete").'</option>
                    133:                         <option value="rename">'.&mt("Rename").'</option>
                    134:                     </select>
                    135:                     <input type="submit" name="doit" value="Go" />
                    136:                     <input type="hidden" name="selectfile" value="'.$filename.'" />
                    137:                     <input type="hidden" name="currentpath" value="'.$current_path.'" />
                    138:                     </form>
                    139:                     </td>');
1.22      albertel  140:                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
1.23      albertel  141:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
1.39      banghart  142: 			    $filename.'</a></td>'); 
1.22      albertel  143:                 $r->print('<td>'.$size.'</td>');
                    144:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
1.19      banghart  145:                 $r->print('</tr>'); 
                    146:             }
1.18      banghart  147:         }
                    148:     }
                    149: #   <tr bgcolor="#FFAA99"> pink bg 
                    150: #   <tr bgcolor="#CCCCFF"> blue bg            
1.24      albertel  151: #   $r->print(&display_directory($current_path, $currentFile, @dir_list));
1.18      banghart  152: #    $r->print('</td>><td>');
1.24      albertel  153: #   $r->print(&display_actions($current_path, $currentFile, $isEmpty));
1.22      albertel  154:     $r->print('</table></form>');
1.24      albertel  155: }
1.47      banghart  156: sub display_file_select {
                    157:     my ($r,$current_path,$is_empty,$dir_list)=@_;
                    158:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.48      banghart  159:     my $display_out;
1.47      banghart  160:     if ($is_empty && ($current_path ne '/')) {
1.48      banghart  161:         $display_out = '<form method="post" action="/adm/portfolio">'.
1.47      banghart  162:         '<input type="hidden" name="action" value="deletedir" />'.
                    163:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
                    164:         '<input type="hidden" name="selectfile" value="" />'.
                    165:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.48      banghart  166: 
1.47      banghart  167:         '</form>';
                    168:         
1.48      banghart  169:         $r->print($display_out);
1.47      banghart  170: 	return;
                    171:     }
                    172:     $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
                    173:             '<tr><th>Select</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
                    174:     my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
1.48      banghart  175:     $r->print('<form method="post" name="checkselect" action="/adm/portfolio">');
1.47      banghart  176:     foreach my $line (sort 
                    177: 		      { 
                    178: 			  my ($afile)=split('&',$a,2);
                    179: 			  my ($bfile)=split('&',$b,2);
                    180: 			  return (lc($afile) cmp lc($bfile));
                    181: 		      } (@$dir_list)) {
                    182:     	#$strip holds directory/file name
                    183:     	#$dom 
                    184:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
                    185:     	if (($filename ne '.') && ($filename ne '..')) {
                    186:             if ($dirptr&$testdir) {
                    187:                 $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
                    188:                 $r->print('<td>Go to ...</td>');
                    189:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/').'</td>'); 
                    190:                 $r->print('</tr>'); 
                    191:             } else {
                    192:                 $r->print('<tr bgcolor="#CCCCFF">');
                    193:                 $r->print('<td>
                    194:                         <input type="checkbox" name="selectedfile" value="'.$filename.'" >
                    195:                     </td>');
                    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>
                    206:             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
                    207:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
                    208:     </form>');
1.47      banghart  209: }
1.24      albertel  210: 
                    211: sub open_form {
                    212:     my ($r)=@_;
                    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" />');
                    217:     $r->print('<input type="hidden" name="selectfile" value="'.
                    218: 	      $ENV{'form.selectfile'}.'" />');
                    219:     $r->print('<input type="hidden" name="currentpath" value="'.
                    220: 	      $ENV{'form.currentpath'}.'" />');
                    221: }
                    222: 
                    223: sub close_form {
                    224:     my ($r)=@_;
                    225:     $r->print('<p><input type="submit" value="'.&mt('Continue').
                    226: 	      '" /></p></form>');
                    227:     $r->print('<form action="/adm/portfolio" method="POST">
                    228:                <p>
                    229:               <input type="hidden" name="currentpath" value="'.
                    230: 	      $ENV{'form.currentpath'}.'" />
                    231:                  <input type="submit" value="'.&mt('Cancel').'" />
                    232:                </p></form>');
                    233: 
                    234: }
                    235: 
                    236: sub display_file {
1.27      albertel  237:     my ($path,$filename)=@_;
                    238:     if (!defined($path)) { $path=$ENV{'form.currentpath'}; }
                    239:     if (!defined($filename)) { $filename=$ENV{'form.selectfile'}; }
                    240:     return '<tt>'.$path.$filename.'</tt>';
1.24      albertel  241: }
                    242: 
                    243: sub done {
1.25      albertel  244:     return ('<h3><a href="/adm/portfolio?currentpath='.
1.50      banghart  245: 	    $ENV{'form.currentpath'}.
                    246: 	    '&fieldname='.$ENV{'form.fieldname'}.
                    247: 	    '">'.&mt('Done').'</a></h3>');
1.24      albertel  248: }
                    249: 
                    250: sub delete {
                    251:     my ($r)=@_;
1.55      banghart  252:     my @check;
                    253:     my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'};
1.56    ! banghart  254:     if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'} ) eq 'true') {
1.55      banghart  255:         $r->print ("The file is locked and cannot be deleted.<br />");
                    256:         $r->print(&done());
                    257:     } else {
                    258:         &open_form($r);
                    259:         $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
                    260:         &close_form($r);
                    261:     }
1.24      albertel  262: } 
                    263: 
                    264: sub delete_confirmed {
                    265:     my ($r)=@_;
                    266:     my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
                    267: 					       $ENV{'user.domain'},'portfolio'.
                    268: 					       $ENV{'form.currentpath'}.
                    269: 					       $ENV{'form.selectfile'});
                    270:     if ($result ne 'ok') {
1.30      banghart  271: 	$r->print('<font color="red"> An error occured ('.$result.
1.25      albertel  272: 		  ') while trying to delete '.&display_file().'</font><br />');
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)=@_;
                    286:     my $directory_name = $ENV{'form.currentpath'};
                    287:     $directory_name =~ m/\/$/;
                    288:     $directory_name = $`;
                    289:     my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
                    290: 					       $ENV{'user.domain'},'portfolio'.
                    291: 					       $directory_name);
1.32      banghart  292: 					       
1.30      banghart  293:     if ($result ne 'ok') {
                    294: 	$r->print('<font color="red"> An error occured (dir) ('.$result.
                    295: 		  ') while trying to delete '.$directory_name.'</font><br />');
1.32      banghart  296:     } else {
1.41      banghart  297:         # now remove from recent
                    298: #        $r->print('<br /> removing '.$directory_name.'<br /');
1.42      banghart  299:         &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
1.32      banghart  300:         my @dirs = split m!/!, $directory_name;
                    301:         
                    302: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
                    303:         $directory_name='/';
                    304:         for (my $i=1; $i < (@dirs - 1); $i ++){
                    305:             $directory_name .= $dirs[$i].'/';
                    306:         }
                    307:         $ENV{'form.currentpath'} = $directory_name;
1.30      banghart  308:     }
                    309:     $r->print(&done());
                    310: }
                    311: 
1.24      albertel  312: sub rename {
                    313:     my ($r)=@_;
1.55      banghart  314:     my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'};
1.56    ! banghart  315:     if (&Apache::lonnet::is_locked($file_name,$ENV{'user.domain'},$ENV{'user.name'}) eq 'true') {
1.55      banghart  316:         $r->print ("The file is locked and cannot be renamed.<br />");
                    317:         $r->print(&done());
                    318:     } else {
                    319:         &open_form($r);
                    320:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
                    321:                    <input name="filenewname" type="input" size="50" />?</p>');
                    322:         &close_form($r);
                    323:     }
1.24      albertel  324: }
                    325: 
                    326: sub rename_confirmed {
                    327:     my ($r)=@_;
1.27      albertel  328:     my $filenewname=&Apache::lonnet::clean_filename($ENV{'form.filenewname'});
                    329:     if ($filenewname eq '') {
                    330: 	$r->print('<font color="red">'.
                    331: 		  &mt("Error: no valid filename was provided to rename to.").
                    332: 		  '</font><br />');
                    333: 	$r->print(&done());
                    334: 	return;
                    335:     } 
                    336:     my $result=
                    337: 	&Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'},
                    338:             'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'},
                    339:             'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.filenewname'});
                    340:     if ($result ne 'ok') {
                    341: 	$r->print('<font color="red"> An errror occured ('.$result.
                    342: 		  ') while trying to rename '.&display_file().' to '.
                    343: 		  &display_file(undef,$filenewname).'</font><br />');
                    344:     }
                    345:     $r->print(&done());
                    346: }
1.47      banghart  347: sub select_files {
                    348:     my ($r)=@_;
1.48      banghart  349:     my $java_script =(<<ENDSMP);
                    350:         <script language='javascript'>
                    351:         function finishSelect() {
1.49      banghart  352:             fileList = "";
                    353:             for (i=0;i<document.forms.checkselect.length;i++) { 
                    354:                 if (document.forms.checkselect[i].checked){
1.54      banghart  355:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49      banghart  356:                 }
                    357:             }
                    358:             opener.document.forms.lonhomework.
                    359: ENDSMP
                    360:     $java_script .= $ENV{'form.fieldname'};
                    361:     $java_script .= (<<ENDSMP);
                    362:         .value=fileList;
1.48      banghart  363:             self.close();
                    364:         }
                    365:         </script>
                    366: ENDSMP
                    367:     $r->print($java_script);
1.47      banghart  368:     $r->print("<h1>Select portfolio files</h1>
                    369:                 Check as many as you wish in response to the essay problem.<br />");
                    370: }
1.24      albertel  371: sub upload {
                    372:     my ($r)=@_;
1.33      banghart  373:     my $fname=$ENV{'form.uploaddoc.filename'};
1.38      banghart  374:     my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?)
                    375:     my $disk_quota = 20000; # expressed in k
1.34      banghart  376:     $fname=&Apache::lonnet::clean_filename($fname);
                    377:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  378: 						 $ENV{'user.name'}).
                    379: 						'/userfiles/portfolio';
1.38      banghart  380:     # Fixme --- Move the checking for existing file to LOND error return
1.34      banghart  381:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
                    382: 					  $ENV{'user.domain'},
                    383: 					  $ENV{'user.name'},$portfolio_root);
                    384:     my $found_file = 0;
1.33      banghart  385:     foreach my $line (@dir_list) {
1.34      banghart  386:         my ($filename)=split(/\&/,$line,2);
1.33      banghart  387:         if ($filename eq $fname){
                    388:             $found_file = 1;
                    389:         }
                    390:     }
1.38      banghart  391:     my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);
                    392:     if (($current_disk_usage + $filesize) > $disk_quota){
                    393:         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
                    394:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
                    395:     } 
                    396:     elsif ($found_file){   
1.33      banghart  397:         $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>'.
                    398:                   '<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'});
                    399:     } else {
                    400:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
                    401: 	        	 'portfolio'.$ENV{'form.currentpath'});
                    402:         if ($result !~ m|^/uploaded/|) {
1.34      banghart  403:             $r->print('<font color="red"> An errror occured ('.$result.
                    404: 	              ') while trying to upload '.&display_file().'</font><br />');
1.33      banghart  405:         }
1.25      albertel  406:     }
                    407:     $r->print(&done());
                    408: }
                    409: 
                    410: sub createdir {
                    411:     my ($r)=@_;
1.28      albertel  412:     my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'});
                    413:     if ($newdir eq '') {
1.37      banghart  414:     	$r->print('<font color="red">'.
                    415: 	    	  &mt("Error: no directory name was provided.").
                    416: 		      '</font><br />');
                    417: 	    $r->print(&done());
                    418: 	    return;
1.28      albertel  419:     } 
1.37      banghart  420:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
                    421: 						 $ENV{'user.name'}).
                    422: 						'/userfiles/portfolio';
                    423:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
                    424: 					  $ENV{'user.domain'},
                    425: 					  $ENV{'user.name'},$portfolio_root);
                    426:     my $found_file = 0;
                    427:     foreach my $line (@dir_list) {
                    428:         my ($filename)=split(/\&/,$line,2);
                    429:         if ($filename eq $newdir){
                    430:             $found_file = 1;
                    431:         }
                    432:     }
                    433:     if ($found_file){
                    434:     	    $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
                    435:     	            ' </strong>a file or directory by that name already exists.</font><br />');
                    436:     } else {
                    437:         my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'},
                    438: 	         $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir);
                    439:         if ($result ne 'ok') {
                    440:     	    $r->print('<font color="red"> An errror occured ('.$result.
                    441: 	    	      ') while trying to create a new directory '.&display_file().'</font><br />');
                    442:         }
1.24      albertel  443:     }
                    444:     $r->print(&done());
                    445: }
                    446: 
                    447: sub handler {
                    448:     # this handles file management
                    449:     my $r = shift;
1.47      banghart  450:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  451: 							 $ENV{'user.name'}).
                    452: 							'/userfiles/portfolio';
1.24      albertel  453:     &Apache::loncommon::no_cache($r);
                    454:     &Apache::loncommon::content_type($r,'text/html');
                    455:     $r->send_http_header;
                    456:     # Give the LON-CAPA page header
                    457:     $r->print('<html><head><title>'.
                    458:               &mt('Portfolio Manager').
                    459:               "</title></head>\n".
                    460:               &Apache::loncommon::bodytag('Portfolio Manager'));
                    461:     $r->rflush();
                    462:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    463:                                             ['selectfile','currentpath',
1.52      banghart  464: 					     'currentfile','action','fieldname','mode']);
1.40      banghart  465: 	if (($ENV{'form.storeupl'} eq 'Upload') & (!$ENV{'form.uploaddoc.filename'})){
                    466:    	    $r->print('<font color="red"> No file was selected to upload.'.
                    467:    	            'To upload a file, click <strong>Browse...</strong>'.
                    468:    	            ', select a file, then click <strong>Upload</strong>,</font>');
                    469: 	}
1.24      albertel  470:     if ($ENV{'form.uploaddoc.filename'}) {
                    471: 	&upload($r);
1.27      albertel  472:     } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) {
                    473: 	&delete_confirmed($r);
1.24      albertel  474:     } elsif ($ENV{'form.action'} eq 'delete') {
1.27      albertel  475: 	&delete($r);
1.30      banghart  476:     } elsif ($ENV{'form.action'} eq 'deletedir' && $ENV{'form.confirmed'}) {
1.31      albertel  477: 	&delete_dir_confirmed($r);
1.30      banghart  478:     } elsif ($ENV{'form.action'} eq 'deletedir'){
1.31      albertel  479: 	&delete_dir($r);
1.27      albertel  480:     } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) {
                    481: 	&rename_confirmed($r);
1.24      albertel  482:     } elsif ($ENV{'form.action'} eq 'rename') {
                    483: 	&rename($r);
1.25      albertel  484:     } elsif ($ENV{'form.createdir'}) {
                    485: 	&createdir($r);
1.24      albertel  486:     } else {
                    487: 	my $current_path='/';
                    488: 	if ($ENV{'form.currentpath'}) {
                    489: 	    $current_path = $ENV{'form.currentpath'};
                    490: 	}
1.43      banghart  491: 	my @dir_list=&Apache::lonnet::dirlist($current_path,
1.27      albertel  492: 					    $ENV{'user.domain'},
                    493: 					    $ENV{'user.name'},$portfolio_root);
1.46      albertel  494: 	if ($dir_list[0] eq 'no_such_dir'){
                    495: 	    # two main reasons for this:
                    496:             #    1) never been here, so directory structure not created
                    497: 	    #    2) back-button navigation after deleting a directory
                    498: 	    if ($current_path eq '/'){
1.43      banghart  499: 	        &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
1.46      albertel  500: 					       $ENV{'user.domain'},'portfolio');
                    501: 	    } else {
                    502:                 # some directory that snuck in get rid of the directory
                    503:                 # from the recent pulldown, just in case
                    504: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
                    505: 						      [$current_path]);
                    506: 		$current_path = '/'; # force it back to the root        
                    507: 	    }
                    508: 	    # now grab the directory list again, for the first time
                    509: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
                    510: 					    $ENV{'user.domain'},
                    511: 					    $ENV{'user.name'},$portfolio_root);
1.43      banghart  512:         }
1.46      albertel  513: 	# need to know if directory is empty so it can be removed if desired
                    514: 	my $is_empty=(@dir_list == 2);
1.48      banghart  515: 	&display_common($r,$current_path,$is_empty,\@dir_list);
1.51      matthew   516: 	if ($ENV{"form.mode"} eq 'selectfile'){
1.50      banghart  517: 	    &select_files($r);
                    518:             &display_file_select($r,$current_path,$is_empty,\@dir_list);
                    519: 	} else {
                    520: 	    &display_directory($r,$current_path,$is_empty,\@dir_list);
                    521: 	}
1.46      albertel  522: 	$r->print("</body>\n</html>\n");
                    523: 	return OK;
1.30      banghart  524:     }
1.2       banghart  525: }
1.1       banghart  526: 1;
                    527: __END__

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