Annotation of loncom/interface/portfolio.pm, revision 1.84
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.82 albertel 32: use Apache::lonnet;
1.16 banghart 33:
34: # receives a file name and path stub from username/userfiles/portfolio/
35: # returns an anchor tag consisting encoding filename and currentpath
1.23 albertel 36: sub make_anchor {
1.83 banghart 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>';
1.8 albertel 40: return $anchor;
1.6 banghart 41: }
1.24 albertel 42: my $dirptr=16384;
1.48 banghart 43: sub display_common {
1.30 banghart 44: my ($r,$current_path,$is_empty,$dir_list)=@_;
1.18 banghart 45: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.20 banghart 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">';
1.50 banghart 49: $displayOut .= '<input name="uploaddoc" type="file" />'.
1.24 albertel 50: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.82 albertel 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"}.'" />'.
1.20 banghart 54: '<input type="submit" name="storeupl" value="Upload" />'.
55: '</form>';
56: $r->print($displayOut);
1.22 albertel 57: $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
1.24 albertel 58: $displayOut = '<form method="post">';
59: $displayOut .= '<input name="newdir" type="input" />'.
60: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
1.82 albertel 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"}.'" />'.
1.22 albertel 64: '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
65: '</form>';
66: $r->print($displayOut);
67: $r->print('</td></tr></table>');
1.24 albertel 68: my @tree = split (/\//,$current_path);
1.83 banghart 69: $r->print('<font size="+2">'.&make_anchor('portfolio','/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"}).'/');
1.19 banghart 70: if (@tree > 1){
71: my $newCurrentPath = '';
72: for (my $i = 1; $i< @tree; $i++){
73: $newCurrentPath .= $tree[$i].'/';
1.83 banghart 74: $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"}).'/');
1.19 banghart 75: }
76: }
77: $r->print('</font>');
1.24 albertel 78: &Apache::lonhtmlcommon::store_recent('portfolio',$current_path,$current_path);
1.82 albertel 79: $r->print('<br /><form method=post action="/adm/portfolio?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.'">'.
1.22 albertel 80: &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
81: 'this.form.submit();'));
1.21 banghart 82: $r->print("</form>");
1.48 banghart 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;
1.77 banghart 88: my $select_mode;
89: my $checked_files;
1.82 albertel 90: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($env{'user.domain'},$env{'user.name'});
91: if ($env{"form.mode"} eq 'selectfile'){
1.77 banghart 92: &select_files($r);
1.82 albertel 93: $checked_files =&Apache::lonnet::files_in_path($env{'user.name'},$env{'form.currentpath'});
1.77 banghart 94: $select_mode = 'true';
95: }
1.45 banghart 96: if ($is_empty && ($current_path ne '/')) {
1.48 banghart 97: $display_out = '<form method="post" action="/adm/portfolio">'.
1.30 banghart 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:
1.48 banghart 104: $r->print($display_out);
1.31 albertel 105: return;
106: }
1.77 banghart 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">'.
1.70 banghart 113: '<tr><th colspan="2">Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
1.77 banghart 114: $r->print('<form method="post" action="/adm/portfolio">');
115: }
1.82 albertel 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";
1.26 albertel 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)) {
1.18 banghart 124: #$strip holds directory/file name
125: #$dom
1.23 albertel 126: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
1.77 banghart 127: $filename =~ s/\s+$//;
1.84 ! banghart 128: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(.*)\.(.*)/)) {
1.23 albertel 129: if ($dirptr&$testdir) {
1.77 banghart 130: if ($select_mode eq 'true'){
131: $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
1.64 banghart 132: } else {
1.77 banghart 133: $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
1.64 banghart 134: }
1.47 banghart 135: $r->print('<td>Go to ...</td>');
1.83 banghart 136: $r->print('<td>'.&make_anchor($filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'}).'</td>');
1.47 banghart 137: $r->print('</tr>');
138: } else {
139: $r->print('<tr bgcolor="#CCCCFF">');
1.77 banghart 140: if ($select_mode eq 'true'){
1.83 banghart 141: $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"');
1.77 banghart 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}){
1.80 banghart 148: $r->print('<td colspan="2"><a href="portfolio?lockinfo='.$current_path.$filename.'">Locked</a></td>');
1.77 banghart 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>
1.80 banghart 152: <td><a href="'.$href_edit_location.$filename.'.meta">Meta</a>
1.77 banghart 153: </td>');
154: }
1.61 banghart 155: }
1.47 banghart 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: }
1.77 banghart 165: if ($select_mode eq 'true') {
166: $r->print('</table>
1.60 banghart 167: <input type="hidden" name="continue" value="true">
1.82 albertel 168: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'">
1.60 banghart 169: <input type="hidden" name="mode" value="selectfile">
170: <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
1.48 banghart 171: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
172: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.77 banghart 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: }
1.47 banghart 181: }
1.72 banghart 182:
1.24 albertel 183: sub open_form {
184: my ($r)=@_;
1.65 banghart 185: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.24 albertel 186: $r->print('<form method="post" action="/adm/portfolio">');
187: $r->print('<input type="hidden" name="action" value="'.
1.82 albertel 188: $env{'form.action'}.'" />');
1.24 albertel 189: $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65 banghart 190: foreach (@files) {
191: $r->print('<input type="hidden" name="selectfile" value="'.
192: $_.'" />');
193: }
1.24 albertel 194: $r->print('<input type="hidden" name="currentpath" value="'.
1.82 albertel 195: $env{'form.currentpath'}.'" />');
1.24 albertel 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="'.
1.82 albertel 205: $env{'form.currentpath'}.'" />
1.24 albertel 206: <input type="submit" value="'.&mt('Cancel').'" />
207: </p></form>');
208:
209: }
210:
211: sub display_file {
1.27 albertel 212: my ($path,$filename)=@_;
1.65 banghart 213: my $display_file_text;
1.82 albertel 214: if (!defined($path)) { $path=$env{'form.currentpath'}; }
1.65 banghart 215: if (!defined($filename)) {
1.82 albertel 216: $filename=$env{'form.selectfile'};
1.65 banghart 217: $display_file_text = '<tt>'.$path.$filename.'</tt>';
218: } elsif (ref($filename) eq "ARRAY") {
219: foreach (@$filename) {
1.66 banghart 220: $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
1.65 banghart 221: }
222: } elsif (ref($filename) eq "SCALAR") {
223: $display_file_text = '<tt>'.$path.$filename.'</tt>';
224: }
225: return $display_file_text;
1.24 albertel 226: }
227:
228: sub done {
1.76 banghart 229: my ($message)=@_;
230: unless (defined $message) {
231: $message='Done';
232: }
1.25 albertel 233: return ('<h3><a href="/adm/portfolio?currentpath='.
1.82 albertel 234: $env{'form.currentpath'}.
235: '&fieldname='.$env{'form.fieldname'}.
236: '&mode='.$env{'form.mode'}.
1.76 banghart 237: '">'.&mt($message).'</a></h3>');
1.24 albertel 238: }
239:
240: sub delete {
241: my ($r)=@_;
1.55 banghart 242: my @check;
1.82 albertel 243: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.65 banghart 244: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.66 banghart 245:
1.82 albertel 246: if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') {
1.55 banghart 247: $r->print ("The file is locked and cannot be deleted.<br />");
1.76 banghart 248: $r->print(&done('Back'));
1.55 banghart 249: } else {
1.66 banghart 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: }
1.55 banghart 258: }
1.24 albertel 259: }
260:
261: sub delete_confirmed {
262: my ($r)=@_;
1.65 banghart 263: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
264: my $result;
265: foreach my $delete_file (@files) {
1.82 albertel 266: $result=&Apache::lonnet::removeuserfile($env{'user.name'},
267: $env{'user.domain'},'portfolio'.
268: $env{'form.currentpath'}.
1.65 banghart 269: $delete_file);
270: if ($result ne 'ok') {
1.30 banghart 271: $r->print('<font color="red"> An error occured ('.$result.
1.65 banghart 272: ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
273: }
1.24 albertel 274: }
275: $r->print(&done());
276: }
277:
1.30 banghart 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)=@_;
1.82 albertel 287: my $directory_name = $env{'form.currentpath'};
1.81 albertel 288: $directory_name =~ s|/$||; # remove any trailing slash
1.82 albertel 289: my $result=&Apache::lonnet::removeuserfile($env{'user.name'},
290: $env{'user.domain'},'portfolio'.
1.30 banghart 291: $directory_name);
1.32 banghart 292:
1.30 banghart 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 />');
1.32 banghart 296: } else {
1.41 banghart 297: # now remove from recent
298: # $r->print('<br /> removing '.$directory_name.'<br /');
1.42 banghart 299: &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
1.32 banghart 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: }
1.82 albertel 307: $env{'form.currentpath'} = $directory_name;
1.30 banghart 308: }
309: $r->print(&done());
310: }
311:
1.24 albertel 312: sub rename {
313: my ($r)=@_;
1.82 albertel 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') {
1.55 banghart 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: }
1.24 albertel 324: }
325:
326: sub rename_confirmed {
327: my ($r)=@_;
1.82 albertel 328: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
1.27 albertel 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=
1.82 albertel 337: &Apache::lonnet::renameuserfile($env{'user.name'},$env{'user.domain'},
338: 'portfolio'.$env{'form.currentpath'}.$env{'form.selectfile'},
339: 'portfolio'.$env{'form.currentpath'}.$filenewname);
1.27 albertel 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: }
1.82 albertel 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>");
1.66 banghart 347: }
1.27 albertel 348: $r->print(&done());
349: }
1.47 banghart 350: sub select_files {
351: my ($r)=@_;
1.82 albertel 352: if ($env{'form.continue'} eq 'true') {
1.60 banghart 353: # here we update the selections for the currentpath
354: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 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: }
1.62 banghart 360: } else {
361: #empty the file for a fresh start
1.83 banghart 362: &Apache::lonnet::logthis("Clearing saved files");
363: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 364: }
1.82 albertel 365: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 366: my $java_files = join ",", @files;
367: if ($java_files) {
368: $java_files.=',';
1.60 banghart 369: }
1.63 banghart 370: my $javascript =(<<ENDSMP);
1.48 banghart 371: <script language='javascript'>
372: function finishSelect() {
1.62 banghart 373: ENDSMP
1.63 banghart 374: $javascript .= 'fileList = "'.$java_files.'";';
375: $javascript .= (<<ENDSMP);
1.49 banghart 376: for (i=0;i<document.forms.checkselect.length;i++) {
377: if (document.forms.checkselect[i].checked){
1.54 banghart 378: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 379: }
380: }
381: opener.document.forms.lonhomework.
382: ENDSMP
1.82 albertel 383: $javascript .= $env{'form.fieldname'};
1.63 banghart 384: $javascript .= (<<ENDSMP);
1.49 banghart 385: .value=fileList;
1.48 banghart 386: self.close();
387: }
388: </script>
389: ENDSMP
1.63 banghart 390: $r->print($javascript);
1.47 banghart 391: $r->print("<h1>Select portfolio files</h1>
392: Check as many as you wish in response to the essay problem.<br />");
1.61 banghart 393: $r->print("<strong>Files selected from other directories:</strong><br />");
1.82 albertel 394: foreach (&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'})) {
1.60 banghart 395: $r->print($_."<br />");
396: }
1.47 banghart 397: }
1.24 albertel 398: sub upload {
399: my ($r)=@_;
1.82 albertel 400: my $fname=$env{'form.uploaddoc.filename'};
401: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1.38 banghart 402: my $disk_quota = 20000; # expressed in k
1.34 banghart 403: $fname=&Apache::lonnet::clean_filename($fname);
1.82 albertel 404: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
405: $env{'user.name'}).
1.33 banghart 406: '/userfiles/portfolio';
1.38 banghart 407: # Fixme --- Move the checking for existing file to LOND error return
1.82 albertel 408: my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
409: $env{'user.domain'},
410: $env{'user.name'},$portfolio_root);
1.34 banghart 411: my $found_file = 0;
1.76 banghart 412: my $locked_file = 0;
1.33 banghart 413: foreach my $line (@dir_list) {
1.76 banghart 414: my ($file_name)=split(/\&/,$line,2);
415: if ($file_name eq $fname){
1.33 banghart 416: $found_file = 1;
1.82 albertel 417: if (&Apache::lonnet::is_locked($env{'form.currentpath'}.$file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') {
1.76 banghart 418: $locked_file = 1;
419: }
1.33 banghart 420: }
421: }
1.82 albertel 422: my $current_disk_usage = &Apache::lonnet::diskusage($env{'user.domain'}, $env{'user.name'},$portfolio_root);
1.69 banghart 423: if ((($current_disk_usage/1000) + $filesize) > $disk_quota){
1.38 banghart 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.');
1.76 banghart 426: $r->print(&done('Back'));
1.38 banghart 427: }
1.76 banghart 428: elsif ($found_file){
429: if ($locked_file){
1.82 albertel 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>'.
1.76 banghart 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 {
1.82 albertel 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'});
1.76 banghart 436: $r->print(&done('Back'));
437: }
1.33 banghart 438: } else {
439: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1.82 albertel 440: 'portfolio'.$env{'form.currentpath'});
1.33 banghart 441: if ($result !~ m|^/uploaded/|) {
1.34 banghart 442: $r->print('<font color="red"> An errror occured ('.$result.
443: ') while trying to upload '.&display_file().'</font><br />');
1.76 banghart 444: $r->print(&done('Back'));
445: } else {
446: $r->print(&done());
1.33 banghart 447: }
1.25 albertel 448: }
449: }
1.80 banghart 450: sub lock_info {
451: my ($r) = @_;
1.84 ! banghart 452: my %current_permissions = &Apache::lonnet::dump('file_permissions',$env{'user.domain'},$env{'user.name'});
! 453: my $file_name = $env{'form.lockinfo'};
! 454: #my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash ($env{'user.domain'},$env{'user.name'});
! 455: foreach my $key (keys(%current_permissions)) {
! 456: if ($file_name eq $key) {
! 457: $r->print("$key = ");
! 458: foreach my $array_item (@{$current_permissions{$key}}) {
! 459: if (ref($array_item)) {
! 460: $r->print(&Apache::lonnet::gettitle($$array_item[0]).' is the problem<br>');
! 461: $r->print(&Apache::lonnet::coursedescription($$array_item[1]).' is the course<br>');
! 462: # $r->print('the third is '.$$array_item[2].'<br>');
! 463: # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
! 464: }
! 465: }
! 466: }
! 467: }
! 468: #$r->print("lock info here");
1.80 banghart 469: return 'ok';
470: }
1.25 albertel 471: sub createdir {
472: my ($r)=@_;
1.82 albertel 473: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 474: if ($newdir eq '') {
1.37 banghart 475: $r->print('<font color="red">'.
476: &mt("Error: no directory name was provided.").
477: '</font><br />');
478: $r->print(&done());
479: return;
1.28 albertel 480: }
1.82 albertel 481: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
482: $env{'user.name'}).
1.37 banghart 483: '/userfiles/portfolio';
1.82 albertel 484: my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
485: $env{'user.domain'},
486: $env{'user.name'},$portfolio_root);
1.37 banghart 487: my $found_file = 0;
488: foreach my $line (@dir_list) {
489: my ($filename)=split(/\&/,$line,2);
490: if ($filename eq $newdir){
491: $found_file = 1;
492: }
493: }
494: if ($found_file){
495: $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
496: ' </strong>a file or directory by that name already exists.</font><br />');
497: } else {
1.82 albertel 498: my $result=&Apache::lonnet::mkdiruserfile($env{'user.name'},
499: $env{'user.domain'},'portfolio'.$env{'form.currentpath'}.$newdir);
1.37 banghart 500: if ($result ne 'ok') {
501: $r->print('<font color="red"> An errror occured ('.$result.
502: ') while trying to create a new directory '.&display_file().'</font><br />');
503: }
1.24 albertel 504: }
1.82 albertel 505: if ($newdir ne $env{'form.newdir'}) {
506: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
1.67 banghart 507: }
1.24 albertel 508: $r->print(&done());
509: }
510:
511: sub handler {
512: # this handles file management
513: my $r = shift;
1.82 albertel 514: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
515: $env{'user.name'}).
1.33 banghart 516: '/userfiles/portfolio';
1.73 banghart 517: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.80 banghart 518: ['selectfile','currentpath','meta','lockinfo',
1.83 banghart 519: 'currentfile','action','fieldname','mode','rename','continue']);
1.24 albertel 520: &Apache::loncommon::no_cache($r);
521: &Apache::loncommon::content_type($r,'text/html');
522: $r->send_http_header;
523: # Give the LON-CAPA page header
1.75 albertel 524: my $html=&Apache::lonxml::xmlbegin();
525: $r->print($html.'<head><title>'.
1.24 albertel 526: &mt('Portfolio Manager').
1.74 banghart 527: "</title></head>\n");
1.82 albertel 528: if ($env{"form.mode"} eq 'selectfile'){
1.74 banghart 529: $r->print(&Apache::loncommon::bodytag('Portfolio Manager',undef,undef,1));
530: } else {
531: $r->print(&Apache::loncommon::bodytag('Portfolio Manager'));
532: }
1.24 albertel 533: $r->rflush();
1.82 albertel 534: if (($env{'form.storeupl'} eq 'Upload') & (!$env{'form.uploaddoc.filename'})){
1.40 banghart 535: $r->print('<font color="red"> No file was selected to upload.'.
536: 'To upload a file, click <strong>Browse...</strong>'.
537: ', select a file, then click <strong>Upload</strong>,</font>');
538: }
1.82 albertel 539: if ($env{'form.meta'}) {
1.70 banghart 540: &open_form($r);
1.82 albertel 541: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1.70 banghart 542: $r->print('Edit the meta data<br />');
543: &close_form($r);
544: }
1.82 albertel 545: if ($env{'form.store'}) {
1.70 banghart 546: }
547:
1.82 albertel 548: if ($env{'form.uploaddoc.filename'}) {
1.24 albertel 549: &upload($r);
1.82 albertel 550: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.27 albertel 551: &delete_confirmed($r);
1.82 albertel 552: } elsif ($env{'form.action'} eq 'delete') {
1.27 albertel 553: &delete($r);
1.82 albertel 554: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.31 albertel 555: &delete_dir_confirmed($r);
1.82 albertel 556: } elsif ($env{'form.action'} eq 'deletedir'){
1.31 albertel 557: &delete_dir($r);
1.82 albertel 558: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.27 albertel 559: &rename_confirmed($r);
1.82 albertel 560: } elsif ($env{'form.rename'}) {
561: $env{'form.selectfile'} = $env{'form.rename'};
562: $env{'form.action'} = 'rename';
1.24 albertel 563: &rename($r);
1.82 albertel 564: } elsif ($env{'form.createdir'}) {
1.25 albertel 565: &createdir($r);
1.82 albertel 566: } elsif ($env{'form.lockinfo'}) {
1.80 banghart 567: &lock_info($r);
1.24 albertel 568: } else {
569: my $current_path='/';
1.82 albertel 570: if ($env{'form.currentpath'}) {
571: $current_path = $env{'form.currentpath'};
1.24 albertel 572: }
1.43 banghart 573: my @dir_list=&Apache::lonnet::dirlist($current_path,
1.82 albertel 574: $env{'user.domain'},
575: $env{'user.name'},$portfolio_root);
1.46 albertel 576: if ($dir_list[0] eq 'no_such_dir'){
577: # two main reasons for this:
578: # 1) never been here, so directory structure not created
579: # 2) back-button navigation after deleting a directory
580: if ($current_path eq '/'){
1.82 albertel 581: &Apache::lonnet::mkdiruserfile($env{'user.name'},
582: $env{'user.domain'},'portfolio');
1.46 albertel 583: } else {
584: # some directory that snuck in get rid of the directory
585: # from the recent pulldown, just in case
586: &Apache::lonhtmlcommon::remove_recent('portfolio',
587: [$current_path]);
588: $current_path = '/'; # force it back to the root
589: }
590: # now grab the directory list again, for the first time
591: @dir_list=&Apache::lonnet::dirlist($current_path,
1.82 albertel 592: $env{'user.domain'},
593: $env{'user.name'},$portfolio_root);
1.43 banghart 594: }
1.46 albertel 595: # need to know if directory is empty so it can be removed if desired
596: my $is_empty=(@dir_list == 2);
1.48 banghart 597: &display_common($r,$current_path,$is_empty,\@dir_list);
1.77 banghart 598: &display_directory($r,$current_path,$is_empty,\@dir_list);
1.46 albertel 599: $r->print("</body>\n</html>\n");
600: return OK;
1.30 banghart 601: }
1.2 banghart 602: }
1.1 banghart 603: 1;
604: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>