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

1.3       banghart    1: # Copyright Michigan State University Board of Trustees
                      2: #
                      3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      4: #
                      5: # LON-CAPA is free software; you can redistribute it and/or modify
                      6: # it under the terms of the GNU General Public License as published by
                      7: # the Free Software Foundation; either version 2 of the License, or 
                      8: # (at your option) any later version.
                      9: #
                     10: # LON-CAPA is distributed in the hope that it will be useful,
                     11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     13: # GNU General Public License for more details.
                     14: #
                     15: # You should have received a copy of the GNU General Public License
                     16: # along with LON-CAPA; if not, write to the Free Software
                     17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     18: #
                     19: # /home/httpd/html/adm/gpl.txt
                     20: #
                     21: # http://www.lon-capa.org/
                     22: #
                     23: 
1.1       banghart   24: package Apache::portfolio;
                     25: use strict;
                     26: use Apache::Constants qw(:common :http);
1.2       banghart   27: use Apache::loncommon;
1.1       banghart   28: use Apache::lonnet;
1.2       banghart   29: use Apache::lontexconvert;
                     30: use Apache::lonfeedback;
                     31: use Apache::lonlocal;
1.82      albertel   32: use Apache::lonnet;
1.99      raeburn    33: use Apache::longroup;
1.101     www        34: use lib '/home/httpd/lib/perl';
                     35: use LONCAPA;
1.16      banghart   36: 
                     37: # receives a file name and path stub from username/userfiles/portfolio/
                     38: # returns an anchor tag consisting encoding filename and currentpath
