233 lines
10 KiB
PHP
Executable File
233 lines
10 KiB
PHP
Executable File
<?php
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
|
|
class MailGenerator extends Module {
|
|
private $_html = '';
|
|
private $_postErrors = array();
|
|
|
|
public function __construct() {
|
|
$this->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 .= '<div class="conf confirm"> '.$this->l('Settings updated').'</div>';
|
|
}
|
|
|
|
private function _displayForm() {
|
|
$this->_html .= '
|
|
<form action="'.Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']).'" method="post">
|
|
<fieldset>
|
|
<legend><img src="../img/admin/contact.gif" />'.$this->l('Style settings').'</legend>
|
|
<table style="border: 0px; width: 100%" cellpadding="0" cellspacing="0" id="form">
|
|
<tr>
|
|
<td width="130" style="vertical-align: top;"><label>'.$this->l('HTML Header').'</label></td>
|
|
<td style="padding-bottom:15px;">';
|
|
|
|
foreach($this->languages as $language) {
|
|
$this->_html .= '
|
|
<div id="header_'.(int) $language['id_lang'].'" style="display: '.($language['id_lang'] == $this->id_lang ? 'block' : 'none').'; float: left;">
|
|
<textarea rows="4" cols="53" name="header['.(int) $language['id_lang'].']" id="header_'.(int) $language['id_lang'].'">'.htmlentities(Tools::getValue('header['.(int) $language['id_lang'].']', isset($this->config['header'][(int) $language['id_lang']])? $this->config['header'][(int) $language['id_lang']]: ''), ENT_COMPAT, 'UTF-8').'</textarea>
|
|
</div>
|
|
';
|
|
}
|
|
|
|
$this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'header', true).'
|
|
<p style="clear: both;"> </p>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="130" style="vertical-align: top;"><label>'.$this->l('Text Header').'</label></td>
|
|
<td style="padding-bottom:15px;">';
|
|
|
|
foreach($this->languages as $language) {
|
|
$this->_html .= '
|
|
<div id="header_txt_'.(int) $language['id_lang'].'" style="display: '.($language['id_lang'] == $this->id_lang ? 'block' : 'none').'; float: left;">
|
|
<textarea rows="4" cols="53" name="header_txt['.(int) $language['id_lang'].']" id="header_txt_'.(int) $language['id_lang'].'">'.htmlentities(Tools::getValue('header_txt['.(int) $language['id_lang'].']', isset($this->config['header_txt'][(int) $language['id_lang']])? $this->config['header_txt'][(int) $language['id_lang']]: ''), ENT_COMPAT, 'UTF-8').'</textarea>
|
|
</div>
|
|
';
|
|
}
|
|
|
|
$this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'header_txt', true).'
|
|
<p style="clear: both;"> </p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td width="130" style="vertical-align: top;"><label>'.$this->l('HTML Footer').'</label></td>
|
|
<td style="padding-bottom:15px;">';
|
|
|
|
foreach($this->languages as $language) {
|
|
$this->_html .= '
|
|
<div id="footer_'.(int) $language['id_lang'].'" style="display: '.($language['id_lang'] == $this->id_lang ? 'block' : 'none').'; float: left;">
|
|
<textarea rows="4" cols="53" name="footer['.(int) $language['id_lang'].']" id="footer_'.(int) $language['id_lang'].'">'.htmlentities(Tools::getValue('footer['.(int) $language['id_lang'].']', isset($this->config['footer'][(int) $language['id_lang']])? $this->config['footer'][(int) $language['id_lang']]: ''), ENT_COMPAT, 'UTF-8').'</textarea>
|
|
</div>
|
|
';
|
|
}
|
|
|
|
$this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'footer', true).'
|
|
<p style="clear: both;"> </p>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td width="130" style="vertical-align: top;"><label>'.$this->l('Text Footer').'</label></td>
|
|
<td style="padding-bottom:15px;">';
|
|
|
|
foreach($this->languages as $language) {
|
|
$this->_html .= '
|
|
<div id="footer_txt_'.(int) $language['id_lang'].'" style="display: '.($language['id_lang'] == $this->id_lang ? 'block' : 'none').'; float: left;">
|
|
<textarea rows="4" cols="53" name="footer_txt['.(int) $language['id_lang'].']" id="header_'.(int) $language['id_lang'].'">'.htmlentities(Tools::getValue('footer_txt['.(int) $language['id_lang'].']', isset($this->config['footer_txt'][(int) $language['id_lang']])? $this->config['footer_txt'][(int) $language['id_lang']]: ''), ENT_COMPAT, 'UTF-8').'</textarea>
|
|
</div>
|
|
';
|
|
}
|
|
|
|
$this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'footer_txt', true).'
|
|
<p style="clear: both;"> </p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td width="130" style="vertical-align: top;"><label>'.$this->l('Titles styles').'</label></td>
|
|
<td style="padding-bottom:15px;">';
|
|
|
|
foreach($this->languages as $language) {
|
|
$this->_html .= '
|
|
<div id="titles_'.(int) $language['id_lang'].'" style="display: '.($language['id_lang'] == $this->id_lang ? 'block' : 'none').'; float: left;">
|
|
<textarea rows="4" cols="53" name="titles['.(int) $language['id_lang'].']" id="titles_'.(int) $language['id_lang'].'">'.htmlentities(Tools::getValue('titles['.(int) $language['id_lang'].']', isset($this->config['titles'][(int) $language['id_lang']])? $this->config['titles'][(int) $language['id_lang']]: ''), ENT_COMPAT, 'UTF-8').'</textarea>
|
|
</div>
|
|
';
|
|
}
|
|
|
|
$this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'titles', true).'
|
|
<p style="clear: both;"> </p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td width="130" style="vertical-align: top;"><label>'.$this->l('Links styles').'</td>
|
|
<td style="padding-bottom:15px;">';
|
|
|
|
foreach($this->languages as $language) {
|
|
$this->_html .= '
|
|
<div id="links_'.(int) $language['id_lang'].'" style="display: '.($language['id_lang'] == $this->id_lang ? 'block' : 'none').'; float: left;">
|
|
<textarea rows="4" cols="53" name="links['.(int) $language['id_lang'].']" id="links_'.(int) $language['id_lang'].'">'.htmlentities(Tools::getValue('links['.(int) $language['id_lang'].']', isset($this->config['links'][(int) $language['id_lang']])? $this->config['links'][(int) $language['id_lang']]: ''), ENT_COMPAT, 'UTF-8').'</textarea>
|
|
</div>
|
|
';
|
|
}
|
|
|
|
$this->_html .= $this->displayFlags($this->languages, (int) $this->id_lang, $this->divLangName, 'links', true).'
|
|
<p style="clear: both;"> </p>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td colspan="2" align="center">
|
|
<input class="button" name="btnSubmit" value="'.$this->l('Update settings').'" type="submit" />
|
|
<input class="button" name="btnSubmitUpdate" value="'.$this->l('Update settings and mail templates').'" type="submit" />
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</fieldset>
|
|
</form>
|
|
';
|
|
}
|
|
|
|
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 = '<h2>'.$this->displayName.'</h2>';
|
|
|
|
if(Tools::isSubmit('btnSubmit') || Tools::isSubmit('btnSubmitUpdate')) {
|
|
$this->_postProcess();
|
|
} else {
|
|
$this->_html .= '<br />';
|
|
}
|
|
|
|
$this->_displayForm();
|
|
|
|
return $this->_html;
|
|
}
|
|
}
|