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