name = 'mailgenerator'; $this->tab = 'administration'; $this->version = '1.0'; $this->author = 'Antadis'; parent::__construct(); $this->displayName = $this->l('Mail Generator'); $this->description = $this->l('Allows to generate custom mail templates'); } private function _postProcess() { Configuration::updateValue('MAILGEN_HEADER', Tools::getValue('header'), TRUE); Configuration::updateValue('MAILGEN_HEADER_TXT', Tools::getValue('header_txt'), TRUE); Configuration::updateValue('MAILGEN_FOOTER', Tools::getValue('footer'), TRUE); Configuration::updateValue('MAILGEN_FOOTER_TXT', Tools::getValue('footer_txt'), TRUE); Configuration::updateValue('MAILGEN_TITLES', Tools::getValue('titles'), TRUE); Configuration::updateValue('MAILGEN_LINKS', Tools::getValue('links'), TRUE); $this->config = array( 'header' => Configuration::getInt('MAILGEN_HEADER'), 'header_txt' => Configuration::getInt('MAILGEN_HEADER_TXT'), 'footer' => Configuration::getInt('MAILGEN_FOOTER'), 'footer_txt' => Configuration::getInt('MAILGEN_FOOTER_TXT'), 'titles' => Configuration::getInt('MAILGEN_TITLES'), 'links' => Configuration::getInt('MAILGEN_LINKS'), ); $language_ids = array(); foreach($this->languages as $language) { $language_ids[$language['iso_code']] = $language['id_lang']; } if(Tools::isSubmit('btnSubmitUpdate')) { $root_dir = dirname(__FILE__).'/root/'; foreach(Tools::scandir($root_dir, 'txt', '', TRUE) as $file) { $lang = explode('mails/', $file); $lang = explode('/', $lang[1]); $lang = $lang[0]; file_put_contents( _PS_ROOT_DIR_.'/'.$file, str_replace( array('{{header}}', '{{footer}}'), array( isset($this->config['header_txt'][$language_ids[$lang]])? $this->config['header_txt'][$language_ids[$lang]]."\n": '', isset($this->config['footer_txt'][$language_ids[$lang]])? "\n".$this->config['footer_txt'][$language_ids[$lang]]: '', ), file_get_contents($root_dir.$file) ) ); } foreach(Tools::scandir($root_dir, 'html', '', TRUE) as $file) { $lang = explode('mails/', $file); $lang = explode('/', $lang[1]); $lang = $lang[0]; file_put_contents( _PS_ROOT_DIR_.'/'.$file, str_replace( array('{{header}}', '{{footer}}', '{{title}}', '{{link}}'), array( isset($this->config['header'][$language_ids[$lang]])? $this->config['header'][$language_ids[$lang]]: '', isset($this->config['footer'][$language_ids[$lang]])? $this->config['footer'][$language_ids[$lang]]: '', isset($this->config['titles'][$language_ids[$lang]])? $this->config['titles'][$language_ids[$lang]]: '', isset($this->config['links'][$language_ids[$lang]])? $this->config['links'][$language_ids[$lang]]: '', ), file_get_contents($root_dir.$file) ) ); } } $this->_html .= '