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

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

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