From 299995af1406dcdbe3a5688b23df57febc15fb65 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Sun, 26 May 2002 18:32:08 +0000 Subject: [PATCH] Changed style system to a "body" configuration rather than header/footer. --- lib/WebGUI/Macro.pm | 20 ++----- lib/WebGUI/Operation/Style.pm | 101 +++++++++++++--------------------- lib/WebGUI/Session.pm | 22 ++++++++ lib/WebGUI/Style.pm | 14 ++--- 4 files changed, 70 insertions(+), 87 deletions(-) diff --git a/lib/WebGUI/Macro.pm b/lib/WebGUI/Macro.pm index d8623ccd0..ca154060a 100644 --- a/lib/WebGUI/Macro.pm +++ b/lib/WebGUI/Macro.pm @@ -29,24 +29,12 @@ sub getParams { #------------------------------------------------------------------- sub process { - my (@files, $file, $cmd, $output, $macroDir); + my ($macro, $cmd, $output); $output = $_[0]; - if ($^O =~ /Win/i) { - $macroDir = "\\lib\\WebGUI\\Macro"; - } else { - $macroDir = "/lib/WebGUI/Macro"; - } - opendir (DIR,$session{config}{webguiRoot}.$macroDir) or WebGUI::ErrorHandler::fatalError("Can't open macro directory!"); - @files = readdir(DIR); - foreach $file (@files) { - if ($file =~ /(.*?)\.pm$/) { - $cmd = "use WebGUI::Macro::".$1; - eval($cmd); - $cmd = "WebGUI::Macro::".$1."::process"; - $output = &$cmd($output); - } + foreach $macro (keys %{$session{macro}}) { + $cmd = "WebGUI::Macro::".$macro."::process"; + $output = &$cmd($output); } - closedir(DIR); return $output; } diff --git a/lib/WebGUI/Operation/Style.pm b/lib/WebGUI/Operation/Style.pm index 718cde3be..654c522ff 100644 --- a/lib/WebGUI/Operation/Style.pm +++ b/lib/WebGUI/Operation/Style.pm @@ -13,59 +13,26 @@ package WebGUI::Operation::Style; use Exporter; use strict; use Tie::CPHash; -use WebGUI::Form; +use WebGUI::HTMLForm; +use WebGUI::Icon; use WebGUI::International; use WebGUI::Paginator; use WebGUI::Privilege; use WebGUI::Session; -use WebGUI::Shortcut; use WebGUI::SQL; use WebGUI::URL; use WebGUI::Utility; our @ISA = qw(Exporter); -our @EXPORT = qw(&www_copyStyle &www_addStyle &www_addStyleSave &www_deleteStyle &www_deleteStyleConfirm &www_editStyle &www_editStyleSave &www_listStyles); - -#------------------------------------------------------------------- -sub www_addStyle { - my ($output); - if (WebGUI::Privilege::isInGroup(5)) { - $output .= helpLink(16); - $output .= '

'.WebGUI::International::get(150).'

'; - $output .= formHeader(); - $output .= WebGUI::Form::hidden("op","addStyleSave"); - $output .= ''; - $output .= tableFormRow(WebGUI::International::get(151),WebGUI::Form::text("name",20,30)); - $output .= tableFormRow(WebGUI::International::get(152),WebGUI::Form::textArea("header",'',50,10)); - $output .= tableFormRow(WebGUI::International::get(153),WebGUI::Form::textArea("footer",'',50,10)); - $output .= tableFormRow(WebGUI::International::get(154),WebGUI::Form::textArea("styleSheet","",50,10)); - $output .= formSave(); - $output .= '
'; - $output .= ' '; - } else { - $output = WebGUI::Privilege::adminOnly(); - } - return $output; -} - -#------------------------------------------------------------------- -sub www_addStyleSave { - my ($output); - if (WebGUI::Privilege::isInGroup(5)) { - WebGUI::SQL->write("insert into style values (".getNextId("styleId").", ".quote($session{form}{name}).", ".quote($session{form}{header}).", ".quote($session{form}{footer}).", ".quote($session{form}{styleSheet}).")"); - $output = www_listStyles(); - } else { - $output = WebGUI::Privilege::adminOnly(); - } - return $output; -} +our @EXPORT = qw(&www_copyStyle &www_deleteStyle &www_deleteStyleConfirm &www_editStyle &www_editStyleSave &www_listStyles); #------------------------------------------------------------------- sub www_copyStyle { my (%style); if (WebGUI::Privilege::isInGroup(5)) { %style = WebGUI::SQL->quickHash("select * from style where styleId=$session{form}{sid}"); - WebGUI::SQL->write("insert into style values (".getNextId("styleId").", ".quote('Copy of '.$style{name}).", ".quote($style{header}).", ".quote($style{footer}).", ".quote($style{styleSheet}).")"); + WebGUI::SQL->write("insert into style (styleId,name,body,styleSheet) values (".getNextId("styleId").", + ".quote('Copy of '.$style{name}).", ".quote($style{body}).", ".quote($style{styleSheet}).")"); return www_listStyles(); } else { return WebGUI::Privilege::adminOnly(); @@ -78,7 +45,7 @@ sub www_deleteStyle { if ($session{form}{sid} < 26 && $session{form}{sid} > 0) { return WebGUI::Privilege::vitalComponent(); } elsif (WebGUI::Privilege::isInGroup(5)) { - $output .= helpLink(4); + $output .= helpIcon(4); $output .= '

'.WebGUI::International::get(42).'

'; $output .= WebGUI::International::get(155).'

'; $output .= '

quickHash("select * from style where styleId=$session{form}{sid}"); + } + $output .= helpIcon(16); $output .= '