1.23      albertel   39: sub make_anchor {
1.94      raeburn    40:     my ($url, $filename, $current_path, $current_mode, $field_name,
                     41:         $continue_select,$group) = @_;
1.83      banghart   42:     if ($continue_select ne 'true') {$continue_select = 'false'};
1.94      raeburn    43:     my $anchor = '<a href="'.$url.'?selectfile='.$filename.'&currentpath='.$current_path.'&mode='.$current_mode.'&continue='.$continue_select.'&fieldname='.$field_name;
                     44:     if (defined($group)) {
                     45:         $anchor .= '&group='.$group;
                     46:     }
                     47:     $anchor .= '">'.$filename.'</a>';
1.8       albertel   48:     return $anchor;
1.6       banghart   49: }
1.24      albertel   50: my $dirptr=16384;
1.48      banghart   51: sub display_common {
1.94      raeburn    52:     my ($r,$url,$current_path,$is_empty,$dir_list,$group)=@_;
                     53:     my $groupitem;
                     54:     my $namespace = &get_namespace($group);
                     55:     my $port_path = &get_port_path($group);
                     56:     if (defined($group)) {
                     57:         $groupitem = '<input type="hidden" name="group" value="'.$group.'" />';
                     58:     } 
1.18      banghart   59:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.88      albertel   60:     my %text=&Apache::lonlocal::texthash('upload' => 'Upload',
                     61: 					 'upload_label' =>  
                     62: 					 'Upload file to current directory:',
                     63: 					 'createdir' => 'Create Subdirectory',
                     64: 					 'createdir_label' => 
                     65: 					 'Create subdirectory in current directory:');
                     66:     $r->print(<<"TABLE"); 
                     67: <table border="0" cellspacing="2" cellpadding="2">
                     68:   <form method="post" enctype="multipart/form-data">
                     69:     <tr valign="middle">
                     70:       <td bgcolor="#ccddaa" align="right">
                     71:         $text{'upload_label'}
                     72:       </td>
1.94      raeburn    73:       <td bgcolor="#ccddaa" align="left">$groupitem
1.88      albertel   74:         <input name="uploaddoc" type="file" />
                     75: 	<input type="hidden" name="currentpath" value="$current_path" />
                     76: 	<input type="hidden" name="action" value="$env{"form.action"}" />
                     77: 	<input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
                     78: 	<input type="hidden" name="mode" value="$env{"form.mode"}" />
                     79: 	<input type="submit" name="storeupl" value="$text{'upload'}" />
                     80:       </td>
                     81:     </tr>
                     82:   </form>
                     83:   <form method="post">
                     84:     <tr>
                     85:       <td bgcolor="#ccddaa" align="right">
                     86:         $text{'createdir_label'}
                     87:       </td>
                     88:       <td bgcolor="#ccddaa" align="left">
1.94      raeburn    89:         <input name="newdir" type="input" />$groupitem
1.88      albertel   90:         <input type="hidden" name="currentpath" value="$current_path" />
                     91:         <input type="hidden" name="action" value="$env{"form.action"}" />
                     92:         <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
                     93:         <input type="hidden" name="mode" value="$env{"form.mode"}" />
                     94:         <input type="submit" name="createdir" value="$text{'createdir'}" />
                     95:       </td>
                     96:     </tr>
                     97:   </form>
                     98: </table>
                     99: TABLE
1.24      albertel  100:     my @tree = split (/\//,$current_path);
1.94      raeburn   101:     $r->print('<font size="+2">'.&make_anchor($url,$port_path,'/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"},$group).'/');
1.19      banghart  102:     if (@tree > 1){
                    103:         my $newCurrentPath = '';
                    104:         for (my $i = 1; $i< @tree; $i++){
                    105:             $newCurrentPath .= $tree[$i].'/';
1.94      raeburn   106:             $r->print(&make_anchor($url,$tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"},$group).'/');
1.19      banghart  107:         }
                    108:     }
                    109:     $r->print('</font>');
1.94      raeburn   110:     &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
                    111:     $r->print('<br /><form method=post action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"});
                    112:     if (defined($group)) {
                    113:         $r->print('&group='.$group);
                    114:     }
                    115:     $r->print('">'.
                    116: 	      &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
1.22      albertel  117: 						    'this.form.submit();'));
1.21      banghart  118:     $r->print("</form>");
1.48      banghart  119: }
                    120: sub display_directory {
1.94      raeburn   121:     my ($r,$url,$current_path,$is_empty,$dir_list,$group)=@_;
1.48      banghart  122:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.94      raeburn   123:     my ($groupitem,$groupecho);
1.48      banghart  124:     my $display_out;
1.77      banghart  125:     my $select_mode;
                    126:     my $checked_files;
1.94      raeburn   127:     my $port_path = &get_port_path($group);
                    128:     my ($uname,$udom) = &get_name_dom($group);
                    129:     if (defined($group)) {
                    130:        $groupitem = '<input type="hidden" name="group" value="'.$group.'" />'; 
                    131:        $groupecho = '&amp;group='.$group;
                    132:     }
1.102     raeburn   133:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
                    134:                                                                         $uname);
                    135:     my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
                    136:                                                   $current_permissions,$group);
                    137:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
                    138:     my $now = time;
1.82      albertel  139:     if ($env{"form.mode"} eq 'selectfile'){
1.77      banghart  140: 	&select_files($r);
1.94      raeburn   141: 	$checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
1.77      banghart  142: 	$select_mode = 'true';
                    143:     } 
1.45      banghart  144:     if ($is_empty && ($current_path ne '/')) {
1.94      raeburn   145:         $display_out = '<form method="post" action="'.$url.'">'.$groupitem.
1.30      banghart  146:         '<input type="hidden" name="action" value="deletedir" />'.
                    147:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
                    148:         '<input type="hidden" name="selectfile" value="" />'.
                    149:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
                    150:         '</form>';
                    151:         
1.48      banghart  152:         $r->print($display_out);
1.31      albertel  153: 	return;
                    154:     }
1.77      banghart  155:     if ($select_mode eq 'true') {
                    156:         $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
                    157:             '<tr><th>Select</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
1.94      raeburn   158:         $r->print('<form method="post" name="checkselect" action="'.$url.'">');
1.77      banghart  159:     } else {
                    160:         $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
1.102     raeburn   161:             '<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   162:         $r->print('<form method="post" action="'.$url.'">');
                    163:     }
                    164:     if (defined($group)) {
                    165:         $r->print("\n".$groupitem."\n");
1.77      banghart  166:     }
1.94      raeburn   167:     my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
                    168:     my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
1.105     banghart  169:     my @dir_lines;
                    170:     my %versioned;
1.26      albertel  171:     foreach my $line (sort 
                    172: 		      { 
                    173: 			  my ($afile)=split('&',$a,2);
                    174: 			  my ($bfile)=split('&',$b,2);
                    175: 			  return (lc($afile) cmp lc($bfile));
                    176: 		      } (@$dir_list)) {
1.18      banghart  177:     	#$strip holds directory/file name
                    178:     	#$dom 
1.23      albertel  179:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
1.77      banghart  180:     	$filename =~ s/\s+$//;
1.105     banghart  181:     	my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
                    182:     	if ($version) {
                    183:     	    $versioned{$fname} .= $version.",";
                    184:     	}
1.106   ! albertel  185:         push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
1.105     banghart  186:     }
1.106   ! albertel  187:     foreach my $line (@dir_lines) {
1.105     banghart  188:         my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$line;
                    189:         my ($fname,$version,$extension) = &Apache::grades::file_name_version_ext($filename);
1.93      albertel  190:     	if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
1.23      albertel  191:             if ($dirptr&$testdir) {
1.77      banghart  192:                 if ($select_mode eq 'true'){
                    193:                     $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
1.64      banghart  194:                 } else {
1.77      banghart  195:                     $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
1.64      banghart  196:                 }
1.47      banghart  197:                 $r->print('<td>Go to ...</td>');
1.94      raeburn   198:                 $r->print('<td>'.&make_anchor($url,$filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'},$group).'</td>'); 
1.47      banghart  199:                 $r->print('</tr>'); 
                    200:             } else {
                    201:                 $r->print('<tr bgcolor="#CCCCFF">');
1.105     banghart  202:                 my $version_flag;
                    203:                 if (exists($versioned{$fname})) {
                    204:                    $version_flag = "*";
                    205:                 } else {
                    206:                     $version_flag = "";
                    207:                 }
                    208:                my $fullpath = $current_path.$filename;
1.103     raeburn   209:                 $fullpath = &prepend_group($fullpath,$group);
1.77      banghart  210:                 if ($select_mode eq 'true'){
1.102     raeburn   211:                     $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"');
1.77      banghart  212:                     if ($$checked_files{$filename} eq 'selected') {
                    213:                         $r->print("CHECKED");
                    214:                     }
                    215:                     $r->print('></td>');
                    216:                 } else {
1.103     raeburn   217:                     if (exists $locked_files{$fullpath}) {
1.94      raeburn   218:                         $r->print('<td colspan="2"><a href="'.$url.'?lockinfo='.$current_path.$filename.$groupecho.'">Locked</a></td>');
1.77      banghart  219:                     } else {
1.89      albertel  220: 			my $cat='<img alt="'.&mt('Catalog Information').
                    221: 			    '" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />';
1.77      banghart  222:                         $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
1.94      raeburn   223:                             <a href="'.$url.'?rename='.$filename.'&amp;currentpath='.$current_path.$groupecho.'">Rename</a></td>
1.89      albertel  224:                             <td><a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>
1.77      banghart  225:                             </td>');
                    226:                     }
1.61      banghart  227:                 }
1.103     raeburn   228:                 my $curr_access;
                    229:                 my $pub_access = 0;
                    230:                 foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
1.104     raeburn   231:                     my ($scope,$end,$start) = ($key =~ /^[^:]+:([a-z]+)_(\d*)_?(\d*)$/);
1.103     raeburn   232:                     if (($now > $start) && (!$end || $end > $now)) {
                    233:                         if ($scope eq 'public')  {
                    234:                             $pub_access = 1;
                    235:                         }
                    236:                     }
                    237:                 }
                    238:                 if (!$pub_access) {
                    239:                     $curr_access = 'Private'
1.104     raeburn   240:                 } else {
1.103     raeburn   241:                     $curr_access = 'Public';
                    242:                 }
1.91      albertel  243:                 $r->print('<td><img src="'.&Apache::loncommon::icon($filename).'"></td>');
1.47      banghart  244:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
                    245: 			    $filename.'</a></td>'); 
                    246:                 $r->print('<td>'.$size.'</td>');
                    247:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
1.102     raeburn   248:                 $r->print('<td><nobr>'.&mt($curr_access).'&nbsp;&nbsp;&nbsp;'.
                    249:                           '<a href="'.$url.'?access='.$filename.
                    250:                           '&amp;currentpath='.$current_path.$groupecho.
                    251:                           '">'.&mt('View/Change').'</a></nobr></td>');
1.47      banghart  252:                 $r->print('</tr>'); 
                    253:             }
                    254:         }
                    255:     }
1.77      banghart  256:     if ($select_mode eq 'true') {
                    257:         $r->print('</table>
1.60      banghart  258:             <input type="hidden" name="continue" value="true">
1.82      albertel  259:             <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'">
1.60      banghart  260:             <input type="hidden" name="mode" value="selectfile">
                    261:             <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
1.48      banghart  262:             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
                    263:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.77      banghart  264:         </form>');        
                    265:     } else {
                    266:         $r->print('</table>
                    267:         <input type="submit" name="doit" value="Delete Checked Files" />
                    268:         <input type="hidden" name="action" value="delete" />
                    269:         <input type="hidden" name="currentpath" value="'.$current_path.'" />
                    270:         </form>');
                    271:     }
1.47      banghart  272: }
1.72      banghart  273: 
1.24      albertel  274: sub open_form {
1.94      raeburn   275:     my ($r,$url)=@_;
1.65      banghart  276:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.102     raeburn   277:     $r->print('<form name="portform" method="post" action="'.$url.'">');
1.24      albertel  278:     $r->print('<input type="hidden" name="action" value="'.
1.82      albertel  279: 	      $env{'form.action'}.'" />');
1.24      albertel  280:     $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65      banghart  281:     foreach (@files) {
                    282:         $r->print('<input type="hidden" name="selectfile" value="'.
                    283: 	      $_.'" />');
                    284:     }
1.24      albertel  285:     $r->print('<input type="hidden" name="currentpath" value="'.
1.82      albertel  286: 	      $env{'form.currentpath'}.'" />');
1.24      albertel  287: }
                    288: 
                    289: sub close_form {
1.94      raeburn   290:     my ($r,$url,$group)=@_;
                    291:     $r->print('<p><input type="submit" value="'.&mt('Continue').'" />');
                    292:     if (defined($group)) {
                    293:        $r->print("\n".'<input type="hidden" name="group" value="'.
                    294:               $group.'" />');
                    295:     }
                    296:     $r->print('</p></form>');
                    297:     $r->print('<form action="'.$url.'" method="POST">
1.24      albertel  298:                <p>
                    299:               <input type="hidden" name="currentpath" value="'.
1.94      raeburn   300: 	      $env{'form.currentpath'}.'" />');
                    301:     if (defined($group)) {
                    302:        $r->print("\n".'<input type="hidden" name="group" value="'.
                    303:               $group.'" />');
                    304:     }
                    305:     $r->print("\n".'   <input type="submit" value="'.&mt('Cancel').'" />
                    306:                </p></form>'); 
1.24      albertel  307: }
                    308: 
                    309: sub display_file {
1.27      albertel  310:     my ($path,$filename)=@_;
1.65      banghart  311:     my $display_file_text;
1.82      albertel  312:     if (!defined($path)) { $path=$env{'form.currentpath'}; }
1.65      banghart  313:     if (!defined($filename)) { 
1.82      albertel  314:         $filename=$env{'form.selectfile'};
1.65      banghart  315:         $display_file_text = '<tt>'.$path.$filename.'</tt>';
                    316:     } elsif (ref($filename) eq "ARRAY") {
                    317:         foreach (@$filename) {
1.66      banghart  318:             $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
1.65      banghart  319:         }
                    320:     } elsif (ref($filename) eq "SCALAR") {
                    321:         $display_file_text = '<tt>'.$path.$filename.'</tt>';        
                    322:     }
                    323:     return $display_file_text;
1.24      albertel  324: }
                    325: 
                    326: sub done {
1.94      raeburn   327:     my ($message,$url,$group)=@_;
1.76      banghart  328:     unless (defined $message) {
                    329:         $message='Done';
                    330:     }
1.94      raeburn   331:     my $result = '<h3><a href="'.$url.'?currentpath='.
                    332: 	         $env{'form.currentpath'}.
                    333: 	         '&fieldname='.$env{'form.fieldname'}.
                    334: 	         '&mode='.$env{'form.mode'};
                    335:     if (defined($group)) {
                    336:         $result .= '&group='.$group;
                    337:     }
                    338:     $result .= '">'.&mt($message).'</a></h3>';
                    339:     return $result;
1.24      albertel  340: }
                    341: 
                    342: sub delete {
1.94      raeburn   343:     my ($r,$url,$group)=@_;
1.55      banghart  344:     my @check;
1.82      albertel  345:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.102     raeburn   346:     $file_name = &prepend_group($file_name,$group);
1.65      banghart  347:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.94      raeburn   348:     my ($uname,$udom) = &get_name_dom($group);
                    349:     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.55      banghart  350:         $r->print ("The file is locked and cannot be deleted.<br />");
1.94      raeburn   351:         $r->print(&done('Back',$url,$group));
1.55      banghart  352:     } else {
1.66      banghart  353:         if (scalar(@files)) {
1.94      raeburn   354:             &open_form($r,$url);
1.66      banghart  355:             $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
1.94      raeburn   356:             &close_form($r,$url,$group);
1.66      banghart  357:         } else {
                    358:             $r->print("No file was checked to delete.<br />");
1.94      raeburn   359:             $r->print(&done(undef,$url,$group));
1.66      banghart  360:         }
1.55      banghart  361:     }
1.24      albertel  362: } 
                    363: 
                    364: sub delete_confirmed {
1.94      raeburn   365:     my ($r,$url,$group)=@_;
1.65      banghart  366:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
                    367:     my $result;
1.94      raeburn   368:     my ($uname,$udom) = &get_name_dom($group);
                    369:     my $port_path = &get_port_path($group);
1.65      banghart  370:     foreach my $delete_file (@files) {
1.94      raeburn   371:         $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.82      albertel  372: 					       $env{'form.currentpath'}.
1.65      banghart  373: 					       $delete_file);
                    374:         if ($result ne 'ok') {
1.30      banghart  375: 	$r->print('<font color="red"> An error occured ('.$result.
1.65      banghart  376: 		  ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
                    377:         }
1.24      albertel  378:     }
1.94      raeburn   379:     $r->print(&done(undef,$url,$group));
1.24      albertel  380: }
                    381: 
1.30      banghart  382: sub delete_dir {
1.94      raeburn   383:     my ($r,$url,$group)=@_;
                    384:     &open_form($r,$url);
1.30      banghart  385:     $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
1.94      raeburn   386:     &close_form($r,$url,$group);
1.30      banghart  387: } 
                    388: 
                    389: sub delete_dir_confirmed {
1.94      raeburn   390:     my ($r,$url,$group)=@_;
1.82      albertel  391:     my $directory_name = $env{'form.currentpath'};
1.81      albertel  392:     $directory_name =~ s|/$||; # remove any trailing slash
1.94      raeburn   393:     my ($uname,$udom) = &get_name_dom($group);
                    394:     my $namespace = &get_namespace($group);
                    395:     my $port_path = &get_port_path($group);
                    396:     my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.30      banghart  397: 					       $directory_name);
1.32      banghart  398: 					       
1.30      banghart  399:     if ($result ne 'ok') {
                    400: 	$r->print('<font color="red"> An error occured (dir) ('.$result.
                    401: 		  ') while trying to delete '.$directory_name.'</font><br />');
1.32      banghart  402:     } else {
1.41      banghart  403:         # now remove from recent
                    404: #        $r->print('<br /> removing '.$directory_name.'<br /');
1.94      raeburn   405:         &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
1.32      banghart  406:         my @dirs = split m!/!, $directory_name;
                    407:         
                    408: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
                    409:         $directory_name='/';
                    410:         for (my $i=1; $i < (@dirs - 1); $i ++){
                    411:             $directory_name .= $dirs[$i].'/';
                    412:         }
1.82      albertel  413:         $env{'form.currentpath'} = $directory_name;
1.30      banghart  414:     }
1.94      raeburn   415:     $r->print(&done(undef,$url,$group));
1.30      banghart  416: }
                    417: 
1.24      albertel  418: sub rename {
1.94      raeburn   419:     my ($r,$url,$group)=@_;
1.82      albertel  420:     my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
1.94      raeburn   421:     my ($uname,$udom) = &get_name_dom($group);
1.102     raeburn   422:     $file_name = &prepend_group($file_name,$group);
1.94      raeburn   423:     if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.55      banghart  424:         $r->print ("The file is locked and cannot be renamed.<br />");
1.94      raeburn   425:         $r->print(&done(undef,$url,$group));
1.55      banghart  426:     } else {
1.94      raeburn   427:         &open_form($r,$url);
1.55      banghart  428:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
                    429:                    <input name="filenewname" type="input" size="50" />?</p>');
1.94      raeburn   430:         &close_form($r,$url,$group);
1.55      banghart  431:     }
1.24      albertel  432: }
                    433: 
                    434: sub rename_confirmed {
1.94      raeburn   435:     my ($r,$url,$group)=@_;
1.82      albertel  436:     my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
1.94      raeburn   437:     my ($uname,$udom) = &get_name_dom($group);
                    438:     my $port_path = &get_port_path($group);
1.27      albertel  439:     if ($filenewname eq '') {
                    440: 	$r->print('<font color="red">'.
                    441: 		  &mt("Error: no valid filename was provided to rename to.").
                    442: 		  '</font><br />');
1.94      raeburn   443: 	$r->print(&done(undef,$url,$group));
1.27      albertel  444: 	return;
                    445:     } 
                    446:     my $result=
1.94      raeburn   447: 	&Apache::lonnet::renameuserfile($uname,$udom,
                    448:             $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
                    449:             $port_path.$env{'form.currentpath'}.$filenewname);
1.27      albertel  450:     if ($result ne 'ok') {
                    451: 	$r->print('<font color="red"> An errror occured ('.$result.
                    452: 		  ') while trying to rename '.&display_file().' to '.
                    453: 		  &display_file(undef,$filenewname).'</font><br />');
                    454:     }
1.82      albertel  455:     if ($filenewname ne $env{'form.filenewname'}) {
                    456:         $r->print("The new file name was changed from:<br /><strong>".$env{'form.filenewname'}."</strong> to <strong>$filenewname </strong>");
1.66      banghart  457:     }
1.94      raeburn   458:     $r->print(&done(undef,$url,$group));
1.27      albertel  459: }
1.102     raeburn   460: 
1.104     raeburn   461: sub display_access {
                    462:     my ($r,$url,$group) = @_;
                    463:     my ($uname,$udom) = &get_name_dom($group);
                    464:     my $file_name = $env{'form.currentpath'}.$env{'form.access'};
                    465:     $file_name = &prepend_group($file_name,$group);
                    466:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
                    467:                                                                         $uname);
                    468:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
                    469:     &open_form($r,$url);
                    470:     $r->print('<h3>'.&mt('Allowing others to retrieve portfolio file: [_1]',$env{'form.currentpath'}.$env{'form.access'}).'</h3>'."\n");
                    471:     $r->print(&mt('Access to this file by others can be set to be one the following types: public.').'<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.').'</li></ul><br />');
                    472:     &access_setting_table($r,$access_controls{$file_name});
                    473:     &close_form($r,$url,$group);
                    474: }
                    475: 
                    476: sub update_access {
                    477:     my ($r,$url,$group) = @_;
                    478:     my $totalprocessed = 0;
                    479:     my %processing;
                    480:     my %title  = (
                    481:                          'activate' => 'New controls added',
                    482:                          'delete'   => 'Existing controls deleted',
                    483:                          'update'   => 'Existing controls modified',
                    484:                      );
                    485:     my $changes;   
                    486:     foreach my $chg (sort(keys(%title))) {     
                    487:         @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
                    488:         $totalprocessed += @{$processing{$chg}};
                    489:         foreach my $num (@{$processing{$chg}}) {
                    490:             my $scope = $env{'form.scope_'.$num};
                    491:             my ($start,$end) = &get_dates_from_form($num);
                    492:             my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
                    493:             if ($chg eq 'delete') {
                    494:                 $$changes{$chg}{$newkey} = 1;
                    495:             } else {
                    496:                 $$changes{$chg}{$newkey} = 
                    497:                                  &build_access_record($num,$scope,$start,$end);
                    498:             }
                    499:         }
                    500:     }
                    501:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
                    502:     $r->print('<h3>'.&mt('Allowing others to retrieve portfolio file: [_1]',$file_name).'</h3>'."\n");
                    503:     $file_name = &prepend_group($file_name,$group);
                    504:     my ($uname,$udom) = &get_name_dom($group);
                    505:     my ($errors,$outcome,$deloutcome,$new_values,$translation);
                    506:     if ($totalprocessed) {
                    507:         ($outcome,$deloutcome,$new_values,$translation) =
                    508:         &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,$uname);
                    509:     }
                    510:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,                                                                    $uname);
                    511:     my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
                    512:     if ($totalprocessed) {
                    513:         if ($outcome eq 'ok') {
                    514:             my $updated_controls = $access_controls{$file_name};
                    515:             my ($showstart,$showend);
                    516:             $r->print(&Apache::loncommon::start_data_table());
                    517:             $r->print(&Apache::loncommon::start_data_table_row());
                    518:             $r->print('<th>'.&mt('Type of change').'</th><th>'.&mt('Access control').'</th><th>'.&mt('Start date').'</th><th>'.&mt('End date').'</th>');
                    519:             $r->print(&Apache::loncommon::end_data_table_row());
                    520:             foreach my $chg (sort(keys(%processing))) {
                    521:                 if (@{$processing{$chg}} > 0) {
                    522:                     if ($chg eq 'delete') {
                    523:                         if (!($deloutcome eq 'ok')) {
                    524:                             $errors .= &mt('A problem occurred deleting access controls: [_1]',$deloutcome);
                    525:                             next;
                    526:                         }
                    527:                     }
                    528:                     my $numchgs = @{$processing{$chg}};
                    529:                     $r->print(&Apache::loncommon::start_data_table_row());
                    530:                     $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).'.</td>');
                    531:                     my $count = 0;
                    532:                     foreach my $key (sort(keys(%{$$changes{$chg}}))) {
                    533:                         if ($count) {
                    534:                             $r->print(&Apache::loncommon::start_data_table_row());
                    535:                         }
                    536:                         my ($num,$scope,$end,$start) = 
                    537:                                    ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
                    538:                         my $newkey = $key;
                    539:                         if ($chg eq 'activate') {
                    540:                             $newkey =~ s/^(\d+)/$$translation{$1}/;
                    541:                         }
                    542:                         my %content = &Apache::lonnet::parse_access_controls(
                    543:                                                      $$updated_controls{$newkey});
                    544:                         if ($chg eq 'delete') {
                    545:                             $showstart = &mt('Deleted');
                    546:                             $showend = $showstart;
                    547:                         } else {
                    548:                             $showstart = localtime($start);
                    549:                             if ($end == 0) {
                    550:                                 $showend = &mt('No end date');
                    551:                             } else {
                    552:                                 $showend = localtime($end);
                    553:                             }
                    554:                         }
                    555:                         $r->print('<td>'.&mt($scope).'</td><td>'.$showstart.
                    556:                                   '</td><td>'. $showend.'</td>');
                    557:                         $r->print(&Apache::loncommon::end_data_table_row());
                    558:                         $count ++;
                    559:                     }
                    560:                 }
                    561:             }
                    562:             $r->print(&Apache::loncommon::end_data_table());
                    563:         } else {
                    564:             if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
                    565:                 $errors .= &mt('A problem occurred storing access control settings: [_1]',$outcome);
                    566:             }
                    567:         }
                    568:         if ($errors) { 
                    569:             $r->print($errors);
                    570:         }
                    571:     }
                    572:     $r->print('<br /><a href="'.$url.'?access='.$env{'form.selectfile'}.'&currentpath='.$env{'form.currentpath'}.'">'.&mt('Display all access settings for this file').'</a>');
                    573:     return;
                    574: }
                    575: 
                    576: sub build_access_record {
                    577:     my ($num,$scope,$start,$end) = @_;
                    578:     my $record = '<scope type="'.$scope.'"><start>'.$start.'</start><end>'.$end.
                    579:                  '</end></scope>';
                    580:     return $record;
                    581: }
                    582: 
                    583: sub get_dates_from_form {
                    584:     my ($id) = @_;
                    585:     my $startdate;
                    586:     my $enddate;
                    587:     $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
                    588:     $enddate   = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
                    589:     if ( exists ($env{'form.noend_'.$id}) ) {
                    590:         $enddate = 0;
                    591:     }
                    592:     return ($startdate,$enddate);
                    593: }
                    594: 
                    595: sub access_setting_table {
                    596:     my ($r,$access_controls) = @_;
                    597:     my ($public,$publictext);
                    598:     $publictext = '<b>'.&mt('Off').'</b>';
                    599:     my ($guest,$guesttext);
                    600:     $guesttext = '<b>'.&mt('Off').'</b>';
                    601:     my @courses = ();
                    602:     my @groups = ();
                    603:     my @domains = ();
                    604:     my @users = ();
                    605:     my $now = time;
                    606:     my $then = $now + (60*60*24*180); # six months approx.
                    607:     foreach my $key (sort(keys(%{$access_controls}))) {
                    608:         my ($scope) = ($key =~ /^[^:]+:([a-z]+)_\d*_?\d*$/);
                    609:         if ($scope eq 'public') {
                    610:             $public = $key;
                    611:             $publictext = '<b>'.&mt('On').'</b>';
                    612:         }
                    613:     }
                    614:     $r->print(&Apache::loncommon::start_data_table());
                    615:     $r->print(&Apache::loncommon::start_data_table_row());
                    616:     $r->print('<th>'.&mt('Access Type').'</th><th colspan="3">'.
                    617:               &mt('Settings').'</th>'."\n");
                    618:     $r->print(&Apache::loncommon::end_data_table_row());
                    619:     $r->print(&Apache::loncommon::start_data_table_row());
                    620:     $r->print('<td><b>Public</b><br />'.$publictext.'</td><td colspan="3">');
                    621:     $r->print(&Apache::loncommon::start_data_table());
                    622:     $r->print(&Apache::loncommon::start_data_table_row());
                    623:     my ($pub_startdate,$pub_enddate,$pub_action,$pub_noend);
                    624:     if ($public) {
                    625:         my ($num,$end,$start) = ($public =~ /^([^:]+):[a-z]+_(\d*)_?(\d*)$/);
                    626:         if ($end == 0) {
                    627:             $pub_noend = 'checked="checked"';
                    628:         }
                    629:         $pub_action = '<td><input type="checkbox" name="delete" value="'.$num.
                    630:                       '" />'.&mt('Delete').'<br /><input type="checkbox" '.
                    631:                       'name="update" value="'.$num.'" />'.&mt('Update').
                    632:                       '<input type="hidden" name="scope_'.$num.'"'.
                    633:                       ' value="public" /></td>';
                    634:         $pub_startdate = &Apache::lonhtmlcommon::date_setter('portform',
                    635:                           'startdate_'.$num,$start,undef,undef,undef,1,undef,
                    636:                           undef,undef,1);
                    637:         $pub_enddate = &Apache::lonhtmlcommon::date_setter('portform',
                    638:                           'enddate_'.$num,$end,undef,undef,undef,1,undef,
                    639:                           undef,undef,1).
                    640:                        '&nbsp;&nbsp;<nobr><input type="checkbox" name="noend_'.
                    641:                        $num.'" '.$pub_noend.' />'.&mt('No end date').'</nobr>';
                    642:     } else {
                    643:         $pub_action = '<input type="checkbox" name="activate" value="0" />'.
                    644:                       &mt('Activate').
                    645:                       '<input type="hidden" name="scope_0" value="public" />';
                    646:         $pub_startdate = &Apache::lonhtmlcommon::date_setter('portform',
                    647:                           'startdate_0',$now,undef,undef,undef,1,undef,
                    648:                           undef,undef,1);
                    649:         $pub_enddate = &Apache::lonhtmlcommon::date_setter('portform',
                    650:                           'enddate_0',$then,,undef,undef,undef,1,undef,
                    651:                           undef,undef,1).
                    652:                        '&nbsp;&nbsp<nobr><input type="checkbox" '.
                    653:                        'name="noend_0" />'.&mt('No end date').
                    654:                        '</nobr>';
                    655: 
                    656:     }
                    657:     $r->print('<td>'.$pub_action.'</td><td>'.&mt('Start: ').$pub_startdate.
                    658:               '<br />'.&mt('End: ').$pub_enddate.'</td>');
                    659:     $r->print(&Apache::loncommon::end_data_table_row());
                    660:     $r->print(&Apache::loncommon::end_data_table());
                    661:     $r->print('</td>');
                    662:     $r->print(&Apache::loncommon::end_data_table_row());
                    663:     $r->print(&Apache::loncommon::end_data_table());
                    664: }
                    665: 
