--- loncom/interface/portfolio.pm 2004/07/01 18:59:33 1.10
+++ loncom/interface/portfolio.pm 2006/06/27 15:37:17 1.122
@@ -18,12 +18,9 @@
#
# /home/httpd/html/adm/gpl.txt
#
-
-
# http://www.lon-capa.org/
#
-
package Apache::portfolio;
use strict;
use Apache::Constants qw(:common :http);
@@ -32,274 +29,1828 @@ use Apache::lonnet;
use Apache::lontexconvert;
use Apache::lonfeedback;
use Apache::lonlocal;
-sub makeAnchor{
- # receives a file name and path stub from username/userfiles/portfolio/
- # returns an anchor tag consisting encoding filename and currentpath
- my ($fileName, $currentPath) = @_;
- my $anchor = ''.$fileName.'';
+use Apache::lonnet;
+use Apache::longroup;
+use HTML::Entities;
+use LONCAPA;
+
+# receives a file name and path stub from username/userfiles/portfolio/
+# returns an anchor tag consisting encoding filename and currentpath
+sub make_anchor {
+ my ($url, $filename, $current_path, $current_mode, $field_name,
+ $continue_select,$group) = @_;
+ if ($continue_select ne 'true') {$continue_select = 'false'};
+ my $anchor = ''.$filename.'';
return $anchor;
}
-sub displayDirectory {
- # returns html with separated contents of the directory
- # returns a currentFile (bolds the selected file/dir)
- my ($currentPath, $currentFile, $isDir, @dirList,) = @_;
- my $displayOut='';
- my $fileName;
- my $upPath;
- if ($currentPath ne '/'){
- $displayOut = 'Listing of '.$currentPath.'
'.
- # provides the "up one directory level" function
- # it means shortening the currentpath to the parent directory
- $currentPath =~ m:(^/.*)(/.*/$):;
- if ($1 ne '/'){
- $upPath = $1.'/';
- }else{
- $upPath = $1;
+my $dirptr=16384;
+sub display_common {
+ my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload)=@_;
+ my $namespace = &get_namespace($group);
+ my $port_path = &get_port_path($group);
+ if ($can_upload) {
+ my $groupitem;
+ if (defined($group)) {
+ $groupitem = '';
+ }
+ my $iconpath= $r->dir_config('lonIconsURL') . "/";
+ my %text=&Apache::lonlocal::texthash(
+ 'upload' => 'Upload',
+ 'upload_label' =>
+ 'Upload file to current directory:',
+ 'createdir' => 'Create Subdirectory',
+ 'createdir_label' =>
+ 'Create subdirectory in current directory:');
+ my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
+ $r->print(<<"TABLE");
+
+
+
+ $text{'upload_label'}
+
+
+
+
+
+
+
+ $text{'createdir_label'}
+
+
+
+
+
+
+TABLE
+ }
+ my @tree = split (/\//,$current_path);
+ $r->print(''.&make_anchor($url,$port_path,'/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"},$group).'/');
+ if (@tree > 1){
+ my $newCurrentPath = '';
+ for (my $i = 1; $i< @tree; $i++){
+ $newCurrentPath .= $tree[$i].'/';
+ $r->print(&make_anchor($url,$tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"},$group).'/');
}
+ }
+ $r->print('');
+ &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
+ $r->print(' ");
+}
+sub display_directory {
+ my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
+ $can_modify,$can_delete,$can_setacl)=@_;
+ my $iconpath= $r->dir_config('lonIconsURL') . "/";
+ my ($groupitem,$groupecho);
+ my $display_out;
+ my $select_mode;
+ my $checked_files;
+ my $port_path = &get_port_path($group);
+ my ($uname,$udom) = &get_name_dom($group);
+ my $access_admin_text = &mt('View Status');
+ if ($can_setacl) {
+ $access_admin_text = &mt('View/Change Status');
+ }
+ if ((defined($group)) && (defined($env{'request.course.id'}))) {
+ $groupitem = '';
+ $groupecho = '&group='.$group;
+ }
+
+ my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
+ $uname);
+ my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
+ $current_permissions,$group);
+ my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
+ my $now = time;
+ if ($env{"form.mode"} eq 'selectfile'){
+ &select_files($r);
+ $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
+ $select_mode = 'true';
+ }
+ if ($is_empty && ($current_path ne '/') && $can_delete) {
+ $display_out = '';
- $displayOut = $displayOut.'.. ';
+ $r->print($display_out);
+ return;
+ }
+ if ($select_mode eq 'true') {
+ $r->print(''
+ );
+ }
+ }
+}
+
+sub open_form {
+ my ($r,$url)=@_;
+ my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
+ $r->print('
');
+ &close_form($r,$url,$group);
+ } else {
+ $r->print("No file was checked to delete. ");
+ $r->print(&done(undef,$url,$group));
+ }
+ }
+}
+
+sub delete_confirmed {
+ my ($r,$url,$group)=@_;
+ my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
+ my $result;
+ my ($uname,$udom) = &get_name_dom($group);
+ my $port_path = &get_port_path($group);
+ foreach my $delete_file (@files) {
+ $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
+ $env{'form.currentpath'}.
+ $delete_file);
+ if ($result ne 'ok') {
+ $r->print(' An error occured ('.$result.
+ ') while trying to delete '.&display_file(undef, $delete_file).' ');
+ }
+ }
+ $r->print(&done(undef,$url,$group));
+}
+
+sub delete_dir {
+ my ($r,$url,$group)=@_;
+ &open_form($r,$url);
+ $r->print('
'.&mt('Delete').' '.&display_file().'?
');
+ &close_form($r,$url,$group);
+}
+
+sub delete_dir_confirmed {
+ my ($r,$url,$group)=@_;
+ my $directory_name = $env{'form.currentpath'};
+ $directory_name =~ s|/$||; # remove any trailing slash
+ my ($uname,$udom) = &get_name_dom($group);
+ my $namespace = &get_namespace($group);
+ my $port_path = &get_port_path($group);
+ my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
+ $directory_name);
+
+ if ($result ne 'ok') {
+ $r->print(' An error occured (dir) ('.$result.
+ ') while trying to delete '.$directory_name.' ');
+ } else {
+ # now remove from recent
+# $r->print(' removing '.$directory_name.' print(&done(undef,$url,$group));
+}
+
+sub rename {
+ my ($r,$url,$group)=@_;
+ my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
+ my ($uname,$udom) = &get_name_dom($group);
+ $file_name = &prepend_group($file_name,$group);
+ if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
+ $r->print ("The file is locked and cannot be renamed. ");
+ $r->print(&done(undef,$url,$group));
+ } else {
+ &open_form($r,$url);
+ $r->print('
'.&mt('Rename').' '.&display_file().' to
+ ?
');
+ &close_form($r,$url,$group);
+ }
+}
+
+sub rename_confirmed {
+ my ($r,$url,$group)=@_;
+ my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
+ my ($uname,$udom) = &get_name_dom($group);
+ my $port_path = &get_port_path($group);
+ if ($filenewname eq '') {
+ $r->print(''.
+ &mt("Error: no valid filename was provided to rename to.").
+ ' ');
+ $r->print(&done(undef,$url,$group));
+ return;
+ }
+ my $result=
+ &Apache::lonnet::renameuserfile($uname,$udom,
+ $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
+ $port_path.$env{'form.currentpath'}.$filenewname);
+ if ($result ne 'ok') {
+ $r->print(''.
+ &mt('An errror occured ([_1]) while trying to rename [_2]'
+ .' to [_3]',$result,&display_file(),
+ &display_file('',$filenewname)).' ');
+ }
+ if ($filenewname ne $env{'form.filenewname'}) {
+ $r->print(&mt("The new file name was changed from: [_1] to [_2]",
+ ''.&display_file('',$env{'form.filenewname'}).'',
+ ''.&display_file('',$filenewname).''));
+ }
+ $r->print(&done(undef,$url,$group));
+}
+
+sub display_access {
+ my ($r,$url,$group,$can_setacl) = @_;
+ my ($uname,$udom) = &get_name_dom($group);
+ my $file_name = $env{'form.currentpath'}.$env{'form.access'};
+ $file_name = &prepend_group($file_name,$group);
+ my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
+ $uname);
+ my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
+ my $aclcount = keys(%access_controls);
+ my $header = '
'.&mt('Allowing others to retrieve portfolio file: [_1]',$env{'form.currentpath'}.$env{'form.access'}).'
';
+ my $info .=
+ &mt('Access to this file by others can be set to be one or more of the following types: public, passphrase-protected or conditional.').
+ '
'.
+ &mt('Public files are available to anyone without the need for login.').
+ '
'.
+ &mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.').
+ '
'.
+ #'
'.
+ #&mt('Conditional files are accessible to logged-in users with accounts in the LON-CAPA network, who satisfy the conditions you set.').
+ #' '.
+ #&mt('The conditions can include affiliation with a particular course or group, or a user account in a specific domain.').
+ #' '.
+ #&mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').
+ '
';
+ if ($can_setacl) {
+ &open_form($r,$url);
+ $r->print($header.$info);
+ &access_setting_table($r,$access_controls{$file_name});
+ my $button_text = {
+ 'continue' => &mt('Proceed'),
+ 'cancel' => &mt('Back to directory listing'),
+ };
+ &close_form($r,$url,$group,$button_text);
+ } else {
+ $r->print($header);
+ if ($aclcount) {
+ $r->print($info);
+ }
+ &view_access_settings($r,$url,$group,$access_controls{$file_name},
+ $aclcount);
+ }
+}
+
+sub view_access_settings {
+ my ($r,$url,$group,$access_controls,$aclcount) = @_;
+ my ($showstart,$showend);
+ my %todisplay;
+ foreach my $key (sort(keys(%{$access_controls}))) {
+ my ($num,$scope,$end,$start) = &unpack_acc_key($key);
+ $todisplay{$scope}{$key} = $$access_controls{$key};
+ }
+ if ($aclcount) {
+ $r->print(&mt('
');
- #grab stuff that was sent
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['selectfile','currentpath', 'currentfile']);
-# $r->print (' CP= '.$ENV{'form.currentpath'}.' ');
- # currentPath and currentFile need to be set for the rest of things to happen
- # sometimes, currentFile will be passed by a form field, selectedfile
- # if there is no 'form.selectedfile' then the current directory is
- # considered as selected
- if ($ENV{'form.currentpath'}){
- $currentPath = $ENV{'form.currentpath'};
- }else{
- $currentPath = '/';
- }
- if ($ENV{'form.selectfile'}){
- $r->print(' found selectfile'.$ENV{'form.selectfile'} .' ');
- # have to check if the selected file is a subdirectory
- if ($ENV{'form.selectfile'} =~ /-\(Dir\)/){
- # $currentPath =~ /\-\(Dir\)/;
- $currentPath = $`.'/';
- $r->print(' '.$currentPath.' ');
- }
- $currentFile = $ENV{'form.selectfile'};
- }else{
- $currentFile = '';
- }
- # if we're uploading a file, we need to do it early so it will show in the directory list
- if ($ENV{'form.uploaddoc.filename'}){
- $r->print ($ENV{'form.storeupl'}.' ');
- $r->print (&Apache::lonnet::userfileupload('uploaddoc','','portfolio'.$currentPath).' ');
- }
- # similarly, we need to delete or rename files before getting directory list
- if ($ENV{'form.selectfile'}){
- if ($ENV{'form.fileaction'} eq 'delete'){
- $r->print(' trying to delete '.$currentPath.$ENV{'form.selectfile'}.' ');
- $r->print(&Apache::lonnet::removeuserfile($ENV{'user.name'}, $ENV{'user.domain'},'portfolio'.$currentPath.$ENV{'form.selectfile'}));
- $currentFile = '';
- }elsif($ENV{'form.fileaction'} eq 'rename') {
- &Apache::lonnet::portfoliomanage($currentPath.$ENV{'form.selectfile'}, 'rename', $currentPath.$ENV{'form.filenewname'} );
- # $r->print ('We will rename your file');
- }
- }
- # we always need $dirList, plus this will return information about the current file
- # as well as information about he home server directory structure, specifically
- # the path to the users userfiles directory.
-# $r->print('dir list follows '.&Apache::lonnet::portfoliolist($currentPath, $currentFile).' ');
- my $list = &Apache::lonnet::portfoliolist($currentPath, $currentFile);
- @dirList = split(/:/,$list);
-# foreach my $line (@dirlist) {
-#
-# #$strip holds directory/file name
-# #$dom
-# my ($strip,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16);
-# $r->print ($strip.' '.$testdir.' ');
-# }
-# @dirList = split / /, (&Apache::lonnet::portfoliolist($currentPath, $currentFile));
-
- # portfoliolist returns isdir, isfile and udir as the final array elements
- # we'll pop them off the bottom of the array, and put them where they belong
-
- # $londcall added to help debug, contains the command sent to lond
- # my $londcall = pop @dirList;
- # $r->print (' udir '.$londcall.' ');
- # $udir = pop @dirList;
- # $r->print (' path returned '.$udir.' ');
- # $isFile = pop @dirList;
-# $r->print (' isfile '.$isFile.' ');
-# $isDir = pop @dirList;
- if (@dirList == 2){ # need to know if directory is empty to it can be removed if desired
- $isEmpty = 1;
- }else{
- $isEmpty = 0;
- }
-# $r->print (' lines left ind dirlist '.@dirList.' ');
-# return OK if $r->header_only;
- # Stuff to maintain proper setting for selected file
- if ($ENV{'form.selectfile'}){
- if ($ENV{'form.fileaction'} eq 'delete'){
- &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'delete', undef );
- $ENV{'portfolio.file'} = 'Selected File Deleted';
- }elsif($ENV{'form.fileaction'} eq 'rename') {
- &Apache::lonnet::portfoliomanage($ENV{'form.selectfile'}, 'rename', $ENV{'form.filenewname'} );
-# $r->print ('We will rename your file');
- }else{
-
- # Remember user's file selection for later
- $ENV{'portfolio.file'} = $ENV{'form.selectfile'};
- # offer things user can do with selected file
- }
- }else{
- unless ($ENV{'portfolio.file'}){
- $ENV{'portfolio.file'} = 'No File Selected';
- }
- }
- ##############################
- #
- # Display begins here
- #
- ##############################
- $r->print (' start ');
- $r->print ($udir);
- $r->print ('