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