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