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