Annotation of loncom/interface/portfolio.pm, revision 1.23
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.16 banghart 32:
33: # receives a file name and path stub from username/userfiles/portfolio/
34: # returns an anchor tag consisting encoding filename and currentpath
1.23 ! albertel 35: sub make_anchor {
! 36: my ($filename, $current_path) = @_;
! 37: my $anchor = '<a href="/adm/portfolio?selectfile='.$filename.'¤tpath='.$current_path.'">'.$filename.'</a>';
1.8 albertel 38: return $anchor;
1.6 banghart 39: }
1.16 banghart 40:
41: # returns html with <br /> separated contents of the directory
42: # returns a <strong>currentFile</strong> (bolds the selected file/dir)
1.23 ! albertel 43: sub display_directory {
1.16 banghart 44: my ($currentPath, $currentFile, @dirList,) = @_;
1.10 banghart 45: my $displayOut='';
1.23 ! albertel 46: my $filename;
1.8 albertel 47: my $upPath;
1.23 ! albertel 48: if ($currentPath ne '/') {
! 49: $displayOut = 'Listing of '.$currentPath.'<br /><hr />';
1.10 banghart 50: # provides the "up one directory level" function
51: # it means shortening the currentpath to the parent directory
52: $currentPath =~ m:(^/.*)(/.*/$):;
1.23 ! albertel 53: if ($1 ne '/') {
1.10 banghart 54: $upPath = $1.'/';
1.23 ! albertel 55: } else {
1.10 banghart 56: $upPath = $1;
57: }
58:
1.17 banghart 59: # $displayOut = $displayOut.'<a href="/adm/portfolio?selectfile='.$upPath.'¤tpath='.$upPath.'">..</a><br />';
1.8 albertel 60: } else {
1.17 banghart 61: # $displayOut = $displayOut.'at root '.$currentPath.'<br />';
1.8 albertel 62: }
1.10 banghart 63: foreach my $line (@dirList) {
64: #$strip holds directory/file name
65: #$dom
1.23 ! albertel 66: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
! 67: if (($filename ne '.') && ($filename ne '..')) {
! 68: if ($testdir =~ m:^1:) {
1.10 banghart 69: # handle directories different from files
1.23 ! albertel 70: if ($filename eq $currentFile) {
! 71: #checks to bold the selected file
! 72: $displayOut.= '<strong>'.(&make_anchor($filename.'/', $filename.'/').'</strong><br />'."\n");
! 73: } else {
! 74: $displayOut.= (&make_anchor($filename.'/', $filename.'/').'<br />'."\n");
1.10 banghart 75: }
1.23 ! albertel 76: } else {
! 77: if ($filename eq $currentFile) {
! 78: #checks to bold the selected file
! 79: $displayOut.='<strong>'.(&make_anchor($filename, $currentPath).'</strong><br />'."\n");
! 80: } else {
! 81: $displayOut.=(&make_anchor($filename, $currentPath).'<br />'."\n");
1.10 banghart 82: }
83: }
1.16 banghart 84:
1.10 banghart 85: }
86:
1.8 albertel 87: }
88: return $displayOut;
1.6 banghart 89: }
1.23 ! albertel 90:
1.6 banghart 91: sub displayActions {
1.10 banghart 92: # returns html to offer user appropriate actions depending on selected file/directory
1.8 albertel 93: my $displayOut;
1.16 banghart 94: my ($currentPath, $currentFile, $isEmpty) = @_;
1.8 albertel 95: # $displayOut = 'here are actions for '.$currentFile;
1.23 ! albertel 96: if ($currentFile =~ m:/$:) {
1.10 banghart 97: # if the selected file is a directory, these are the options
98: # offer the chance to delete the directory only if it is empty
99: if ($isEmpty && ($currentPath ne '/')) {
100: $displayOut = $displayOut.'<form method="POST">
101: <input type="hidden" name="selectfile"
102: value="'.$currentFile.'" />
103: <input type="hidden" name="fileaction" value="delete" />
104: <input type="hidden" name="currentpath" value="'.$currentPath.'" />
105: <center>
106: <input type="submit"
107: value="Delete '.$currentFile.'" />
108: </center>
109: </form>';
110: }
111: if ($currentPath ne '/') {
112: $displayOut = $displayOut.'<hr />
113: <form method="POST">
114: <input type="hidden" name="selectfile"
115: value="'.$currentFile.'" />
116: <input type="hidden" name="fileaction" value="rename" />
117: <input type="hidden" name="currentpath" value="'.$currentPath.'" />
118: <input type="input" name="filenewname" value="Type new name here" />
119: <input type="submit"
120: value="Rename '.$currentFile.'" />
121: </form>';
122: }
1.23 ! albertel 123: } else { #action options offered for files
1.10 banghart 124: $displayOut = $displayOut.'<form method="POST">';
125: $displayOut = $displayOut.'<input type="hidden" name="selectfile"';
126: $displayOut = $displayOut.'value="'.$currentFile;
127: $displayOut = $displayOut.'" /><input type="hidden" name="fileaction" value="delete" />
128: <input type="hidden" name="currentpath" value="'.$currentPath.'" />
129: <center>
130: <input type="submit"
131: value="Delete '.$currentFile.'" />
132: </center>
133: </form>';
134:
135: $displayOut = $displayOut.'<hr />
136: <form method="POST">
137: <input type="hidden" name="selectfile"
138: value="'.$currentFile.'" />
139: <input type="hidden" name="fileaction" value="rename" />
140: <input type="hidden" name="currentpath" value="'.$currentPath.'" />
141: <input type="input" name="filenewname" value="Type new name here" />
142: <input type="submit"
143: value="Rename '.$currentFile.'" />
144: </form>
145: <hr />';
1.8 albertel 146: }
1.10 banghart 147: $displayOut = $displayOut.'<hr />Add a file to '.$currentPath;
1.8 albertel 148: # file upload form
149: $displayOut = $displayOut.'<form method="post" enctype="multipart/form-data">';
1.9 albertel 150: $displayOut = $displayOut.'<input name="uploaddoc" type="file" />'.
1.10 banghart 151: '<input type="hidden" name="currentpath" value="'.$currentPath.'" />'.
152: '<input type="submit" name="storeupl" value="Upload" />'.
153: '</form><hr />';
1.8 albertel 154: $displayOut = $displayOut.'<form method="POST">
1.10 banghart 155: <input name="subdir" type="text" />
156: <input type="submit" value="Create Subdirectory" />
157: </form>
158: ';
1.8 albertel 159: return $displayOut;
1.6 banghart 160: }
1.23 ! albertel 161:
1.1 banghart 162: sub handler {
1.8 albertel 163: # this handles file management
1.10 banghart 164: my $r = shift;
1.18 banghart 165: my $iconpath= $r->dir_config('lonIconsURL') . "/";
1.8 albertel 166: my @dirList; # will hold directory listing as array
167: my $udir; # returned from home server
168: my $currentPath; # path assuming /userfiles/portfolio/ as root
169: my $currentFile; # directory or file contained in $pathToRoot.$currentPath
170: my $action; # delete, rename, makedirectory, removedirectory,
171: my $filenewname; # for rename action (guess what we do with it!)
172: my $isFile;
1.10 banghart 173: my $isEmpty;
1.18 banghart 174: my $dirptr=16384;
1.10 banghart 175: &Apache::loncommon::no_cache($r);
1.14 banghart 176: &Apache::loncommon::content_type($r,'text/html');
1.8 albertel 177: $r->send_http_header;
1.14 banghart 178: # Give the LON-CAPA page header
179: $r->print('<html><head><title>'.
180: &mt('Portfolio Manager').
181: "</title></head>\n".
182: &Apache::loncommon::bodytag('Portfolio Manager'));
183: $r->rflush();
1.8 albertel 184: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.10 banghart 185: ['selectfile','currentpath', 'currentfile']);
1.8 albertel 186: # currentPath and currentFile need to be set for the rest of things to happen
187: # sometimes, currentFile will be passed by a form field, selectedfile
188: # if there is no 'form.selectedfile' then the current directory is
189: # considered as selected
1.11 banghart 190: if ($ENV{'form.currentpath'}) {
1.10 banghart 191: $currentPath = $ENV{'form.currentpath'};
1.11 banghart 192: } else {
1.10 banghart 193: $currentPath = '/';
1.8 albertel 194: }
1.11 banghart 195: if ($ENV{'form.selectfile'}) {
1.10 banghart 196: # have to check if the selected file is a subdirectory
1.23 ! albertel 197: if ($ENV{'form.selectfile'} =~ /-\(Dir\)/) {
1.10 banghart 198: # $currentPath =~ /\-\(Dir\)/;
199: $currentPath = $`.'/';
200: $r->print('<br />'.$currentPath.'<br />');
201: }
202: $currentFile = $ENV{'form.selectfile'};
1.11 banghart 203: } else {
1.10 banghart 204: $currentFile = '';
1.8 albertel 205: }
206: # if we're uploading a file, we need to do it early so it will show in the directory list
1.11 banghart 207: if ($ENV{'form.uploaddoc.filename'}) {
208: $r->print($ENV{'form.storeupl'}.'<br />');
209: $r->print(&Apache::lonnet::userfileupload('uploaddoc','','portfolio'.$currentPath).'<br />');
1.8 albertel 210: }
211: # similarly, we need to delete or rename files before getting directory list
1.23 ! albertel 212: if ($ENV{'form.selectfile'}) {
1.11 banghart 213: if ($ENV{'form.fileaction'} eq 'delete') {
1.10 banghart 214: $r->print('<br />trying to delete '.$currentPath.$ENV{'form.selectfile'}.'<br />');
215: $r->print(&Apache::lonnet::removeuserfile($ENV{'user.name'}, $ENV{'user.domain'},'portfolio'.$currentPath.$ENV{'form.selectfile'}));
216: $currentFile = '';
1.11 banghart 217: } elsif ($ENV{'form.fileaction'} eq 'rename') {
1.10 banghart 218: &Apache::lonnet::portfoliomanage($currentPath.$ENV{'form.selectfile'}, 'rename', $currentPath.$ENV{'form.filenewname'} );
219: }
1.8 albertel 220: }
221: # we always need $dirList, plus this will return information about the current file
1.18 banghart 222: # as well as information about the home server directory structure, specifically
1.10 banghart 223: # the path to the users userfiles directory.
1.16 banghart 224: #
1.15 albertel 225: my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
226: $ENV{'user.name'}).
1.19 banghart 227: '/userfiles/portfolio';
1.18 banghart 228: @dirList = &Apache::lonnet::dirlist($currentPath, $ENV{'user.domain'}, $ENV{'user.name'}, $portfolio_root);
1.16 banghart 229:
1.12 banghart 230: if (@dirList == 2) { # need to know if directory is empty so it can be removed if desired
1.10 banghart 231: $isEmpty = 1;
1.13 banghart 232: } else {
1.10 banghart 233: $isEmpty = 0;
234: }
1.16 banghart 235:
1.11 banghart 236: if ($ENV{'form.selectfile'}) {
237: if ($ENV{'form.fileaction'} eq 'delete') {
1.10 banghart 238: &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef );
239: $ENV{'portfolio.file'} = 'Selected File Deleted';
1.11 banghart 240: } elsif ($ENV{'form.fileaction'} eq 'rename') {
241: &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'});
242: } else {
1.23 ! albertel 243: # Remember user's file selection for later
! 244: $ENV{'portfolio.file'} = $ENV{'form.selectfile'};
! 245: # offer things user can do with selected file
1.10 banghart 246: }
1.23 ! albertel 247: } else {
1.10 banghart 248: unless ($ENV{'portfolio.file'}){
249: $ENV{'portfolio.file'} = 'No File Selected';
250: }
1.8 albertel 251: }
252: ##############################
253: #
254: # Display begins here
255: #
256: ##############################
1.20 banghart 257: $r->print('<table border="0" cellspacing="2" cellpadding="2"><tr valign="middle">');
258: $r->print('<td bgcolor="#ccddaa" align="center">');
259: my $displayOut = '<form method="post" enctype="multipart/form-data">';
260: $displayOut = $displayOut.'<input name="uploaddoc" type="file" />'.
261: '<input type="hidden" name="currentpath" value="'.$currentPath.'" />'.
262: '<input type="submit" name="storeupl" value="Upload" />'.
263: '</form>';
264: $r->print($displayOut);
1.22 albertel 265: $r->print('</td></tr><tr><td bgcolor="#ccddaa" align="center">');
266: my $displayOut = '<form method="post">';
267: $displayOut = $displayOut.'<input name="newdir" type="input" />'.
268: '<input type="hidden" name="currentpath" value="'.$currentPath.'" />'.
269: '<input type="submit" name="createdir" value="'.&mt("Create Directory").'" />'.
270: '</form>';
271: $r->print($displayOut);
272: $r->print('</td></tr></table>');
1.19 banghart 273: my @tree = split (/\//,$currentPath);
1.23 ! albertel 274: $r->print('<font size="+2">'.&make_anchor('/','/'));
1.19 banghart 275: if (@tree > 1){
276: my $newCurrentPath = '';
277: for (my $i = 1; $i< @tree; $i++){
278: $newCurrentPath .= $tree[$i].'/';
1.23 ! albertel 279: $r->print(&make_anchor($tree[$i],'/'.$newCurrentPath).'/');
1.19 banghart 280: }
281: }
282: $r->print('</font>');
1.21 banghart 283: &Apache::lonhtmlcommon::store_recent('portfolio',$currentPath,$currentPath);
1.22 albertel 284: $r->print('<br /><form method=post action="/adm/portfolio">'.
285: &Apache::lonhtmlcommon::select_recent('portfolio','currentpath',
286: 'this.form.submit();'));
1.21 banghart 287: $r->print("</form>");
1.18 banghart 288: $r->print('<table border="0" cellspacing="2" cellpadding="2">'.
1.22 albertel 289: '<tr><th>Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>');
290: my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio/$currentPath/";
1.18 banghart 291: foreach my $line (@dirList) {
292: #$strip holds directory/file name
293: #$dom
1.23 ! albertel 294: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
! 295: if (($filename ne '.') && ($filename ne '..')) {
! 296: if ($dirptr&$testdir) {
1.19 banghart 297: $r->print('<tr bgcolor="#FFAA99"><td><img src="'.$iconpath.'folder_closed.gif"></td>');
298: $r->print('<td>Go to ...</td>');
1.23 ! albertel 299: $r->print('<td>'.&make_anchor($filename.'/',$currentPath.$filename.'/').'</td>');
1.19 banghart 300: $r->print('</tr>');
1.23 ! albertel 301: } else {
1.22 albertel 302: $r->print('<tr bgcolor="#CCCCFF">');
303: $r->print('<td>
304: <select name="action">
305: <option value=""></option>
306: <option value="delete">'.&mt("Delete").'</option>
307: <option value="rename">'.&mt("Rename").'</option>
308: </select>
309: <input type="submit" name="doit" value="Go" />
310: </td>');
311: $r->print('<td><img src="'.$iconpath.'unknown.gif"></td>');
1.23 ! albertel 312: $r->print('<td><a href="'.$href_location.$filename.'">'.
! 313: $filename.'</a></td>');
1.22 albertel 314: $r->print('<td>'.$size.'</td>');
315: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
1.19 banghart 316: $r->print('</tr>');
317: }
1.18 banghart 318: }
319: }
320: # <tr bgcolor="#FFAA99"> pink bg
321: # <tr bgcolor="#CCCCFF"> blue bg
1.23 ! albertel 322: # $r->print(&display_directory($currentPath, $currentFile, @dirList));
1.18 banghart 323: # $r->print('</td>><td>');
1.23 ! albertel 324: # $r->print(&display_actions($currentPath, $currentFile, $isEmpty));
1.22 albertel 325: $r->print('</table></form>');
1.14 banghart 326: $r->print('</blockquote>');
327: $r->print("</body>\n</html>\n");
328: $r->rflush();
1.8 albertel 329: return OK;
1.2 banghart 330: }
1.1 banghart 331:
332: 1;
333: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>