1.47      banghart  666: sub select_files {
1.104     raeburn   667:     my ($r,$group) = @_;
1.82      albertel  668:     if ($env{'form.continue'} eq 'true') {
1.60      banghart  669:         # here we update the selections for the currentpath
                    670:         # eventually, have to handle removing those not checked, but . . . 
1.83      banghart  671:         my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
                    672:         if (scalar(@items)){
1.85      banghart  673:              &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83      banghart  674:         }
1.62      banghart  675:     } else {
                    676:             #empty the file for a fresh start
1.83      banghart  677:             &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62      banghart  678:     }
1.82      albertel  679:     my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62      banghart  680:     my $java_files = join ",", @files;
                    681:     if ($java_files) {
                    682:         $java_files.=',';
1.60      banghart  683:     }
1.63      banghart  684:     my $javascript =(<<ENDSMP);
1.48      banghart  685:         <script language='javascript'>
                    686:         function finishSelect() {
1.62      banghart  687: ENDSMP
1.63      banghart  688:     $javascript .= 'fileList = "'.$java_files.'";';
                    689:     $javascript .= (<<ENDSMP);
1.49      banghart  690:             for (i=0;i<document.forms.checkselect.length;i++) { 
                    691:                 if (document.forms.checkselect[i].checked){
1.54      banghart  692:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49      banghart  693:                 }
                    694:             }
                    695:             opener.document.forms.lonhomework.
                    696: ENDSMP
1.82      albertel  697:     $javascript .= $env{'form.fieldname'};
1.63      banghart  698:     $javascript .= (<<ENDSMP);
1.49      banghart  699:         .value=fileList;
1.48      banghart  700:             self.close();
                    701:         }
                    702:         </script>
                    703: ENDSMP
1.63      banghart  704:     $r->print($javascript);
1.47      banghart  705:     $r->print("<h1>Select portfolio files</h1>
1.88      albertel  706:                 Check as many as you wish in response to the problem.<br />");
                    707:     my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
                    708:     if (@otherfiles) {
                    709: 	$r->print("<strong>Files selected from other directories:</strong><br />");
                    710: 	foreach my $file (@otherfiles) {
                    711: 	    $r->print($file."<br />");
                    712: 	}
1.60      banghart  713:     }
1.47      banghart  714: }
1.24      albertel  715: sub upload {
1.94      raeburn   716:     my ($r,$url,$group)=@_;
1.82      albertel  717:     my $fname=$env{'form.uploaddoc.filename'};
                    718:     my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1.38      banghart  719:     my $disk_quota = 20000; # expressed in k
1.34      banghart  720:     $fname=&Apache::lonnet::clean_filename($fname);
1.94      raeburn   721: 
                    722:     my $portfolio_root=&get_portfolio_root($group);
                    723:     my ($uname,$udom) = &get_name_dom($group);
                    724:     my $port_path = &get_port_path($group);
1.38      banghart  725:     # Fixme --- Move the checking for existing file to LOND error return
1.94      raeburn   726:     my @dir_list=&get_dir_list($portfolio_root,$group);
1.34      banghart  727:     my $found_file = 0;
1.76      banghart  728:     my $locked_file = 0;
1.33      banghart  729:     foreach my $line (@dir_list) {
1.76      banghart  730:         my ($file_name)=split(/\&/,$line,2);
                    731:         if ($file_name eq $fname){
1.102     raeburn   732:             $file_name = $env{'form.currentpath'}.$file_name;
                    733:             $file_name = &prepend_group($file_name,$group);
1.33      banghart  734:             $found_file = 1;
1.102     raeburn   735:             if (defined($group)) {
                    736:                 $file_name = $group.'/'.$file_name;
                    737:             }
                    738:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.76      banghart  739:                 $locked_file = 1;
                    740:             } 
1.33      banghart  741:         }
                    742:     }
1.94      raeburn   743:     my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
1.87      albertel  744:     if (($current_disk_usage + $filesize) > $disk_quota){
1.86      albertel  745:         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.'.
1.38      banghart  746:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1.94      raeburn   747:         $r->print(&done('Back',$url,$group));
1.38      banghart  748:     } 
1.76      banghart  749:     elsif ($found_file){
                    750:         if ($locked_file){
1.94      raeburn   751:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></font>'.
1.76      banghart  752:                   '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
1.94      raeburn   753:             $r->print(&done('Back',$url,$group));      
1.76      banghart  754:         } else {   
1.94      raeburn   755:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></font>'.
                    756:                   '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
                    757:             $r->print(&done('Back',$url,$group));
1.76      banghart  758:         }
1.33      banghart  759:     } else {
                    760:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1.94      raeburn   761: 	        	 $port_path.$env{'form.currentpath'});
1.33      banghart  762:         if ($result !~ m|^/uploaded/|) {
1.34      banghart  763:             $r->print('<font color="red"> An errror occured ('.$result.
                    764: 	              ') while trying to upload '.&display_file().'</font><br />');
1.94      raeburn   765: 	    $r->print(&done('Back',$url,$group));
1.76      banghart  766:         } else {
1.94      raeburn   767:             $r->print(&done(undef,$url,$group));
1.33      banghart  768:         }
1.25      albertel  769:     }
                    770: }
