I use this:
PHP Code:
function template_insert($name, $content)
{
global $DB_site;
$template = compile_template($content);
$DB_site->query("INSERT INTO " . TABLE_PREFIX . "template (templateid, title, template, template_un, styleid, templatetype, dateline, username, version) VALUES (NULL, '$name', '" . addslashes($template) . "', '" . addslashes($content) ."', '-1', 'template', '" . time() . "', 'USERNAME', '3.0.7')");
}
-1 mean the default style I think but I didn't test for all style, maybe you should query all styleid and then use a while loop for that function.