From 27356b09f61e66b598d122f9f01e22f08c3579a7 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sat, 25 Dec 2004 16:07:28 +0000 Subject: [PATCH] added file pile --- docs/changelog/6.x.x.txt | 2 + lib/WebGUI/Asset.pm | 4 +- lib/WebGUI/Asset/FilePile.pm | 241 +++++++++++++++++++++++++++++++++++ lib/WebGUI/Storage.pm | 10 +- 4 files changed, 249 insertions(+), 8 deletions(-) create mode 100644 lib/WebGUI/Asset/FilePile.pm diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 722dc9708..be50a8f71 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -48,6 +48,8 @@ - bugfix [1073753]. bug in WebGUI::Search (Leendert Bottelberghs). - Added an e-commerce system. Thanks to Atomic Learning for funding this feature. + - Added new asset type: File Pile. This allows you to do a mass upload of + files and images. 6.2.9 - bugfix [ 1058105 ] input tag has to be closed with / diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 683fec25f..c4c42b3d9 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -620,8 +620,8 @@ sub processPropertiesFromFormPost { foreach my $property (keys %{$definition->{properties}}) { $data{$property} = WebGUI::FormProcessor::process( $property, - $definition->{properties}{fieldType}, - $definition->{properties}{defaultValue} + $definition->{properties}{$property}{fieldType}, + $definition->{properties}{$property}{defaultValue} ); } } diff --git a/lib/WebGUI/Asset/FilePile.pm b/lib/WebGUI/Asset/FilePile.pm new file mode 100644 index 000000000..72ae5b075 --- /dev/null +++ b/lib/WebGUI/Asset/FilePile.pm @@ -0,0 +1,241 @@ +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::Template; + +our @ISA = qw(WebGUI::Asset); + + +=head1 NAME + +Package WebGUI::Asset::File + +=head1 DESCRIPTION + +Provides a mechanism to upload files to WebGUI. + +=head1 SYNOPSIS + +use WebGUI::Asset::File; + + +=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}{afterEdit}) { + $tabform->hidden({ + name=>"afterEdit", + value=>$session{form}{afterEdit} + }); + } + $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("privileges",WebGUI::International::get(107),6); + $tabform->getTab("privileges")->dateTime( + -name=>"startDate", + -label=>WebGUI::International::get(497), + -value=>$self->get("startDate"), + -uiLevel=>6 + ); + $tabform->getTab("privileges")->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("privileges")->selectList( + -name=>"ownerUserId", + -options=>$users, + -label=>WebGUI::International::get(108), + -value=>[$self->get("ownerUserId")], + -subtext=>$subtext, + -uiLevel=>6 + ); + $tabform->getTab("privileges")->group( + -name=>"groupIdView", + -label=>WebGUI::International::get(872), + -value=>[$self->get("groupIdView")], + -uiLevel=>6 + ); + $tabform->getTab("privileges")->group( + -name=>"groupIdEdit", + -label=>WebGUI::International::get(871), + -value=>[$self->get("groupIdEdit")], + -excludeGroups=>[1,7], + -uiLevel=>6 + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + $tabform->getTab("properties")->file( + -name=>"file", + -label=>"Upload File" + ); + return $self->getAdminConsole->render($tabform->print); +} + +sub editSave { + my $self = 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 $newAsset = $parent->addChild({className=>'WebGUI::Asset::File'}); + foreach my $definition (@{$self->definition}) { + foreach my $property (keys %{$definition->{properties}}) { + $data{$property} = WebGUI::FormProcessor::process( + $property, + $definition->{properties}{$property}{fieldType}, + $definition->{properties}{$property}{defaultValue} + ); + } + } + $data{filename} = $filename; + $data{storageId} = $storage->getId; + $data{title} = $data{menuTitle} = $filename; + $data{url} = $parent->getUrl.'/'.$filename; + $newAsset->update(\%data); + $newAsset->setSize($storage->getFileSize($filename)); + } + $tempStorage->delete; + return $parent->www_manageAssets if ($session{form}{afterEdit} eq "assetManager"); + 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 www_edit { + my $self = shift; + unless ($session{form}{doit}) { + return $self->edit; + } else { + return $self->editSave; + } +} + + + + +1; + diff --git a/lib/WebGUI/Storage.pm b/lib/WebGUI/Storage.pm index d56e7c2c1..69de1d34a 100644 --- a/lib/WebGUI/Storage.pm +++ b/lib/WebGUI/Storage.pm @@ -158,7 +158,7 @@ Grabs an attachment from a form POST and saves it to this storage location. =head3 formVariableName -Provide the form variable name to which the file being uploaded is assigned. +Provide the form variable name to which the file being uploaded is assigned. Note that if multiple files are uploaded with the same formVariableName then they'll all be stored in the storage location, but only the last filename will be returned. Use the getFiles() method on the storage location to get all the filenames stored. =cut @@ -166,9 +166,8 @@ sub addFileFromFormPost { my $self = shift; my $formVariableName = shift; return "" if (WebGUI::HTTP::getStatus() =~ /^413/); - my $tempPath = $session{cgi}->upload($formVariableName); - if (defined $tempPath) { - my $filename; + my $filename; + foreach my $tempPath ($session{cgi}->upload($formVariableName)) { if ($tempPath =~ /([^\/\\]+)$/) { $filename = $1; } else { @@ -193,9 +192,8 @@ sub addFileFromFormPost { $self->_addError("Couldn't open file ".$self->getPath($filename)." for writing due to error: ".$!); return undef; } - return $filename; } - return undef; + return $filename; }