File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.84: download - view: text, annotated - select for diffs
Fri Apr 29 16:51:42 2005 UTC (19 years, 2 months ago) by banghart
Branches: MAIN
CVS tags: HEAD
	Suppress display of versioned files.
	Begin display of reason a file is locked.

    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: 
   24: package Apache::portfolio;
   25: use strict;
   26: use Apache::Constants qw(:common :http);
   27: use Apache::loncommon;
   28: use Apache::lonnet;
   29: use Apache::lontexconvert;
   30: use Apache::lonfeedback;
   31: use Apache::lonlocal;
   32: use Apache::lonnet;
   33: 
   34: # receives a file name and path stub from username/userfiles/portfolio/
   35: # returns an anchor tag consisting encoding filename and currentpath
   36: sub make_anchor {
   37:     my ($filename, $current_path, $current_mode, $field_name, $continue_select) = @_;
   38:     if ($continue_select ne 'true') {$continue_select = 'false'};
   39:     my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'&currentpath='.$current_path.'&mode='.$current_mode.'&continue='.$continue_select.'&fieldname='.$field_name.'">'.$filename.'</a>';
   40:     return $anchor;
   41: }
   42: my $dirptr=16384;
   43: sub display_common {
   44:     my ($r,$current_path,$is_empty,$dir_list)=@_;
   45:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   46:     $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">');
   47:     $r->print('<td bgcolor="#ccddaa" align="center">');
   48:     my $displayOut = '<form method="post" enctype="multipart/form-data">';
   49:     $displayOut .= '<input name="uploaddoc" type="file" />'.
   50:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
   51:         '<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'.
   52:         '<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'.
   53:         '<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'. 
   54:         '<input type="submit" name="storeupl" value="Upload" />'.
   55:         '</form>';
   56:     $r->print($displayOut);
   57:     $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
   58:     $displayOut = '<form method="post">';
   59:     $displayOut .= '<input name="newdir" type="input" />'.
   60:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
   61:         '<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'.
   62:         '<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'.
   63:         '<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'. 
   64:         '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
   65:         '</form>';
   66:     $r->print($displayOut);
   67:     $r->print('</td></tr></table>');
   68:     my @tree = split (/\//,$current_path);
   69:     $r->print('<font size="+2">'.&make_anchor('portfolio','/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"}).'/');
   70:     if (@tree > 1){
   71:         my $newCurrentPath = '';
   72:         for (my $i = 1; $i< @tree; $i++){
   73:             $newCurrentPath .= $tree[$i].'/';
   74:             $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"}).'/');
   75:         }
   76:     }
   77:     $r->print('</font>');
   78:     &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
   79:     $r->print('<br /><form method=post action="/adm/portfolio?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.'">'.
   80: 	      &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
   81: 						    'this.form.submit();'));
   82:     $r->print("</form>");
   83: }
   84: sub display_directory {
   85:     my ($r,$current_path,$is_empty,$dir_list)=@_;
   86:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   87:     my $display_out;
   88:     my $select_mode;
   89:     my $checked_files;
   90:     my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($env{'user.domain'},$env{'user.name'});
   91:     if ($env{"form.mode"} eq 'selectfile'){
   92: 	&select_files($r);
   93: 	$checked_files =&Apache::lonnet::files_in_path($env{'user.name'},$env{'form.currentpath'});
   94: 	$select_mode = 'true';
   95:     } 
   96:     if ($is_empty && ($current_path ne '/')) {
   97:         $display_out = '<form method="post" action="/adm/portfolio">'.
   98:         '<input type="hidden" name="action" value="deletedir" />'.
   99:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
  100:         '<input type="hidden" name="selectfile" value="" />'.
  101:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
  102:         '</form>';
  103:         
  104:         $r->print($display_out);
  105: 	return;
  106:     }
  107:     if ($select_mode eq 'true') {
  108:         $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
  109:             '<tr><th>Select</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
  110:         $r->print('<form method="post" name="checkselect" action="/adm/portfolio">');
  111:     } else {
  112:         $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
  113:             '<tr><th colspan="2">Actions</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
  114:         $r->print('<form method="post" action="/adm/portfolio">');
  115:     }
  116:     my $href_location="/uploaded/$env{'user.domain'}/$env{'user.name'}/portfolio$current_path";
  117:     my $href_edit_location="/editupload/$env{'user.domain'}/$env{'user.name'}/portfolio$current_path";
  118:     foreach my $line (sort 
  119: 		      { 
  120: 			  my ($afile)=split('&',$a,2);
  121: 			  my ($bfile)=split('&',$b,2);
  122: 			  return (lc($afile) cmp lc($bfile));
  123: 		      } (@$dir_list)) {
  124:     	#$strip holds directory/file name
  125:     	#$dom 
  126:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
  127:     	$filename =~ s/\s+$//;
  128:     	if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(.*)\.(.*)/)) {
  129:             if ($dirptr&$testdir) {
  130:                 if ($select_mode eq 'true'){
  131:                     $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
  132:                 } else {
  133:                     $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
  134:                 }
  135:                 $r->print('<td>Go to ...</td>');
  136:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'}).'</td>'); 
  137:                 $r->print('</tr>'); 
  138:             } else {
  139:                 $r->print('<tr bgcolor="#CCCCFF">');
  140:                 if ($select_mode eq 'true'){
  141:                     $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"'); 
  142:                     if ($$checked_files{$filename} eq 'selected') {
  143:                         $r->print("CHECKED");
  144:                     }
  145:                     $r->print('></td>');
  146:                 } else {
  147:                     if (exists $locked_files{$current_path.$filename}){
  148:                         $r->print('<td colspan="2"><a href="portfolio?lockinfo='.$current_path.$filename.'">Locked</a></td>');
  149:                     } else {
  150:                         $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
  151:                             <a href="/adm/portfolio?rename='.$filename.'&amp;currentpath='.$current_path.'">Rename</a></td>
  152:                             <td><a href="'.$href_edit_location.$filename.'.meta">Meta</a>
  153:                             </td>');
  154:                     }
  155:                 }
  156:                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
  157:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
  158: 			    $filename.'</a></td>'); 
  159:                 $r->print('<td>'.$size.'</td>');
  160:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
  161:                 $r->print('</tr>'); 
  162:             }
  163:         }
  164:     }
  165:     if ($select_mode eq 'true') {
  166:         $r->print('</table>
  167:             <input type="hidden" name="continue" value="true">
  168:             <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'">
  169:             <input type="hidden" name="mode" value="selectfile">
  170:             <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
  171:             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
  172:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
  173:         </form>');        
  174:     } else {
  175:         $r->print('</table>
  176:         <input type="submit" name="doit" value="Delete Checked Files" />
  177:         <input type="hidden" name="action" value="delete" />
  178:         <input type="hidden" name="currentpath" value="'.$current_path.'" />
  179:         </form>');
  180:     }
  181: }
  182: 
  183: sub open_form {
  184:     my ($r)=@_;
  185:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  186:     $r->print('<form method="post" action="/adm/portfolio">');
  187:     $r->print('<input type="hidden" name="action" value="'.
  188: 	      $env{'form.action'}.'" />');
  189:     $r->print('<input type="hidden" name="confirmed" value="1" />');
  190:     foreach (@files) {
  191:         $r->print('<input type="hidden" name="selectfile" value="'.
  192: 	      $_.'" />');
  193:     }
  194:     $r->print('<input type="hidden" name="currentpath" value="'.
  195: 	      $env{'form.currentpath'}.'" />');
  196: }
  197: 
  198: sub close_form {
  199:     my ($r)=@_;
  200:     $r->print('<p><input type="submit" value="'.&mt('Continue').
  201: 	      '" /></p></form>');
  202:     $r->print('<form action="/adm/portfolio" method="POST">
  203:                <p>
  204:               <input type="hidden" name="currentpath" value="'.
  205: 	      $env{'form.currentpath'}.'" />
  206:                  <input type="submit" value="'.&mt('Cancel').'" />
  207:                </p></form>');
  208: 
  209: }
  210: 
  211: sub display_file {
  212:     my ($path,$filename)=@_;
  213:     my $display_file_text;
  214:     if (!defined($path)) { $path=$env{'form.currentpath'}; }
  215:     if (!defined($filename)) { 
  216:         $filename=$env{'form.selectfile'};
  217:         $display_file_text = '<tt>'.$path.$filename.'</tt>';
  218:     } elsif (ref($filename) eq "ARRAY") {
  219:         foreach (@$filename) {
  220:             $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
  221:         }
  222:     } elsif (ref($filename) eq "SCALAR") {
  223:         $display_file_text = '<tt>'.$path.$filename.'</tt>';        
  224:     }
  225:     return $display_file_text;
  226: }
  227: 
  228: sub done {
  229:     my ($message)=@_;
  230:     unless (defined $message) {
  231:         $message='Done';
  232:     }
  233:     return ('<h3><a href="/adm/portfolio?currentpath='.
  234: 	    $env{'form.currentpath'}.
  235: 	    '&fieldname='.$env{'form.fieldname'}.
  236: 	    '&mode='.$env{'form.mode'}.
  237: 	    '">'.&mt($message).'</a></h3>');
  238: }
  239: 
  240: sub delete {
  241:     my ($r)=@_;
  242:     my @check;
  243:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
  244:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  245: 
  246:     if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') {
  247:         $r->print ("The file is locked and cannot be deleted.<br />");
  248:         $r->print(&done('Back'));
  249:     } else {
  250:         if (scalar(@files)) {
  251:             &open_form($r);
  252:             $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
  253:             &close_form($r);
  254:         } else {
  255:             $r->print("No file was checked to delete.<br />");
  256:             $r->print(&done());
  257:         }
  258:     }
  259: } 
  260: 
  261: sub delete_confirmed {
  262:     my ($r)=@_;
  263:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  264:     my $result;
  265:     foreach my $delete_file (@files) {
  266:         $result=&Apache::lonnet::removeuserfile($env{'user.name'},
  267: 					       $env{'user.domain'},'portfolio'.
  268: 					       $env{'form.currentpath'}.
  269: 					       $delete_file);
  270:         if ($result ne 'ok') {
  271: 	$r->print('<font color="red"> An error occured ('.$result.
  272: 		  ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
  273:         }
  274:     }
  275:     $r->print(&done());
  276: }
  277: 
  278: sub delete_dir {
  279:     my ($r)=@_;
  280:     &open_form($r);
  281:     $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
  282:     &close_form($r);
  283: } 
  284: 
  285: sub delete_dir_confirmed {
  286:     my ($r)=@_;
  287:     my $directory_name = $env{'form.currentpath'};
  288:     $directory_name =~ s|/$||; # remove any trailing slash
  289:     my $result=&Apache::lonnet::removeuserfile($env{'user.name'},
  290: 					       $env{'user.domain'},'portfolio'.
  291: 					       $directory_name);
  292: 					       
  293:     if ($result ne 'ok') {
  294: 	$r->print('<font color="red"> An error occured (dir) ('.$result.
  295: 		  ') while trying to delete '.$directory_name.'</font><br />');
  296:     } else {
  297:         # now remove from recent
  298: #        $r->print('<br /> removing '.$directory_name.'<br /');
  299:         &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
  300:         my @dirs = split m!/!, $directory_name;
  301:         
  302: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
  303:         $directory_name='/';
  304:         for (my $i=1; $i < (@dirs - 1); $i ++){
  305:             $directory_name .= $dirs[$i].'/';
  306:         }
  307:         $env{'form.currentpath'} = $directory_name;
  308:     }
  309:     $r->print(&done());
  310: }
  311: 
  312: sub rename {
  313:     my ($r)=@_;
  314:     my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
  315:     if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'}) eq 'true') {
  316:         $r->print ("The file is locked and cannot be renamed.<br />");
  317:         $r->print(&done());
  318:     } else {
  319:         &open_form($r);
  320:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
  321:                    <input name="filenewname" type="input" size="50" />?</p>');
  322:         &close_form($r);
  323:     }
  324: }
  325: 
  326: sub rename_confirmed {
  327:     my ($r)=@_;
  328:     my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
  329:     if ($filenewname eq '') {
  330: 	$r->print('<font color="red">'.
  331: 		  &mt("Error: no valid filename was provided to rename to.").
  332: 		  '</font><br />');
  333: 	$r->print(&done());
  334: 	return;
  335:     } 
  336:     my $result=
  337: 	&Apache::lonnet::renameuserfile($env{'user.name'},$env{'user.domain'},
  338:             'portfolio'.$env{'form.currentpath'}.$env{'form.selectfile'},
  339:             'portfolio'.$env{'form.currentpath'}.$filenewname);
  340:     if ($result ne 'ok') {
  341: 	$r->print('<font color="red"> An errror occured ('.$result.
  342: 		  ') while trying to rename '.&display_file().' to '.
  343: 		  &display_file(undef,$filenewname).'</font><br />');
  344:     }
  345:     if ($filenewname ne $env{'form.filenewname'}) {
  346:         $r->print("The new file name was changed from:<br /><strong>".$env{'form.filenewname'}."</strong> to <strong>$filenewname </strong>");
  347:     }
  348:     $r->print(&done());
  349: }
  350: sub select_files {
  351:     my ($r)=@_;
  352:     if ($env{'form.continue'} eq 'true') {
  353:         # here we update the selections for the currentpath
  354:         # eventually, have to handle removing those not checked, but . . . 
  355:         my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
  356:         if (scalar(@items)){
  357:             &Apache::lonnet::logthis("one of the items is $items[0]");
  358:             &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
  359:         }
  360:     } else {
  361:             #empty the file for a fresh start
  362:             &Apache::lonnet::logthis("Clearing saved files");
  363:             &Apache::lonnet::clear_selected_files($env{'user.name'});
  364:     }
  365:     my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
  366:     my $java_files = join ",", @files;
  367:     if ($java_files) {
  368:         $java_files.=',';
  369:     }
  370:     my $javascript =(<<ENDSMP);
  371:         <script language='javascript'>
  372:         function finishSelect() {
  373: ENDSMP
  374:     $javascript .= 'fileList = "'.$java_files.'";';
  375:     $javascript .= (<<ENDSMP);
  376:             for (i=0;i<document.forms.checkselect.length;i++) { 
  377:                 if (document.forms.checkselect[i].checked){
  378:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
  379:                 }
  380:             }
  381:             opener.document.forms.lonhomework.
  382: ENDSMP
  383:     $javascript .= $env{'form.fieldname'};
  384:     $javascript .= (<<ENDSMP);
  385:         .value=fileList;
  386:             self.close();
  387:         }
  388:         </script>
  389: ENDSMP
  390:     $r->print($javascript);
  391:     $r->print("<h1>Select portfolio files</h1>
  392:                 Check as many as you wish in response to the essay problem.<br />");
  393:     $r->print("<strong>Files selected from other directories:</strong><br />");
  394:     foreach (&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'})) {
  395:         $r->print($_."<br />");
  396:     }
  397: }
  398: sub upload {
  399:     my ($r)=@_;
  400:     my $fname=$env{'form.uploaddoc.filename'};
  401:     my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
  402:     my $disk_quota = 20000; # expressed in k
  403:     $fname=&Apache::lonnet::clean_filename($fname);
  404:     my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
  405: 						 $env{'user.name'}).
  406: 						'/userfiles/portfolio';
  407:     # Fixme --- Move the checking for existing file to LOND error return
  408:     my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
  409: 					  $env{'user.domain'},
  410: 					  $env{'user.name'},$portfolio_root);
  411:     my $found_file = 0;
  412:     my $locked_file = 0;
  413:     foreach my $line (@dir_list) {
  414:         my ($file_name)=split(/\&/,$line,2);
  415:         if ($file_name eq $fname){
  416:             $found_file = 1;
  417:             if (&Apache::lonnet::is_locked($env{'form.currentpath'}.$file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') {
  418:                 $locked_file = 1;
  419:             } 
  420:         }
  421:     }
  422:     my $current_disk_usage = &Apache::lonnet::diskusage($env{'user.domain'}, $env{'user.name'},$portfolio_root);
  423:     if ((($current_disk_usage/1000) + $filesize) > $disk_quota){
  424:         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
  425:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
  426:         $r->print(&done('Back'));
  427:     } 
  428:     elsif ($found_file){
  429:         if ($locked_file){
  430:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>portfolio'.$env{'form.currentpath'}.'</strong></font>'.
  431:                   '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
  432:             $r->print(&done('Back'));      
  433:         } else {   
  434:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>portfolio'.$env{'form.currentpath'}.'</strong></font>'.
  435:                   '<br />To upload, rename or delete existing '.$fname.' in portfolio'.$env{'form.currentpath'});
  436:             $r->print(&done('Back'));
  437:         }
  438:     } else {
  439:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
  440: 	        	 'portfolio'.$env{'form.currentpath'});
  441:         if ($result !~ m|^/uploaded/|) {
  442:             $r->print('<font color="red"> An errror occured ('.$result.
  443: 	              ') while trying to upload '.&display_file().'</font><br />');
  444: 	    $r->print(&done('Back'));
  445:         } else {
  446:             $r->print(&done());
  447:         }
  448:     }
  449: }
  450: sub lock_info {
  451:     my ($r) = @_;
  452:     my %current_permissions = &Apache::lonnet::dump('file_permissions',$env{'user.domain'},$env{'user.name'});
  453:     my $file_name = $env{'form.lockinfo'};
  454:     #my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($env{'user.domain'},$env{'user.name'});
  455:     foreach my $key (keys(%current_permissions)) {
  456:         if ($file_name eq $key) {
  457:         $r->print("$key = ");
  458:         foreach my $array_item (@{$current_permissions{$key}}) {
  459:             if (ref($array_item)) {
  460:             $r->print(&Apache::lonnet::gettitle($$array_item[0]).' is the problem<br>');
  461:             $r->print(&Apache::lonnet::coursedescription($$array_item[1]).' is the course<br>');
  462:             # $r->print('the third is '.$$array_item[2].'<br>');
  463:             # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
  464:         }
  465:         }
  466:         }    
  467:     }
  468:     #$r->print("lock info here");
  469:     return 'ok';
  470: }
  471: sub createdir {
  472:     my ($r)=@_;
  473:     my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
  474:     if ($newdir eq '') {
  475:     	$r->print('<font color="red">'.
  476: 	    	  &mt("Error: no directory name was provided.").
  477: 		      '</font><br />');
  478: 	    $r->print(&done());
  479: 	    return;
  480:     } 
  481:     my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
  482: 						 $env{'user.name'}).
  483: 						'/userfiles/portfolio';
  484:     my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
  485: 					  $env{'user.domain'},
  486: 					  $env{'user.name'},$portfolio_root);
  487:     my $found_file = 0;
  488:     foreach my $line (@dir_list) {
  489:         my ($filename)=split(/\&/,$line,2);
  490:         if ($filename eq $newdir){
  491:             $found_file = 1;
  492:         }
  493:     }
  494:     if ($found_file){
  495:     	    $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
  496:     	            ' </strong>a file or directory by that name already exists.</font><br />');
  497:     } else {
  498:         my $result=&Apache::lonnet::mkdiruserfile($env{'user.name'},
  499: 	         $env{'user.domain'},'portfolio'.$env{'form.currentpath'}.$newdir);
  500:         if ($result ne 'ok') {
  501:     	    $r->print('<font color="red"> An errror occured ('.$result.
  502: 	    	      ') while trying to create a new directory '.&display_file().'</font><br />');
  503:         }
  504:     }
  505:     if ($newdir ne $env{'form.newdir'}) {
  506:         $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");  
  507:     }
  508:     $r->print(&done());
  509: }
  510: 
  511: sub handler {
  512:     # this handles file management
  513:     my $r = shift;
  514:     my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
  515: 							 $env{'user.name'}).
  516: 							'/userfiles/portfolio';
  517:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  518:                                             ['selectfile','currentpath','meta','lockinfo',
  519: 					     'currentfile','action','fieldname','mode','rename','continue']);
  520:     &Apache::loncommon::no_cache($r);
  521:     &Apache::loncommon::content_type($r,'text/html');
  522:     $r->send_http_header;
  523:     # Give the LON-CAPA page header
  524:     my $html=&Apache::lonxml::xmlbegin();
  525:     $r->print($html.'<head><title>'.
  526:               &mt('Portfolio Manager').
  527:               "</title></head>\n");
  528:     if ($env{"form.mode"} eq 'selectfile'){
  529:         $r->print(&Apache::loncommon::bodytag('Portfolio Manager',undef,undef,1));
  530:     } else {
  531:         $r->print(&Apache::loncommon::bodytag('Portfolio Manager'));
  532:     }
  533:     $r->rflush();
  534: 	if (($env{'form.storeupl'} eq 'Upload') & (!$env{'form.uploaddoc.filename'})){
  535:    	    $r->print('<font color="red"> No file was selected to upload.'.
  536:    	            'To upload a file, click <strong>Browse...</strong>'.
  537:    	            ', select a file, then click <strong>Upload</strong>,</font>');
  538: 	}
  539:     if ($env{'form.meta'}) {
  540:         &open_form($r);
  541: #        $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
  542:         $r->print('Edit the meta data<br />');
  543:         &close_form($r);
  544:     }
  545:     if ($env{'form.store'}) {
  546:     }
  547: 
  548:     if ($env{'form.uploaddoc.filename'}) {
  549: 	&upload($r);
  550:     } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
  551: 	&delete_confirmed($r);
  552:     } elsif ($env{'form.action'} eq 'delete') {
  553: 	&delete($r);
  554:     } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
  555: 	&delete_dir_confirmed($r);
  556:     } elsif ($env{'form.action'} eq 'deletedir'){
  557: 	&delete_dir($r);
  558:     } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
  559: 	&rename_confirmed($r);
  560:     } elsif ($env{'form.rename'}) {
  561:         $env{'form.selectfile'} = $env{'form.rename'};
  562:         $env{'form.action'} = 'rename';
  563: 	&rename($r);
  564:     } elsif ($env{'form.createdir'}) {
  565: 	&createdir($r);
  566:     } elsif ($env{'form.lockinfo'}) {
  567:         &lock_info($r);
  568:     } else {
  569: 	my $current_path='/';
  570: 	if ($env{'form.currentpath'}) {
  571: 	    $current_path = $env{'form.currentpath'};
  572: 	}
  573: 	my @dir_list=&Apache::lonnet::dirlist($current_path,
  574: 					    $env{'user.domain'},
  575: 					    $env{'user.name'},$portfolio_root);
  576: 	if ($dir_list[0] eq 'no_such_dir'){
  577: 	    # two main reasons for this:
  578:             #    1) never been here, so directory structure not created
  579: 	    #    2) back-button navigation after deleting a directory
  580: 	    if ($current_path eq '/'){
  581: 	        &Apache::lonnet::mkdiruserfile($env{'user.name'},
  582: 					       $env{'user.domain'},'portfolio');
  583: 	    } else {
  584:                 # some directory that snuck in get rid of the directory
  585:                 # from the recent pulldown, just in case
  586: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
  587: 						      [$current_path]);
  588: 		$current_path = '/'; # force it back to the root        
  589: 	    }
  590: 	    # now grab the directory list again, for the first time
  591: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
  592: 					    $env{'user.domain'},
  593: 					    $env{'user.name'},$portfolio_root);
  594:         }
  595: 	# need to know if directory is empty so it can be removed if desired
  596: 	my $is_empty=(@dir_list == 2);
  597: 	&display_common($r,$current_path,$is_empty,\@dir_list);
  598:         &display_directory($r,$current_path,$is_empty,\@dir_list);
  599: 	$r->print("</body>\n</html>\n");
  600: 	return OK;
  601:     }
  602: }
  603: 1;
  604: __END__

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