diff --git a/docs/upgrades/upgrade_4.6.9-4.7.0.sql b/docs/upgrades/upgrade_4.6.9-4.7.0.sql
index fec682273..acea0ceaf 100644
--- a/docs/upgrades/upgrade_4.6.9-4.7.0.sql
+++ b/docs/upgrades/upgrade_4.6.9-4.7.0.sql
@@ -74,7 +74,7 @@ alter table Product change productTemplateId Product_templateId int not null def
alter table Product_benefit change productBenefitId Product_benefitId int not null;
alter table Product_feature change productFeatureId Product_featureId int not null;
alter table Product_specification change productSpecificationId Product_specificationId int not null;
-
+update wobject set templatePosition=templatePosition+1;
diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm
index a9b188b93..63ca0e4e6 100644
--- a/lib/WebGUI.pm
+++ b/lib/WebGUI.pm
@@ -28,8 +28,9 @@ use WebGUI::Utility;
#-------------------------------------------------------------------
sub page {
my ($debug, %contentHash, $w, $cmd, $pageEdit, $wobject, $wobjectOutput, $extra, $originalWobject, $proxyWobjectId,
- $sth, $httpHeader, $header, $footer, $content, $operationOutput, $adminBar, %hash, $canEdit);
+ $sth, $httpHeader, $content, $operationOutput, $adminBar, $template, %hash, $canEdit);
WebGUI::Session::open($_[0],$_[1]);
+ $template = 1;
if (exists $session{form}{op}) {
if ($session{form}{op} =~ /^[A-Za-z]+$/) {
$cmd = "WebGUI::Operation::www_".$session{form}{op};
@@ -95,11 +96,9 @@ sub page {
WebGUI::Session::close();
return $httpHeader.$operationOutput.$wobjectOutput;
} elsif ($operationOutput ne "") {
- $contentHash{0} = $operationOutput;
- $content = WebGUI::Template::generate(\%contentHash,1);
+ $contentHash{"template.position".1} = $operationOutput;
} elsif ($wobjectOutput ne "") {
- $contentHash{0} = $wobjectOutput;
- $content = WebGUI::Template::generate(\%contentHash,1);
+ $contentHash{"template.position".1} = $wobjectOutput;
} elsif ($session{page}{redirectURL}) {
$session{header}{redirect} = WebGUI::Session::httpRedirect($session{page}{redirectURL})
} else {
@@ -120,7 +119,7 @@ sub page {
$sth = WebGUI::SQL->read("select * from wobject where pageId=$session{page}{pageId} order by sequenceNumber, wobjectId");
while ($wobject = $sth->hashRef) {
if ($session{var}{adminOn} && $canEdit) {
- $contentHash{${$wobject}{templatePosition}} .= "\n
"
+ $contentHash{"template.position".${$wobject}{templatePosition}} .= "\n
"
.deleteIcon('func=delete&wid='.${$wobject}{wobjectId})
.editIcon('func=edit&wid='.${$wobject}{wobjectId})
.moveUpIcon('func=moveUp&wid='.${$wobject}{wobjectId})
@@ -151,18 +150,17 @@ sub page {
$w = eval{$cmd->new($wobject)};
WebGUI::ErrorHandler::fatalError("Couldn't instanciate wobject: ${$wobject}{namespace}. Root cause: ".$@) if($@);
if ($w->inDateRange) {
- $contentHash{${$wobject}{templatePosition}} .= '';
- $contentHash{${$wobject}{templatePosition}} .= '
';
- $contentHash{${$wobject}{templatePosition}} .= eval{$w->www_view};
+ $contentHash{"template.position".${$wobject}{templatePosition}} .= '
';
+ $contentHash{"template.position".${$wobject}{templatePosition}} .= '
';
+ $contentHash{"template.position".${$wobject}{templatePosition}} .= eval{$w->www_view};
WebGUI::ErrorHandler::fatalError("Wobject runtime error: ${$wobject}{namespace}. Root cause: ".$@) if($@);
- $contentHash{${$wobject}{templatePosition}} .= "
\n\n";
+ $contentHash{"template.position".${$wobject}{templatePosition}} .= "
\n\n";
}
}
$sth->finish;
- $content = WebGUI::Template::generate(\%contentHash,$session{page}{templateId});
+ $template = $session{page}{templateId};
} else {
- $contentHash{0} = WebGUI::Privilege::noAccess();
- $content = WebGUI::Template::generate(\%contentHash,1);
+ $contentHash{"template.position".1} = WebGUI::Privilege::noAccess();
}
}
if ($session{setting}{showDebug} || ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3))) {
@@ -191,9 +189,17 @@ sub page {
return $httpHeader;
} else {
$httpHeader = WebGUI::Session::httpHeader();
- ($header, $footer) = WebGUI::Style::getStyle();
+ $content = WebGUI::Template::process(
+ WebGUI::Macro::process(
+ WebGUI::Style::get(
+ $pageEdit
+ .WebGUI::Template::get($template)
+ )
+ ),
+ \%contentHash
+ );
WebGUI::Session::close();
- return $httpHeader.$adminBar.$header.$pageEdit.$content.$footer.$debug;
+ return $httpHeader.$adminBar.$content.$debug;
}
}
diff --git a/lib/WebGUI/HTML.pm b/lib/WebGUI/HTML.pm
index 7e4adc0f5..522bdd8ff 100644
--- a/lib/WebGUI/HTML.pm
+++ b/lib/WebGUI/HTML.pm
@@ -122,5 +122,6 @@ sub filter {
+
1;
diff --git a/lib/WebGUI/Operation/Page.pm b/lib/WebGUI/Operation/Page.pm
index 77b6fdf9c..7f5162a56 100644
--- a/lib/WebGUI/Operation/Page.pm
+++ b/lib/WebGUI/Operation/Page.pm
@@ -197,7 +197,7 @@ sub www_editPage {
-uiLevel=>8
);
$f->readOnly(
- -value=>WebGUI::Template::selectTemplate($page{templateId}),
+ -value=>WebGUI::Template::select($page{templateId}),
-label=>WebGUI::International::get(356),
-uiLevel=>5
);
@@ -362,8 +362,8 @@ sub www_editPageSave {
menuTitle=".quote($session{form}{menuTitle}).",
synopsis=".quote($session{form}{synopsis})."
where pageId=$session{form}{pageId}");
- WebGUI::SQL->write("update wobject set templatePosition=0 where pageId=$session{form}{pageId}
- and templatePosition>".(WebGUI::Template::countPositions($session{form}{templateId})-1));
+ WebGUI::SQL->write("update wobject set templatePosition=1 where pageId=$session{form}{pageId}
+ and templatePosition>".WebGUI::Template::countPositions($session{form}{templateId}));
_recursivelyChangeStyle($session{page}{pageId}) if ($session{form}{recurseStyle});
_recursivelyChangePrivileges($session{page}{pageId}) if ($session{form}{recursePrivs});
WebGUI::Session::refreshPageInfo($session{page}{pageId}) if ($session{form}{pageId} == $session{page}{pageId});
diff --git a/lib/WebGUI/Operation/Template.pm b/lib/WebGUI/Operation/Template.pm
index ea8bfb33e..2228cf171 100644
--- a/lib/WebGUI/Operation/Template.pm
+++ b/lib/WebGUI/Operation/Template.pm
@@ -68,7 +68,7 @@ sub www_deleteTemplateConfirm {
} elsif (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) {
$a = WebGUI::SQL->read("select * from page where templateId=".$session{form}{tid});
while (($pageId) = $a->array) {
- WebGUI::SQL->write("update wobject set templatePosition=0 where pageId=$pageId");
+ WebGUI::SQL->write("update wobject set templatePosition=1 where pageId=$pageId");
}
$a->finish;
WebGUI::SQL->write("delete from template where templateId=".$session{form}{tid});
@@ -85,7 +85,7 @@ sub www_editTemplate {
tie %template, 'Tie::CPHash';
if (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) {
if ($session{form}{tid} eq "new") {
- $template{template} = "\n";
+ $template{template} = "\n";
} else {
%template = WebGUI::SQL->quickHash("select * from template where templateId=$session{form}{tid}");
}
diff --git a/lib/WebGUI/Style.pm b/lib/WebGUI/Style.pm
index 38e0a08e2..b127461a5 100644
--- a/lib/WebGUI/Style.pm
+++ b/lib/WebGUI/Style.pm
@@ -15,51 +15,42 @@ use Tie::CPHash;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::SQL;
+use WebGUI::Template;
#-------------------------------------------------------------------
-sub getStyle {
- my ($header, $footer, %style, $styleId, @body);
- tie %style, 'Tie::CPHash';
- if ($session{form}{makePrintable}) {
- $styleId = $session{form}{style} || 3;
- %style = WebGUI::SQL->quickHash("select * from style where styleId=$styleId");
- @body = split(/\^\-\;/,$style{body});
- $header = ''."\n";
- $header .= ''.$session{page}{title}.' - '.$session{setting}{companyName}.'';
- $header .= $style{styleSheet}.''.$body[0];
- } else {
- %style = WebGUI::SQL->quickHash("select * from style where styleId=$session{page}{styleId}");
- @body = split(/\^\-\;/,$style{body});
- $header = $session{setting}{docTypeDec}."\n".'
-
-
- ';
- $header .= $session{page}{title}.' - '.$session{setting}{companyName};
- $header .= ''
- .$style{styleSheet}
- .$session{page}{metaTags};
- if ($session{var}{adminOn}) {
- # This "triple incantation" panders to the delicate tastes of various browsers for reliable cache suppression.
- $header .= '';
- $header .= '';
- $header .= '';
- }
- if ($session{page}{defaultMetaTags}) {
- $header .= '';
- $header .= '';
+sub get {
+ my ($header, $footer, %style, $styleId, @body);
+ tie %style, 'Tie::CPHash';
+ if ($session{form}{makePrintable}) {
+ $styleId = $session{form}{style} || 3;
+ } else {
+ $styleId = $session{page}{styleId} || 2;
+ }
+ %style = WebGUI::SQL->quickHash("select * from style where styleId=$styleId");
+ @body = split(/\^\-\;/,$style{body});
+ $header = $session{setting}{docTypeDec}."\n".' ';
+ $header .= $session{page}{title}.' - '.$session{setting}{companyName};
+ $header .= ''
+ .$style{styleSheet}.$session{page}{metaTags};
+ if ($session{var}{adminOn}) {
+ # This "triple incantation" panders to the delicate tastes of various browsers for reliable cache suppression.
+ $header .= '';
+ $header .= '';
+ $header .= '';
+ }
+ if ($session{page}{defaultMetaTags}) {
+ $header .= '';
+ $header .= '';
- }
- $header .= ''.$body[0];
- }
- $footer = $body[1].' ';
- $header = WebGUI::Macro::process($header);
- $footer = WebGUI::Macro::process($footer);
- return ($header, $footer);
+ }
+ $header .= ''.$body[0];
+ $footer = $body[1].' ';
+ return $header.$_[0].$footer;
}
+
1;
diff --git a/lib/WebGUI/Template.pm b/lib/WebGUI/Template.pm
index 35751800f..b2a8cb9d8 100644
--- a/lib/WebGUI/Template.pm
+++ b/lib/WebGUI/Template.pm
@@ -10,6 +10,7 @@ package WebGUI::Template;
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
+use HTML::Template;
use strict;
use Tie::IxHash;
use WebGUI::ErrorHandler;
@@ -17,24 +18,39 @@ use WebGUI::HTMLForm;
use WebGUI::Session;
use WebGUI::SQL;
+
+#-------------------------------------------------------------------
+sub _newPositionFormat {
+ return "";
+}
+
#-------------------------------------------------------------------
sub countPositions {
my ($template, $i);
($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]);
- $i = 0;
- while ($template =~ m/\^$i\;/) {
+ $i = 1;
+ while ($template =~ m/template\.position$i/) {
$i++;
}
- return $i;
+ return $i-1;
}
#-------------------------------------------------------------------
-sub generate {
- my ($output, $content, $template);
- $template = WebGUI::SQL->quickHashRef("select * from template where templateId=".$_[1]);
- $content = $template->{template};
- $content =~ s/\^(\d+)\;/${$_[0]}{$1}/g;
- return $content;
+sub draw {
+ my $template = get($_[0]);
+ $template =~ s/\n//g;
+ $template =~ s/\r//g;
+ $template =~ s/\'/\\\'/g;
+ $template =~ s/\/\/ig;
+ $template =~ s/\/$1/ig;
+ return $template;
+}
+
+#-------------------------------------------------------------------
+sub get {
+ my ($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]);
+ $template =~ s/\^(\d+)\;/_newPositionFormat($1)/eg; #compatibility with old-style templates
+ return $template;
}
#-------------------------------------------------------------------
@@ -42,30 +58,54 @@ sub getList {
my (%list);
tie %list, 'Tie::IxHash';
%list = WebGUI::SQL->buildHash("select templateId,name from template order by name");
- return %list;
+ return \%list;
}
#-------------------------------------------------------------------
sub getPositions {
my (%hash, $template, $i);
tie %hash, "Tie::IxHash";
- ($template) = WebGUI::SQL->quickArray("select template from template where templateId=".$_[0]);
- $i = 0;
- while ($template =~ m/\^$i\;/) {
+ for ($i=1; $i<=countPositions($_[0]); $i++) {
$hash{$i} = $i;
- $i++;
}
return \%hash;
}
#-------------------------------------------------------------------
-sub selectTemplate {
- my ($output, $f, %templates, $key);
- tie %templates,'Tie::IxHash';
+sub process {
+ my ($t, $html);
+ $html = $_[0];
+ $t = HTML::Template->new(
+ scalarref=>\$html,
+ loop_context_vars=>1,
+ die_on_bad_params=>0,
+ strict=>0
+ );
+ while (my ($section, $hash) = each %session) {
+ while (my ($key, $value) = each %$hash) {
+ if (ref $value eq 'ARRAY') {
+ next;
+ #$value = '['.join(', ',@$value).']';
+ } elsif (ref $value eq 'HASH') {
+ next;
+ #$value = '{'.join(', ',map {"$_ => $value->{$_}"} keys %$value).'}';
+ }
+ unless (lc($key) eq "password" || lc($key) eq "identifier") {
+ $t->param($section.".".$key=>$value);
+ }
+ }
+ }
+ $t->param(%{$_[1]});
+ $t->param("webgui.version"=>$WebGUI::VERSION);
+ return $t->output;
+}
+
+#-------------------------------------------------------------------
+sub select {
+ my ($templates, $output, $f, $key);
$f = WebGUI::HTMLForm->new(1);
- %templates = WebGUI::SQL->buildHash("select templateId,name from template order by name");
- $f->select("templateId",\%templates,'',[$_[0]],'','','onChange="changeTemplatePreview(this.form.templateId.value)"');
- %templates = WebGUI::SQL->buildHash("select templateId,template from template");
+ $templates = getList();
+ $f->select("templateId",$templates,'',[$_[0]],'','','onChange="changeTemplatePreview(this.form.templateId.value)"');
$output = '
';
$output .= $f->printRowsOnly;
diff --git a/lib/WebGUI/Wobject.pm b/lib/WebGUI/Wobject.pm
index a4f6cd9b3..9027ffbc8 100644
--- a/lib/WebGUI/Wobject.pm
+++ b/lib/WebGUI/Wobject.pm
@@ -941,7 +941,8 @@ sub www_edit {
-label=>WebGUI::International::get(363),
-value=>[$templatePosition],
-uiLevel=>5,
- -options=>WebGUI::Template::getPositions($session{page}{templateId})
+ -options=>WebGUI::Template::getPositions($session{page}{templateId}),
+ -subtext=>WebGUI::Template::draw($session{page}{templateId})
);
$f->date(
-name=>"startDate",