--- loncom/interface/portfolio.pm 2004/07/28 22:30:31 1.19
+++ loncom/interface/portfolio.pm 2004/10/12 00:44:05 1.48
@@ -32,142 +32,419 @@ use Apache::lonlocal;
# receives a file name and path stub from username/userfiles/portfolio/
# returns an anchor tag consisting encoding filename and currentpath
-sub makeAnchor{
- my ($fileName, $currentPath) = @_;
- my $anchor = ''.$fileName.'';
+sub make_anchor {
+ my ($filename, $current_path) = @_;
+ my $anchor = ''.$filename.'';
return $anchor;
}
-
-# returns html with separated contents of the directory
-# returns a currentFile (bolds the selected file/dir)
-sub displayDirectory {
- my ($currentPath, $currentFile, @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,$current_path,$is_empty,$dir_list)=@_;
+ my $iconpath= $r->dir_config('lonIconsURL') . "/";
+ $r->print('
');
+ $r->print('
');
+ my $displayOut = '';
+ $r->print($displayOut);
+ $r->print('
');
+ &close_form($r);
+}
+
+sub delete_confirmed {
+ my ($r)=@_;
+ my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
+ $ENV{'user.domain'},'portfolio'.
+ $ENV{'form.currentpath'}.
+ $ENV{'form.selectfile'});
+ if ($result ne 'ok') {
+ $r->print(' An error occured ('.$result.
+ ') while trying to delete '.&display_file().' ');
+ }
+ $r->print(&done());
+}
+
+sub delete_dir {
+ my ($r)=@_;
+ &open_form($r);
+ $r->print('
'.&mt('Delete').' '.&display_file().'?
');
+ &close_form($r);
+}
+
+sub delete_dir_confirmed {
+ my ($r)=@_;
+ my $directory_name = $ENV{'form.currentpath'};
+ $directory_name =~ m/\/$/;
+ $directory_name = $`;
+ my $result=&Apache::lonnet::removeuserfile($ENV{'user.name'},
+ $ENV{'user.domain'},'portfolio'.
+ $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());
+}
+
+sub rename {
+ my ($r)=@_;
+ &open_form($r);
+ $r->print('
'.&mt('Rename').' '.&display_file().' to
+ ?
');
+ &close_form($r);
+}
+
+sub rename_confirmed {
+ my ($r)=@_;
+ my $filenewname=&Apache::lonnet::clean_filename($ENV{'form.filenewname'});
+ if ($filenewname eq '') {
+ $r->print(''.
+ &mt("Error: no valid filename was provided to rename to.").
+ ' ');
+ $r->print(&done());
+ return;
+ }
+ my $result=
+ &Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'},
+ 'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'},
+ 'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.filenewname'});
+ if ($result ne 'ok') {
+ $r->print(' An errror occured ('.$result.
+ ') while trying to rename '.&display_file().' to '.
+ &display_file(undef,$filenewname).' ');
+ }
+ $r->print(&done());
+}
+sub select_files {
+ my ($r)=@_;
+ my $java_script =(<
+ function finishSelect() {
+ opener.document.forms.lonhomework.selectedfiles.value='files were selected';
+ self.close();
}
-
+
+ENDSMP
+ $r->print($java_script);
+ $r->print("
Select portfolio files
+ Check as many as you wish in response to the essay problem. ");
+ my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
+ $ENV{'user.name'}).
+ '/userfiles/portfolio';
+ my $current_path='/';
+ if ($ENV{'form.currentpath'}) {
+ $current_path = $ENV{'form.currentpath'};
}
- return $displayOut;
+ my @dir_list=&Apache::lonnet::dirlist($current_path,
+ $ENV{'user.domain'},
+ $ENV{'user.name'},$portfolio_root);
+ if ($dir_list[0] eq 'no_such_dir'){
+ # two main reasons for this:
+ # 1) never been here, so directory structure not created
+ # 2) back-button navigation after deleting a directory
+ if ($current_path eq '/'){
+ &Apache::lonnet::mkdiruserfile($ENV{'user.name'},
+ $ENV{'user.domain'},'portfolio');
+ } else {
+ # some directory that snuck in get rid of the directory
+ # from the recent pulldown, just in case
+ &Apache::lonhtmlcommon::remove_recent('portfolio',
+ [$current_path]);
+ $current_path = '/'; # force it back to the root
+ }
+ # now grab the directory list again, for the first time
+ @dir_list=&Apache::lonnet::dirlist($current_path,
+ $ENV{'user.domain'},
+ $ENV{'user.name'},$portfolio_root);
+ }
+ # need to know if directory is empty so it can be removed if desired
+ my $is_empty=(@dir_list == 2);
+ &display_common($r,$current_path,$is_empty,\@dir_list);
+ &display_file_select($r,$current_path,$is_empty,\@dir_list);
+ $r->print("