1.80      banghart  771: sub lock_info {
1.94      raeburn   772:     my ($r,$url,$group) = @_;
                    773:     my ($uname,$udom) = &get_name_dom($group);
1.102     raeburn   774:     my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
                    775:                                                                        $uname);
1.84      banghart  776:     my $file_name = $env{'form.lockinfo'};
1.102     raeburn   777:     $file_name = &prepend_group($file_name,$group);
                    778:     if (defined($file_name) && defined($$current_permissions{$file_name})) {
                    779:         foreach my $array_item (@{$$current_permissions{$file_name}}) {
                    780:             if (ref($array_item) eq 'ARRAY') {
                    781:                 my $filetext;
                    782:                 if (defined($group)) {
                    783:                     $filetext = '<strong>'.$env{'form.lockinfo'}.
                    784:                                     '</strong> (group: '.$group.')'; 
                    785:                 } else {
                    786:                     $filetext = '<strong>'.$file_name.'</strong>';
                    787:                 } 
                    788:                 $r->print(&mt('[_1] was submitted in response to problem: ',
                    789:                               $filetext).
                    790:                           '<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
                    791:                           '</strong><br />');
                    792:                 my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
                    793:                 $r->print(&mt('In the course: <strong>[_1]</strong><br />',
                    794:                               $course_description{'description'}));
                    795:                 # $r->print('the third is '.$$array_item[2].'<br>');
                    796:                 # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
1.85      banghart  797:             }
1.102     raeburn   798:         }
1.84      banghart  799:     }
1.94      raeburn   800:     $r->print(&done('Back',$url,$group));
1.80      banghart  801:     return 'ok';
                    802: }
