package WebGUI::Operation::Style; #------------------------------------------------------------------- # WebGUI is Copyright 2001 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 Exporter; use strict; use Tie::CPHash; use WebGUI::Form; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Utility; our @ISA = qw(Exporter); our @EXPORT = qw(&www_addStyle &www_addStyleSave &www_deleteStyle &www_deleteStyleConfirm &www_editStyle &www_editStyleSave &www_listStyles); #------------------------------------------------------------------- sub www_addStyle { my ($output); if (WebGUI::Privilege::isInGroup(3)) { $output .= '

Add Style

'; $output .= WebGUI::Form::hidden("op","addStyleSave"); $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= '
Style Name'.WebGUI::Form::text("name",20,30).'
Header'.WebGUI::Form::textArea("header",'',50,10,1).'
Footer'.WebGUI::Form::textArea("footer",'',50,10,1).'
Style Sheet'.WebGUI::Form::textArea("styleSheet",'',50,10).'
'.WebGUI::Form::submit("save").'
'; $output .= '
'; } else { $output = WebGUI::Privilege::adminOnly(); } return $output; } #------------------------------------------------------------------- sub www_addStyleSave { my ($output); if (WebGUI::Privilege::isInGroup(3)) { 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}).")",$session{dbh}); $output = www_listStyles(); } else { $output = WebGUI::Privilege::adminOnly(); } return $output; } #------------------------------------------------------------------- sub www_deleteStyle { my ($output); if ($session{form}{sid} < 26) { return WebGUI::Privilege::vitalComponent(); } elsif (WebGUI::Privilege::isInGroup(3)) { $output .= '

Please Confirm

'; $output .= 'Are you certain you wish to delete this style and migrate all pages using this style to the "Fail Safe" style?

'; $output .= '

Yes, I\'m sure.'; $output .= '    No, I made a mistake.
'; return $output; } else { return WebGUI::Privilege::adminOnly(); } } #------------------------------------------------------------------- sub www_deleteStyleConfirm { if ($session{form}{sid} < 26) { return WebGUI::Privilege::vitalComponent(); } elsif (WebGUI::Privilege::isInGroup(3)) { WebGUI::SQL->write("delete from style where styleId=".$session{form}{sid},$session{dbh}); WebGUI::SQL->write("update page set styleId=2 where styleId=".$session{form}{sid},$session{dbh}); return www_listStyles(); } else { return WebGUI::Privilege::adminOnly(); } } #------------------------------------------------------------------- sub www_editStyle { my ($output, %style); tie %style, 'Tie::CPHash'; if (WebGUI::Privilege::isInGroup(3)) { %style = WebGUI::SQL->quickHash("select * from style where styleId=$session{form}{sid}",$session{dbh}); $output .= '

Edit Style

'; $output .= WebGUI::Form::hidden("op","editStyleSave"); $output .= WebGUI::Form::hidden("sid",$session{form}{sid}); $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= '
Style Name'.WebGUI::Form::text("name",20,30,$style{name}).'
Header'.WebGUI::Form::textArea("header",$style{header},50,10,1).'
Footer'.WebGUI::Form::textArea("footer",$style{footer},50,10,1).'
Style Sheet'.WebGUI::Form::textArea("styleSheet",$style{styleSheet},50,10).'
'.WebGUI::Form::submit("save").'
'; $output .= '
'; } else { $output = WebGUI::Privilege::adminOnly(); } return $output; } #------------------------------------------------------------------- sub www_editStyleSave { if (WebGUI::Privilege::isInGroup(3)) { 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},$session{dbh}); return www_listStyles(); } else { return WebGUI::Privilege::adminOnly(); } } #------------------------------------------------------------------- sub www_listStyles { my ($output, $pn, $sth, @data, @row, $i, $itemsPerPage); if (WebGUI::Privilege::isInGroup(3)) { $itemsPerPage = 50; $output = '

Styles

'; $output .= '
Add a new style.
'; $output .= ''; $sth = WebGUI::SQL->read("select styleId,name from style where name<>'Reserved' order by name",$session{dbh}); while (@data = $sth->array) { $row[$i] = ''; $row[$i] .= ''; $i++; } if ($session{form}{pn} < 1) { $pn = 0; } else { $pn = $session{form}{pn}; } for ($i=($itemsPerPage*$pn); $i<($itemsPerPage*($pn+1));$i++) { $output .= $row[$i]; } $output .= '
'.$data[1].'
'; $output .= ''; return $output; } else { return WebGUI::Privilege::adminOnly(); } } 1;