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

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'};
        !           254:     push @check, $file_name;
        !           255:     my %locked = &Apache::lonnet::get('file_permissions',\@check,
        !           256:                                         $ENV{'user.domain'},$ENV{'user.name'});
        !           257:     if (ref($locked{$file_name}) eq 'ARRAY') {
        !           258:         $r->print ("The file is locked and cannot be deleted.<br />");
        !           259:         $r->print(&done());
        !           260:     } else {
        !           261:         &open_form($r);
        !           262:         $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
        !           263:         &close_form($r);
        !           264:     }
1.24      albertel  265: } 
                    266: 
                    267: sub delete_confirmed {
                    268:     my ($r)=@_;
                    269:     my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
                    270: 					       $ENV{'user.domain'},'portfolio'.
                    271: 					       $ENV{'form.currentpath'}.
                    272: 					       $ENV{'form.selectfile'});
                    273:     if ($result ne 'ok') {
1.30      banghart  274: 	$r->print('<font color="red"> An error occured ('.$result.
1.25      albertel  275: 		  ') while trying to delete '.&display_file().'</font><br />');
1.24      albertel  276:     }
                    277:     $r->print(&done());
                    278: }
                    279: 
1.30      banghart  280: sub delete_dir {
                    281:     my ($r)=@_;
                    282:     &open_form($r);
                    283:     $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
                    284:     &close_form($r);
                    285: } 
                    286: 
                    287: sub delete_dir_confirmed {
                    288:     my ($r)=@_;
                    289:     my $directory_name = $ENV{'form.currentpath'};
                    290:     $directory_name =~ m/\/$/;
                    291:     $directory_name = $`;
                    292:     my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
                    293: 					       $ENV{'user.domain'},'portfolio'.
                    294: 					       $directory_name);
1.32      banghart  295: 					       
1.30      banghart  296:     if ($result ne 'ok') {
                    297: 	$r->print('<font color="red"> An error occured (dir) ('.$result.
                    298: 		  ') while trying to delete '.$directory_name.'</font><br />');
1.32      banghart  299:     } else {
1.41      banghart  300:         # now remove from recent
                    301: #        $r->print('<br /> removing '.$directory_name.'<br /');
1.42      banghart  302:         &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
1.32      banghart  303:         my @dirs = split m!/!, $directory_name;
                    304:         
                    305: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
                    306:         $directory_name='/';
                    307:         for (my $i=1; $i < (@dirs - 1); $i ++){
                    308:             $directory_name .= $dirs[$i].'/';
                    309:         }
                    310:         $ENV{'form.currentpath'} = $directory_name;
1.30      banghart  311:     }
                    312:     $r->print(&done());
                    313: }
                    314: 
1.24      albertel  315: sub rename {
                    316:     my ($r)=@_;
1.55    ! banghart  317:     my @check;
        !           318:     my $file_name = $ENV{'form.currentpath'}.$ENV{'form.selectfile'};
        !           319:     push @check, $file_name;
        !           320:     my %locked = &Apache::lonnet::get('file_permissions',\@check,
        !           321:                                         $ENV{'user.domain'},$ENV{'user.name'});
        !           322:     if (ref($locked{$file_name}) eq 'ARRAY') {
        !           323:         $r->print ("The file is locked and cannot be renamed.<br />");
        !           324:         $r->print(&done());
        !           325:     } else {
        !           326:         &open_form($r);
        !           327:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
        !           328:                    <input name="filenewname" type="input" size="50" />?</p>');
        !           329:         &close_form($r);
        !           330:     }
1.24      albertel  331: }
                    332: 
                    333: sub rename_confirmed {
                    334:     my ($r)=@_;
1.27      albertel  335:     my $filenewname=&Apache::lonnet::clean_filename($ENV{'form.filenewname'});
                    336:     if ($filenewname eq '') {
                    337: 	$r->print('<font color="red">'.
                    338: 		  &mt("Error: no valid filename was provided to rename to.").
                    339: 		  '</font><br />');
                    340: 	$r->print(&done());
                    341: 	return;
                    342:     } 
                    343:     my $result=
                    344: 	&Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'},
                    345:             'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'},
                    346:             'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.filenewname'});
                    347:     if ($result ne 'ok') {
                    348: 	$r->print('<font color="red"> An errror occured ('.$result.
                    349: 		  ') while trying to rename '.&display_file().' to '.
                    350: 		  &display_file(undef,$filenewname).'</font><br />');
                    351:     }
                    352:     $r->print(&done());
                    353: }
1.47      banghart  354: sub select_files {
                    355:     my ($r)=@_;
1.48      banghart  356:     my $java_script =(<<ENDSMP);
                    357:         <script language='javascript'>
                    358:         function finishSelect() {
1.49      banghart  359:             fileList = "";
                    360:             for (i=0;i<document.forms.checkselect.length;i++) { 
                    361:                 if (document.forms.checkselect[i].checked){
1.54      banghart  362:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49      banghart  363:                 }
                    364:             }
                    365:             opener.document.forms.lonhomework.
                    366: ENDSMP
                    367:     $java_script .= $ENV{'form.fieldname'};
                    368:     $java_script .= (<<ENDSMP);
                    369:         .value=fileList;
1.48      banghart  370:             self.close();
                    371:         }
                    372:         </script>
                    373: ENDSMP
                    374:     $r->print($java_script);
1.47      banghart  375:     $r->print("<h1>Select portfolio files</h1>
                    376:                 Check as many as you wish in response to the essay problem.<br />");
                    377: }
1.24      albertel  378: sub upload {
                    379:     my ($r)=@_;
1.33      banghart  380:     my $fname=$ENV{'form.uploaddoc.filename'};
1.38      banghart  381:     my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?)
                    382:     my $disk_quota = 20000; # expressed in k
1.34      banghart  383:     $fname=&Apache::lonnet::clean_filename($fname);
                    384:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  385: 						 $ENV{'user.name'}).
                    386: 						'/userfiles/portfolio';
1.38      banghart  387:     # Fixme --- Move the checking for existing file to LOND error return
1.34      banghart  388:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
                    389: 					  $ENV{'user.domain'},
                    390: 					  $ENV{'user.name'},$portfolio_root);
                    391:     my $found_file = 0;
1.33      banghart  392:     foreach my $line (@dir_list) {
1.34      banghart  393:         my ($filename)=split(/\&/,$line,2);
1.33      banghart  394:         if ($filename eq $fname){
                    395:             $found_file = 1;
                    396:         }
                    397:     }
1.38      banghart  398:     my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);
                    399:     if (($current_disk_usage + $filesize) > $disk_quota){
                    400:         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
                    401:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
                    402:     } 
                    403:     elsif ($found_file){   
1.33      banghart  404:         $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>'.
                    405:                   '<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'});
                    406:     } else {
                    407:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
                    408: 	        	 'portfolio'.$ENV{'form.currentpath'});
                    409:         if ($result !~ m|^/uploaded/|) {
1.34      banghart  410:             $r->print('<font color="red"> An errror occured ('.$result.
                    411: 	              ') while trying to upload '.&display_file().'</font><br />');
1.33      banghart  412:         }
1.25      albertel  413:     }
                    414:     $r->print(&done());
                    415: }
                    416: 
                    417: sub createdir {
                    418:     my ($r)=@_;
1.28      albertel  419:     my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'});
                    420:     if ($newdir eq '') {
1.37      banghart  421:     	$r->print('<font color="red">'.
                    422: 	    	  &mt("Error: no directory name was provided.").
                    423: 		      '</font><br />');
                    424: 	    $r->print(&done());
                    425: 	    return;
1.28      albertel  426:     } 
1.37      banghart  427:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
                    428: 						 $ENV{'user.name'}).
                    429: 						'/userfiles/portfolio';
                    430:     my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
                    431: 					  $ENV{'user.domain'},
                    432: 					  $ENV{'user.name'},$portfolio_root);
                    433:     my $found_file = 0;
                    434:     foreach my $line (@dir_list) {
                    435:         my ($filename)=split(/\&/,$line,2);
                    436:         if ($filename eq $newdir){
                    437:             $found_file = 1;
                    438:         }
                    439:     }
                    440:     if ($found_file){
                    441:     	    $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
                    442:     	            ' </strong>a file or directory by that name already exists.</font><br />');
                    443:     } else {
                    444:         my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'},
                    445: 	         $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir);
                    446:         if ($result ne 'ok') {
                    447:     	    $r->print('<font color="red"> An errror occured ('.$result.
                    448: 	    	      ') while trying to create a new directory '.&display_file().'</font><br />');
                    449:         }
1.24      albertel  450:     }
                    451:     $r->print(&done());
                    452: }
                    453: 
                    454: sub handler {
                    455:     # this handles file management
                    456:     my $r = shift;
1.47      banghart  457:     my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33      banghart  458: 							 $ENV{'user.name'}).
                    459: 							'/userfiles/portfolio';
1.24      albertel  460:     &Apache::loncommon::no_cache($r);
                    461:     &Apache::loncommon::content_type($r,'text/html');
                    462:     $r->send_http_header;
                    463:     # Give the LON-CAPA page header
                    464:     $r->print('<html><head><title>'.
                    465:               &mt('Portfolio Manager').
                    466:               "</title></head>\n".
                    467:               &Apache::loncommon::bodytag('Portfolio Manager'));
                    468:     $r->rflush();
                    469:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    470:                                             ['selectfile','currentpath',
1.52      banghart  471: 					     'currentfile','action','fieldname','mode']);
1.40      banghart  472: 	if (($ENV{'form.storeupl'} eq 'Upload') & (!$ENV{'form.uploaddoc.filename'})){
                    473:    	    $r->print('<font color="red"> No file was selected to upload.'.
                    474:    	            'To upload a file, click <strong>Browse...</strong>'.
                    475:    	            ', select a file, then click <strong>Upload</strong>,</font>');
                    476: 	}
1.24      albertel  477:     if ($ENV{'form.uploaddoc.filename'}) {
                    478: 	&upload($r);
1.27      albertel  479:     } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) {
                    480: 	&delete_confirmed($r);
1.24      albertel  481:     } elsif ($ENV{'form.action'} eq 'delete') {
1.27      albertel  482: 	&delete($r);
1.30      banghart  483:     } elsif ($ENV{'form.action'} eq 'deletedir' && $ENV{'form.confirmed'}) {
1.31      albertel  484: 	&delete_dir_confirmed($r);
1.30      banghart  485:     } elsif ($ENV{'form.action'} eq 'deletedir'){
1.31      albertel  486: 	&delete_dir($r);
1.27      albertel  487:     } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) {
                    488: 	&rename_confirmed($r);
1.24      albertel  489:     } elsif ($ENV{'form.action'} eq 'rename') {
                    490: 	&rename($r);
1.25      albertel  491:     } elsif ($ENV{'form.createdir'}) {
                    492: 	&createdir($r);
1.24      albertel  493:     } else {
                    494: 	my $current_path='/';
                    495: 	if ($ENV{'form.currentpath'}) {
                    496: 	    $current_path = $ENV{'form.currentpath'};
                    497: 	}
1.43      banghart  498: 	my @dir_list=&Apache::lonnet::dirlist($current_path,
1.27      albertel  499: 					    $ENV{'user.domain'},
                    500: 					    $ENV{'user.name'},$portfolio_root);
1.46      albertel  501: 	if ($dir_list[0] eq 'no_such_dir'){
                    502: 	    # two main reasons for this:
                    503:             #    1) never been here, so directory structure not created
                    504: 	    #    2) back-button navigation after deleting a directory
                    505: 	    if ($current_path eq '/'){
1.43      banghart  506: 	        &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
1.46      albertel  507: 					       $ENV{'user.domain'},'portfolio');
                    508: 	    } else {
                    509:                 # some directory that snuck in get rid of the directory
                    510:                 # from the recent pulldown, just in case
                    511: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
                    512: 						      [$current_path]);
                    513: 		$current_path = '/'; # force it back to the root        
                    514: 	    }
                    515: 	    # now grab the directory list again, for the first time
                    516: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
                    517: 					    $ENV{'user.domain'},
                    518: 					    $ENV{'user.name'},$portfolio_root);
1.43      banghart  519:         }
1.46      albertel  520: 	# need to know if directory is empty so it can be removed if desired
                    521: 	my $is_empty=(@dir_list == 2);
1.48      banghart  522: 	&display_common($r,$current_path,$is_empty,\@dir_list);
1.51      matthew   523: 	if ($ENV{"form.mode"} eq 'selectfile'){
1.50      banghart  524: 	    &select_files($r);
                    525:             &display_file_select($r,$current_path,$is_empty,\@dir_list);
                    526: 	} else {
                    527: 	    &display_directory($r,$current_path,$is_empty,\@dir_list);
                    528: 	}
1.46      albertel  529: 	$r->print("</body>\n</html>\n");
                    530: 	return OK;
1.30      banghart  531:     }
1.2       banghart  532: }
1.1       banghart  533: 1;
                    534: __END__

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