<?php
/**
 * @version $Id$
 * @package    Contact_Enhanced
 * @subpackage Views
 * @author     Douglas Machado {@link http://ideal.fok.com.br}
 * @author     Created on 28-Jul-09
 * @license		GNU/GPL, see license.txt
 * Contact Enhanced  is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 */

//--No direct access
defined('_JEXEC') or die('Direct Access NOT Allowed. Please try to access the main page');

jimport('joomla.application.component.view');

class Contact_EnhancedsViewtemplate extends JView
{

	function display($tpl = null)
	{
		global $controller,$option,$mainframe;
		JHTML::stylesheet( 'contact_enhanced.css', 'administrator/components/com_contact_enhanced/assets/css/' );
		JToolBarHelper::title(   '&nbsp;&nbsp;'.JText::_( 'Contact Enhanced' ). '&nbsp;&nbsp;<small><small>[' .JText::_( 'Templates' ).']</small></small>', 'thememanager');
		JToolBarHelper::save();
		JToolBarHelper::apply();
		JToolBarHelper::cancel();
		//JHTML::script( 'nicEdit.js', 'administrator/components/com_contact_enhanced/helpers/nicEditor/' );
		
		
		jimport('joomla.filesystem.path');

		// Initialize some variables
		$cid		= JRequest::getVar('cid', array(), 'method', 'array');
		$cid		= array(JFilterInput::clean(@$cid[0], 'cmd'));
		$template	= $cid[0];
		$templateType	= JRequest::getVar('templateType','email');
		$option		= JRequest::getCmd('option');

		if (!$cid[0]) {
			return JError::raiseWarning( 500, JText::_('Template not specified') );
		}
		$tBaseDir = JPATH_ROOT.DS.'components'.DS.COMPONENT_FOLDER.DS.'templates'.DS.$templateType;
		require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_templates'.DS.'helpers'.DS.'template.php');
				
		if (!is_dir( $tBaseDir . DS . $template )) {
			JError::raiseWarning( 500, JText::_('Template not found') );
			$mainframe->redirect('index.php?option='.$option.'&controller=templates');
		}
		$lang =& JFactory::getLanguage();
		
		$ini	= $tBaseDir.DS.$template.DS.'params.ini';
		$xml	= $tBaseDir.DS.$template.DS.'templateDetails.xml';
		$row	= TemplatesHelper::parseXMLTemplateFile($tBaseDir, $template);

		jimport('joomla.filesystem.file');
		// Read the ini file
		if (JFile::exists($ini)) {
			$iniContent = JFile::read($ini);
		} else {
			$iniContent = null;
		}
		$params = new JParameter($iniContent, $xml, 'template');
		
		$file		= $tBaseDir.DS.$template.DS.'index.html';
		// Read the source file
		$content = JFile::read($file);
		
		// Set FTP credentials, if given
		jimport('joomla.client.helper');
		$ftp =& JClientHelper::setCredentialsFromRequest('ftp');
		
		$this->assignRef('row',		$row);
		$this->assignRef('ftp',		$ftp);
		$this->assignRef('params',	$params);
		$this->assignRef('template',$template);
		$this->assignRef('content',	$content);
		$this->assignRef('tBaseDir',$tBaseDir);

		parent::display($tpl);
	}// function

}// class
