is a hash reference of parameters with the following keys:
errors -> An array reference of error messages to the user
=cut
sub www_editAdSpace {
my $session = shift;
my $adSpace = shift;
my $params = shift;
return $session->privilege->insufficient unless canView($session);
my $i18n = WebGUI::International->new( $session, "AdSpace" );
my $ac = WebGUI::AdminConsole->new( $session, "adSpace" );
my $f = WebGUI::HTMLForm->new($session);
# Get the adspace we're working with
my $id;
if ( $adSpace ) {
$id = $adSpace->getId;
} else {
$id = $session->form->param("adSpaceId") || "new";
$adSpace = WebGUI::AdSpace->new($session, $id);
}
if ( $adSpace ) {
$ac->addSubmenuItem(
$session->url->page("op=editAd;adSpaceId=".$id), $i18n->get("add an ad")
);
}
$ac->addSubmenuItem(
$session->url->page("op=manageAdSpaces"), $i18n->get("manage ad spaces")
);
# Give the errors to the user
if ( $params->{errors} ) {
$f->raw( '' . $i18n->get('error heading') . '
'
. ''
. join( "", map { '- ' . $_ . '
' } @{ $params->{errors} } )
. '
'
);
}
# Build the form
$f->submit;
$f->hidden( name => "adSpaceId", value => $id );
$f->readOnly( label => $i18n->get("ad space id"), value => $id );
$f->hidden( name => "op", value => "editAdSpaceSave" );
$f->text(
name => "name",
value => $session->form->get('name') || ($adSpace && $adSpace->get("name")),
hoverHelp => $i18n->get("name help"),
label => $i18n->get("name"),
);
$f->text(
name => "title",
value => $session->form->get('title') || ($adSpace && $adSpace->get('title')),
hoverHelp => $i18n->get("title help"),
label => $i18n->get("title"),
);
$f->textarea(
name => "description",
value => $session->form->get('description') || ($adSpace && $adSpace->get('description')),
hoverHelp => $i18n->get("description help"),
label => $i18n->get("description"),
);
$f->integer(
name => "minimumClicks",
value => $session->form->get('minimumClicks') || ($adSpace && $adSpace->get('minimumClicks')),
defaultValue => 1000,
hoverHelp => $i18n->get("minimum clicks help"),
label => $i18n->get("minimum clicks"),
);
$f->integer(
name => "minimumImpressions",
value => $session->form->get('minimumImpressions') || ($adSpace && $adSpace->get('minimumImpressions')),
defaultValue => 1000,
hoverHelp => $i18n->get("minimum impressions help"),
label => $i18n->get("minimum impressions"),
);
$f->integer(
name => "width",
value => $session->form->get('width') || ($adSpace && $adSpace->get('width')),
defaultValue => 468,
hoverHelp => $i18n->get("width help"),
label => $i18n->get("width"),
);
$f->integer(
name => "height",
value => $session->form->get('height') || ($adSpace && $adSpace->get('height')),
defaultValue => 60,
hoverHelp => $i18n->get("height help"),
label => $i18n->get("height"),
);
$f->submit;
# Show the ads in this adspace.
my $ads = "";
my $code = "";
if ( $adSpace ) {
$code = ''.$i18n->get("macro code prompt").'
^AdSpace('.$adSpace->get("name").');
';
my $rs = $session->db->read("select adId, title, renderedAd from advertisement where adSpaceId=?",[$id]);
while (my ($adId, $title, $ad) = $rs->array) {
$ads .= ''.$session->icon->delete("op=deleteAd;adSpaceId=".$id.";adId=".$adId, undef, $i18n->get("confirm ad delete"))
. $session->icon->edit( "op=editAd;adSpaceId=" . $id . ";adId=" . $adId )
. ' ' . $title . '
' . $ad . '
'
;
}
$ads .= '';
}
return $ac->render($code.$f->print.$ads, $i18n->get("edit ad space"));
}
#-------------------------------------------------------------------
=head2 www_editAdSpaceSave ( )
Save the www_editAdSpace method.
=cut
sub www_editAdSpaceSave {
my $session = shift;
return $session->privilege->insufficient unless canView($session);
my $i18n = WebGUI::International->new( $session, "AdSpace" );
my %properties = (
name => $session->form->process("name", "text"),
title => $session->form->process("title", "text"),
description => $session->form->process("description", "textarea"),
width => $session->form->process("width", "integer"),
height => $session->form->process("height", "integer"),
minimumClicks => $session->form->process("minimumClicks", "integer"),
minimumImpressions => $session->form->process("minimumImpressions", "integer"),
);
### Validate form entry
my @errors;
# Adspace titles cannot contain ] characters because of caching in the Layout asset
if ( $properties{name} =~ /[\]]/ ) {
push @errors, $i18n->get('error invalid characters');
}
if ( @errors ) {
return www_editAdSpace( $session, undef, { errors => \@errors } );
}
# Create the new Ad Space
if ($session->form->param("adSpaceId") eq "new") {
my $adSpace = WebGUI::AdSpace->create($session, \%properties);
return www_editAdSpace($session, $adSpace);
}
# Edit the existing Ad Space
else {
my $adSpace = WebGUI::AdSpace->new($session, $session->form->param("adSpaceId"));
$adSpace->set(\%properties);
}
return www_manageAdSpaces($session);
}
#-------------------------------------------------------------------
=head2 www_manageAdSpaces ( )
Manage ad spaces.
=cut
sub www_manageAdSpaces {
my $session = shift;
return $session->privilege->insufficient unless canView($session);
my $ac = WebGUI::AdminConsole->new($session,"adSpace");
my $i18n = WebGUI::International->new($session,"AdSpace");
my $output = "";
foreach my $adSpace (@{WebGUI::AdSpace->getAdSpaces($session)}) {
$output .= ''
.$session->icon->delete("op=deleteAdSpace;adSpaceId=".$adSpace->getId, undef, $i18n->get("confirm ad space delete"))
.$session->icon->edit("op=editAdSpace;adSpaceId=".$adSpace->getId)
.' '.$adSpace->get("title").'
'
.$adSpace->displayImpression(1)
.'
';
}
$output .= '';
$ac->addSubmenuItem($session->url->page("op=editAdSpace"), $i18n->get("add ad space"));
return $ac->render($output);
}
1;