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