Annotation of loncom/interface/portfolio.pm, revision 1.89
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 {
1.89 ! albertel 168: my $cat='<img alt="'.&mt('Catalog Information').
! 169: '" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />';
1.77 banghart 170: $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
171: <a href="/adm/portfolio?rename='.$filename.'&currentpath='.$current_path.'">Rename</a></td>
1.89 ! albertel 172: <td><a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>
1.77 banghart 173: </td>');
174: }
1.61 banghart 175: }
1.47 banghart 176: $r->print('<td><img src="'.$iconpath.'unknown.gif"></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: }
1.77 banghart 185: if ($select_mode eq 'true') {
186: $r->print('</table>
1.60 banghart 187: <input type="hidden" name="continue" value="true">
1.82 albertel 188: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'">
1.60 banghart 189: <input type="hidden" name="mode" value="selectfile">
190: <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
1.48 banghart 191: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
192: <input type="hidden" name="currentpath" value="'.$current_path.'" />
1.77 banghart 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: }
1.47 banghart 201: }
1.72 banghart 202:
1.24 albertel 203: sub open_form {
204: my ($r)=@_;
1.65 banghart 205: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.24 albertel 206: $r->print('<form method="post" action="/adm/portfolio">');
207: $r->print('<input type="hidden" name="action" value="'.
1.82 albertel 208: $env{'form.action'}.'" />');
1.24 albertel 209: $r->print('<input type="hidden" name="confirmed" value="1" />');
1.65 banghart 210: foreach (@files) {
211: $r->print('<input type="hidden" name="selectfile" value="'.
212: $_.'" />');
213: }
1.24 albertel 214: $r->print('<input type="hidden" name="currentpath" value="'.
1.82 albertel 215: $env{'form.currentpath'}.'" />');
1.24 albertel 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="'.
1.82 albertel 225: $env{'form.currentpath'}.'" />
1.24 albertel 226: <input type="submit" value="'.&mt('Cancel').'" />
227: </p></form>');
228:
229: }
230:
231: sub display_file {
1.27 albertel 232: my ($path,$filename)=@_;
1.65 banghart 233: my $display_file_text;
1.82 albertel 234: if (!defined($path)) { $path=$env{'form.currentpath'}; }
1.65 banghart 235: if (!defined($filename)) {
1.82 albertel 236: $filename=$env{'form.selectfile'};
1.65 banghart 237: $display_file_text = '<tt>'.$path.$filename.'</tt>';
238: } elsif (ref($filename) eq "ARRAY") {
239: foreach (@$filename) {
1.66 banghart 240: $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
1.65 banghart 241: }
242: } elsif (ref($filename) eq "SCALAR") {
243: $display_file_text = '<tt>'.$path.$filename.'</tt>';
244: }
245: return $display_file_text;
1.24 albertel 246: }
247:
248: sub done {
1.76 banghart 249: my ($message)=@_;
250: unless (defined $message) {
251: $message='Done';
252: }
1.25 albertel 253: return ('<h3><a href="/adm/portfolio?currentpath='.
1.82 albertel 254: $env{'form.currentpath'}.
255: '&fieldname='.$env{'form.fieldname'}.
256: '&mode='.$env{'form.mode'}.
1.76 banghart 257: '">'.&mt($message).'</a></h3>');
1.24 albertel 258: }
259:
260: sub delete {
261: my ($r)=@_;
1.55 banghart 262: my @check;
1.82 albertel 263: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.65 banghart 264: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
1.66 banghart 265:
1.82 albertel 266: if (&Apache::lonnet::is_locked($file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') {
1.55 banghart 267: $r->print ("The file is locked and cannot be deleted.<br />");
1.76 banghart 268: $r->print(&done('Back'));
1.55 banghart 269: } else {
1.66 banghart 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: }
1.55 banghart 278: }
1.24 albertel 279: }
280:
281: sub delete_confirmed {
282: my ($r)=@_;
1.65 banghart 283: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
284: my $result;
285: foreach my $delete_file (@files) {
1.82 albertel 286: $result=&Apache::lonnet::removeuserfile($env{'user.name'},
287: $env{'user.domain'},'portfolio'.
288: $env{'form.currentpath'}.
1.65 banghart 289: $delete_file);
290: if ($result ne 'ok') {
1.30 banghart 291: $r->print('<font color="red"> An error occured ('.$result.
1.65 banghart 292: ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
293: }
1.24 albertel 294: }
295: $r->print(&done());
296: }
297:
1.30 banghart 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)=@_;
1.82 albertel 307: my $directory_name = $env{'form.currentpath'};
1.81 albertel 308: $directory_name =~ s|/$||; # remove any trailing slash
1.82 albertel 309: my $result=&Apache::lonnet::removeuserfile($env{'user.name'},
310: $env{'user.domain'},'portfolio'.
1.30 banghart 311: $directory_name);
1.32 banghart 312:
1.30 banghart 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 />');
1.32 banghart 316: } else {
1.41 banghart 317: # now remove from recent
318: # $r->print('<br /> removing '.$directory_name.'<br /');
1.42 banghart 319: &Apache::lonhtmlcommon::remove_recent('portfolio',[$directory_name.'/']);
1.32 banghart 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: }
1.82 albertel 327: $env{'form.currentpath'} = $directory_name;
1.30 banghart 328: }
329: $r->print(&done());
330: }
331:
1.24 albertel 332: sub rename {
333: my ($r)=@_;
1.82 albertel 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') {
1.55 banghart 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: }
1.24 albertel 344: }
345:
346: sub rename_confirmed {
347: my ($r)=@_;
1.82 albertel 348: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
1.27 albertel 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=
1.82 albertel 357: &Apache::lonnet::renameuserfile($env{'user.name'},$env{'user.domain'},
358: 'portfolio'.$env{'form.currentpath'}.$env{'form.selectfile'},
359: 'portfolio'.$env{'form.currentpath'}.$filenewname);
1.27 albertel 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: }
1.82 albertel 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>");
1.66 banghart 367: }
1.27 albertel 368: $r->print(&done());
369: }
1.47 banghart 370: sub select_files {
371: my ($r)=@_;
1.82 albertel 372: if ($env{'form.continue'} eq 'true') {
1.60 banghart 373: # here we update the selections for the currentpath
374: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 375: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
376: if (scalar(@items)){
1.85 banghart 377: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83 banghart 378: }
1.62 banghart 379: } else {
380: #empty the file for a fresh start
1.83 banghart 381: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 382: }
1.82 albertel 383: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 384: my $java_files = join ",", @files;
385: if ($java_files) {
386: $java_files.=',';
1.60 banghart 387: }
1.63 banghart 388: my $javascript =(<<ENDSMP);
1.48 banghart 389: <script language='javascript'>
390: function finishSelect() {
1.62 banghart 391: ENDSMP
1.63 banghart 392: $javascript .= 'fileList = "'.$java_files.'";';
393: $javascript .= (<<ENDSMP);
1.49 banghart 394: for (i=0;i<document.forms.checkselect.length;i++) {
395: if (document.forms.checkselect[i].checked){
1.54 banghart 396: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 397: }
398: }
399: opener.document.forms.lonhomework.
400: ENDSMP
1.82 albertel 401: $javascript .= $env{'form.fieldname'};
1.63 banghart 402: $javascript .= (<<ENDSMP);
1.49 banghart 403: .value=fileList;
1.48 banghart 404: self.close();
405: }
406: </script>
407: ENDSMP
1.63 banghart 408: $r->print($javascript);
1.47 banghart 409: $r->print("<h1>Select portfolio files</h1>
1.88 albertel 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: }
1.60 banghart 417: }
1.47 banghart 418: }
1.24 albertel 419: sub upload {
420: my ($r)=@_;
1.82 albertel 421: my $fname=$env{'form.uploaddoc.filename'};
422: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1.38 banghart 423: my $disk_quota = 20000; # expressed in k
1.34 banghart 424: $fname=&Apache::lonnet::clean_filename($fname);
1.82 albertel 425: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
426: $env{'user.name'}).
1.33 banghart 427: '/userfiles/portfolio';
1.38 banghart 428: # Fixme --- Move the checking for existing file to LOND error return
1.82 albertel 429: my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
430: $env{'user.domain'},
431: $env{'user.name'},$portfolio_root);
1.34 banghart 432: my $found_file = 0;
1.76 banghart 433: my $locked_file = 0;
1.33 banghart 434: foreach my $line (@dir_list) {
1.76 banghart 435: my ($file_name)=split(/\&/,$line,2);
436: if ($file_name eq $fname){
1.33 banghart 437: $found_file = 1;
1.82 albertel 438: if (&Apache::lonnet::is_locked($env{'form.currentpath'}.$file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') {
1.76 banghart 439: $locked_file = 1;
440: }
1.33 banghart 441: }
442: }
1.82 albertel 443: my $current_disk_usage = &Apache::lonnet::diskusage($env{'user.domain'}, $env{'user.name'},$portfolio_root);
1.87 albertel 444: if (($current_disk_usage + $filesize) > $disk_quota){
1.86 albertel 445: $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.'.
1.38 banghart 446: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1.76 banghart 447: $r->print(&done('Back'));
1.38 banghart 448: }
1.76 banghart 449: elsif ($found_file){
450: if ($locked_file){
1.82 albertel 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>'.
1.76 banghart 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 {
1.82 albertel 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'});
1.76 banghart 457: $r->print(&done('Back'));
458: }
1.33 banghart 459: } else {
460: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1.82 albertel 461: 'portfolio'.$env{'form.currentpath'});
1.33 banghart 462: if ($result !~ m|^/uploaded/|) {
1.34 banghart 463: $r->print('<font color="red"> An errror occured ('.$result.
464: ') while trying to upload '.&display_file().'</font><br />');
1.76 banghart 465: $r->print(&done('Back'));
466: } else {
467: $r->print(&done());
1.33 banghart 468: }
1.25 albertel 469: }
470: }
1.80 banghart 471: sub lock_info {
472: my ($r) = @_;
1.84 banghart 473: my %current_permissions = &Apache::lonnet::dump('file_permissions',$env{'user.domain'},$env{'user.name'});
474: my $file_name = $env{'form.lockinfo'};
1.85 banghart 475: foreach my $key(keys(%current_permissions)) {
1.84 banghart 476: if ($file_name eq $key) {
1.85 banghart 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: }
1.84 banghart 487: }
488: }
1.85 banghart 489: $r->print(&done('Back'));
1.80 banghart 490: return 'ok';
491: }
1.25 albertel 492: sub createdir {
493: my ($r)=@_;
1.82 albertel 494: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 495: if ($newdir eq '') {
1.37 banghart 496: $r->print('<font color="red">'.
497: &mt("Error: no directory name was provided.").
498: '</font><br />');
499: $r->print(&done());
500: return;
1.28 albertel 501: }
1.82 albertel 502: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
503: $env{'user.name'}).
1.37 banghart 504: '/userfiles/portfolio';
1.82 albertel 505: my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
506: $env{'user.domain'},
507: $env{'user.name'},$portfolio_root);
1.37 banghart 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 {
1.82 albertel 519: my $result=&Apache::lonnet::mkdiruserfile($env{'user.name'},
520: $env{'user.domain'},'portfolio'.$env{'form.currentpath'}.$newdir);
1.37 banghart 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: }
1.24 albertel 525: }
1.82 albertel 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>");
1.67 banghart 528: }
1.24 albertel 529: $r->print(&done());
530: }
531:
532: sub handler {
533: # this handles file management
534: my $r = shift;
1.82 albertel 535: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
536: $env{'user.name'}).
1.33 banghart 537: '/userfiles/portfolio';
1.73 banghart 538: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.80 banghart 539: ['selectfile','currentpath','meta','lockinfo',
1.83 banghart 540: 'currentfile','action','fieldname','mode','rename','continue']);
1.24 albertel 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
1.75 albertel 545: my $html=&Apache::lonxml::xmlbegin();
546: $r->print($html.'<head><title>'.
1.24 albertel 547: &mt('Portfolio Manager').
1.74 banghart 548: "</title></head>\n");
1.82 albertel 549: if ($env{"form.mode"} eq 'selectfile'){
1.74 banghart 550: $r->print(&Apache::loncommon::bodytag('Portfolio Manager',undef,undef,1));
551: } else {
552: $r->print(&Apache::loncommon::bodytag('Portfolio Manager'));
553: }
1.24 albertel 554: $r->rflush();
1.88 albertel 555: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.40 banghart 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: }
1.82 albertel 560: if ($env{'form.meta'}) {
1.70 banghart 561: &open_form($r);
1.82 albertel 562: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1.70 banghart 563: $r->print('Edit the meta data<br />');
564: &close_form($r);
565: }
1.82 albertel 566: if ($env{'form.store'}) {
1.70 banghart 567: }
568:
1.82 albertel 569: if ($env{'form.uploaddoc.filename'}) {
1.24 albertel 570: &upload($r);
1.82 albertel 571: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.27 albertel 572: &delete_confirmed($r);
1.82 albertel 573: } elsif ($env{'form.action'} eq 'delete') {
1.27 albertel 574: &delete($r);
1.82 albertel 575: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.31 albertel 576: &delete_dir_confirmed($r);
1.82 albertel 577: } elsif ($env{'form.action'} eq 'deletedir'){
1.31 albertel 578: &delete_dir($r);
1.82 albertel 579: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.27 albertel 580: &rename_confirmed($r);
1.82 albertel 581: } elsif ($env{'form.rename'}) {
582: $env{'form.selectfile'} = $env{'form.rename'};
583: $env{'form.action'} = 'rename';
1.24 albertel 584: &rename($r);
1.82 albertel 585: } elsif ($env{'form.createdir'}) {
1.25 albertel 586: &createdir($r);
1.82 albertel 587: } elsif ($env{'form.lockinfo'}) {
1.80 banghart 588: &lock_info($r);
1.24 albertel 589: } else {
590: my $current_path='/';
1.82 albertel 591: if ($env{'form.currentpath'}) {
592: $current_path = $env{'form.currentpath'};
1.24 albertel 593: }
1.43 banghart 594: my @dir_list=&Apache::lonnet::dirlist($current_path,
1.82 albertel 595: $env{'user.domain'},
596: $env{'user.name'},$portfolio_root);
1.46 albertel 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 '/'){
1.82 albertel 602: &Apache::lonnet::mkdiruserfile($env{'user.name'},
603: $env{'user.domain'},'portfolio');
1.46 albertel 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,
1.82 albertel 613: $env{'user.domain'},
614: $env{'user.name'},$portfolio_root);
1.43 banghart 615: }
1.46 albertel 616: # need to know if directory is empty so it can be removed if desired
617: my $is_empty=(@dir_list == 2);
1.48 banghart 618: &display_common($r,$current_path,$is_empty,\@dir_list);
1.77 banghart 619: &display_directory($r,$current_path,$is_empty,\@dir_list);
1.46 albertel 620: $r->print("</body>\n</html>\n");
621: return OK;
1.30 banghart 622: }
1.2 banghart 623: }
1.1 banghart 624: 1;
625: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>