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

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

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