diff --git a/lib/WebGUI/Form/Control.pm b/lib/WebGUI/Form/Control.pm index 830bd2016..bc417e1fc 100644 --- a/lib/WebGUI/Form/Control.pm +++ b/lib/WebGUI/Form/Control.pm @@ -48,6 +48,20 @@ The following methods are available via this package. =cut +#------------------------------------------------------------------- + +=head2 privateName ( ) + +Creates a safe, private name for additional use in multi-part forms +like File and Image. + +=cut + +sub privateName { + my ($self, $action) = @_; + return join '_', '_', $self->get('name'), $action; +} + #------------------------------------------------------------------- =head2 definition ( $session, [ additionalTerms ] ) @@ -314,7 +328,7 @@ sub getName { =head2 fixMacros ( string ) -Returns the string having converted all macros in the string to HTML entities so that they won't be processed my the macro engine, but instead will be displayed. +Returns the string having converted all macros in the string to HTML entities so that they won't be processed by the macro engine, but instead will be displayed. =head3 string diff --git a/lib/WebGUI/Form/File.pm b/lib/WebGUI/Form/File.pm index 7cc1fd4d1..7be48ed6d 100644 --- a/lib/WebGUI/Form/File.pm +++ b/lib/WebGUI/Form/File.pm @@ -51,10 +51,6 @@ The following additional parameters have been added via this sub class. If no name is specified a default name of "file" will be used. -=head4 maxAttachments - -Defaults to 1. Determines how many files the user can upload with this form control. - =head4 profileEnabled Flag that tells the User Profile system that this is a valid form element in a User Profile @@ -73,9 +69,6 @@ sub definition { name=>{ defaultValue=>"file" }, - maxAttachments=>{ - defaultValue=>1 - }, profileEnabled=>{ defaultValue=>1 }, @@ -87,7 +80,7 @@ sub definition { =head2 displayForm ( ) -If an image is uploaded, then return the image and a control to +If an file is uploaded, then return an icon for that file's type and a control to delete it. Otherwise, display a form element to upload a file. =cut @@ -95,21 +88,18 @@ delete it. Otherwise, display a form element to upload a file. sub displayForm { my ($self) = @_; return $self->toHtml unless $self->get("value"); - ##There are files inside here, for each one, display the image + ##There are files inside here, for each one, display the file icon ##and another form control for deleting it. my $location = WebGUI::Storage->get($self->session,$self->get("value")); - my $id = $location->getId; my $fileForm = ''; my $i18n = WebGUI::International->new($self->session); - foreach my $file ( @{ $location->getFiles } ) { - $fileForm .= sprintf qq!
!, $location->getUrl($file); - my $action = join '_', '_', $self->get("name"), 'delete'; - $fileForm .= $i18n->get(392) - . " "x4 - . WebGUI::Form::YesNo->new($self->session,{-name=>$action, -value=>0})->toHtml; - } - my $hid = $self->toHtmlAsHidden(); - $fileForm .= $hid; + my $file = shift @{ $location->getFiles }; + $fileForm .= sprintf qq!
!, $location->getFileIconUrl($file); + $fileForm .= $i18n->get(392) + . " "x4 + . WebGUI::Form::YesNo->new($self->session,{-name=>$self->privateName('delete'), -value=>0})->toHtml; + $fileForm .= $self->toHtmlAsHidden(); + $fileForm .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'keep'})->toHtml(); return $fileForm; } @@ -126,10 +116,9 @@ sub displayValue { my ($self) = @_; return '' unless $self->get("value"); my $location = WebGUI::Storage->get($self->session,$self->get("value")); - local $_; - my @files = map { sprintf qq! %s!, $location->getFileIconUrl($_), $_; } @{ $location->getFiles }; - my $fileValue = join "
\n", @files; -return $fileValue; + my $file = shift @{ $location->getFiles }; + my $fileValue = sprintf qq! %s!, $location->getFileIconUrl($file), $file; + return $fileValue; } #------------------------------------------------------------------- @@ -145,20 +134,18 @@ deleting the file if it was specified. sub getValueFromPost { my $self = shift; my $value = $self->session->form->param($self->get("name")); - if ($self->session->form->param(join '_', '_', $self->get("name"), 'delete')) { + if ($self->session->form->param($self->privateName('delete'))) { my $storage = WebGUI::Storage->get($self->session,$value); $storage->delete; return ''; } - else { + elsif ($self->session->form->param($self->privateName('action')) eq 'keep') { + return $value; + } + elsif ($self->session->form->param($self->privateName('action')) eq 'upload') { my $storage; - if ($value) { - $storage = WebGUI::Storage::Image->get($self->session,$value); - } - else { - $storage = WebGUI::Storage::Image->create($self->session); - } - $storage->addFileFromFormPost($self->get("name")); + $storage = WebGUI::Storage::Image->create($self->session); + $storage->addFileFromFormPost($self->get("name"), 1); my @files = @{ $storage->getFiles }; if (scalar(@files) < 1) { $storage->delete; @@ -195,9 +182,10 @@ sub toHtml { } } my $i18n = WebGUI::International->new($self->session); - $uploadControl .= 'var uploader = new FileUploadControl("'.$self->get("name").'", fileIcons, "'.$i18n->get('removeLabel','WebGUI').'","'.$self->get("maxAttachments").'"); + $uploadControl .= sprintf q!var uploader = new FileUploadControl("%s", fileIcons, "%s","%d"); uploader.addRow(); - '; + !, $self->get("name"), $i18n->get("removeLabel"), 1; + $uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'upload'})->toHtml(); return $uploadControl; } diff --git a/lib/WebGUI/Form/Image.pm b/lib/WebGUI/Form/Image.pm index db38f25ee..e5234c584 100644 --- a/lib/WebGUI/Form/Image.pm +++ b/lib/WebGUI/Form/Image.pm @@ -52,10 +52,6 @@ The following additional parameters have been added via this sub class. If no name is specified a default name of "file" will be used. -=head4 maxAttachments - -Defaults to 1. Determines how many files the user can upload with this form control. - =head4 profileEnabled Flag that tells the User Profile system that this is a valid form element in a User Profile @@ -72,10 +68,7 @@ sub definition { defaultValue=>$i18n->get("image") }, name=>{ - defaultValue=>"file" - }, - maxAttachments=>{ - defaultValue=>1 + defaultValue=>"image" }, profileEnabled=>{ defaultValue=>1 @@ -85,6 +78,33 @@ sub definition { } +#------------------------------------------------------------------- + +=head2 displayForm ( ) + +If an image is uploaded, then return the image and a control to +delete it. Otherwise, display a form element to upload a file. + +=cut + +sub displayForm { + my ($self) = @_; + return $self->toHtml unless $self->get('value'); + ##There are files inside here, for each one, display the image + ##and another form control for deleting it. + my $location = WebGUI::Storage->get($self->session, $self->get('value')); + my $i18n = WebGUI::International->new($self->session); + my $fileForm = ''; + my $file = shift @{ $location->getFiles }; + $fileForm .= sprintf qq!
!, $location->getUrl($file); + $fileForm .= $i18n->get(392) + . " "x4 + . WebGUI::Form::YesNo->new($self->session, {-name=>$self->privateName('delete'), -value=>0})->toHtml; + $fileForm .= $self->toHtmlAsHidden(); + $fileForm .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'keep'})->toHtml(); + return $fileForm; +} + #------------------------------------------------------------------- =head2 displayValue ( ) @@ -99,9 +119,8 @@ sub displayValue { my ($self) = @_; return '' unless $self->get("value"); my $location = WebGUI::Storage->get($self->session,$self->get("value")); - local $_; - my @files = map { sprintf qq!!, $location->getUrl($_) } @{ $location->getFiles }; - my $fileValue = join "
\n", @files; + my $file = shift @{ $location->getFiles }; + my $fileValue = sprintf qq! %s!, $location->getUrl($file), $file; return $fileValue; } diff --git a/lib/WebGUI/Operation/Profile.pm b/lib/WebGUI/Operation/Profile.pm index 87e091e0a..687b35230 100644 --- a/lib/WebGUI/Operation/Profile.pm +++ b/lib/WebGUI/Operation/Profile.pm @@ -132,9 +132,9 @@ sub www_editProfile { sub www_editProfileSave { my $session = shift; my ($profile, $fieldName, $error, $u, $warning); - return WebGUI::Operation::Auth::www_auth("init") if ($session->user->userId eq '1'); + return WebGUI::Operation::Auth::www_auth($session, "init") if ($session->user->userId eq '1'); - ($profile, $error, $warning) = validateProfileData(); + ($profile, $error, $warning) = validateProfileData($session); $error .= $warning; return www_editProfile('') if($error ne ""); @@ -144,7 +144,7 @@ sub www_editProfileSave { $u->profileField($fieldName,$profile->{$fieldName}); } $session->user({user=>$u}); - return WebGUI::Operation::Auth::www_auth(); + return WebGUI::Operation::Auth::www_auth($session); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Operation/Shared.pm b/lib/WebGUI/Operation/Shared.pm index 35f694bbb..008327636 100644 --- a/lib/WebGUI/Operation/Shared.pm +++ b/lib/WebGUI/Operation/Shared.pm @@ -77,6 +77,7 @@ sub secureEval { my %trusted = ( 'WebGUI::International::get' => sub {$i18n->get(@_)}, 'WebGUI::International::getLanguages' => sub { $i18n->getLanguages(@_) }, + 'WebGUI::DateTime::epochToHuman' => sub { $session->datetime->epochToHuman(@_) }, '$session->datetime->epochToHuman' => sub { $session->datetime->epochToHuman(@_) }, 'WebGUI::Icon::getToolbarOptions' => sub { $session->icon->getToolbarOptions() }, ); diff --git a/lib/WebGUI/Session/Privilege.pm b/lib/WebGUI/Session/Privilege.pm index e8122edf3..14298790a 100644 --- a/lib/WebGUI/Session/Privilege.pm +++ b/lib/WebGUI/Session/Privilege.pm @@ -130,7 +130,7 @@ sub noAccess { my $self = shift; $self->session->http->setStatus("401", "No Access"); if ($self->session->user->userId eq '1') { - return WebGUI::Operation::Auth::www_auth("init"); + return WebGUI::Operation::Auth::www_auth($self->session, "init"); } else { my $i18n = WebGUI::International->new($self->session); my $output = '

'.$i18n->get(37).'

';