package WebGUI::Operation::Template; #------------------------------------------------------------------- # WebGUI is Copyright 2001-2004 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::AdminConsole; use WebGUI::Grouping; use WebGUI::HTML; use WebGUI::HTMLForm; use WebGUI::Icon; use WebGUI::International; use WebGUI::Paginator; use WebGUI::Privilege; use WebGUI::Session; use WebGUI::SQL; use WebGUI::Template; use WebGUI::URL; use WebGUI::Utility; #------------------------------------------------------------------- sub _submenu { my $workarea = shift; my $title = shift; $title = WebGUI::International::get($title) if ($title); my $help = shift; my $ac = WebGUI::AdminConsole->new("templates"); if ($help) { $ac->setHelp($help); } $ac->addSubmenuItem(WebGUI::URL::page('op=editTemplate&tid=new&namespace='.$session{form}{namespace}), WebGUI::International::get(505)); if ($session{form}{op} eq "editTemplate" && ($session{form}{tid} ne "new" || $session{form}{op} ne "deleteTemplateConfirm")) { $ac->addSubmenuItem( WebGUI::URL::page('op=editTemplate&tid='.$session{form}{tid}.'&namespace='.$session{form}{namespace}), WebGUI::International::get(851) ); $ac->addSubmenuItem( WebGUI::URL::page('op=copyTemplate&tid='.$session{form}{tid}.'&namespace='.$session{form}{namespace}), WebGUI::International::get(852) ); $ac->addSubmenuItem( WebGUI::URL::page('op=deleteTemplate&tid='.$session{form}{tid}.'&namespace='.$session{form}{namespace}), WebGUI::International::get(853) ); $ac->addSubmenuItem( WebGUI::URL::page('op=listTemplates&namespace='.$session{form}{namespace}), WebGUI::International::get(854) ); } $ac->addSubmenuItem(WebGUI::URL::page('op=listTemplates'), WebGUI::International::get(855)); return $ac->render($workarea, $title); } #------------------------------------------------------------------- sub www_copyTemplate { if (WebGUI::Grouping::isInGroup(8)) { my $template = WebGUI::Template::get($session{form}{tid},$session{form}{namespace}); $template->{name} .= " (copy)"; $template->{templateId} = "new"; WebGUI::Template::set($template); return www_listTemplates(); } else { return WebGUI::Privilege::adminOnly(); } } #------------------------------------------------------------------- sub www_deleteTemplate { my ($output); if ($session{form}{tid} =~ /^\d+$/ && $session{form}{tid} < 1000 && $session{form}{tid} > 0) { return _submenu(WebGUI::Privilege::vitalComponent()); } elsif (WebGUI::Grouping::isInGroup(8)) { $output .= WebGUI::International::get(502).'
'; $output .= '
'; return _submenu($output,'42',"template delete"); } else { return WebGUI::Privilege::adminOnly(); } } #------------------------------------------------------------------- sub www_deleteTemplateConfirm { my ($a, $pageId); if ($session{form}{tid} =~ /^\d+$/ && $session{form}{tid} < 1000 && $session{form}{tid} > 0) { return _submenu(WebGUI::Privilege::vitalComponent()); } elsif (WebGUI::Grouping::isInGroup(8)) { if ($session{form}{namespace} eq "Page") { $a = WebGUI::SQL->read("select * from page where templateId=".quote($session{form}{tid})); while (($pageId) = $a->array) { WebGUI::SQL->write("update wobject set templatePosition=1 where pageId=".quote($pageId)); } $a->finish; WebGUI::SQL->write("update page set templateId=2 where templateId=".quote($session{form}{tid})); } WebGUI::SQL->write("delete from template where templateId=".quote($session{form}{tid}) ." and namespace=".quote($session{form}{namespace})); return www_listTemplates(); } else { return WebGUI::Privilege::adminOnly(); } } #------------------------------------------------------------------- sub www_editTemplate { my ($namespaces, %template, $f); tie %template, 'Tie::CPHash'; if (WebGUI::Grouping::isInGroup(8)) { if ($session{form}{tid} eq "new" || $session{form}{tid} eq "") { if ($session{form}{namespace} eq "Page") { $template{template} = "| \n\n | \n
| \n\n | \n