'.WebGUI::International::get(156).'

'; - $output .= formHeader(); - $output .= WebGUI::Form::hidden("op","editStyleSave"); - $output .= WebGUI::Form::hidden("sid",$session{form}{sid}); - $output .= ''; - $output .= tableFormRow(WebGUI::International::get(380),$session{form}{sid}); - $output .= tableFormRow(WebGUI::International::get(151),WebGUI::Form::text("name",20,30,$style{name})); - $output .= tableFormRow(WebGUI::International::get(152),WebGUI::Form::textArea("header",$style{header},50,10)); - $output .= tableFormRow(WebGUI::International::get(153),WebGUI::Form::textArea("footer",$style{footer},50,10)); - $output .= tableFormRow(WebGUI::International::get(154),WebGUI::Form::textArea("styleSheet",$style{styleSheet},50,10)); - $output .= formSave(); - $output .= '
'; - $output .= ' '; + $f = WebGUI::HTMLForm->new; + $f->hidden("op","editStyleSave"); + $f->hidden("sid",$session{form}{sid}); + $f->readOnly($session{form}{sid},WebGUI::International::get(380)); + $f->text("name",WebGUI::International::get(151),$style{name}); + $f->HTMLArea("body",WebGUI::International::get(501),$style{body},'','','',(5+$session{setting}{textAreaRows})); + $f->textarea("styleSheet",WebGUI::International::get(154),$style{styleSheet},'','','',(5+$session{setting}{textAreaRows})); + $f->submit; + $output .= $f->print; } else { $output = WebGUI::Privilege::adminOnly(); } @@ -134,7 +103,13 @@ sub www_editStyle { #------------------------------------------------------------------- sub www_editStyleSave { if (WebGUI::Privilege::isInGroup(5)) { - WebGUI::SQL->write("update style set name=".quote($session{form}{name}).", header=".quote($session{form}{header}).", footer=".quote($session{form}{footer}).", styleSheet=".quote($session{form}{styleSheet})." where styleId=".$session{form}{sid}); + if ($session{form}{sid} eq "new") { + $session{form}{sid} = getNextId("styleId"); + WebGUI::SQL->write("insert into style (styleId) values ($session{form}{sid})"); + } + $session{form}{body} = "^-;" if ($session{form}{body} eq ""); + WebGUI::SQL->write("update style set name=".quote($session{form}{name}).", body=".quote($session{form}{body}).", + styleSheet=".quote($session{form}{styleSheet})." where styleId=".$session{form}{sid}); return www_listStyles(); } else { return WebGUI::Privilege::adminOnly(); @@ -145,19 +120,17 @@ sub www_editStyleSave { sub www_listStyles { my ($output, $sth, @data, @row, $i, $p); if (WebGUI::Privilege::isInGroup(5)) { - $output = helpLink(9); + $output = helpIcon(9); $output .= '

