diff --git a/lib/WebGUI/Wobject/Product.pm b/lib/WebGUI/Wobject/Product.pm deleted file mode 100644 index 9bf71d222..000000000 --- a/lib/WebGUI/Wobject/Product.pm +++ /dev/null @@ -1,647 +0,0 @@ -package WebGUI::Wobject::Product; - -#------------------------------------------------------------------- -# WebGUI is Copyright 2001-2005 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 -#------------------------------------------------------------------- - -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); - -#------------------------------------------------------------------- -sub duplicate { - my ($w, %data, $file, $row, $sth); - tie %data, 'Tie::CPHash'; - $w = $_[0]->SUPER::duplicate($_[1]); - $w = WebGUI::Wobject::Product->new({wobjectId=>$w,namespace=>$_[0]->get("namespace")}); - $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=".quote($_[0]->get("wobjectId"))); - while ($row = $sth->hashRef) { - $row->{"Product_featureId"} = "new"; - $w->setCollateral("Product_feature","Product_featureId",$row); - } - $sth->finish; - $sth = WebGUI::SQL->read("select * from Product_benefit where wobjectId=".quote($_[0]->get("wobjectId"))); - while ($row = $sth->hashRef) { - $row->{"Product_benefitId"} = "new"; - $w->setCollateral("Product_benefit","Product_benefitId",$row); - } - $sth->finish; - $sth = WebGUI::SQL->read("select * from Product_specification where wobjectId=".quote($_[0]->get("wobjectId"))); - while ($row = $sth->hashRef) { - $row->{"Product_specificationId"} = "new"; - $w->setCollateral("Product_specification","Product_specificationId",$row); - } - $sth->finish; - $sth = WebGUI::SQL->read("select * from Product_accessory where wobjectId=".quote($_[0]->get("wobjectId"))); - while (%data = $sth->hash) { - WebGUI::SQL->write("insert into Product_accessory values (".quote($w->get("wobjectId")).", - ".quote($data{accessoryWobjectId}).", $data{sequenceNumber})"); - } - $sth->finish; - $sth = WebGUI::SQL->read("select * from Product_related where wobjectId=".quote($_[0]->get("wobjectId"))); - while (%data = $sth->hash) { - WebGUI::SQL->write("insert into Product_related values (".quote($w->get("wobjectId")).", - ".quote($data{relatedWobjectId}).", $data{sequenceNumber})"); - } - $sth->finish; -} - -#------------------------------------------------------------------- -sub getIndexerParams { - my $self = shift; - my $now = shift; - return { - Product => { - sql => "select Product.wobjectId as wid, - Product.image1 as image1, - Product.image2 as image2, - Product.image3 as image3, - Product.brochure as brochure, - Product.manual as manual, - Product.warranty as warranty, - Product.price as price, - Product.productNumber as productNumber, - Product_benefit.benefit as benefit, - Product_feature.feature as feature, - Product_specification.name as name, - Product_specification.value as value, - Product_specification.units as units, - wobject.namespace as namespace, - wobject.addedBy as ownerId, - page.urlizedTitle as urlizedTitle, - page.languageId as languageId, - page.pageId as pageId, - page.groupIdView as page_groupIdView, - wobject.groupIdView as wobject_groupIdView, - 7 as wobject_special_groupIdView - from Product, wobject, page - left join Product_benefit on Product_benefit.wobjectId=Product.wobjectId - left join Product_feature on Product_feature.wobjectId=Product.wobjectId - left join Product_specification on Product_specification.wobjectId=Product.wobjectId - where Product.wobjectId = wobject.wobjectId - and wobject.pageId = page.pageId - and wobject.startDate < $now - and wobject.endDate > $now - and page.startDate < $now - and page.endDate > $now", - fieldsToIndex => ["image1", "image2", "image3", "brochure", "manual", "warranty", "price", - "productNumber", "benefit", "feature", "name", "value", "units"], - contentType => 'wobjectDetail', - url => 'WebGUI::URL::append($data{urlizedTitle}, "func=view&wid=$data{wid}")', - headerShortcut => 'select title from wobject where wobjectId = \'$data{wid}\'', - bodyShortcut => 'select description from wobject where wobjectId = \'$data{wid}\'', - } - }; -} - -#------------------------------------------------------------------- -sub name { - return WebGUI::International::get(1,$_[0]->get("namespace")); -} - -#------------------------------------------------------------------- -sub new { - my $class = shift; - my $property = shift; - my $self = WebGUI::Wobject->new( - -properties=>$property, - -extendedProperties=>{ - price=>{}, - productNumber=>{}, - image1=>{}, - image2=>{}, - image3=>{}, - manual=>{}, - brochure=>{}, - warranty=>{} - }, - -useTemplate=>1, - -useMetaData=>1 - ); - bless $self, $class; -} - -#------------------------------------------------------------------- -sub purge { - WebGUI::SQL->write("delete from Product_accessory where wobjectId=".quote($_[0]->get("wobjectId"))." - or accessoryWobjectId=".quote($_[0]->get("wobjectId"))); - WebGUI::SQL->write("delete from Product_related where wobjectId=".quote($_[0]->get("wobjectId"))." - or relatedWobjectId=".quote($_[0]->get("wobjectId"))); - WebGUI::SQL->write("delete from Product_benefit where wobjectId=".quote($_[0]->get("wobjectId"))); - WebGUI::SQL->write("delete from Product_feature where wobjectId=".quote($_[0]->get("wobjectId"))); - WebGUI::SQL->write("delete from Product_specification where wobjectId=".quote($_[0]->get("wobjectId"))); - $_[0]->SUPER::purge(); -} - - -#------------------------------------------------------------------- -sub www_addAccessory { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - my ($f, $accessory, @usedAccessories); - $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=".quote($session{form}{wid})); - push(@usedAccessories,$session{form}{wid}); - $accessory = WebGUI::SQL->buildHashRef("select wobjectId,title from wobject where namespace='Product' - and wobjectId not in (".quoteAndJoin(\@usedAccessories).")"); - $f->select("accessoryWobjectId",$accessory,WebGUI::International::get(17,$_[0]->get("namespace"))); - $f->yesNo("proceed",WebGUI::International::get(18,$_[0]->get("namespace"))); - $f->submit; - return $_[0]->adminConsole($f->print, '16', "product accessory add/edit"); -} - -#------------------------------------------------------------------- -sub www_addAccessorySave { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - return "" unless ($session{form}{accessoryWobjectId}); - my ($seq); - ($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from Product_accessory - where wobjectId=".quote($_[0]->get("wobjectId"))); - WebGUI::SQL->write("insert into Product_accessory (wobjectId,accessoryWobjectId,sequenceNumber) values - (".quote($_[0]->get("wobjectId")).",".quote($session{form}{accessoryWobjectId}).",".($seq+1).")"); - if ($session{form}{proceed}) { - return $_[0]->www_addAccessory(); - } else { - return ""; - } -} - -#------------------------------------------------------------------- -sub www_addRelated { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - my ($f, $related, @usedRelated); - $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=".quote($session{form}{wid})); - push(@usedRelated,$session{form}{wid}); - $related = WebGUI::SQL->buildHashRef("select wobjectId,title from wobject where namespace='Product' - and wobjectId not in (".quoteAndJoin(\@usedRelated).")"); - $f->select("relatedWobjectId",$related,WebGUI::International::get(20,$_[0]->get("namespace"))); - $f->yesNo("proceed",WebGUI::International::get(21,$_[0]->get("namespace"))); - $f->submit; - return $_[0]->adminConsole( $f->print, '19',"product related add/edit"); -} - -#------------------------------------------------------------------- -sub www_addRelatedSave { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - return "" unless ($session{form}{relatedWobjectId}); - my ($seq); - ($seq) = WebGUI::SQL->quickArray("select max(sequenceNumber) from Product_related - where wobjectId=".quote($_[0]->get("wobjectId"))); - WebGUI::SQL->write("insert into Product_related (wobjectId,relatedWobjectId,sequenceNumber) values - (".quote($_[0]->get("wobjectId")).",".quote($session{form}{relatedWobjectId}).",".($seq+1).")"); - if ($session{form}{proceed}) { - return $_[0]->www_addRelated(); - } else { - return ""; - } -} - -#------------------------------------------------------------------- -sub www_deleteAccessoryConfirm { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - WebGUI::SQL->write("delete from Product_accessory where wobjectId=".quote($_[0]->get("wobjectId"))." and accessoryWobjectId=".quote($session{form}{aid})); - $_[0]->reorderCollateral("Product_accessory","accessoryWobjectId"); - return ""; -} - -#------------------------------------------------------------------- -sub www_deleteBenefitConfirm { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->deleteCollateral("Product_benefit","Product_benefitId",$session{form}{bid}); - $_[0]->reorderCollateral("Product_benefit","Product_benefitId"); - return ""; -} - -#------------------------------------------------------------------- -sub www_deleteFeatureConfirm { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->deleteCollateral("Product_feature","Product_featureId",$session{form}{fid}); - $_[0]->reorderCollateral("Product_feature","Product_featureId"); - return ""; -} - -#------------------------------------------------------------------- -sub www_deleteRelatedConfirm { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - WebGUI::SQL->write("delete from Product_related where wobjectId=".quote($_[0]->get("wobjectId"))." and relatedWobjectId=".quote($session{form}{rid})); - $_[0]->reorderCollateral("Product_related","relatedWobjectId"); - return ""; -} - -#------------------------------------------------------------------- -sub www_deleteSpecificationConfirm { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->deleteCollateral("Product_specification","Product_specificationId",$session{form}{sid}); - $_[0]->reorderCollateral("Product_specification","Product_specificationId"); - return ""; -} - -#------------------------------------------------------------------- -sub www_edit { - my $properties = WebGUI::HTMLForm->new; - $properties->text( - -name=>"price", - -label=>WebGUI::International::get(10,$_[0]->get("namespace")), - -value=>$_[0]->getValue("price") - ); - $properties->text( - -name=>"productNumber", - -label=>WebGUI::International::get(11,$_[0]->get("namespace")), - -value=>$_[0]->getValue("productNumber") - ); - $properties->raw($_[0]->fileProperty("image1",7)); - $properties->raw($_[0]->fileProperty("image2",8)); - $properties->raw($_[0]->fileProperty("image3",9)); - $properties->raw($_[0]->fileProperty("brochure",13)); - $properties->raw($_[0]->fileProperty("manual",14)); - $properties->raw($_[0]->fileProperty("warranty",15)); - return $_[0]->SUPER::www_edit( - -properties=>$properties->printRowsOnly, - -helpId=>"product add/edit", - -headingId=>6 - ); -} - -#------------------------------------------------------------------- -sub www_editSave { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - my ($file, %property); - $_[0]->SUPER::www_editSave() if ($_[0]->get("wobjectId") eq "new"); - $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 ""); - $_[0]->SUPER::www_editSave(\%property); - return ""; -} - -#------------------------------------------------------------------- -sub www_editBenefit { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - my ($data, $f, $benefits); - $data = $_[0]->getCollateral("Product_benefit","Product_benefitId",$session{form}{bid}); - $f = WebGUI::HTMLForm->new; - $f->hidden("wid",$_[0]->get("wobjectId")); - $f->hidden("bid",$data->{Product_benefitId}); - $f->hidden("func","editBenefitSave"); - $benefits = WebGUI::SQL->buildHashRef("select benefit,benefit from Product_benefit order by benefit"); - $f->combo("benefit",$benefits,WebGUI::International::get(51,$_[0]->get("namespace")),[$data->{benefits}]); - $f->yesNo("proceed",WebGUI::International::get(52,$_[0]->get("namespace"))); - $f->submit; - return $_[0]->adminConsole($f->print,'53',"product benefit add/edit"); -} - -#------------------------------------------------------------------- -sub www_editBenefitSave { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $session{form}{benefit} = $session{form}{benefit_new} if ($session{form}{benefit_new} ne ""); - $_[0]->setCollateral("Product_benefit", "Product_benefitId", { - Product_benefitId => $session{form}{bid}, - benefit => $session{form}{benefit} - }); - if ($session{form}{proceed}) { - $session{form}{bid} = "new"; - return $_[0]->www_editBenefit(); - } else { - return ""; - } -} - -#------------------------------------------------------------------- -sub www_editFeature { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - my ($data, $f, $features); - $data = $_[0]->getCollateral("Product_feature","Product_featureId",$session{form}{fid}); - $f = WebGUI::HTMLForm->new; - $f->hidden("wid",$_[0]->get("wobjectId")); - $f->hidden("fid",$data->{Product_featureId}); - $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,$_[0]->get("namespace")),[$data->{feature}]); - $f->yesNo("proceed",WebGUI::International::get(24,$_[0]->get("namespace"))); - $f->submit; - return $_[0]->adminConsole($f->print,'22',"product feature add/edit"); -} - -#------------------------------------------------------------------- -sub www_editFeatureSave { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $session{form}{feature} = $session{form}{feature_new} if ($session{form}{feature_new} ne ""); - $_[0]->setCollateral("Product_feature", "Product_featureId", { - Product_featureId => $session{form}{fid}, - feature => $session{form}{feature} - }); - if ($session{form}{proceed}) { - $session{form}{fid} = "new"; - return $_[0]->www_editFeature(); - } else { - return ""; - } -} - -#------------------------------------------------------------------- -sub www_editSpecification { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - my ($data, $f, $hashRef); - $data = $_[0]->getCollateral("Product_specification","Product_specificationId",$session{form}{sid}); - $f = WebGUI::HTMLForm->new; - $f->hidden("wid",$_[0]->get("wobjectId")); - $f->hidden("sid",$data->{Product_specificationId}); - $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,$_[0]->get("namespace")),[$data->{name}]); - $f->text("value",WebGUI::International::get(27,$_[0]->get("namespace")),$data->{value}); - $hashRef = WebGUI::SQL->buildHashRef("select units,units from Product_specification order by units"); - $f->combo("units",$hashRef,WebGUI::International::get(29,$_[0]->get("namespace")),[$data->{units}]); - $f->yesNo("proceed",WebGUI::International::get(28,$_[0]->get("namespace"))); - $f->submit; - return $_[0]->adminConsole($f->print,'25',"product specification add/edit"); -} - -#------------------------------------------------------------------- -sub www_editSpecificationSave { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $session{form}{name} = $session{form}{name_new} if ($session{form}{name_new} ne ""); - $session{form}{units} = $session{form}{units_new} if ($session{form}{units_new} ne ""); - $_[0]->setCollateral("Product_specification", "Product_specificationId", { - Product_specificationId => $session{form}{sid}, - name => $session{form}{name}, - value => $session{form}{value}, - units => $session{form}{units} - }); - if ($session{form}{proceed}) { - $session{form}{sid} = "new"; - return $_[0]->www_editSpecification(); - } else { - return ""; - } -} - -#------------------------------------------------------------------- -sub www_moveAccessoryDown { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralDown("Product_related","accessoryWobjectId",$session{form}{aid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_moveAccessoryUp { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralUp("Product_accessory","accessoryWobjectId",$session{form}{aid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_moveBenefitDown { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralDown("Product_benefit","Product_benefitId",$session{form}{bid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_moveBenefitUp { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralUp("Product_benefit","Product_benefitId",$session{form}{bid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_moveFeatureDown { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralDown("Product_feature","Product_featureId",$session{form}{fid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_moveFeatureUp { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralUp("Product_feature","Product_featureId",$session{form}{fid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_moveRelatedDown { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralDown("Product_related","relatedWobjectId",$session{form}{rid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_moveRelatedUp { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralUp("Product_related","relatedWobjectId",$session{form}{rid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_moveSpecificationDown { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralDown("Product_specification","Product_specificationId",$session{form}{sid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_moveSpecificationUp { - return WebGUI::Privilege::insufficient() unless ($_[0]->canEdit); - $_[0]->moveCollateralUp("Product_specification","Product_specificationId",$session{form}{sid}); - return ""; -} - -#------------------------------------------------------------------- -sub www_view { - $_[0]->logView() if ($session{setting}{passiveProfilingEnabled}); - my (%data, $sth, $file, $segment, %var, @featureloop, @benefitloop, @specificationloop, @accessoryloop, @relatedloop); - tie %data, 'Tie::CPHash'; - #---brochure - if ($_[0]->get("brochure")) { - $file = WebGUI::Attachment->new($_[0]->get("brochure"),$_[0]->get("wobjectId")); - $var{"brochure.icon"} = $file->getIcon; - $var{"brochure.label"} = WebGUI::International::get(13,$_[0]->get("namespace")); - $var{"brochure.URL"} = $file->getURL; - } - #---manual - if ($_[0]->get("manual")) { - $file = WebGUI::Attachment->new($_[0]->get("manual"),$_[0]->get("wobjectId")); - $var{"manual.icon"} = $file->getIcon; - $var{"manual.label"} = WebGUI::International::get(14,$_[0]->get("namespace")); - $var{"manual.URL"} = $file->getURL; - } - #---warranty - if ($_[0]->get("warranty")) { - $file = WebGUI::Attachment->new($_[0]->get("warranty"),$_[0]->get("wobjectId")); - $var{"warranty.icon"} = $file->getIcon; - $var{"warranty.label"} = WebGUI::International::get(15,$_[0]->get("namespace")); - $var{"warranty.URL"} = $file->getURL; - } - #---image1 - if ($_[0]->get("image1")) { - $file = WebGUI::Attachment->new($_[0]->get("image1"),$_[0]->get("wobjectId")); - $var{thumbnail1} = $file->getThumbnail; - $var{image1} = $file->getURL; - } - #---image2 - if ($_[0]->get("image2")) { - $file = WebGUI::Attachment->new($_[0]->get("image2"),$_[0]->get("wobjectId")); - $var{thumbnail2} = $file->getThumbnail; - $var{image2} = $file->getURL; - } - #---image3 - if ($_[0]->get("image3")) { - $file = WebGUI::Attachment->new($_[0]->get("image3"),$_[0]->get("wobjectId")); - $var{thumbnail3} = $file->getThumbnail; - $var{image3} = $file->getURL; - } - - #---features - $var{"addFeature.url"} = WebGUI::URL::page('func=editFeature&fid=new&wid='.$_[0]->get("wobjectId")); - $var{"addFeature.label"} = WebGUI::International::get(34,$_[0]->get("namespace")); - $sth = WebGUI::SQL->read("select feature,Product_featureId from Product_feature where wobjectId=" - .quote($_[0]->get("wobjectId"))." order by sequenceNumber"); - while (%data = $sth->hash) { - $segment = deleteIcon('func=deleteFeatureConfirm&wid='.$_[0]->get("wobjectId").'&fid='.$data{Product_featureId},'',WebGUI::International::get(3,$_[0]->get("namespace"))) - .editIcon('func=editFeature&wid='.$_[0]->get("wobjectId").'&fid='.$data{Product_featureId}) - .moveUpIcon('func=moveFeatureUp&wid='.$_[0]->get("wobjectId").'&fid='.$data{Product_featureId}) - .moveDownIcon('func=moveFeatureDown&wid='.$_[0]->get("wobjectId").'&fid='.$data{Product_featureId}); - push(@featureloop,{ - "feature.feature"=>$data{feature}, - "feature.controls"=>$segment - }); - } - $sth->finish; - $var{feature_loop} = \@featureloop; - - #---benefits - $var{"addBenefit.url"} = WebGUI::URL::page('func=editBenefit&fid=new&wid='.$_[0]->get("wobjectId")); - $var{"addBenefit.label"} = WebGUI::International::get(55,$_[0]->get("namespace")); - $sth = WebGUI::SQL->read("select benefit,Product_benefitId from Product_benefit where wobjectId=" - .quote($_[0]->get("wobjectId"))." order by sequenceNumber"); - while (%data = $sth->hash) { - $segment = deleteIcon('func=deleteBenefitConfirm&wid='.$_[0]->get("wobjectId").'&bid='.$data{Product_benefitId},'',WebGUI::International::get(48,$_[0]->get("namespace"))) - .editIcon('func=editBenefit&wid='.$_[0]->get("wobjectId").'&bid='.$data{Product_benefitId}) - .moveUpIcon('func=moveBenefitUp&wid='.$_[0]->get("wobjectId").'&bid='.$data{Product_benefitId}) - .moveDownIcon('func=moveBenefitDown&wid='.$_[0]->get("wobjectId").'&bid='.$data{Product_benefitId}); - push(@benefitloop,{ - "benefit.benefit"=>$data{benefit}, - "benefit.controls"=>$segment - }); - } - $sth->finish; - $var{benefit_loop} = \@benefitloop; - - #---specifications - $var{"addSpecification.url"} = WebGUI::URL::page('func=editSpecification&sid=new&wid='.$_[0]->get("wobjectId")); - $var{"addSpecification.label"} = WebGUI::International::get(35,$_[0]->get("namespace")); - $sth = WebGUI::SQL->read("select name,value,units,Product_specificationId from Product_specification - where wobjectId=".quote($_[0]->get("wobjectId"))." order by sequenceNumber"); - while (%data = $sth->hash) { - $segment = deleteIcon('func=deleteSpecificationConfirm&wid='.$_[0]->get("wobjectId").'&sid='.$data{Product_specificationId},'',WebGUI::International::get(5,$_[0]->get("namespace"))) - .editIcon('func=editSpecification&wid='.$_[0]->get("wobjectId").'&sid='.$data{Product_specificationId}) - .moveUpIcon('func=moveSpecificationUp&wid='.$_[0]->get("wobjectId").'&sid='.$data{Product_specificationId}) - .moveDownIcon('func=moveSpecificationDown&wid='.$_[0]->get("wobjectId").'&sid='.$data{Product_specificationId}); - push(@specificationloop,{ - "specification.controls"=>$segment, - "specification.specification"=>$data{value}, - "specification.units"=>$data{units}, - "specification.label"=>$data{name} - }); - } - $sth->finish; - $var{specification_loop} = \@specificationloop; - - #---accessories - $var{"addaccessory.url"} = WebGUI::URL::page('func=addAccessory&wid='.$_[0]->get("wobjectId")); - $var{"addaccessory.label"} = WebGUI::International::get(36,$_[0]->get("namespace")); - $sth = WebGUI::SQL->read("select wobject.title,page.urlizedTitle,Product_accessory.accessoryWobjectId - from Product_accessory,wobject,page - where Product_accessory.wobjectId=".quote($_[0]->get("wobjectId"))." - and Product_accessory.accessoryWobjectId=wobject.wobjectId - and wobject.pageId=page.pageId order by Product_accessory.sequenceNumber"); - while (%data = $sth->hash) { - $segment = deleteIcon('func=deleteAccessoryConfirm&wid='.$_[0]->get("wobjectId").'&aid='.$data{accessoryWobjectId},WebGUI::International::get(2,$_[0]->get("namespace"))) - .moveUpIcon('func=moveAccessoryUp&wid='.$_[0]->get("wobjectId").'&aid='.$data{accessoryWobjectId}) - .moveDownIcon('func=moveAccessoryDown&wid='.$_[0]->get("wobjectId").'&aid='.$data{accessoryWobjectId}); - push(@accessoryloop,{ - "accessory.URL"=>WebGUI::URL::gateway($data{urlizedTitle}), - "accessory.title"=>$data{title}, - "accessory.controls"=>$segment - }); - } - $sth->finish; - $var{accessory_loop} = \@accessoryloop; - - #---related - $var{"addrelatedproduct.url"} = WebGUI::URL::page('func=addRelated&wid='.$_[0]->get("wobjectId")); - $var{"addrelatedproduct.label"} = WebGUI::International::get(37,$_[0]->get("namespace")); - $sth = WebGUI::SQL->read("select wobject.title,page.urlizedTitle,Product_related.relatedWobjectId - from Product_related,wobject,page - where Product_related.wobjectId=".quote($_[0]->get("wobjectId"))." - and Product_related.relatedWobjectId=wobject.wobjectId - and wobject.pageId=page.pageId order by Product_related.sequenceNumber"); - while (%data = $sth->hash) { - $segment = deleteIcon('func=deleteRelatedConfirm&wid='.$_[0]->get("wobjectId").'&rid='.$data{relatedWobjectId},'',WebGUI::International::get(4,$_[0]->get("namespace"))) - .moveUpIcon('func=moveRelatedUp&wid='.$_[0]->get("wobjectId").'&rid='.$data{relatedWobjectId}) - .moveDownIcon('func=moveRelatedDown&wid='.$_[0]->get("wobjectId").'&rid='.$data{relatedWobjectId}); - push(@relatedloop,{ - "relatedproduct.URL"=>WebGUI::URL::gateway($data{urlizedTitle}), - "relatedproduct.title"=>$data{title}, - "relatedproduct.controls"=>$segment - }); - } - $sth->finish; - $var{relatedproduct_loop} = \@relatedloop; - return $_[0]->processTemplate($_[0]->get("templateId"),\%var); -} - - - - -1; - diff --git a/lib/WebGUI/Wobject/WobjectProxy.pm b/lib/WebGUI/Wobject/WobjectProxy.pm deleted file mode 100644 index c9adac7e1..000000000 --- a/lib/WebGUI/Wobject/WobjectProxy.pm +++ /dev/null @@ -1,434 +0,0 @@ -package WebGUI::Wobject::WobjectProxy; - -#------------------------------------------------------------------- -# WebGUI is Copyright 2001-2005 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 -#------------------------------------------------------------------- - -use strict; -use Tie::CPHash; -use WebGUI::DateTime; -use WebGUI::Icon; -use WebGUI::International; -use WebGUI::Privilege; -use WebGUI::Session; -use WebGUI::SQL; -use WebGUI::Page; -use WebGUI::TabForm; -use WebGUI::Template; -use WebGUI::Wobject; -use WebGUI::MetaData; - -our @ISA = qw(WebGUI::Wobject); - - -#------------------------------------------------------------------- -sub name { - return WebGUI::International::get(3,$_[0]->get("namespace")); -} - -#------------------------------------------------------------------- -sub new { - my $class = shift; - my $property = shift; - my $self = WebGUI::Wobject->new( - -properties=>$property, - -useMetaData=>undef, # NO MetaData for wobject proxy - -extendedProperties=>{ - proxiedWobjectId=>{ - fieldType=>"hidden" - }, - proxiedNamespace=>{ - fieldType=>"hidden" - }, - overrideTitle=>{ - fieldType=>"yesNo", - defaultValue=>0 - }, - overrideTemplate=>{ - fieldType=>"yesNo", - defaultValue=>0 - }, - overrideDisplayTitle=>{ - fieldType=>"yesNo", - defaultValue=>0 - }, - overrideDescription=>{ - fieldType=>"yesNo", - defaultValue=>0 - }, - proxiedTemplateId=>{ - fieldType=>"template", - defaultValue=>1 - }, - proxyByCriteria=>{ - fieldType=>"yesNo", - defaultValue=>0, - }, - resolveMultiples=>{ - fieldType=>"selectList", - defaultValue=>"mostRecent", - }, - proxyCriteria=>{ - fieldType=>"textarea", - defaultValue=>"", - }, - } - ); - bless $self, $class; -} - - -#------------------------------------------------------------------- -sub uiLevel { - return 999; -} - -#------------------------------------------------------------------- -sub www_edit { - my $properties = WebGUI::HTMLForm->new; - my $layout = WebGUI::HTMLForm->new; - $layout->template( - -name=>"proxiedTemplateId", - -value=>$_[0]->getValue("proxiedTemplateId"), - -namespace=>$_[0]->get("proxiedNamespace") - ); - $properties->yesNo( - -name=>"overrideTitle", - -value=>$_[0]->getValue("overrideTitle"), - -label=>WebGUI::International::get(7,$_[0]->get("namespace")) - ); - $layout->yesNo( - -name=>"overrideDisplayTitle", - -value=>$_[0]->getValue("overrideDisplayTitle"), - -label=>WebGUI::International::get(8,$_[0]->get("namespace")) - ); - $properties->yesNo( - -name=>"overrideDescription", - -value=>$_[0]->getValue("overrideDescription"), - -label=>WebGUI::International::get(9,$_[0]->get("namespace")) - ); - $layout->yesNo( - -name=>"overrideTemplate", - -value=>$_[0]->getValue("overrideTemplate"), - -label=>WebGUI::International::get(10,$_[0]->get("namespace")) - ); - my @data = WebGUI::SQL->quickArray("select page.urlizedTitle,wobject.title from wobject left join page on wobject.pageId=page.pageId - where wobject.wobjectId=".quote($_[0]->get("proxiedWobjectId"))); - $properties->readOnly( - -label=>WebGUI::International::get(1,$_[0]->get("namespace")), - -value=>''.$data[1].' ('.$_[0]->get("proxiedWobjectId").')' - ); - if($session{setting}{metaDataEnabled}) { - $properties->yesNo( - -name=>"proxyByCriteria", - -value=>$_[0]->getValue("proxyByCriteria"), - -label=>WebGUI::International::get("Proxy by alternate criteria?",$_[0]->get("namespace")), - -extras=>q|Onchange=" - if (this.form.proxyByCriteria[0].checked) { - this.form.resolveMultiples.disabled=false; - this.form.proxyCriteria.disabled=false; - } else { - this.form.resolveMultiples.disabled=true; - this.form.proxyCriteria.disabled=true; - }"| - ); - if ($_[0]->getValue("proxyByCriteria") == 0) { - $_[0]->{_disabled} = 'disabled=true'; - } - $properties->selectList( - -name=>"resolveMultiples", - -value=>[ $_[0]->getValue("resolveMultiples") ], - -label=>WebGUI::International::get("Resolve Multiples?",$_[0]->get("namespace")), - -options=>{ - mostRecent=>WebGUI::International::get("Most Recent",$_[0]->get("namespace")), - random=>WebGUI::International::get("Random",$_[0]->get("namespace")), - }, - -extras=>$_[0]->{_disabled} - ); - - $properties->readOnly( - -value=>$_[0]->_drawQueryBuilder(), - -label=>WebGUI::International::get("Criteria",$_[0]->get("namespace")), - ); - } - return $_[0]->SUPER::www_edit( - -properties=>$properties->printRowsOnly, - -layout=>$layout->printRowsOnly, - -headingId=>2, - -helpId=>"wobject proxy add/edit" - ); -} - -#------------------------------------------------------------------- -sub www_editSave { - $_[0]->SUPER::www_editSave(); # This will do the priv check as well. - my $scratchId = "WobjectProxy_" . $_[0]->get("wobjectId"); - WebGUI::Session::deleteAllScratch($scratchId); - return ""; -} - -#------------------------------------------------------------------- -sub _drawQueryBuilder { - # Initialize operators - my @textFields = qw|text yesNo selectList radioList|; - my %operator; - foreach (@textFields) { - $operator{$_} = { - "=" => WebGUI::International::get("is",$_[0]->get("namespace")), - "!=" => WebGUI::International::get("isnt",$_[0]->get("namespace")) - }; - } - $operator{integer} = { - "=" => WebGUI::International::get("equal to",$_[0]->get("namespace")), - "!=" => WebGUI::International::get("not equal to",$_[0]->get("namespace")), - "<" => WebGUI::International::get("less than",$_[0]->get("namespace")), - ">" => WebGUI::International::get("greater than",$_[0]->get("namespace")) - }; - - # Get the fields and count them - my $fields = WebGUI::MetaData::getMetaDataFields(); - my $fieldCount = scalar(keys %$fields); - - unless ($fieldCount) { # No fields found.... - return 'No metadata defined yet. - Click here to define metadata attributes.'; - } - - # Static form fields - my $proxyCriteriaField = WebGUI::Form::textarea({ - name=>"proxyCriteria", - value=>$_[0]->getValue("proxyCriteria"), - extras=>'style="width: 100%" '.$_[0]->{_disabled} - }); - my $conjunctionField = WebGUI::Form::selectList({ - name=>"conjunction", - options=>{ - "AND" => WebGUI::International::get("AND",$_[0]->get("namespace")), - "OR" => WebGUI::International::get("OR",$_[0]->get("namespace"))}, - value=>["OR"], - extras=>'class="qbselect"', - }); - - # html - my $output; - $output .= ''; - $output .= ''; - - $output .= qq| - - - - - - - - - - - - - - - - - - |; - - # Here starts the field loop - foreach my $field (keys %$fields) { - my $fieldLabel = $fields->{$field}{fieldName}; - my $fieldType = $fields->{$field}{fieldType} || "text"; - - # The operator select field - my $opFieldName = "op_field".$fields->{$field}{fieldId}; - my $opField = WebGUI::Form::selectList({ - name=>$opFieldName, - uiLevel=>5, - options=>$operator{$fieldType}, - extras=>'class="qbselect"' - }); - # The value select field - my $valFieldName = "val_field".$fields->{$field}{fieldId}; - my $valueField = WebGUI::Form::dynamicField($fieldType, { - name=>$valFieldName, - uiLevel=>5, - extras=>qq/title="$fields->{$field}{description}" class="qbselect"/, - possibleValues=>$fields->{$field}{possibleValues}, - }); - # An empty row - $output .= qq| - - - - - - - - |; - - # Table row with field info - $output .= qq| - - - - - - - - |; - } - # Close the table - $output .= "
$proxyCriteriaField
-
- $conjunctionField -

