<?php
/*======================================================================================
Module: Articles
======================================================================================*/

// Check authorisation
if (!isset($gCms)) exit;
if ( !$this->CheckPermission('Modify Templates') ) exit;
$errors = array();

// Get POST data
$tabto = preg_replace('/[^0-9a-zA-Z_-]/','',$params['tabto']);
$template = isset($params['template']) ? preg_replace('/[^0-9a-zA-Z_-]/','',$params['template']) : '';
if (!$template) $template = isset($params['templatename']) ? preg_replace('/[^0-9a-zA-Z_-]/','',$params['templatename']) : '';
$content = isset($params['content']) ? $params['content'] : '';

// Save template changes
if ($template && (isset($params['submit']) || isset($params['add']) || isset($params['cache']) || isset($params['cacheadd']))) {
    $this->SetTemplate($template, $content, $this->GetName());
}

// Redirect
if (isset($params['cache']) || isset($params['cacheadd'])) $this->Redirect($id, 'defaultadmin', $returnid, array( 'tabto'=>$tabto, 'template'=>$template, 'errors' => implode(',',str_replace(',',';',$errors)), 'message' => $this->Lang('changessaved') ));
if (isset($params['submit']) || isset($params['add'])) $this->Redirect($id, 'defaultadmin', $returnid, array( 'tabto'=>$tabto, 'errors' => implode(',',str_replace(',',';',$errors)), 'message' => $this->Lang('changessaved') ));
else if (isset($params['cancel'])) $this->Redirect($id, 'defaultadmin', $returnid, array( 'tabto'=>$tabto ));
else $this->Redirect($id, 'defaultadmin', $returnid, array( 'tabto'=>$tabto, 'template'=>$template ));

// EOF