GetDb(); $templateops = cmsms()->GetTemplateOperations(); $userid = get_userid(); $access = check_permission($userid, 'Add Templates'); /*$use_javasyntax = false; if (get_preference($userid, 'use_javasyntax') == "1") $use_javasyntax = true; */ if ($access) { if (isset($_POST["addtemplate"])/* && !$preview*/) { $validinfo = true; if ($template == "") { $error .= "
  • ".lang("nofieldgiven",array(lang('name')))."
  • "; $validinfo = false; } else { $query = "SELECT template_id from ".cms_db_prefix()."templates WHERE template_name = " . $db->qstr($template); $result = $db->Execute($query); if ($result && $result->RecordCount() > 0) { $error .= "
  • ".lang('templateexists')."
  • "; $validinfo = false; } } if ($content == "") { $error .= "
  • ".lang('nofieldgiven', array(lang('content')))."
  • "; $validinfo = false; } if ($validinfo) { try { $parser = cmsms()->get_template_parser(); cms_utils::set_app_data('tmp_template',$content); try { $parser->fetch('template:appdata;tmp_template'); // do the magic. } catch ( SmartyCompilerException $e ) { $error .= "
  • ".$e->getMessage().'
  • '; $validinfo = false; } $contentBlocks = CMS_Content_Block::get_content_blocks(); if( !is_array($contentBlocks) || count($contentBlocks) == 0 ) { throw new CmsEditContentException('No content blocks defined in template'); } if( !isset($contentBlocks['content_en']) ) { throw new CmsEditContentException('No default content block {content} or {content block=\'content_en\'} defined in template'); } // if we got here, we're golden. } catch( CmsEditContentException $e ) { $error .= "
  • ".$e->getMessage()."
  • "; $validinfo = false; } } if ($validinfo) { $newtemplate = new Template(); $newtemplate->name = $template; $newtemplate->content = $content; //$newtemplate->stylesheet = $stylesheet; $newtemplate->active = $active; $newtemplate->default = 0; Events::SendEvent('Core', 'AddTemplatePre', array('template' => &$newtemplate)); $result = $newtemplate->save(); if ($result) { Events::SendEvent('Core', 'AddTemplatePost', array('template' => &$newtemplate)); // put mention into the admin log audit($newtemplate->id, 'HTML-template: '.$template, 'Added'); redirect($from); return; } else { $error .= "
  • ".lang('errorinsertingtemplate')."$query
  • "; } } } } include_once("header.php"); if (!$access) { //echo "

    ".lang('noaccessto', array(lang('addtemplate')))."

    "; $themeObject->ShowErrors(lang('noaccessto', lang('noaccessto', array(lang('addtemplate'))))); return; } else { if ($error != "") { echo "
    "; //$themeObject->ShowErrors(lang('noaccessto',$error)); } } $smarty = cmsms()->GetSmarty(); $smarty->assign("themeobj",$themeObject); $smarty->assign("template",$template); $smarty->assign("content",$content); $smarty->assign("formurl","addtemplate.php".$urlext); echo $smarty->fetch('addtemplate.tpl'); include_once("footer.php"); # vim:ts=4 sw=4 noet ?>