File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.105: download - view: text, annotated - select for diffs
Tue Jun 20 01:56:17 2006 UTC (17 years, 11 months ago) by banghart
Branches: MAIN
CVS tags: HEAD
	Saving work in progress. Get version info available in directory
	display loop.

    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: use Apache::longroup;
   34: use lib '/home/httpd/lib/perl';
   35: use LONCAPA;
   36: 
   37: # receives a file name and path stub from username/userfiles/portfolio/
   38: # returns an anchor tag consisting encoding filename and currentpath
   39: sub make_anchor {
   40:     my ($url, $filename, $current_path, $current_mode, $field_name,
   41:         $continue_select,$group) = @_;
   42:     if ($continue_select ne 'true') {$continue_select = 'false'};
   43:     my $anchor = '<a href="'.$url.'?selectfile='.$filename.'&currentpath='.$current_path.'&mode='.$current_mode.'&continue='.$continue_select.'&fieldname='.$field_name;
   44:     if (defined($group)) {
   45:         $anchor .= '&group='.$group;
   46:     }
   47:     $anchor .= '">'.$filename.'</a>';
   48:     return $anchor;
   49: }
   50: my $dirptr=16384;
   51: sub display_common {
   52:     my ($r,$url,$current_path,$is_empty,$dir_list,$group)=@_;
   53:     my $groupitem;
   54:     my $namespace = &get_namespace($group);
   55:     my $port_path = &get_port_path($group);
   56:     if (defined($group)) {
   57:         $groupitem = '<input type="hidden" name="group" value="'.$group.'" />';
   58:     } 
   59:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   60:     my %text=&Apache::lonlocal::texthash('upload' => 'Upload',
   61: 					 'upload_label' =>  
   62: 					 'Upload file to current directory:',
   63: 					 'createdir' => 'Create Subdirectory',
   64: 					 'createdir_label' => 
   65: 					 'Create subdirectory in current directory:');
   66:     $r->print(<<"TABLE"); 
   67: <table border="0" cellspacing="2" cellpadding="2">
   68:   <form method="post" enctype="multipart/form-data">
   69:     <tr valign="middle">
   70:       <td bgcolor="#ccddaa" align="right">
   71:         $text{'upload_label'}
   72:       </td>
   73:       <td bgcolor="#ccddaa" align="left">$groupitem
   74:         <input name="uploaddoc" type="file" />
   75: 	<input type="hidden" name="currentpath" value="$current_path" />
   76: 	<input type="hidden" name="action" value="$env{"form.action"}" />
   77: 	<input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
   78: 	<input type="hidden" name="mode" value="$env{"form.mode"}" />
   79: 	<input type="submit" name="storeupl" value="$text{'upload'}" />
   80:       </td>
   81:     </tr>
   82:   </form>
   83:   <form method="post">
   84:     <tr>
   85:       <td bgcolor="#ccddaa" align="right">
   86:         $text{'createdir_label'}
   87:       </td>
   88:       <td bgcolor="#ccddaa" align="left">
   89:         <input name="newdir" type="input" />$groupitem
   90:         <input type="hidden" name="currentpath" value="$current_path" />
   91:         <input type="hidden" name="action" value="$env{"form.action"}" />
   92:         <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
   93:         <input type="hidden" name="mode" value="$env{"form.mode"}" />
   94:         <input type="submit" name="createdir" value="$text{'createdir'}" />
   95:       </td>
   96:     </tr>
   97:   </form>
   98: </table>
   99: TABLE
  100:     my @tree = split (/\//,$current_path);
  101:     $r->print('<font size="+2">'.&make_anchor($url,$port_path,'/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"},$group).'/');
  102:     if (@tree > 1){
  103:         my $newCurrentPath = '';
  104:         for (my $i = 1; $i< @tree; $i++){
  105:             $newCurrentPath .= $tree[$i].'/';
  106:             $r->print(&make_anchor($url,$tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"},$group).'/');
  107:         }
  108:     }
  109:     $r->print('</font>');
  110:     &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
  111:     $r->print('<br /><form method=post action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"});
  112:     if (defined($group)) {
  113:         $r->print('&group='.$group);
  114:     }
  115:     $r->print('">'.
  116: 	      &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
  117: 						    'this.form.submit();'));
  118:     $r->print("</form>");
  119: }
  120: sub display_directory {
  121:     my ($r,$url,$current_path,$is_empty,$dir_list,$group)=@_;
  122:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
  123:     my ($groupitem,$groupecho);
  124:     my $display_out;
  125:     my $select_mode;
  126:     my $checked_files;
  127:     my $port_path = &get_port_path($group);
  128:     my ($uname,$udom) = &get_name_dom($group);
  129:     if (defined($group)) {
  130:        $groupitem = '<input type="hidden" name="group" value="'.$group.'" />'; 
  131:        $groupecho = '&amp;group='.$group;
  132:     }
  133:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
  134:                                                                         $uname);
  135:     my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
  136:                                                   $current_permissions,$group);
  137:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
  138:     my $now = time;
  139:     if ($env{"form.mode"} eq 'selectfile'){
  140: 	&select_files($r);
  141: 	$checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
  142: 	$select_mode = 'true';
  143:     } 
  144:     if ($is_empty && ($current_path ne '/')) {
  145:         $display_out = '<form method="post" action="'.$url.'">'.$groupitem.
  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.'" />'.
  150:         '</form>';
  151:         
  152:         $r->print($display_out);
  153: 	return;
  154:     }
  155:     if ($select_mode eq 'true') {
  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:         $r->print('<form method="post" name="checkselect" action="'.$url.'">');
  159:     } else {
  160:         $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
  161:             '<tr><th colspan="2">Actions</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th><th>Current Access Status</th></tr>');
  162:         $r->print('<form method="post" action="'.$url.'">');
  163:     }
  164:     if (defined($group)) {
  165:         $r->print("\n".$groupitem."\n");
  166:     }
  167:     my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
  168:     my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
  169:     my @dir_lines;
  170:     my %versioned;
  171:     foreach my $line (sort 
  172: 		      { 
  173: 			  my ($afile)=split('&',$a,2);
  174: 			  my ($bfile)=split('&',$b,2);
  175: 			  return (lc($afile) cmp lc($bfile));
  176: 		      } (@$dir_list)) {
  177:     	#$strip holds directory/file name
  178:     	#$dom 
  179:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
  180:     	$filename =~ s/\s+$//;
  181:     	my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
  182:     	if ($version) {
  183:     	    $versioned{$fname} .= $version.",";
  184:     	}
  185:         push @dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs];
  186:     }
  187:     foreach my $line(@dir_lines) {
  188:         my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$line;
  189:         my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
  190:     	if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
  191:             if ($dirptr&$testdir) {
  192:                 if ($select_mode eq 'true'){
  193:                     $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
  194:                 } else {
  195:                     $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
  196:                 }
  197:                 $r->print('<td>Go to ...</td>');
  198:                 $r->print('<td>'.&make_anchor($url,$filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'},$group).'</td>'); 
  199:                 $r->print('</tr>'); 
  200:             } else {
  201:                 $r->print('<tr bgcolor="#CCCCFF">');
  202:                 my $version_flag;
  203:                 if (exists($versioned{$fname})) {
  204:                    $version_flag = "*";
  205:                 } else {
  206:                     $version_flag = "";
  207:                 }
  208:                my $fullpath = $current_path.$filename;
  209:                 $fullpath = &prepend_group($fullpath,$group);
  210:                 if ($select_mode eq 'true'){
  211:                     $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"');
  212:                     if ($$checked_files{$filename} eq 'selected') {
  213:                         $r->print("CHECKED");
  214:                     }
  215:                     $r->print('></td>');
  216:                 } else {
  217:                     if (exists $locked_files{$fullpath}) {
  218:                         $r->print('<td colspan="2"><a href="'.$url.'?lockinfo='.$current_path.$filename.$groupecho.'">Locked</a></td>');
  219:                     } else {
  220: 			my $cat='<img alt="'.&mt('Catalog Information').
  221: 			    '" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />';
  222:                         $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
  223:                             <a href="'.$url.'?rename='.$filename.'&amp;currentpath='.$current_path.$groupecho.'">Rename</a></td>
  224:                             <td><a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>
  225:                             </td>');
  226:                     }
  227:                 }
  228:                 my $curr_access;
  229:                 my $pub_access = 0;
  230:                 foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
  231:                     my ($scope,$end,$start) = ($key =~ /^[^:]+:([a-z]+)_(\d*)_?(\d*)$/);
  232:                     if (($now > $start) && (!$end || $end > $now)) {
  233:                         if ($scope eq 'public')  {
  234:                             $pub_access = 1;
  235:                         }
  236:                     }
  237:                 }
  238:                 if (!$pub_access) {
  239:                     $curr_access = 'Private'
  240:                 } else {
  241:                     $curr_access = 'Public';
  242:                 }
  243:                 $r->print('<td><img src="'.&Apache::loncommon::icon($filename).'"></td>');
  244:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
  245: 			    $filename.'</a></td>'); 
  246:                 $r->print('<td>'.$size.'</td>');
  247:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
  248:                 $r->print('<td><nobr>'.&mt($curr_access).'&nbsp;&nbsp;&nbsp;'.
  249:                           '<a href="'.$url.'?access='.$filename.
  250:                           '&amp;currentpath='.$current_path.$groupecho.
  251:                           '">'.&mt('View/Change').'</a></nobr></td>');
  252:                 $r->print('</tr>'); 
  253:             }
  254:         }
  255:     }
  256:     if ($select_mode eq 'true') {
  257:         $r->print('</table>
  258:             <input type="hidden" name="continue" value="true">
  259:             <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'">
  260:             <input type="hidden" name="mode" value="selectfile">
  261:             <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
  262:             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
  263:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
  264:         </form>');        
  265:     } else {
  266:         $r->print('</table>
  267:         <input type="submit" name="doit" value="Delete Checked Files" />
  268:         <input type="hidden" name="action" value="delete" />
  269:         <input type="hidden" name="currentpath" value="'.$current_path.'" />
  270:         </form>');
  271:     }
  272: }
  273: 
  274: sub open_form {
  275:     my ($r,$url)=@_;
  276:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  277:     $r->print('<form name="portform" method="post" action="'.$url.'">');
  278:     $r->print('<input type="hidden" name="action" value="'.
  279: 	      $env{'form.action'}.'" />');
  280:     $r->print('<input type="hidden" name="confirmed" value="1" />');
  281:     foreach (@files) {
  282:         $r->print('<input type="hidden" name="selectfile" value="'.
  283: 	      $_.'" />');
  284:     }
  285:     $r->print('<input type="hidden" name="currentpath" value="'.
  286: 	      $env{'form.currentpath'}.'" />');
  287: }
  288: 
  289: sub close_form {
  290:     my ($r,$url,$group)=@_;
  291:     $r->print('<p><input type="submit" value="'.&mt('Continue').'" />');
  292:     if (defined($group)) {
  293:        $r->print("\n".'<input type="hidden" name="group" value="'.
  294:               $group.'" />');
  295:     }
  296:     $r->print('</p></form>');
  297:     $r->print('<form action="'.$url.'" method="POST">
  298:                <p>
  299:               <input type="hidden" name="currentpath" value="'.
  300: 	      $env{'form.currentpath'}.'" />');
  301:     if (defined($group)) {
  302:        $r->print("\n".'<input type="hidden" name="group" value="'.
  303:               $group.'" />');
  304:     }
  305:     $r->print("\n".'   <input type="submit" value="'.&mt('Cancel').'" />
  306:                </p></form>'); 
  307: }
  308: 
  309: sub display_file {
  310:     my ($path,$filename)=@_;
  311:     my $display_file_text;
  312:     if (!defined($path)) { $path=$env{'form.currentpath'}; }
  313:     if (!defined($filename)) { 
  314:         $filename=$env{'form.selectfile'};
  315:         $display_file_text = '<tt>'.$path.$filename.'</tt>';
  316:     } elsif (ref($filename) eq "ARRAY") {
  317:         foreach (@$filename) {
  318:             $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
  319:         }
  320:     } elsif (ref($filename) eq "SCALAR") {
  321:         $display_file_text = '<tt>'.$path.$filename.'</tt>';        
  322:     }
  323:     return $display_file_text;
  324: }
  325: 
  326: sub done {
  327:     my ($message,$url,$group)=@_;
  328:     unless (defined $message) {
  329:         $message='Done';
  330:     }
  331:     my $result = '<h3><a href="'.$url.'?currentpath='.
  332: 	         $env{'form.currentpath'}.
  333: 	         '&fieldname='.$env{'form.fieldname'}.
  334: 	         '&mode='.$env{'form.mode'};
  335:     if (defined($group)) {
  336:         $result .= '&group='.$group;
  337:     }
  338:     $result .= '">'.&mt($message).'</a></h3>';
  339:     return $result;
  340: }
  341: 
  342: sub delete {
  343:     my ($r,$url,$group)=@_;
  344:     my @check;
  345:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
  346:     $file_name = &prepend_group($file_name,$group);
  347:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  348:     my ($uname,$udom) = &get_name_dom($group);
  349:     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
  350:         $r->print ("The file is locked and cannot be deleted.<br />");
  351:         $r->print(&done('Back',$url,$group));
  352:     } else {
  353:         if (scalar(@files)) {
  354:             &open_form($r,$url);
  355:             $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
  356:             &close_form($r,$url,$group);
  357:         } else {
  358:             $r->print("No file was checked to delete.<br />");
  359:             $r->print(&done(undef,$url,$group));
  360:         }
  361:     }
  362: } 
  363: 
  364: sub delete_confirmed {
  365:     my ($r,$url,$group)=@_;
  366:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  367:     my $result;
  368:     my ($uname,$udom) = &get_name_dom($group);
  369:     my $port_path = &get_port_path($group);
  370:     foreach my $delete_file (@files) {
  371:         $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
  372: 					       $env{'form.currentpath'}.
  373: 					       $delete_file);
  374:         if ($result ne 'ok') {
  375: 	$r->print('<font color="red"> An error occured ('.$result.
  376: 		  ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
  377:         }
  378:     }
  379:     $r->print(&done(undef,$url,$group));
  380: }
  381: 
  382: sub delete_dir {
  383:     my ($r,$url,$group)=@_;
  384:     &open_form($r,$url);
  385:     $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
  386:     &close_form($r,$url,$group);
  387: } 
  388: 
  389: sub delete_dir_confirmed {
  390:     my ($r,$url,$group)=@_;
  391:     my $directory_name = $env{'form.currentpath'};
  392:     $directory_name =~ s|/$||; # remove any trailing slash
  393:     my ($uname,$udom) = &get_name_dom($group);
  394:     my $namespace = &get_namespace($group);
  395:     my $port_path = &get_port_path($group);
  396:     my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
  397: 					       $directory_name);
  398: 					       
  399:     if ($result ne 'ok') {
  400: 	$r->print('<font color="red"> An error occured (dir) ('.$result.
  401: 		  ') while trying to delete '.$directory_name.'</font><br />');
  402:     } else {
  403:         # now remove from recent
  404: #        $r->print('<br /> removing '.$directory_name.'<br /');
  405:         &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
  406:         my @dirs = split m!/!, $directory_name;
  407:         
  408: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
  409:         $directory_name='/';
  410:         for (my $i=1; $i < (@dirs - 1); $i ++){
  411:             $directory_name .= $dirs[$i].'/';
  412:         }
  413:         $env{'form.currentpath'} = $directory_name;
  414:     }
  415:     $r->print(&done(undef,$url,$group));
  416: }
  417: 
  418: sub rename {
  419:     my ($r,$url,$group)=@_;
  420:     my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
  421:     my ($uname,$udom) = &get_name_dom($group);
  422:     $file_name = &prepend_group($file_name,$group);
  423:     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
  424:         $r->print ("The file is locked and cannot be renamed.<br />");
  425:         $r->print(&done(undef,$url,$group));
  426:     } else {
  427:         &open_form($r,$url);
  428:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
  429:                    <input name="filenewname" type="input" size="50" />?</p>');
  430:         &close_form($r,$url,$group);
  431:     }
  432: }
  433: 
  434: sub rename_confirmed {
  435:     my ($r,$url,$group)=@_;
  436:     my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
  437:     my ($uname,$udom) = &get_name_dom($group);
  438:     my $port_path = &get_port_path($group);
  439:     if ($filenewname eq '') {
  440: 	$r->print('<font color="red">'.
  441: 		  &mt("Error: no valid filename was provided to rename to.").
  442: 		  '</font><br />');
  443: 	$r->print(&done(undef,$url,$group));
  444: 	return;
  445:     } 
  446:     my $result=
  447: 	&Apache::lonnet::renameuserfile($uname,$udom,
  448:             $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
  449:             $port_path.$env{'form.currentpath'}.$filenewname);
  450:     if ($result ne 'ok') {
  451: 	$r->print('<font color="red"> An errror occured ('.$result.
  452: 		  ') while trying to rename '.&display_file().' to '.
  453: 		  &display_file(undef,$filenewname).'</font><br />');
  454:     }
  455:     if ($filenewname ne $env{'form.filenewname'}) {
  456:         $r->print("The new file name was changed from:<br /><strong>".$env{'form.filenewname'}."</strong> to <strong>$filenewname </strong>");
  457:     }
  458:     $r->print(&done(undef,$url,$group));
  459: }
  460: 
  461: sub display_access {
  462:     my ($r,$url,$group) = @_;
  463:     my ($uname,$udom) = &get_name_dom($group);
  464:     my $file_name = $env{'form.currentpath'}.$env{'form.access'};
  465:     $file_name = &prepend_group($file_name,$group);
  466:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
  467:                                                                         $uname);
  468:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
  469:     &open_form($r,$url);
  470:     $r->print('<h3>'.&mt('Allowing others to retrieve portfolio file: [_1]',$env{'form.currentpath'}.$env{'form.access'}).'</h3>'."\n");
  471:     $r->print(&mt('Access to this file by others can be set to be one the following types: public.').'<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.').'</li></ul><br />');
  472:     &access_setting_table($r,$access_controls{$file_name});
  473:     &close_form($r,$url,$group);
  474: }
  475: 
  476: sub update_access {
  477:     my ($r,$url,$group) = @_;
  478:     my $totalprocessed = 0;
  479:     my %processing;
  480:     my %title  = (
  481:                          'activate' => 'New controls added',
  482:                          'delete'   => 'Existing controls deleted',
  483:                          'update'   => 'Existing controls modified',
  484:                      );
  485:     my $changes;   
  486:     foreach my $chg (sort(keys(%title))) {     
  487:         @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
  488:         $totalprocessed += @{$processing{$chg}};
  489:         foreach my $num (@{$processing{$chg}}) {
  490:             my $scope = $env{'form.scope_'.$num};
  491:             my ($start,$end) = &get_dates_from_form($num);
  492:             my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
  493:             if ($chg eq 'delete') {
  494:                 $$changes{$chg}{$newkey} = 1;
  495:             } else {
  496:                 $$changes{$chg}{$newkey} = 
  497:                                  &build_access_record($num,$scope,$start,$end);
  498:             }
  499:         }
  500:     }
  501:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
  502:     $r->print('<h3>'.&mt('Allowing others to retrieve portfolio file: [_1]',$file_name).'</h3>'."\n");
  503:     $file_name = &prepend_group($file_name,$group);
  504:     my ($uname,$udom) = &get_name_dom($group);
  505:     my ($errors,$outcome,$deloutcome,$new_values,$translation);
  506:     if ($totalprocessed) {
  507:         ($outcome,$deloutcome,$new_values,$translation) =
  508:         &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,$uname);
  509:     }
  510:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,                                                                    $uname);
  511:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
  512:     if ($totalprocessed) {
  513:         if ($outcome eq 'ok') {
  514:             my $updated_controls = $access_controls{$file_name};
  515:             my ($showstart,$showend);
  516:             $r->print(&Apache::loncommon::start_data_table());
  517:             $r->print(&Apache::loncommon::start_data_table_row());
  518:             $r->print('<th>'.&mt('Type of change').'</th><th>'.&mt('Access control').'</th><th>'.&mt('Start date').'</th><th>'.&mt('End date').'</th>');
  519:             $r->print(&Apache::loncommon::end_data_table_row());
  520:             foreach my $chg (sort(keys(%processing))) {
  521:                 if (@{$processing{$chg}} > 0) {
  522:                     if ($chg eq 'delete') {
  523:                         if (!($deloutcome eq 'ok')) {
  524:                             $errors .= &mt('A problem occurred deleting access controls: [_1]',$deloutcome);
  525:                             next;
  526:                         }
  527:                     }
  528:                     my $numchgs = @{$processing{$chg}};
  529:                     $r->print(&Apache::loncommon::start_data_table_row());
  530:                     $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).'.</td>');
  531:                     my $count = 0;
  532:                     foreach my $key (sort(keys(%{$$changes{$chg}}))) {
  533:                         if ($count) {
  534:                             $r->print(&Apache::loncommon::start_data_table_row());
  535:                         }
  536:                         my ($num,$scope,$end,$start) = 
  537:                                    ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
  538:                         my $newkey = $key;
  539:                         if ($chg eq 'activate') {
  540:                             $newkey =~ s/^(\d+)/$$translation{$1}/;
  541:                         }
  542:                         my %content = &Apache::lonnet::parse_access_controls(
  543:                                                      $$updated_controls{$newkey});
  544:                         if ($chg eq 'delete') {
  545:                             $showstart = &mt('Deleted');
  546:                             $showend = $showstart;
  547:                         } else {
  548:                             $showstart = localtime($start);
  549:                             if ($end == 0) {
  550:                                 $showend = &mt('No end date');
  551:                             } else {
  552:                                 $showend = localtime($end);
  553:                             }
  554:                         }
  555:                         $r->print('<td>'.&mt($scope).'</td><td>'.$showstart.
  556:                                   '</td><td>'. $showend.'</td>');
  557:                         $r->print(&Apache::loncommon::end_data_table_row());
  558:                         $count ++;
  559:                     }
  560:                 }
  561:             }
  562:             $r->print(&Apache::loncommon::end_data_table());
  563:         } else {
  564:             if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
  565:                 $errors .= &mt('A problem occurred storing access control settings: [_1]',$outcome);
  566:             }
  567:         }
  568:         if ($errors) { 
  569:             $r->print($errors);
  570:         }
  571:     }
  572:     $r->print('<br /><a href="'.$url.'?access='.$env{'form.selectfile'}.'&currentpath='.$env{'form.currentpath'}.'">'.&mt('Display all access settings for this file').'</a>');
  573:     return;
  574: }
  575: 
  576: sub build_access_record {
  577:     my ($num,$scope,$start,$end) = @_;
  578:     my $record = '<scope type="'.$scope.'"><start>'.$start.'</start><end>'.$end.
  579:                  '</end></scope>';
  580:     return $record;
  581: }
  582: 
  583: sub get_dates_from_form {
  584:     my ($id) = @_;
  585:     my $startdate;
  586:     my $enddate;
  587:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
  588:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
  589:     if ( exists ($env{'form.noend_'.$id}) ) {
  590:         $enddate = 0;
  591:     }
  592:     return ($startdate,$enddate);
  593: }
  594: 
  595: sub access_setting_table {
  596:     my ($r,$access_controls) = @_;
  597:     my ($public,$publictext);
  598:     $publictext = '<b>'.&mt('Off').'</b>';
  599:     my ($guest,$guesttext);
  600:     $guesttext = '<b>'.&mt('Off').'</b>';
  601:     my @courses = ();
  602:     my @groups = ();
  603:     my @domains = ();
  604:     my @users = ();
  605:     my $now = time;
  606:     my $then = $now + (60*60*24*180); # six months approx.
  607:     foreach my $key (sort(keys(%{$access_controls}))) {
  608:         my ($scope) = ($key =~ /^[^:]+:([a-z]+)_\d*_?\d*$/);
  609:         if ($scope eq 'public') {
  610:             $public = $key;
  611:             $publictext = '<b>'.&mt('On').'</b>';
  612:         }
  613:     }
  614:     $r->print(&Apache::loncommon::start_data_table());
  615:     $r->print(&Apache::loncommon::start_data_table_row());
  616:     $r->print('<th>'.&mt('Access Type').'</th><th colspan="3">'.
  617:               &mt('Settings').'</th>'."\n");
  618:     $r->print(&Apache::loncommon::end_data_table_row());
  619:     $r->print(&Apache::loncommon::start_data_table_row());
  620:     $r->print('<td><b>Public</b><br />'.$publictext.'</td><td colspan="3">');
  621:     $r->print(&Apache::loncommon::start_data_table());
  622:     $r->print(&Apache::loncommon::start_data_table_row());
  623:     my ($pub_startdate,$pub_enddate,$pub_action,$pub_noend);
  624:     if ($public) {
  625:         my ($num,$end,$start) = ($public =~ /^([^:]+):[a-z]+_(\d*)_?(\d*)$/);
  626:         if ($end == 0) {
  627:             $pub_noend = 'checked="checked"';
  628:         }
  629:         $pub_action = '<td><input type="checkbox" name="delete" value="'.$num.
  630:                       '" />'.&mt('Delete').'<br /><input type="checkbox" '.
  631:                       'name="update" value="'.$num.'" />'.&mt('Update').
  632:                       '<input type="hidden" name="scope_'.$num.'"'.
  633:                       ' value="public" /></td>';
  634:         $pub_startdate = &Apache::lonhtmlcommon::date_setter('portform',
  635:                           'startdate_'.$num,$start,undef,undef,undef,1,undef,
  636:                           undef,undef,1);
  637:         $pub_enddate = &Apache::lonhtmlcommon::date_setter('portform',
  638:                           'enddate_'.$num,$end,undef,undef,undef,1,undef,
  639:                           undef,undef,1).
  640:                        '&nbsp;&nbsp;<nobr><input type="checkbox" name="noend_'.
  641:                        $num.'" '.$pub_noend.' />'.&mt('No end date').'</nobr>';
  642:     } else {
  643:         $pub_action = '<input type="checkbox" name="activate" value="0" />'.
  644:                       &mt('Activate').
  645:                       '<input type="hidden" name="scope_0" value="public" />';
  646:         $pub_startdate = &Apache::lonhtmlcommon::date_setter('portform',
  647:                           'startdate_0',$now,undef,undef,undef,1,undef,
  648:                           undef,undef,1);
  649:         $pub_enddate = &Apache::lonhtmlcommon::date_setter('portform',
  650:                           'enddate_0',$then,,undef,undef,undef,1,undef,
  651:                           undef,undef,1).
  652:                        '&nbsp;&nbsp<nobr><input type="checkbox" '.
  653:                        'name="noend_0" />'.&mt('No end date').
  654:                        '</nobr>';
  655: 
  656:     }
  657:     $r->print('<td>'.$pub_action.'</td><td>'.&mt('Start: ').$pub_startdate.
  658:               '<br />'.&mt('End: ').$pub_enddate.'</td>');
  659:     $r->print(&Apache::loncommon::end_data_table_row());
  660:     $r->print(&Apache::loncommon::end_data_table());
  661:     $r->print('</td>');
  662:     $r->print(&Apache::loncommon::end_data_table_row());
  663:     $r->print(&Apache::loncommon::end_data_table());
  664: }
  665: 
  666: sub select_files {
  667:     my ($r,$group) = @_;
  668:     if ($env{'form.continue'} eq 'true') {
  669:         # here we update the selections for the currentpath
  670:         # eventually, have to handle removing those not checked, but . . . 
  671:         my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
  672:         if (scalar(@items)){
  673:              &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
  674:         }
  675:     } else {
  676:             #empty the file for a fresh start
  677:             &Apache::lonnet::clear_selected_files($env{'user.name'});
  678:     }
  679:     my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
  680:     my $java_files = join ",", @files;
  681:     if ($java_files) {
  682:         $java_files.=',';
  683:     }
  684:     my $javascript =(<<ENDSMP);
  685:         <script language='javascript'>
  686:         function finishSelect() {
  687: ENDSMP
  688:     $javascript .= 'fileList = "'.$java_files.'";';
  689:     $javascript .= (<<ENDSMP);
  690:             for (i=0;i<document.forms.checkselect.length;i++) { 
  691:                 if (document.forms.checkselect[i].checked){
  692:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
  693:                 }
  694:             }
  695:             opener.document.forms.lonhomework.
  696: ENDSMP
  697:     $javascript .= $env{'form.fieldname'};
  698:     $javascript .= (<<ENDSMP);
  699:         .value=fileList;
  700:             self.close();
  701:         }
  702:         </script>
  703: ENDSMP
  704:     $r->print($javascript);
  705:     $r->print("<h1>Select portfolio files</h1>
  706:                 Check as many as you wish in response to the problem.<br />");
  707:     my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
  708:     if (@otherfiles) {
  709: 	$r->print("<strong>Files selected from other directories:</strong><br />");
  710: 	foreach my $file (@otherfiles) {
  711: 	    $r->print($file."<br />");
  712: 	}
  713:     }
  714: }
  715: sub upload {
  716:     my ($r,$url,$group)=@_;
  717:     my $fname=$env{'form.uploaddoc.filename'};
  718:     my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
  719:     my $disk_quota = 20000; # expressed in k
  720:     $fname=&Apache::lonnet::clean_filename($fname);
  721: 
  722:     my $portfolio_root=&get_portfolio_root($group);
  723:     my ($uname,$udom) = &get_name_dom($group);
  724:     my $port_path = &get_port_path($group);
  725:     # Fixme --- Move the checking for existing file to LOND error return
  726:     my @dir_list=&get_dir_list($portfolio_root,$group);
  727:     my $found_file = 0;
  728:     my $locked_file = 0;
  729:     foreach my $line (@dir_list) {
  730:         my ($file_name)=split(/\&/,$line,2);
  731:         if ($file_name eq $fname){
  732:             $file_name = $env{'form.currentpath'}.$file_name;
  733:             $file_name = &prepend_group($file_name,$group);
  734:             $found_file = 1;
  735:             if (defined($group)) {
  736:                 $file_name = $group.'/'.$file_name;
  737:             }
  738:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
  739:                 $locked_file = 1;
  740:             } 
  741:         }
  742:     }
  743:     my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
  744:     if (($current_disk_usage + $filesize) > $disk_quota){
  745:         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.'.
  746:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
  747:         $r->print(&done('Back',$url,$group));
  748:     } 
  749:     elsif ($found_file){
  750:         if ($locked_file){
  751:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></font>'.
  752:                   '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
  753:             $r->print(&done('Back',$url,$group));      
  754:         } else {   
  755:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></font>'.
  756:                   '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
  757:             $r->print(&done('Back',$url,$group));
  758:         }
  759:     } else {
  760:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
  761: 	        	 $port_path.$env{'form.currentpath'});
  762:         if ($result !~ m|^/uploaded/|) {
  763:             $r->print('<font color="red"> An errror occured ('.$result.
  764: 	              ') while trying to upload '.&display_file().'</font><br />');
  765: 	    $r->print(&done('Back',$url,$group));
  766:         } else {
  767:             $r->print(&done(undef,$url,$group));
  768:         }
  769:     }
  770: }
  771: sub lock_info {
  772:     my ($r,$url,$group) = @_;
  773:     my ($uname,$udom) = &get_name_dom($group);
  774:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
  775:                                                                        $uname);
  776:     my $file_name = $env{'form.lockinfo'};
  777:     $file_name = &prepend_group($file_name,$group);
  778:     if (defined($file_name) && defined($$current_permissions{$file_name})) {
  779:         foreach my $array_item (@{$$current_permissions{$file_name}}) {
  780:             if (ref($array_item) eq 'ARRAY') {
  781:                 my $filetext;
  782:                 if (defined($group)) {
  783:                     $filetext = '<strong>'.$env{'form.lockinfo'}.
  784:                                     '</strong> (group: '.$group.')'; 
  785:                 } else {
  786:                     $filetext = '<strong>'.$file_name.'</strong>';
  787:                 } 
  788:                 $r->print(&mt('[_1] was submitted in response to problem: ',
  789:                               $filetext).
  790:                           '<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
  791:                           '</strong><br />');
  792:                 my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
  793:                 $r->print(&mt('In the course: <strong>[_1]</strong><br />',
  794:                               $course_description{'description'}));
  795:                 # $r->print('the third is '.$$array_item[2].'<br>');
  796:                 # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
  797:             }
  798:         }
  799:     }
  800:     $r->print(&done('Back',$url,$group));
  801:     return 'ok';
  802: }
  803: sub createdir {
  804:     my ($r,$url,$group)=@_;
  805:     my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
  806:     if ($newdir eq '') {
  807:     	$r->print('<font color="red">'.
  808: 	    	  &mt("Error: no directory name was provided.").
  809: 		      '</font><br />');
  810: 	    $r->print(&done(undef,$url,$group));
  811: 	    return;
  812:     }
  813:     my $portfolio_root = &get_portfolio_root($group); 
  814:     my @dir_list=&get_dir_list($portfolio_root,$group);
  815:     my $found_file = 0;
  816:     foreach my $line (@dir_list) {
  817:         my ($filename)=split(/\&/,$line,2);
  818:         if ($filename eq $newdir){
  819:             $found_file = 1;
  820:         }
  821:     }
  822:     if ($found_file){
  823:     	    $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
  824:     	            ' </strong>a file or directory by that name already exists.</font><br />');
  825:     } else {
  826:         my ($uname,$udom) = &get_name_dom($group);
  827:         my $port_path = &get_port_path($group);
  828:         my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
  829: 	         $port_path.$env{'form.currentpath'}.$newdir);
  830:         if ($result ne 'ok') {
  831:     	    $r->print('<font color="red"> An errror occured ('.$result.
  832: 	    	      ') while trying to create a new directory '.&display_file().'</font><br />');
  833:         }
  834:     }
  835:     if ($newdir ne $env{'form.newdir'}) {
  836:         $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");  
  837:     }
  838:     $r->print(&done(undef,$url,$group));
  839: }
  840: 
  841: sub get_portfolio_root {
  842:     my ($group) = @_;
  843:     my ($portfolio_root,$udom,$uname,$path);
  844:     ($uname,$udom) = &get_name_dom($group);
  845:     if (defined($group)) {
  846:         $path = '/userfiles/groups/'.$group.'/portfolio';
  847:     } else {
  848:         $path = '/userfiles/portfolio';
  849:     }
  850:     return (&Apache::loncommon::propath($udom,$uname).$path);
  851: }
  852: 
  853: sub get_dir_list {
  854:     my ($portfolio_root,$group) = @_;
  855:     my ($uname,$udom) = &get_name_dom($group);
  856:     return &Apache::lonnet::dirlist($env{'form.currentpath'},
  857:                                           $udom,$uname,$portfolio_root);
  858: }
  859: 
  860: sub get_name_dom {
  861:     my ($group) = @_;
  862:     my ($uname,$udom);
  863:     if (defined($group)) {
  864:         $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  865:         $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
  866:     } else {
  867:         $udom = $env{'user.domain'};
  868:         $uname = $env{'user.name'};
  869:     }
  870:     return ($uname,$udom);
  871: }
  872: 
  873: sub prepend_group {
  874:     my ($filename,$group) = @_;
  875:     if (defined($group)) {
  876:         $filename = $group.'/'.$filename;
  877:     }
  878:     return $filename;
  879: }
  880: 
  881: sub get_namespace {
  882:     my ($group) = @_;
  883:     my $namespace = 'portfolio';
  884:     if (defined($group)) {
  885:         my ($uname,$udom) = &get_name_dom($group);
  886:         $namespace .= '_'.$udom.'_'.$uname.'_'.$group;
  887:     }
  888:     return $namespace;
  889: }
  890: 
  891: sub get_port_path {
  892:     my ($group) = @_;
  893:     my $port_path;
  894:     if (defined($group)) {
  895:        $port_path = "groups/$group/portfolio";
  896:     } else {
  897:        $port_path = 'portfolio';
  898:     }
  899:     return $port_path;
  900: }
  901: 
  902: sub handler {
  903:     # this handles file management
  904:     my $r = shift;
  905:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  906:          ['selectfile','currentpath','meta','lockinfo','currentfile',
  907: 	  'action','fieldname','mode','rename','continue','group','access']);
  908:     my ($uname,$udom,$portfolio_root,$url,$group,$caller,$title);
  909:     if ($r->uri =~ m|^(/adm/)([^/]+)|) {
  910:         $url = $1.$2;
  911:         $caller = $2;
  912:     }
  913:     if ($caller eq 'coursegrp_portfolio') {
  914:     #  Needs to be in a course
  915:         if (! ($env{'request.course.fn'})) {
  916:         # Not in a course
  917:             $env{'user.error.msg'}=
  918:      "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
  919:             return HTTP_NOT_ACCEPTABLE;
  920:         }
  921:         my $earlyout = 0;
  922:         my $view_permission = &Apache::lonnet::allowed('vcg',
  923:                                                 $env{'request.course.id'});
  924:         $group = $env{'form.group'};
  925:         $group =~ s/\W//g;
  926:         if ($group) {
  927:             ($uname,$udom) = &get_name_dom($group);
  928:             my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
  929: 							       $group); 
  930:             if (%curr_groups) {
  931:                 if (($view_permission) || (&Apache::lonnet::allowed('rgf',
  932:                                       $env{'request.course.id'}.'/'.$group))) {
  933:                     $portfolio_root = &get_portfolio_root($group);
  934:                 } else {
  935:                     $r->print('You do not have the privileges required to access the shared files space for this group');
  936:                     $earlyout = 1;
  937:                 }
  938:             } else {
  939:                 $r->print('Not a valid group for this course');
  940:                 $earlyout = 1;
  941:             }
  942:             $title = &mt('Group files').' for '.$group; 
  943:         } else {
  944:             $r->print('Invalid group');
  945:             $earlyout = 1;
  946:         }
  947:         if ($earlyout) { return OK; }
  948:     } else {
  949:         ($uname,$udom) = &get_name_dom();
  950:         $portfolio_root = &get_portfolio_root();
  951:         $title = &mt('Portfolio Manager');
  952:     }
  953: 
  954:     &Apache::loncommon::no_cache($r);
  955:     &Apache::loncommon::content_type($r,'text/html');
  956:     $r->send_http_header;
  957:     # Give the LON-CAPA page header
  958:     if ($env{"form.mode"} eq 'selectfile'){
  959:         $r->print(&Apache::loncommon::start_page($title,undef,
  960: 						 {'only_body' => 1}));
  961:     } else {
  962:         $r->print(&Apache::loncommon::start_page($title));
  963:     }
  964:     $r->rflush();
  965: 	if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
  966:    	    $r->print('<font color="red"> No file was selected to upload.'.
  967:    	            'To upload a file, click <strong>Browse...</strong>'.
  968:    	            ', select a file, then click <strong>Upload</strong>,</font>');
  969: 	}
  970:     if ($env{'form.meta'}) {
  971:         &open_form($r,$url);
  972: #        $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
  973:         $r->print('Edit the meta data<br />');
  974:         &close_form($r,$url,$group);
  975:     }
  976:     if ($env{'form.store'}) {
  977:     }
  978: 
  979:     if ($env{'form.uploaddoc.filename'}) {
  980: 	&upload($r,$url,$group);
  981:     } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
  982: 	&delete_confirmed($r,$url,$group);
  983:     } elsif ($env{'form.action'} eq 'delete') {
  984: 	&delete($r,$url,$group);
  985:     } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
  986: 	&delete_dir_confirmed($r,$url,$group);
  987:     } elsif ($env{'form.action'} eq 'deletedir'){
  988: 	&delete_dir($r,$url,$group);
  989:     } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
  990: 	&rename_confirmed($r,$url,$group);
  991:     } elsif ($env{'form.rename'}) {
  992:         $env{'form.selectfile'} = $env{'form.rename'};
  993:         $env{'form.action'} = 'rename';
  994: 	&rename($r,$url,$group);
  995:     } elsif ($env{'form.access'}) {
  996:         $env{'form.selectfile'} = $env{'form.access'};
  997:         $env{'form.action'} = 'chgaccess';
  998:         &display_access($r,$url,$group);
  999:     } elsif ($env{'form.action'} eq 'chgaccess') {
 1000:         &update_access($r,$url,$group);
 1001:     } elsif ($env{'form.createdir'}) {
 1002: 	&createdir($r,$url,$group);
 1003:     } elsif ($env{'form.lockinfo'}) {
 1004:         &lock_info($r,$url,$group);
 1005:     } else {
 1006: 	my $current_path='/';
 1007: 	if ($env{'form.currentpath'}) {
 1008: 	    $current_path = $env{'form.currentpath'};
 1009: 	}
 1010:         my @dir_list=&get_dir_list($portfolio_root,$group);
 1011: 	if ($dir_list[0] eq 'no_such_dir'){
 1012: 	    # two main reasons for this:
 1013:             #    1) never been here, so directory structure not created
 1014: 	    #    2) back-button navigation after deleting a directory
 1015: 	    if ($current_path eq '/'){
 1016: 	        &Apache::lonnet::mkdiruserfile($uname,$udom,
 1017: 					       &get_port_path($group));
 1018: 	    } else {
 1019:                 # some directory that snuck in get rid of the directory
 1020:                 # from the recent pulldown, just in case
 1021: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
 1022: 						      [$current_path]);
 1023: 		$current_path = '/'; # force it back to the root        
 1024: 	    }
 1025: 	    # now grab the directory list again, for the first time
 1026: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
 1027: 					    $udom,$uname,$portfolio_root);
 1028:         }
 1029: 	# need to know if directory is empty so it can be removed if desired
 1030: 	my $is_empty=(@dir_list == 2);
 1031: 	&display_common($r,$url,$current_path,$is_empty,\@dir_list,$group);
 1032:         &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group);
 1033: 	$r->print(&Apache::loncommon::end_page());
 1034:     }
 1035:     return OK;
 1036: }
 1037: 1;
 1038: __END__

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