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

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

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