'.WebGUI::International::get(157).'

'; - $output .= '
'.WebGUI::International::get(158).'
'; $sth = WebGUI::SQL->read("select styleId,name from style where name<>'Reserved' order by name"); while (@data = $sth->array) { - $row[$i] = ''; + $row[$i] = '' + .deleteIcon('op=deleteStyle&sid='.$data[0]) + .editIcon('op=editStyle&sid='.$data[0]) + .copyIcon('op=copyStyle&sid='.$data[0]) + .''; $row[$i] .= ''.$data[1].''; $i++; } diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index d13be1c54..1e9553230 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -93,6 +93,27 @@ sub _getUserInfo { return \%user; } +#------------------------------------------------------------------- +sub _loadMacros { + my ($namespace, $cmd, @files, $file, $dir); + if ($^O =~ /Win/i) { + $dir = "\\lib\\WebGUI\\Macro"; + } else { + $dir = "/lib/WebGUI/Macro"; + } + opendir (DIR,$session{config}{webguiRoot}.$dir) or WebGUI::ErrorHandler::fatalError("Can't open macro directory!"); + @files = readdir(DIR); + foreach $file (@files) { + if ($file =~ /(.*?)\.pm$/) { + $namespace = $1; + $cmd = "use WebGUI::Macro::".$1; + eval($cmd); + $session{macro}{$namespace} = $namespace; + } + } + closedir(DIR); +} + #------------------------------------------------------------------- sub _loadWobjects { my ($dir, @files, $file, $cmd, $namespace); @@ -199,6 +220,7 @@ sub open { ###---------------------------- ### loading plugins _loadWobjects(); + _loadMacros(); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Style.pm b/lib/WebGUI/Style.pm index a8fec778a..e7a5aa9c6 100644 --- a/lib/WebGUI/Style.pm +++ b/lib/WebGUI/Style.pm @@ -18,18 +18,18 @@ use WebGUI::SQL; #------------------------------------------------------------------- sub getStyle { - my ($header, $footer, @style, %style, $styleId); + my ($header, $footer, %style, $styleId, @body); tie %style, 'Tie::CPHash'; if ($session{form}{makePrintable}) { $styleId = $session{form}{style} || 3; - %style = WebGUI::SQL->quickHash("select header,footer,styleSheet from style where styleId=$styleId"); + %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}.''.$style{header}; - $footer = $style{footer}.''; } else { - tie %style, 'Tie::CPHash'; - %style = WebGUI::SQL->quickHash("select header,footer,styleSheet from style where styleId=$session{page}{styleId}"); + %style = WebGUI::SQL->quickHash("select * from style where styleId=$session{page}{styleId}"); + @body = split(/\^\-\;/,$style{body}); $header = $session{setting}{docTypeDec}."\n".' @@ -51,9 +51,9 @@ sub getStyle { $session{page}{synopsis}.'">'; } - $header .= ''.$style{header}; - $footer = $style{footer}.' '; + $header .= ''.$body[0]; } + $footer = $body[1].' '; $header = WebGUI::Macro::process($header); $footer = WebGUI::Macro::process($footer); return ($header, $footer);