File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.152: download - view: text, annotated - select for diffs
Wed Aug 9 17:47:26 2006 UTC (17 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- clenaup

    1: # The LearningOnline Network
    2: # portfolio browser
    3: #
    4: # $Id: portfolio.pm,v 1.152 2006/08/09 17:47:26 albertel Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or 
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::portfolio;
   30: use strict;
   31: use Apache::Constants qw(:common :http);
   32: use Apache::loncommon;
   33: use Apache::lonnet;
   34: use Apache::lontexconvert;
   35: use Apache::lonfeedback;
   36: use Apache::lonlocal;
   37: use Apache::lonnet;
   38: use Apache::longroup;
   39: use Apache::lonhtmlcommon;
   40: use HTML::Entities;
   41: use LONCAPA;
   42: 
   43: sub group_args {
   44:     my $output;
   45:     if (defined($env{'form.group'})) {
   46:         $output .= '&group='.$env{'form.group'};
   47: 	if (defined($env{'form.ref'})) {
   48: 	    $output .= '&ref='.$env{'form.ref'};
   49: 	}
   50:     }
   51:     return $output;
   52: }
   53: 
   54: sub group_form_data {
   55:     my $output;
   56:     if (defined($env{'form.group'})) {
   57: 	$output = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />';
   58: 	if (exists($env{'form.ref'})) {
   59: 	    $output .= '<input type="hidden" name="ref" value="'.
   60: 		$env{'form.ref'}.'" />';
   61: 	}
   62:     }
   63:     return $output;
   64: } 
   65: 
   66: # receives a file name and path stub from username/userfiles/portfolio/
   67: # returns an anchor tag consisting encoding filename and currentpath
   68: sub make_anchor {
   69:     my ($url, $anchor_fields, $inner_text) = @_;
   70:     if ($$anchor_fields{'continue'} ne 'true') {$$anchor_fields{'continue'} = 'false'};
   71:     my $anchor = '<a href="'.$url.'?';
   72:     foreach my $field_name (keys(%$anchor_fields)) {
   73:         $anchor .= $field_name.'='.$$anchor_fields{$field_name}.'&amp;';
   74:     }
   75:     $anchor =~ s/&amp;$//;
   76:     $anchor .= &group_args();
   77:     $anchor .= '">'.$inner_text.'</a>';
   78:     return $anchor;
   79: }
   80: 
   81: my $dirptr=16384;
   82: sub display_common {
   83:     my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload)=@_;
   84:     my $namespace = &get_namespace();
   85:     my $port_path = &get_port_path();
   86:     if ($can_upload) {
   87:         my $groupitem = &group_form_data();
   88: 
   89:         my $iconpath= $r->dir_config('lonIconsURL') . "/";
   90:         my %text=&Apache::lonlocal::texthash(
   91: 					 'upload' => 'Upload',
   92: 					 'upload_label' =>  
   93: 					 'Upload file to current directory:',
   94: 					 'createdir' => 'Create Subdirectory',
   95: 					 'createdir_label' => 
   96: 					 'Create subdirectory in current directory:');
   97:         my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
   98:         $r->print(<<"TABLE"); 
   99: <table id="LC_portfolio_actions">
  100:   <tr id="LC_portfolio_upload">
  101:     <td class="LC_label">
  102:       $text{'upload_label'}
  103:     </td>
  104:     <td class="LC_value">
  105:       <form method="post" enctype="multipart/form-data" action="$escuri">
  106:         $groupitem 
  107:         <input name="uploaddoc" type="file" />
  108: 	<input type="hidden" name="currentpath" value="$current_path" />
  109: 	<input type="hidden" name="action" value="$env{"form.action"}" />
  110: 	<input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
  111: 	<input type="hidden" name="mode" value="$env{"form.mode"}" />
  112: 	<input type="submit" name="storeupl" value="$text{'upload'}" />
  113:       </form>
  114:     </td>
  115:   </tr>
  116:   <tr id="LC_portfolio_createdir">
  117:     <td class="LC_label">
  118:       $text{'createdir_label'}
  119:     </td>
  120:     <td class="LC_value">
  121:       <form method="post" action="$escuri">
  122:         <input name="newdir" type="input" />$groupitem
  123:         <input type="hidden" name="currentpath" value="$current_path" />
  124:         <input type="hidden" name="action" value="$env{"form.action"}" />
  125:         <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
  126:         <input type="hidden" name="mode" value="$env{"form.mode"}" />
  127:         <input type="submit" name="createdir" value="$text{'createdir'}" />
  128:       </form>
  129:     </td>
  130:   </tr>
  131: </table>
  132: TABLE
  133:     }
  134:     my @tree = split (/\//,$current_path);
  135:     my %anchor_fields = (
  136:         'selectfile'    => $port_path,
  137:         'currentpath'   => '/',
  138:         'mode'          => $env{"form.mode"},
  139:         'fieldname'     => $env{"form.fieldname"},
  140:         'continue'      => $env{"form.continue"}
  141:     );
  142:     $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
  143:     if (@tree > 1){
  144:         my $newCurrentPath = '';
  145:         for (my $i = 1; $i< @tree; $i++){
  146:             $newCurrentPath .= $tree[$i].'/';
  147:             my %anchor_fields = (
  148:                 'selectfile' => $tree[$i],
  149:                 'currentpath' => '/',
  150:                 'mode' => $env{"form.mode"},
  151:                 'fieldname' => $env{"form.fieldname"},
  152:                 'continue' => $env{"form.continue"}
  153:             );
  154:             $r->print(&make_anchor($url,\%anchor_fields,$tree[$i]).'/');
  155:         }
  156:     }
  157:     $r->print('</span>');
  158:     &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
  159:     $r->print('<br /><form method="post" action="'.$url.'?mode='.$env{"form.mode"}.'&amp;fieldname='.$env{"form.fieldname"}.&group_args());
  160:     $r->print('">'.
  161: 	      &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
  162: 						    'this.form.submit();'));
  163:     $r->print("</form>");
  164: }
  165: 
  166: sub display_directory_line {
  167:     my ($r,$select_mode,$fullpath, $filename, $mtime, $size, $css_class,
  168: 	$line, $access_controls, $curr_access, $now, $version_flag,
  169: 	$href_location, $url, $current_path, $access_admin_text, $versions)=@_;
  170:     # my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
  171:     $r->print('<tr class="'.$css_class.'">');
  172:     $r->print($line);
  173:     $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" /></td>');
  174:     $r->print('<td>'.$$version_flag{$filename}.'</td><td>');
  175:     $r->print(&make_anchor($href_location.$filename,undef,$filename).'</td>'); 
  176:     $r->print('<td>'.$size.'</td>');
  177:     $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
  178:     if ($select_mode ne 'true') {
  179: 	$r->print('<td><span style="white-space: nowrap">'.
  180: 		  &mt($curr_access).'&nbsp;&nbsp;&nbsp;');
  181:         my %anchor_fields = (
  182:             'access' => $filename,
  183:             'currentpath' => $current_path
  184:         );
  185: 	$r->print(&make_anchor($url, \%anchor_fields, $access_admin_text).'</span></td>');
  186:     }
  187:     $r->print('</tr>'.$/);
  188: }
  189: 
  190: sub display_directory {
  191:     my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
  192:         $can_modify,$can_delete,$can_setacl)=@_;
  193:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
  194:     my $display_out;
  195:     my $select_mode;
  196:     my $checked_files;
  197:     my $port_path = &get_port_path();
  198:     my ($uname,$udom) = &get_name_dom();
  199:     my $access_admin_text = &mt('View Status');
  200:     if ($can_setacl) {
  201:         $access_admin_text = &mt('View/Change Status');
  202:     }
  203: 
  204:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
  205:                                                                         $uname);
  206:     my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
  207:                                                   $current_permissions,$group);
  208:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
  209:     my $now = time;
  210:     if ($env{"form.mode"} eq 'selectfile'){
  211: 	&select_files($r);
  212: 	$checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
  213: 	$select_mode = 'true';
  214:     } 
  215:     if ($is_empty && ($current_path ne '/') && $can_delete) {
  216:         $display_out = '<form method="post" action="'.$url.'">'.
  217: 	    &group_form_data().
  218:         '<input type="hidden" name="action" value="deletedir" />'.
  219:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
  220:         '<input type="hidden" name="selectfile" value="" />'.
  221:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
  222:         '</form>';
  223:         
  224:         $r->print($display_out);
  225: 	return;
  226:     }
  227:     if ($select_mode eq 'true') {
  228:         $r->print('<form method="post" name="checkselect" action="'.$url.'">');
  229:         $r->print('<table id="LC_browser">'.
  230:             '<tr><th>Select</th><th>&nbsp;</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
  231:     } else {
  232:         $r->print('<form method="post" action="'.$url.'">');
  233:         $r->print('<table id="LC_browser">'.
  234:             '<tr><th colspan="2">Actions</th><th>&nbsp;</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th><th>Current Access Status</th></tr>');
  235:     }
  236:     $r->print("\n".&group_form_data()."\n");
  237: 
  238:     my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
  239:     my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
  240:     my @dir_lines;
  241:     my @version_lines;
  242:     my %versioned;
  243:     foreach my $dir_line (sort 
  244: 		      { 
  245: 			  my ($afile)=split('&',$a,2);
  246: 			  my ($bfile)=split('&',$b,2);
  247: 			  return (lc($afile) cmp lc($bfile));
  248: 		      } (@$dir_list)) {
  249:     	#$strip holds directory/file name
  250:     	#$dom 
  251:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16); 
  252:     	$filename =~ s/\s+$//;
  253:     	my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
  254:     	if ($version) {
  255:     	    push(@version_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
  256:     	    $versioned{$fname.'.'.$extension} .= $version.",";
  257:     	} else {
  258:     	    push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
  259:     	}
  260:     }
  261:     foreach my $dir_line (@dir_lines) {
  262:         my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line;
  263:         my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
  264:     	if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
  265:     	    my %version_flag;
  266:     	    my $show_versions;
  267:     	    if ($env{'form.showversions'} eq $filename) {
  268:     	        $show_versions = 'true';
  269:     	    }
  270:     	    if (exists($versioned{$filename})) {
  271:     	        my %anchor_fields = (
  272:     	            'selectfile' => $filename,
  273:     	            'continue' => 'false',
  274:     	            'currentpath' => $current_path,
  275:     	        );
  276:     	        if ($show_versions) {
  277:                     $version_flag{$filename} = &make_anchor('portfolio',\%anchor_fields,
  278:                         '<img class="LC_icon" alt="'.&mt('opened folder').'" src="'.$iconpath.'folder_pointer_opened.gif" />');
  279:     	        } else {
  280:     	            $anchor_fields{'showversions'} = $filename;
  281:                     $version_flag{$filename} = &make_anchor('portfolio',\%anchor_fields,
  282:                         '<img class="LC_icon" alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_pointer_closed.gif" />');
  283:                 }
  284:     	    } else {
  285:     	        $version_flag{$filename} = '&nbsp;';
  286:     	    }
  287:             if ($dirptr&$testdir) {
  288: 		my $colspan='colspan="2"';
  289:                 if ($select_mode eq 'true'){
  290: 		    undef($colspan);
  291:                 }
  292: 		$r->print('<tr class="LC_browser_folder"><td '.$colspan.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_closed.gif" /></td>');
  293:                 $r->print('<td>Go to ...</td>');
  294:                 my %anchor_fields = (
  295:                     'selectfile'    => $filename.'/',
  296:                     'currentpath'   => $current_path.$filename.'/',
  297:                     'mode'          => $env{"form.mode"},
  298:                     'fieldname'     => $env{"form.fieldname"},
  299:                     'continue'      => $env{"form.continue"}
  300:                 );  
  301:                 $r->print('<td>'.$version_flag{$filename}.'</td><td>'.&make_anchor($url,\%anchor_fields,$filename.'/').'</td>'); 
  302:                 $r->print('</tr>'); 
  303:             } else {
  304: 		my $css_class = 'LC_browser_file';
  305: 		my $line;
  306:                 my $fullpath = $current_path.$filename;
  307:                 $fullpath = &prepend_group($fullpath);
  308:                 if ($select_mode eq 'true') {
  309:                     $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"';
  310: 		    if ($$checked_files{$filename} eq 'selected') {
  311:                         $line.=" checked ";
  312:                     }
  313: 		    $line.=' /></td>';
  314:                 } else {
  315:                     if (exists $locked_files{$fullpath}) {
  316:                         my %anchor_fields = (
  317:                             'lockinfo' => $current_path.$filename
  318:                         );
  319:                         $line.='<td colspan="2">'.&make_anchor($url,\%anchor_fields,'Locked').'</td>';
  320: 			$css_class= 'LC_browser_file_locked';
  321:                     } else {
  322:                         if (!$can_modify) {
  323:                             $line .= '<td colspan="2">';
  324:                         } else {
  325:                             $line .= '<td>';
  326:                         }
  327:                         if ($can_delete) {
  328:                             $line .= '<input type="checkbox" name="selectfile" value="'.$filename.'" />';
  329:                         }
  330:                         if ($can_modify) {
  331:                             my $cat='<img class="LC_icon" alt="'.&mt('Catalog Information').
  332:                             '" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />';
  333:                             my %anchor_fields = (
  334:                                 'rename' => $filename,
  335:                                 currentpath => $current_path
  336:                             );
  337:                             $line .= &make_anchor($url,\%anchor_fields,'Rename');
  338:                             $line .= '</td><td>'.&make_anchor($href_edit_location.$filename.'.meta',undef,$cat);
  339:                             # '<a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>';
  340:                         }
  341:                         $line .= '</td>';
  342:                     }
  343:                 }
  344: 		my $curr_access;
  345: 		if ($select_mode ne 'true') {
  346: 		    my $pub_access = 0;
  347: 		    my $guest_access = 0;
  348: 		    my $cond_access = 0;
  349: 		    foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
  350: 			my ($num,$scope,$end,$start) = &unpack_acc_key($key);
  351: 			if (($now > $start) && (!$end || $end > $now)) {
  352: 			    if ($scope eq 'public')  {
  353: 				$pub_access = 1;
  354: 			    } elsif ($scope eq 'guest') {
  355: 				$guest_access = 1;
  356: 			    } else {
  357: 				$cond_access = 1;
  358: 			    }
  359: 			}
  360: 		    }
  361: 		    if (!$pub_access && !$guest_access && !$cond_access) {
  362: 			$curr_access = &mt('Private');
  363: 		    } else {
  364: 			my @allaccesses; 
  365: 			if ($pub_access) {
  366: 			    push(@allaccesses,&mt('Public'));
  367: 			}
  368: 			if ($guest_access) {
  369: 			    push(@allaccesses,&mt('Passphrase-protected'));
  370: 			}
  371: 			if ($cond_access) {
  372: 			    push(@allaccesses,&mt('Conditional'));
  373: 			}
  374: 			$curr_access = join('+ ',@allaccesses);
  375: 		    }
  376: 		}
  377:                 &display_directory_line($r,$select_mode,$fullpath, $filename, $mtime, $size, $css_class, $line, 
  378:                                         \%access_controls, $curr_access,$now, \%version_flag, $href_location, 
  379:                                         $url, $current_path, $access_admin_text);
  380: 		if ($show_versions) {
  381: 		    foreach my $dir_line (@version_lines) {
  382: 		        my ($v_filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line;
  383:                         my ($v_fname,$version,$v_extension) = &Apache::grades::file_name_version_ext($v_filename);
  384:                         $line = '<td colspan="2">&nbsp;</td>';
  385:                         if (($v_fname eq $fname)&&($v_extension eq $extension)) {
  386: 		            &display_directory_line($r,$select_mode,$fullpath, $v_filename, $mtime, $size, 
  387: 		                            $css_class, $line, \%access_controls, $curr_access, $now,
  388: 		                             \%version_flag, $href_location, $url, $current_path, $access_admin_text, 1);
  389: 		        }
  390: 		    }
  391: 		}
  392:             }
  393:         }
  394:     }
  395:     if ($select_mode eq 'true') {
  396:         $r->print('</table>
  397:             <input type="hidden" name="continue" value="true" />
  398:             <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" />
  399:             <input type="hidden" name="mode" value="selectfile" />
  400:             <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
  401:             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
  402:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
  403:         </form>');        
  404:     } else {
  405:         $r->print('</table>');
  406:         if ($can_delete) {
  407:             $r->print('
  408:         <input type="submit" name="doit" value="Delete Checked Files" />
  409:         <input type="hidden" name="action" value="delete" />
  410:         <input type="hidden" name="currentpath" value="'.$current_path.'" />
  411:         </form>'
  412:             );
  413:         }
  414:     }
  415: }
  416: 
  417: sub open_form {
  418:     my ($r,$url)=@_;
  419:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  420:     $r->print('<form name="portform" method="post" action="'.$url.'">');
  421:     $r->print('<input type="hidden" name="action" value="'.
  422: 	      $env{'form.action'}.'" />');
  423:     $r->print('<input type="hidden" name="confirmed" value="1" />');
  424:     foreach (@files) {
  425:         $r->print('<input type="hidden" name="selectfile" value="'.
  426: 	      $_.'" />');
  427:     }
  428:     $r->print('<input type="hidden" name="currentpath" value="'.
  429: 	      $env{'form.currentpath'}.'" />');
  430: }
  431: 
  432: sub close_form {
  433:     my ($r,$url,$button_text)=@_;
  434:     if (!defined($button_text)) {
  435:         $button_text = {
  436:                          'continue' => &mt('Continue'),
  437:                          'cancel'   => &mt('Cancel'),
  438:                        };
  439:     }
  440:     $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
  441:     $r->print(&group_form_data().'</p></form>');
  442:     $r->print('<form action="'.$url.'" method="post">
  443:                <p>
  444:               <input type="hidden" name="currentpath" value="'.
  445: 	      $env{'form.currentpath'}.'" />'.
  446: 	      &group_form_data());
  447:     $r->print("\n".'   <input type="submit" value="'.$button_text->{'cancel'}.'" />
  448:                </p></form>'); 
  449: }
  450: 
  451: sub display_file {
  452:     my ($path,$filename)=@_;
  453:     my $display_file_text;
  454:     my $file_start='<span class="LC_filename">';
  455:     my $file_end='</span>';
  456:     if (!defined($path)) { $path=$env{'form.currentpath'}; }
  457:     if (!defined($filename)) { 
  458:         $filename=$env{'form.selectfile'};
  459:         $display_file_text = $file_start.$path.$filename.$file_end;
  460:     } elsif (ref($filename) eq "ARRAY") {
  461:         foreach my $file (@$filename) {
  462:             $display_file_text .= $file_start.$path.$file.$file_end.'<br />';
  463:         }
  464:     } elsif (ref($filename) eq "SCALAR") {
  465:         $display_file_text = $file_start.$path.$$filename.$file_end;
  466:     } else {
  467: 	$display_file_text = $file_start.$path.$filename.$file_end;
  468:     }
  469:     return $display_file_text;
  470: }
  471: 
  472: sub done {
  473:     my ($message,$url)=@_;
  474:     unless (defined $message) {
  475:         $message='Done';
  476:     }
  477:     my $result = '<h3><a href="'.$url.'?currentpath='.
  478: 	         $env{'form.currentpath'}.
  479: 	         '&fieldname='.$env{'form.fieldname'}.
  480: 	         '&mode='.$env{'form.mode'}.
  481: 		 &group_args();
  482:     $result .= '">'.&mt($message).'</a></h3>';
  483:     return $result;
  484: }
  485: 
  486: sub delete {
  487:     my ($r,$url)=@_;
  488:     my @check;
  489:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
  490:     $file_name = &prepend_group($file_name);
  491:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  492:     my ($uname,$udom) = &get_name_dom();
  493:     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
  494:         $r->print ("The file is locked and cannot be deleted.<br />");
  495:         $r->print(&done('Back',$url));
  496:     } else {
  497:         if (scalar(@files)) {
  498:             &open_form($r,$url);
  499:             $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
  500:             &close_form($r,$url);
  501:         } else {
  502:             $r->print("No file was checked to delete.<br />");
  503:             $r->print(&done(undef,$url));
  504:         }
  505:     }
  506: } 
  507: 
  508: sub delete_confirmed {
  509:     my ($r,$url)=@_;
  510:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  511:     my $result;
  512:     my ($uname,$udom) = &get_name_dom();
  513:     my $port_path = &get_port_path();
  514:     foreach my $delete_file (@files) {
  515:         $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
  516: 					       $env{'form.currentpath'}.
  517: 					       $delete_file);
  518:         if ($result ne 'ok') {
  519: 	$r->print('<span class="LC_error"> An error occured ('.$result.
  520: 		  ') while trying to delete '.&display_file(undef, $delete_file).'</span><br />');
  521:         }
  522:     }
  523:     $r->print(&done(undef,$url));
  524: }
  525: 
  526: sub delete_dir {
  527:     my ($r,$url)=@_;
  528:     &open_form($r,$url);
  529:     $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
  530:     &close_form($r,$url);
  531: } 
  532: 
  533: sub delete_dir_confirmed {
  534:     my ($r,$url)=@_;
  535:     my $directory_name = $env{'form.currentpath'};
  536:     $directory_name =~ s|/$||; # remove any trailing slash
  537:     my ($uname,$udom) = &get_name_dom();
  538:     my $namespace = &get_namespace();
  539:     my $port_path = &get_port_path();
  540:     my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
  541: 					       $directory_name);
  542: 					       
  543:     if ($result ne 'ok') {
  544: 	$r->print('<span class="LC_error"> An error occured (dir) ('.$result.
  545: 		  ') while trying to delete '.$directory_name.'</span><br />');
  546:     } else {
  547:         # now remove from recent
  548: #        $r->print('<br /> removing '.$directory_name.'<br /');
  549:         &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
  550:         my @dirs = split m!/!, $directory_name;
  551:         
  552: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
  553:         $directory_name='/';
  554:         for (my $i=1; $i < (@dirs - 1); $i ++){
  555:             $directory_name .= $dirs[$i].'/';
  556:         }
  557:         $env{'form.currentpath'} = $directory_name;
  558:     }
  559:     $r->print(&done(undef,$url));
  560: }
  561: 
  562: sub rename {
  563:     my ($r,$url)=@_;
  564:     my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
  565:     my ($uname,$udom) = &get_name_dom();
  566:     $file_name = &prepend_group($file_name);
  567:     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
  568:         $r->print ("The file is locked and cannot be renamed.<br />");
  569:         $r->print(&done(undef,$url));
  570:     } else {
  571:         &open_form($r,$url);
  572:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
  573:                    <input name="filenewname" type="input" size="50" />?</p>');
  574:         &close_form($r,$url);
  575:     }
  576: }
  577: 
  578: sub rename_confirmed {
  579:     my ($r,$url)=@_;
  580:     my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
  581:     my ($uname,$udom) = &get_name_dom();
  582:     my $port_path = &get_port_path();
  583:     if ($filenewname eq '') {
  584: 	$r->print('<span class="LC_error">'.
  585: 		  &mt("Error: no valid filename was provided to rename to.").
  586: 		  '</span><br />');
  587: 	$r->print(&done(undef,$url));
  588: 	return;
  589:     } 
  590:     my $result=
  591: 	&Apache::lonnet::renameuserfile($uname,$udom,
  592:             $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
  593:             $port_path.$env{'form.currentpath'}.$filenewname);
  594:     if ($result ne 'ok') {
  595: 	$r->print('<span class="LC_error">'.
  596: 		  &mt('An errror occured ([_1]) while trying to rename [_2]'
  597: 		      .' to [_3]',$result,&display_file(),
  598: 		      &display_file('',$filenewname)).'</span><br />');
  599:     }
  600:     if ($filenewname ne $env{'form.filenewname'}) {
  601:         $r->print(&mt("The new file name was changed from:<br />[_1] to [_2]",
  602: 		      '<strong>'.&display_file('',$env{'form.filenewname'}).'</strong>',
  603: 		      '<strong>'.&display_file('',$filenewname).'</strong>'));
  604:     }
  605:     $r->print(&done(undef,$url));
  606: }
  607: 
  608: sub display_access {
  609:     my ($r,$url,$group,$can_setacl,$port_path) = @_;
  610:     my ($uname,$udom) = &get_name_dom();
  611:     my $file_name = $env{'form.currentpath'}.$env{'form.access'};
  612:     $file_name = &prepend_group($file_name);
  613:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
  614:                                                                         $uname);
  615:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
  616:     my $aclcount = keys(%access_controls);
  617:     my $header = '<h3>'.&mt('Allowing others to retrieve file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>';
  618:     my $info .= &mt('Access to this file by others can be set to be one or more of the following types: public, passphrase-protected or conditional.').'<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.').'</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.').'</li><li>'.&mt('Conditional files are accessible to logged-in users with accounts in the LON-CAPA network, who satisfy the conditions you set.').'<br />'.&mt('The conditions can include affiliation with a particular course or group, or a user account in a specific domain.').'<br />'.&mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').'</li></ul>';
  619: 
  620:     if ($group eq '') {
  621:         $info .= (&mt("Direct others to the 'Display file listing' link (shown when there are viewable files) on your personal information page:<br /><a href='/adm/$udom/$uname/aboutme'>http://$ENV{'SERVER_NAME'}/adm/$udom/$uname/aboutme</a>"));
  622:     }
  623:     
  624:     if ($can_setacl) {
  625:         &open_form($r,$url);
  626:         $r->print($header.$info);
  627:         &access_setting_table($r,$access_controls{$file_name});
  628:         my $button_text = {
  629:                         'continue' => &mt('Proceed'),
  630:                         'cancel' => &mt('Back to directory listing'),
  631:                       };
  632:         &close_form($r,$url,$button_text);
  633:     } else {
  634:         $r->print($header);
  635:         if ($aclcount) {  
  636:             $r->print($info);
  637:         }
  638:         &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
  639:     }
  640: }
  641: 
  642: sub view_access_settings {
  643:     my ($r,$url,$access_controls,$aclcount) = @_;
  644:     my ($showstart,$showend);
  645:     my %todisplay;
  646:     foreach my $key (sort(keys(%{$access_controls}))) {
  647:         my ($num,$scope,$end,$start) = &unpack_acc_key($key);
  648:         $todisplay{$scope}{$key} = $$access_controls{$key};
  649:     }
  650:     if ($aclcount) {
  651:         $r->print(&mt('<h4>Current access controls defined for this file:</h4>'));
  652:         $r->print(&Apache::loncommon::start_data_table());
  653:         $r->print(&Apache::loncommon::start_data_table_header_row());
  654:         $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
  655:                   '</th><th>'.&mt('Additional information').'</th>');
  656:         $r->print(&Apache::loncommon::end_data_table_header_row());
  657:         my $count = 1;
  658:         my $chg = 'none';
  659:         &build_access_summary($r,$count,$chg,%todisplay);
  660:         $r->print(&Apache::loncommon::end_data_table());
  661:     } else {
  662:         $r->print(&mt('No access control settings currently exist for this file.<br />' ));
  663:     }
  664:     $r->print('<br /><a href="'.$url.'?currentpath='.$env{'form.currentpath'}.
  665:               &group_args().'">'.&mt('Return to directory listing').'</a>');
  666:     return;
  667: }
  668: 
  669: sub build_access_summary {
  670:     my ($r,$count,$chg,%todisplay) = @_; 
  671:     my ($showstart,$showend);
  672:     my %scope_desc = (
  673:                       public => 'Public',
  674:                       guest => 'Passphrase-protected',
  675:                       domains => 'Conditional: domain-based',
  676:                       users => 'Conditional: user-based',
  677:                       course => 'Conditional: course-based',
  678:                       group => 'Conditional: group-based',
  679:                      );
  680:     my @allscopes = ('public','guest','domains','users','course','group');
  681:     foreach my $scope (@allscopes) {
  682:         if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
  683:             next;
  684:         }
  685:         foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
  686:             if ($count) {
  687:                 $r->print(&Apache::loncommon::start_data_table_row());
  688:             }
  689:             my ($num,$scope,$end,$start) = &unpack_acc_key($key);
  690:             my $content = $todisplay{$scope}{$key};
  691:             if ($chg eq 'delete') {
  692:                 $showstart = &mt('Deleted');
  693:                 $showend = $showstart;
  694:             } else {
  695:                 $showstart = localtime($start);
  696:                 if ($end == 0) {
  697:                     $showend = &mt('No end date');
  698:                 } else {
  699:                     $showend = localtime($end);
  700:                 }
  701:             }
  702:             $r->print('<td>'.&mt($scope_desc{$scope}));
  703:             if (($scope eq 'course') || ($scope eq 'group')) {
  704:                 if ($chg ne 'delete') {
  705:                     my $cid = $content->{'domain'}.'_'.$content->{'number'};
  706:                     my %course_description = &Apache::lonnet::coursedescription($cid);
  707:                     $r->print('<br />('.$course_description{'description'}.')');
  708:                 }
  709:             }
  710:             $r->print('</td><td>'.&mt('Start: ').$showstart.
  711:                   '<br />'.&mt('End: ').$showend.'</td><td>');
  712:             if ($chg ne 'delete') {
  713:                 if ($scope eq 'guest') {
  714:                     $r->print(&mt('Passphrase').': '.$content->{'password'});
  715:                 } elsif ($scope eq 'course' || $scope eq 'group') {
  716:                     $r->print('<table><tr>');
  717:                     $r->print('<th>'.&mt('Roles').'</th><th>'.
  718:                           &mt('Access').'</th><th>'.
  719:                                           &mt('Sections').'</th>');
  720:                     if ($scope eq 'course') {
  721:                         $r->print('<th>'.&mt('Groups').'</th>');
  722:                     } else {
  723:                         $r->print('<th>'.&mt('Teams').'</th>');
  724:                     }
  725:                     $r->print('</tr>');
  726:                     foreach my $id (sort(keys(%{$content->{'roles'}}))) {
  727:                         $r->print('<tr>');
  728:                         foreach my $item ('role','access','section','group') {
  729:                             $r->print('<td>');
  730:                             if ($item eq 'role') {
  731:                                 my $ucscope = $scope;
  732:                                 $ucscope =~ s/^(\w)/uc($1)/e;
  733:                                 my $role_output;
  734:                                 foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
  735:                                     if ($role eq 'all') {
  736:                                         $role_output .= $role.',';
  737:                                     } elsif ($role =~ /^cr/) {
  738:                                         $role_output .= (split('/',$role))[3].',';
  739:                                     } else {
  740:                                         $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
  741:                                     }
  742:                                 }
  743:                                 $role_output =~ s/,$//;
  744:                                 $r->print($role_output);
  745:                             } else {
  746:                                 $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
  747:                             }
  748:                             $r->print('</tr>');
  749:                         }
  750: 			$r->print("</table>");
  751:                     }
  752: 		    $r->print("</tr></table>");
  753:                 } elsif ($scope eq 'domains') {
  754:                     $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
  755:                 } elsif ($scope eq 'users') {
  756:                     my $curr_user_list = &sort_users($content->{'users'});
  757:                     $r->print(&mt('Users: ').$curr_user_list);
  758:                 } else {
  759:                     $r->print('&nbsp;');
  760:                 }
  761:             } else {
  762:                 $r->print('&nbsp;');
  763:             }
  764:             $r->print('</td>');
  765:             $r->print(&Apache::loncommon::end_data_table_row());
  766:             $count ++;
  767:         }
  768:     }
  769: }
  770: 
  771: 
  772: sub update_access {
  773:     my ($r,$url,$group,$port_path) = @_;
  774:     my $totalprocessed = 0;
  775:     my %processing;
  776:     my %title  = (
  777:                          'activate' => 'New control(s) added',
  778:                          'delete'   => 'Existing control(s) deleted',
  779:                          'update'   => 'Existing control(s) modified',
  780:                      );
  781:     my $changes;
  782:     foreach my $chg (sort(keys(%title))) {     
  783:         @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
  784:         $totalprocessed += @{$processing{$chg}};
  785:         foreach my $num (@{$processing{$chg}}) {
  786:             my $scope = $env{'form.scope_'.$num};
  787:             my ($start,$end) = &get_dates_from_form($num);
  788:             my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
  789:             if ($chg eq 'delete') {
  790:                 $$changes{$chg}{$newkey} = 1;
  791:             } else {
  792:                 $$changes{$chg}{$newkey} = 
  793:                             &build_access_record($num,$scope,$start,$end,$chg);
  794:             }
  795:         }
  796:     }
  797:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
  798:     $r->print('<h3>'.&mt('Allowing others to retrieve file: [_1]',
  799:               $port_path.$file_name).'</h3>'."\n");
  800:     $file_name = &prepend_group($file_name);
  801:     my ($uname,$udom) = &get_name_dom();
  802:     my ($errors,$outcome,$deloutcome,$new_values,$translation);
  803:     if ($totalprocessed) {
  804:         ($outcome,$deloutcome,$new_values,$translation) =
  805:         &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
  806:                                                 $uname);
  807:     }
  808:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
  809:                                                                        $uname);
  810:     my %access_controls = 
  811: 	&Apache::lonnet::get_access_controls($current_permissions,
  812: 					     $group,$file_name);
  813:     if ($totalprocessed) {
  814:         if ($outcome eq 'ok') {
  815:             my $updated_controls = $access_controls{$file_name};
  816:             my ($showstart,$showend);
  817:             $r->print(&Apache::loncommon::start_data_table());
  818:             $r->print(&Apache::loncommon::start_data_table_header_row());
  819:             $r->print('<th>'.&mt('Type of change').'</th><th>'.
  820:                       &mt('Access control').'</th><th>'.&mt('Dates available').
  821:                       '</th><th>'.&mt('Additional information').'</th>');
  822:             $r->print(&Apache::loncommon::end_data_table_header_row());
  823:             foreach my $chg (sort(keys(%processing))) {
  824:                 if (@{$processing{$chg}} > 0) {
  825:                     if ($chg eq 'delete') {
  826:                         if (!($deloutcome eq 'ok')) {
  827:                             $errors .='<span class="LC_error">'.
  828: 				&mt('A problem occurred deleting access controls: [_1]',$deloutcome).
  829: 				'</span>';
  830:                             next;
  831:                         }
  832:                     }
  833:                     my $numchgs = @{$processing{$chg}};
  834:                     $r->print(&Apache::loncommon::start_data_table_row());
  835:                     $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
  836:                               '.</td>');
  837:                     my $count = 0;
  838:                     my %todisplay;
  839:                     foreach my $key (sort(keys(%{$$changes{$chg}}))) {
  840:                         my ($num,$scope,$end,$start) = &unpack_acc_key($key);
  841:                         my $newkey = $key;
  842:                         if ($chg eq 'activate') {
  843:                             $newkey =~ s/^(\d+)/$$translation{$1}/;
  844:                         }
  845:                         $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
  846:                     }
  847:                     &build_access_summary($r,$count,$chg,%todisplay);  
  848:                 }
  849:             }
  850:             $r->print(&Apache::loncommon::end_data_table());
  851:         } else {
  852:             if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
  853:                 $errors .= '<span class="LC_error">'.
  854: 		    &mt('A problem occurred storing access control settings: [_1]',$outcome).
  855: 		    '</span>';
  856:             }
  857:         }
  858:         if ($errors) { 
  859:             $r->print($errors);
  860:         }
  861:     }
  862:     my $allnew = 0;
  863:     my $totalnew = 0;
  864:     my $status = 'new';
  865:     my ($firstitem,$lastitem);
  866:     foreach my $newitem ('course','group','domains','users') {
  867:         $allnew += $env{'form.new'.$newitem};
  868:     }
  869:     if ($allnew > 0) {
  870:         my $now = time;
  871:         my $then = $now + (60*60*24*180); # six months approx.
  872:         &open_form($r,$url);
  873:         foreach my $newitem ('course','group','domains','users') {
  874:             if ($env{'form.new'.$newitem} > 0) {
  875:                 $r->print('<br />'.&mt('Add new <b>[_1]-based</b> access control for portfolio file: <b>[_2]</b>',$newitem,$env{'form.currentpath'}.$env{'form.selectfile'}).'<br /><br />');
  876:                 $firstitem = $totalnew;
  877:                 $lastitem = $totalnew + $env{'form.new'.$newitem};
  878:                 $totalnew = $lastitem;
  879:                 my @numbers;   
  880:                 for (my $i=$firstitem; $i<$lastitem; $i++) {
  881:                     push (@numbers,$i);
  882:                 }
  883:                 &display_access_row($r,$status,$newitem,\@numbers,
  884:                                     $access_controls{$file_name},$now,$then);
  885:             }
  886:         }
  887:         &close_form($r,$url);
  888:     } else {
  889:         $r->print('<br /><a href="'.$url.'?access='.$env{'form.selectfile'}.
  890:                   '&amp;currentpath='.$env{'form.currentpath'}.&group_args().'">'.
  891:                    &mt('Display all access settings for this file').'</a>'.
  892:                   '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.
  893:                   '<a href="'.$url.'?currentpath='.$env{'form.currentpath'}.
  894:                   &group_args().'">'.&mt('Return to directory listing').'</a>');
  895:     }
  896:     return;
  897: }
  898: 
  899: sub build_access_record {
  900:     my ($num,$scope,$start,$end,$chg) = @_;
  901:     my $record = {
  902: 	type => $scope,
  903: 	time => {
  904: 	    start => $start,
  905: 	    end   => $end
  906: 	    },
  907: 	    };
  908: 		
  909:     if ($scope eq 'guest') {	
  910:         $record->{'password'} = $env{'form.password'};
  911:     } elsif (($scope eq 'course') || ($scope eq 'group')) {
  912:         $record->{'domain'} = $env{'form.crsdom_'.$num};
  913: 	$record->{'number'} = $env{'form.crsnum_'.$num};
  914:         my @role_ids;
  915:         my @delete_role_ids =
  916:             &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
  917: 	my @preserves =
  918: 	    &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
  919: 	if (@delete_role_ids) {
  920: 	    foreach my $id (@preserves) {
  921: 		if (grep {$_ = $id} (@delete_role_ids)) {
  922: 		    next;
  923: 		}
  924: 		push(@role_ids,$id); 
  925: 	    }
  926: 	} else {
  927: 	    push(@role_ids,@preserves);
  928: 	}
  929: 
  930: 	my $next_id = $env{'form.add_role_'.$num};
  931: 	if ($next_id) {
  932: 	    push(@role_ids,$next_id);
  933: 	}
  934: 
  935:         foreach my $id (@role_ids) {
  936:             my (@roles,@accesses,@sections,@groups);
  937:             if (($id == $next_id) && ($chg eq 'update')) {
  938:                 @roles    = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
  939:                 @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
  940:                 @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
  941:                 @groups   = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
  942:             } else {
  943:                 @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
  944:                 @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
  945:                 @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
  946:                 @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
  947:             }
  948: 	    $record->{'roles'}{$id}{'role'}    = \@roles;
  949: 	    $record->{'roles'}{$id}{'access'}  = \@accesses;
  950: 	    $record->{'roles'}{$id}{'section'} = \@sections;
  951: 	    $record->{'roles'}{$id}{'group'}   = \@groups;
  952:         }
  953:     } elsif ($scope eq 'domains') {
  954:         my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
  955: 	$record->{'dom'} = \@doms;
  956:     } elsif ($scope eq 'users') {
  957:         my $userlist = $env{'form.users_'.$num};
  958:         $userlist =~ s/\s+//sg;
  959: 	my %userhash = map { ($_,1) } (split(/,/,$userlist));
  960:         foreach my $user (keys(%userhash)) {
  961:             my ($uname,$udom) = split(/:/,$user);
  962: 	    push(@{$record->{'users'}}, {
  963: 		'uname' => $uname,
  964: 		'udom'  => $udom
  965: 		});
  966: 	}
  967:     }
  968:     return $record;
  969: }
  970: 
  971: sub get_dates_from_form {
  972:     my ($id) = @_;
  973:     my $startdate;
  974:     my $enddate;
  975:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
  976:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
  977:     if ( exists ($env{'form.noend_'.$id}) ) {
  978:         $enddate = 0;
  979:     }
  980:     return ($startdate,$enddate);
  981: }
  982: 
  983: sub sort_users {
  984:     my ($users) = @_; 
  985:     my @curr_users = map {
  986: 	$_->{'uname'}.':'.$_->{'udom'}
  987:     } (@{$users});
  988:     my $curr_user_list = join(",\n",sort(@curr_users));
  989:     return $curr_user_list;
  990: }
  991: 
  992: sub access_setting_table {
  993:     my ($r,$access_controls) = @_;
  994:     my ($public,$publictext);
  995:     $publictext = &mt('Off');
  996:     my ($guest,$guesttext);
  997:     $guesttext = &mt('Off');
  998:     my @courses = ();
  999:     my @groups = ();
 1000:     my @domains = ();
 1001:     my @users = ();
 1002:     my $now = time;
 1003:     my $then = $now + (60*60*24*180); # six months approx.
 1004:     my ($num,$scope,$publicnum,$guestnum);
 1005:     my (%acl_count,%end,%start);
 1006:     foreach my $key (sort(keys(%{$access_controls}))) {
 1007:         ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
 1008:         if ($scope eq 'public') {
 1009:             $public = $key;
 1010:             $publicnum = $num;
 1011:             $publictext = &acl_status($start{$key},$end{$key},$now);
 1012:         } elsif ($scope eq 'guest') {
 1013:             $guest=$key;
 1014:             $guestnum = $num;  
 1015:             $guesttext = &acl_status($start{$key},$end{$key},$now);
 1016:         } elsif ($scope eq 'course') {
 1017:             push(@courses,$key);
 1018:         } elsif ($scope eq 'group') {
 1019:             push(@groups,$key);
 1020:         } elsif ($scope eq 'domains') {
 1021:             push(@domains,$key);
 1022:         } elsif ($scope eq 'users') {
 1023:             push(@users,$key);
 1024:         }
 1025:         $acl_count{$scope} ++;
 1026:     }
 1027:     $r->print('<table border="0"><tr><td valign="top">');
 1028:     $r->print('<h3>'.&mt('Public access:').' '.$publictext.'</h3>');
 1029:     $r->print(&Apache::loncommon::start_data_table());
 1030:     $r->print(&Apache::loncommon::start_data_table_header_row());
 1031:     $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
 1032:     $r->print(&Apache::loncommon::end_data_table_header_row());
 1033:     $r->print(&Apache::loncommon::start_data_table_row());
 1034:     if ($public) {
 1035:         $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
 1036:                   &dateboxes($publicnum,$start{$public},$end{$public}).'</td>');
 1037:     } else {
 1038:         $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
 1039:                   &dateboxes('0',$now,$then).'</td>');
 1040:     }
 1041:     $r->print(&Apache::loncommon::end_data_table_row());
 1042:     $r->print(&Apache::loncommon::end_data_table());
 1043:     $r->print('</td><td width="40">&nbsp;</td><td valign="top">');
 1044:     $r->print('<h3>'.&mt('Passphrase-protected access:').' '.$guesttext.'</h3>');
 1045:     $r->print(&Apache::loncommon::start_data_table());
 1046:     $r->print(&Apache::loncommon::start_data_table_header_row());
 1047:     $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
 1048:               '</th><th>'. &mt('Passphrase').'</th>');
 1049:     $r->print(&Apache::loncommon::end_data_table_header_row());
 1050:     $r->print(&Apache::loncommon::start_data_table_row());
 1051:     my $passwd;
 1052:     if ($guest) {
 1053:         $passwd = $$access_controls{$guest}{'password'};
 1054:         $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
 1055:                   &dateboxes($guestnum,$start{$guest},$end{$guest}).'</td>');
 1056:     } else {
 1057:         $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
 1058:                   &dateboxes('1',$now,$then).'</td>');
 1059:     }
 1060:     $r->print('<td><input type="text" size="15" name="password" value="'.
 1061:               $passwd.'" /></td>');
 1062:     $r->print(&Apache::loncommon::end_data_table_row());
 1063:     $r->print(&Apache::loncommon::end_data_table());
 1064:     $r->print('</td></tr><tr><td colspan="3">&nbsp;</td></tr><tr><td valign="top">');
 1065:     &access_element($r,'domains',\%acl_count,\@domains,$access_controls,$now,$then);
 1066:     $r->print('</td><td>&nbsp;</td><td valign="top">');
 1067:     &access_element($r,'users',\%acl_count,\@users,$access_controls,$now,$then);
 1068:     $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
 1069:     if (@courses > 0 || @groups > 0) {
 1070:         $r->print('<td colspan="3" valign="top">');
 1071:     } else {
 1072:         $r->print('<td valign="top">');
 1073:     }
 1074:     &access_element($r,'course',\%acl_count,\@courses,$access_controls,$now,$then);
 1075:     $r->print('</td>');
 1076:     if (@courses > 0 || @groups > 0) {
 1077:         $r->print('</tr><tr><td colspan="3">&nbsp;</td></tr><tr><td colspan="3" valign="top">');
 1078:     } else {
 1079:         $r->print('<td>&nbsp;</td><td valign="top">');
 1080:     }
 1081:     &access_element($r,'group',\%acl_count,\@groups,$access_controls,$now,$then);
 1082:     $r->print('</td></tr></table>');
 1083: }
 1084: 
 1085: sub acl_status {
 1086:     my ($start,$end,$now) = @_;
 1087:     if ($start > $now) {
 1088:         return &mt('Inactive');
 1089:     }
 1090:     if ($end && $end<$now) {
 1091:         return &mt('Inactive');
 1092:     }
 1093:     return &mt('Active');
 1094: }
 1095: 
 1096: sub access_element {
 1097:     my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
 1098:     my $title = $type;
 1099:     $title =~ s/s$//;
 1100:     $title =~ s/^(\w)/uc($1)/e;
 1101:     $r->print('<h3>'.&mt('[_1]-based conditional access: ',$title));
 1102:     if ($$acl_count{$type}) {
 1103:         $r->print($$acl_count{$type}.' ');
 1104:         if ($$acl_count{$type} > 1) {
 1105:             $r->print(&mt('conditions'));
 1106:         } else {
 1107:             $r->print(&mt('condition'));
 1108:         }
 1109:     } else {
 1110:         $r->print(&mt('Off'));
 1111:     }
 1112:     $r->print('</h3>');
 1113:     &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
 1114:     return;
 1115: }
 1116: 
 1117: sub display_access_row {
 1118:     my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
 1119:     if (@{$items} > 0) {
 1120:         my @all_doms;
 1121:         my $colspan = 3;
 1122:         my $uctype = $type;
 1123:         $uctype =~ s/^(\w)/uc($1)/e;
 1124:         $r->print(&Apache::loncommon::start_data_table());
 1125:         $r->print(&Apache::loncommon::start_data_table_header_row());
 1126:         $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
 1127:               &mt('Dates available').'</th>');
 1128:         if (($type eq 'course') || ($type eq 'group')) {
 1129:             $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
 1130:                       '</th>');
 1131:             $colspan ++;
 1132:         } elsif ($type eq 'domains') {
 1133:             @all_doms = &Apache::loncommon::get_domains();
 1134:         }
 1135:         $r->print(&Apache::loncommon::end_data_table_header_row());
 1136:         foreach my $key (@{$items}) {
 1137: 	    $r->print(&Apache::loncommon::start_data_table_row());
 1138:             if (($type eq 'course') || ($type eq 'group')) {
 1139:                 &course_row($r,$status,$type,$key,$access_controls,$now,$then);
 1140:             } elsif ($type eq 'domains') {
 1141:                 &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
 1142:                             $then);
 1143:             } elsif ($type eq 'users') {
 1144:                 &users_row($r,$status,$key,$access_controls,$now,$then);
 1145:             }
 1146: 	    $r->print(&Apache::loncommon::end_data_table_row());
 1147:         }
 1148:         if ($status eq 'old') {
 1149: 	    $r->print(&Apache::loncommon::start_data_table_row());
 1150:             $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
 1151:                       '</td>');
 1152: 	    $r->print(&Apache::loncommon::end_data_table_row());
 1153:         }
 1154:         $r->print(&Apache::loncommon::end_data_table());
 1155:     } else {
 1156:         $r->print(&mt('No [_1]-based conditions defined.<br />',$type).
 1157:                   &additional_item($type));
 1158:     }
 1159:     return;
 1160: }
 1161: 
 1162: sub course_js {
 1163:     return qq|
 1164: <script type="text/javascript">
 1165: function setRoleOptions(caller,num,cdom,cnum,type) {
 1166:     addIndexnum = getCallerIndex(caller);
 1167:     updateIndexnum = getIndex('update',num);
 1168:     if (caller.checked) {
 1169:         document.portform.elements[updateIndexnum].checked = true;
 1170:         var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
 1171:         var title = 'Roles_Chooser';
 1172:         var options = 'scrollbars=1,resizable=1,menubar=0';
 1173:         options += ',width=700,height=600';
 1174:         rolebrowser = open(url,title,options,'1');
 1175:         rolebrowser.focus();
 1176:     } else {
 1177:         for (var j=0;j<5;j++) {
 1178:             document.portform.elements[addIndexnum+j].value = '';
 1179:         }
 1180:     }
 1181: }
 1182: 
 1183: function getCallerIndex(caller) {
 1184:     for (var i=0;i<document.portform.elements.length;i++) {
 1185:         if (document.portform.elements[i] == caller) {
 1186:             return i;
 1187:         }
 1188:     }
 1189:     return -1;
 1190: }
 1191: 
 1192: function getIndex(name,value) {
 1193:     for (var i=0;i<document.portform.elements.length;i++) {
 1194:         if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
 1195:             return i;
 1196:         }
 1197:     }
 1198:     return -1;
 1199: }
 1200: 
 1201: </script>
 1202: |;
 1203: }
 1204: 
 1205: sub course_row {
 1206:     my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
 1207:     my $content;
 1208:     my $defdom = $env{'user.domain'};
 1209:     if ($status eq 'old') {
 1210:         $content = $$access_controls{$item}; 
 1211:         $defdom =  $content->{'domain'};
 1212:     }
 1213:     my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
 1214: 	.&course_js();
 1215:     my $crsgrptext = 'Groups';
 1216:     if ($type eq 'group') {
 1217:         $crsgrptext = 'Teams';
 1218:     }
 1219:     my $uctype = $type;
 1220:     $uctype =~ s/^(\w)/uc($1)/e;
 1221:     my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
 1222:                                                     $type);
 1223:     $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
 1224:     if ($status eq 'old') {
 1225:         my $cid = $content->{'domain'}.'_'.$content->{'number'};
 1226:         my %course_description = &Apache::lonnet::coursedescription($cid);
 1227:         $r->print('<td><input type="hidden" name="crsdom_'.$num.'" value="'.$content->{'domain'}.'" /><input type="hidden" name="crsnum_'.$num.'" value="'.$content->{'number'}.'" />'.$course_description{'description'}.'</td>');
 1228:     } elsif ($status eq 'new') {
 1229:         $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,undef,undef,$uctype).'&nbsp;&nbsp;<input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
 1230:     }
 1231:     $r->print('<td>'.&dateboxes($num,$start,$end).'</td>');
 1232:     $r->print('<td><table><tr>');
 1233:     $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'.
 1234:               &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'.
 1235:               &mt($crsgrptext).'</th></tr>');
 1236:     if ($status eq 'old') {
 1237:         my $max_id = 0;
 1238:         foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
 1239:             if ($role_id > $max_id) {
 1240:                 $max_id = $role_id;
 1241:             }
 1242:             $max_id ++;
 1243:             my $role_selects = &role_selectors($num,$role_id,$status,$type,$content,'display');
 1244:             $r->print('<tr><td><span style="white-space: nowrap"><label><input type="checkbox" name="delete_role_'.$num.'" value="'.$role_id.'" />'.&mt('Delete').'</label></span><br /><input type="hidden" name="preserve_role_'.$num.'" value="'.$role_id.'" /></td>'.$role_selects.'</tr>');
 1245:         }
 1246:         $r->print('</table><br />'.&mt('Add a roles-based condition').'&nbsp;<input type="checkbox" name ="add_role_'.$num.'" onClick="javascript:setRoleOptions(this,'."'$num','$content->{'domain'}','$content->{'number'}','$uctype'".')" value="'.$max_id.'" /><input type="hidden" name="role_'.$num.'_'.$max_id.'" /><input type="hidden" name="access_'.$num.'_'.$max_id.'" /><input type="hidden" name="section_'.$num.'_'.$max_id.'" /><input type="hidden" name="group_'.$num.'_'.$max_id.'" /></td>');
 1247:     } elsif ($status eq 'new') {
 1248:         my $role_id = 1;
 1249:         my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display');
 1250:         $r->print('<tr><td><input type="checkbox" name="add_role_'.$num.'" value="'.$role_id.'" checked="checked" />'.&mt('Add').'<input type="hidden" name="grplist_'.$num.'_'.$role_id.'" /></td>'.$role_selects);
 1251:         $r->print('</tr></table></td>');
 1252:     }
 1253:     return;
 1254: }
 1255: 
 1256: sub domains_row {
 1257:     my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
 1258:     my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
 1259:                                                     'domains');
 1260:     my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true">'.
 1261:                      ' <option value="">'.&mt('Please select').'</option>';
 1262:     if ($status eq 'old') {
 1263:         my $content =  $$access_controls{$item};
 1264: 	foreach my $dom (@{$all_doms}) {
 1265:             if ((@{$content->{'dom'}} > 0) 
 1266: 		&& (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
 1267:                 $dom_select .= '<option value="'.$dom.'" selected>'.
 1268:                                $dom.'</option>';
 1269:             } else {
 1270:                 $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
 1271:             }
 1272:         }
 1273:     } else {
 1274:         foreach my $dom (@{$all_doms}) {
 1275:             $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
 1276:         }
 1277:     }
 1278:     $dom_select .= '</select>';
 1279:     $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
 1280:               '</td><td>'.&dateboxes($num,$start,$end).'</td>');
 1281: }
 1282: 
 1283: sub users_row {
 1284:     my ($r,$status,$item,$access_controls,$now,$then) = @_;
 1285:     my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
 1286:                                                     'users');
 1287:     my $curr_user_list;
 1288:     if ($status eq 'old') {
 1289:         my $content = $$access_controls{$item};
 1290:         $curr_user_list = &sort_users($content->{'users'});
 1291:     }
 1292:     $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt("Format for users' username:domain information:").'<br /><tt>sparty:msu,illini:uiuc  ... etc.</tt><br /><textarea name="users_'.$num.'" cols="30"  rows="5">'.$curr_user_list.'</textarea></td><td>'.&dateboxes($num,$start,$end).'</td>');
 1293: }
 1294: 
 1295: sub additional_item {
 1296:     my ($type) = @_;
 1297:     my $output = &mt('Add new [_1] condition(s)?',$type).'&nbsp;'.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
 1298:     return $output;
 1299: }
 1300: 
 1301: sub actionbox {
 1302:     my ($status,$num,$scope) = @_;
 1303:     my $output = '<span style="white-space: nowrap"><label>';
 1304:     if ($status eq 'new') {
 1305:         $output .= '<input type="checkbox" name="activate" value="'.$num.'" />'.
 1306:         &mt('Activate');
 1307:     } else {
 1308:         $output .= '<input type="checkbox" name="delete" value="'.$num.
 1309:                    '" />'.&mt('Delete').'</label></span><br /><span style="white-space: nowrap">'.
 1310:                    '<label><input type="checkbox" name="update" value="'.
 1311:                    $num.'" />'.&mt('Update');
 1312:     }
 1313:     $output .= '</label></span><input type="hidden" name="scope_'.$num.                '" value="'.$scope.'" />';
 1314:     return $output;
 1315: }
 1316:                                                                                    
 1317: sub dateboxes {
 1318:     my ($num,$start,$end) = @_;
 1319:     my $noend;
 1320:     if ($end == 0) {
 1321:         $noend = 'checked="checked"';
 1322:     }
 1323:     my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
 1324:                            'startdate_'.$num,$start,undef,undef,undef,1,undef,
 1325:                             undef,undef,1);
 1326:     my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
 1327:                                'enddate_'.$num,$end,undef,undef,undef,1,undef,
 1328:                                 undef,undef,1). '&nbsp;&nbsp;<span style="white-space: nowrap"><label>'.
 1329:                                 '<input type="checkbox" name="noend_'.
 1330:                                 $num.'" '.$noend.' />'.&mt('No end date').
 1331:                                 '</label></span>';
 1332:                                                                                    
 1333:     my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
 1334:     return $output;
 1335: }
 1336: 
 1337: sub unpack_acc_key {
 1338:     my ($acc_key) = @_;
 1339:     my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
 1340:     return ($num,$scope,$end,$start);
 1341: }
 1342: 
 1343: sub set_identifiers {
 1344:     my ($status,$item,$now,$then,$scope) = @_;
 1345:     if ($status eq 'old') {
 1346:         return(&unpack_acc_key($item));
 1347:     } else {
 1348:         return($item,$scope,$then,$now);
 1349:     }
 1350: } 
 1351: 
 1352: sub role_selectors {
 1353:     my ($num,$role_id,$status,$type,$content,$caller) = @_;
 1354:     my ($output,$cdom,$cnum,$longid);
 1355:     if ($caller eq 'display') {
 1356:         $longid = '_'.$num.'_'.$role_id;
 1357:         if ($status eq 'new') {
 1358:             foreach my $item ('role','access','section','group') {
 1359:                 $output .= '<td><select name="'.$item.$longid.'">'.
 1360:                            '<option value="">'.&mt('Pick [_1] first',$type).
 1361:                            '</option></select></td>';
 1362:             }
 1363:             return $output;
 1364:         } else {
 1365:             $cdom = $$content{'domain'};
 1366:             $cnum = $$content{'number'};
 1367:         }
 1368:     } elsif ($caller eq 'rolepicker') {
 1369:          $cdom = $env{'form.cdom'};
 1370:          $cnum = $env{'form.cnum'};
 1371:     }
 1372:     my $uctype = $type;
 1373:     $uctype =~ s/^(\w)/uc($1)/e;
 1374:     my ($sections,$groups,$allroles,$rolehash,$accesshash) =
 1375:             &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$uctype);
 1376:     if (!@{$sections}) {
 1377:         @{$sections} = ('none');
 1378:     } else {
 1379:         unshift(@{$sections},('all','none'));
 1380:     }
 1381:     if (!@{$groups}) {
 1382:         @{$groups} = ('none');
 1383:     } else {
 1384:         unshift(@{$groups},('all','none'));
 1385:     }
 1386:     my @allacesses = sort(keys(%{$accesshash}));
 1387:     my (%sectionhash,%grouphash);
 1388:     foreach my $sec (@{$sections}) {
 1389:         $sectionhash{$sec} = $sec;
 1390:     }
 1391:     foreach my $grp (@{$groups}) {
 1392:         $grouphash{$grp} = $grp;
 1393:     }
 1394:     my %lookup = (
 1395:                    'role' => $rolehash,
 1396:                    'access' => $accesshash,
 1397:                    'section' => \%sectionhash,
 1398:                    'group' => \%grouphash,
 1399:                  );
 1400:     my @allaccesses = sort(keys(%{$accesshash}));
 1401:     my %allitems = (
 1402:                     'role' => $allroles,
 1403:                     'access' => \@allaccesses,
 1404:                     'section' => $sections,
 1405:                     'group' => $groups, 
 1406:                    );
 1407:     foreach my $item ('role','access','section','group') {
 1408:         $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
 1409:         foreach my $entry (@{$allitems{$item}}) {
 1410:             if ($caller eq 'display') {
 1411:                 if ((@{$$content{'roles'}{$role_id}{$item}} > 0) && 
 1412:                     (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
 1413:                     $output .= '  <option value="'.$entry.'" selected>'.
 1414:                                   $lookup{$item}{$entry}.'</option>';
 1415:                     next;
 1416:                 }
 1417:             }
 1418:             $output .= '  <option value="'.$entry.'">'.
 1419:                        $lookup{$item}{$entry}.'</option>';
 1420:         }
 1421:         $output .= '</select>';
 1422:     }
 1423:     $output .= '</td>';
 1424:     return $output;
 1425: }
 1426: 
 1427: sub role_options_window {
 1428:     my ($r) = @_;
 1429:     my $cdom = $env{'form.cdom'};
 1430:     my $cnum = $env{'form.cnum'};
 1431:     my $type = $env{'form.type'};
 1432:     my $addindex = $env{'form.setroles'};
 1433:     my $grouptitle = 'Groups';
 1434:     if ($type eq 'Group') {
 1435:          $grouptitle = 'Teams';
 1436:     } 
 1437:     my $role_selects = &role_selectors(1,1,'new',$type,undef,'rolepicker');
 1438:     $r->print(<<"END_SCRIPT");
 1439: <script type="text/javascript">
 1440: function setRoles() {
 1441:     var addidx = $addindex+1;
 1442:     for (var i=0; i<4; i++) {
 1443:         var copylist = '';
 1444:         for (var j=0; j<document.rolepicker.elements[i].length; j++) {
 1445:             if (document.rolepicker.elements[i].options[j].selected) {
 1446:                 copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
 1447:             }
 1448:         }
 1449:         copylist = copylist.substr(0,copylist.length-1);
 1450:         opener.document.portform.elements[addidx+i].value = copylist;
 1451:     }
 1452:     self.close();
 1453: }
 1454: </script>
 1455: END_SCRIPT
 1456:     $r->print(&mt('Select roles, course status, section(s) and group(s) for users who will be able to access the portfolio file.'));
 1457:     $r->print('<form name="rolepicker" action="/adm/portfolio" method="post"><table><tr><th>'.&mt('Roles').'</th><th>'.&mt('[_1] status',$type).'</th><th>'.&mt('Sections').'</th><th>'.&mt($grouptitle).'</th></tr><tr>'.$role_selects.'</tr></table><br /><input type="button" name="rolepickbutton" value="Save selections" onclick="setRoles()" />');
 1458:     return;
 1459: }
 1460: 
 1461: sub select_files {
 1462:     my ($r) = @_;
 1463:     if ($env{'form.continue'} eq 'true') {
 1464:         # here we update the selections for the currentpath
 1465:         # eventually, have to handle removing those not checked, but . . . 
 1466:         my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
 1467:         if (scalar(@items)){
 1468:              &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
 1469:         }
 1470:     } else {
 1471:             #empty the file for a fresh start
 1472:             &Apache::lonnet::clear_selected_files($env{'user.name'});
 1473:     }
 1474:     my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
 1475:     my $java_files = join ",", @files;
 1476:     if ($java_files) {
 1477:         $java_files.=',';
 1478:     }
 1479:     my $javascript =(<<ENDSMP);
 1480:         <script type="text/javascript">
 1481:         function finishSelect() {
 1482: ENDSMP
 1483:     $javascript .= 'fileList = "'.$java_files.'";';
 1484:     $javascript .= (<<ENDSMP);
 1485:             for (i=0;i<document.forms.checkselect.length;i++) { 
 1486:                 if (document.forms.checkselect[i].checked){
 1487:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
 1488:                 }
 1489:             }
 1490:             opener.document.forms.lonhomework.$env{'form.fieldname'}.value=fileList;
 1491:             self.close();
 1492:         }
 1493:         </script>
 1494: ENDSMP
 1495:     $r->print($javascript);
 1496:     $r->print("<h1>Select portfolio files</h1>
 1497:                 Check as many as you wish in response to the problem.<br />");
 1498:     my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
 1499:     if (@otherfiles) {
 1500: 	$r->print("<strong>Files selected from other directories:</strong><br />");
 1501: 	foreach my $file (@otherfiles) {
 1502: 	    $r->print($file."<br />");
 1503: 	}
 1504:     }
 1505: }
 1506: 
 1507: sub upload {
 1508:     my ($r,$url,$group)=@_;
 1509:     my $fname=$env{'form.uploaddoc.filename'};
 1510:     my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
 1511:     my $disk_quota = 20000; # expressed in k
 1512:     if (defined($group)) {
 1513:         my $grp_quota = &get_group_quota($group); # quota expressed in k 
 1514:         if ($grp_quota ne '') {
 1515:             $disk_quota = $grp_quota;
 1516:         } else {
 1517:             $disk_quota = 0;
 1518:         }
 1519:     }
 1520:     $fname=&Apache::lonnet::clean_filename($fname);
 1521: 
 1522:     my $portfolio_root=&get_portfolio_root();
 1523:     my ($uname,$udom) = &get_name_dom();
 1524:     my $port_path = &get_port_path();
 1525:     # Fixme --- Move the checking for existing file to LOND error return
 1526:     my @dir_list=&get_dir_list($portfolio_root);
 1527:     my $found_file = 0;
 1528:     my $locked_file = 0;
 1529:     foreach my $line (@dir_list) {
 1530:         my ($file_name)=split(/\&/,$line,2);
 1531:         if ($file_name eq $fname){
 1532:             $file_name = $env{'form.currentpath'}.$file_name;
 1533:             $file_name = &prepend_group($file_name);
 1534:             $found_file = 1;
 1535:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
 1536:                 $locked_file = 1;
 1537:             } 
 1538:         }
 1539:     }
 1540:     my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
 1541:     if (($current_disk_usage + $filesize) > $disk_quota){
 1542:         $r->print('<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
 1543:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
 1544:         $r->print(&done('Back',$url));
 1545:     } 
 1546:     elsif ($found_file){
 1547:         if ($locked_file){
 1548:             $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
 1549:                   '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
 1550:             $r->print(&done('Back',$url));      
 1551:         } else {   
 1552:             $r->print('<span class="LC_error">'.'Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></span>'.
 1553:                   '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
 1554:             $r->print(&done('Back',$url));
 1555:         }
 1556:     } else {
 1557:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
 1558: 	        	 $port_path.$env{'form.currentpath'});
 1559:         if ($result !~ m|^/uploaded/|) {
 1560:             $r->print('<span class="LC_error">'.'An errror occured ('.$result.
 1561: 	              ') while trying to upload '.&display_file().'</span><br />');
 1562: 	    $r->print(&done('Back',$url));
 1563:         } else {
 1564:             $r->print(&done(undef,$url));
 1565:         }
 1566:     }
 1567: }
 1568: 
 1569: sub lock_info {
 1570:     my ($r,$url,$group) = @_;
 1571:     my ($uname,$udom) = &get_name_dom();
 1572:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
 1573:                                                                        $uname);
 1574:     my $file_name = $env{'form.lockinfo'};
 1575:     $file_name = &prepend_group($file_name);
 1576:     if (defined($file_name) && defined($$current_permissions{$file_name})) {
 1577:         foreach my $array_item (@{$$current_permissions{$file_name}}) {
 1578:             if (ref($array_item) eq 'ARRAY') {
 1579:                 my $filetext;
 1580:                 if (defined($group)) {
 1581:                     $filetext = '<strong>'.$env{'form.lockinfo'}.
 1582:                                     '</strong> (group: '.$group.')'; 
 1583:                 } else {
 1584:                     $filetext = '<strong>'.$file_name.'</strong>';
 1585:                 } 
 1586:                 $r->print(&mt('[_1] was submitted in response to problem: ',
 1587:                               $filetext).
 1588:                           '<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
 1589:                           '</strong><br />');
 1590:                 my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
 1591:                 $r->print(&mt('In the course: <strong>[_1]</strong><br />',
 1592:                               $course_description{'description'}));
 1593:                 # $r->print('the third is '.$$array_item[2].'<br>');
 1594:                 # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
 1595:             }
 1596:         }
 1597:     }
 1598:     $r->print(&done('Back',$url));
 1599:     return 'ok';
 1600: }
 1601: 
 1602: sub createdir {
 1603:     my ($r,$url)=@_;
 1604:     my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
 1605:     if ($newdir eq '') {
 1606:     	$r->print('<span class="LC_error">'.
 1607: 	    	  &mt("Error: no directory name was provided.").
 1608: 		      '</span><br />');
 1609: 	    $r->print(&done(undef,$url));
 1610: 	    return;
 1611:     }
 1612:     my $portfolio_root = &get_portfolio_root(); 
 1613:     my @dir_list=&get_dir_list($portfolio_root);
 1614:     my $found_file = 0;
 1615:     foreach my $line (@dir_list) {
 1616:         my ($filename)=split(/\&/,$line,2);
 1617:         if ($filename eq $newdir){
 1618:             $found_file = 1;
 1619:         }
 1620:     }
 1621:     if ($found_file){
 1622:     	    $r->print('<span class="LC_error">'.'Unable to create a directory named <strong>'.$newdir.
 1623:     	            ' </strong>a file or directory by that name already exists.</span><br />');
 1624:     } else {
 1625:         my ($uname,$udom) = &get_name_dom();
 1626:         my $port_path = &get_port_path();
 1627:         my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
 1628: 	         $port_path.$env{'form.currentpath'}.$newdir);
 1629:         if ($result ne 'ok') {
 1630:     	    $r->print('<span class="LC_error">'.'An errror occured ('.$result.
 1631: 	    	      ') while trying to create a new directory '.&display_file().'</span><br />');
 1632:         }
 1633:     }
 1634:     if ($newdir ne $env{'form.newdir'}) {
 1635:         $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");  
 1636:     }
 1637:     $r->print(&done(undef,$url));
 1638: }
 1639: 
 1640: sub get_portfolio_root {
 1641:     my ($uname,$udom) = &get_name_dom();
 1642:     my $path;
 1643:     if (defined($env{'form.group'})) {
 1644:         $path = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
 1645:     } else {
 1646:         $path = '/userfiles/portfolio';
 1647:     }
 1648:     return (&Apache::loncommon::propath($udom,$uname).$path);
 1649: }
 1650: 
 1651: sub get_group_quota {
 1652:     my ($group) = @_;
 1653:     my $group_quota; 
 1654:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1655:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 1656:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
 1657:     if (%curr_groups) {
 1658:         my %group_info =  &Apache::longroup::get_group_settings(
 1659:                                                     $curr_groups{$group});
 1660:         $group_quota = $group_info{'quota'}; #expressed in Mb
 1661:         if ($group_quota) {
 1662:             $group_quota = 1000 * $group_quota; #expressed in k
 1663:         } 
 1664:     }
 1665:     return $group_quota;
 1666: } 
 1667: 
 1668: sub get_dir_list {
 1669:     my ($portfolio_root) = @_;
 1670:     my ($uname,$udom) = &get_name_dom();
 1671:     return &Apache::lonnet::dirlist($env{'form.currentpath'},
 1672:                                           $udom,$uname,$portfolio_root);
 1673: }
 1674: 
 1675: sub get_name_dom {
 1676:     my ($uname,$udom);
 1677:     if (defined($env{'form.group'})) {
 1678:         $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 1679:         $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
 1680:     } else {
 1681:         $udom = $env{'user.domain'};
 1682:         $uname = $env{'user.name'};
 1683:     }
 1684:     return ($uname,$udom);
 1685: }
 1686: 
 1687: sub prepend_group {
 1688:     my ($filename) = @_;
 1689:     if (defined($env{'form.group'})) {
 1690:         $filename = $env{'form.group'}.$filename;
 1691:     }
 1692:     return $filename;
 1693: }
 1694: 
 1695: sub get_namespace {
 1696:     my $namespace = 'portfolio';
 1697:     if (defined($env{'form.group'})) {
 1698:         my ($uname,$udom) = &get_name_dom();
 1699:         $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
 1700:     }
 1701:     return $namespace;
 1702: }
 1703: 
 1704: sub get_port_path {
 1705:     my $port_path;
 1706:     if (defined($env{'form.group'})) {
 1707:        $port_path = "groups/$env{'form.group'}/portfolio";
 1708:     } else {
 1709:        $port_path = 'portfolio';
 1710:     }
 1711:     return $port_path;
 1712: }
 1713: 
 1714: sub missing_priv {
 1715:     my ($r,$url,$priv) = @_;
 1716:     my $longtext = {
 1717:                       upload => 'upload files',
 1718:                       delete => 'delete files',
 1719:                       rename => 'rename files',
 1720:                       setacl => 'set access controls for files',
 1721:                    };
 1722:     my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
 1723:     my $rtnlink = '<a href="'.$url;
 1724:     if ($url =~ /\?/) {
 1725:         $rtnlink .= '&';
 1726:     } else {
 1727:         $rtnlink .= '?';
 1728:     }
 1729:     $rtnlink .= 'currentpath='.$escpath;
 1730:     $r->print(&mt('<h3>Action disallowed</h3>'));
 1731:     $r->print(&mt('You do not have sufficient privileges to [_1] ',
 1732:                   $longtext->{$priv}));
 1733:     if (defined($env{'form.group'})) {
 1734:         $r->print(&mt("in the group's file repository."));
 1735:         $rtnlink .= &group_args()
 1736:     } else {
 1737:         $r->print(&mt('in this portfolio.'));
 1738:     }
 1739:     $rtnlink .= '">'.&mt('Return to directory listing page').'</a>';
 1740:     $r->print('<br />'.$rtnlink);
 1741:     $r->print(&Apache::loncommon::end_page());
 1742:     return;
 1743: }
 1744: 
 1745: sub coursegrp_portfolio_header {
 1746:     my ($cdom,$cnum,$grp_desc)=@_;
 1747:     my $gpterm  = &Apache::loncommon::group_term();
 1748:     my $ucgpterm = $gpterm;
 1749:     $ucgpterm =~ s/^(\w)/uc($1)/e;
 1750:     if ($env{'form.ref'}) {
 1751:         &Apache::lonhtmlcommon::add_breadcrumb
 1752:             ({href=>"/adm/coursegroups",
 1753:               text=>"Groups",
 1754:               title=>"Course Groups"});
 1755:     }
 1756:     &Apache::lonhtmlcommon::add_breadcrumb
 1757:         ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
 1758:           text=>"$ucgpterm: $grp_desc",
 1759:           title=>"Go to group's home page"},
 1760:          {href=>"/adm/coursegrp_portfolio?".&group_args(),
 1761:           text=>"Group Portfolio",
 1762:           title=>"Display group portfolio"});
 1763:     my $output = &Apache::lonhtmlcommon::breadcrumbs(
 1764:                          &mt('[_1] portfolio files - [_2]',$gpterm,$grp_desc));
 1765:     return $output;
 1766: }
 1767: 
 1768: 
 1769: sub handler {
 1770:     # this handles file management
 1771:     my $r = shift;
 1772:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 1773:          ['selectfile','currentpath','meta','lockinfo','currentfile','action',
 1774: 	  'fieldname','mode','rename','continue','group','access','setnum',
 1775:           'cnum','cdom','type','setroles','showversions','ref']);
 1776:     my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
 1777:     if ($r->uri =~ m|^(/adm/)([^/]+)|) {
 1778:         $url = $1.$2;
 1779:         $caller = $2;
 1780:     }
 1781:     my ($can_modify,$can_delete,$can_upload,$can_setacl);
 1782:     if ($caller eq 'coursegrp_portfolio') {
 1783:     #  Needs to be in a course
 1784:         if (! ($env{'request.course.fn'})) {
 1785:         # Not in a course
 1786:             $env{'user.error.msg'}=
 1787:      "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
 1788:             return HTTP_NOT_ACCEPTABLE;
 1789:         }
 1790:         my $earlyout = 0;
 1791:         my $view_permission = 
 1792:            &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
 1793:         $env{'form.group'} =~ s/\W//g;
 1794: 	$group = $env{'form.group'};
 1795:         if ($group) {
 1796:             ($uname,$udom) = &get_name_dom();
 1797:             my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
 1798: 							       $group); 
 1799:             if (%curr_groups) {
 1800:                 my %grp_content = &Apache::longroup::get_group_settings(
 1801:                                                          $curr_groups{$group});
 1802:                 $grp_desc = &unescape($grp_content{'description'});
 1803:                 if (($view_permission) || (&Apache::lonnet::allowed('rgf',
 1804:                                       $env{'request.course.id'}.'/'.$group))) {
 1805:                     $portfolio_root = &get_portfolio_root();
 1806:                 } else {
 1807:                     $r->print('You do not have the privileges required to access the shared files space for this group.');
 1808:                     $earlyout = 1;
 1809:                 }
 1810:             } else {
 1811:                 $r->print('Not a valid group for this course');
 1812:                 $earlyout = 1;
 1813:             }
 1814:             $title = &mt('Group files').' for '.$group; 
 1815:         } else {
 1816:             $r->print('Invalid group');
 1817:             $earlyout = 1;
 1818:         }
 1819:         if ($earlyout) { return OK; }
 1820:         if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 1821:             $can_modify = 1;
 1822:             $can_delete = 1;
 1823:             $can_upload = 1;
 1824:             $can_setacl = 1;
 1825:         } else {
 1826:             if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
 1827:                 $can_setacl = 1;
 1828:             }
 1829:             if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
 1830:                 $can_upload = 1;
 1831:             }
 1832:             if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
 1833:                 $can_modify = 1;
 1834:             }
 1835:             if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
 1836:                 $can_delete = 1;
 1837:             }
 1838:         }
 1839:     } else {
 1840:         ($uname,$udom) = &get_name_dom();
 1841:         $portfolio_root = &get_portfolio_root();
 1842:         $title = &mt('Portfolio Manager');
 1843:         $can_modify = 1;
 1844:         $can_delete = 1;
 1845:         $can_upload = 1;
 1846:         $can_setacl = 1;
 1847:     }
 1848: 
 1849:     my $port_path = &get_port_path();
 1850:     &Apache::loncommon::no_cache($r);
 1851:     &Apache::loncommon::content_type($r,'text/html');
 1852:     $r->send_http_header;
 1853:     # Give the LON-CAPA page header
 1854:     if ($env{"form.mode"} eq 'selectfile'){
 1855:         $r->print(&Apache::loncommon::start_page($title,undef,
 1856: 						 {'only_body' => 1}));
 1857:     } elsif ($env{'form.action'} eq 'rolepicker') {
 1858:         $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
 1859:                                                  {'no_nav_bar'  => 1, }));
 1860:     } else {
 1861:         $r->print(&Apache::loncommon::start_page($title));
 1862:     }
 1863:     $r->rflush();
 1864: 	if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
 1865:    	    $r->print('<span class="LC_error">'.
 1866: 		      'No file was selected to upload.'.
 1867: 		      'To upload a file, click <strong>Browse...</strong>'.
 1868: 		      ', select a file, then click <strong>Upload</strong>.'.
 1869: 		      '</span>');
 1870: 	}
 1871:     if ($env{'form.meta'}) {
 1872:         &open_form($r,$url);
 1873: #        $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
 1874:         $r->print('Edit the meta data<br />');
 1875:         &close_form($r,$url);
 1876:     }
 1877:     if ($env{'form.store'}) {
 1878:     }
 1879: 
 1880:     if ($env{'form.uploaddoc.filename'}) {
 1881:         if ($can_upload) {
 1882: 	    &upload($r,$url,$group);
 1883:         } else {
 1884:             &missing_priv($r,$url,'upload');
 1885:         }
 1886:     } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
 1887:         if ($can_delete) {
 1888: 	    &delete_confirmed($r,$url);
 1889:         } else {
 1890:             &missing_priv($r,$url,'delete');
 1891:         }
 1892:     } elsif ($env{'form.action'} eq 'delete') {
 1893:         if ($can_delete) {
 1894: 	    &delete($r,$url);
 1895:         } else {
 1896:             &missing_priv($r,$url,'delete');
 1897:         }
 1898:     } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
 1899:         if ($can_delete) {
 1900: 	    &delete_dir_confirmed($r,$url);
 1901:         } else {
 1902:             &missing_priv($r,$url,'delete');
 1903:         }
 1904:     } elsif ($env{'form.action'} eq 'deletedir') {
 1905:         if ($can_delete) {
 1906: 	    &delete_dir($r,$url);
 1907:         } else {
 1908:             &missing_priv($r,$url,'delete');
 1909:         }
 1910:     } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
 1911:         if ($can_modify) {
 1912: 	    &rename_confirmed($r,$url);
 1913:         } else {
 1914:             &missing_priv($r,$url,'rename');
 1915:         }
 1916:     } elsif ($env{'form.rename'}) {
 1917:         $env{'form.selectfile'} = $env{'form.rename'};
 1918:         $env{'form.action'} = 'rename';
 1919:         if ($can_modify) {
 1920: 	    &rename($r,$url);
 1921:         } else {
 1922:             &missing_priv($r,$url,'rename');
 1923:         }
 1924:     } elsif ($env{'form.access'}) {
 1925:         $env{'form.selectfile'} = $env{'form.access'};
 1926:         $env{'form.action'} = 'chgaccess';
 1927:         &display_access($r,$url,$group,$can_setacl,$port_path);
 1928:     } elsif ($env{'form.action'} eq 'chgaccess') {
 1929:         if ($can_setacl) {
 1930:             &update_access($r,$url,$group,$port_path);
 1931:         } else {
 1932:             &missing_priv($r,$url,'setacl');
 1933:         }
 1934:     } elsif ($env{'form.action'} eq 'rolepicker') {
 1935:         if ($can_setacl) { 
 1936:             &role_options_window($r);
 1937:         } else {
 1938:             &missing_priv($r,$url,'setacl');
 1939:         }
 1940:     } elsif ($env{'form.createdir'}) {
 1941:         if ($can_upload) {
 1942: 	    &createdir($r,$url);
 1943:         } else {
 1944:             &missing_priv($r,$url,'upload');
 1945:         }
 1946:     } elsif ($env{'form.lockinfo'}) {
 1947:         &lock_info($r,$url,$group);
 1948:     } else {
 1949: 	my $current_path='/';
 1950: 	if ($env{'form.currentpath'}) {
 1951: 	    $current_path = $env{'form.currentpath'};
 1952: 	}
 1953:         if ($caller eq 'coursegrp_portfolio') {
 1954:             &Apache::lonhtmlcommon::clear_breadcrumbs();
 1955:             $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
 1956:         }
 1957:         my @dir_list=&get_dir_list($portfolio_root);
 1958: 	if ($dir_list[0] eq 'no_such_dir'){
 1959: 	    # two main reasons for this:
 1960:             #    1) never been here, so directory structure not created
 1961: 	    #    2) back-button navigation after deleting a directory
 1962: 	    if ($current_path eq '/'){
 1963: 	        &Apache::lonnet::mkdiruserfile($uname,$udom,
 1964: 					       &get_port_path());
 1965: 	    } else {
 1966:                 # some directory that snuck in get rid of the directory
 1967:                 # from the recent pulldown, just in case
 1968: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
 1969: 						      [$current_path]);
 1970: 		$current_path = '/'; # force it back to the root        
 1971: 	    }
 1972: 	    # now grab the directory list again, for the first time
 1973: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
 1974: 					    $udom,$uname,$portfolio_root);
 1975:         }
 1976: 	# need to know if directory is empty so it can be removed if desired
 1977: 	my $is_empty=(@dir_list == 2);
 1978: 	&display_common($r,$url,$current_path,$is_empty,\@dir_list,
 1979: 			$can_upload);
 1980:         &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
 1981:                            $can_upload,$can_modify,$can_delete,$can_setacl);
 1982: 	$r->print(&Apache::loncommon::end_page());
 1983:     }
 1984:     return OK;
 1985: }
 1986: 
 1987: 1;
 1988: __END__

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