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