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