Missing session variables in Operation subroutines.

Forward port of Form/File,Image big fixes.
This commit is contained in:
Colin Kuskie 2006-01-26 18:07:56 +00:00
parent d35d57e1b8
commit 8639f53783
6 changed files with 72 additions and 50 deletions

View file

@ -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

View file

@ -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!<img src="%s" /><br />!, $location->getUrl($file);
my $action = join '_', '_', $self->get("name"), 'delete';
$fileForm .= $i18n->get(392)
. "&nbsp"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!<img src="%s" /><br />!, $location->getFileIconUrl($file);
$fileForm .= $i18n->get(392)
. "&nbsp"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!<img src="%s" />&nbsp;%s!, $location->getFileIconUrl($_), $_; } @{ $location->getFiles };
my $fileValue = join "<br />\n", @files;
return $fileValue;
my $file = shift @{ $location->getFiles };
my $fileValue = sprintf qq!<img src="%s" />&nbsp;%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();
</script>';
</script>!, $self->get("name"), $i18n->get("removeLabel"), 1;
$uploadControl .= WebGUI::Form::Hidden->new($self->session, {-name => $self->privateName('action'), -value => 'upload'})->toHtml();
return $uploadControl;
}

View file

@ -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!<img src="%s" /><br />!, $location->getUrl($file);
$fileForm .= $i18n->get(392)
. "&nbsp"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!<img src="%s" />!, $location->getUrl($_) } @{ $location->getFiles };
my $fileValue = join "<br />\n", @files;
my $file = shift @{ $location->getFiles };
my $fileValue = sprintf qq!<img src="%s" />&nbsp;%s!, $location->getUrl($file), $file;
return $fileValue;
}

View file

@ -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('<ul>'.$error.'</ul>') 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);
}
#-------------------------------------------------------------------

View file

@ -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() },
);

View file

@ -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 = '<h1>'.$i18n->get(37).'</h1>';