1.25      albertel  803: sub createdir {
1.94      raeburn   804:     my ($r,$url,$group)=@_;
1.82      albertel  805:     my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28      albertel  806:     if ($newdir eq '') {
1.37      banghart  807:     	$r->print('<font color="red">'.
                    808: 	    	  &mt("Error: no directory name was provided.").
                    809: 		      '</font><br />');
1.94      raeburn   810: 	    $r->print(&done(undef,$url,$group));
1.37      banghart  811: 	    return;
1.94      raeburn   812:     }
                    813:     my $portfolio_root = &get_portfolio_root($group); 
                    814:     my @dir_list=&get_dir_list($portfolio_root,$group);
1.37      banghart  815:     my $found_file = 0;
                    816:     foreach my $line (@dir_list) {
                    817:         my ($filename)=split(/\&/,$line,2);
                    818:         if ($filename eq $newdir){
                    819:             $found_file = 1;
                    820:         }
                    821:     }
                    822:     if ($found_file){
                    823:     	    $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
                    824:     	            ' </strong>a file or directory by that name already exists.</font><br />');
                    825:     } else {
1.94      raeburn   826:         my ($uname,$udom) = &get_name_dom($group);
                    827:         my $port_path = &get_port_path($group);
                    828:         my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
                    829: 	         $port_path.$env{'form.currentpath'}.$newdir);