$fieldLabel

- $opField - - $valueField - -
"; - - return $output; -} - -#------------------------------------------------------------------- -sub www_view { - return WebGUI::International::get(4,$_[0]->get("namespace")); -} - - -1; - - -#------------------------------------------------------------------- - -=head2 getAssetByCriteria ( hashRef ) - -This function will search for a asset that match a metadata criteria set. -If no asset is found, undef will be returned. - -=head3 hashRef - -A typical hashRef for this function will look like: - -{ - proxiedNamespace => "Article", - resolveMultiples => "random", - proxyCriteria => "State = Wisconsin AND Country != Sauk" -} - -Most of the time this will be a: - -WebGUI::SQL->quickHashRef("select * from AssetProxy where assetId=".quote($proxiedId)); - -=cut - -sub getAssetByCriteria { - my $assetProxy = shift; - my $criteria = $assetProxy->{proxyCriteria}; - my $order = $assetProxy->{resolveMultiples}; - my $namespace = $assetProxy->{proxiedNamespace}; - my $assetId = $assetProxy->{assetId}; - - # Parse macro's in criteria - $criteria = WebGUI::Macro::process($criteria); - - # Once a asset is found, we will stick to that asset, - # to prevent the proxying of multiple- depth assets like Surveys and USS. - my $scratchId; - if ($assetId) { - $scratchId = "AssetProxy_" . $assetId; - if($session{scratch}{$scratchId}) { - return $session{scratch}{$scratchId} unless ($session{var}{adminOn}); - } - } - - # $criteria = "State = Wisconsin AND Country != Sauk"; - # - # State = Wisconsin AND Country != Sauk - # | | | - # |- $field |_ $operator |- $value - # |_ $attribute |_ $attribute - my $operator = qr/<>|!=|=|>=|<=|>|<|like/i; - my $attribute = qr/['"][^()|=>unconditionalRead($sql); - while (my ($data) = $sth->array) { - push (@wids, $data); - } - $sth->finish; - - # No matching assets found. - if (scalar(@wids) == 0) { - return undef; # fall back to the originally mirrored asset. - } - my $wid; - # Grab a wid from the results - if ($order eq 'random') { - $wid = $wids[ rand @wids ]; - } else { - #default order is mostRecent - $wid = $wids[0]; # 1st element in list is most recent. - } - - # Store the matching assetId in user scratch. - WebGUI::Session::setScratch($scratchId,$wid) if ($scratchId); - - return $wid; -} - -