File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.135: download - view: text, annotated - select for diffs
Tue Jul 18 02:20:19 2006 UTC (17 years, 11 months ago) by banghart
Branches: MAIN
CVS tags: HEAD
	saving work in progress. I think the refactoring is good, we'll see.

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

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