Adding templates.

This commit is contained in:
JT Smith 2002-10-16 06:06:45 +00:00
parent fc1e0eb763
commit 2b09ea9f64
9 changed files with 471 additions and 381 deletions

View file

@ -21,6 +21,7 @@ use WebGUI::Paginator;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Template;
use WebGUI::URL;
use WebGUI::Utility;
@ -32,8 +33,10 @@ sub www_copyTemplate {
my (%template);
if (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) {
%template = WebGUI::SQL->quickHash("select * from template where templateId=$session{form}{tid}");
WebGUI::SQL->write("insert into template (templateId,name,template) values (".getNextId("templateId").",
".quote('Copy of '.$template{name}).", ".quote($template{template}).")");
WebGUI::SQL->write("insert into template (templateId,name,template,namespace)
values (".getNextId("templateId").",
".quote('Copy of '.$template{name}).", ".quote($template{template}).",
".quote($template{namespace}).")");
return www_listTemplates();
} else {
return WebGUI::Privilege::adminOnly();
@ -50,10 +53,11 @@ sub www_deleteTemplate {
$output .= '<h1>'.WebGUI::International::get(42).'</h1>';
$output .= WebGUI::International::get(502).'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('op=deleteTemplateConfirm&tid='.$session{form}{tid})
WebGUI::URL::page('op=deleteTemplateConfirm&tid='.$session{form}{tid}.'&namespace='
.$session{form}{namespace})
.'">'.WebGUI::International::get(44).'</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page('op=listTemplates').
'">'.WebGUI::International::get(45).'</a></div>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page('op=listTemplates&namespace='
.$session{form}{namespace}).'">'.WebGUI::International::get(45).'</a></div>';
return $output;
} else {
return WebGUI::Privilege::adminOnly();
@ -66,13 +70,16 @@ sub www_deleteTemplateConfirm {
if ($session{form}{tid} < 1000 && $session{form}{tid} > 1000) {
return WebGUI::Privilege::vitalComponent();
} 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=1 where pageId=$pageId");
if ($session{form}{namespace} eq "Page") {
$a = WebGUI::SQL->read("select * from page where templateId=".$session{form}{tid});
while (($pageId) = $a->array) {
WebGUI::SQL->write("update wobject set templatePosition=1 where pageId=$pageId");
}
$a->finish;
WebGUI::SQL->write("update page set templateId=2 where templateId=".$session{form}{tid});
}
$a->finish;
WebGUI::SQL->write("delete from template where templateId=".$session{form}{tid});
WebGUI::SQL->write("update page set templateId=2 where templateId=".$session{form}{tid});
WebGUI::SQL->write("delete from template where templateId=".$session{form}{tid}
." and namespace=".quote($session{form}{namespace}));
return www_listTemplates();
} else {
return WebGUI::Privilege::adminOnly();
@ -85,14 +92,22 @@ sub www_editTemplate {
tie %template, 'Tie::CPHash';
if (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) {
if ($session{form}{tid} eq "new") {
$template{template} = "<table>\n <tr>\n <td>\n\n<tmpl_var template.position1>\n\n </td>\n </tr>\n</table>\n";
if ($session{form}{namespace} eq "Page") {
$template{template} = "<table>\n <tr>\n <td>\n\n<tmpl_var template.position1>\n\n".
"</td>\n </tr>\n</table>\n";
} else {
$template{template} = "<h1><tmpl_var title></h1>\n\n";
}
} else {
%template = WebGUI::SQL->quickHash("select * from template where templateId=$session{form}{tid}");
%template = WebGUI::SQL->quickHash("select * from template where templateId=$session{form}{tid} and
namespace=".quote($session{form}{namespace}));
}
$output .= helpIcon(34);
$output .= '<h1>'.WebGUI::International::get(507).'</h1>';
$f = WebGUI::HTMLForm->new;
$f->hidden("op","editTemplateSave");
$f->hidden("afterEdit",$session{form}{afterEdit});
$f->hidden("namespace",$session{form}{namespace});
$f->hidden("tid",$session{form}{tid});
$f->readOnly($session{form}{tid},WebGUI::International::get(503));
$f->text("name",WebGUI::International::get(528),$template{name});
@ -100,7 +115,7 @@ sub www_editTemplate {
$f->submit;
$output .= $f->print;
} else {
$output = WebGUI::Privilege::adminOnly();
$output = WebGUI::Privilege::insufficient();
}
return $output;
}
@ -109,45 +124,54 @@ sub www_editTemplate {
sub www_editTemplateSave {
if (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) {
if ($session{form}{tid} eq "new") {
$session{form}{tid} = getNextId("templateId");
WebGUI::SQL->write("insert into template (templateId) values ($session{form}{tid})");
($session{form}{tid}) = WebGUI::SQL->quickArray("select max(internationalId)
from international where templateId=".$session{form}{tid}."
and namespace=".quote($session{form}{namespace}));
$session{form}{tid}++;
WebGUI::SQL->write("insert into template (templateId,namespace) values
($session{form}{tid}, ".quote($session{form}{namespace}).")");
}
$session{form}{template} = "<table>\n <tr>\n <td>\n\n^0;\n\n </td>\n </tr>\n</table>\n" if ($session{form}{template} eq "");
WebGUI::SQL->write("update template set name=".quote($session{form}{name}).", template=".quote($session{form}{template})."
if ($session{form}{template} eq "" && $session{form}{namespace} eq "Page") {
$session{form}{template} = "<table>\n<tr>\n<td>\n\n<tmpl_var template.position1>\n\n</td>\n </tr>\n</table>\n";
}
WebGUI::SQL->write("update template set name=".quote($session{form}{name}).",
template=".quote($session{form}{template})."
where templateId=".$session{form}{tid});
return www_listTemplates();
} else {
return WebGUI::Privilege::adminOnly();
return WebGUI::Privilege::insufficient();
}
}
#-------------------------------------------------------------------
sub www_listTemplates {
my ($output, $sth, @data, @row, $i, $p);
my ($output, $sth, @data, @row, $i, $p, $where);
if (WebGUI::Privilege::isInGroup($session{setting}{templateManagersGroup})) {
$where = "where namespace=".quote($session{form}{namespace}) if ($session{form}{namespace});
$output = helpIcon(33);
$output .= '<h1>'.WebGUI::International::get(506).'</h1>';
$output .= '<div align="center"><a href="'.WebGUI::URL::page('op=editTemplate&tid=new').
'">'.WebGUI::International::get(505).'</a><p/></div>';
$sth = WebGUI::SQL->read("select templateId,name from template order by name");
$sth = WebGUI::SQL->read("select templateId,name,namespace from template $where order by namespace,name");
while (@data = $sth->array) {
$row[$i] = '<tr><td valign="top" class="tableData">'
.deleteIcon('op=deleteTemplate&tid='.$data[0])
.editIcon('op=editTemplate&tid='.$data[0])
.copyIcon('op=copyTemplate&tid='.$data[0])
.deleteIcon('op=deleteTemplate&tid='.$data[0].'&namespace='.$data[2])
.editIcon('op=editTemplate&tid='.$data[0].'&namespace='.$data[2])
.copyIcon('op=copyTemplate&tid='.$data[0].'&namespace='.$data[2])
.'</td>';
$row[$i] .= '<td valign="top" class="tableData">'.$data[1].'</td></tr>';
$row[$i] .= '<td valign="top" class="tableData">'.$data[1].'</td>';
$row[$i] .= '<td valign="top" class="tableData">'.$data[2].'</td></tr>';
$i++;
}
$sth->finish;
$p = WebGUI::Paginator->new(WebGUI::URL::page('op=listTemplates'),\@row);
$p = WebGUI::Paginator->new(WebGUI::URL::page('op=listTemplates&namespace='.$session{form}{namespace}),\@row);
$output .= '<table border=1 cellpadding=5 cellspacing=0 align="center">';
$output .= $p->getPage($session{form}{pn});
$output .= '</table>';
$output .= $p->getBarTraditional($session{form}{pn});
return $output;
} else {
return WebGUI::Privilege::adminOnly();
return WebGUI::Privilege::insufficient();
}
}