1.37      banghart  830:         if ($result ne 'ok') {
                    831:     	    $r->print('<font color="red"> An errror occured ('.$result.
                    832: 	    	      ') while trying to create a new directory '.&display_file().'</font><br />');
                    833:         }
1.24      albertel  834:     }
1.82      albertel  835:     if ($newdir ne $env{'form.newdir'}) {
                    836:         $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");  
1.67      banghart  837:     }
1.94      raeburn   838:     $r->print(&done(undef,$url,$group));
                    839: }
                    840: 
                    841: sub get_portfolio_root {
                    842:     my ($group) = @_;
                    843:     my ($portfolio_root,$udom,$uname,$path);
                    844:     ($uname,$udom) = &get_name_dom($group);
                    845:     if (defined($group)) {
                    846:         $path = '/userfiles/groups/'.$group.'/portfolio';
                    847:     } else {
                    848:         $path = '/userfiles/portfolio';
                    849:     }
                    850:     return (&Apache::loncommon::propath($udom,$uname).$path);
                    851: }
                    852: 
                    853: sub get_dir_list {
                    854:     my ($portfolio_root,$group) = @_;
                    855:     my ($uname,$udom) = &get_name_dom($group);
                    856:     return &Apache::lonnet::dirlist($env{'form.currentpath'},
                    857:                                           $udom,$uname,$portfolio_root);
                    858: }
                    859: 
                    860: sub get_name_dom {
                    861:     my ($group) = @_;
                    862:     my ($uname,$udom);
                    863:     if (defined($group)) {
                    864:         $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                    865:         $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
                    866:     } else {
                    867:         $udom = $env{'user.domain'};
                    868:         $uname = $env{'user.name'};
                    869:     }
                    870:     return ($uname,$udom);
                    871: }
                    872: 
