Annotation of loncom/interface/portfolio.pm, revision 1.85
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)){
1.85 ! banghart 357: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83 banghart 358: }
1.62 banghart 359: } else {
360: #empty the file for a fresh start
1.83 banghart 361: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 362: }
1.82 albertel 363: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 364: my $java_files = join ",", @files;
365: if ($java_files) {
366: $java_files.=',';
1.60 banghart 367: }
1.63 banghart 368: my $javascript =(<<ENDSMP);
1.48 banghart 369: <script language='javascript'>
370: function finishSelect() {
1.62 banghart 371: ENDSMP
1.63 banghart 372: $javascript .= 'fileList = "'.$java_files.'";';
373: $javascript .= (<<ENDSMP);
1.49 banghart 374: for (i=0;i<document.forms.checkselect.length;i++) {
375: if (document.forms.checkselect[i].checked){
1.54 banghart 376: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 377: }
378: }
379: opener.document.forms.lonhomework.
380: ENDSMP
1.82 albertel 381: $javascript .= $env{'form.fieldname'};
1.63 banghart 382: $javascript .= (<<ENDSMP);
1.49 banghart 383: .value=fileList;
1.48 banghart 384: self.close();
385: }
386: </script>
387: ENDSMP
1.63 banghart 388: $r->print($javascript);
1.47 banghart 389: $r->print("<h1>Select portfolio files</h1>
390: Check as many as you wish in response to the essay problem.<br />");
1.61 banghart 391: $r->print("<strong>Files selected from other directories:</strong><br />");
1.82 albertel 392: foreach (&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'})) {
1.60 banghart 393: $r->print($_."<br />");
394: }
1.47 banghart 395: }
1.24 albertel 396: sub upload {
397: my ($r)=@_;
1.82 albertel 398: my $fname=$env{'form.uploaddoc.filename'};
399: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1.38 banghart 400: my $disk_quota = 20000; # expressed in k
1.34 banghart 401: $fname=&Apache::lonnet::clean_filename($fname);
1.82 albertel 402: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
403: $env{'user.name'}).
1.33 banghart 404: '/userfiles/portfolio';
1.38 banghart 405: # Fixme --- Move the checking for existing file to LOND error return
1.82 albertel 406: my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
407: $env{'user.domain'},
408: $env{'user.name'},$portfolio_root);
1.34 banghart 409: my $found_file = 0;
1.76 banghart 410: my $locked_file = 0;
1.33 banghart 411: foreach my $line (@dir_list) {
1.76 banghart 412: my ($file_name)=split(/\&/,$line,2);
413: if ($file_name eq $fname){
1.33 banghart 414: $found_file = 1;
1.82 albertel 415: if (&Apache::lonnet::is_locked($env{'form.currentpath'}.$file_name,$env{'user.domain'},$env{'user.name'} ) eq 'true') {
1.76 banghart 416: $locked_file = 1;
417: }
1.33 banghart 418: }
419: }
1.82 albertel 420: my $current_disk_usage = &Apache::lonnet::diskusage($env{'user.domain'}, $env{'user.name'},$portfolio_root);
1.69 banghart 421: if ((($current_disk_usage/1000) + $filesize) > $disk_quota){
1.38 banghart 422: $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'.
423: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1.76 banghart 424: $r->print(&done('Back'));
1.38 banghart 425: }
1.76 banghart 426: elsif ($found_file){
427: if ($locked_file){
1.82 albertel 428: $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 429: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
430: $r->print(&done('Back'));
431: } else {
1.82 albertel 432: $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>'.
433: '<br />To upload, rename or delete existing '.$fname.' in portfolio'.$env{'form.currentpath'});
1.76 banghart 434: $r->print(&done('Back'));
435: }
1.33 banghart 436: } else {
437: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1.82 albertel 438: 'portfolio'.$env{'form.currentpath'});
1.33 banghart 439: if ($result !~ m|^/uploaded/|) {
1.34 banghart 440: $r->print('<font color="red"> An errror occured ('.$result.
441: ') while trying to upload '.&display_file().'</font><br />');
1.76 banghart 442: $r->print(&done('Back'));
443: } else {
444: $r->print(&done());
1.33 banghart 445: }
1.25 albertel 446: }
447: }
1.80 banghart 448: sub lock_info {
449: my ($r) = @_;
1.84 banghart 450: my %current_permissions = &Apache::lonnet::dump('file_permissions',$env{'user.domain'},$env{'user.name'});
451: my $file_name = $env{'form.lockinfo'};
1.85 ! banghart 452: foreach my $key(keys(%current_permissions)) {
1.84 banghart 453: if ($file_name eq $key) {
1.85 ! banghart 454: foreach my $array_item (@{$current_permissions{$key}}) {
! 455: if (ref($array_item)) {
! 456: $r->print('<strong>'.$key.'</strong> was submitted in response to problem: <strong>'.
! 457: &Apache::lonnet::gettitle($$array_item[0]).'</strong><br />');
! 458: my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
! 459: $r->print('In the course: <strong>'.$course_description{'description'}.'</strong><br />');
! 460: # $r->print('the third is '.$$array_item[2].'<br>');
! 461: # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
! 462: }
! 463: }
1.84 banghart 464: }
465: }
1.85 ! banghart 466: $r->print(&done('Back'));
1.80 banghart 467: return 'ok';
468: }
1.25 albertel 469: sub createdir {
470: my ($r)=@_;
1.82 albertel 471: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 472: if ($newdir eq '') {
1.37 banghart 473: $r->print('<font color="red">'.
474: &mt("Error: no directory name was provided.").
475: '</font><br />');
476: $r->print(&done());
477: return;
1.28 albertel 478: }
1.82 albertel 479: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
480: $env{'user.name'}).
1.37 banghart 481: '/userfiles/portfolio';
1.82 albertel 482: my @dir_list=&Apache::lonnet::dirlist($env{'form.currentpath'},
483: $env{'user.domain'},
484: $env{'user.name'},$portfolio_root);
1.37 banghart 485: my $found_file = 0;
486: foreach my $line (@dir_list) {
487: my ($filename)=split(/\&/,$line,2);
488: if ($filename eq $newdir){
489: $found_file = 1;
490: }
491: }
492: if ($found_file){
493: $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
494: ' </strong>a file or directory by that name already exists.</font><br />');
495: } else {
1.82 albertel 496: my $result=&Apache::lonnet::mkdiruserfile($env{'user.name'},
497: $env{'user.domain'},'portfolio'.$env{'form.currentpath'}.$newdir);
1.37 banghart 498: if ($result ne 'ok') {
499: $r->print('<font color="red"> An errror occured ('.$result.
500: ') while trying to create a new directory '.&display_file().'</font><br />');
501: }
1.24 albertel 502: }
1.82 albertel 503: if ($newdir ne $env{'form.newdir'}) {
504: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
1.67 banghart 505: }
1.24 albertel 506: $r->print(&done());
507: }
508:
509: sub handler {
510: # this handles file management
511: my $r = shift;
1.82 albertel 512: my $portfolio_root = &Apache::loncommon::propath($env{'user.domain'},
513: $env{'user.name'}).
1.33 banghart 514: '/userfiles/portfolio';
1.73 banghart 515: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.80 banghart 516: ['selectfile','currentpath','meta','lockinfo',
1.83 banghart 517: 'currentfile','action','fieldname','mode','rename','continue']);
1.24 albertel 518: &Apache::loncommon::no_cache($r);
519: &Apache::loncommon::content_type($r,'text/html');
520: $r->send_http_header;
521: # Give the LON-CAPA page header
1.75 albertel 522: my $html=&Apache::lonxml::xmlbegin();
523: $r->print($html.'<head><title>'.
1.24 albertel 524: &mt('Portfolio Manager').
1.74 banghart 525: "</title></head>\n");
1.82 albertel 526: if ($env{"form.mode"} eq 'selectfile'){
1.74 banghart 527: $r->print(&Apache::loncommon::bodytag('Portfolio Manager',undef,undef,1));
528: } else {
529: $r->print(&Apache::loncommon::bodytag('Portfolio Manager'));
530: }
1.24 albertel 531: $r->rflush();
1.82 albertel 532: if (($env{'form.storeupl'} eq 'Upload') & (!$env{'form.uploaddoc.filename'})){
1.40 banghart 533: $r->print('<font color="red"> No file was selected to upload.'.
534: 'To upload a file, click <strong>Browse...</strong>'.
535: ', select a file, then click <strong>Upload</strong>,</font>');
536: }
1.82 albertel 537: if ($env{'form.meta'}) {
1.70 banghart 538: &open_form($r);
1.82 albertel 539: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1.70 banghart 540: $r->print('Edit the meta data<br />');
541: &close_form($r);
542: }
1.82 albertel 543: if ($env{'form.store'}) {
1.70 banghart 544: }
545:
1.82 albertel 546: if ($env{'form.uploaddoc.filename'}) {
1.24 albertel 547: &upload($r);
1.82 albertel 548: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.27 albertel 549: &delete_confirmed($r);
1.82 albertel 550: } elsif ($env{'form.action'} eq 'delete') {
1.27 albertel 551: &delete($r);
1.82 albertel 552: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.31 albertel 553: &delete_dir_confirmed($r);
1.82 albertel 554: } elsif ($env{'form.action'} eq 'deletedir'){
1.31 albertel 555: &delete_dir($r);
1.82 albertel 556: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.27 albertel 557: &rename_confirmed($r);
1.82 albertel 558: } elsif ($env{'form.rename'}) {
559: $env{'form.selectfile'} = $env{'form.rename'};
560: $env{'form.action'} = 'rename';
1.24 albertel 561: &rename($r);
1.82 albertel 562: } elsif ($env{'form.createdir'}) {
1.25 albertel 563: &createdir($r);
1.82 albertel 564: } elsif ($env{'form.lockinfo'}) {
1.80 banghart 565: &lock_info($r);
1.24 albertel 566: } else {
567: my $current_path='/';
1.82 albertel 568: if ($env{'form.currentpath'}) {
569: $current_path = $env{'form.currentpath'};
1.24 albertel 570: }
1.43 banghart 571: my @dir_list=&Apache::lonnet::dirlist($current_path,
1.82 albertel 572: $env{'user.domain'},
573: $env{'user.name'},$portfolio_root);
1.46 albertel 574: if ($dir_list[0] eq 'no_such_dir'){
575: # two main reasons for this:
576: # 1) never been here, so directory structure not created
577: # 2) back-button navigation after deleting a directory
578: if ($current_path eq '/'){
1.82 albertel 579: &Apache::lonnet::mkdiruserfile($env{'user.name'},
580: $env{'user.domain'},'portfolio');
1.46 albertel 581: } else {
582: # some directory that snuck in get rid of the directory
583: # from the recent pulldown, just in case
584: &Apache::lonhtmlcommon::remove_recent('portfolio',
585: [$current_path]);
586: $current_path = '/'; # force it back to the root
587: }
588: # now grab the directory list again, for the first time
589: @dir_list=&Apache::lonnet::dirlist($current_path,
1.82 albertel 590: $env{'user.domain'},
591: $env{'user.name'},$portfolio_root);
1.43 banghart 592: }
1.46 albertel 593: # need to know if directory is empty so it can be removed if desired
594: my $is_empty=(@dir_list == 2);
1.48 banghart 595: &display_common($r,$current_path,$is_empty,\@dir_list);
1.77 banghart 596: &display_directory($r,$current_path,$is_empty,\@dir_list);
1.46 albertel 597: $r->print("</body>\n</html>\n");
598: return OK;
1.30 banghart 599: }
1.2 banghart 600: }
1.1 banghart 601: 1;
602: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>