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

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

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