1.102     raeburn   873: sub prepend_group {
                    874:     my ($filename,$group) = @_;
                    875:     if (defined($group)) {
                    876:         $filename = $group.'/'.$filename;
                    877:     }
                    878:     return $filename;
                    879: }
                    880: 
1.94      raeburn   881: sub get_namespace {
                    882:     my ($group) = @_;
                    883:     my $namespace = 'portfolio';
                    884:     if (defined($group)) {
                    885:         my ($uname,$udom) = &get_name_dom($group);
                    886:         $namespace .= '_'.$udom.'_'.$uname.'_'.$group;
                    887:     }
                    888:     return $namespace;
                    889: }
                    890: 
                    891: sub get_port_path {
                    892:     my ($group) = @_;
                    893:     my $port_path;
                    894:     if (defined($group)) {
                    895:        $port_path = "groups/$group/portfolio";
                    896:     } else {
                    897:        $port_path = 'portfolio';
                    898:     }
                    899:     return $port_path;
1.24      albertel  900: }
                    901: 
                    902: sub handler {
                    903:     # this handles file management
                    904:     my $r = shift;
1.73      banghart  905:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.94      raeburn   906:          ['selectfile','currentpath','meta','lockinfo','currentfile',
1.102     raeburn   907: 	  'action','fieldname','mode','rename','continue','group','access']);
1.94      raeburn   908:     my ($uname,$udom,$portfolio_root,$url,$group,$caller,$title);
                    909:     if ($r->uri =~ m|^(/adm/)([^/]+)|) {
                    910:         $url = $1.$2;
                    911:         $caller = $2;
                    912:     }
                    913:     if ($caller eq 'coursegrp_portfolio') {
                    914:     #  Needs to be in a course
                    915:         if (! ($env{'request.course.fn'})) {
                    916:         # Not in a course
                    917:             $env{'user.error.msg'}=
                    918:      "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
                    919:             return HTTP_NOT_ACCEPTABLE;
                    920:         }
                    921:         my $earlyout = 0;
                    922:         my $view_permission = &Apache::lonnet::allowed('vcg',
                    923:                                                 $env{'request.course.id'});
                    924:         $group = $env{'form.group'};
                    925:         $group =~ s/\W//g;
                    926:         if ($group) {
                    927:             ($uname,$udom) = &get_name_dom($group);
1.99      raeburn   928:             my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1.98      albertel  929: 							       $group); 
                    930:             if (%curr_groups) {
1.94      raeburn   931:                 if (($view_permission) || (&Apache::lonnet::allowed('rgf',
                    932:                                       $env{'request.course.id'}.'/'.$group))) {
                    933:                     $portfolio_root = &get_portfolio_root($group);
                    934:                 } else {
                    935:                     $r->print('You do not have the privileges required to access the shared files space for this group');
                    936:                     $earlyout = 1;
                    937:                 }
                    938:             } else {
                    939:                 $r->print('Not a valid group for this course');
                    940:                 $earlyout = 1;
                    941:             }
                    942:             $title = &mt('Group files').' for '.$group; 
                    943:         } else {
                    944:             $r->print('Invalid group');
                    945:             $earlyout = 1;
                    946:         }
                    947:         if ($earlyout) { return OK; }
                    948:     } else {
                    949:         ($uname,$udom) = &get_name_dom();
                    950:         $portfolio_root = &get_portfolio_root();
                    951:         $title = &mt('Portfolio Manager');
                    952:     }
                    953: 
