File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.218: download - view: text, annotated - select for diffs
Mon Nov 23 03:57:27 2009 UTC (14 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD, GCI_3
- Wrap disk meter in head_subbox.

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

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