File:  [LON-CAPA] / loncom / interface / portfolio.pm
Revision 1.88: download - view: text, annotated - select for diffs
Fri Sep 9 19:12:29 2005 UTC (18 years, 9 months ago) by albertel
Branches: MAIN
CVS tags: version_2_0_X, version_2_0_2, HEAD
- hide the 'files from other dirs' message unless there are othe files.
- add some text to the upload/create dir fileds to make them more obvious

    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: 
   24: package Apache::portfolio;
   25: use strict;
   26: use Apache::Constants qw(:common :http);
   27: use Apache::loncommon;
   28: use Apache::lonnet;
   29: use Apache::lontexconvert;
   30: use Apache::lonfeedback;
   31: use Apache::lonlocal;
   32: use Apache::lonnet;
   33: 
   34: # receives a file name and path stub from username/userfiles/portfolio/
   35: # returns an anchor tag consisting encoding filename and currentpath
   36: sub make_anchor {
   37:     my ($filename, $current_path, $current_mode, $field_name, $continue_select) = @_;
   38:     if ($continue_select ne 'true') {$continue_select = 'false'};
   39:     my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'&currentpath='.$current_path.'&mode='.$current_mode.'&continue='.$continue_select.'&fieldname='.$field_name.'">'.$filename.'</a>';
   40:     return $anchor;
   41: }
   42: my $dirptr=16384;
   43: sub display_common {
   44:     my ($r,$current_path,$is_empty,$dir_list)=@_;
   45:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
   46:     my %text=&Apache::lonlocal::texthash('upload' => 'Upload',
   47: 					 'upload_label' =>  
   48: 					 'Upload file to current directory:',
   49: 					 'createdir' => 'Create Subdirectory',
   50: 					 'createdir_label' => 
   51: 					 'Create subdirectory in current directory:');
   52:     $r->print(<<"TABLE"); 
   53: <table border="0" cellspacing="2" cellpadding="2">
   54:   <form method="post" enctype="multipart/form-data">
   55:     <tr valign="middle">
   56:       <td bgcolor="#ccddaa" align="right">
   57:         $text{'upload_label'}
   58:       </td>
   59:       <td bgcolor="#ccddaa" align="left">
   60:         <input name="uploaddoc" type="file" />
   61: 	<input type="hidden" name="currentpath" value="$current_path" />
   62: 	<input type="hidden" name="action" value="$env{"form.action"}" />
   63: 	<input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
   64: 	<input type="hidden" name="mode" value="$env{"form.mode"}" />
   65: 	<input type="submit" name="storeupl" value="$text{'upload'}" />
   66:       </td>
   67:     </tr>
   68:   </form>
   69:   <form method="post">
   70:     <tr>
   71:       <td bgcolor="#ccddaa" align="right">
   72:         $text{'createdir_label'}
   73:       </td>
   74:       <td bgcolor="#ccddaa" align="left">
   75:         <input name="newdir" type="input" />
   76:         <input type="hidden" name="currentpath" value="$current_path" />
   77:         <input type="hidden" name="action" value="$env{"form.action"}" />
   78:         <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
   79:         <input type="hidden" name="mode" value="$env{"form.mode"}" />
   80:         <input type="submit" name="createdir" value="$text{'createdir'}" />
   81:       </td>
   82:     </tr>
   83:   </form>
   84: </table>
   85: TABLE
   86:     my @tree = split (/\//,$current_path);
   87:     $r->print('<font size="+2">'.&make_anchor('portfolio','/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"}).'/');
   88:     if (@tree > 1){
   89:         my $newCurrentPath = '';
   90:         for (my $i = 1; $i< @tree; $i++){
   91:             $newCurrentPath .= $tree[$i].'/';
   92:             $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"}).'/');
   93:         }
   94:     }
   95:     $r->print('</font>');
   96:     &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
   97:     $r->print('<br /><form method=post action="/adm/portfolio?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.'">'.
   98: 	      &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
   99: 						    'this.form.submit();'));
  100:     $r->print("</form>");
  101: }
  102: sub display_directory {
  103:     my ($r,$current_path,$is_empty,$dir_list)=@_;
  104:     my $iconpath= $r->dir_config('lonIconsURL') . "/";
  105:     my $display_out;
  106:     my $select_mode;
  107:     my $checked_files;
  108:     my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($env{'user.domain'},$env{'user.name'});
  109:     if ($env{"form.mode"} eq 'selectfile'){
  110: 	&select_files($r);
  111: 	$checked_files =&Apache::lonnet::files_in_path($env{'user.name'},$env{'form.currentpath'});
  112: 	$select_mode = 'true';
  113:     } 
  114:     if ($is_empty && ($current_path ne '/')) {
  115:         $display_out = '<form method="post" action="/adm/portfolio">'.
  116:         '<input type="hidden" name="action" value="deletedir" />'.
  117:         '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
  118:         '<input type="hidden" name="selectfile" value="" />'.
  119:         '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
  120:         '</form>';
  121:         
  122:         $r->print($display_out);
  123: 	return;
  124:     }
  125:     if ($select_mode eq 'true') {
  126:         $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
  127:             '<tr><th>Select</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
  128:         $r->print('<form method="post" name="checkselect" action="/adm/portfolio">');
  129:     } else {
  130:         $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
  131:             '<tr><th colspan="2">Actions</th><th>&nbsp;</th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
  132:         $r->print('<form method="post" action="/adm/portfolio">');
  133:     }
  134:     my $href_location="/uploaded/$env{'user.domain'}/$env{'user.name'}/portfolio$current_path";
  135:     my $href_edit_location="/editupload/$env{'user.domain'}/$env{'user.name'}/portfolio$current_path";
  136:     foreach my $line (sort 
  137: 		      { 
  138: 			  my ($afile)=split('&',$a,2);
  139: 			  my ($bfile)=split('&',$b,2);
  140: 			  return (lc($afile) cmp lc($bfile));
  141: 		      } (@$dir_list)) {
  142:     	#$strip holds directory/file name
  143:     	#$dom 
  144:     	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
  145:     	$filename =~ s/\s+$//;
  146:     	if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(.*)\.(.*)/)) {
  147:             if ($dirptr&$testdir) {
  148:                 if ($select_mode eq 'true'){
  149:                     $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
  150:                 } else {
  151:                     $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
  152:                 }
  153:                 $r->print('<td>Go to ...</td>');
  154:                 $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'}).'</td>'); 
  155:                 $r->print('</tr>'); 
  156:             } else {
  157:                 $r->print('<tr bgcolor="#CCCCFF">');
  158:                 if ($select_mode eq 'true'){
  159:                     $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"'); 
  160:                     if ($$checked_files{$filename} eq 'selected') {
  161:                         $r->print("CHECKED");
  162:                     }
  163:                     $r->print('></td>');
  164:                 } else {
  165:                     if (exists $locked_files{$current_path.$filename}){
  166:                         $r->print('<td colspan="2"><a href="portfolio?lockinfo='.$current_path.$filename.'">Locked</a></td>');
  167:                     } else {
  168:                         $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
  169:                             <a href="/adm/portfolio?rename='.$filename.'&amp;currentpath='.$current_path.'">Rename</a></td>
  170:                             <td><a href="'.$href_edit_location.$filename.'.meta">Meta</a>
  171:                             </td>');
  172:                     }
  173:                 }
  174:                 $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
  175:                 $r->print('<td><a href="'.$href_location.$filename.'">'.
  176: 			    $filename.'</a></td>'); 
  177:                 $r->print('<td>'.$size.'</td>');
  178:                 $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
  179:                 $r->print('</tr>'); 
  180:             }
  181:         }
  182:     }
  183:     if ($select_mode eq 'true') {
  184:         $r->print('</table>
  185:             <input type="hidden" name="continue" value="true">
  186:             <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'">
  187:             <input type="hidden" name="mode" value="selectfile">
  188:             <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
  189:             <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
  190:             <input type="hidden" name="currentpath" value="'.$current_path.'" />
  191:         </form>');        
  192:     } else {
  193:         $r->print('</table>
  194:         <input type="submit" name="doit" value="Delete Checked Files" />
  195:         <input type="hidden" name="action" value="delete" />
  196:         <input type="hidden" name="currentpath" value="'.$current_path.'" />
  197:         </form>');
  198:     }
  199: }
  200: 
  201: sub open_form {
  202:     my ($r)=@_;
  203:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  204:     $r->print('<form method="post" action="/adm/portfolio">');
  205:     $r->print('<input type="hidden" name="action" value="'.
  206: 	      $env{'form.action'}.'" />');
  207:     $r->print('<input type="hidden" name="confirmed" value="1" />');
  208:     foreach (@files) {
  209:         $r->print('<input type="hidden" name="selectfile" value="'.
  210: 	      $_.'" />');
  211:     }
  212:     $r->print('<input type="hidden" name="currentpath" value="'.
  213: 	      $env{'form.currentpath'}.'" />');
  214: }
  215: 
  216: sub close_form {
  217:     my ($r)=@_;
  218:     $r->print('<p><input type="submit" value="'.&mt('Continue').
  219: 	      '" /></p></form>');
  220:     $r->print('<form action="/adm/portfolio" method="POST">
  221:                <p>
  222:               <input type="hidden" name="currentpath" value="'.
  223: 	      $env{'form.currentpath'}.'" />
  224:                  <input type="submit" value="'.&mt('Cancel').'" />
  225:                </p></form>');
  226: 
  227: }
  228: 
  229: sub display_file {
  230:     my ($path,$filename)=@_;
  231:     my $display_file_text;
  232:     if (!defined($path)) { $path=$env{'form.currentpath'}; }
  233:     if (!defined($filename)) { 
  234:         $filename=$env{'form.selectfile'};
  235:         $display_file_text = '<tt>'.$path.$filename.'</tt>';
  236:     } elsif (ref($filename) eq "ARRAY") {
  237:         foreach (@$filename) {
  238:             $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
  239:         }
  240:     } elsif (ref($filename) eq "SCALAR") {
  241:         $display_file_text = '<tt>'.$path.$filename.'</tt>';        
  242:     }
  243:     return $display_file_text;
  244: }
  245: 
  246: sub done {
  247:     my ($message)=@_;
  248:     unless (defined $message) {
  249:         $message='Done';
  250:     }
  251:     return ('<h3><a href="/adm/portfolio?currentpath='.
  252: 	    $env{'form.currentpath'}.
  253: 	    '&fieldname='.$env{'form.fieldname'}.
  254: 	    '&mode='.$env{'form.mode'}.
  255: 	    '">'.&mt($message).'</a></h3>');
  256: }
  257: 
  258: sub delete {
  259:     my ($r)=@_;
  260:     my @check;
  261:     my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
  262:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  263: 
  264:     if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') {
  265:         $r->print ("The file is locked and cannot be deleted.<br />");
  266:         $r->print(&done('Back'));
  267:     } else {
  268:         if (scalar(@files)) {
  269:             &open_form($r);
  270:             $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
  271:             &close_form($r);
  272:         } else {
  273:             $r->print("No file was checked to delete.<br />");
  274:             $r->print(&done());
  275:         }
  276:     }
  277: } 
  278: 
  279: sub delete_confirmed {
  280:     my ($r)=@_;
  281:     my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
  282:     my $result;
  283:     foreach my $delete_file (@files) {
  284:         $result=&Apache::lonnet::removeuserfile($env{'user.name'},
  285: 					       $env{'user.domain'},'portfolio'.
  286: 					       $env{'form.currentpath'}.
  287: 					       $delete_file);
  288:         if ($result ne 'ok') {
  289: 	$r->print('<font color="red"> An error occured ('.$result.
  290: 		  ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
  291:         }
  292:     }
  293:     $r->print(&done());
  294: }
  295: 
  296: sub delete_dir {
  297:     my ($r)=@_;
  298:     &open_form($r);
  299:     $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
  300:     &close_form($r);
  301: } 
  302: 
  303: sub delete_dir_confirmed {
  304:     my ($r)=@_;
  305:     my $directory_name = $env{'form.currentpath'};
  306:     $directory_name =~ s|/$||; # remove any trailing slash
  307:     my $result=&Apache::lonnet::removeuserfile($env{'user.name'},
  308: 					       $env{'user.domain'},'portfolio'.
  309: 					       $directory_name);
  310: 					       
  311:     if ($result ne 'ok') {
  312: 	$r->print('<font color="red"> An error occured (dir) ('.$result.
  313: 		  ') while trying to delete '.$directory_name.'</font><br />');
  314:     } else {
  315:         # now remove from recent
  316: #        $r->print('<br /> removing '.$directory_name.'<br /');
  317:         &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
  318:         my @dirs = split m!/!, $directory_name;
  319:         
  320: #        $directory_name =~ m/^(\/*\/)(\/*.)$/;
  321:         $directory_name='/';
  322:         for (my $i=1; $i < (@dirs - 1); $i ++){
  323:             $directory_name .= $dirs[$i].'/';
  324:         }
  325:         $env{'form.currentpath'} = $directory_name;
  326:     }
  327:     $r->print(&done());
  328: }
  329: 
  330: sub rename {
  331:     my ($r)=@_;
  332:     my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
  333:     if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'}) eq 'true') {
  334:         $r->print ("The file is locked and cannot be renamed.<br />");
  335:         $r->print(&done());
  336:     } else {
  337:         &open_form($r);
  338:         $r->print('<p>'.&mt('Rename').' '.&display_file().' to 
  339:                    <input name="filenewname" type="input" size="50" />?</p>');
  340:         &close_form($r);
  341:     }
  342: }
  343: 
  344: sub rename_confirmed {
  345:     my ($r)=@_;
  346:     my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
  347:     if ($filenewname eq '') {
  348: 	$r->print('<font color="red">'.
  349: 		  &mt("Error: no valid filename was provided to rename to.").
  350: 		  '</font><br />');
  351: 	$r->print(&done());
  352: 	return;
  353:     } 
  354:     my $result=
  355: 	&Apache::lonnet::renameuserfile($env{'user.name'},$env{'user.domain'},
  356:             'portfolio'.$env{'form.currentpath'}.$env{'form.selectfile'},
  357:             'portfolio'.$env{'form.currentpath'}.$filenewname);
  358:     if ($result ne 'ok') {
  359: 	$r->print('<font color="red"> An errror occured ('.$result.
  360: 		  ') while trying to rename '.&display_file().' to '.
  361: 		  &display_file(undef,$filenewname).'</font><br />');
  362:     }
  363:     if ($filenewname ne $env{'form.filenewname'}) {
  364:         $r->print("The new file name was changed from:<br /><strong>".$env{'form.filenewname'}."</strong> to <strong>$filenewname </strong>");
  365:     }
  366:     $r->print(&done());
  367: }
  368: sub select_files {
  369:     my ($r)=@_;
  370:     if ($env{'form.continue'} eq 'true') {
  371:         # here we update the selections for the currentpath
  372:         # eventually, have to handle removing those not checked, but . . . 
  373:         my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
  374:         if (scalar(@items)){
  375:              &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
  376:         }
  377:     } else {
  378:             #empty the file for a fresh start
  379:             &Apache::lonnet::clear_selected_files($env{'user.name'});
  380:     }
  381:     my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
  382:     my $java_files = join ",", @files;
  383:     if ($java_files) {
  384:         $java_files.=',';
  385:     }
  386:     my $javascript =(<<ENDSMP);
  387:         <script language='javascript'>
  388:         function finishSelect() {
  389: ENDSMP
  390:     $javascript .= 'fileList = "'.$java_files.'";';
  391:     $javascript .= (<<ENDSMP);
  392:             for (i=0;i<document.forms.checkselect.length;i++) { 
  393:                 if (document.forms.checkselect[i].checked){
  394:                     fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
  395:                 }
  396:             }
  397:             opener.document.forms.lonhomework.
  398: ENDSMP
  399:     $javascript .= $env{'form.fieldname'};
  400:     $javascript .= (<<ENDSMP);
  401:         .value=fileList;
  402:             self.close();
  403:         }
  404:         </script>
  405: ENDSMP
  406:     $r->print($javascript);
  407:     $r->print("<h1>Select portfolio files</h1>
  408:                 Check as many as you wish in response to the problem.<br />");
  409:     my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
  410:     if (@otherfiles) {
  411: 	$r->print("<strong>Files selected from other directories:</strong><br />");
  412: 	foreach my $file (@otherfiles) {
  413: 	    $r->print($file."<br />");
  414: 	}
  415:     }
  416: }
  417: sub upload {
  418:     my ($r)=@_;
  419:     my $fname=$env{'form.uploaddoc.filename'};
  420:     my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
  421:     my $disk_quota = 20000; # expressed in k
  422:     $fname=&Apache::lonnet::clean_filename($fname);
  423:     my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
  424: 						 $env{'user.name'}).
  425: 						'/userfiles/portfolio';
  426:     # Fixme --- Move the checking for existing file to LOND error return
  427:     my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
  428: 					  $env{'user.domain'},
  429: 					  $env{'user.name'},$portfolio_root);
  430:     my $found_file = 0;
  431:     my $locked_file = 0;
  432:     foreach my $line (@dir_list) {
  433:         my ($file_name)=split(/\&/,$line,2);
  434:         if ($file_name eq $fname){
  435:             $found_file = 1;
  436:             if (&Apache::lonnet::is_locked($env{'form.currentpath'}.$file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') {
  437:                 $locked_file = 1;
  438:             } 
  439:         }
  440:     }
  441:     my $current_disk_usage = &Apache::lonnet::diskusage($env{'user.domain'}, $env{'user.name'},$portfolio_root);
  442:     if (($current_disk_usage + $filesize) > $disk_quota){
  443:         $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.'.
  444:                   '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
  445:         $r->print(&done('Back'));
  446:     } 
  447:     elsif ($found_file){
  448:         if ($locked_file){
  449:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>portfolio'.$env{'form.currentpath'}.'</strong></font>'.
  450:                   '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
  451:             $r->print(&done('Back'));      
  452:         } else {   
  453:             $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>portfolio'.$env{'form.currentpath'}.'</strong></font>'.
  454:                   '<br />To upload, rename or delete existing '.$fname.' in portfolio'.$env{'form.currentpath'});
  455:             $r->print(&done('Back'));
  456:         }
  457:     } else {
  458:         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
  459: 	        	 'portfolio'.$env{'form.currentpath'});
  460:         if ($result !~ m|^/uploaded/|) {
  461:             $r->print('<font color="red"> An errror occured ('.$result.
  462: 	              ') while trying to upload '.&display_file().'</font><br />');
  463: 	    $r->print(&done('Back'));
  464:         } else {
  465:             $r->print(&done());
  466:         }
  467:     }
  468: }
  469: sub lock_info {
  470:     my ($r) = @_;
  471:     my %current_permissions = &Apache::lonnet::dump('file_permissions',$env{'user.domain'},$env{'user.name'});
  472:     my $file_name = $env{'form.lockinfo'};
  473:     foreach my $key(keys(%current_permissions)) {
  474:         if ($file_name eq $key) {
  475:             foreach my $array_item (@{$current_permissions{$key}}) {
  476:                 if (ref($array_item)) {
  477:                     $r->print('<strong>'.$key.'</strong> was submitted in response to problem: <strong>'.
  478:                             &Apache::lonnet::gettitle($$array_item[0]).'</strong><br />');
  479:                     my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
  480:                     $r->print('In the course: <strong>'.$course_description{'description'}.'</strong><br />');
  481:                     # $r->print('the third is '.$$array_item[2].'<br>');
  482:                     # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
  483:                 }
  484:             }
  485:         }    
  486:     }
  487:     $r->print(&done('Back'));
  488:     return 'ok';
  489: }
  490: sub createdir {
  491:     my ($r)=@_;
  492:     my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
  493:     if ($newdir eq '') {
  494:     	$r->print('<font color="red">'.
  495: 	    	  &mt("Error: no directory name was provided.").
  496: 		      '</font><br />');
  497: 	    $r->print(&done());
  498: 	    return;
  499:     } 
  500:     my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
  501: 						 $env{'user.name'}).
  502: 						'/userfiles/portfolio';
  503:     my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
  504: 					  $env{'user.domain'},
  505: 					  $env{'user.name'},$portfolio_root);
  506:     my $found_file = 0;
  507:     foreach my $line (@dir_list) {
  508:         my ($filename)=split(/\&/,$line,2);
  509:         if ($filename eq $newdir){
  510:             $found_file = 1;
  511:         }
  512:     }
  513:     if ($found_file){
  514:     	    $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
  515:     	            ' </strong>a file or directory by that name already exists.</font><br />');
  516:     } else {
  517:         my $result=&Apache::lonnet::mkdiruserfile($env{'user.name'},
  518: 	         $env{'user.domain'},'portfolio'.$env{'form.currentpath'}.$newdir);
  519:         if ($result ne 'ok') {
  520:     	    $r->print('<font color="red"> An errror occured ('.$result.
  521: 	    	      ') while trying to create a new directory '.&display_file().'</font><br />');
  522:         }
  523:     }
  524:     if ($newdir ne $env{'form.newdir'}) {
  525:         $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");  
  526:     }
  527:     $r->print(&done());
  528: }
  529: 
  530: sub handler {
  531:     # this handles file management
  532:     my $r = shift;
  533:     my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
  534: 							 $env{'user.name'}).
  535: 							'/userfiles/portfolio';
  536:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
  537:                                             ['selectfile','currentpath','meta','lockinfo',
  538: 					     'currentfile','action','fieldname','mode','rename','continue']);
  539:     &Apache::loncommon::no_cache($r);
  540:     &Apache::loncommon::content_type($r,'text/html');
  541:     $r->send_http_header;
  542:     # Give the LON-CAPA page header
  543:     my $html=&Apache::lonxml::xmlbegin();
  544:     $r->print($html.'<head><title>'.
  545:               &mt('Portfolio Manager').
  546:               "</title></head>\n");
  547:     if ($env{"form.mode"} eq 'selectfile'){
  548:         $r->print(&Apache::loncommon::bodytag('Portfolio Manager',undef,undef,1));
  549:     } else {
  550:         $r->print(&Apache::loncommon::bodytag('Portfolio Manager'));
  551:     }
  552:     $r->rflush();
  553: 	if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
  554:    	    $r->print('<font color="red"> No file was selected to upload.'.
  555:    	            'To upload a file, click <strong>Browse...</strong>'.
  556:    	            ', select a file, then click <strong>Upload</strong>,</font>');
  557: 	}
  558:     if ($env{'form.meta'}) {
  559:         &open_form($r);
  560: #        $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
  561:         $r->print('Edit the meta data<br />');
  562:         &close_form($r);
  563:     }
  564:     if ($env{'form.store'}) {
  565:     }
  566: 
  567:     if ($env{'form.uploaddoc.filename'}) {
  568: 	&upload($r);
  569:     } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
  570: 	&delete_confirmed($r);
  571:     } elsif ($env{'form.action'} eq 'delete') {
  572: 	&delete($r);
  573:     } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
  574: 	&delete_dir_confirmed($r);
  575:     } elsif ($env{'form.action'} eq 'deletedir'){
  576: 	&delete_dir($r);
  577:     } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
  578: 	&rename_confirmed($r);
  579:     } elsif ($env{'form.rename'}) {
  580:         $env{'form.selectfile'} = $env{'form.rename'};
  581:         $env{'form.action'} = 'rename';
  582: 	&rename($r);
  583:     } elsif ($env{'form.createdir'}) {
  584: 	&createdir($r);
  585:     } elsif ($env{'form.lockinfo'}) {
  586:         &lock_info($r);
  587:     } else {
  588: 	my $current_path='/';
  589: 	if ($env{'form.currentpath'}) {
  590: 	    $current_path = $env{'form.currentpath'};
  591: 	}
  592: 	my @dir_list=&Apache::lonnet::dirlist($current_path,
  593: 					    $env{'user.domain'},
  594: 					    $env{'user.name'},$portfolio_root);
  595: 	if ($dir_list[0] eq 'no_such_dir'){
  596: 	    # two main reasons for this:
  597:             #    1) never been here, so directory structure not created
  598: 	    #    2) back-button navigation after deleting a directory
  599: 	    if ($current_path eq '/'){
  600: 	        &Apache::lonnet::mkdiruserfile($env{'user.name'},
  601: 					       $env{'user.domain'},'portfolio');
  602: 	    } else {
  603:                 # some directory that snuck in get rid of the directory
  604:                 # from the recent pulldown, just in case
  605: 		&Apache::lonhtmlcommon::remove_recent('portfolio',
  606: 						      [$current_path]);
  607: 		$current_path = '/'; # force it back to the root        
  608: 	    }
  609: 	    # now grab the directory list again, for the first time
  610: 	    @dir_list=&Apache::lonnet::dirlist($current_path,
  611: 					    $env{'user.domain'},
  612: 					    $env{'user.name'},$portfolio_root);
  613:         }
  614: 	# need to know if directory is empty so it can be removed if desired
  615: 	my $is_empty=(@dir_list == 2);
  616: 	&display_common($r,$current_path,$is_empty,\@dir_list);
  617:         &display_directory($r,$current_path,$is_empty,\@dir_list);
  618: 	$r->print("</body>\n</html>\n");
  619: 	return OK;
  620:     }
  621: }
  622: 1;
  623: __END__

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