237 lines
6.9 KiB
Perl
237 lines
6.9 KiB
Perl
package WebGUI::Asset::FilePile;
|
|
|
|
=head1 LEGAL
|
|
|
|
-------------------------------------------------------------------
|
|
WebGUI is Copyright 2001-2004 Plain Black Corporation.
|
|
-------------------------------------------------------------------
|
|
Please read the legal notices (docs/legal.txt) and the license
|
|
(docs/license.txt) that came with this distribution before using
|
|
this software.
|
|
-------------------------------------------------------------------
|
|
http://www.plainblack.com info@plainblack.com
|
|
-------------------------------------------------------------------
|
|
|
|
=cut
|
|
|
|
use strict;
|
|
use WebGUI::Asset;
|
|
use WebGUI::HTTP;
|
|
use WebGUI::Icon;
|
|
use WebGUI::Session;
|
|
use WebGUI::SQL;
|
|
use WebGUI::Storage;
|
|
use WebGUI::TabForm;
|
|
use WebGUI::Utility;
|
|
|
|
our @ISA = qw(WebGUI::Asset);
|
|
|
|
|
|
=head1 NAME
|
|
|
|
Package WebGUI::Asset::FilePile
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
Provides a mechanism to upload files to WebGUI.
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
use WebGUI::Asset::FilePile;
|
|
|
|
|
|
=head1 METHODS
|
|
|
|
These methods are available from this class:
|
|
|
|
=cut
|
|
|
|
#-------------------------------------------------------------------
|
|
sub edit {
|
|
my $self = shift;
|
|
my $tabform = WebGUI::TabForm->new();
|
|
$tabform->hidden({
|
|
name=>"func",
|
|
value=>"add"
|
|
});
|
|
$tabform->hidden({
|
|
name=>"doit",
|
|
value=>"1"
|
|
});
|
|
$tabform->hidden({
|
|
name=>"class",
|
|
value=>"WebGUI::Asset::FilePile"
|
|
});
|
|
if ($session{form}{proceed}) {
|
|
$tabform->hidden({
|
|
name=>"proceed",
|
|
value=>$session{form}{proceed}
|
|
});
|
|
}
|
|
$tabform->addTab("properties",WebGUI::International::get("properties","Asset"));
|
|
$tabform->getTab("properties")->yesNo(
|
|
-name=>"hideFromNavigation",
|
|
-value=>1,
|
|
-label=>WebGUI::International::get(886),
|
|
-uiLevel=>6
|
|
);
|
|
$tabform->getTab("properties")->yesNo(
|
|
-name=>"newWindow",
|
|
-value=>0,
|
|
-label=>WebGUI::International::get(940),
|
|
-uiLevel=>6
|
|
);
|
|
$tabform->addTab("security",WebGUI::International::get(107),6);
|
|
$tabform->getTab("security")->dateTime(
|
|
-name=>"startDate",
|
|
-label=>WebGUI::International::get(497),
|
|
-value=>$self->get("startDate"),
|
|
-uiLevel=>6
|
|
);
|
|
$tabform->getTab("security")->dateTime(
|
|
-name=>"endDate",
|
|
-label=>WebGUI::International::get(498),
|
|
-value=>$self->get("endDate"),
|
|
-uiLevel=>6
|
|
);
|
|
my $subtext;
|
|
if (WebGUI::Grouping::isInGroup(3)) {
|
|
$subtext = manageIcon('op=listUsers');
|
|
} else {
|
|
$subtext = "";
|
|
}
|
|
my $clause;
|
|
if (WebGUI::Grouping::isInGroup(3)) {
|
|
my $contentManagers = WebGUI::Grouping::getUsersInGroup(4,1);
|
|
push (@$contentManagers, $session{user}{userId});
|
|
$clause = "userId in (".quoteAndJoin($contentManagers).")";
|
|
} else {
|
|
$clause = "userId=".quote($self->get("ownerUserId"));
|
|
}
|
|
my $users = WebGUI::SQL->buildHashRef("select userId,username from users where $clause order by username");
|
|
$tabform->getTab("security")->selectList(
|
|
-name=>"ownerUserId",
|
|
-options=>$users,
|
|
-label=>WebGUI::International::get(108),
|
|
-value=>[$self->get("ownerUserId")],
|
|
-subtext=>$subtext,
|
|
-uiLevel=>6
|
|
);
|
|
$tabform->getTab("security")->group(
|
|
-name=>"groupIdView",
|
|
-label=>WebGUI::International::get(872),
|
|
-value=>[$self->get("groupIdView")],
|
|
-uiLevel=>6
|
|
);
|
|
$tabform->getTab("security")->group(
|
|
-name=>"groupIdEdit",
|
|
-label=>WebGUI::International::get(871),
|
|
-value=>[$self->get("groupIdEdit")],
|
|
-excludeGroups=>[1,7],
|
|
-uiLevel=>6
|
|
);
|
|
$tabform->getTab("properties")->readOnly(
|
|
-label=>WebGUI::International::get("upload files", "Asset");
|
|
-value=>$self->getUploadControl
|
|
);
|
|
return $self->getAdminConsole->render($tabform->print,
|
|
WebGUI::International::get("add pile", "Asset");
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
sub editSave {
|
|
my $class = shift;
|
|
my $parent = WebGUI::Asset->newByUrl;
|
|
my $tempStorage = WebGUI::Storage->create;
|
|
$tempStorage->addFileFromFormPost("file");
|
|
foreach my $filename (@{$tempStorage->getFiles}) {
|
|
my $storage = WebGUI::Storage->create;
|
|
$storage->addFileFromFilesystem($tempStorage->getPath($filename));
|
|
my %data;
|
|
my $class = 'WebGUI::Asset::File';
|
|
$class = "WebGUI::Asset::File::Image" if (isIn($storage->getFileExtension($filename),qw(jpg jpeg gif png)));
|
|
foreach my $definition (@{$class->definition}) {
|
|
foreach my $property (keys %{$definition->{properties}}) {
|
|
$data{$property} = WebGUI::FormProcessor::process(
|
|
$property,
|
|
$definition->{properties}{$property}{fieldType},
|
|
$definition->{properties}{$property}{defaultValue}
|
|
);
|
|
}
|
|
}
|
|
$data{className} = $class;
|
|
$data{storageId} = $storage->getId;
|
|
$data{filename} = $data{title} = $data{menuTitle} = $filename;
|
|
$data{url} = $parent->getUrl.'/'.$filename;
|
|
my $newAsset = $parent->addChild(\%data);
|
|
$newAsset->setSize($storage->getFileSize($filename));
|
|
$newAsset->generateThumbnail if ($class eq "WebGUI::Asset::File::Image");
|
|
}
|
|
$tempStorage->delete;
|
|
return $parent->www_manageAssets if ($session{form}{proceed} eq "manageAssets");
|
|
return $parent->www_view;
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
sub getIcon {
|
|
my $self = shift;
|
|
my $small = shift;
|
|
if ($small) {
|
|
return $session{config}{extrasURL}.'/assets/small/folder.gif';
|
|
}
|
|
return $session{config}{extrasURL}.'/assets/folder.gif';
|
|
}
|
|
|
|
|
|
#-------------------------------------------------------------------
|
|
|
|
=head2 getName
|
|
|
|
Returns the displayable name of this asset.
|
|
|
|
=cut
|
|
|
|
sub getName {
|
|
return "File Pile";
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
sub getUploadControl {
|
|
my $self = shift;
|
|
WebGUI::Style::setScript($session{config}{extrasURL}.'/FileUploadControl.js',{type=>"text/javascript"});
|
|
my $uploadControl = '<div id="fileUploadControl"> </div>
|
|
<script>
|
|
var images = new Array();
|
|
';
|
|
opendir(DIR,$session{config}{extrasPath}.'/fileIcons');
|
|
my @files = readdir(DIR);
|
|
closedir(DIR);
|
|
foreach my $file (@files) {
|
|
unless ($file eq "." || $file eq "..") {
|
|
my $ext = $file;
|
|
$ext =~ s/(.*?)\.gif/$1/;
|
|
$uploadControl .= 'images["'.$ext.'"] = "'.$session{config}{extrasURL}.'/fileIcons/'.$file.'";'."\n";
|
|
}
|
|
}
|
|
$uploadControl .= 'var uploader = new FileUploadControl("fileUploadControl", images);
|
|
uploader.addRow();
|
|
</script>';
|
|
return $uploadControl;
|
|
}
|
|
|
|
|
|
#-------------------------------------------------------------------
|
|
sub www_edit {
|
|
my $self = shift;
|
|
unless ($session{form}{doit}) {
|
|
return $self->edit;
|
|
} else {
|
|
return $self->editSave;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|
|
|