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