File:
[LON-CAPA] /
loncom /
interface /
portfolio.pm
Revision
1.103:
download - view:
text,
annotated -
select for diffs
Wed Jun 7 21:15:01 2006 UTC (18 years ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
file_permissions.db now stores information for each file as an array of arrays and a hash. In the hash, keys can either be accesscount or access. For key = access value is an anonymous hash containing key=value pairs defining access controls. For key = accesscount, value is a scalar (integer to be used when creating the next accesscontrol). Documentation added.
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:
24: package Apache::portfolio;
25: use strict;
26: use Apache::Constants qw(:common :http);
27: use Apache::loncommon;
28: use Apache::lonnet;
29: use Apache::lontexconvert;
30: use Apache::lonfeedback;
31: use Apache::lonlocal;
32: use Apache::lonnet;
33: use Apache::longroup;
34: use lib '/home/httpd/lib/perl';
35: use LONCAPA;
36:
37: # receives a file name and path stub from username/userfiles/portfolio/
38: # returns an anchor tag consisting encoding filename and currentpath
39: sub make_anchor {
40: my ($url, $filename, $current_path, $current_mode, $field_name,
41: $continue_select,$group) = @_;
42: if ($continue_select ne 'true') {$continue_select = 'false'};
43: my $anchor = '<a href="'.$url.'?selectfile='.$filename.'¤tpath='.$current_path.'&mode='.$current_mode.'&continue='.$continue_select.'&fieldname='.$field_name;
44: if (defined($group)) {
45: $anchor .= '&group='.$group;
46: }
47: $anchor .= '">'.$filename.'</a>';
48: return $anchor;
49: }
50: my $dirptr=16384;
51: sub display_common {
52: my ($r,$url,$current_path,$is_empty,$dir_list,$group)=@_;
53: my $groupitem;
54: my $namespace = &get_namespace($group);
55: my $port_path = &get_port_path($group);
56: if (defined($group)) {
57: $groupitem = '<input type="hidden" name="group" value="'.$group.'" />';
58: }
59: my $iconpath= $r->dir_config('lonIconsURL') . "/";
60: my %text=&Apache::lonlocal::texthash('upload' => 'Upload',
61: 'upload_label' =>
62: 'Upload file to current directory:',
63: 'createdir' => 'Create Subdirectory',
64: 'createdir_label' =>
65: 'Create subdirectory in current directory:');
66: $r->print(<<"TABLE");
67: <table border="0" cellspacing="2" cellpadding="2">
68: <form method="post" enctype="multipart/form-data">
69: <tr valign="middle">
70: <td bgcolor="#ccddaa" align="right">
71: $text{'upload_label'}
72: </td>
73: <td bgcolor="#ccddaa" align="left">$groupitem
74: <input name="uploaddoc" type="file" />
75: <input type="hidden" name="currentpath" value="$current_path" />
76: <input type="hidden" name="action" value="$env{"form.action"}" />
77: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
78: <input type="hidden" name="mode" value="$env{"form.mode"}" />
79: <input type="submit" name="storeupl" value="$text{'upload'}" />
80: </td>
81: </tr>
82: </form>
83: <form method="post">
84: <tr>
85: <td bgcolor="#ccddaa" align="right">
86: $text{'createdir_label'}
87: </td>
88: <td bgcolor="#ccddaa" align="left">
89: <input name="newdir" type="input" />$groupitem
90: <input type="hidden" name="currentpath" value="$current_path" />
91: <input type="hidden" name="action" value="$env{"form.action"}" />
92: <input type="hidden" name="fieldname" value="$env{"form.fieldname"}" />
93: <input type="hidden" name="mode" value="$env{"form.mode"}" />
94: <input type="submit" name="createdir" value="$text{'createdir'}" />
95: </td>
96: </tr>
97: </form>
98: </table>
99: TABLE
100: my @tree = split (/\//,$current_path);
101: $r->print('<font size="+2">'.&make_anchor($url,$port_path,'/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"},$group).'/');
102: if (@tree > 1){
103: my $newCurrentPath = '';
104: for (my $i = 1; $i< @tree; $i++){
105: $newCurrentPath .= $tree[$i].'/';
106: $r->print(&make_anchor($url,$tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"},$group).'/');
107: }
108: }
109: $r->print('</font>');
110: &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
111: $r->print('<br /><form method=post action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"});
112: if (defined($group)) {
113: $r->print('&group='.$group);
114: }
115: $r->print('">'.
116: &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
117: 'this.form.submit();'));
118: $r->print("</form>");
119: }
120: sub display_directory {
121: my ($r,$url,$current_path,$is_empty,$dir_list,$group)=@_;
122: my $iconpath= $r->dir_config('lonIconsURL') . "/";
123: my ($groupitem,$groupecho);
124: my $display_out;
125: my $select_mode;
126: my $checked_files;
127: my $port_path = &get_port_path($group);
128: my ($uname,$udom) = &get_name_dom($group);
129: if (defined($group)) {
130: $groupitem = '<input type="hidden" name="group" value="'.$group.'" />';
131: $groupecho = '&group='.$group;
132: }
133: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
134: $uname);
135: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
136: $current_permissions,$group);
137: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
138: my $now = time;
139: if ($env{"form.mode"} eq 'selectfile'){
140: &select_files($r);
141: $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
142: $select_mode = 'true';
143: }
144: if ($is_empty && ($current_path ne '/')) {
145: $display_out = '<form method="post" action="'.$url.'">'.$groupitem.
146: '<input type="hidden" name="action" value="deletedir" />'.
147: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
148: '<input type="hidden" name="selectfile" value="" />'.
149: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
150: '</form>';
151:
152: $r->print($display_out);
153: return;
154: }
155: if ($select_mode eq 'true') {
156: $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
157: '<tr><th>Select</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
158: $r->print('<form method="post" name="checkselect" action="'.$url.'">');
159: } else {
160: $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
161: '<tr><th colspan="2">Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th><th>Current Access Status</th></tr>');
162: $r->print('<form method="post" action="'.$url.'">');
163: }
164: if (defined($group)) {
165: $r->print("\n".$groupitem."\n");
166: }
167: my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
168: my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
169: foreach my $line (sort
170: {
171: my ($afile)=split('&',$a,2);
172: my ($bfile)=split('&',$b,2);
173: return (lc($afile) cmp lc($bfile));
174: } (@$dir_list)) {
175: #$strip holds directory/file name
176: #$dom
177: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
178: $filename =~ s/\s+$//;
179: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
180: if ($dirptr&$testdir) {
181: if ($select_mode eq 'true'){
182: $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
183: } else {
184: $r->print('<tr bgcolor="#FFAA99"><td colspan="2"><img src="'.$iconpath.'folder_closed.gif"></td>');
185: }
186: $r->print('<td>Go to ...</td>');
187: $r->print('<td>'.&make_anchor($url,$filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'},$group).'</td>');
188: $r->print('</tr>');
189: } else {
190: $r->print('<tr bgcolor="#CCCCFF">');
191: my $fullpath = $current_path.$filename;
192: $fullpath = &prepend_group($fullpath,$group);
193: if ($select_mode eq 'true'){
194: $r->print('<td><input type="checkbox" name="checkfile" value="'.$filename.'"');
195: if ($$checked_files{$filename} eq 'selected') {
196: $r->print("CHECKED");
197: }
198: $r->print('></td>');
199: } else {
200: if (exists $locked_files{$fullpath}) {
201: $r->print('<td colspan="2"><a href="'.$url.'?lockinfo='.$current_path.$filename.$groupecho.'">Locked</a></td>');
202: } else {
203: my $cat='<img alt="'.&mt('Catalog Information').
204: '" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.gif').'" />';
205: $r->print('<td><input type="checkbox" name="selectfile" value="'.$filename.'" />
206: <a href="'.$url.'?rename='.$filename.'&currentpath='.$current_path.$groupecho.'">Rename</a></td>
207: <td><a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>
208: </td>');
209: }
210: }
211: my $curr_access;
212: my $pub_access = 0;
213: foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
214: my ($scope,$end,$start) = ($key =~ /^\d+:(\w+)_(\d*)_?(\d*)$/);
215: if (($now > $start) && (!$end || $end > $now)) {
216: if ($scope eq 'public') {
217: $pub_access = 1;
218: last;
219: }
220: }
221: }
222: if (!$pub_access) {
223: $curr_access = 'Private'
224: } elsif ($pub_access) {
225: $curr_access = 'Public';
226: }
227: $r->print('<td><img src="'.&Apache::loncommon::icon($filename).'"></td>');
228: $r->print('<td><a href="'.$href_location.$filename.'">'.
229: $filename.'</a></td>');
230: $r->print('<td>'.$size.'</td>');
231: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
232: $r->print('<td><nobr>'.&mt($curr_access).' '.
233: '<a href="'.$url.'?access='.$filename.
234: '&currentpath='.$current_path.$groupecho.
235: '">'.&mt('View/Change').'</a></nobr></td>');
236: $r->print('</tr>');
237: }
238: }
239: }
240: if ($select_mode eq 'true') {
241: $r->print('</table>
242: <input type="hidden" name="continue" value="true">
243: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'">
244: <input type="hidden" name="mode" value="selectfile">
245: <input type="submit" name="submit" value="Select checked files, and continue selecting." /><br />
246: <input type="button" name="doit" onClick= "finishSelect();" value="Select checked files, and close window" />
247: <input type="hidden" name="currentpath" value="'.$current_path.'" />
248: </form>');
249: } else {
250: $r->print('</table>
251: <input type="submit" name="doit" value="Delete Checked Files" />
252: <input type="hidden" name="action" value="delete" />
253: <input type="hidden" name="currentpath" value="'.$current_path.'" />
254: </form>');
255: }
256: }
257:
258: sub open_form {
259: my ($r,$url)=@_;
260: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
261: $r->print('<form name="portform" method="post" action="'.$url.'">');
262: $r->print('<input type="hidden" name="action" value="'.
263: $env{'form.action'}.'" />');
264: $r->print('<input type="hidden" name="confirmed" value="1" />');
265: foreach (@files) {
266: $r->print('<input type="hidden" name="selectfile" value="'.
267: $_.'" />');
268: }
269: $r->print('<input type="hidden" name="currentpath" value="'.
270: $env{'form.currentpath'}.'" />');
271: }
272:
273: sub close_form {
274: my ($r,$url,$group)=@_;
275: $r->print('<p><input type="submit" value="'.&mt('Continue').'" />');
276: if (defined($group)) {
277: $r->print("\n".'<input type="hidden" name="group" value="'.
278: $group.'" />');
279: }
280: $r->print('</p></form>');
281: $r->print('<form action="'.$url.'" method="POST">
282: <p>
283: <input type="hidden" name="currentpath" value="'.
284: $env{'form.currentpath'}.'" />');
285: if (defined($group)) {
286: $r->print("\n".'<input type="hidden" name="group" value="'.
287: $group.'" />');
288: }
289: $r->print("\n".' <input type="submit" value="'.&mt('Cancel').'" />
290: </p></form>');
291: }
292:
293: sub display_file {
294: my ($path,$filename)=@_;
295: my $display_file_text;
296: if (!defined($path)) { $path=$env{'form.currentpath'}; }
297: if (!defined($filename)) {
298: $filename=$env{'form.selectfile'};
299: $display_file_text = '<tt>'.$path.$filename.'</tt>';
300: } elsif (ref($filename) eq "ARRAY") {
301: foreach (@$filename) {
302: $display_file_text .= '<tt>'.$path.$_.'</tt><br />';
303: }
304: } elsif (ref($filename) eq "SCALAR") {
305: $display_file_text = '<tt>'.$path.$filename.'</tt>';
306: }
307: return $display_file_text;
308: }
309:
310: sub done {
311: my ($message,$url,$group)=@_;
312: unless (defined $message) {
313: $message='Done';
314: }
315: my $result = '<h3><a href="'.$url.'?currentpath='.
316: $env{'form.currentpath'}.
317: '&fieldname='.$env{'form.fieldname'}.
318: '&mode='.$env{'form.mode'};
319: if (defined($group)) {
320: $result .= '&group='.$group;
321: }
322: $result .= '">'.&mt($message).'</a></h3>';
323: return $result;
324: }
325:
326: sub delete {
327: my ($r,$url,$group)=@_;
328: my @check;
329: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
330: $file_name = &prepend_group($file_name,$group);
331: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
332: my ($uname,$udom) = &get_name_dom($group);
333: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
334: $r->print ("The file is locked and cannot be deleted.<br />");
335: $r->print(&done('Back',$url,$group));
336: } else {
337: if (scalar(@files)) {
338: &open_form($r,$url);
339: $r->print('<p>'.&mt('Delete').' '.&display_file(undef,\@files).'?</p>');
340: &close_form($r,$url,$group);
341: } else {
342: $r->print("No file was checked to delete.<br />");
343: $r->print(&done(undef,$url,$group));
344: }
345: }
346: }
347:
348: sub delete_confirmed {
349: my ($r,$url,$group)=@_;
350: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
351: my $result;
352: my ($uname,$udom) = &get_name_dom($group);
353: my $port_path = &get_port_path($group);
354: foreach my $delete_file (@files) {
355: $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
356: $env{'form.currentpath'}.
357: $delete_file);
358: if ($result ne 'ok') {
359: $r->print('<font color="red"> An error occured ('.$result.
360: ') while trying to delete '.&display_file(undef, $delete_file).'</font><br />');
361: }
362: }
363: $r->print(&done(undef,$url,$group));
364: }
365:
366: sub delete_dir {
367: my ($r,$url,$group)=@_;
368: &open_form($r,$url);
369: $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
370: &close_form($r,$url,$group);
371: }
372:
373: sub delete_dir_confirmed {
374: my ($r,$url,$group)=@_;
375: my $directory_name = $env{'form.currentpath'};
376: $directory_name =~ s|/$||; # remove any trailing slash
377: my ($uname,$udom) = &get_name_dom($group);
378: my $namespace = &get_namespace($group);
379: my $port_path = &get_port_path($group);
380: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
381: $directory_name);
382:
383: if ($result ne 'ok') {
384: $r->print('<font color="red"> An error occured (dir) ('.$result.
385: ') while trying to delete '.$directory_name.'</font><br />');
386: } else {
387: # now remove from recent
388: # $r->print('<br /> removing '.$directory_name.'<br /');
389: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
390: my @dirs = split m!/!, $directory_name;
391:
392: # $directory_name =~ m/^(\/*\/)(\/*.)$/;
393: $directory_name='/';
394: for (my $i=1; $i < (@dirs - 1); $i ++){
395: $directory_name .= $dirs[$i].'/';
396: }
397: $env{'form.currentpath'} = $directory_name;
398: }
399: $r->print(&done(undef,$url,$group));
400: }
401:
402: sub rename {
403: my ($r,$url,$group)=@_;
404: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
405: my ($uname,$udom) = &get_name_dom($group);
406: $file_name = &prepend_group($file_name,$group);
407: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
408: $r->print ("The file is locked and cannot be renamed.<br />");
409: $r->print(&done(undef,$url,$group));
410: } else {
411: &open_form($r,$url);
412: $r->print('<p>'.&mt('Rename').' '.&display_file().' to
413: <input name="filenewname" type="input" size="50" />?</p>');
414: &close_form($r,$url,$group);
415: }
416: }
417:
418: sub rename_confirmed {
419: my ($r,$url,$group)=@_;
420: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
421: my ($uname,$udom) = &get_name_dom($group);
422: my $port_path = &get_port_path($group);
423: if ($filenewname eq '') {
424: $r->print('<font color="red">'.
425: &mt("Error: no valid filename was provided to rename to.").
426: '</font><br />');
427: $r->print(&done(undef,$url,$group));
428: return;
429: }
430: my $result=
431: &Apache::lonnet::renameuserfile($uname,$udom,
432: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
433: $port_path.$env{'form.currentpath'}.$filenewname);
434: if ($result ne 'ok') {
435: $r->print('<font color="red"> An errror occured ('.$result.
436: ') while trying to rename '.&display_file().' to '.
437: &display_file(undef,$filenewname).'</font><br />');
438: }
439: if ($filenewname ne $env{'form.filenewname'}) {
440: $r->print("The new file name was changed from:<br /><strong>".$env{'form.filenewname'}."</strong> to <strong>$filenewname </strong>");
441: }
442: $r->print(&done(undef,$url,$group));
443: }
444:
445: sub select_files {
446: my ($r,$group)=@_;
447: if ($env{'form.continue'} eq 'true') {
448: # here we update the selections for the currentpath
449: # eventually, have to handle removing those not checked, but . . .
450: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
451: if (scalar(@items)){
452: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
453: }
454: } else {
455: #empty the file for a fresh start
456: &Apache::lonnet::clear_selected_files($env{'user.name'});
457: }
458: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
459: my $java_files = join ",", @files;
460: if ($java_files) {
461: $java_files.=',';
462: }
463: my $javascript =(<<ENDSMP);
464: <script language='javascript'>
465: function finishSelect() {
466: ENDSMP
467: $javascript .= 'fileList = "'.$java_files.'";';
468: $javascript .= (<<ENDSMP);
469: for (i=0;i<document.forms.checkselect.length;i++) {
470: if (document.forms.checkselect[i].checked){
471: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
472: }
473: }
474: opener.document.forms.lonhomework.
475: ENDSMP
476: $javascript .= $env{'form.fieldname'};
477: $javascript .= (<<ENDSMP);
478: .value=fileList;
479: self.close();
480: }
481: </script>
482: ENDSMP
483: $r->print($javascript);
484: $r->print("<h1>Select portfolio files</h1>
485: Check as many as you wish in response to the problem.<br />");
486: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
487: if (@otherfiles) {
488: $r->print("<strong>Files selected from other directories:</strong><br />");
489: foreach my $file (@otherfiles) {
490: $r->print($file."<br />");
491: }
492: }
493: }
494: sub upload {
495: my ($r,$url,$group)=@_;
496: my $fname=$env{'form.uploaddoc.filename'};
497: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
498: my $disk_quota = 20000; # expressed in k
499: $fname=&Apache::lonnet::clean_filename($fname);
500:
501: my $portfolio_root=&get_portfolio_root($group);
502: my ($uname,$udom) = &get_name_dom($group);
503: my $port_path = &get_port_path($group);
504: # Fixme --- Move the checking for existing file to LOND error return
505: my @dir_list=&get_dir_list($portfolio_root,$group);
506: my $found_file = 0;
507: my $locked_file = 0;
508: foreach my $line (@dir_list) {
509: my ($file_name)=split(/\&/,$line,2);
510: if ($file_name eq $fname){
511: $file_name = $env{'form.currentpath'}.$file_name;
512: $file_name = &prepend_group($file_name,$group);
513: $found_file = 1;
514: if (defined($group)) {
515: $file_name = $group.'/'.$file_name;
516: }
517: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
518: $locked_file = 1;
519: }
520: }
521: }
522: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
523: if (($current_disk_usage + $filesize) > $disk_quota){
524: $r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.'.
525: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
526: $r->print(&done('Back',$url,$group));
527: }
528: elsif ($found_file){
529: if ($locked_file){
530: $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a <strong>locked</strong> file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></font>'.
531: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
532: $r->print(&done('Back',$url,$group));
533: } else {
534: $r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$port_path.$env{'form.currentpath'}.'</strong></font>'.
535: '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
536: $r->print(&done('Back',$url,$group));
537: }
538: } else {
539: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
540: $port_path.$env{'form.currentpath'});
541: if ($result !~ m|^/uploaded/|) {
542: $r->print('<font color="red"> An errror occured ('.$result.
543: ') while trying to upload '.&display_file().'</font><br />');
544: $r->print(&done('Back',$url,$group));
545: } else {
546: $r->print(&done(undef,$url,$group));
547: }
548: }
549: }
550: sub lock_info {
551: my ($r,$url,$group) = @_;
552: my ($uname,$udom) = &get_name_dom($group);
553: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
554: $uname);
555: my $file_name = $env{'form.lockinfo'};
556: $file_name = &prepend_group($file_name,$group);
557: if (defined($file_name) && defined($$current_permissions{$file_name})) {
558: foreach my $array_item (@{$$current_permissions{$file_name}}) {
559: if (ref($array_item) eq 'ARRAY') {
560: my $filetext;
561: if (defined($group)) {
562: $filetext = '<strong>'.$env{'form.lockinfo'}.
563: '</strong> (group: '.$group.')';
564: } else {
565: $filetext = '<strong>'.$file_name.'</strong>';
566: }
567: $r->print(&mt('[_1] was submitted in response to problem: ',
568: $filetext).
569: '<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
570: '</strong><br />');
571: my %course_description = &Apache::lonnet::coursedescription($$array_item[1]);
572: $r->print(&mt('In the course: <strong>[_1]</strong><br />',
573: $course_description{'description'}));
574: # $r->print('the third is '.$$array_item[2].'<br>');
575: # $r->print("item is $$array_item[0]<br> and $$array_item[0]");
576: }
577: }
578: }
579: $r->print(&done('Back',$url,$group));
580: return 'ok';
581: }
582: sub createdir {
583: my ($r,$url,$group)=@_;
584: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
585: if ($newdir eq '') {
586: $r->print('<font color="red">'.
587: &mt("Error: no directory name was provided.").
588: '</font><br />');
589: $r->print(&done(undef,$url,$group));
590: return;
591: }
592: my $portfolio_root = &get_portfolio_root($group);
593: my @dir_list=&get_dir_list($portfolio_root,$group);
594: my $found_file = 0;
595: foreach my $line (@dir_list) {
596: my ($filename)=split(/\&/,$line,2);
597: if ($filename eq $newdir){
598: $found_file = 1;
599: }
600: }
601: if ($found_file){
602: $r->print('<font color="red"> Unable to create a directory named <strong>'.$newdir.
603: ' </strong>a file or directory by that name already exists.</font><br />');
604: } else {
605: my ($uname,$udom) = &get_name_dom($group);
606: my $port_path = &get_port_path($group);
607: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
608: $port_path.$env{'form.currentpath'}.$newdir);
609: if ($result ne 'ok') {
610: $r->print('<font color="red"> An errror occured ('.$result.
611: ') while trying to create a new directory '.&display_file().'</font><br />');
612: }
613: }
614: if ($newdir ne $env{'form.newdir'}) {
615: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
616: }
617: $r->print(&done(undef,$url,$group));
618: }
619:
620: sub get_portfolio_root {
621: my ($group) = @_;
622: my ($portfolio_root,$udom,$uname,$path);
623: ($uname,$udom) = &get_name_dom($group);
624: if (defined($group)) {
625: $path = '/userfiles/groups/'.$group.'/portfolio';
626: } else {
627: $path = '/userfiles/portfolio';
628: }
629: return (&Apache::loncommon::propath($udom,$uname).$path);
630: }
631:
632: sub get_dir_list {
633: my ($portfolio_root,$group) = @_;
634: my ($uname,$udom) = &get_name_dom($group);
635: return &Apache::lonnet::dirlist($env{'form.currentpath'},
636: $udom,$uname,$portfolio_root);
637: }
638:
639: sub get_name_dom {
640: my ($group) = @_;
641: my ($uname,$udom);
642: if (defined($group)) {
643: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
644: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
645: } else {
646: $udom = $env{'user.domain'};
647: $uname = $env{'user.name'};
648: }
649: return ($uname,$udom);
650: }
651:
652: sub prepend_group {
653: my ($filename,$group) = @_;
654: if (defined($group)) {
655: $filename = $group.'/'.$filename;
656: }
657: return $filename;
658: }
659:
660: sub get_namespace {
661: my ($group) = @_;
662: my $namespace = 'portfolio';
663: if (defined($group)) {
664: my ($uname,$udom) = &get_name_dom($group);
665: $namespace .= '_'.$udom.'_'.$uname.'_'.$group;
666: }
667: return $namespace;
668: }
669:
670: sub get_port_path {
671: my ($group) = @_;
672: my $port_path;
673: if (defined($group)) {
674: $port_path = "groups/$group/portfolio";
675: } else {
676: $port_path = 'portfolio';
677: }
678: return $port_path;
679: }
680:
681: sub handler {
682: # this handles file management
683: my $r = shift;
684: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
685: ['selectfile','currentpath','meta','lockinfo','currentfile',
686: 'action','fieldname','mode','rename','continue','group','access']);
687: my ($uname,$udom,$portfolio_root,$url,$group,$caller,$title);
688: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
689: $url = $1.$2;
690: $caller = $2;
691: }
692: if ($caller eq 'coursegrp_portfolio') {
693: # Needs to be in a course
694: if (! ($env{'request.course.fn'})) {
695: # Not in a course
696: $env{'user.error.msg'}=
697: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
698: return HTTP_NOT_ACCEPTABLE;
699: }
700: my $earlyout = 0;
701: my $view_permission = &Apache::lonnet::allowed('vcg',
702: $env{'request.course.id'});
703: $group = $env{'form.group'};
704: $group =~ s/\W//g;
705: if ($group) {
706: ($uname,$udom) = &get_name_dom($group);
707: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
708: $group);
709: if (%curr_groups) {
710: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
711: $env{'request.course.id'}.'/'.$group))) {
712: $portfolio_root = &get_portfolio_root($group);
713: } else {
714: $r->print('You do not have the privileges required to access the shared files space for this group');
715: $earlyout = 1;
716: }
717: } else {
718: $r->print('Not a valid group for this course');
719: $earlyout = 1;
720: }
721: $title = &mt('Group files').' for '.$group;
722: } else {
723: $r->print('Invalid group');
724: $earlyout = 1;
725: }
726: if ($earlyout) { return OK; }
727: } else {
728: ($uname,$udom) = &get_name_dom();
729: $portfolio_root = &get_portfolio_root();
730: $title = &mt('Portfolio Manager');
731: }
732:
733: &Apache::loncommon::no_cache($r);
734: &Apache::loncommon::content_type($r,'text/html');
735: $r->send_http_header;
736: # Give the LON-CAPA page header
737: if ($env{"form.mode"} eq 'selectfile'){
738: $r->print(&Apache::loncommon::start_page($title,undef,
739: {'only_body' => 1}));
740: } else {
741: $r->print(&Apache::loncommon::start_page($title));
742: }
743: $r->rflush();
744: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
745: $r->print('<font color="red"> No file was selected to upload.'.
746: 'To upload a file, click <strong>Browse...</strong>'.
747: ', select a file, then click <strong>Upload</strong>,</font>');
748: }
749: if ($env{'form.meta'}) {
750: &open_form($r,$url);
751: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
752: $r->print('Edit the meta data<br />');
753: &close_form($r,$url,$group);
754: }
755: if ($env{'form.store'}) {
756: }
757:
758: if ($env{'form.uploaddoc.filename'}) {
759: &upload($r,$url,$group);
760: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
761: &delete_confirmed($r,$url,$group);
762: } elsif ($env{'form.action'} eq 'delete') {
763: &delete($r,$url,$group);
764: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
765: &delete_dir_confirmed($r,$url,$group);
766: } elsif ($env{'form.action'} eq 'deletedir'){
767: &delete_dir($r,$url,$group);
768: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
769: &rename_confirmed($r,$url,$group);
770: } elsif ($env{'form.rename'}) {
771: $env{'form.selectfile'} = $env{'form.rename'};
772: $env{'form.action'} = 'rename';
773: &rename($r,$url,$group);
774: } elsif ($env{'form.createdir'}) {
775: &createdir($r,$url,$group);
776: } elsif ($env{'form.lockinfo'}) {
777: &lock_info($r,$url,$group);
778: } else {
779: my $current_path='/';
780: if ($env{'form.currentpath'}) {
781: $current_path = $env{'form.currentpath'};
782: }
783: my @dir_list=&get_dir_list($portfolio_root,$group);
784: if ($dir_list[0] eq 'no_such_dir'){
785: # two main reasons for this:
786: # 1) never been here, so directory structure not created
787: # 2) back-button navigation after deleting a directory
788: if ($current_path eq '/'){
789: &Apache::lonnet::mkdiruserfile($uname,$udom,
790: &get_port_path($group));
791: } else {
792: # some directory that snuck in get rid of the directory
793: # from the recent pulldown, just in case
794: &Apache::lonhtmlcommon::remove_recent('portfolio',
795: [$current_path]);
796: $current_path = '/'; # force it back to the root
797: }
798: # now grab the directory list again, for the first time
799: @dir_list=&Apache::lonnet::dirlist($current_path,
800: $udom,$uname,$portfolio_root);
801: }
802: # need to know if directory is empty so it can be removed if desired
803: my $is_empty=(@dir_list == 2);
804: &display_common($r,$url,$current_path,$is_empty,\@dir_list,$group);
805: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group);
806: $r->print(&Apache::loncommon::end_page());
807: }
808: return OK;
809: }
810: 1;
811: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>