Annotation of loncom/interface/portfolio.pm, revision 1.165

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

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