Annotation of loncom/interface/portfolio.pm, revision 1.53
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.16 banghart 32:
33: # receives a file name and path stub from username/userfiles/portfolio/
34: # returns an anchor tag consisting encoding filename and currentpath
1.23 albertel 35: sub make_anchor {
36: my ($filename, $current_path) = @_;
37: my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'¤tpath='.$current_path.'">'.$filename.'</a>';
1.8 albertel 38: return $anchor;
1.6 banghart 39: }
1.24 albertel 40: my $dirptr=16384;
1.48 banghart 41: sub display_common {
1.30 banghart 42: my ($r,$current_path,$is_empty,$dir_list)=@_;
1.18 banghart 43: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.20 banghart 44: $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">');
45: $r->print('<td bgcolor="#ccddaa" align="center">');
46: my $displayOut = '<form method="post" enctype="multipart/form-data">';
1.50 banghart 47: $displayOut .= '<input name="uploaddoc" type="file" />'.
1.24 albertel 48: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.50 banghart 49: '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
50: '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
1.20 banghart 51: '<input type="submit" name="storeupl" value="Upload" />'.
52: '</form>';
53: $r->print($displayOut);
1.22 albertel 54: $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
1.24 albertel 55: $displayOut = '<form method="post">';
56: $displayOut .= '<input name="newdir" type="input" />'.
57: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.50 banghart 58: '<input type="hidden" name="action" value="'.$ENV{"form.action"}.'" />'.
59: '<input type="hidden" name="fieldname" value="'.$ENV{"form.fieldname"}.'" />'.
1.22 albertel 60: '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
61: '</form>';
62: $r->print($displayOut);
63: $r->print('</td></tr></table>');
1.24 albertel 64: my @tree = split (/\//,$current_path);
1.29 albertel 65: $r->print('<font size="+2">'.&make_anchor('portfolio','/').'/');
1.19 banghart 66: if (@tree > 1){
67: my $newCurrentPath = '';
68: for (my $i = 1; $i< @tree; $i++){
69: $newCurrentPath .= $tree[$i].'/';
1.23 albertel 70: $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath).'/');
1.19 banghart 71: }
72: }
73: $r->print('</font>');
1.24 albertel 74: &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
1.39 banghart 75: #Fixme -- remove from recent those paths that are deleted
1.22 albertel 76: $r->print('<br /><form method=post action="/adm/portfolio">'.
77: &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
78: 'this.form.submit();'));
1.21 banghart 79: $r->print("</form>");
1.48 banghart 80: }
81: sub display_directory {
82: my ($r,$current_path,$is_empty,$dir_list)=@_;
83: my $iconpath= $r->dir_config('lonIconsURL') . "/";
84: my $display_out;
1.53 ! banghart 85: my %locked_files=&Apache::lonnet::dump('file_permissions',
! 86: $ENV{'user.domain'},$ENV{'user.name'});
! 87: my $locked_file;
! 88: foreach my $key (keys %locked_files) {
! 89: $locked_file .= $locked_files{$key}.':';
! 90: }
1.45 banghart 91: if ($is_empty && ($current_path ne '/')) {
1.48 banghart 92: $display_out = '<form method="post" action="/adm/portfolio">'.
1.30 banghart 93: '<input type="hidden" name="action" value="deletedir" />'.
94: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
95: '<input type="hidden" name="selectfile" value="" />'.
96: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
97: '</form>';
98:
1.48 banghart 99: $r->print($display_out);
1.31 albertel 100: return;
101: }
1.18 banghart 102: $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
1.22 albertel 103: '<tr><th>Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
1.39 banghart 104: my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
1.26 albertel 105: foreach my $line (sort
106: {
107: my ($afile)=split('&',$a,2);
108: my ($bfile)=split('&',$b,2);
109: return (lc($afile) cmp lc($bfile));
110: } (@$dir_list)) {
1.18 banghart 111: #$strip holds directory/file name
112: #$dom
1.23 albertel 113: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1.53 ! banghart 114: if ($Apache::lonhomework::results{"resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename"}eq'true'){
! 115: &Apache::lonnet::logthis("found submitted file");
! 116: &Apache::lonnet::logthis("resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename");
! 117: } else {
! 118: &Apache::lonnet::logthis("$filename not found submitted file");
! 119: &Apache::lonnet::logthis("resource.$ENV{'user.domain'}.$ENV{'user.name'}.$filename");
! 120: }
1.23 albertel 121: if (($filename ne '.') && ($filename ne '..')) {
122: if ($dirptr&$testdir) {
1.19 banghart 123: $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
124: $r->print('<td>Go to ...</td>');
1.24 albertel 125: $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/').'</td>');
1.19 banghart 126: $r->print('</tr>');
1.23 albertel 127: } else {
1.22 albertel 128: $r->print('<tr bgcolor="#CCCCFF">');
129: $r->print('<td>
1.39 banghart 130: <form method="post" action="/adm/portfolio">
131: <select name="action">
132: <option value=""></option>
133: <option value="delete">'.&mt("Delete").'</option>
134: <option value="rename">'.&mt("Rename").'</option>
135: </select>
136: <input type="submit" name="doit" value="Go" />
137: <input type="hidden" name="selectfile" value="'.$filename.'" />
138: <input type="hidden" name="currentpath" value="'.$current_path.'" />
139: </form>
140: </td>');
1.22 albertel 141: $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
1.23 albertel 142: $r->print('<td><a href="'.$href_location.$filename.'">'.
1.39 banghart 143: $filename.'</a></td>');
1.22 albertel 144: $r->print('<td>'.$size.'</td>');
145: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
1.19 banghart 146: $r->print('</tr>');
147: }
1.18 banghart 148: }
149: }
150: # <tr bgcolor="#FFAA99"> pink bg
151: # <tr bgcolor="#CCCCFF"> blue bg
1.24 albertel 152: # $r->print(&display_directory($current_path, $currentFile, @dir_list));
1.18 banghart 153: # $r->print('</td>><td>');
1.24 albertel 154: # $r->print(&display_actions($current_path, $currentFile, $isEmpty));
1.22 albertel 155: $r->print('</table></form>');
1.24 albertel 156: }
1.47 banghart 157: sub display_file_select {
158: my ($r,$current_path,$is_empty,$dir_list)=@_;
159: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.48 banghart 160: my $display_out;
1.47 banghart 161: if ($is_empty && ($current_path ne '/')) {
1.48 banghart 162: $display_out = '<form method="post" action="/adm/portfolio">'.
1.47 banghart 163: '<input type="hidden" name="action" value="deletedir" />'.
164: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
165: '<input type="hidden" name="selectfile" value="" />'.
166: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.48 banghart 167:
1.47 banghart 168: '</form>';
169:
1.48 banghart 170: $r->print($display_out);
1.47 banghart 171: return;
172: }
173: $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
174: '<tr><th>Select</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
175: my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio$current_path";
1.48 banghart 176: $r->print('<form method="post" name="checkselect" action="/adm/portfolio">');
1.47 banghart 177: foreach my $line (sort
178: {
179: my ($afile)=split('&',$a,2);
180: my ($bfile)=split('&',$b,2);
181: return (lc($afile) cmp lc($bfile));
182: } (@$dir_list)) {
183: #$strip holds directory/file name
184: #$dom
185: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
186: if (($filename ne '.') && ($filename ne '..')) {
187: if ($dirptr&$testdir) {
188: $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
189: $r->print('<td>Go to ...</td>');
190: $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/').'</td>');
191: $r->print('</tr>');
192: } else {
193: $r->print('<tr bgcolor="#CCCCFF">');
194: $r->print('<td>
195: <input type="checkbox" name="selectedfile" value="'.$filename.'" >
196: </td>');
197: $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
198: $r->print('<td><a href="'.$href_location.$filename.'">'.
199: $filename.'</a></td>');
200: $r->print('<td>'.$size.'</td>');
201: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
202: $r->print('</tr>');
203: }
204: }
205: }
1.48 banghart 206: $r->print('</table>
207: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
208: <input type="hidden" name="currentpath" value="'.$current_path.'" />
209: </form>');
1.47 banghart 210: }
1.24 albertel 211:
212: sub open_form {
213: my ($r)=@_;
214: $r->print('<form method="post" action="/adm/portfolio">');
215: $r->print('<input type="hidden" name="action" value="'.
216: $ENV{'form.action'}.'" />');
217: $r->print('<input type="hidden" name="confirmed" value="1" />');
218: $r->print('<input type="hidden" name="selectfile" value="'.
219: $ENV{'form.selectfile'}.'" />');
220: $r->print('<input type="hidden" name="currentpath" value="'.
221: $ENV{'form.currentpath'}.'" />');
222: }
223:
224: sub close_form {
225: my ($r)=@_;
226: $r->print('<p><input type="submit" value="'.&mt('Continue').
227: '" /></p></form>');
228: $r->print('<form action="/adm/portfolio" method="POST">
229: <p>
230: <input type="hidden" name="currentpath" value="'.
231: $ENV{'form.currentpath'}.'" />
232: <input type="submit" value="'.&mt('Cancel').'" />
233: </p></form>');
234:
235: }
236:
237: sub display_file {
1.27 albertel 238: my ($path,$filename)=@_;
239: if (!defined($path)) { $path=$ENV{'form.currentpath'}; }
240: if (!defined($filename)) { $filename=$ENV{'form.selectfile'}; }
241: return '<tt>'.$path.$filename.'</tt>';
1.24 albertel 242: }
243:
244: sub done {
1.25 albertel 245: return ('<h3><a href="/adm/portfolio?currentpath='.
1.50 banghart 246: $ENV{'form.currentpath'}.
247: '&fieldname='.$ENV{'form.fieldname'}.
248: '">'.&mt('Done').'</a></h3>');
1.24 albertel 249: }
250:
251: sub delete {
252: my ($r)=@_;
253: &open_form($r);
254: $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
255: &close_form($r);
256: }
257:
258: sub delete_confirmed {
259: my ($r)=@_;
260: my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
261: $ENV{'user.domain'},'portfolio'.
262: $ENV{'form.currentpath'}.
263: $ENV{'form.selectfile'});
264: if ($result ne 'ok') {
1.30 banghart 265: $r->print('<font color="red"> An error occured ('.$result.
1.25 albertel 266: ') while trying to delete '.&display_file().'</font><br />');
1.24 albertel 267: }
268: $r->print(&done());
269: }
270:
1.30 banghart 271: sub delete_dir {
272: my ($r)=@_;
273: &open_form($r);
274: $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
275: &close_form($r);
276: }
277:
278: sub delete_dir_confirmed {
279: my ($r)=@_;
280: my $directory_name = $ENV{'form.currentpath'};
281: $directory_name =~ m/\/$/;
282: $directory_name = $`;
283: my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
284: $ENV{'user.domain'},'portfolio'.
285: $directory_name);
1.32 banghart 286:
1.30 banghart 287: if ($result ne 'ok') {
288: $r->print('<font color="red"> An error occured (dir) ('.$result.
289: ') while trying to delete '.$directory_name.'</font><br />');
1.32 banghart 290: } else {
1.41 banghart 291: # now remove from recent
292: # $r->print('<br /> removing '.$directory_name.'<br /');
1.42 banghart 293: &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
1.32 banghart 294: my @dirs = split m!/!, $directory_name;
295:
296: # $directory_name =~ m/^(\/*\/)(\/*.)$/;
297: $directory_name='/';
298: for (my $i=1; $i < (@dirs - 1); $i ++){
299: $directory_name .= $dirs[$i].'/';
300: }
301: $ENV{'form.currentpath'} = $directory_name;
1.30 banghart 302: }
303: $r->print(&done());
304: }
305:
1.24 albertel 306: sub rename {
307: my ($r)=@_;
308: &open_form($r);
1.27 albertel 309: $r->print('<p>'.&mt('Rename').' '.&display_file().' to
310: <input name="filenewname" type="input" size="50" />?</p>');
1.24 albertel 311: &close_form($r);
312: }
313:
314: sub rename_confirmed {
315: my ($r)=@_;
1.27 albertel 316: my $filenewname=&Apache::lonnet::clean_filename($ENV{'form.filenewname'});
317: if ($filenewname eq '') {
318: $r->print('<font color="red">'.
319: &mt("Error: no valid filename was provided to rename to.").
320: '</font><br />');
321: $r->print(&done());
322: return;
323: }
324: my $result=
325: &Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'},
326: 'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'},
327: 'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.filenewname'});
328: if ($result ne 'ok') {
329: $r->print('<font color="red"> An errror occured ('.$result.
330: ') while trying to rename '.&display_file().' to '.
331: &display_file(undef,$filenewname).'</font><br />');
332: }
333: $r->print(&done());
334: }
1.47 banghart 335: sub select_files {
336: my ($r)=@_;
1.48 banghart 337: my $java_script =(<<ENDSMP);
338: <script language='javascript'>
339: function finishSelect() {
1.49 banghart 340: fileList = "";
341: for (i=0;i<document.forms.checkselect.length;i++) {
342: if (document.forms.checkselect[i].checked){
343: fileList = fileList + document.forms.checkselect[i].value + "," ;
344: }
345: }
346: opener.document.forms.lonhomework.
347: ENDSMP
348: $java_script .= $ENV{'form.fieldname'};
349: $java_script .= (<<ENDSMP);
350: .value=fileList;
1.48 banghart 351: self.close();
352: }
353: </script>
354: ENDSMP
355: $r->print($java_script);
1.47 banghart 356: $r->print("<h1>Select portfolio files</h1>
357: Check as many as you wish in response to the essay problem.<br />");
358: }
1.24 albertel 359: sub upload {
360: my ($r)=@_;
1.33 banghart 361: my $fname=$ENV{'form.uploaddoc.filename'};
1.38 banghart 362: my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?)
363: my $disk_quota = 20000; # expressed in k
1.34 banghart 364: $fname=&Apache::lonnet::clean_filename($fname);
365: my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33 banghart 366: $ENV{'user.name'}).
367: '/userfiles/portfolio';
1.38 banghart 368: # Fixme --- Move the checking for existing file to LOND error return
1.34 banghart 369: my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
370: $ENV{'user.domain'},
371: $ENV{'user.name'},$portfolio_root);
372: my $found_file = 0;
1.33 banghart 373: foreach my $line (@dir_list) {
1.34 banghart 374: my ($filename)=split(/\&/,$line,2);
1.33 banghart 375: if ($filename eq $fname){
376: $found_file = 1;
377: }
378: }
1.38 banghart 379: my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);
380: if (($current_disk_usage + $filesize) > $disk_quota){
381: $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
382: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
383: }
384: elsif ($found_file){
1.33 banghart 385: $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$ENV{'form.currentpath'}.'</strong></font>'.
386: '<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'});
387: } else {
388: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
389: 'portfolio'.$ENV{'form.currentpath'});
390: if ($result !~ m|^/uploaded/|) {
1.34 banghart 391: $r->print('<font color="red"> An errror occured ('.$result.
392: ') while trying to upload '.&display_file().'</font><br />');
1.33 banghart 393: }
1.25 albertel 394: }
395: $r->print(&done());
396: }
397:
398: sub createdir {
399: my ($r)=@_;
1.28 albertel 400: my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'});
401: if ($newdir eq '') {
1.37 banghart 402: $r->print('<font color="red">'.
403: &mt("Error: no directory name was provided.").
404: '</font><br />');
405: $r->print(&done());
406: return;
1.28 albertel 407: }
1.37 banghart 408: my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
409: $ENV{'user.name'}).
410: '/userfiles/portfolio';
411: my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
412: $ENV{'user.domain'},
413: $ENV{'user.name'},$portfolio_root);
414: my $found_file = 0;
415: foreach my $line (@dir_list) {
416: my ($filename)=split(/\&/,$line,2);
417: if ($filename eq $newdir){
418: $found_file = 1;
419: }
420: }
421: if ($found_file){
422: $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
423: ' </strong>a file or directory by that name already exists.</font><br />');
424: } else {
425: my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'},
426: $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir);
427: if ($result ne 'ok') {
428: $r->print('<font color="red"> An errror occured ('.$result.
429: ') while trying to create a new directory '.&display_file().'</font><br />');
430: }
1.24 albertel 431: }
432: $r->print(&done());
433: }
434:
435: sub handler {
436: # this handles file management
437: my $r = shift;
1.47 banghart 438: my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
1.33 banghart 439: $ENV{'user.name'}).
440: '/userfiles/portfolio';
1.24 albertel 441: &Apache::loncommon::no_cache($r);
442: &Apache::loncommon::content_type($r,'text/html');
443: $r->send_http_header;
444: # Give the LON-CAPA page header
445: $r->print('<html><head><title>'.
446: &mt('Portfolio Manager').
447: "</title></head>\n".
448: &Apache::loncommon::bodytag('Portfolio Manager'));
449: $r->rflush();
450: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
451: ['selectfile','currentpath',
1.52 banghart 452: 'currentfile','action','fieldname','mode']);
1.40 banghart 453: if (($ENV{'form.storeupl'} eq 'Upload') & (!$ENV{'form.uploaddoc.filename'})){
454: $r->print('<font color="red"> No file was selected to upload.'.
455: 'To upload a file, click <strong>Browse...</strong>'.
456: ', select a file, then click <strong>Upload</strong>,</font>');
457: }
1.24 albertel 458: if ($ENV{'form.uploaddoc.filename'}) {
459: &upload($r);
1.27 albertel 460: } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) {
461: &delete_confirmed($r);
1.24 albertel 462: } elsif ($ENV{'form.action'} eq 'delete') {
1.27 albertel 463: &delete($r);
1.30 banghart 464: } elsif ($ENV{'form.action'} eq 'deletedir' && $ENV{'form.confirmed'}) {
1.31 albertel 465: &delete_dir_confirmed($r);
1.30 banghart 466: } elsif ($ENV{'form.action'} eq 'deletedir'){
1.31 albertel 467: &delete_dir($r);
1.27 albertel 468: } elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) {
469: &rename_confirmed($r);
1.24 albertel 470: } elsif ($ENV{'form.action'} eq 'rename') {
471: &rename($r);
1.25 albertel 472: } elsif ($ENV{'form.createdir'}) {
473: &createdir($r);
1.24 albertel 474: } else {
475: my $current_path='/';
476: if ($ENV{'form.currentpath'}) {
477: $current_path = $ENV{'form.currentpath'};
478: }
1.43 banghart 479: my @dir_list=&Apache::lonnet::dirlist($current_path,
1.27 albertel 480: $ENV{'user.domain'},
481: $ENV{'user.name'},$portfolio_root);
1.46 albertel 482: if ($dir_list[0] eq 'no_such_dir'){
483: # two main reasons for this:
484: # 1) never been here, so directory structure not created
485: # 2) back-button navigation after deleting a directory
486: if ($current_path eq '/'){
1.43 banghart 487: &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
1.46 albertel 488: $ENV{'user.domain'},'portfolio');
489: } else {
490: # some directory that snuck in get rid of the directory
491: # from the recent pulldown, just in case
492: &Apache::lonhtmlcommon::remove_recent('portfolio',
493: [$current_path]);
494: $current_path = '/'; # force it back to the root
495: }
496: # now grab the directory list again, for the first time
497: @dir_list=&Apache::lonnet::dirlist($current_path,
498: $ENV{'user.domain'},
499: $ENV{'user.name'},$portfolio_root);
1.43 banghart 500: }
1.46 albertel 501: # need to know if directory is empty so it can be removed if desired
502: my $is_empty=(@dir_list == 2);
1.48 banghart 503: &display_common($r,$current_path,$is_empty,\@dir_list);
1.51 matthew 504: if ($ENV{"form.mode"} eq 'selectfile'){
1.50 banghart 505: &select_files($r);
506: &display_file_select($r,$current_path,$is_empty,\@dir_list);
507: } else {
508: &display_directory($r,$current_path,$is_empty,\@dir_list);
509: }
1.46 albertel 510: $r->print("</body>\n</html>\n");
511: return OK;
1.30 banghart 512: }
1.2 banghart 513: }
1.1 banghart 514: 1;
515: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>