LoadGlobalTags();
$section = "in-portal:template_editor";
$ThemeId = GetVar('ThemeId');
$FileId = GetVar('FileId');
if(!GetVar('Action',true) || !is_object($f) ) $f = new clsThemeFile($FileId);
if($FileId)
{
$theme = new clsTheme( $f->Get("ThemeId") ); // create theme from file
$f->LoadFileContents(false);
$name = $f->Get("FileName");
$Action="m_template_edit";
}
else
{
if($ThemeId) // if theme is set
{
$theme = new clsTheme($ThemeId);
$f->Set("ThemeId",$ThemeId);
$f->Set("FilePath",$theme->Get("name"));
$name = "New Template";
$Action = "m_template_add";
}
}
if( is_object($f) && isset($_POST['Action']) )
{
// aka SetFieldsFromHash
//print_pre($_POST);
//echo "SetFields From POST
";
$f->Set( Array('FileName','Description','Contents'),
Array(basename($_POST['name']), $_POST['Description'], $_POST['contents']) );
}
$objTemplateCheck = new clsTemplateChecker($theme->ThemeDirectory()."/");
if(count($f->Contents)>0)
{
$fullname = $f->Get("FilePath")."/".$name;
$TemplateType = $objTemplateCheck->GetTemplateType($fullname);
}
else
$TemplateType="new";
if($ThemeId)
{
$m_var_list_update["theme"]=$ThemeId;
$cat = 0;
$template = "index";
if(is_object($f))
{
$p = $f->Get("FilePath");
if(strlen($p))
{
if(substr($p,0,1)=="/")
$p = substr($p,1);
$p .= "/";
$mod = $objModules->GetModuleByPath($p);
if(is_object($mod))
{
$cat = $mod->Get("RootCat");
$template=$mod->Get("TemplatePath")."index";
}
}
}
$m_var_list_update["t"] = $template;
$m_var_list_update["cat"] = $cat;
$PreviewUrl ="http://".ThisDomain().$objConfig->Get("Site_Path")."index.php?env=".BuildEnv();
}
unset($objEditItems);
$envar = "env=".BuildEnv();
$formaction = $_SERVER["PHP_SELF"]."?".$envar;
$sec = $objSections->GetSection($section);
$objListToolBar = new clsToolBar();
$objListToolBar->Set("section",$section);
$objListToolBar->Set("load_menu_func","");
$objListToolBar->Set("CheckClass","ThemeChecks");
$objListToolBar->Add("select", "la_ToolTip_Save","#","swap('select','toolbar/tool_select_f2.gif');",
"swap('select', 'toolbar/tool_select.gif');",
"SelectSubmit();",
"tool_select.gif");
$objListToolBar->Add("cancel", "la_ToolTip_Close","#","swap('cancel','toolbar/tool_stop_f2.gif');",
"swap('cancel', 'toolbar/tool_stop.gif');","window.close();","tool_stop.gif");
$objListToolBar->Add("divider");
$objListToolBar->Add("template_preview","la_ToolTip_Preview","#", "swap('template_preview','toolbar/tool_preview_template_f2.gif');",
"swap('template_preview', 'toolbar/tool_preview_template.gif');",
"ShowPreview('$PreviewUrl');","tool_preview_template.gif");
//$objListToolBar->AddToInitScript("fwLoadMenus();");
$title = prompt_language("la_Text_Editing")." ".prompt_language("la_Text_Theme")." '".$theme->Get("Name")."' - ".prompt_language("la_Text_Template");
$title .= " '".$name."'";
$path = $f->FullPath();
if(!is_writable($path))
$title .= " (".admin_language("la_text_ReadOnly").")";
int_header($objListToolBar,NULL,$title);
?>