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