File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.254.2.6: download - view: text, annotated - select for diffs
Tue Dec 14 03:34:43 2021 UTC (2 years, 5 months ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4
- For 2.11
  Backport 1.264, 1.265

    1: # The LearningOnline Network
    2: # portfolio browser
    3: #
    4: # $Id: portfolio.pm,v 1.254.2.6 2021/12/14 03:34:43 raeburn 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 qw(:DEFAULT :match);
   42: 
   43: sub group_args {
   44:     my $output;
   45:     if (defined($env{'form.group'})) {
   46:         $output .= '&group='.$env{'form.group'};
   47: 	if (defined($env{'form.ref'})) {
   48: 	    $output .= '&ref='.$env{'form.ref'};
   49: 	}
   50:     }
   51:     return $output;
   52: }
   53: 
   54: sub group_form_data {
   55:     my $output;
   56:     if (defined($env{'form.group'})) {
   57: 	$output = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />';
   58: 	if (exists($env{'form.ref'})) {
   59: 	    $output .= '<input type="hidden" name="ref" value="'.
   60: 		$env{'form.ref'}.'" />';
   61: 	}
   62:     }
   63:     return $output;
   64: } 
   65: 
   66: # receives a filename and path stub from username/userfiles/portfolio/
   67: # returns an anchor tag consisting encoding filename and currentpath
   68: sub make_anchor {
   69:     my ($url, $anchor_fields, $inner_text) = @_;
   70:     if ($$anchor_fields{'continue'} ne 'true') {$$anchor_fields{'continue'} = 'false'};
   71:     my $anchor = '<a href="'.$url.'?';
   72:     foreach my $field_name (keys(%$anchor_fields)) {
   73:         $anchor .= $field_name.'='.$$anchor_fields{$field_name}.'&amp;';
   74:     }
   75:     $anchor =~ s/&amp;$//;
   76:     $anchor .= &group_args();
   77:     $anchor .= '">'.$inner_text.'</a>';
   78:     return $anchor;
   79: }
   80: 
   81: my $dirptr=16384;
   82: sub display_common {
   83:     my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload,$group)=@_;
   84:     my $namespace = &get_namespace();
   85:     my $port_path = &get_port_path();
   86:     if ($can_upload) {
   87:         my $groupitem = &group_form_data();
   88: 
   89:         my $iconpath= $r->dir_config('lonIconsURL') . "/";
   90:         my %lt=&Apache::lonlocal::texthash(
   91:                    'upload'          => 'Upload',
   92:                    'upload_label'    => 'Upload file to current directory',
   93:                    'createdir'       => 'Create Subdirectory',
   94:                    'createdir_label' => 'Create subdirectory in current directory',
   95:                    'parse'           => 'Upload embedded images/multimedia/css/linked files if HTML file',
   96:                );
   97:         my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
   98: 	my $help_fileupload = &Apache::loncommon::help_open_topic('Portfolio AddFiles');
   99: 	my $help_createdir = &Apache::loncommon::help_open_topic('Portfolio CreateDirectory');
  100:         my $help_portfolio = &Apache::loncommon::help_open_topic('Portfolio About', &mt('Help on the portfolio'));
  101:         $r->print(&display_portfolio_usage($group,$help_portfolio));
  102:         my $parse_check;
  103:         if (!&suppress_embed_prompt()) {
  104:             $parse_check = <<"END";
  105:         <br />
  106:         <span class="LC_nobreak">
  107:          <label>
  108:           <input type="checkbox" name="parserflag" checked="checked" />
  109:           $lt{'parse'}
  110:          </label>
  111:         </span>
  112: END
  113:         }
  114: 
  115:         # Find space available before uploading
  116:         my $free_space = &free_space($group);
  117: 
  118:         # Upload File
  119:         $r->print('<div class="LC_left_float">'
  120:                  .'<form method="post" enctype="multipart/form-data" action="'.$escuri.'">'
  121:                  .'<fieldset>'
  122:                  .'<legend>'.$lt{'upload_label'}.'</legend>'
  123:                  .$groupitem 
  124:                  .'<input name="uploaddoc" type="file" class="LC_flUpload" />'
  125:                  .'<input type="hidden" id="LC_free_space" value="'.$free_space.'" />'
  126:                  .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
  127:                  .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
  128:                  .'<input type="hidden" name="symb" value="'.$env{"form.symb"}.'" />'
  129:                  .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
  130:                  .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
  131:                  .'<input type="submit" name="storeupl" value="'.$lt{'upload'}.'" />'
  132:                  .$help_fileupload
  133:                  .$parse_check
  134:                  .'</fieldset>'
  135:                  .'</form>'
  136:                  .'</div>'
  137:         );
  138:         # Create Subdirectory
  139:         $r->print('<div class="LC_left_float">'
  140:                  .'<form method="post" action="'.$escuri.'">'
  141:                  .'<fieldset>'
  142:                  .'<legend>'.$lt{'createdir_label'}.'</legend>'
  143:                  .'<input name="newdir" type="text" />'.$groupitem
  144:                  .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
  145:                  .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
  146:                  .'<input type="hidden" name="symb" value="'.$env{"form.symb"}.'" />'
  147:                  .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
  148:                  .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
  149:                  .'<input type="submit" name="createdir" value="'.$lt{'createdir'}.'" />'
  150:                  .$help_createdir
  151:                  .'</fieldset>'
  152:                  .'</form>'
  153:                  .'</div>'
  154:         );
  155:     } # end "if can_upload"
  156: 
  157:     my @tree = split (/\//,$current_path);
  158:     my %anchor_fields = (
  159:         'selectfile'    => $port_path,
  160:         'currentpath'   => '/',
  161:         'mode'          => $env{"form.mode"},
  162:         'symb'          => $env{"form.symb"},
  163:         'fieldname'     => $env{"form.fieldname"},
  164:         'continue'      => $env{"form.continue"}
  165:     );
  166:     $r->print('<br clear="all" />');
  167:     $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
  168:     if (@tree > 1){
  169:         my $newCurrentPath = '/';
  170:         for (my $i = 1; $i< @tree; $i++){
  171:             $newCurrentPath .= $tree[$i].'/';
  172:             my %anchor_fields = (
  173:                 'selectfile' => $tree[$i],
  174:                 'currentpath' => $newCurrentPath,
  175:                 'mode' => $env{"form.mode"},
  176:                 'symb' => $env{"form.symb"},
  177:                 'fieldname' => $env{"form.fieldname"},
  178:                 'continue' => $env{"form.continue"}
  179:             );
  180:             $r->print(&make_anchor($url,\%anchor_fields,$tree[$i]).'/');
  181:         }
  182:     }
  183:     $r->print('</span>');
  184:     $r->print(&Apache::loncommon::help_open_topic('Portfolio ChangeDirectory'));
  185:     &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
  186:     $r->print('<br /><form method="post" action="'.$url.'?mode='.$env{"form.mode"}.'&amp;fieldname='.$env{"form.fieldname"}.'&amp;symb='.$env{'form.symb'}.&group_args());
  187:     $r->print('">'.
  188: 	      &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
  189: 						    'this.form.submit();'));
  190:     $r->print("</form>");
  191: }
  192: 
  193: sub display_portfolio_usage {
  194:     my ($group,$helpitem) = @_;
  195:     my $disk_quota = &get_quota($group);
  196:     my $getpropath = 1;
  197:     my $portfolio_root = &get_portfolio_root();
  198:     my ($uname,$udom) = &get_name_dom($group);
  199:     my $current_disk_usage =
  200:          &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
  201:     return &Apache::loncommon::head_subbox(
  202:                      '<div style="float:right;padding-top:0;margin-top;0">'
  203:                     .$helpitem
  204:                     .'</div>'
  205:                     .'<div>'
  206:                     .&Apache::lonhtmlcommon::display_usage($current_disk_usage,
  207:                                                            $disk_quota,'portfolio')
  208:                     .'</div>');
  209: }
  210: 
  211: sub display_directory_line {
  212:     my ($r,$select_mode, $filename, $mtime, $size, $css_class,
  213: 	$line, $access_controls, $curr_access, $now, $version_flag,
  214: 	$href_location, $url, $current_path, $access_admin_text, $versions)=@_;
  215: 
  216:     my $fullpath =  &prepend_group($current_path.$filename);
  217:     $r->print(&Apache::loncommon::start_data_table_row());
  218:     $r->print($line); # contains first two cells of table
  219:     my $lock_info;
  220:     if ($version_flag) { # versioned can't be versioned, so TRUE when root file
  221:         $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" class="LC_fileicon" /></td>');
  222:         $r->print('<td>'.$version_flag.'</td>');
  223:     } else { # this is a graded or handed back file
  224:         my ($user,$domain) = &get_name_dom($env{'form.group'});
  225:         my $permissions_hash = &Apache::lonnet::get_portfile_permissions($domain,$user);
  226:         if (defined($$permissions_hash{$fullpath})) {
  227:             foreach my $array_item (@{$$permissions_hash{$fullpath}}) {
  228:                 if (ref($array_item) eq 'ARRAY') {
  229:                     if ($$array_item[-1] eq 'handback') {
  230:                         $lock_info = 'Handback';
  231:                     } elsif ($$array_item[-1] eq 'graded') {
  232:                         $lock_info = 'Graded';
  233:                     }
  234:                  }
  235:             }
  236:         }
  237: 	if ($lock_info) {
  238: 	    my %anchor_fields = ('lockinfo' => $fullpath);
  239: 	    if ($versions) { # hold the folder open
  240: 	        my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($fullpath);
  241: 	        $fname =~ s|^/||;
  242: 	        $anchor_fields{'showversions'} = $fname.'.'.$extension;
  243: 	    }
  244: 	    $lock_info = &make_anchor(undef,\%anchor_fields,$lock_info);
  245: 	}
  246: 	$r->print('<td colspan="2">'.$lock_info.'</td>');
  247:     }
  248:     # $r->print('<td>'.$$version_flag{$filename}.'</td><td>');
  249:     $r->print('<td>'.&make_anchor($href_location.$filename,undef,$filename).'</td>'); 
  250:     $r->print('<td>'.$size.'</td>');
  251:     $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
  252:     if ($select_mode ne 'true') {
  253:         $r->print('<td class="'.$css_class.'">&nbsp;&nbsp;</td>'); # Display status
  254:         $r->print('<td><span class="LC_nobreak">'
  255:                  .&mt($curr_access).'&nbsp;&nbsp;&nbsp;'
  256:        );
  257:         my %anchor_fields = (
  258:             'access' => $filename,
  259:             'currentpath' => $current_path
  260:         );
  261: 	$r->print(&make_anchor($url, \%anchor_fields, $access_admin_text).'</span></td>');
  262:     } else {
  263:         $r->print('<td class="'.$css_class.'">&nbsp;&nbsp;</td>'); # Display status
  264:     }
  265:     $r->print(&Apache::loncommon::end_data_table_row().$/);
  266: }
  267: 
  268: sub display_directory {
  269:     my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
  270:         $can_modify,$can_delete,$can_setacl)=@_;
  271:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
  272:     my $select_mode;
  273:     my $checked_files;
  274:     my $port_path = &get_port_path();
  275:     my ($uname,$udom) = &get_name_dom($group);
  276:     my $access_admin_text = &mt('View Status');
  277:     if ($can_setacl) {
  278:         $access_admin_text = &mt('View/Change Status');
  279:     }
  280: 
  281:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
  282:                                                                         $uname);
  283:     my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
  284:                                                   $current_permissions,$group);
  285:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
  286:     my $now = time;
  287:     if ($env{"form.mode"} eq 'selectfile') {
  288:         &select_files($r,$dir_list);
  289:         $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
  290:         $select_mode = 'true';
  291:     }
  292:     if ($select_mode eq 'true') {
  293:         $r->print('<form method="post" name="checkselect" action="'.$url.'">');
  294:         $r->print(&Apache::loncommon::start_data_table()
  295:                  .&Apache::loncommon::start_data_table_header_row()
  296:                  .'<th>'.&mt('Select').'</th>'
  297:                  .'<th>&nbsp;</th>'
  298:                  .'<th>&nbsp;</th>'
  299:                  .'<th>'.&mt('Name').'</th>'
  300:                  .'<th>'.&mt('Size').'</th>'
  301:                  .'<th>'.&mt('Last Modified').'</th>'
  302:                  .'<th>&nbsp;</th>'
  303:                  .&Apache::loncommon::end_data_table_header_row()
  304:         );
  305:     } else {
  306:         $r->print('<form method="post" action="'.$url.'">');
  307:         $r->print(
  308:             '<p>'
  309:            .&Apache::loncommon::help_open_topic(
  310:                 'Portfolio FileList',
  311:                 &mt('Using the portfolio file list'))
  312:            .'</p>'
  313:         );
  314:         $r->print(&Apache::loncommon::start_data_table()
  315:                  .&Apache::loncommon::start_data_table_header_row()
  316:                  .'<th colspan="2">'.&mt('Actions'). &Apache::loncommon::help_open_topic('Portfolio FileAction').'</th>'
  317:                  .'<th>&nbsp;</th>'
  318:                  .'<th>&nbsp;</th>'
  319:                  .'<th>'.&mt('Name').&Apache::loncommon::help_open_topic('Portfolio OpenFile').'</th>'
  320:                  .'<th>'.&mt('Size').'</th>'
  321:                  .'<th>'.&mt('Last Modified').'</th>'
  322:                  .'<th>&nbsp;</th>'
  323:                  .'<th>'.&mt('Current Access Status').&Apache::loncommon::help_open_topic('Portfolio ShareFile').'</th>'
  324:                  .&Apache::loncommon::end_data_table_header_row());
  325:     }
  326: 
  327:     # Empty directory?
  328:     if ($is_empty && ($current_path ne '/') && $can_delete) {
  329:         my $cols = ($select_mode eq 'true') ? 7 : 9;
  330:         # Empty message
  331:         $r->print(
  332:             &Apache::loncommon::start_data_table_row()
  333:            .'<td colspan="'.$cols.'">'
  334:            .'<p class="LC_info">'
  335:            .&mt('This directory is empty.')
  336:            .'</p>'
  337:            .'</td>'
  338:            .&Apache::loncommon::end_data_table_row()
  339:            .&Apache::loncommon::end_data_table()
  340:            .'</form>'
  341:         );
  342:         # Delete button
  343:         $r->print(
  344:             '<form method="post" action="'.$url.'">'.
  345:             &group_form_data().
  346:             '<input type="hidden" name="action" value="deletedir" />'.
  347:             '<p>'.
  348:             '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
  349:             '</p>'.
  350:             '<input type="hidden" name="selectfile" value="" />'.
  351:             '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
  352:             '</form>'
  353:         );
  354:         # Directory is empty, so nothing else to display
  355:         return;
  356:     }
  357: 
  358:     $r->print("\n".&group_form_data()."\n");
  359: 
  360:     my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
  361:     my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
  362:     my @dir_lines;
  363:     my %versioned;
  364:     if (ref($dir_list) eq 'ARRAY') { 
  365:         foreach my $dir_line (sort 
  366: 		          { 
  367: 			      my ($afile)=split('&',$a,2);
  368: 			      my ($bfile)=split('&',$b,2);
  369: 			      return (lc($afile) cmp lc($bfile));
  370: 		          } (@{$dir_list})) {
  371:     	    my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16); 
  372:     	    $filename =~ s/\s+$//;
  373:     	    my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
  374:     	    if ($version) {
  375: 	        my $fullpath = &prepend_group($current_path.$fname.'.'.$extension);
  376:     	        push(@{ $versioned{$fullpath} },
  377: 		     [$filename,$dom,$testdir,$size,$mtime,$obs,]);
  378:     	    } else {
  379:     	        push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
  380:     	    }
  381:         }
  382:     }
  383:     my $zerobyte;
  384:     foreach my $dir_line (@dir_lines) {
  385:         my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line;
  386:         my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
  387:     	if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
  388:     	    my $version_flag;
  389:     	    my $show_versions;
  390: 	    my $fullpath =  &prepend_group($current_path.$filename);
  391:     	    if ($env{'form.showversions'} =~ /$filename/) {
  392:     	        $show_versions = 'true';
  393:     	    }
  394:     	    if (exists($versioned{$fullpath})) {
  395:     	        my %anchor_fields = (
  396:     	            'selectfile' => $fullpath,
  397:     	            'continue' => 'false',
  398:     	            'currentpath' => $current_path,
  399:     	        );
  400:     	        if ($show_versions) {
  401:     	            # Must preserve other possible showversion files
  402:     	            my $version_remainder = $env{'form.showversions'};
  403:     	            $version_remainder =~ s/$filename//g;    	            
  404:     	            $anchor_fields{'showversions'} = $version_remainder;
  405:                     $version_flag = &make_anchor('portfolio',\%anchor_fields,
  406:                         '<img class="LC_icon" alt="'.&mt('opened folder').'" src="'.$iconpath.'folder_pointer_opened.gif" />');
  407:     	        } else {
  408:     	            # allow multiple files to show versioned
  409:     	            $anchor_fields{'showversions'} = $env{'form.showversions'}.','.$filename;
  410:                     $version_flag = &make_anchor('portfolio',\%anchor_fields,
  411:                         '<img class="LC_icon" alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_pointer_closed.gif" />');
  412:                 }
  413:     	    } else {
  414:     	        $version_flag = '&nbsp;';
  415:     	    }
  416:             if ($dirptr&$testdir) {
  417: 		my $colspan_folder='';
  418: 		my $colspan_fill='';
  419:                 if ($select_mode eq 'true'){
  420:                     $colspan_fill=' colspan="3"';
  421:                 } else {
  422:                     $colspan_folder=' colspan="2"';
  423:                     $colspan_fill=' colspan="4"';
  424:                 }
  425: 		$r->print('<tr class="LC_browser_folder">');
  426:                 $r->print('<td'.$colspan_folder.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'navmap.folder.closed.gif" class="LC_fileicon" /></td>'
  427:                          .'<td>'.&mt('Go to ...').'</td>');
  428:                 my %anchor_fields = (
  429:                     'selectfile'    => $filename.'/',
  430:                     'currentpath'   => $current_path.$filename.'/',
  431:                     'mode'          => $env{"form.mode"},
  432:                     'symb'          => $env{"form.symb"},
  433:                     'fieldname'     => $env{"form.fieldname"},
  434:                     'continue'      => $env{"form.continue"}
  435:                 );  
  436:                 $r->print('<td>'.$version_flag.'</td>'
  437:                          .'<td>'.&make_anchor($url,\%anchor_fields,$filename.'/').'</td>'); 
  438:                 $r->print('<td'.$colspan_fill.'>&nbsp;</td>');
  439:                 $r->print('</tr>'); 
  440:             } else {
  441: 		my $css_class = 'LC_browser_file';
  442: 		my $line;
  443:                 if ($select_mode eq 'true') {
  444:                     if ($size > 0) {
  445:                         $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"';
  446: 		        if ($$checked_files{$filename} eq 'selected') {
  447:                             $line.=' checked="checked" ';
  448:                         }
  449: 		        $line.=' /></td>';
  450:                     } else {
  451:                         $line = '<td>&nbsp;</td>';
  452:                         $zerobyte ++;
  453:                     }
  454:                 } else {
  455:                     if (exists $locked_files{$fullpath}) {
  456:                         my %anchor_fields = (
  457:                             'lockinfo' => $fullpath
  458:                         );
  459:                         $line.='<td colspan="2">'.&make_anchor($url,\%anchor_fields,&mt('Locked')).'</td>';
  460: 			$css_class= 'LC_browser_file_locked';
  461:                     } else {
  462:                         if (!$can_modify) {
  463:                             $line .= '<td colspan="2">';
  464:                         } else {
  465:                             $line .= '<td>';
  466:                         }
  467:                         if ($can_delete) {
  468:                             $line .= '<input type="checkbox" name="selectfile" value="'.$filename.'" />';
  469:                         }
  470:                         if ($can_modify) {
  471:                             my $cat='<img class="LC_icon" alt="'.&mt('Metadata').'" title="'.&mt('Metadata').'" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.png').'" />';
  472:                             my %anchor_fields = (
  473:                                 'rename' => $filename,
  474:                                 currentpath => $current_path
  475:                             );
  476:                             $line .= &make_anchor($url,\%anchor_fields,&mt('Rename'));
  477:                             $line .= '</td><td>'.&make_anchor($href_edit_location.$filename.'.meta',\%anchor_fields,$cat);
  478:                             # '<a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>';
  479:                         }
  480:                         $line .= '</td>';
  481:                     }
  482:                 }
  483: 		my $curr_access;
  484: 		if ($select_mode ne 'true') {
  485: 		    my $pub_access = 0;
  486: 		    my $guest_access = 0;
  487: 		    my $cond_access = 0;
  488: 		    foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
  489: 			my ($num,$scope,$end,$start) = &unpack_acc_key($key);
  490: 			if (($now > $start) && (!$end || $end > $now)) {
  491: 			    if ($scope eq 'public')  {
  492: 				$pub_access = 1;
  493: 			    } elsif ($scope eq 'guest') {
  494: 				$guest_access = 1;
  495: 			    } else {
  496: 				$cond_access = 1;
  497: 			    }
  498: 			}
  499: 		    }
  500: 		    if (!$pub_access && !$guest_access && !$cond_access) {
  501: 			$curr_access = &mt('Private');
  502: 		    } else {
  503: 			my @allaccesses; 
  504: 			if ($pub_access) {
  505: 			    push(@allaccesses,&mt('Public'));
  506: 			}
  507: 			if ($guest_access) {
  508: 			    push(@allaccesses,&mt('Passphrase-protected'));
  509: 			}
  510: 			if ($cond_access) {
  511: 			    push(@allaccesses,&mt('Conditional'));
  512: 			}
  513: 			$curr_access = join('+ ',@allaccesses);
  514: 		    }
  515: 		}
  516:                 &display_directory_line($r,$select_mode, $filename, $mtime, $size, $css_class, $line, 
  517:                                         \%access_controls, $curr_access,$now, $version_flag, $href_location, 
  518:                                         $url, $current_path, $access_admin_text);
  519: 		if ($show_versions) {
  520: 		    foreach my $dir_line (@{ $versioned{$fullpath} }) {
  521: 		        my ($v_filename,$dom,$testdir,$size,$mtime,$obs) =
  522: 			    @$dir_line;
  523:                         $line = '<td colspan="2">&nbsp;</td>';
  524: 			&display_directory_line($r,$select_mode, $v_filename, $mtime, $size, 
  525: 						$css_class, $line, \%access_controls, $curr_access, $now,
  526: 						undef, $href_location, $url, $current_path, $access_admin_text, 1);
  527: 		    }
  528: 		}
  529:             }
  530:         }
  531:     }
  532:     if ($select_mode eq 'true') {
  533:         $r->print(&Apache::loncommon::end_data_table());
  534:         if ($zerobyte) {
  535:             $r->print('<p class="LC_warning">'.&mt('[quant,_1,file] in list not selectable as file size is 0 bytes.',$zerobyte).'</p>');
  536:         }
  537:         $r->print('
  538:             <input type="hidden" name="continue" value="true" />
  539:             <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" />
  540:             <input type="hidden" name="symb" value="'.$env{'form.symb'}.'" />
  541:             <input type="hidden" name="mode" value="selectfile" />
  542:             <p>
  543:             <input type="submit" name="submit" value="'.&mt('Select checked files, and continue selecting').'" /><br />
  544:             <input type="button" name="doit" onclick="finishSelect();" value="'.&mt('Select checked files, and close window').'" />
  545:             </p>
  546:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
  547:         </form>');        
  548:     } else {
  549:         $r->print(&Apache::loncommon::end_data_table());
  550:         if ($can_delete) {
  551:             $r->print('
  552:         <p>
  553:         <input type="submit" name="doit" value="'.&mt('Delete Selected').'" />'.
  554: 	&Apache::loncommon::help_open_topic('Portfolio DeleteFile').'
  555:         </p>
  556:         <input type="hidden" name="action" value="delete" />
  557:         <input type="hidden" name="currentpath" value="'.$current_path.'" />
  558:         </form>'
  559:             );
  560:         }
  561:     }
  562: }
  563: 
  564: sub open_form {
  565:     my ($r,$url)=@_;
  566:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  567:     $r->print('<form name="portform" method="post" action="'.$url.'">');
  568:     $r->print('<input type="hidden" name="action" value="'.
  569: 	      $env{'form.action'}.'" />');
  570:     $r->print('<input type="hidden" name="confirmed" value="1" />');
  571:     foreach (@files) {
  572:         $r->print('<input type="hidden" name="selectfile" value="'.
  573: 	      $_.'" />');
  574:     }
  575:     $r->print('<input type="hidden" name="currentpath" value="'.
  576: 	      $env{'form.currentpath'}.'" />');
  577: }
  578: 
  579: sub close_form {
  580:     my ($r,$url,$button_text)=@_;
  581:     if (!defined($button_text)) {
  582:         $button_text = {
  583:                          'continue' => &mt('Continue'),
  584:                          'cancel'   => &mt('Cancel'),
  585:                        };
  586:     }
  587:     $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
  588:     $r->print(&group_form_data().'</p></form>');
  589:     $r->print('<form action="'.$url.'" method="post">
  590:                <p>
  591:               <input type="hidden" name="currentpath" value="'.
  592: 	      $env{'form.currentpath'}.'" />'.
  593: 	      &group_form_data());
  594:     $r->print("\n".'   <input type="submit" value="'.$button_text->{'cancel'}.'" />
  595:                </p></form>'); 
  596: }
  597: 
  598: sub display_file {
  599:     my ($path,$filename)=@_;
  600:     my $display_file_text;
  601:     my $file_start='<span class="LC_filename">';
  602:     my $file_end='</span>';
  603:     if (!defined($path)) { $path=$env{'form.currentpath'}; }
  604:     if (!defined($filename)) { 
  605:         $filename=$env{'form.selectfile'};
  606:         $display_file_text = $file_start.$path.$filename.$file_end;
  607:     } elsif (ref($filename) eq "ARRAY") {
  608:         foreach my $file (@$filename) {
  609:             $display_file_text .= $file_start.$path.$file.$file_end.'<br />';
  610:         }
  611:     } elsif (ref($filename) eq "SCALAR") {
  612:         $display_file_text = $file_start.$path.$$filename.$file_end;
  613:     } else {
  614: 	$display_file_text = $file_start.$path.$filename.$file_end;
  615:     }
  616:     return $display_file_text;
  617: }
  618: 
  619: sub done {
  620:     my ($linktext,$url)=@_;
  621:     unless (defined($linktext)) {
  622:         $linktext='Return to directory';
  623:     }
  624:     my %anchor_fields = (
  625:         'showversions' => $env{'form.showversions'},
  626:         'currentpath' => $env{'form.currentpath'},
  627:         'fieldname' => $env{'form.fieldname'},
  628:         'symb'      => $env{'form.symb'},
  629:         'mode'      => $env{'form.mode'}
  630:     );
  631:     my $result = &Apache::lonhtmlcommon::actionbox(
  632:                      [&make_anchor($url,\%anchor_fields,&mt($linktext))]);
  633:     return $result;
  634: }
  635: 
  636: sub delete {
  637:     my ($r,$url,$group)=@_;
  638:     my @check;
  639:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
  640:     $file_name = &prepend_group($file_name);
  641:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  642:     my ($uname,$udom) = &get_name_dom($group);
  643:     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
  644:         $r->print(
  645:             '<p class="LC_warning">'
  646:            .&mt('The file is locked and cannot be deleted.')
  647:            .'</p>'
  648:            .&done(undef,$url)
  649:         );
  650:     } else {
  651:         if (scalar(@files)) {
  652:             &open_form($r,$url);
  653:             $r->print('<p>'.&mt('Delete [_1]?',&display_file(undef,\@files)).'</p>');
  654:             &close_form($r,$url);
  655:         } else {
  656:             $r->print('<p class="LC_warning">'.&mt('No file was checked to delete.').'</p>');
  657:             $r->print(&done(undef,$url));
  658:         }
  659:     }
  660: } 
  661: 
  662: sub delete_confirmed {
  663:     my ($r,$url,$group)=@_;
  664:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  665:     my $result;
  666:     my ($uname,$udom) = &get_name_dom($group);
  667:     my $port_path = &get_port_path();
  668:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
  669:                                                                         $uname);
  670:     my @msg;
  671:     foreach my $delete_file (@files) {
  672:         $result =
  673:             &Apache::lonnet::removeuserfile(
  674:                 $uname,$udom,$port_path.
  675:                 $env{'form.currentpath'}.
  676:                 $delete_file);
  677:         if ($result ne 'ok') {
  678:             push(@msg, &Apache::lonhtmlcommon::confirm_success(
  679:                 &mt('An error occurred ([_1]) while trying to delete [_2].'
  680:                     ,$result,&display_file(undef, $delete_file)),1));
  681:         } else {
  682:             push(@msg, &Apache::lonhtmlcommon::confirm_success(
  683:                 &mt('File: [_1] deleted.'
  684:                     ,&display_file(undef,$delete_file))));
  685:             my $file_name = $env{'form.currentpath'}.$delete_file;
  686:             $file_name = &prepend_group($file_name);
  687:             my %access_controls = 
  688:                     &Apache::lonnet::get_access_controls($current_permissions,
  689:                                                          $group,$file_name);
  690:             if (keys(%access_controls) > 0) {
  691:                 my %changes; 
  692:                 foreach my $key (keys(%{$access_controls{$file_name}})) {
  693:                     $changes{'delete'}{$key} = 1;
  694:                 }
  695:                 if (keys(%changes) > 0) {
  696:                     my ($outcome,$deloutcome,$new_values,$translation) =
  697:                     &Apache::lonnet::modify_access_controls($file_name,\%changes,
  698:                                                             $udom,$uname);
  699:                     if ($outcome ne 'ok') {
  700:                         push(@msg, &Apache::lonhtmlcommon::confirm_success(
  701:                             &mt('An error occurred ([_1]) while '.
  702:                                 'trying to delete access controls for the file.',$outcome),1));
  703:                     } else {
  704:                         if ($deloutcome eq 'ok') {
  705:                             push(@msg, &mt('Access controls also deleted for the file.')); # FIXME: Does the user really need this message?
  706:                         } else {
  707:                             push(@msg, &Apache::lonhtmlcommon::confirm_success(
  708:                                 &mt('An error occurred ([_1]) while '.
  709:                                     'trying to delete access controls for the file.'
  710:                                     ,$deloutcome),1));
  711:                         }
  712:                     }
  713:                 }
  714:             }
  715:         }
  716:     }
  717:     $r->print(&Apache::loncommon::confirmwrapper(join('<br />',@msg)));
  718:     $r->print(&done(undef,$url));
  719: }
  720: 
  721: sub delete_dir {
  722:     my ($r,$url)=@_;
  723:     &open_form($r,$url);
  724:      $r->print('<p>'.&mt('Delete [_1]?',&display_file()).'</p>');
  725:     &close_form($r,$url);
  726: } 
  727: 
  728: sub delete_dir_confirmed {
  729:     my ($r,$url,$group)=@_;
  730:     my $directory_name = $env{'form.currentpath'};
  731:     $directory_name =~ s|/$||; # remove any trailing slash
  732:     my ($uname,$udom) = &get_name_dom($group);
  733:     my $namespace = &get_namespace();
  734:     my $port_path = &get_port_path();
  735:     my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
  736: 					       $directory_name);
  737:        
  738:     if ($result ne 'ok') {
  739:         $r->print(
  740:             &Apache::loncommon::confirmwrapper(
  741:                 &Apache::lonhtmlcommon::confirm_success(
  742:                     &mt('An error occurred (dir) ([_1]) while trying to delete [_2].'
  743:                         ,$result,$directory_name),1)));
  744:         $r->print(&done(undef,$url));
  745:         return;
  746:     } else {
  747:         # now remove from recent
  748:         &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
  749:         my @dirs = split m!/!, $directory_name;
  750:         $directory_name='/';
  751:         for (my $i=1; $i < (@dirs - 1); $i ++){
  752:             $directory_name .= $dirs[$i].'/';
  753:         }
  754:         $env{'form.currentpath'} = $directory_name;
  755:     }
  756:     $r->print(
  757:         &Apache::loncommon::confirmwrapper(
  758:             &Apache::lonhtmlcommon::confirm_success(
  759:                 &mt('Directory successfully deleted'))));
  760:     $r->print(&done(undef,$url));
  761: }
  762: 
  763: sub rename {
  764:     my ($r,$url,$group)=@_;
  765:     my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
  766:     my ($uname,$udom) = &get_name_dom($group);
  767:     $file_name = &prepend_group($file_name);
  768:     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
  769:         $r->print(
  770:             '<p class="LC_error">'
  771:            .&mt('The file is locked and cannot be renamed.')
  772:            .'</p>'
  773:         );
  774:         $r->print(&done(undef,$url));
  775:     } else {
  776:         &open_form($r,$url);
  777:         $r->print('<p>'.&mt('Rename [_1] to [_2]?', &display_file()
  778:                   , '<input name="filenewname" type="text" size="50" />').'</p>');
  779:         &close_form($r,$url);
  780:     }
  781: }
  782: 
  783: sub rename_confirmed {
  784:     my ($r,$url,$group)=@_;
  785:     my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
  786:     my ($uname,$udom) = &get_name_dom($group);
  787:     my $port_path = &get_port_path();
  788: 
  789:     # Display warning in case of filename cleaning has changed the filename
  790:     if ($filenewname ne $env{'form.filenewname'}) {
  791:         $r->print(
  792:             '<p><span class="LC_warning">'
  793:            .&mt('Invalid characters')
  794:            .'</span><br />'
  795:            .&mt('The new filename was changed from [_1] to [_2].'
  796:                ,'<span class="LC_filename">'.&display_file('',$env{'form.filenewname'}).'</span>'
  797:                ,'<span class="LC_filename">'.&display_file('',$filenewname).'</span>')
  798:            .'</p>'
  799:         );
  800:                 
  801:     }
  802: 
  803:     # Filename empty?
  804:     if ($filenewname eq '') {
  805:         $r->print(
  806:             &Apache::loncommon::confirmwrapper(
  807:                 &Apache::lonhtmlcommon::confirm_success(
  808:                     &mt('Error: no valid filename was provided to rename to.'),1)));
  809:         $r->print(&done(undef,$url));
  810:         return;
  811:     } 
  812: 
  813:    # Rename the file
  814:     my $chg_access;
  815:     my $result=
  816: 	&Apache::lonnet::renameuserfile($uname,$udom,
  817:             $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
  818:             $port_path.$env{'form.currentpath'}.$filenewname);
  819:     if ($result eq 'ok') {
  820:         $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
  821:     } else {      
  822:         $r->print(
  823:             &Apache::loncommon::confirmwrapper(
  824:                 &Apache::lonhtmlcommon::confirm_success(
  825:                     &mt('An error occurred ([_1]) while trying to rename [_2] to [_3].'
  826:                         ,$result,&display_file(),&display_file('',$filenewname))
  827:                     ,1)));
  828:         $r->print(&done(undef,$url));
  829:         return;
  830:     }
  831:     $r->print($chg_access);
  832:     $r->print(
  833:         &Apache::loncommon::confirmwrapper(
  834:             &Apache::lonhtmlcommon::confirm_success(
  835:                 &mt('File successfully renamed'))));
  836:     $r->print(&done(undef,$url));
  837: }
  838: 
  839: sub access_for_renamed {
  840:     my ($filenewname,$group,$udom,$uname) = @_;
  841:     my $oldfile = $env{'form.currentpath'}.$env{'form.selectfile'};
  842:     $oldfile = &prepend_group($oldfile);
  843:     my $newfile = $env{'form.currentpath'}.$filenewname;
  844:     $newfile = &prepend_group($newfile);
  845:     my $current_permissions =
  846: 	&Apache::lonnet::get_portfile_permissions($udom,$uname);
  847:     my %access_controls =
  848: 	&Apache::lonnet::get_access_controls($current_permissions,
  849: 					     $group,$oldfile);
  850:     my $chg_text;
  851:     if (keys(%access_controls) > 0) {
  852:         my %change_old;
  853:         my %change_new;
  854:         foreach my $key (keys(%{$access_controls{$oldfile}})) {
  855:             $change_old{'delete'}{$key} = 1;
  856:             $change_new{'activate'}{$key} = $access_controls{$oldfile}{$key};
  857:         }
  858:         my ($outcome,$deloutcome,$new_values,$translation) =
  859:             &Apache::lonnet::modify_access_controls($oldfile,\%change_old,
  860: 						    $udom,$uname);
  861:         if ($outcome ne 'ok') {
  862:             $chg_text ='<br /><br />'.&mt("An error occurred ([_1]) while ".
  863:                 "trying to delete access control records for the old name.",$outcome).
  864:                 '</span><br />';
  865:         } else {
  866:             if ($deloutcome ne 'ok') {
  867:                 $chg_text = '<br /><br /><span class="LC_error"><br />'.
  868: 		    &mt("An error occurred ([_1]) while ".
  869: 			"trying to delete access control records for the old name.",$deloutcome).
  870: 			'</span><br />';
  871:             }
  872:         }
  873:         ($outcome,$deloutcome,$new_values,$translation) =
  874:             &Apache::lonnet::modify_access_controls($newfile,\%change_new,
  875:                                                     $udom,$uname);
  876:         if ($outcome ne 'ok') {
  877:             $chg_text .= '<br /><br />'.
  878: 		&mt("An error occurred ([_1]) while ".
  879:                 "trying to update access control records for the new name.",$outcome).
  880:                 '</span><br />';
  881:         }
  882:         if ($chg_text eq '') {
  883:             $chg_text = '<br /><br />'.&mt('Access controls updated to reflect the name change.');
  884:         }
  885:     }
  886:     return $chg_text;
  887: }
  888: 
  889: sub display_access {
  890:     my ($r,$url,$group,$can_setacl,$port_path,$action) = @_;
  891:     my ($uname,$udom) = &get_name_dom($group);
  892:     my $file_name = $env{'form.currentpath'}.$env{'form.access'};
  893:     $file_name = &prepend_group($file_name);
  894:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
  895:                                                                         $uname);
  896:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
  897:     my $aclcount = keys(%access_controls);
  898:     my ($header,$info);
  899:     if ($action eq 'chgaccess') {
  900:         $header =
  901:             '<h2>'
  902:             .&mt('Allowing others to retrieve file: [_1]'
  903:                  ,'<span class="LC_filename">'
  904:                  .$port_path.$env{'form.currentpath'}.$env{'form.access'}
  905:                  .'</span>')
  906:             .'</h2>';
  907:         $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.');
  908:         $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');
  909:         $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
  910:         $info .= '</li><li>'.&explain_conditionals();
  911:         $info .= '</li></ul>'.
  912:                   &mt('A listing of files viewable without log-in is available at: ')."<a href=\"/adm/$udom/$uname/aboutme/portfolio\">".&Apache::lonnet::absolute_url()."/adm/$udom/$uname/aboutme/portfolio</a>.<br />";
  913:         if ($group eq '') {
  914:             $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:");
  915:         } else {
  916:             $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:");
  917:         }
  918:         $info .= "<br /><a href=\"/adm/$udom/$uname/aboutme\">".&Apache::lonnet::absolute_url()."/adm/$udom/$uname/aboutme</a><br />";
  919:         if ($group ne '') {
  920:             $info .= &mt("Users with course editing rights may add a 'Group Portfolio' item using the Course Editor (Collaboration tab), to provide access to viewable group portfolio files.").'<br />';
  921:         }
  922:     } else {
  923:         $header = '<h3>'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>'.
  924:                   &explain_conditionals().'<br />';
  925:     }
  926:     if ($can_setacl) {
  927:         &open_form($r,$url);
  928:         $r->print($header.$info);
  929: 	$r->print('<br />'.&Apache::loncommon::help_open_topic('Portfolio ShareFile SetAccess', &mt('Help on setting up share access')));
  930: 	$r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile ChangeSetting', &mt('Help on changing settings')));
  931: 	$r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile StopAccess', &mt('Help on removing share access')));
  932:         &access_setting_table($r,$url,$file_name,$access_controls{$file_name},
  933:                               $action);
  934:         my $button_text = {
  935:                         'continue' => &mt('Proceed'),
  936:                         'cancel' => &mt('Return to directory'),
  937:                       };
  938:         &close_form($r,$url,$button_text);
  939:     } else {
  940:         $r->print($header);
  941:         if ($aclcount) {  
  942:             $r->print($info);
  943:         }
  944:         &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
  945:     }
  946: }
  947: 
  948: sub explain_conditionals {
  949:     return
  950:         &mt('Conditional files are accessible to users who satisfy the conditions you set.').'<br /><ul>'.
  951:         '<li>'.&mt('Conditions can be IP-based, in which case no log-in is required').'</li>'.
  952:         '<li>'.&mt("Conditions can also be based on a user's status, in which case the user needs an account in the LON-CAPA network, and needs to be logged in.").'<br />'."\n".
  953:         &mt('The status-based conditions can include affiliation with a particular course or community, or a user account in a specific domain.').'<br />'."\n".
  954:         &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').'</li></ul>';
  955: }
  956: 
  957: sub view_access_settings {
  958:     my ($r,$url,$access_controls,$aclcount) = @_;
  959:     my ($showstart,$showend);
  960:     my %todisplay;
  961:     foreach my $key (sort(keys(%{$access_controls}))) {
  962:         my ($num,$scope,$end,$start) = &unpack_acc_key($key);
  963:         $todisplay{$scope}{$key} = $$access_controls{$key};
  964:     }
  965:     if ($aclcount) {
  966:         $r->print('<h4>'.&mt('Current access controls defined for this file:').'</h4>');
  967:         $r->print(&Apache::loncommon::start_data_table());
  968:         $r->print(&Apache::loncommon::start_data_table_header_row());
  969:         $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
  970:                   '</th><th>'.&mt('Additional information').'</th>');
  971:         $r->print(&Apache::loncommon::end_data_table_header_row());
  972:         my $count = 1;
  973:         my $chg = 'none';
  974:         &build_access_summary($r,$count,$chg,%todisplay);
  975:         $r->print(&Apache::loncommon::end_data_table());
  976:     } else {
  977:         $r->print(&mt('No access control settings currently exist for this file.').'<br />');
  978:     }
  979:     my %anchor_fields = (
  980:         'currentpath' => $env{'form.currentpath'}
  981:     );
  982:     $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory')));
  983:     return;
  984: }
  985: 
  986: sub build_access_summary {
  987:     my ($r,$count,$chg,%todisplay) = @_; 
  988:     my ($showstart,$showend);
  989:     my %scope_desc = (
  990:                       public => 'Public',
  991:                       guest => 'Passphrase-protected',
  992:                       domains => 'Conditional: domain-based',
  993:                       users => 'Conditional: user-based',
  994:                       course => 'Conditional: course/community-based',
  995:                       ip     => 'Conditional: IP-based',
  996:                      );
  997:     my @allscopes = ('public','guest','domains','users','course','ip');
  998:     foreach my $scope (@allscopes) {
  999:         if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
 1000:             next;
 1001:         }
 1002:         foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
 1003:             if ($count) {
 1004:                 $r->print(&Apache::loncommon::start_data_table_row());
 1005:             }
 1006:             my ($num,$scope,$end,$start) = &unpack_acc_key($key);
 1007:             my $content = $todisplay{$scope}{$key};
 1008:             if ($chg eq 'delete') {
 1009:                 $showstart = &mt('Deleted');
 1010:                 $showend = $showstart;
 1011:             } else {
 1012:                 $showstart = &Apache::lonlocal::locallocaltime($start);
 1013:                 if ($end == 0) {
 1014:                     $showend = &mt('No end date');
 1015:                 } else {
 1016:                     $showend = &Apache::lonlocal::locallocaltime($end);
 1017:                 }
 1018:             }
 1019:             $r->print('<td>'.&mt($scope_desc{$scope}));
 1020:             my $crstype;
 1021:             if ($scope eq 'course') {
 1022:                 if ($chg ne 'delete') {
 1023:                     my $cid = $content->{'domain'}.'_'.$content->{'number'};
 1024:                     my %course_description = &Apache::lonnet::coursedescription($cid);
 1025:                     $r->print('<br />('.$course_description{'description'}.')');
 1026:                     $crstype = 'Course';
 1027:                     if ($course_description{'type'} ne '') {
 1028:                         $crstype = $course_description{'type'};
 1029:                     }
 1030:                 }
 1031:             }
 1032:             $r->print('</td><td>'.&mt('Start: ').$showstart.
 1033:                   '<br />'.&mt('End: ').$showend.'</td><td>');
 1034:             if ($chg ne 'delete') {
 1035:                 if ($scope eq 'guest') {
 1036:                     $r->print(&mt('Passphrase').': '.$content->{'password'});
 1037:                 } elsif ($scope eq 'course') {
 1038:                     $r->print('<table width="100%"><tr>');
 1039:                     $r->print('<th>'.&mt('Roles').'</th><th>'.
 1040:                           &mt('Access').'</th><th>'.
 1041:                                           &mt('Sections').'</th>');
 1042:                     $r->print('<th>'.&mt('Groups').'</th>');
 1043:                     $r->print('</tr>');
 1044:                     foreach my $id (sort(keys(%{$content->{'roles'}}))) {
 1045:                         $r->print('<tr>');
 1046:                         foreach my $item ('role','access','section','group') {
 1047:                             $r->print('<td>');
 1048:                             if ($item eq 'role') {
 1049:                                 my $role_output;
 1050:                                 foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
 1051:                                     if ($role eq 'all') {
 1052:                                         $role_output .= $role.',';
 1053:                                     } elsif ($role =~ /^cr/) {
 1054:                                         $role_output .= (split('/',$role))[3].',';
 1055:                                     } else {
 1056:                                         $role_output .= &Apache::lonnet::plaintext($role,$crstype).',';
 1057:                                     }
 1058:                                 }
 1059:                                 $role_output =~ s/,$//;
 1060:                                 $r->print($role_output);
 1061:                             } else {
 1062:                                 $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
 1063:                             }
 1064:                             $r->print('</td>');
 1065:                         }
 1066: 			$r->print('</tr>');
 1067:                     }
 1068: 		    $r->print('</table>');
 1069:                 } elsif ($scope eq 'domains') {
 1070:                     $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
 1071:                 } elsif ($scope eq 'users') {
 1072:                     my $curr_user_list = &sort_users($content->{'users'});
 1073:                     $r->print(&mt('Users: ').$curr_user_list);
 1074:                 } elsif ($scope eq 'ip') {
 1075:                     my $curr_ips_list = &sort_ips($content->{'ip'});
 1076:                     $r->print(&mt('IP(s):').' '.$curr_ips_list);
 1077:                 } else {
 1078:                     $r->print('&nbsp;');
 1079:                 }
 1080:             } else {
 1081:                 $r->print('&nbsp;');
 1082:             }
 1083:             $r->print('</td>');
 1084:             $r->print(&Apache::loncommon::end_data_table_row());
 1085:             $count ++;
 1086:         }
 1087:     }
 1088: }
 1089: 
 1090: 
 1091: sub update_access {
 1092:     my ($r,$url,$group,$port_path) = @_;
 1093:     my $totalprocessed = 0;
 1094:     my %processing;
 1095:     my %title  = (
 1096:                          'activate' => 'New control(s) added',
 1097:                          'delete'   => 'Existing control(s) deleted',
 1098:                          'update'   => 'Existing control(s) modified',
 1099:                      );
 1100:     my $changes;
 1101:     foreach my $chg (sort(keys(%title))) {     
 1102:         @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
 1103:         $totalprocessed += @{$processing{$chg}};
 1104:         foreach my $num (@{$processing{$chg}}) {
 1105:             my $scope = $env{'form.scope_'.$num};
 1106:             my ($start,$end) = &get_dates_from_form($num);
 1107:             my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
 1108:             if ($chg eq 'delete') {
 1109:                 $$changes{$chg}{$newkey} = 1;
 1110:             } else {
 1111:                 $$changes{$chg}{$newkey} = 
 1112:                             &build_access_record($num,$scope,$start,$end,$chg);
 1113:             }
 1114:         }
 1115:     }
 1116:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
 1117:     $r->print('<h2>'.&mt('Allowing others to retrieve file: [_1]',
 1118:               '<span class="LC_filename">'.$port_path.$file_name.'</span>').'</h2>'."\n");
 1119:     $file_name = &prepend_group($file_name);
 1120:     my ($uname,$udom) = &get_name_dom($group);
 1121:     my ($errors,$outcome,$deloutcome,$new_values,$translation);
 1122:     if ($totalprocessed) {
 1123:         ($outcome,$deloutcome,$new_values,$translation) =
 1124:         &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
 1125:                                                 $uname);
 1126:     }
 1127:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
 1128:                                                                        $uname);
 1129:     my %access_controls = 
 1130: 	&Apache::lonnet::get_access_controls($current_permissions,
 1131: 					     $group,$file_name);
 1132:     if ($totalprocessed) {
 1133:         if ($outcome eq 'ok') {
 1134:             my $updated_controls = $access_controls{$file_name};
 1135:             my ($showstart,$showend);
 1136:             $r->print(&Apache::loncommon::start_data_table());
 1137:             $r->print(&Apache::loncommon::start_data_table_header_row());
 1138:             $r->print('<th>'.&mt('Type of change').'</th><th>'.
 1139:                       &mt('Access control').'</th><th>'.&mt('Dates available').
 1140:                       '</th><th>'.&mt('Additional information').'</th>');
 1141:             $r->print(&Apache::loncommon::end_data_table_header_row());
 1142:             foreach my $chg (sort(keys(%processing))) {
 1143:                 if (@{$processing{$chg}} > 0) {
 1144:                     if ($chg eq 'delete') {
 1145:                         if (!($deloutcome eq 'ok')) {
 1146:                             $errors .='<span class="LC_error">'.
 1147: 				&mt('A problem occurred deleting access controls: [_1]',$deloutcome).
 1148: 				'</span>';
 1149:                             next;
 1150:                         }
 1151:                     }
 1152:                     my $numchgs = @{$processing{$chg}};
 1153:                     $r->print(&Apache::loncommon::start_data_table_row());
 1154:                     $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
 1155:                               '.</td>');
 1156:                     my $count = 0;
 1157:                     my %todisplay;
 1158:                     foreach my $key (sort(keys(%{$$changes{$chg}}))) {
 1159:                         my ($num,$scope,$end,$start) = &unpack_acc_key($key);
 1160:                         my $newkey = $key;
 1161:                         if ($chg eq 'activate') {
 1162:                             $newkey =~ s/^(\d+)/$$translation{$1}/;
 1163:                         }
 1164:                         $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
 1165:                     }
 1166:                     &build_access_summary($r,$count,$chg,%todisplay);  
 1167:                 }
 1168:             }
 1169:             $r->print(&Apache::loncommon::end_data_table());
 1170:         } else {
 1171:             if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
 1172:                 $errors .= '<span class="LC_error">'.
 1173: 		    &mt('A problem occurred saving access control settings: [_1]',$outcome).
 1174: 		    '</span>';
 1175:             }
 1176:         }
 1177:         if ($errors) { 
 1178:             $r->print($errors);
 1179:         }
 1180:     }
 1181:     my $allnew = 0;
 1182:     my $totalnew = 0;
 1183:     my $status = 'new';
 1184:     my ($firstitem,$lastitem);
 1185:     my @types = ('course','domains','users','ip');
 1186:     foreach my $newitem (@types) {
 1187:         $allnew += $env{'form.new'.$newitem};
 1188:     }
 1189:     if ($allnew > 0) {
 1190:         my $now = time;
 1191:         my $then = $now + (60*60*24*180); # six months approx.
 1192:         &open_form($r,$url);
 1193:         my %showtypes = (
 1194:            course  => 'course/community',
 1195:            domains => 'domain',
 1196:            users   => 'user',
 1197:            ip      => 'IP',
 1198:         );
 1199:         foreach my $newitem (@types) {
 1200:             next if ($env{'form.new'.$newitem} <= 0);
 1201:             $r->print(
 1202:                 '<p>'
 1203:                .&mt('Add new [_1]'.$showtypes{$newitem}.'-based[_2] access control for portfolio file: [_3]',
 1204:                     '<b>','</b>',
 1205:                     '<span class="LC_filename"><b>'
 1206:                    .$env{'form.currentpath'}.$env{'form.selectfile'}.'</b></span>')
 1207:                .'</p>');
 1208:             $firstitem = $totalnew;
 1209:             $lastitem = $totalnew + $env{'form.new'.$newitem};
 1210:             $totalnew = $lastitem;
 1211:             my @numbers;   
 1212:             for (my $i=$firstitem; $i<$lastitem; $i++) {
 1213:                 push(@numbers,$i);
 1214:             }
 1215:             &display_access_row($r,$status,$newitem,\@numbers,
 1216:                                 $access_controls{$file_name},$now,$then);
 1217:         }
 1218:         &close_form($r,$url);
 1219:     } else {
 1220:         my %anchor_fields = (
 1221:             'currentpath' => $env{'form.currentpath'},
 1222:             'access' => $env{'form.selectfile'}
 1223:         );
 1224:         my @actions;
 1225:         push(@actions, &make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
 1226:         delete $anchor_fields{'access'};
 1227:         push(@actions, &make_anchor($url,\%anchor_fields,&mt('Return to directory')));
 1228:         $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(\@actions));
 1229:     }
 1230:     return;
 1231: }
 1232: 
 1233: sub build_access_record {
 1234:     my ($num,$scope,$start,$end,$chg) = @_;
 1235:     my $record = {
 1236: 	type => $scope,
 1237: 	time => {
 1238: 	    start => $start,
 1239: 	    end   => $end
 1240: 	    },
 1241: 	    };
 1242: 		
 1243:     if ($scope eq 'guest') {	
 1244:         $record->{'password'} = $env{'form.password'};
 1245:     } elsif ($scope eq 'course') {
 1246:         $record->{'domain'} = $env{'form.crsdom_'.$num};
 1247: 	$record->{'number'} = $env{'form.crsnum_'.$num};
 1248:         my @role_ids;
 1249:         my @delete_role_ids =
 1250:             &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
 1251: 	my @preserves =
 1252: 	    &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
 1253: 	if (@delete_role_ids) {
 1254: 	    foreach my $id (@preserves) {
 1255: 		if (grep {$_ = $id} (@delete_role_ids)) {
 1256: 		    next;
 1257: 		}
 1258: 		push(@role_ids,$id); 
 1259: 	    }
 1260: 	} else {
 1261: 	    push(@role_ids,@preserves);
 1262: 	}
 1263: 
 1264: 	my $next_id = $env{'form.add_role_'.$num};
 1265: 	if ($next_id) {
 1266: 	    push(@role_ids,$next_id);
 1267: 	}
 1268: 
 1269:         foreach my $id (@role_ids) {
 1270:             my (@roles,@accesses,@sections,@groups);
 1271:             if (($id == $next_id) && ($chg eq 'update')) {
 1272:                 @roles    = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
 1273:                 @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
 1274:                 @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
 1275:                 @groups   = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
 1276:             } else {
 1277:                 @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
 1278:                 @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
 1279:                 @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
 1280:                 @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
 1281:             }
 1282: 	    $record->{'roles'}{$id}{'role'}    = \@roles;
 1283: 	    $record->{'roles'}{$id}{'access'}  = \@accesses;
 1284: 	    $record->{'roles'}{$id}{'section'} = \@sections;
 1285: 	    $record->{'roles'}{$id}{'group'}   = \@groups;
 1286:         }
 1287:     } elsif ($scope eq 'domains') {
 1288:         my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
 1289: 	$record->{'dom'} = \@doms;
 1290:     } elsif ($scope eq 'users') {
 1291:         my $userlist = $env{'form.users_'.$num};
 1292:         $userlist =~ s/\s+//sg;
 1293: 	my %userhash = map { ($_,1) } (split(/,/,$userlist));
 1294:         foreach my $user (keys(%userhash)) {
 1295:             my ($uname,$udom) = split(/:/,$user);
 1296: 	    push(@{$record->{'users'}}, {
 1297: 		'uname' => $uname,
 1298: 		'udom'  => $udom
 1299: 		});
 1300: 	}
 1301:     } elsif ($scope eq 'ip') {
 1302:         my $ipslist = $env{'form.ips_'.$num};
 1303:         $ipslist =~ s/\s+//sg;
 1304:         my %ipshash = map { ($_,1) } (split(/,/,$ipslist));
 1305:         foreach my $ip (keys(%ipshash)) {
 1306:             push(@{$record->{'ip'}},$ip);
 1307:         }
 1308:     }
 1309:     return $record;
 1310: }
 1311: 
 1312: sub get_dates_from_form {
 1313:     my ($id) = @_;
 1314:     my $startdate;
 1315:     my $enddate;
 1316:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
 1317:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
 1318:     if ( exists ($env{'form.noend_'.$id}) ) {
 1319:         $enddate = 0;
 1320:     }
 1321:     return ($startdate,$enddate);
 1322: }
 1323: 
 1324: sub sort_users {
 1325:     my ($users) = @_; 
 1326:     my @curr_users = map {
 1327: 	$_->{'uname'}.':'.$_->{'udom'}
 1328:     } (@{$users});
 1329:     my $curr_user_list = join(",\n",sort(@curr_users));
 1330:     return $curr_user_list;
 1331: }
 1332: 
 1333: sub sort_ips {
 1334:     my ($ips) = @_;
 1335:     if (ref($ips) eq 'ARRAY') {
 1336:         return join(",\n",sort(@{$ips}));
 1337:     }
 1338: }
 1339: 
 1340: sub access_setting_table {
 1341:     my ($r,$url,$filename,$access_controls,$action) = @_;
 1342:     my ($public,$publictext);
 1343:     $publictext ='Off';
 1344:     my ($guest,$guesttext);
 1345:     $guesttext = 'Off';
 1346:     my @courses = ();
 1347:     my @domains = ();
 1348:     my @users = ();
 1349:     my @ips = ();
 1350:     my $now = time;
 1351:     my $then = $now + (60*60*24*180); # six months approx.
 1352:     my ($num,$scope,$publicnum,$guestnum);
 1353:     my (%acl_count,%end,%start,%conditionals);
 1354:     foreach my $key (sort(keys(%{$access_controls}))) {
 1355:         ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
 1356:         if ($scope eq 'public') {
 1357:             $public = $key;
 1358:             $publicnum = $num;
 1359:             $publictext = &acl_status($start{$key},$end{$key},$now);
 1360:         } elsif ($scope eq 'guest') {
 1361:             $guest=$key;
 1362:             $guestnum = $num;  
 1363:             $guesttext = &acl_status($start{$key},$end{$key},$now);
 1364:         } else {
 1365:             $conditionals{$scope}{$key} = $$access_controls{$key};
 1366:             if ($scope eq 'course') {
 1367:                 push(@courses,$key);
 1368:             } elsif ($scope eq 'domains') {
 1369:                 push(@domains,$key);
 1370:             } elsif ($scope eq 'users') {
 1371:                 push(@users,$key);
 1372:             } elsif ($scope eq 'ip') {
 1373:                 push(@ips,$key);
 1374:             }
 1375:         }
 1376:         $acl_count{$scope} ++;
 1377:     }
 1378:     $r->print('<table border="0"><tr><td valign="top">');
 1379:     if ($action eq 'chgaccess') {
 1380:         &standard_settings($r,$now,$then,$url,$filename,\%acl_count,\%start,
 1381:                            \%end,$public,$publicnum,$publictext,$guest,$guestnum,
 1382:                            $guesttext,$access_controls,%conditionals);
 1383:     } else {
 1384:         &condition_setting($r,$access_controls,$now,$then,\%acl_count,
 1385:                            \@domains,\@users,\@courses,\@ips);
 1386:     }
 1387:     $r->print('</td></tr></table>');
 1388: }
 1389: 
 1390: sub standard_settings {
 1391:     my ($r,$now,$then,$url,$filename,$acl_count,$start,$end,$public,$publicnum,
 1392:       $publictext,$guest,$guestnum,$guesttext,$access_controls,%conditionals)=@_;
 1393:     $r->print('<h3>'.&mt('Public access: [_1]',&mt($publictext)).'</h3>');
 1394:     $r->print(&Apache::loncommon::start_data_table());
 1395:     $r->print(&Apache::loncommon::start_data_table_header_row());
 1396:     $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
 1397:     $r->print(&Apache::loncommon::end_data_table_header_row());
 1398:     $r->print(&Apache::loncommon::start_data_table_row());
 1399:     if ($public) {
 1400:         $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
 1401:              &dateboxes($publicnum,$start->{$public},$end->{$public}).'</td>');
 1402:     } else {
 1403:         $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
 1404:                   &dateboxes('0',$now,$then).'</td>');
 1405:     }
 1406:     $r->print(&Apache::loncommon::end_data_table_row());
 1407:     $r->print(&Apache::loncommon::end_data_table());
 1408:     $r->print('</td><td width="40">&nbsp;</td><td valign="top">');
 1409:     $r->print('<h3>'.&mt('Passphrase-protected access: [_1]',&mt($guesttext)).'</h3>');
 1410:     $r->print(&Apache::loncommon::start_data_table());
 1411:     $r->print(&Apache::loncommon::start_data_table_header_row());
 1412:     $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
 1413:               '</th><th>'. &mt('Passphrase').'</th>');
 1414:     $r->print(&Apache::loncommon::end_data_table_header_row());
 1415:     $r->print(&Apache::loncommon::start_data_table_row());
 1416:     my $passwd;
 1417:     if ($guest) {
 1418:         $passwd = $$access_controls{$guest}{'password'};
 1419:         $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
 1420:               &dateboxes($guestnum,$start->{$guest},$end->{$guest}).'</td>');
 1421:     } else {
 1422:         $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
 1423:                   &dateboxes('1',$now,$then).'</td>');
 1424:     }
 1425:     $r->print('<td><input type="text" size="15" name="password" value="'.
 1426:               $passwd.'" /></td>');
 1427:     $r->print(&Apache::loncommon::end_data_table_row());
 1428:     $r->print(&Apache::loncommon::end_data_table());
 1429:     $r->print('</td></tr><tr><td colspan="3">&nbsp;</td></tr>'.
 1430:               '<tr><td colspan="3" valign="top">');
 1431:     my $numconditionals = 0;
 1432:     my $conditionstext;
 1433:     my %cond_status;
 1434:     foreach my $scope ('domains','users','course','ip') {
 1435:         $numconditionals += $acl_count->{$scope}; 
 1436:         if ($acl_count->{$scope} > 0) {
 1437:             if ($conditionstext ne 'Active') {
 1438:                 foreach my $key (keys(%{$conditionals{$scope}})) {
 1439:                     $conditionstext = &acl_status($start->{$key},$end->{$key},$now);
 1440:                     if ($conditionstext eq 'Active') {
 1441:                        last;
 1442:                     }
 1443:                 }
 1444:             }
 1445:         }
 1446:     }
 1447:     if ($conditionstext eq '') {
 1448:         $conditionstext = 'Off';
 1449:     }
 1450:     my %anchor_fields = (
 1451:             'access' => $env{'form.selectfile'},
 1452:             'action' => 'chgconditions',
 1453:             'currentpath' => $env{'form.currentpath'},
 1454:         );
 1455:     $r->print('<h3>'.&mt('Conditional access: [_1]',&mt($conditionstext)).'</h3>');
 1456:     if ($numconditionals > 0) {
 1457:         my $count = 1;
 1458:         my $chg = 'none';
 1459:         $r->print(&mt('You have previously set [_1] conditional access controls.',$numconditionals).' '.&make_anchor($url,\%anchor_fields,&mt('Change Conditions')).'<br /><br />');
 1460:         $r->print(&Apache::loncommon::start_data_table());
 1461:         $r->print(&Apache::loncommon::start_data_table_header_row());
 1462:         $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
 1463:                   '</th><th>'.&mt('Additional information').'</th>');
 1464:         $r->print(&Apache::loncommon::end_data_table_header_row());
 1465:         &build_access_summary($r,$count,$chg,%conditionals);
 1466:         $r->print(&Apache::loncommon::end_data_table());
 1467:     } else {
 1468:         $r->print(&make_anchor($url,\%anchor_fields,&mt('Add conditional access')).' '.&mt("based on domain, username, course/community affiliation or user's IP address."));
 1469:     }
 1470: }
 1471: 
 1472: sub condition_setting {
 1473:     my ($r,$access_controls,$now,$then,$acl_count,$domains,$users,$courses,$ips) = @_;
 1474:     $r->print('<tr><td valign="top">');
 1475:     &access_element($r,'domains',$acl_count,$domains,$access_controls,$now,$then);
 1476:     $r->print('</td><td>&nbsp;</td><td valign="top">');
 1477:     &access_element($r,'users',$acl_count,$users,$access_controls,$now,$then);
 1478:     $r->print('</td></tr><tr><td colspan="3"></td></tr><tr><td valign="top">');
 1479:     &access_element($r,'course',$acl_count,$courses,$access_controls,$now,$then);
 1480:     $r->print('</td><td>&nbsp;</td><td valign="top">');
 1481:     &access_element($r,'ip',$acl_count,$ips,$access_controls,$now,$then);
 1482:     $r->print('</td></tr></table>');
 1483: }
 1484: 
 1485: sub acl_status {
 1486:     my ($start,$end,$now) = @_;
 1487:     if ($start > $now) {
 1488:         return 'Inactive';
 1489:     }
 1490:     if ($end && $end<$now) {
 1491:         return 'Inactive';
 1492:     }
 1493:     return 'Active';
 1494: }
 1495: 
 1496: sub access_element {
 1497:     my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
 1498:     my %typetext = (
 1499:         domains => 'Domain',
 1500:         users   => 'User',
 1501:         course  => 'Course/Community',
 1502:         ip      => 'IP',
 1503:     );
 1504:     $r->print('<h3>'.&mt($typetext{$type}.'-based conditional access:').' ');
 1505:     if ($$acl_count{$type}) {
 1506:         $r->print(&mt('[quant,_1,condition]',$$acl_count{$type}));
 1507:     } else {
 1508:         $r->print(&mt('Off'));
 1509:     }
 1510:     $r->print('</h3>');
 1511:     &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
 1512:     return;
 1513: }
 1514: 
 1515: sub display_access_row {
 1516:     my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
 1517:     my ($showtype, $infotype);
 1518:     if ($type eq 'course') {
 1519:         $showtype = &mt('Courses/Communities');
 1520:         $infotype = 'Course/Community';
 1521:     } elsif ($type eq 'domains') {
 1522:         $showtype = &mt('Domains');
 1523:         $infotype = 'Domain';
 1524:     } elsif ($type eq 'users') {
 1525:         $showtype = &mt('Users');
 1526:         $infotype = 'User';
 1527:     } elsif ($type eq 'ip') {
 1528:         $showtype = &mt('IP-based');
 1529:         $infotype = 'IP';  
 1530:     }
 1531:     if (@{$items} > 0) {
 1532:         my @all_doms;
 1533:         my $colspan = 3;
 1534:         $r->print(&Apache::loncommon::start_data_table());
 1535:         $r->print(&Apache::loncommon::start_data_table_header_row());
 1536:         $r->print('<th>'.&mt('Action?').'</th><th>'.$showtype.'</th><th>'.
 1537:               &mt('Dates available').'</th>');
 1538:         if ($type eq 'course' && $status eq 'old') {
 1539:             $r->print('<th>'.&mt('Allowed course/community affiliations').
 1540:                       '</th>');
 1541:             $colspan ++;
 1542:         } elsif ($type eq 'domains') {
 1543:             @all_doms = sort(&Apache::lonnet::all_domains());
 1544:         }
 1545:         $r->print(&Apache::loncommon::end_data_table_header_row());
 1546:         foreach my $key (@{$items}) {
 1547: 	    $r->print(&Apache::loncommon::start_data_table_row());
 1548:             if ($type eq 'course') {
 1549:                 &course_row($r,$status,$type,$key,$access_controls,$now,$then);
 1550:             } elsif ($type eq 'domains') {
 1551:                 &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
 1552:                             $then);
 1553:             } elsif ($type eq 'users') {
 1554:                 &users_row($r,$status,$key,$access_controls,$now,$then);
 1555:             } elsif ($type eq 'ip') {
 1556:                 &ips_row($r,$status,$key,$access_controls,$now,$then);
 1557:             }
 1558: 	    $r->print(&Apache::loncommon::end_data_table_row());
 1559:         }
 1560:         if ($status eq 'old') {
 1561: 	    $r->print(&Apache::loncommon::start_data_table_row());
 1562:             $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
 1563:                       '</td>');
 1564: 	    $r->print(&Apache::loncommon::end_data_table_row());
 1565:         }
 1566:         $r->print(&Apache::loncommon::end_data_table());
 1567:     } else {
 1568:         $r->print(
 1569:             '<p class="LC_info">'
 1570:            .&mt('No '.$infotype.'-based conditions defined')
 1571:            .'</p>'
 1572:            .&additional_item($type)
 1573:         );
 1574:     }
 1575:     return;
 1576: }
 1577: 
 1578: sub course_js {
 1579:     return qq|
 1580: <script type="text/javascript">
 1581: // <![CDATA[
 1582: function setRoleOptions(num,roleid,cdom,cnum,type) {
 1583:     updateIndexNum = getIndexByValue('update',num);
 1584:     var addItem = 'add_role_'+num;
 1585:     var addIndexNum = getIndexByName(addItem);
 1586:     if (document.portform.elements[addItem].checked) {
 1587:         document.portform.elements[updateIndexNum].checked = true;
 1588:         var url = '/adm/portfolio?action=rolepicker&setroles='+num+'_'+roleid+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
 1589:         var title = 'Roles_Chooser';
 1590:         var options = 'scrollbars=1,resizable=1,menubar=0';
 1591:         options += ',width=700,height=600';
 1592:         rolebrowser = open(url,title,options,'1');
 1593:         rolebrowser.focus();
 1594:     } else {
 1595:         addArray = new Array ('role','access','section','group');
 1596:         for (var j=0;j<addArray.length;j++) {
 1597:             var itemIndex = getIndexByName(addArray[j]+'_'+num+'_'+roleid);
 1598:             document.portform.elements[itemIndex].value = '';
 1599:         }
 1600:     }
 1601: }
 1602: 
 1603: function getIndexByName(item) {
 1604:     for (var i=0;i<document.portform.elements.length;i++) {
 1605:         if (document.portform.elements[i].name == item) {
 1606:             return i;
 1607:         }
 1608:     }
 1609:     return -1;
 1610: }
 1611: 
 1612: function getIndexByValue(name,value) {
 1613:     for (var i=0;i<document.portform.elements.length;i++) {
 1614:         if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
 1615:             return i;
 1616:         }
 1617:     }
 1618:     return -1;
 1619: }
 1620: 
 1621: // ]]>
 1622: </script>
 1623: |;
 1624: }
 1625: 
 1626: sub course_row {
 1627:     my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
 1628:     my $content;
 1629:     my $defdom = $env{'user.domain'};
 1630:     if ($status eq 'old') {
 1631:         $content = $$access_controls{$item}; 
 1632:         $defdom =  $content->{'domain'};
 1633:     }
 1634:     my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
 1635: 	.&course_js();
 1636:     my $showtype = &mt('Course/Community');
 1637:     my $crstype = 'Course';
 1638:     my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
 1639:                                                     $type);
 1640:     $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
 1641:     if ($status eq 'old') {
 1642:         my $cid = $content->{'domain'}.'_'.$content->{'number'};
 1643:         my %course_description = &Apache::lonnet::coursedescription($cid);
 1644:         if ($course_description{'type'} ne '') {
 1645:             $crstype = $course_description{'type'};
 1646:         }
 1647:         $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>');
 1648:     } elsif ($status eq 'new') {
 1649:         $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,$num.'_1',undef,$showtype).'&nbsp;&nbsp;<input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
 1650:     }
 1651:     $r->print('<td>'.&dateboxes($num,$start,$end));
 1652:     my $newrole_id = 1;
 1653:     if ($status eq 'old') {
 1654:         $r->print('</td><td>');
 1655:         my $max_id = 0;
 1656:         if (keys(%{$content->{'roles'}}) > 0) {
 1657:             $r->print('<table><tr><th>'.&mt('Action').'</th>'.
 1658:                       '<th>'.&mt('Roles').'</th>'.
 1659:                       '<th>'.&mt('Access').'</th>'.
 1660:                       '<th>'.&mt('Sections').'</th>'.
 1661:                       '<th>'.&mt('Groups').'</th></tr>');
 1662:             foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
 1663:                 if ($role_id > $max_id) {
 1664:                     $max_id = $role_id;
 1665:                 }
 1666:                 $max_id ++;
 1667:                 my $role_selects = &role_selectors($num,$role_id,$crstype,$content,'display');
 1668:                 $r->print('<tr><td><span class="LC_nobreak"><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>');
 1669:             }
 1670:             $r->print('</table>');
 1671:         }
 1672:         $r->print('<br />'.&mt('Add a roles-based condition').
 1673:                   '&nbsp;<input type="checkbox" name="add_role_'.
 1674:                   $num.'" onclick="javascript:setRoleOptions('."'$num',
 1675:                   '$max_id','$content->{'domain'}','$content->{'number'}',
 1676:                   '$showtype'".')" value="" />');
 1677:         $newrole_id = $max_id;
 1678:     } else {
 1679:         $r->print('<input type="hidden" name="add_role_'.$num.'" value="" />');
 1680:     }
 1681:     $r->print(&add_course_role($num,$newrole_id));
 1682:     $r->print('</td>');
 1683:     return;
 1684: }
 1685: 
 1686: sub add_course_role {
 1687:     my ($num,$max_id) = @_;
 1688:     my $output;
 1689:     $output .='<input type="hidden" name="role_'.$num.'_'.$max_id.'" />'.
 1690:               '<input type="hidden" name="access_'.$num.'_'.$max_id.'" />'.
 1691:               '<input type="hidden" name="section_'.$num.'_'.$max_id.'" />'.
 1692:               '<input type="hidden" name="group_'.$num.'_'.$max_id.'" />';
 1693:     return $output;
 1694: }
 1695: 
 1696: sub domains_row {
 1697:     my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
 1698:     my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
 1699:                                                     'domains');
 1700:     my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="multiple">'.
 1701:                      ' <option value="">'.&mt('Please select').'</option>';
 1702:     if ($status eq 'old') {
 1703:         my $content =  $$access_controls{$item};
 1704: 	foreach my $dom (@{$all_doms}) {
 1705:             if ((@{$content->{'dom'}} > 0) 
 1706: 		&& (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
 1707:                 $dom_select .= '<option value="'.$dom.'" selected="selected">'.
 1708:                                $dom.'</option>';
 1709:             } else {
 1710:                 $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
 1711:             }
 1712:         }
 1713:     } else {
 1714:         foreach my $dom (@{$all_doms}) {
 1715:             $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
 1716:         }
 1717:     }
 1718:     $dom_select .= '</select>';
 1719:     $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
 1720:               '</td><td>'.&dateboxes($num,$start,$end).'</td>');
 1721: }
 1722: 
 1723: sub users_row {
 1724:     my ($r,$status,$item,$access_controls,$now,$then) = @_;
 1725:     my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
 1726:                                                     'users');
 1727:     my $curr_user_list;
 1728:     if ($status eq 'old') {
 1729:         my $content = $$access_controls{$item};
 1730:         $curr_user_list = &sort_users($content->{'users'});
 1731:     }
 1732:     $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>');
 1733: }
 1734: 
 1735: sub ips_row {
 1736:     my ($r,$status,$item,$access_controls,$now,$then) = @_;
 1737:     my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
 1738:                                                     'ip');
 1739:     my $curr_ips_list;
 1740:     if ($status eq 'old') {
 1741:         my $content = $$access_controls{$item};
 1742:         $curr_ips_list = &sort_ips($content->{'ip'});
 1743:     }
 1744:     $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt('Format for IP controls').'<br />'.
 1745:               &mt('[_1] or [_2] or [_3] or [_4] or [_5]','<tt>35.8.*</tt>','<tt>35.8.3.[34-56]</tt>',
 1746:                   '<tt>*.msu.edu</tt>','<tt>35.8.3.34</tt>','<tt>somehostname.pa.msu.edu</tt>').'<br />'.
 1747:               &mt('Use a comma to separate different ranges.').'</br/>'.
 1748:               '<textarea name="ips_'.$num.'" cols="30"  rows="5">'.$curr_ips_list.'</textarea></td>'.
 1749:               '<td>'.&dateboxes($num,$start,$end).'</td>');
 1750: }
 1751: 
 1752: sub additional_item {
 1753:     my ($type) = @_;
 1754:     my $showtype;
 1755:     if ($type eq 'course') {
 1756:         $showtype = 'course/community';
 1757:     } elsif ($type eq 'domains') {
 1758:         $showtype = 'domain';
 1759:     } elsif ($type eq 'users') {
 1760:         $showtype = 'user';
 1761:     } elsif ($type eq 'ip') {
 1762:         $showtype = 'IP';
 1763:     }
 1764:     return
 1765:         &mt('Add new '.$showtype.'-based condition(s)?')
 1766:        .'&nbsp;'.&mt('Number to add: ')
 1767:        .'<input type="text" name="new'.$type.'" size="3" value="0" />';
 1768: }
 1769: 
 1770: sub actionbox {
 1771:     my ($status,$num,$scope) = @_;
 1772:     my $output = '<span class="LC_nobreak"><label>';
 1773:     if ($status eq 'new') {
 1774:         my $checkstate;
 1775:         if ($scope eq 'domains' || $scope eq 'users' || $scope eq 'course' || $scope eq 'ip') {
 1776:             $checkstate = 'checked="checked"';
 1777:         }
 1778:         $output .= '<input type="checkbox" name="activate" value="'.$num.'" '.
 1779:                    $checkstate.'  />'.
 1780:         &mt('Activate');
 1781:     } else {
 1782:         $output .= '<input type="checkbox" name="delete" value="'.$num.
 1783:                    '" />'.&mt('Delete').'</label></span><br /><span class="LC_nobreak">'.
 1784:                    '<label><input type="checkbox" name="update" value="'.
 1785:                    $num.'" />'.&mt('Update');
 1786:     }
 1787:     $output .= '</label></span><input type="hidden" name="scope_'.$num.'" value="'.$scope.'" />';
 1788:     return $output;
 1789: }
 1790:                                                                                    
 1791: sub dateboxes {
 1792:     my ($num,$start,$end) = @_;
 1793:     my $noend;
 1794:     if ($end == 0) {
 1795:         $noend = 'checked="checked"';
 1796:     }
 1797:     my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
 1798:                            'startdate_'.$num,$start,undef,undef,undef,1,undef,
 1799:                             undef,undef,1);
 1800:     my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
 1801:                                'enddate_'.$num,$end,undef,undef,undef,1,undef,
 1802:                                 undef,undef,1). '&nbsp;&nbsp;<span class="LC_nobreak"><label>'.
 1803:                                 '<input type="checkbox" name="noend_'.
 1804:                                 $num.'" '.$noend.' />'.&mt('No end date').
 1805:                                 '</label></span>';
 1806:                                                                                    
 1807:     my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
 1808:     return $output;
 1809: }
 1810: 
 1811: sub unpack_acc_key {
 1812:     my ($acc_key) = @_;
 1813:     my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
 1814:     return ($num,$scope,$end,$start);
 1815: }
 1816: 
 1817: sub set_identifiers {
 1818:     my ($status,$item,$now,$then,$scope) = @_;
 1819:     if ($status eq 'old') {
 1820:         return(&unpack_acc_key($item));
 1821:     } else {
 1822:         return($item,$scope,$then,$now);
 1823:     }
 1824: } 
 1825: 
 1826: sub role_selectors {
 1827:     my ($num,$role_id,$type,$content,$caller) = @_;
 1828:     my ($output,$cdom,$cnum,$longid);
 1829:     if ($caller eq 'display') {
 1830:         $longid = '_'.$num.'_'.$role_id;
 1831:         $cdom = $$content{'domain'};
 1832:         $cnum = $$content{'number'};
 1833:     } elsif ($caller eq 'rolepicker') {
 1834:          $cdom = $env{'form.cdom'};
 1835:          $cnum = $env{'form.cnum'};
 1836:     }
 1837:     my $crstype = 'Course';
 1838:     if ($cnum =~ /^$match_community$/) {
 1839:         $crstype = 'Community'
 1840:     }
 1841:     my ($sections,$groups,$allroles,$rolehash,$accesshash) =
 1842:             &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$crstype);
 1843:     if (!@{$sections}) {
 1844:         @{$sections} = ('none');
 1845:     } else {
 1846:         unshift(@{$sections},('all','none'));
 1847:     }
 1848:     if (!@{$groups}) {
 1849:         @{$groups} = ('none');
 1850:     } else {
 1851:         unshift(@{$groups},('all','none'));
 1852:     }
 1853:     my @allacesses = sort(keys(%{$accesshash}));
 1854:     my (%sectionhash,%grouphash);
 1855:     foreach my $sec (@{$sections}) {
 1856:         $sectionhash{$sec} = $sec;
 1857:     }
 1858:     foreach my $grp (@{$groups}) {
 1859:         $grouphash{$grp} = $grp;
 1860:     }
 1861:     my %lookup = (
 1862:                    'role' => $rolehash,
 1863:                    'access' => $accesshash,
 1864:                    'section' => \%sectionhash,
 1865:                    'group' => \%grouphash,
 1866:                  );
 1867:     my @allaccesses = sort(keys(%{$accesshash}));
 1868:     my %allitems = (
 1869:                     'role' => $allroles,
 1870:                     'access' => \@allaccesses,
 1871:                     'section' => $sections,
 1872:                     'group' => $groups,
 1873:                    );
 1874:     foreach my $item ('role','access','section','group') {
 1875:         $output .= '<td><select name="'.$item.$longid.'" multiple="multiple" size="4">'."\n";
 1876:         foreach my $entry (@{$allitems{$item}}) {
 1877:             if ($caller eq 'display') {
 1878:                 if ((@{$$content{'roles'}{$role_id}{$item}} > 0) && 
 1879:                     (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
 1880:                     $output .= '  <option value="'.$entry.'" selected="selected">'.
 1881:                                   $lookup{$item}{$entry}.'</option>';
 1882:                     next;
 1883:                 }
 1884:             }
 1885:             $output .= '  <option value="'.$entry.'">'.
 1886:                        $lookup{$item}{$entry}.'</option>';
 1887:         }
 1888:         $output .= '</select>';
 1889:     }
 1890:     $output .= '</td>';
 1891:     return $output;
 1892: }
 1893: 
 1894: sub role_options_window {
 1895:     my ($r) = @_;
 1896:     my $type = $env{'form.type'};
 1897:     my $rolenum = $env{'form.setroles'};
 1898:     my ($num,$role_id) = ($rolenum =~ /^([\d_]+)_(\d+)$/);
 1899:     my $role_elements;
 1900:     foreach my $item ('role','access','section','group') {
 1901:         $role_elements .= "'".$item.'_'.$rolenum."',";
 1902:     }
 1903:     $role_elements =~ s/,$//; 
 1904:     my $role_selects = &role_selectors($num,$role_id,$type,undef,
 1905:                                        'rolepicker');
 1906:     $r->print(<<"END_SCRIPT");
 1907: <script type="text/javascript">
 1908: function setRoles() {
 1909:     var role_elements = new Array($role_elements);
 1910:     for (var i=0; i<role_elements.length; i++) {
 1911:         var copylist = '';
 1912:         for (var j=0; j<document.rolepicker.elements[i].length; j++) {
 1913:             if (document.rolepicker.elements[i].options[j].selected) {
 1914:                 copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
 1915:             }
 1916:         }
 1917:         copylist = copylist.substr(0,copylist.length-1);
 1918:         var openerItem = getIndexByName(role_elements[i]);
 1919:         opener.document.portform.elements[openerItem].value = copylist; 
 1920:     }
 1921:     var roleAdder = getIndexByName('add_role_$num');
 1922:     opener.document.portform.elements[roleAdder].value = '$role_id';
 1923:     self.close();
 1924: }
 1925: 
 1926: function getIndexByName(item) {
 1927:     for (var i=0;i<opener.document.portform.elements.length;i++) {
 1928:         if (opener.document.portform.elements[i].name == item) {
 1929:             return i;
 1930:         }
 1931:     }
 1932:     return -1;
 1933: }
 1934: 
 1935: </script>
 1936: END_SCRIPT
 1937:     $r->print(
 1938:         '<p>'
 1939:        .&mt('Select roles, '.lc($type).' status, section(s) and group(s) for users'
 1940:            .' who will be able to access the portfolio file.')
 1941:        .'</p>'
 1942:     );
 1943:     $r->print(
 1944:         '<form name="rolepicker" action="/adm/portfolio" method="post">'
 1945:        .'<table><tr>'
 1946:        .'<th>'.&mt('Roles').'</th>'
 1947:        .'<th>'.&mt("$type status").'</th>'
 1948:        .'<th>'.&mt('Sections').'</th>'
 1949:        .'<th>'.&mt('Groups').'</th>'
 1950:        .'</tr><tr>'.$role_selects.'</tr>'
 1951:        .'</table><br />'
 1952:        .'<input type="button" name="rolepickbutton" value="'.&mt('Save').'" onclick="setRoles()" />'
 1953:     );
 1954:     return;
 1955: }
 1956: 
 1957: sub select_files {
 1958:     my ($r,$dir_list) = @_;
 1959:     if ($env{'form.continue'} eq 'true') {
 1960:         # here we update the selections for the currentpath
 1961:         # eventually, have to handle removing those not checked, but . . . 
 1962:         my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
 1963:         if (scalar(@items)){
 1964:             my @ok_items;
 1965:             if (ref($dir_list) eq 'ARRAY') {
 1966:                 foreach my $dir_line (@{$dir_list}) {
 1967:                     my ($filename,undef,undef,undef,undef,undef,undef,undef,$size)=split(/\&/,$dir_line,10);
 1968:                     if (grep(/^\Q$filename\E$/,@items)) {
 1969:                         if ($size) {
 1970:                             push(@ok_items,$filename); 
 1971:                         }
 1972:                     }
 1973:                 }
 1974:             }
 1975:             &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @ok_items);
 1976:         }
 1977:     } else {
 1978:             #empty the file for a fresh start
 1979:             &Apache::lonnet::clear_selected_files($env{'user.name'});
 1980:     }
 1981:     my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
 1982:     my $java_files = join ",", @files;
 1983:     if ($java_files) {
 1984:         $java_files.=',';
 1985:     }
 1986:     my $javascript =(<<ENDSMP);
 1987:         <script type="text/javascript">
 1988:         function finishSelect() {
 1989: ENDSMP
 1990:     $javascript .= 'fileList = "'.$java_files.'";';
 1991:     $javascript .= (<<ENDSMP);
 1992:             for (i=0;i<document.forms.checkselect.length;i++) { 
 1993:                 if (document.forms.checkselect[i].checked){
 1994:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
 1995:                 }
 1996:             }
 1997:             var hwfield = opener.document.getElementsByName('$env{'form.fieldname'}');
 1998:             hwfield[0].value = fileList;
 1999:             self.close();
 2000:         }
 2001:         </script>
 2002: ENDSMP
 2003:     $r->print($javascript);
 2004:     $r->print("<h1>".&mt('Select portfolio files')."</h1>");
 2005:     my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
 2006:     if (@otherfiles) {
 2007: 	$r->print(&Apache::loncommon::start_data_table()
 2008:                  .&Apache::loncommon::start_data_table_header_row()
 2009:                  .'<th>'.&mt('Files selected from other directories:')."</th>"
 2010:                  .&Apache::loncommon::end_data_table_header_row()
 2011:         );
 2012: 	foreach my $file (@otherfiles) {
 2013: 	    $r->print(&Apache::loncommon::start_data_table_row()
 2014:                      .'<td>'.$file."</td>"
 2015:                      .&Apache::loncommon::end_data_table_row()
 2016:             );
 2017: 	}
 2018:         $r->print(&Apache::loncommon::end_data_table()
 2019:                  .'<br />'
 2020:         );
 2021:     }
 2022:     $r->print('<div>'
 2023:              .&mt('Check as many files as you wish in response to the problem:')
 2024:              .'</div>'
 2025:     );
 2026: }
 2027: 
 2028: sub upload {
 2029:     my ($r,$url,$group)=@_;
 2030:     my $formname = 'uploaddoc';
 2031:     my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formname.'.filename'});
 2032:     my ($state,$msg);
 2033:     if ($fname eq '') {
 2034:         $r->print(
 2035:             &Apache::loncommon::confirmwrapper(
 2036:                 &Apache::lonhtmlcommon::confirm_success(
 2037:                     &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
 2038:                       'so after eliminating special characters there was nothing left.',
 2039:                       '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>'),1)));
 2040: 
 2041:         $r->print(&done(undef,$url));
 2042:         return;
 2043:     }
 2044:     my $disk_quota = &get_quota($group);
 2045:     my $portfolio_root = &get_portfolio_root();
 2046:     my $port_path = &get_port_path();
 2047:     my ($uname,$udom) = &get_name_dom($group);
 2048:     my $getpropath = 1;
 2049:     my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
 2050:     ($state,$msg) = 
 2051:         &Apache::loncommon::check_for_upload($env{'form.currentpath'},$fname,
 2052: 		                             $group,$formname,$portfolio_root,
 2053:                                              $port_path,$disk_quota,
 2054:                                              $current_disk_usage,$uname,$udom);
 2055:     if ($state eq 'will_exceed_quota'
 2056: 	|| $state eq 'file_locked'
 2057:         || $state eq 'zero_bytes') {
 2058: 	$r->print($msg.&done(undef,$url));
 2059: 	return;
 2060:     }
 2061: 
 2062:     my (%allfiles,%codebase,$mode,$mimetype);
 2063:     if ($env{'form.'.$formname.'.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) {
 2064:         if ($env{'form.parserflag'}) {
 2065: 	    $mode = 'parse';
 2066:         }
 2067:     }
 2068:     my $context;
 2069:     if ($state eq 'existingfile') {
 2070:         $context = $state;
 2071:     }
 2072:     my $subdir = $port_path.$env{'form.currentpath'};
 2073:     $subdir =~ s{(/)$}{};
 2074:     my ($result,$timestamp) =
 2075: 	&Apache::lonnet::userfileupload($formname,$context,$subdir,
 2076: 					$mode,\%allfiles,\%codebase,undef,undef,
 2077:                                         undef,undef,undef,undef,\$mimetype);
 2078:     if ($state eq 'existingfile') {
 2079:         my $group_elem;
 2080:         my $rootdir = $r->dir_config('lonDaemons').'/tmp/overwrites';
 2081:         if ($group eq '') {
 2082:             $rootdir .= '/'.$env{'user.domain'}.'/'.$env{'user.name'};
 2083:         } else {
 2084:             $rootdir .= '/'.$env{'course.'.$env{'request.course.id'}.'.domain'}.
 2085:                         '/'.$env{'course.'.$env{'request.course.id'}.'.num'};
 2086:             $group_elem = '<input type="hidden" name="group" value="'.$group.'" />';
 2087:         }
 2088:         if (($result eq $rootdir.'/'.$port_path.$env{'form.currentpath'}.$fname) && ($timestamp =~ /^\d+$/)) {
 2089:             my $showfname = &HTML::Entities::encode($fname,'&<>"');
 2090:             my %lt = &Apache::lonlocal::texthash (
 2091:                                                    over => 'Overwrite existing file?',
 2092:                                                    yes  => 'Yes',
 2093:                                                    no   => 'No',
 2094:                                                    undo => 'This action can not be undone.',
 2095:                                                    conf => 'Are you sure you want to overwrite an existing file?',
 2096:                                                    cont => 'Continue',
 2097:                                                  );
 2098:             my $parserflag;
 2099:             my $hidden = &hidden_elems();
 2100:             if ($mode eq 'parse') {
 2101:                 $parserflag = '<input type="hidden" name="parserflag" value="1" />';
 2102:             }
 2103:             $r->print(<<"END");
 2104: <script type="text/javascript">
 2105: // <![CDATA[
 2106: function confirmOverwrite() {
 2107:     var chosen;
 2108:     if (document.existingfile.overwrite.length) {
 2109:         for (var i=0; i<document.existingfile.overwrite.length; i++) {
 2110:             if (document.existingfile.overwrite[i].checked) {
 2111:                 chosen = document.existingfile.overwrite[i].value;
 2112:             }
 2113:         }
 2114:     }
 2115:     if (chosen == 1) {
 2116:         if (confirm('$lt{'conf'}')) {
 2117:             document.existingfile.action.value = "process_overwrite";
 2118:             return true;
 2119:         } else {
 2120:             document.existingfile.action.value = "cancel_overwrite";
 2121:             if (document.existingfile.overwrite.length) {
 2122:                 for (var i=0; i<document.existingfile.overwrite.length; i++) {
 2123:                     if (document.existingfile.overwrite[i].value == "0") {
 2124:                         document.existingfile.overwrite[i].checked = true;
 2125:                     }
 2126:                 }
 2127:             }
 2128:             return false;
 2129:         }
 2130:     } else {
 2131:         document.existingfile.action.value = "cancel_overwrite";
 2132:         return true;
 2133:     }
 2134: }
 2135: // ]]>
 2136: </script>
 2137: <p>
 2138: $msg
 2139: </p>
 2140: <form method="post" action="$url" name="existingfile" onsubmit="return confirmOverwrite();">
 2141: <p class="LC_nobreak">$lt{'over'}
 2142: <label><input type="radio" name="overwrite" value="1" />
 2143: $lt{'yes'}</label>&nbsp;
 2144: <label><input type="radio" name="overwrite" value="0" checked="checked" />$lt{'no'}</label></p>
 2145: <p>
 2146: <input type="hidden" name="action" value="cancel_overwrite" />
 2147: <input type="hidden" name="filename" value="$showfname" />
 2148: <input type="hidden" name="timestamp" value="$timestamp" />
 2149: $hidden
 2150: $parserflag
 2151: $group_elem
 2152: <input type="submit" name="process" value="$lt{'cont'}" />
 2153: </p>
 2154: </form>
 2155: END
 2156:         } else {
 2157:         $r->print(
 2158:             &Apache::loncommon::confirmwrapper(
 2159:                 &Apache::lonhtmlcommon::confirm_success(
 2160:                     &mt('An error occurred ([_1]) while trying to upload [_2].'
 2161:                         ,$result,&display_file(undef,$fname)),1)));
 2162:             $r->print(&done(undef,$url));
 2163:         }
 2164:     } elsif ($result !~ m|^/uploaded/|) {
 2165:         $r->print(
 2166:             &Apache::loncommon::confirmwrapper(
 2167:                 &Apache::lonhtmlcommon::confirm_success(
 2168:                     &mt('An error occurred ([_1]) while trying to upload [_2].'
 2169:                         ,$result,&display_file(undef,$fname)),1)));
 2170: 	$r->print(&done(undef,$url));
 2171:     } else {
 2172:         if (!&suppress_embed_prompt()) {
 2173:             if ($mimetype eq 'text/html') {
 2174: 	        if (keys(%allfiles) > 0) {
 2175:                     &print_dependency_form($r,$url,\%allfiles,\%codebase,$result);
 2176:                     return;
 2177: 	        } else {
 2178:                     $r->print('<p class="LC_warning">'.&mt('No embedded items identified.').'</p>');
 2179:                 }
 2180:             }
 2181:         }
 2182:         $r->print(
 2183:             &Apache::loncommon::confirmwrapper(
 2184:                 &Apache::lonhtmlcommon::confirm_success(
 2185:                     &mt('File successfully uploaded'))));
 2186: 	$r->print(&done(undef,$url));
 2187:     }
 2188:     return;
 2189: }
 2190: 
 2191: sub hidden_elems {
 2192:     my $contelem;
 2193:     if ($env{'form.mode'} eq 'selectfile') {
 2194:         $contelem = '<input type="hidden" name="continue" value="true" />';
 2195:     }
 2196:     return <<END;
 2197: <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
 2198: <input type="hidden" name="symb" value="$env{'form.symb'}" />
 2199: <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
 2200: <input type="hidden" name="mode" value="$env{'form.mode'}" />
 2201: <input type="hidden" name="showversions" value="$env{'form.showversions'}" />
 2202: $contelem
 2203: END
 2204: }
 2205: 
 2206: sub print_dependency_form {
 2207:     my ($r,$url,$allfiles,$codebase,$result) = @_;
 2208:     my $container = &HTML::Entities::encode($result,'<>"&');
 2209:     my $state = &embedded_form_elems($container);
 2210:     my ($embedded,$num,$pathchg) = &Apache::loncommon::ask_for_embedded_content($url,$state,$allfiles,$codebase,
 2211:                                   {'error_on_invalid_names'   => 1,
 2212:                                    'ignore_remote_references' => 1,});
 2213:     if ($embedded) {
 2214:         if ($num || $pathchg) {
 2215:             $r->print('<h3>'.&mt("Reference Warning").'</h3>');
 2216:         } else {
 2217:             $r->print('<h3>'.&mt("Reference Information").'</h3>');
 2218:         }
 2219:         if ($num) {
 2220:             $r->print('<p>'.&mt('Completed upload of the file.').' '.
 2221:                       &mt('This file contained references to other files.').' '.
 2222:                       &mt('You must upload the referenced files or else the uploaded file may not work properly.').
 2223:                       '</p>'.
 2224:                       '<p>'.&mt("Please select the locations from which the referenced files are to be uploaded.").'</p>'.
 2225:                        $embedded.
 2226:                        '<p>'.&mt('or').'</p>'.&done('Return to directory',$url));
 2227:         } else {
 2228:             $r->print('<p>'.&mt("Completed upload of the file. This file contained references to other files.").'</p>'.
 2229:                       $embedded.
 2230:                       '<p>'.&done('Return to directory',$url).'</p>');
 2231:         }
 2232:     } else {
 2233:         $r->print(&done(undef,$url));
 2234:     }
 2235:     return;
 2236: }
 2237: 
 2238: sub overwrite {
 2239:     my ($r,$url,$group)=@_;
 2240:     my $formname = 'existingfile';
 2241:     my $port_path = &get_port_path();
 2242:     my $fname = &Apache::lonnet::clean_filename($env{'form.filename'});
 2243:     my (%allfiles,%codebase,$mode,$mimetype);
 2244:     unless (&suppress_embed_prompt()) {
 2245:         if ($env{'form.parserflag'}) {
 2246:             if ($fname =~ /\.s?html?$/i) {
 2247:                 $mode = 'parse';
 2248:             }
 2249:         }
 2250:     }
 2251:     if ($fname eq '') {
 2252:         $r->print(
 2253:             &Apache::loncommon::confirmwrapper(
 2254:                 &Apache::lonhtmlcommon::confirm_success(
 2255:                     &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
 2256:                       'so after eliminating special characters there was nothing left.',
 2257:                       '<span class="LC_filename">'.$env{'form.filename'}.'</span>'),1)));
 2258:         $r->print(&done(undef,$url));
 2259:         return;
 2260:     }
 2261:     $env{'form.'.$formname.'.filename'} = $fname;
 2262:     my $subdir = $port_path.$env{'form.currentpath'};
 2263:     $subdir =~ s{(/)$}{};
 2264:     my $result=
 2265:         &Apache::lonnet::userfileupload($formname,'overwrite',$subdir,$mode,
 2266:                                         \%allfiles,\%codebase,undef,undef,undef,
 2267:                                         undef,undef,undef,\$mimetype);
 2268:     if ($result !~ m|^/uploaded/|) {
 2269:         $r->print(
 2270:             &Apache::loncommon::confirmwrapper(
 2271:                 &Apache::lonhtmlcommon::confirm_success(
 2272:                     &mt('An error occurred ([_1]) while trying to overwrite [_2].'
 2273:                        ,$result,&display_file(undef,$fname)),1)));
 2274:     } else {
 2275:         if ($mode eq 'parse') {
 2276:             if ($mimetype eq 'text/html') {
 2277:                 if (keys(%allfiles) > 0) {
 2278:                     &print_dependency_form($r,$url,\%allfiles,\%codebase,$result);
 2279:                     return;
 2280:                 } else {
 2281:                     $r->print(
 2282:                         &Apache::loncommon::confirmwrapper(
 2283:                             &Apache::lonhtmlcommon::confirm_success(
 2284:                                 &mt('Overwriting completed.'))
 2285:                            .'<br />'.&mt('No embedded items identified.')));
 2286:                 }
 2287:             }
 2288:         } else {
 2289:             $r->print(
 2290:                 &Apache::loncommon::confirmwrapper(
 2291:                     &Apache::lonhtmlcommon::confirm_success(
 2292:                         &mt('Overwriting completed.'))));
 2293:         }
 2294:     }
 2295: 
 2296:     my $group_elem;
 2297:     if (defined($env{'form.group'})) {
 2298:         $group_elem = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />';
 2299:         if (defined($env{'form.ref'})) {
 2300:             $group_elem .= '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'."\n";
 2301:         }
 2302:     }
 2303:     my $hidden = &hidden_elems();
 2304:     $r->print(
 2305:         &Apache::lonhtmlcommon::actionbox(
 2306:             ['<a href="javascript:document.overwritedone.submit();">'
 2307:             .&mt('Return to directory')
 2308:             .'</a>'])
 2309:        .'<form name="overwritedone" method="post" action="'.$url.'">'
 2310:        .$hidden
 2311:        .$group_elem
 2312:        .'</form>'
 2313:     );
 2314:     return;
 2315: }
 2316: 
 2317: sub lock_info {
 2318:     my ($r,$url,$group) = @_;
 2319:     my ($uname,$udom) = &get_name_dom($group);
 2320:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
 2321:                                                                        $uname);
 2322:     my $file_name = $env{'form.lockinfo'};
 2323:     $file_name = &prepend_group($file_name);
 2324:     if (defined($file_name) && defined($$current_permissions{$file_name})) {
 2325:         foreach my $array_item (@{$$current_permissions{$file_name}}) {
 2326:             next if (ref($array_item) ne 'ARRAY');
 2327: 
 2328: 	    my $filetext;
 2329: 	    if (defined($group)) {
 2330: 		$filetext = '<strong>'.$env{'form.lockinfo'}.
 2331: 		    '</strong> (group: '.$group.')'; 
 2332: 	    } else {
 2333: 		$filetext = '<span class="LC_filename">'.$file_name.'</span>';
 2334: 	    } 
 2335: 	    
 2336: 	    my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
 2337: 		'</strong><br />';
 2338: 	    if ($$array_item[-1] eq 'graded') {
 2339: 		$r->print(&mt('[_1] was submitted in response to problem: [_2]',
 2340:                               $filetext,$title));
 2341: 	    } elsif ($$array_item[-1] eq 'handback') {
 2342: 		$r->print(&mt('[_1] was handed back in response to problem: [_2]',
 2343:                               $filetext,$title));
 2344: 	    } else {
 2345: 		# submission style lock
 2346: 		$r->print(&mt('[_1] was submitted in response to problem: [_2]',
 2347:                               $filetext,$title));
 2348: 	    }
 2349: 	    my %course_description = 
 2350: 		&Apache::lonnet::coursedescription($$array_item[1]);
 2351: 	    if ( $course_description{'description'} ne '') {
 2352: 		$r->print(&mt('In the course:').' <strong>'.$course_description{'description'}.'</strong><br />');
 2353: 	    }
 2354:         }
 2355:     }
 2356:     $r->print(&done(undef,$url));
 2357:     return 'ok';
 2358: }
 2359: 
 2360: sub createdir {
 2361:     my ($r,$url,$group)=@_;
 2362:     my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
 2363:     # Display warning in case of directory name cleaning has changed the directory name
 2364:     if ($newdir ne $env{'form.newdir'}) {
 2365:         $r->print(
 2366:             '<p><span class="LC_warning">'
 2367:            .&mt('Invalid characters')
 2368:            .'</span><br />'
 2369:            .&mt('The new directory name was changed from [_1] to [_2].'
 2370:                       ,'<span class="LC_filename">'.$env{'form.newdir'}.'</span>'
 2371:                       ,'<span class="LC_filename">'.$newdir.'</span>')
 2372:            .'</p>'
 2373:         );
 2374:     }
 2375: 
 2376:     # Directory name empty?
 2377:     if ($newdir eq '') {
 2378:         $r->print(
 2379:             &Apache::loncommon::confirmwrapper(
 2380:                 &Apache::lonhtmlcommon::confirm_success(
 2381:                     &mt('Error: no directory name was provided.'),1)));
 2382:             $r->print(&done(undef,$url));
 2383:             return;
 2384:     }
 2385: 
 2386:     my $portfolio_root = &get_portfolio_root(); 
 2387:     my ($dirlistref,$listerror) = &get_dir_list($portfolio_root,undef,$group);
 2388:     my $found_file = 0;
 2389:     if (ref($dirlistref) eq 'ARRAY') {
 2390:         foreach my $line (@{$dirlistref}) {
 2391:             my ($filename)=split(/\&/,$line,2);
 2392:             if ($filename eq $newdir){
 2393:                 $found_file = 1;
 2394:             }
 2395:         }
 2396:     }
 2397:     if ($found_file) {
 2398:         $r->print(
 2399:             &Apache::loncommon::confirmwrapper(
 2400:                 &Apache::lonhtmlcommon::confirm_success(
 2401:                     &mt('Unable to create a directory named [_1].'
 2402:                         ,'<span class="LC_filename">'.$newdir.'</span>'),1)
 2403:                .'<br />'.&mt('A file or directory by that name already exists.')));
 2404:     } else {
 2405:         my ($uname,$udom) = &get_name_dom($group);
 2406:         my $port_path = &get_port_path();
 2407:         my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
 2408: 	         $port_path.$env{'form.currentpath'}.$newdir);
 2409:         if ($result ne 'ok') {
 2410:         $r->print(
 2411:             &Apache::loncommon::confirmwrapper(
 2412:                 &Apache::lonhtmlcommon::confirm_success(
 2413:                     &mt('An error occurred ([_1]) while trying to create a new directory [_2].'
 2414:                         ,$result,&display_file()),1)));
 2415: 
 2416:         } else {
 2417:         $r->print(
 2418:             &Apache::loncommon::confirmwrapper(
 2419:                 &Apache::lonhtmlcommon::confirm_success(
 2420:                     &mt('Directory successfully created'))));
 2421:         }
 2422:     }
 2423:     $r->print(&done(undef,$url));
 2424: }
 2425: 
 2426: sub get_portfolio_root {
 2427:     my ($udom,$uname,$group) = @_;
 2428:     if (!(defined($udom)) || !(defined($uname))) {
 2429:         ($uname,$udom) = &get_name_dom($group);
 2430:     }
 2431:     my $path = '/userfiles/portfolio';
 2432:     if (!defined($group)) { 
 2433:         if (defined($env{'form.group'})) {
 2434:             $group = $env{'form.group'};      
 2435:         }
 2436:     }
 2437:     if (defined($group)) {
 2438:         $path = '/userfiles/groups/'.$group.'/portfolio';
 2439:     } 
 2440:     return $path;
 2441: }
 2442: 
 2443: sub get_group_quota {
 2444:     my ($group) = @_;
 2445:     my $group_quota; 
 2446:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 2447:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
 2448:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
 2449:     if (%curr_groups) {
 2450:         my %group_info =  &Apache::longroup::get_group_settings(
 2451:                                                     $curr_groups{$group});
 2452:         $group_quota = $group_info{'quota'}; #expressed in MB
 2453:         if ($group_quota) {
 2454:             $group_quota = 1000 * $group_quota; #expressed in k
 2455:         }
 2456:     }
 2457:     return $group_quota;
 2458: }
 2459: 
 2460: sub get_dir_list {
 2461:     my ($portfolio_root,$path,$group) = @_;
 2462:     $path ||= $env{'form.currentpath'};
 2463:     my ($uname,$udom) = &get_name_dom($group);
 2464:     my $getpropath = 1;
 2465:     return &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
 2466: }
 2467: 
 2468: sub get_name_dom {
 2469:     my ($group) = @_;
 2470:     my ($uname,$udom);
 2471:     if (defined($group)) {
 2472:         $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
 2473:         $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
 2474:     } else {
 2475:         $udom = $env{'user.domain'};
 2476:         $uname = $env{'user.name'};
 2477:     }
 2478:     return ($uname,$udom);
 2479: }
 2480: 
 2481: sub prepend_group {
 2482:     my ($filename) = @_;
 2483:     if (defined($env{'form.group'})) {
 2484:         $filename = $env{'form.group'}.$filename;
 2485:     }
 2486:     return $filename;
 2487: }
 2488: 
 2489: sub get_namespace {
 2490:     my $namespace = 'portfolio';
 2491:     if (defined($env{'form.group'})) {
 2492:         my ($uname,$udom) = &get_name_dom($env{'form.group'});
 2493:         $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
 2494:     }
 2495:     return $namespace;
 2496: }
 2497: 
 2498: sub get_port_path {
 2499:     my $port_path;
 2500:     if (defined($env{'form.group'})) {
 2501:        $port_path = "groups/$env{'form.group'}/portfolio";
 2502:     } else {
 2503:        $port_path = 'portfolio';
 2504:     }
 2505:     return $port_path;
 2506: }
 2507: 
 2508: sub missing_priv {
 2509:     my ($r,$url,$priv) = @_;
 2510:     my %longtext = 
 2511:         &Apache::lonlocal::texthash(
 2512:                       upload => 'upload files',
 2513:                       delete => 'delete files',
 2514:                       rename => 'rename files',
 2515:                       setacl => 'set access controls for files',
 2516:     );
 2517:     my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
 2518:     my $rtnlink = '<a href="'.$url;
 2519:     if ($url =~ /\?/) {
 2520:         $rtnlink .= '&';
 2521:     } else {
 2522:         $rtnlink .= '?';
 2523:     }
 2524:     $rtnlink .= 'currentpath='.$escpath;
 2525:     $r->print('<h3>'.&mt('Action disallowed').'</h3>');
 2526:     $r->print(&mt('You do not have sufficient privileges to [_1]',
 2527:                   $longtext{$priv}));
 2528:     if (defined($env{'form.group'})) {
 2529:         $r->print(' '.&mt("in the group's group portfolio."));
 2530:         $rtnlink .= &group_args()
 2531:     } else {
 2532:         $r->print(' '.&mt('in this portfolio.'));
 2533:     }
 2534:     $rtnlink .= '">'.&mt('Return to directory').'</a>';
 2535:     $r->print('<br />'.$rtnlink);
 2536:     return;
 2537: }
 2538: 
 2539: sub coursegrp_portfolio_header {
 2540:     my ($cdom,$cnum,$grp_desc)=@_;
 2541:     my $gpterm  = &Apache::loncommon::group_term();
 2542:     my $ucgpterm = $gpterm;
 2543:     $ucgpterm =~ s/^(\w)/uc($1)/e;
 2544:     if ($env{'form.ref'}) {
 2545:         &Apache::lonhtmlcommon::add_breadcrumb
 2546:             ({href=>"/adm/coursegroups",
 2547:               text=>"Groups",
 2548:               title=>"Course Groups"});
 2549:     }
 2550:     &Apache::lonhtmlcommon::add_breadcrumb
 2551:         ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
 2552:           text=>&mt('Group').": $grp_desc",
 2553:           title=>&mt("Go to group's home page"),
 2554:           no_mt=>1},
 2555:          {href=>"/adm/coursegrp_portfolio?".&group_args(),
 2556:           text=>"Group Portfolio",
 2557:           title=>"Display group portfolio"});
 2558:     my $output = &Apache::lonhtmlcommon::breadcrumbs(
 2559:                          &mt('Group portfolio files - [_1]',$grp_desc),
 2560:                                                      undef,undef,undef,undef,1);
 2561:     return $output;
 2562: }
 2563: 
 2564: sub get_quota {
 2565:     my ($group) = @_;
 2566:     my $disk_quota;
 2567:     if (defined($group)) {
 2568:         my $grp_quota = &get_group_quota($group); # quota expressed in k
 2569:         if ($grp_quota ne '') {
 2570:             $disk_quota = $grp_quota;
 2571:         } else {
 2572:             $disk_quota = 0;
 2573:         }
 2574:     } else {
 2575:         $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
 2576:                                     $env{'user.domain'}); #expressed in MB
 2577:         $disk_quota = 1024 * $disk_quota; # convert from MB to kB
 2578:     }
 2579:     return $disk_quota;
 2580: }
 2581: 
 2582: sub suppress_embed_prompt {
 2583:     my $suppress_prompt = 0;
 2584:     if (($env{'request.role'} =~ /^st/) && ($env{'request.course.id'} ne '')) {
 2585:         if ($env{'course.'.$env{'request.course.id'}.'.suppress_embed_prompt'} eq 'yes') {
 2586:             $suppress_prompt = 1;
 2587:         }
 2588:     }
 2589:     return $suppress_prompt;
 2590: }
 2591: 
 2592: sub embedded_form_elems {
 2593:     my ($container) = @_;
 2594:     my $state = <<STATE;
 2595:     <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
 2596:     <input type="hidden" name="symb" value="$env{'form.symb'}" />
 2597:     <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
 2598:     <input type="hidden" name="mode" value="$env{'form.mode'}" />
 2599:     <input type="hidden" name="container" value="$container" />
 2600: STATE
 2601:     if ($env{'form.group'} ne '') {
 2602:         $state .= '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />'."\n";
 2603:     }
 2604:     return $state;
 2605: }
 2606: 
 2607: # Find space available in a user's portfolio (convert to bytes)
 2608: sub free_space {
 2609:     my ($group) = @_;
 2610:     my $disk_quota = &get_quota($group); # Expressed in kB
 2611:     my ($uname,$udom) = &get_name_dom($group);
 2612:     my $portfolio_root = &get_portfolio_root();
 2613:     my $getpropath = 1;
 2614:     my $current_disk_usage = &Apache::lonnet::diskusage($udom, $uname,
 2615:                              $portfolio_root, $getpropath); # Expressed in kB
 2616:     my $free_space = 1024 * ($disk_quota - $current_disk_usage);
 2617:     return $free_space;
 2618: }
 2619: 
 2620: sub valid_container {
 2621:     my ($uname,$udom,$group) = @_;
 2622:     my $container_prefix;
 2623:     if ($group ne '') {
 2624:         $container_prefix = "/uploaded/$udom/$uname/groups/$group/portfolio";
 2625:     } else {
 2626:         $container_prefix = "/uploaded/$udom/$uname/portfolio";
 2627:     }
 2628:     if ($env{'form.currentpath'}) {
 2629:         $container_prefix .= $env{'form.currentpath'};
 2630:     } else {
 2631:         $container_prefix .= '/';
 2632:     }
 2633:     if ($env{'form.container'} =~ m{^\Q$container_prefix\E(.+)$}) {
 2634:         my $filename = $1;
 2635:         if ($filename eq &Apache::lonnet::clean_filename($filename)) {
 2636:             return 1;
 2637:         }
 2638:     }
 2639:     return;
 2640: }
 2641: 
 2642: sub invalid_parms {
 2643:     my ($r,$url,$currentpath) = @_;
 2644:     my $escpath = &HTML::Entities::encode($currentpath,'&<>"');
 2645:     my $rtnlink = '<a href="'.$url;
 2646:     if ($url =~ /\?/) {
 2647:         $rtnlink .= '&';
 2648:     } else {
 2649:         $rtnlink .= '?';
 2650:     }
 2651:     $rtnlink .= 'currentpath='.$escpath;
 2652:     $rtnlink .= '">'.&mt('Return to directory').'</a>';
 2653:     $r->print('<h3>'.&mt('Action disallowed').'</h3>');
 2654:     $r->print(&mt('Some of the data included with this request were invalid'));
 2655:     $r->print('<br />'.$rtnlink);
 2656:     return;
 2657: }
 2658: 
 2659: sub handler {
 2660:     # this handles file management
 2661:     my $r = shift;
 2662:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 2663:          ['selectfile','currentpath','meta','lockinfo','currentfile','action',
 2664: 	  'fieldname','mode','rename','continue','group','access','setnum',
 2665:           'cnum','cdom','type','setroles','showversions','ref','symb']);
 2666:     my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
 2667:     if ($r->uri =~ m|^(/adm/)([^/]+)|) {
 2668:         $url = $1.$2;
 2669:         $caller = $2;
 2670:     }
 2671:     my ($can_modify,$can_delete,$can_upload,$can_setacl);
 2672:     if ($caller eq 'coursegrp_portfolio') {
 2673:     #  Needs to be in a course
 2674:         if (! ($env{'request.course.fn'})) {
 2675:         # Not in a course
 2676:             $env{'user.error.msg'}=
 2677:      "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
 2678:             return HTTP_NOT_ACCEPTABLE;
 2679:         }
 2680:         my $earlyout = 0;
 2681:         my $view_permission = 
 2682:            &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
 2683:         $env{'form.group'} =~ s/\W//g;
 2684: 	$group = $env{'form.group'};
 2685:         if ($group ne '') {
 2686:             ($uname,$udom) = &get_name_dom($group);
 2687:             my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
 2688: 							       $group); 
 2689:             if (%curr_groups) {
 2690:                 my %grp_content = &Apache::longroup::get_group_settings(
 2691:                                                          $curr_groups{$group});
 2692:                 $grp_desc = &unescape($grp_content{'description'});
 2693:                 if (($view_permission) || (&Apache::lonnet::allowed('rgf',
 2694:                                       $env{'request.course.id'}.'/'.$group))) {
 2695:                     $portfolio_root = &get_portfolio_root();
 2696:                 } else {
 2697:                     $r->print(&mt('You do not have the privileges required to access the shared files space for this group.'));
 2698:                     $earlyout = 1;
 2699:                 }
 2700:             } else {
 2701:                 $r->print(&mt('Not a valid group for this course'));
 2702:                 $earlyout = 1;
 2703:             }
 2704:             $title = &mt('Group portfolio for [_1]', $group); 
 2705:         } else {
 2706:             $r->print(&mt('Invalid group'));
 2707:             $earlyout = 1;
 2708:         }
 2709:         if ($earlyout) { return OK; }
 2710:         if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
 2711:             $can_modify = 1;
 2712:             $can_delete = 1;
 2713:             $can_upload = 1;
 2714:             $can_setacl = 1;
 2715:         } else {
 2716:             if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
 2717:                 $can_setacl = 1;
 2718:             }
 2719:             if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
 2720:                 $can_upload = 1;
 2721:             }
 2722:             if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
 2723:                 $can_modify = 1;
 2724:             }
 2725:             if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
 2726:                 $can_delete = 1;
 2727:             }
 2728:         }
 2729:     } else {
 2730:         ($uname,$udom) = &get_name_dom();
 2731:         $portfolio_root = &get_portfolio_root();
 2732:         $title = 'My Space';
 2733:         $can_modify = 1;
 2734:         $can_delete = 1;
 2735:         $can_upload = 1;
 2736:         $can_setacl = 1;
 2737:     }
 2738: 
 2739:     my $port_path = &get_port_path();
 2740:     &Apache::loncommon::no_cache($r);
 2741:     &Apache::loncommon::content_type($r,'text/html');
 2742:     $r->send_http_header;
 2743:     # Give the LON-CAPA page header
 2744:     my $brcrum = [{href=>"/adm/portfolio",text=>"Portfolio Manager"}];
 2745: 
 2746:     my $js = '<script type="text/javascript"
 2747:                 src="/res/adm/includes/file_upload.js"></script>';
 2748: 
 2749:     if ($env{"form.mode"} eq 'selectfile'){
 2750:         $r->print(&Apache::loncommon::start_page($title, $js,
 2751: 						 {'only_body' => 1}));
 2752:     } elsif ($env{'form.action'} eq 'rolepicker') {
 2753:         $r->print(&Apache::loncommon::start_page('New role-based condition', $js,
 2754:                                                  {'no_nav_bar'  => 1, }));
 2755:     } elsif ($caller eq 'coursegrp_portfolio') {
 2756:         $r->print(&Apache::loncommon::start_page($title, $js));
 2757:     } else {
 2758:         $r->print(&Apache::loncommon::start_page($title, $js,
 2759:                                                  {'bread_crumbs' => $brcrum}));
 2760:         if (!&Apache::lonnet::usertools_access($uname,$udom,'portfolio')) {
 2761:             $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
 2762:                       &mt('This is a result of one of the following:').'<ul>'.
 2763:                       '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
 2764:                       '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
 2765:                       '</ul>');
 2766:             $r->print(&Apache::loncommon::end_page());
 2767:             return OK;
 2768:         }
 2769:     }
 2770:     $r->rflush();
 2771:     # Check if access to portfolio is blocked by one or more blocking events in courses.
 2772:     my $clientip = &Apache::lonnet::get_requestor_ip($r);
 2773:     my ($blocked,$blocktext) = 
 2774:         &Apache::loncommon::blocking_status('port',$clientip,$uname,$udom);
 2775:     if ($blocked) {
 2776:         my $evade_block;
 2777:         # If portfolio display is in a window popped up from a "Select Portfolio Files"
 2778:         # link in a .task resource, check if access to the task included proctor validation
 2779:         # of check-in to a slot limited by IP.
 2780:         # If so, and the slot is between its open and close dates, override the block. 
 2781:         if ($env{'request.course.id'} && $env{'form.symb'}) {
 2782:             (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
 2783:             if ($res =~ /\.task$/i) {
 2784:                 my %history =
 2785:                     &Apache::lonnet::restore($env{'form.symb'},$env{'request.course.id'},
 2786:                                              $env{'user.domain'},$env{'user.name'});
 2787:                 my $version = $history{'resource.0.version'};
 2788:                 if ($history{'resource.'.$version.'.0.checkedin'}) {
 2789:                     if ($history{'resource.'.$version.'.0.checkedin.slot'}) {
 2790:                         my %slot = &Apache::lonnet::get_slot($history{'resource.'.$version.'.0.checkedin.slot'});
 2791:                         if ($slot{'ip'}) {
 2792:                             if (&Apache::loncommon::check_ip_acc($slot{'ip'})) {
 2793:                                 my $now = time;
 2794:                                 if (($slot{'slottime'} < $now) && ($slot{'endtime'} > $now)) {
 2795:                                     $evade_block = 1;
 2796:                                 }
 2797:                             }
 2798:                         }
 2799:                     }
 2800:                 }
 2801:             }
 2802:         }
 2803:         unless ($evade_block) {
 2804:             $r->print($blocktext);
 2805:             $r->print(&Apache::loncommon::end_page());
 2806:             return OK;
 2807:         }
 2808:     }
 2809:     if (($env{'form.currentpath'}) && ($env{'form.currentpath'} ne '/')) {
 2810:         my $clean_currentpath = '/'.&Apache::loncommon::clean_path($env{'form.currentpath'}).'/';
 2811:         unless ($env{'form.currentpath'} eq $clean_currentpath) {
 2812:             &invalid_parms($r,$url);
 2813:             $r->print(&Apache::loncommon::end_page());
 2814:             return OK;
 2815:         }
 2816:     }
 2817:     if ($env{'form.container'}) {
 2818:         unless (&valid_container($uname,$udom,$group)) {
 2819:             &invalid_parms($r,$url,$env{'form.currentpath'});
 2820:             $r->print(&Apache::loncommon::end_page());
 2821:             return OK;
 2822:         }
 2823:     }
 2824:     if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
 2825:    	$r->print(
 2826:             '<p><span class="LC_warning">'
 2827:            .&mt('No file was selected to upload.')
 2828:            .'</span><br />'
 2829:            .&mt('To upload a file, click [_1]Browse...[_2] and select a file, then click [_1]Upload[_2].'
 2830:                 ,'<strong>','</strong>')
 2831:            .'</p>'
 2832:         );
 2833:     }
 2834:     if ($env{'form.meta'}) {
 2835:         &open_form($r,$url);
 2836:         $r->print(&mt('Edit Metadata').'<br />');
 2837:         &close_form($r,$url);
 2838:     }
 2839:     if ($env{'form.uploaddoc.filename'}) {
 2840:         if ($can_upload) {
 2841: 	    &upload($r,$url,$group);
 2842:         } else {
 2843:             &missing_priv($r,$url,'upload');
 2844:         }
 2845:     } elsif ($env{'form.action'} eq 'process_overwrite') {
 2846:         if ($can_upload) {
 2847:             &overwrite($r,$url,$group);
 2848:         } else {
 2849:             &missing_priv($r,$url,'existingfile');
 2850:         }
 2851:     } elsif ($env{'form.action'} eq 'upload_embedded') {
 2852: 	if ($can_upload) {
 2853:             my $disk_quota = &get_quota($group);
 2854:             my $getpropath = 1;
 2855:             my $current_disk_usage = 
 2856:                 &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
 2857:             my $container = &HTML::Entities::encode($env{'form.container'},'<>&"');
 2858:             my $state = &embedded_form_elems($container).
 2859:                         '<input type="hidden" name="action" value="modify_orightml" />';
 2860: 	    my ($result,$flag) =
 2861:                 &Apache::loncommon::upload_embedded('portfolio',$port_path,$uname,$udom,
 2862:                     $group,$portfolio_root,$group,$disk_quota,$current_disk_usage,$state,$url);
 2863:             $r->print($result.&done('Return to directory',$url));
 2864:         } else {
 2865:             &missing_priv($r,$url,'upload');
 2866:         }
 2867:     } elsif ($env{'form.action'} eq 'modify_orightml') {
 2868:         if ($can_upload) {
 2869:             my $result = 
 2870:                 &Apache::loncommon::modify_html_refs('portfolio',$port_path,$uname,
 2871:                                                      $udom,$portfolio_root);
 2872:             $r->print($result.
 2873:                       &done('Return to directory',$url));
 2874:         } else {
 2875:             &missing_priv($r,$url,'upload');
 2876:         }
 2877:     } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
 2878:         if ($can_delete) {
 2879: 	    &delete_confirmed($r,$url,$group);
 2880:         } else {
 2881:             &missing_priv($r,$url,'delete');
 2882:         }
 2883:     } elsif ($env{'form.action'} eq 'delete') {
 2884:         if ($can_delete) {
 2885: 	    &delete($r,$url,$group);
 2886:         } else {
 2887:             &missing_priv($r,$url,'delete');
 2888:         }
 2889:     } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
 2890:         if ($can_delete) {
 2891: 	    &delete_dir_confirmed($r,$url,$group);
 2892:         } else {
 2893:             &missing_priv($r,$url,'delete');
 2894:         }
 2895:     } elsif ($env{'form.action'} eq 'deletedir') {
 2896:         if ($can_delete) {
 2897: 	    &delete_dir($r,$url);
 2898:         } else {
 2899:             &missing_priv($r,$url,'delete');
 2900:         }
 2901:     } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
 2902:         if ($can_modify) {
 2903: 	    &rename_confirmed($r,$url,$group);
 2904:         } else {
 2905:             &missing_priv($r,$url,'rename');
 2906:         }
 2907:     } elsif ($env{'form.rename'}) {
 2908:         $env{'form.selectfile'} = $env{'form.rename'};
 2909:         $env{'form.action'} = 'rename';
 2910:         if ($can_modify) {
 2911: 	    &rename($r,$url,$group);
 2912:         } else {
 2913:             &missing_priv($r,$url,'rename');
 2914:         }
 2915:     } elsif ($env{'form.access'}) {
 2916:         $env{'form.selectfile'} = $env{'form.access'};
 2917:         if (!defined($env{'form.action'})) { 
 2918:             $env{'form.action'} = 'chgaccess';
 2919:         }
 2920:         &display_access($r,$url,$group,$can_setacl,$port_path,$env{'form.action'});
 2921:     } elsif (($env{'form.action'} eq 'chgaccess') || 
 2922:              ($env{'form.action'} eq 'chgconditions')) {
 2923:         if ($can_setacl) {
 2924:             &update_access($r,$url,$group,$port_path);
 2925:         } else {
 2926:             &missing_priv($r,$url,'setacl');
 2927:         }
 2928:     } elsif ($env{'form.action'} eq 'rolepicker') {
 2929:         if ($can_setacl) { 
 2930:             &role_options_window($r);
 2931:         } else {
 2932:             &missing_priv($r,$url,'setacl');
 2933:         }
 2934:     } elsif ($env{'form.createdir'}) {
 2935:         if ($can_upload) {
 2936: 	    &createdir($r,$url,$group);
 2937:         } else {
 2938:             &missing_priv($r,$url,'upload');
 2939:         }
 2940:     } elsif ($env{'form.lockinfo'}) {
 2941:         &lock_info($r,$url,$group);
 2942:     } else {
 2943:         if ($env{'form.action'} eq 'cancel_overwrite') {
 2944:             if ($can_upload) {
 2945:                 my $formname = 'existingfile';
 2946:                 my $fname = &Apache::lonnet::clean_filename($env{'form.filename'});
 2947:                 $env{'form.'.$formname.'.filename'} = $fname;
 2948:                 my $subdir = $port_path.$env{'form.currentpath'};
 2949:                 $subdir =~ s{(/)$}{};
 2950:                 &Apache::lonnet::userfileupload($formname,'canceloverwrite',$subdir);
 2951:             }
 2952:         }
 2953: 	my $current_path='/';
 2954: 	if ($env{'form.currentpath'}) {
 2955: 	    $current_path = $env{'form.currentpath'};
 2956: 	}
 2957:         if ($caller eq 'coursegrp_portfolio') {
 2958:             &Apache::lonhtmlcommon::clear_breadcrumbs();
 2959:             $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
 2960:         }
 2961:         my ($dirlistref,$listerror) =
 2962:             &get_dir_list($portfolio_root,$current_path,$group);
 2963: 	if ($listerror eq 'no_such_dir'){
 2964: 	    # two main reasons for this:
 2965:             #    1) never been here, so directory structure not created
 2966: 	    #    2) back-button navigation after deleting a directory
 2967: 	    if ($current_path eq '/'){
 2968: 	        &Apache::lonnet::mkdiruserfile($uname,$udom,
 2969: 					       &get_port_path());
 2970: 	    } else {
 2971:                 # some directory that snuck in get rid of the directory
 2972:                 # from the recent pulldown, just in case
 2973: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
 2974: 						      [$current_path]);
 2975: 		$current_path = '/'; # force it back to the root        
 2976: 	    }
 2977: 	    # now grab the directory list again, for the first time
 2978:             ($dirlistref,$listerror) =
 2979:                 &get_dir_list($portfolio_root,$current_path,$group);
 2980:         }
 2981: 	# need to know if directory is empty so it can be removed if desired
 2982:         my $is_empty;
 2983:         if ($listerror eq 'empty') {
 2984:             $is_empty = 1;
 2985:         } elsif (ref($dirlistref) eq 'ARRAY') {
 2986:             if ((scalar(@{$dirlistref}) == 2) && ($dirlistref->[0] =~ /^\.+\&/)
 2987:                 && ($dirlistref->[1] =~ /^\.+\&/))  {
 2988:                 $is_empty = 1;
 2989:             }
 2990:         }
 2991: 	&display_common($r,$url,$current_path,$is_empty,$dirlistref,
 2992: 			$can_upload,$group);
 2993:         &display_directory($r,$url,$current_path,$is_empty,$dirlistref,$group,
 2994:                            $can_upload,$can_modify,$can_delete,$can_setacl);
 2995:     }
 2996:     $r->print(&Apache::loncommon::end_page());
 2997:     return OK;
 2998: }
 2999: 
 3000: 1;
 3001: __END__

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