1.24      albertel  954:     &Apache::loncommon::no_cache($r);
                    955:     &Apache::loncommon::content_type($r,'text/html');
                    956:     $r->send_http_header;
                    957:     # Give the LON-CAPA page header
1.82      albertel  958:     if ($env{"form.mode"} eq 'selectfile'){
1.96      albertel  959:         $r->print(&Apache::loncommon::start_page($title,undef,
1.97      albertel  960: 						 {'only_body' => 1}));
1.74      banghart  961:     } else {
1.97      albertel  962:         $r->print(&Apache::loncommon::start_page($title));
1.74      banghart  963:     }
1.24      albertel  964:     $r->rflush();
1.88      albertel  965: 	if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.40      banghart  966:    	    $r->print('<font color="red"> No file was selected to upload.'.
                    967:    	            'To upload a file, click <strong>Browse...</strong>'.
                    968:    	            ', select a file, then click <strong>Upload</strong>,</font>');
                    969: 	}
1.82      albertel  970:     if ($env{'form.meta'}) {
1.94      raeburn   971:         &open_form($r,$url);
1.82      albertel  972: #        $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1.70      banghart  973:         $r->print('Edit the meta data<br />');
1.94      raeburn   974:         &close_form($r,$url,$group);
1.70      banghart  975:     }
1.82      albertel  976:     if ($env{'form.store'}) {
1.70      banghart  977:     }
                    978: 
1.82      albertel  979:     if ($env{'form.uploaddoc.filename'}) {
1.94      raeburn   980: 	&upload($r,$url,$group);
1.82      albertel  981:     } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.94      raeburn   982: 	&delete_confirmed($r,$url,$group);
1.82      albertel  983:     } elsif ($env{'form.action'} eq 'delete') {
1.94      raeburn   984: 	&delete($r,$url,$group);
1.82      albertel  985:     } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.94      raeburn   986: 	&delete_dir_confirmed($r,$url,$group);
1.82      albertel  987:     } elsif ($env{'form.action'} eq 'deletedir'){
1.94      raeburn   988: 	&delete_dir($r,$url,$group);
1.82      albertel  989:     } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.94      raeburn   990: 	&rename_confirmed($r,$url,$group);
1.82      albertel  991:     } elsif ($env{'form.rename'}) {
                    992:         $env{'form.selectfile'} = $env{'form.rename'};
                    993:         $env{'form.action'} = 'rename';
1.94      raeburn   994: 	&rename($r,$url,$group);
1.104     raeburn   995:     } elsif ($env{'form.access'}) {
                    996:         $env{'form.selectfile'} = $env{'form.access'};
                    997:         $env{'form.action'} = 'chgaccess';
                    998:         &display_access($r,$url,$group);
                    999:     } elsif ($env{'form.action'} eq 'chgaccess') {
                   1000:         &update_access($r,$url,$group);
1.82      albertel 1001:     } elsif ($env{'form.createdir'}) {
1.94      raeburn  1002: 	&createdir($r,$url,$group);
1.82      albertel 1003:     } elsif ($env{'form.lockinfo'}) {
1.94      raeburn  1004:         &lock_info($r,$url,$group);
1.24      albertel 1005:     } else {
                   1006: 	my $current_path='/';
1.82      albertel 1007: 	if ($env{'form.currentpath'}) {
                   1008: 	    $current_path = $env{'form.currentpath'};
1.24      albertel 1009: 	}
1.94      raeburn  1010:         my @dir_list=&get_dir_list($portfolio_root,$group);
1.46      albertel 1011: 	if ($dir_list[0] eq 'no_such_dir'){
                   1012: 	    # two main reasons for this:
                   1013:             #    1) never been here, so directory structure not created
                   1014: 	    #    2) back-button navigation after deleting a directory
                   1015: 	    if ($current_path eq '/'){
1.100     albertel 1016: 	        &Apache::lonnet::mkdiruserfile($uname,$udom,
                   1017: 					       &get_port_path($group));
1.46      albertel 1018: 	    } else {
                   1019:                 # some directory that snuck in get rid of the directory
                   1020:                 # from the recent pulldown, just in case
                   1021: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
                   1022: 						      [$current_path]);
                   1023: 		$current_path = '/'; # force it back to the root        
                   1024: 	    }
                   1025: 	    # now grab the directory list again, for the first time
                   1026: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
1.94      raeburn  1027: 					    $udom,$uname,$portfolio_root);
1.43      banghart 1028:         }
1.46      albertel 1029: 	# need to know if directory is empty so it can be removed if desired
                   1030: 	my $is_empty=(@dir_list == 2);
1.94      raeburn  1031: 	&display_common($r,$url,$current_path,$is_empty,\@dir_list,$group);
                   1032:         &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group);
1.95      albertel 1033: 	$r->print(&Apache::loncommon::end_page());
1.30      banghart 1034:     }
1.90      albertel 1035:     return OK;
1.2       banghart 1036: }
1.1       banghart 1037: 1;
                   1038: __END__

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