Annotation of loncom/interface/portfolio.pm, revision 1.7
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:
22:
23: # http://www.lon-capa.org/
24: #
25:
26:
1.1 banghart 27: package Apache::portfolio;
28: use strict;
29: use Apache::Constants qw(:common :http);
1.2 banghart 30: use Apache::loncommon;
1.1 banghart 31: use Apache::lonnet;
1.2 banghart 32: use Apache::lontexconvert;
33: use Apache::lonfeedback;
34: use Apache::lonlocal;
1.6 banghart 35: sub makeAnchor{
36: # receives a file name assumed to reside in username/userfiles/portfolio/
37: # returns a form consisting of a single submit button labeled with the file name
38: my ($fileName, $currentPath) = @_;
39: my $anchor = '<a href="/adm/portfolio?selectfile='.$fileName.'¤tpath='.$currentPath.'">'.$fileName.'</a>';
40: # my $button = '
41: # <form method="POST" action="/adm/portfolio">
42: # <input type="hidden" name="selectfile" value="'.$fileName.'">
43: # <input type="submit" value="'.$fileName.'" name="storeupl">
44: # </form>
45: # ';
46: return $anchor;
47: }
48: sub displayDirectory {
49: # returns html with <br /> separated contents of the directory
50: # returns a <strong>currentFile</strong> (bolds the selected file/dir)
51:
52: my ($currentPath, $currentFile, $isDir, @dirList,) = @_;
53: my $displayOut='';
54: my $fileName;
55: my $upPath;
56: if ($currentPath ne '/'){
57: $displayOut = 'Listing of '.$currentPath.'<br /><hr />'.
58: # provides the "up one directory level" function
59: # it means shortening the currentpath to the parent directory
60: $currentPath =~ m:(^/.*)(/.*/$):;
61: if ($1 ne '/'){
62: $upPath = $1.'/';
63: }else{
64: $upPath = $1;
65: }
66:
67: $displayOut = $displayOut.'<a href="/adm/portfolio?selectfile=updir¤tpath='.$upPath.'">..</a><br />';
68: } else {
69: $displayOut = $displayOut.'at root '.$currentPath.'<br />';
70: }
71: while ($fileName = shift @dirList){
72: if (($fileName ne './') && ($fileName ne '../')){
73: if ($fileName =~ m:/$:){
74: # handle directories different from files
75: if ($fileName eq $currentFile){ #checks to bold the selected file
76: $displayOut = $displayOut.'<strong>'.(makeAnchor($fileName, $currentPath.$fileName).'</strong><br />');
77: }else{
78: $displayOut = $displayOut.(makeAnchor($fileName, $currentPath.$fileName).'<br />');
79: }
80: }else{
81: if ($fileName eq $currentFile){ #checks to bold the selected file
82: $displayOut = $displayOut.'<strong>'.(makeAnchor($fileName, $currentPath).'</strong><br />');
83: }else{
84: $displayOut = $displayOut.(makeAnchor($fileName, $currentPath).'<br />');
85: }
86: }
87: }
88: }
89: $displayOut = $displayOut.
90: return $displayOut;
91: }
92: sub displayActions {
93: # returns html to offer user appropriate actions depending on selected file/directory
94: my $displayOut;
95: my ($currentPath, $currentFile, $isDir, $isFile) = @_;
96: # $displayOut = 'here are actions for '.$currentFile;
97: if ($isDir){
98: $displayOut = 'Directory';
99: }
100: if ($isFile){
101: $displayOut = 'File';
102: }
103:
104: $displayOut = $displayOut.'<form method="POST">
105: <input type="hidden" name="selectfile"
106: value="'.$currentFile.'">
107: <input type="hidden" name="fileaction" value="delete">
108: <center>
109: <input type="submit"
110:
111: value="Delete '.$currentFile.'">
112: </center>
113: </form>
114: <hr />
115: <form method="POST">
116: <input type="hidden" name="selectfile"
117: value="'.$currentFile.'">
118: <input type="hidden" name="fileaction" value="rename">
119: <input type="input" name="filenewname" value="Type new name here">
120: <input type="submit"
121: value="Rename '.$currentFile.'">
122: </form>
123: <hr>';
124: $displayOut = $displayOut.'<hr>Add a file to your portfolio';
125: # file upload form
126: $displayOut = $displayOut.'<form method="post" enctype="multipart/form-data">';
127: $displayOut = $displayOut.'<input name="uploaddoc" type="file">'.
128: '<input type="hidden" name="currentpath" value="'.$currentPath.'">'.
129: '<input type="submit" name="storeupl" value="Upload">'.
130: '</form><hr>';
131: $displayOut = $displayOut.'<form method="POST">
132: <input name="subdir" type="text" >
133: <input type="submit" value="Create Subdirectory">
134: </form>
135: ';
136: return $displayOut;
137: }
1.1 banghart 138: sub handler {
1.6 banghart 139: # this handles file management
1.7 ! matthew 140: my ($r)=@_;
1.6 banghart 141: my @dirList; # will hold directory listing as array
142: my $udir; # returned from home server
143: my $currentPath; # path assuming /userfiles/portfolio/ as root
144: my $currentFile; # directory or file contained in $pathToRoot.$currentPath
145: my $action; # delete, rename, makedirectory, removedirectory,
146: my $filenewname; # for rename action (guess what we do with it!)
147: my $isFile;
148: my $isDir;
149: # send header
1.1 banghart 150: $r->content_type('text/html');
151: $r->send_http_header;
1.6 banghart 152: $r->print('<html><head><title>'.
153: 'Portfolio Management'.
154: "</title></head>\n");
155:
156: $r->print ('
157: <body bgcolor="dogfood">
158: <blockquote>');
159: #grab stuff that was sent
160: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
161: ['selectfile','currentpath', 'currentfile']);
162: $r->print ('<br />CP= '.$ENV{'form.currentpath'}.'<br />');
163: # currentPath and currentFile need to be set for the rest of things to happen
164: # sometimes, currentFile will be passed by a form field, selectedfile
165: # if there is no 'form.selectedfile' then the current directory is
166: # considered as selected
167: if ($ENV{'form.currentpath'}){
168: $currentPath = $ENV{'form.currentpath'};
169: }else{
170: $currentPath = '/';
171: }
172: if ($ENV{'form.selectfile'}){
173: $r->print('<br />found selectfile'.$ENV{'form.selectfile'} .'<br />');
174: # have to check if the selected file is a subdirectory
175: if ($ENV{'form.selectfile'} =~ /-\(Dir\)/){
176: # $currentPath =~ /\-\(Dir\)/;
177: $currentPath = $`.'/';
178: $r->print('<br />'.$currentPath.'<br />');
179: }
180: $currentFile = $ENV{'form.selectfile'};
181: }else{
182: $currentFile = '';
183: }
184: # if we're uploading a file, we need to do it early so it will show in the directory list
1.2 banghart 185: if ($ENV{'form.uploaddoc.filename'}){
1.6 banghart 186: $r->print ($ENV{'form.storeupl'}.'<br />');
187: $r->print (&Apache::lonnet::userfileupload('uploaddoc','','portfolio'.$currentPath).'<br />');
1.2 banghart 188: }
1.6 banghart 189: # similarly, we need to delete or rename files before getting directory list
190: if ($ENV{'form.selectfile'}){
191: if ($ENV{'form.fileaction'} eq 'delete'){
192: &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef );
193: $currentFile = '';
194: }elsif($ENV{'form.fileaction'} eq 'rename') {
195: &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'} );
196: # $r->print ('We will rename your file');
197: }
198: }
199: # we always need $dirList, plus this will return information about the current file
200: # as well as information about he home server directory structure, specifically
201: # the path to the users userfiles directory.
202: @dirList = split /<br\s\/>/, (&Apache::lonnet::portfoliolist($currentPath, $currentFile));
203: # portfoliolist returns isdir, isfile and udir as the final array elements
204: # we'll pop them off the bottom of the array, and put them where they belong
1.2 banghart 205:
1.6 banghart 206: # $londcall added to help debug
207: my $londcall = pop @dirList;
208: $r->print ('<br />udir '.$londcall.'<br />');
209: $udir = pop @dirList;
210: $r->print ('<br />path returned '.$udir.'<br />');
211: $isFile = pop @dirList;
212: # $r->print ('<br />isfile '.$isFile.'<br />');
213: $isDir = pop @dirList;
214: # $r->print ('<br />isdir '.$isDir.'<br />');
215: # return OK if $r->header_only;
216: # Stuff to maintain proper setting for selected file
217: if ($ENV{'form.selectfile'}){
218: if ($ENV{'form.fileaction'} eq 'delete'){
219: &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef );
220: $ENV{'portfolio.file'} = 'Selected File Deleted';
221: }elsif($ENV{'form.fileaction'} eq 'rename') {
222: &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'} );
223: # $r->print ('We will rename your file');
224: }else{
1.4 banghart 225:
1.6 banghart 226: # Remember user's file selection for later
227: $ENV{'portfolio.file'} = $ENV{'form.selectfile'};
228: # offer things user can do with selected file
229: }
230: }else{
231: unless ($ENV{'portfolio.file'}){
232: $ENV{'portfolio.file'} = 'No File Selected';
233: }
234: }
235: ##############################
236: #
237: # Display begins here
238: #
239: ##############################
240: $r->print ('<hr /> start ');
241: $r->print ($udir);
242: $r->print ('<table border=1><tr><td>');
243: $r->print (displayDirectory ($currentPath, $currentFile, $isDir, @dirList));
244: $r->print ('</td>><td>');
245: $r->print (displayActions ($currentPath, $currentFile, $isDir, $isFile));
246: $r->print ('</td>></tr></table>');
247: $r->print ('<br />end display<br /><hr />');
248: $r->print ('</blockquote></body>');
1.1 banghart 249: return OK;
1.2 banghart 250: }
1.1 banghart 251:
252: 1;
253: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>