<?php //if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once('libraries/mmail/htmlMimeMail.php');
include("../configuration.php");

class CI_Email extends htmlMimeMail5
{
	function __construct()
	{
		parent::__construct();
		//$this->CI = &get_instance();	
	}

	function initialize($settings = false)
	{
		if (!$settings) {
			//$settings = $this->CI->config->item('email');
			$conf = new JConfig();
			$settings['host'] = $conf->smtphost;
			$settings['port'] = $conf->smtpport;
			$settings['helo'] = null;
			$settings['auth'] = $conf->smtpauth;
			$settings['user'] = $conf->smtpuser;
			$settings['pass'] = $conf->smtppass;
			/*$settings['host'] = 'localhost';
			$settings['port'] = 25;
			$settings['helo'] = null;
			$settings['auth'] = true;
			$settings['user'] = 'www.smtp@cadline.hu';
			$settings['pass'] = 'Chieng0t';*/
		}

		$this->setSMTPParams($settings['host'], $settings['port'], $settings['helo'], $settings['auth'], $settings['user'], $settings['pass']);

		$this->setHTMLCharset('UTF-8');
		$this->setHeadCharset('UTF-8');
		$this->setHTMLEncoding(new EightBitEncoding());
	}

	function addOfficialImages()
	{
		$this->addEmbeddedImage(new fileEmbeddedImage('../public/img/mail/title.jpg'));
		$this->addEmbeddedImage(new fileEmbeddedImage('../public/img/mail/footer.jpg'));
	}

	function addImage($path)
	{
		$this->addEmbeddedImage(new fileEmbeddedImage('../public/img/' . $path));
	}

	function clear()
	{
		$this->is_built = false;
		$this->setHTML(null);
		$this->setFrom(null);
	}

	function message($html)
	{
		$tomb['�'] = '&aacute;';
		$tomb['�'] = '&Aacute;';
		$tomb['�'] = '&eacute;';
		$tomb['�'] = '&Eacute;';
		$tomb['�'] = '&oacute;';
		$tomb['�'] = '&Oacute;';
		$tomb['�'] = '&ouml;';
		$tomb['�'] = '&Ouml;';
		$tomb['�'] = '&#337;';
		$tomb['�'] = '&#336;';
		$tomb['�'] = '&uacute;';
		$tomb['�'] = '&Uacute;';
		$tomb['�'] = '&uuml;';
		$tomb['�'] = '&Uuml;';
		$tomb['�'] = '&#369;';
		$tomb['�'] = '&#368;';
		$tomb['�'] = '&iacute;';
		$tomb['�'] = '&Iacute;';

		$string = $html;
		foreach ($tomb as $k => $v) {
			$string = str_replace($k, $v, $string);
		}
		$this->setHTML($string);
	}

	function from($from)
	{
		$this->setFrom($from);
	}

	function subject($subj)
	{
		$this->setSubject($subj);
	}
}
