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 .= '
'.$this->l('Settings updated').'
'; } private function _displayForm() { $this->_html .= '
'.$this->l('Style settings').'
'; foreach($this->languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'header', true).'

'; foreach($this->languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'header_txt', true).'

'; foreach($this->languages as $language) { $this->_html .= ' '; } $this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'footer', true).'

'; foreach($this->languages as $language) { $this->_html .= ' '; } $this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'footer_txt', true).'

'; foreach($this->languages as $language) { $this->_html .= '
'; } $this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'titles', true).'

'; foreach($this->languages as $language) { $this->_html .= ' '; } $this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'links', true).'

'; } public function getContent() { $this->id_lang = (int)Context::getContext()->language->id; $this->languages = $this->context->controller->getLanguages(); $this->default_language = (int)Configuration::get('PS_LANG_DEFAULT'); $this->divLangName = 'header¤header_txt¤footer¤footer_txt¤titles¤links¤names'; $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'), ); $this->_html = '

'.$this->displayName.'

'; if(Tools::isSubmit('btnSubmit') || Tools::isSubmit('btnSubmitUpdate')) { $this->_postProcess(); } else { $this->_html .= '
'; } $this->_displayForm(); return $this->_html; } }