* @copyright 2007-2012 PrestaShop SA * @version Release: $Revision: 14011 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) exit; class Ekomi extends Module { private $_html = ''; private $_postErrors = array(); public $id_lang; public $iso_lang; function __construct() { $this->name = 'ekomi'; $this->tab = 'advertising_marketing'; $this->author = 'PrestaShop'; $this->version = 1.3; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('eKomi'); $this->description = $this->l('Adds an eKomi block'); if (self::isInstalled($this->name)) { $this->id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); $this->iso_lang = pSQL(Language::getIsoById($this->id_lang)); /* Check Mail Directory */ if (!is_dir('../modules/'.$this->name.'/mails/'.$this->iso_lang.'/')) $this->warning .= $this->l('directory').' "'.$this->iso_lang.'" does not exist '.'../modules/'.$this->name.'/mails/'.$this->iso_lang.'/'; } } public function install() { return (parent::install() AND $this->registerHook('rightColumn') AND $this->registerHook('newOrder')); } public function getContent() { $output = '

'.$this->displayName.'

'; if (Tools::isSubmit('submitEkomi')) { $email = Tools::getValue('ekomi_email'); Configuration::updateValue('PS_EKOMI_DISPLAY', Tools::getValue('ekomi_display')); Configuration::updateValue('PS_EKOMI_SCRIPT', htmlentities(str_replace(array("\r\n", "\n"), '', Tools::getValue('ekomi_script')))); if (!empty($email) && !Validate::isEmail($email)) Configuration::updateValue('PS_EKOMI_EMAIL', ''); else Configuration::updateValue('PS_EKOMI_EMAIL', Tools::getValue('ekomi_email')); $output .= '
'.$this->l('Confirmation').''.$this->l('Settings updated').'
'; } return $output.$this->displayForm(); } public function displayForm() { return '
'.$this->l('Settings').'





'.$this->l('Show or don\'t show the block (orders will be sent to eKomi whether you choose to hide or display the block).').'

'.$this->l('Please fill the form with the data that eKomi gives you.').'

'; } public function hookRightColumn($params) { if (!Configuration::get('PS_EKOMI_SCRIPT')) return; if (!Configuration::get('PS_EKOMI_DISPLAY')) return; return stripslashes(html_entity_decode(Configuration::get('PS_EKOMI_SCRIPT'))).'

'; } public function hookLeftColumn($params) { return $this->hookRightColumn($params); } public function hookNewOrder($params) { if (!Configuration::get('PS_EKOMI_EMAIL')) return true; /* Check Mail Directory */ if (!file_exists(dirname(__FILE__.'/'.$this->iso_lang.'/'))) return true; /* Email generation */ $subject = '[Ekomi-Prestashop] '.Configuration::get('PS_SHOP_NAME'); $templateVars = array( '{firstname}' => $params['customer']->firstname, '{lastname}' => $params['customer']->lastname, '{email}' => $params['customer']->email, '{id_order}' => $params['order']->id ); /* Email sending */ if (!Mail::Send((int)$this->id_lang, 'ekomi', $subject, $templateVars, Configuration::get('PS_EKOMI_EMAIL'), NULL, $params['customer']->email, Configuration::get('PS_SHOP_NAME'), NULL, NULL, dirname(__FILE__).'/mails/')) return true; return true; } }