Added Product wobject.

This commit is contained in:
JT Smith 2002-07-06 21:04:30 +00:00
parent 61236cae5d
commit ec4629d886
3 changed files with 1014 additions and 3 deletions

View file

@ -55,9 +55,52 @@ insert into international values (579,'WebGUI','English','Your message has been
insert into international values (580,'WebGUI','English','Your message has been denied.');
insert into international values (58,'UserSubmission','English','Previous Submission');
insert into international values (59,'UserSubmission','English','Next Submission');
insert into international values (1,'Product','English','Product');
create table Product_specification ( wobjectId int not null, productSpecificationId int not null primary key, name varchar(255), value varchar(255), units varchar(255), sequenceNumber int not null);
create table Product_feature ( wobjectId int not null, productFeatureId int not null primary key, feature varchar(255), sequenceNumber int not null);
create table Product (wobjectId int not null primary key, image1 varchar(255), image2 varchar(255), image3 varchar(255), brochure varchar(255), manual varchar(255), warranty varchar(255), price varchar(255), productNumber varchar(255));
insert into incrementer values ('productFeatureId',1000);
insert into incrementer values ('productSpecificationId',1000);
create table Product_accessory ( wobjectId int not null, AccessoryWobjectId int not null, sequenceNumber int not null, primary key (wobjectId, AccessoryWobjectId));
create table Product_related ( wobjectId int not null, RelatedWobjectId int not null, sequenceNumber int not null, primary key (wobjectId, RelatedWobjectId));
insert into international values (7,'Product','English','Product Image 1');
insert into international values (8,'Product','English','Product Image 2');
insert into international values (9,'Product','English','Product Image 3');
insert into international values (5,'Product','English','Are you certain you wish to delete this specification?');
insert into international values (4,'Product','English','Are you certain you wish to delete the relationship to this related product?');
insert into international values (3,'Product','English','Are you certain you wish to delete this feature?');
insert into international values (2,'Product','English','Are you certain you wish to delete the relationship to this accessory?');
insert into international values (6,'Product','English','Edit Product');
insert into international values (10,'Product','English','Price');
insert into international values (11,'Product','English','Product Number');
insert into international values (12,'Product','English','Are you certain you wish to delete this file?');
insert into international values (13,'Product','English','Brochure');
insert into international values (14,'Product','English','Manual');
insert into international values (15,'Product','English','Warranty');
insert into international values (16,'Product','English','Add Accessory');
insert into international values (17,'Product','English','Accessory');
insert into international values (18,'Product','English','Add another accessory?');
insert into international values (21,'Product','English','Add another related product?');
insert into international values (19,'Product','English','Add Related Product');
insert into international values (20,'Product','English','Related Product');
insert into international values (22,'Product','English','Edit Feature');
insert into international values (23,'Product','English','Feature');
insert into international values (24,'Product','English','Add another feature?');
insert into international values (25,'Product','English','Edit Specification');
insert into international values (26,'Product','English','Label');
insert into international values (27,'Product','English','Specification');
insert into international values (28,'Product','English','Add another specification?');
insert into international values (29,'Product','English','Units');
insert into international values (30,'Product','English','Features');
insert into international values (31,'Product','English','Specifications');
insert into international values (32,'Product','English','Accessories');
insert into international values (33,'Product','English','Related Products');
insert into international values (34,'Product','English','Add a feature.');
insert into international values (35,'Product','English','Add a specification.');
insert into international values (36,'Product','English','Add an accessory.');
insert into international values (37,'Product','English','Add a related product.');
insert into international values (581,'WebGUI','English','Add New Value');
insert into international values (582,'WebGUI','English','Leave Blank');

View file

@ -31,6 +31,7 @@ use WebGUI::URL;
$f = WebGUI::HTMLForm->new;
$f->checkbox("toggleGadget","Turn Gadgets On?");
$f->combo("fruit",\%fruit,"Choose a fruit or enter your own.");
$f->date("endDate","End Date",$endDate);
$f->email("emailAddress","Email Address");
$f->file("image","Image to Upload");
@ -140,6 +141,88 @@ sub checkbox {
#-------------------------------------------------------------------
=head2 combo ( name, options [ label, value, size, multiple, extras, subtext ] )
Adds a combination select list / text box row to this form. If the
text box is filled out it will have a value stored in "name"_new
where name is the first field passed into this method.
=item name
The name field for this form element.
=item options
The list of options for this select list. Should be passed as a
hash reference.
=item label
The left column label for this form row.
=item value
The default value(s) for this form element. This should be passed
as an array reference.
=item size
The number of characters tall this form element should be. Defaults
to "1".
=item multiple
A boolean value for whether this select list should allow multiple
selections. Defaults to "0".
=item extras
If you want to add anything special to this form element like
javascript actions, or stylesheet information, you'd add it in
here as follows:
'onChange="this.form.submit()"'
=item subtext
Extra text to describe this form element or to provide special
instructions.
=cut
sub combo {
my ($label, $subtext, $class, $output, $value, $key, $item, $name, $options, $size, $multiple, $extras);
$class = shift;
$name = shift;
$options = shift;
${$options}{''} = '['.WebGUI::International::get(582).']';
$label = shift;
$value = shift;
$size = shift || 1;
$multiple = shift;
$multiple = ' multiple="1"' if ($multiple);
$extras = shift;
$subtext = shift;
$output = '<select name="'.$name.'" size="'.$size.'" '.$extras.$multiple.'>';
$output .= '<option value="_new_">'.WebGUI::International::get(581).'-&gt;';
foreach $key (keys %{$options}) {
$output .= '<option value="'.$key.'"';
foreach $item (@$value) {
if ($item eq $key) {
$output .= " selected";
}
}
$output .= '>'.${$options}{$key};
}
$output .= '</select>';
$size = $session{setting}{textBoxSize}-5;
$output .= '<input type="text" name="'.$name.'_new" size="'.$size.'" maxlength="255">';
$output .= _subtext($subtext);
$output = _tableFormRow($label,$output) unless ($class->{_noTable});
$class->{_data} .= $output;
}
#-------------------------------------------------------------------
=head2 date ( name [ label, value, extras, subtext, size ] )
Adds a date row to this form.

View file

@ -0,0 +1,885 @@
package WebGUI::Wobject::Product;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black Software.
#-------------------------------------------------------------------
# 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
#-------------------------------------------------------------------
use strict;
use Tie::CPHash;
use WebGUI::Attachment;
use WebGUI::HTMLForm;
use WebGUI::Icon;
use WebGUI::International;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Wobject;
our @ISA = qw(WebGUI::Wobject);
our $namespace = "Product";
our $name = WebGUI::International::get(1,$namespace);
#-------------------------------------------------------------------
sub _fileProperty {
my ($filename, $f, $labelId, $name);
$name = shift;
$labelId = shift;
$filename = shift;
$f = WebGUI::HTMLForm->new;
if ($filename ne "") {
$f->readOnly('<a href="'.WebGUI::URL::page('func=deleteFile&file='.$name.'&wid='.$session{form}{wid}).'">'.
WebGUI::International::get(391).'</a>',WebGUI::International::get($labelId,$namespace));
} else {
$f->file($name,WebGUI::International::get($labelId,$namespace));
}
return $f->printRowsOnly;
}
#-------------------------------------------------------------------
sub _layoutStandard {
my ($output, %data, $sth, $rows, $file, @column, $i, $seperator);
tie %data, 'Tie::CPHash';
$output = $_[0]->displayTitle;
$output .= '<table width="100%" cellpadding="3" cellspacing="0" border="0"><tr><td class="content" valign="top">';
$output .= $_[0]->description;
$output .= '<b>'.WebGUI::International::get(10,$namespace).':</b> '.$_[0]->get("price").'<br>' if ($_[0]->get("price") ne "");
$output .= '<b>'.WebGUI::International::get(11,$namespace).':</b> '.$_[0]->get("productNumber") if ($_[0]->get("productNumber") ne "");
$output .= '<p>';
if ($_[0]->get("brochure")) {
$file = WebGUI::Attachment->new($_[0]->get("brochure"),$_[0]->get("wobjectId"));
$output .= '<a href="'.$file->getURL.'"><img src="'.$file->getIcon.'" border=0 align="absmiddle">'.WebGUI::International::get(13,$namespace).'</a><br>';
}
if ($_[0]->get("manual")) {
$file = WebGUI::Attachment->new($_[0]->get("manual"),$_[0]->get("wobjectId"));
$output .= '<a href="'.$file->getURL.'"><img src="'.$file->getIcon.'" border=0 align="absmiddle">'.WebGUI::International::get(14,$namespace).'</a><br>';
}
if ($_[0]->get("warranty")) {
$file = WebGUI::Attachment->new($_[0]->get("warranty"),$_[0]->get("wobjectId"));
$output .= '<a href="'.$file->getURL.'"><img src="'.$file->getIcon.'" border=0 align="absmiddle">'.WebGUI::International::get(15,$namespace).'</a><br>';
}
$output .= '</td><td valign="top">';
if ($_[0]->get("image1")) {
$file = WebGUI::Attachment->new($_[0]->get("image1"),$_[0]->get("wobjectId"));
$output .= '<a href="'.$file->getURL.'"><img src="'.$file->getThumbnail.'" border=0></a><p>';
}
if ($_[0]->get("image2")) {
$file = WebGUI::Attachment->new($_[0]->get("image2"),$_[0]->get("wobjectId"));
$output .= '<a href="'.$file->getURL.'"><img src="'.$file->getThumbnail.'" border=0></a><p>';
}
if ($_[0]->get("image3")) {
$file = WebGUI::Attachment->new($_[0]->get("image3"),$_[0]->get("wobjectId"));
$output .= '<a href="'.$file->getURL.'"><img src="'.$file->getThumbnail.'" border=0></a><p>';
}
$output .= '</td></tr></table>';
$output .= '<table border="0" cellpadding="0" cellspacing="5">';
$output .= '<tr>';
$sth = WebGUI::SQL->read("select feature,productFeatureId from Product_feature where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber");
$rows = $sth->rows;
if ($rows > 0 || $session{var}{adminOn}) {
$column[$i] = '<td valign="top" class="productFeature">';
$column[$i] .= '<div class="productFeatureHeader">'.WebGUI::International::get(30,$namespace).'</div>';
if ($session{var}{adminOn}) {
$column[$i] .= '<a href="'.WebGUI::URL::page('func=editFeature&sid=new&wid='
.$_[0]->get("wobjectId")).'">'.WebGUI::International::get(34,$namespace).'</a><p/>';
}
}
while (%data = $sth->hash) {
if ($session{var}{adminOn}) {
$column[$i] .= deleteIcon('func=deleteFeature&wid='.$_[0]->get("wobjectId").'&fid='.$data{productFeatureId})
.editIcon('func=editFeature&wid='.$_[0]->get("wobjectId").'&fid='.$data{productFeatureId})
.moveUpIcon('func=moveFeatureUp&wid='.$_[0]->get("wobjectId").'&fid='.$data{productFeatureId})
.moveDownIcon('func=moveFeatureDown&wid='.$_[0]->get("wobjectId").'&fid='.$data{productFeatureId});
}
$column[$i] .= '&middot;'.$data{feature}.'<br>';
}
if ($rows > 0 || $session{var}{adminOn}) {
$column[$i] .= '</td>';
$i++;
}
$sth->finish;
$sth = WebGUI::SQL->read("select name,value,units,productSpecificationId from Product_specification
where wobjectId=".$_[0]->get("wobjectId")." order by sequenceNumber");
$rows = $sth->rows;
if ($rows > 0 || $session{var}{adminOn}) {
$column[$i] = '<td valign="top" class="productSpecification">';
$column[$i] .= '<div class="productSpecificationHeader">'.WebGUI::International::get(31,$namespace).'</div>';
if ($session{var}{adminOn}) {
$column[$i] .= '<a href="'.WebGUI::URL::page('func=editSpecification&sid=new&wid='
.$_[0]->get("wobjectId")).'">'.WebGUI::International::get(35,$namespace).'</a><p/>';
}
}
while (%data = $sth->hash) {
if ($session{var}{adminOn}) {
$column[$i] .= deleteIcon('func=deleteSpecification&wid='.$_[0]->get("wobjectId").'&sid='.$data{productSpecificationId})
.editIcon('func=editSpecification&wid='.$_[0]->get("wobjectId").'&sid='.$data{productSpecificationId})
.moveUpIcon('func=moveSpecificationUp&wid='.$_[0]->get("wobjectId").'&sid='.$data{productSpecificationId})
.moveDownIcon('func=moveSpecificationDown&wid='.$_[0]->get("wobjectId").'&sid='.$data{productSpecificationId});
}
$column[$i] .= '&middot;<span class="productSpecificationLabel">'.$data{name}.':</span> '.$data{value}.' '.$data{units}.'<br>';
}
if ($rows > 0 || $session{var}{adminOn}) {
$column[$i] .= '</td>';
$i++;
}
$sth->finish;
$sth = WebGUI::SQL->read("select wobject.title,page.urlizedTitle,Product_accessory.accessoryWobjectId from Product_accessory,wobject,page
where Product_accessory.wobjectId=".$_[0]->get("wobjectId")."
and Product_accessory.accessoryWobjectId=wobject.wobjectId and wobject.pageId=page.pageId order by Product_accessory.sequenceNumber");
$rows = $sth->rows;
if ($rows > 0 || $session{var}{adminOn}) {
$column[$i] = '<td valign="top" class="productAccessory">';
$column[$i] .= '<div class="productAccessoryHeader">'.WebGUI::International::get(32,$namespace).'</div>';
if ($session{var}{adminOn}) {
$column[$i] .= '<a href="'.WebGUI::URL::page('func=addAccessory&wid='
.$_[0]->get("wobjectId")).'">'.WebGUI::International::get(36,$namespace).'</a><p/>';
}
}
while (%data = $sth->hash) {
if ($session{var}{adminOn}) {
$column[$i] .= deleteIcon('func=deleteAccessory&wid='.$_[0]->get("wobjectId").'&aid='.$data{accessoryWobjectId})
.moveUpIcon('func=moveAccessoryUp&wid='.$_[0]->get("wobjectId").'&aid='.$data{accessoryWobjectId})
.moveDownIcon('func=moveAccessoryDown&wid='.$_[0]->get("wobjectId").'&aid='.$data{accessoryWobjectId});
}
$column[$i] .= '&middot;<a href="'.WebGUI::URL::gateway($data{urlizedTitle}).'">'.$data{title}.'</a><br>';
}
if ($rows > 0 || $session{var}{adminOn}) {
$column[$i] .= '</td>';
$i++;
}
$sth->finish;
$sth = WebGUI::SQL->read("select wobject.title,page.urlizedTitle,Product_related.relatedWobjectId from Product_related,wobject,page
where Product_related.wobjectId=".$_[0]->get("wobjectId")."
and Product_related.relatedWobjectId=wobject.wobjectId and wobject.pageId=page.pageId order by Product_related.sequenceNumber");
$rows = $sth->rows;
if ($rows > 0 || $session{var}{adminOn}) {
$column[$i] = '<td valign="top" class="productRelated">';
$column[$i] .= '<div class="productRelatedHeader">'.WebGUI::International::get(33,$namespace).'</div>';
if ($session{var}{adminOn}) {
$column[$i] .= '<a href="'.WebGUI::URL::page('func=addRelated&wid='
.$_[0]->get("wobjectId")).'">'.WebGUI::International::get(37,$namespace).'</a><p/>';
}
}
while (%data = $sth->hash) {
if ($session{var}{adminOn}) {
$column[$i] .= deleteIcon('func=deleteRelated&wid='.$_[0]->get("wobjectId").'&rid='.$data{relatedWobjectId})
.moveUpIcon('func=moveRelatedUp&wid='.$_[0]->get("wobjectId").'&rid='.$data{relatedWobjectId})
.moveDownIcon('func=moveRelatedDown&wid='.$_[0]->get("wobjectId").'&rid='.$data{relatedWobjectId});
}
$column[$i] .= '&middot;<a href="'.WebGUI::URL::gateway($data{urlizedTitle}).'">'.$data{title}.'</a><br>';
}
if ($rows > 0 || $session{var}{adminOn}) {
$column[$i] .= '</td>';
$i++;
}
$sth->finish;
$seperator = '<td class="productAttributeSeperator"><img src="'.$session{setting}{lib}.'/spacer.gif" width="1" height="1"></td>';
$output .= join($seperator,@column);
$output .= '</tr>';
$output .= '</table>';
return $_[0]->processMacros($output);
}
#-------------------------------------------------------------------
sub _reorderAccessories {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select accessoryWobjectId from
Product_accessory where wobjectId=$_[0] order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update Product_accessory set sequenceNumber='$i'
where wobjectId=$_[0] and accessoryWobjectId=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub _reorderFeatures {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select productFeatureId from
Product_feature where wobjectId=$_[0] order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update Product_feature set sequenceNumber='$i' where productFeatureId=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub _reorderRelated {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select relatedWobjectId from
Product_related where wobjectId=$_[0] order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update Product_related set sequenceNumber='$i'
where wobjectId=$_[0] and relatedWobjectId=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub _reorderSpecifications {
my ($sth, $i, $id);
$sth = WebGUI::SQL->read("select productSpecificationId from
Product_specification where wobjectId=$_[0] order by sequenceNumber");
while (($id) = $sth->array) {
WebGUI::SQL->write("update Product_specification set sequenceNumber='$i' where productSpecificationId=$id");
$i++;
}
$sth->finish;
}
#-------------------------------------------------------------------
sub duplicate {
my ($w, $file, %data, $newId, $sth);
tie %data, 'Tie::CPHash';
$w = $_[0]->SUPER::duplicate($_[1]);
$w = WebGUI::Wobject::Product->new({wobjectId=>$w,namespace=>$namespace});
$w->set({
image1=>$_[0]->get("image1"),
image2=>$_[0]->get("image2"),
image3=>$_[0]->get("image3"),
warranty=>$_[0]->get("warranty"),
manual=>$_[0]->get("manual"),
brochure=>$_[0]->get("brochure"),
price=>$_[0]->get("price"),
productNumber=>$_[0]->get("productNumber")
});
$file = WebGUI::Attachment->new($_[0]->get("image1"),$_[0]->get("wobjectId"));
$file->copy($w->get("wobjectId"));
$file = WebGUI::Attachment->new($_[0]->get("image2"),$_[0]->get("wobjectId"));
$file->copy($w->get("wobjectId"));
$file = WebGUI::Attachment->new($_[0]->get("image3"),$_[0]->get("wobjectId"));
$file->copy($w->get("wobjectId"));
$file = WebGUI::Attachment->new($_[0]->get("manual"),$_[0]->get("wobjectId"));
$file->copy($w->get("wobjectId"));
$file = WebGUI::Attachment->new($_[0]->get("brochure"),$_[0]->get("wobjectId"));
$file->copy($w->get("wobjectId"));
$file = WebGUI::Attachment->new($_[0]->get("warranty"),$_[0]->get("wobjectId"));
$file->copy($w->get("wobjectId"));
$sth = WebGUI::SQL->read("select * from Product_feature where wobjectId=".$_[0]->get("wobjectId"));
while (%data = $sth->hash) {
$newId = getNextId("productFeatureId");
WebGUI::SQL->write("insert into Product_feature values (".$w->get("wobjectId").", $newId, "
.quote($data{feature}).", $data{sequenceNumber})");
}
$sth->finish;
$sth = WebGUI::SQL->read("select * from Product_specification where wobjectId=".$_[0]->get("wobjectId"));
while (%data = $sth->hash) {
$newId = getNextId("productSpecificationId");
WebGUI::SQL->write("insert into Product_specification values (".$w->get("wobjectId").", $newId, "
.quote($data{name}).", ".quote($data{value}).", $data{sequenceNumber})");
}
$sth->finish;
$sth = WebGUI::SQL->read("select * from Product_accessory where wobjectId=".$_[0]->get("wobjectId"));
while (%data = $sth->hash) {
WebGUI::SQL->write("insert into Product_accessory values (".$w->get("wobjectId").",
$data{accessoryWobjectId}, $data{sequenceNumber})");
}
$sth->finish;
$sth = WebGUI::SQL->read("select * from Product_related where wobjectId=".$_[0]->get("wobjectId"));
while (%data = $sth->hash) {
WebGUI::SQL->write("insert into Product_related values (".$w->get("wobjectId").",
$data{relatedWobjectId}, $data{sequenceNumber})");
}
$sth->finish;
}
#-------------------------------------------------------------------
sub new {
my ($self, $class, $property);
$class = shift;
$property = shift;
$self = WebGUI::Wobject->new($property);
bless $self, $class;
}
#-------------------------------------------------------------------
sub purge {
WebGUI::SQL->write("delete from Product_accessory where wobjectId=".$_[0]->get("wobjectId")."
or accessoryWobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("delete from Product_related where wobjectId=".$_[0]->get("wobjectId")."
or relatedWobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("delete from Product_feature where wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("delete from Product_specification where wobjectId=".$_[0]->get("wobjectId"));
$_[0]->SUPER::purge();
}
#-------------------------------------------------------------------
sub set {
$_[0]->SUPER::set($_[1],[qw(price productNumber image1 image2 image3 manual brochure warranty)]);
}
#-------------------------------------------------------------------
sub www_addAccessory {
my ($output, $f, $accessory, @usedAccessories);
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>'.WebGUI::International::get(16,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$f->hidden("func","addAccessorySave");
@usedAccessories = WebGUI::SQL->quickArray("select accessoryWobjectId from Product_accessory
where wobjectId=".$session{form}{wid});
push(@usedAccessories,$session{form}{wid});
$accessory = WebGUI::SQL->buildHashRef("select wobjectId,title from wobject where namespace='Product'
and wobjectId not in (".join(",",@usedAccessories).")");
$f->select("accessoryWobjectId",$accessory,WebGUI::International::get(17,$namespace));
$f->yesNo("proceed",WebGUI::International::get(18,$namespace));
$f->submit;
$output .= $f->print;
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
return $output;
}
#-------------------------------------------------------------------
sub www_addAccessorySave {
my ($seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from Product_accessory
where wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("insert into Product_accessory (wobjectId,accessoryWobjectId,sequenceNumber) values
(".$_[0]->get("wobjectId").",$session{form}{accessoryWobjectId},".($seq+1).")");
if ($session{form}{proceed}) {
return $_[0]->www_addAccessory();
} else {
return "";
}
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_addRelated {
my ($output, $f, $related, @usedRelated);
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>'.WebGUI::International::get(19,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$f->hidden("func","addRelatedSave");
@usedRelated = WebGUI::SQL->quickArray("select relatedWobjectId from Product_related
where wobjectId=".$session{form}{wid});
push(@usedRelated,$session{form}{wid});
$related = WebGUI::SQL->buildHashRef("select wobjectId,title from wobject where namespace='Product'
and wobjectId not in (".join(",",@usedRelated).")");
$f->select("relatedWobjectId",$related,WebGUI::International::get(20,$namespace));
$f->yesNo("proceed",WebGUI::International::get(21,$namespace));
$f->submit;
$output .= $f->print;
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
return $output;
}
#-------------------------------------------------------------------
sub www_addRelatedSave {
my ($seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from Product_related
where wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("insert into Product_related (wobjectId,relatedWobjectId,sequenceNumber) values
(".$_[0]->get("wobjectId").",$session{form}{relatedWobjectId},".($seq+1).")");
if ($session{form}{proceed}) {
return $_[0]->www_addRelated();
} else {
return "";
}
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_copy {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->duplicate;
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteAccessory {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(2,$namespace).'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('func=deleteAccessoryConfirm&wid='.$_[0]->get("wobjectId").
'&aid='.$session{form}{aid}).'">'.WebGUI::International::get(44).'</a>';
$output .= ' &nbsp; <a href="'.WebGUI::URL::page().'">'.WebGUI::International::get(45).'</a></div>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteAccessoryConfirm {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("delete from Product_accessory where wobjectId=$session{form}{wid}
and accessoryWobjectId=$session{form}{aid}");
_reorderAccessories($_[0]->get("wobjectId"));
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteFeature {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(3,$namespace).'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('func=deleteFeatureConfirm&wid='.$_[0]->get("wobjectId").
'&fid='.$session{form}{fid}).'">'.WebGUI::International::get(44).'</a>';
$output .= ' &nbsp; <a href="'.WebGUI::URL::page().'">'.WebGUI::International::get(45).'</a></div>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteFeatureConfirm {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("delete from Product_feature where productFeatureId=$session{form}{fid}");
_reorderFeatures($_[0]->get("wobjectId"));
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteFile {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(12,$namespace).'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('func=deleteFileConfirm&wid='.$_[0]->get("wobjectId").
'&file='.$session{form}{file}).'">'.WebGUI::International::get(44).'</a>';
$output .= ' &nbsp; <a href="'.WebGUI::URL::page().'">'.WebGUI::International::get(45).'</a></div>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteFileConfirm {
if (WebGUI::Privilege::canEditPage()) {
$_[0]->set({$session{form}{file}=>''});
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteRelated {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(4,$namespace).'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('func=deleteRelatedConfirm&wid='.$_[0]->get("wobjectId").
'&rid='.$session{form}{rid}).'">'.WebGUI::International::get(44).'</a>';
$output .= ' &nbsp; <a href="'.WebGUI::URL::page().'">'.WebGUI::International::get(45).'</a></div>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteRelatedConfirm {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("delete from Product_related where wobjectId=$session{form}{wid}
and relatedWobjectId=$session{form}{rid}");
_reorderRelated($_[0]->get("wobjectId"));
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteSpecification {
my ($output);
if (WebGUI::Privilege::canEditPage()) {
$output = '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(5,$namespace).'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('func=deleteSpecificationConfirm&wid='.$_[0]->get("wobjectId").
'&sid='.$session{form}{sid}).'">'.WebGUI::International::get(44).'</a>';
$output .= ' &nbsp; <a href="'.WebGUI::URL::page().'">'.WebGUI::International::get(45).'</a></div>';
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_deleteSpecificationConfirm {
if (WebGUI::Privilege::canEditPage()) {
WebGUI::SQL->write("delete from Product_specification where productSpecificationId=$session{form}{sid}");
_reorderSpecifications($_[0]->get("wobjectId"));
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_edit {
my ($f, $output, $proceed);
if (WebGUI::Privilege::canEditPage()) {
$output = helpIcon(1,$namespace);
$output .= '<h1>'.WebGUI::International::get(6,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->text("price",WebGUI::International::get(10,$namespace),$_[0]->get("price"));
$f->text("productNumber",WebGUI::International::get(11,$namespace),$_[0]->get("productNumber"));
$f->raw(_fileProperty("image1",7,$_[0]->get("image1")));
$f->raw(_fileProperty("image2",8,$_[0]->get("image2")));
$f->raw(_fileProperty("image3",9,$_[0]->get("image3")));
$f->raw(_fileProperty("brochure",13,$_[0]->get("brochure")));
$f->raw(_fileProperty("manual",14,$_[0]->get("manual")));
$f->raw(_fileProperty("warranty",15,$_[0]->get("warranty")));
$output .= $_[0]->SUPER::www_edit($f->printRowsOnly);
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editSave {
my ($file, %property);
if (WebGUI::Privilege::canEditPage()) {
$_[0]->SUPER::www_editSave();
$file = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$file->save("image1");
$property{image1}=$file->getFilename("image1") if ($file->getFilename("image1") ne "");
$file = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$file->save("image2");
$property{image2}=$file->getFilename("image2") if ($file->getFilename("image2") ne "");
$file = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$file->save("image3");
$property{image3}=$file->getFilename("image3") if ($file->getFilename("image3") ne "");
$file = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$file->save("manual");
$property{manual}=$file->getFilename("manual") if ($file->getFilename("manual") ne "");
$file = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$file->save("brochure");
$property{brochure}=$file->getFilename("brochure") if ($file->getFilename("brochure") ne "");
$file = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
$file->save("warranty");
$property{warranty}=$file->getFilename("warranty") if ($file->getFilename("warranty") ne "");
$property{price}=$session{form}{price};
$property{productNumber}=$session{form}{productNumber};
$_[0]->set(\%property);
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editFeature {
my ($output, %data, $f, $features);
tie %data, 'Tie::CPHash';
if (WebGUI::Privilege::canEditPage()) {
%data = WebGUI::SQL->quickHash("select * from Product_feature where
productFeatureId='$session{form}{fid}'");
$output = '<h1>'.WebGUI::International::get(22,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$session{form}{fid} = "new" if ($session{form}{fid} eq "");
$f->hidden("fid",$session{form}{fid});
$f->hidden("func","editFeatureSave");
$features = WebGUI::SQL->buildHashRef("select feature,feature from Product_feature order by feature");
$f->combo("feature",$features,WebGUI::International::get(23,$namespace),[$data{feature}]);
$f->yesNo("proceed",WebGUI::International::get(24,$namespace));
$f->submit;
$output .= $f->print;
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
return $output;
}
#-------------------------------------------------------------------
sub www_editFeatureSave {
my ($seq);
if (WebGUI::Privilege::canEditPage()) {
if ($session{form}{fid} eq "new") {
($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from Product_feature
where wobjectId=".$_[0]->get("wobjectId"));
$session{form}{fid} = getNextId("productFeatureId");
WebGUI::SQL->write("insert into Product_feature (wobjectId,productFeatureId,sequenceNumber) values
(".$_[0]->get("wobjectId").",$session{form}{fid},".($seq+1).")");
}
$session{form}{feature} = $session{form}{feature_new} if ($session{form}{feature_new} ne "");
WebGUI::SQL->write("update Product_feature set feature=".quote($session{form}{feature})."
where productFeatureId=$session{form}{fid}");
if ($session{form}{proceed}) {
$session{form}{fid} = "new";
return $_[0]->www_editFeature();
} else {
return "";
}
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_editSpecification {
my ($output, %data, $f, $hashRef);
tie %data, 'Tie::CPHash';
if (WebGUI::Privilege::canEditPage()) {
%data = WebGUI::SQL->quickHash("select * from Product_specification where
productSpecificationId='$session{form}{sid}'");
$output = '<h1>'.WebGUI::International::get(25,$namespace).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("wid",$_[0]->get("wobjectId"));
$session{form}{sid} = "new" if ($session{form}{sid} eq "");
$f->hidden("sid",$session{form}{sid});
$f->hidden("func","editSpecificationSave");
$hashRef = WebGUI::SQL->buildHashRef("select name,name from Product_specification order by name");
$f->combo("name",$hashRef,WebGUI::International::get(26,$namespace),[$data{name}]);
$f->text("value",WebGUI::International::get(27,$namespace),$data{value});
$hashRef = WebGUI::SQL->buildHashRef("select units,units from Product_specification order by units");
$f->combo("units",$hashRef,WebGUI::International::get(29,$namespace),[$data{units}]);
$f->yesNo("proceed",WebGUI::International::get(28,$namespace));
$f->submit;
$output .= $f->print;
return $output;
} else {
return WebGUI::Privilege::insufficient();
}
return $output;
}
#-------------------------------------------------------------------
sub www_editSpecificationSave {
my ($seq);
if (WebGUI::Privilege::canEditPage()) {
if ($session{form}{sid} eq "new") {
($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from Product_specification
where wobjectId=".$_[0]->get("wobjectId"));
$session{form}{sid} = getNextId("productSpecificationId");
WebGUI::SQL->write("insert into Product_specification (wobjectId,productSpecificationId,sequenceNumber) values
(".$_[0]->get("wobjectId").",$session{form}{sid},".($seq+1).")");
}
$session{form}{name} = $session{form}{name_new} if ($session{form}{name_new} ne "");
$session{form}{value} = $session{form}{value_new} if ($session{form}{value_new} ne "");
$session{form}{units} = $session{form}{units_new} if ($session{form}{units_new} ne "");
WebGUI::SQL->write("update Product_specification set name=".quote($session{form}{name}).",
value=".quote($session{form}{value}).", units=".quote($session{form}{units})." where productSpecificationId=$session{form}{sid}");
if ($session{form}{proceed}) {
$session{form}{sid} = "new";
return $_[0]->www_editSpecification();
} else {
return "";
}
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveAccessoryDown {
my ($id, $seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select sequenceNumber from Product_accessory
where accessoryWobjectId=$session{form}{aid} and wobjectId=".$_[0]->get("wobjectId"));
($id) = WebGUI::SQL->quickArray("select accessoryWobjectId from Product_accessory
where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$seq+1 group by wobjectId");
if ($id ne "") {
WebGUI::SQL->write("update Product_accessory set sequenceNumber=sequenceNumber+1
where accessoryWobjectId=$session{form}{aid} and wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("update Product_accessory set sequenceNumber=sequenceNumber-1
where accessoryWobjectId=$id and wobjectId=".$_[0]->get("wobjectId"));
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveAccessoryUp {
my ($id, $seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select sequenceNumber from Product_accessory
where accessoryWobjectId=$session{form}{aid} and wobjectId=".$_[0]->get("wobjectId"));
($id) = WebGUI::SQL->quickArray("select accessoryWobjectId from Product_accessory
where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$seq-1 group by wobjectId");
if ($id ne "") {
WebGUI::SQL->write("update Product_accessory set sequenceNumber=sequenceNumber-1
where accessoryWobjectId=$session{form}{aid} and wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("update Product_accessory set sequenceNumber=sequenceNumber+1
where accessoryWobjectId=$id and wobjectId=".$_[0]->get("wobjectId"));
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveFeatureDown {
my ($id, $seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select sequenceNumber from Product_feature
where productFeatureId=$session{form}{fid}");
($id) = WebGUI::SQL->quickArray("select productFeatureId from Product_feature
where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$seq+1 group by wobjectId");
if ($id ne "") {
WebGUI::SQL->write("update Product_feature set sequenceNumber=sequenceNumber+1
where productFeatureId=$session{form}{fid}");
WebGUI::SQL->write("update Product_feature set sequenceNumber=sequenceNumber-1 where productFeatureId=$id");
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveFeatureUp {
my ($id, $seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select sequenceNumber from Product_feature
where productFeatureId=$session{form}{fid}");
($id) = WebGUI::SQL->quickArray("select productFeatureId from Product_feature
where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$seq-1 group by wobjectId");
if ($id ne "") {
WebGUI::SQL->write("update Product_feature set sequenceNumber=sequenceNumber-1
where productFeatureId=$session{form}{fid}");
WebGUI::SQL->write("update Product_feature set sequenceNumber=sequenceNumber+1 where productFeatureId=$id");
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveRelatedDown {
my ($id, $seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select sequenceNumber from Product_related
where relatedWobjectId=$session{form}{rid} and wobjectId=".$_[0]->get("wobjectId"));
($id) = WebGUI::SQL->quickArray("select relatedWobjectId from Product_related
where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$seq+1 group by wobjectId");
if ($id ne "") {
WebGUI::SQL->write("update Product_related set sequenceNumber=sequenceNumber+1
where relatedWobjectId=$session{form}{rid} and wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("update Product_related set sequenceNumber=sequenceNumber-1
where relatedWobjectId=$id and wobjectId=".$_[0]->get("wobjectId"));
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveRelatedUp {
my ($id, $seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select sequenceNumber from Product_related
where relatedWobjectId=$session{form}{rid} and wobjectId=".$_[0]->get("wobjectId"));
($id) = WebGUI::SQL->quickArray("select relatedWobjectId from Product_related
where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$seq-1 group by wobjectId");
if ($id ne "") {
WebGUI::SQL->write("update Product_related set sequenceNumber=sequenceNumber-1
where relatedWobjectId=$session{form}{rid} and wobjectId=".$_[0]->get("wobjectId"));
WebGUI::SQL->write("update Product_related set sequenceNumber=sequenceNumber+1
where relatedWobjectId=$id and wobjectId=".$_[0]->get("wobjectId"));
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveSpecificationDown {
my ($id, $seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select sequenceNumber from Product_specification
where productSpecificationId=$session{form}{sid}");
($id) = WebGUI::SQL->quickArray("select productSpecificationId from Product_specification
where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$seq+1 group by wobjectId");
if ($id ne "") {
WebGUI::SQL->write("update Product_specification set sequenceNumber=sequenceNumber+1
where productSpecificationId=$session{form}{sid}");
WebGUI::SQL->write("update Product_specification set sequenceNumber=sequenceNumber-1
where productSpecificationId=$id");
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_moveSpecificationUp {
my ($id, $seq);
if (WebGUI::Privilege::canEditPage()) {
($seq) = WebGUI::SQL->quickArray("select sequenceNumber from Product_specification
where productSpecificationId=$session{form}{sid}");
($id) = WebGUI::SQL->quickArray("select productSpecificationId from Product_specification
where wobjectId=".$_[0]->get("wobjectId")." and sequenceNumber=$seq-1 group by wobjectId");
if ($id ne "") {
WebGUI::SQL->write("update Product_specification set sequenceNumber=sequenceNumber-1
where productSpecificationId=$session{form}{sid}");
WebGUI::SQL->write("update Product_specification set sequenceNumber=sequenceNumber+1
where productSpecificationId=$id");
}
return "";
} else {
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_view {
my ($output);
if ($_[0]->get("layout") eq "something") {
return $_[0]->_layoutSomething;
} elsif ($_[0]->get("layout") eq "somethingelse") {
return $_[0]->_layoutSomethingelse;
} else {
return $_[0]->_layoutStandard;
}
}
1;