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