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