107 lines
3.2 KiB
PHP
107 lines
3.2 KiB
PHP
<?php
|
|
if (!defined('_PS_VERSION_'))
|
|
exit;
|
|
|
|
class Ant_Alert extends Module
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
$this->name = 'ant_alert';
|
|
$this->tab = 'administration';
|
|
$this->author = 'Antadis';
|
|
$this->version = '1.0';
|
|
$this->need_instance = 0;
|
|
|
|
parent::__construct();
|
|
|
|
$this->displayName = $this->l('Alert for message');
|
|
$this->description = $this->l('Alert for message of technical error');
|
|
}
|
|
|
|
public function install()
|
|
{
|
|
|
|
|
|
$hooks = array(
|
|
'ant_alert' => array('Ant Alert', 'Called when a message of technical error is sent'),
|
|
);
|
|
foreach($hooks as $k => $v) {
|
|
if(count(Db::getInstance()->ExecuteS('
|
|
SELECT `id_hook`
|
|
FROM `'._DB_PREFIX_.'hook`
|
|
WHERE `name` = "'.$k.'"
|
|
LIMIT 1
|
|
')) == 0) {
|
|
Db::getInstance()->ExecuteS('
|
|
INSERT INTO `'._DB_PREFIX_.'hook`
|
|
VALUES (DEFAULT, "'.$k.'", "'.$v[0].'", "'.$v[1].'", 0, 0)
|
|
');
|
|
}
|
|
}
|
|
|
|
if(!parent::install()
|
|
|| !$this->registerHook('ant_alert')) {
|
|
return FALSE;
|
|
}
|
|
|
|
# Set default configuration values
|
|
Configuration::updateValue('ANT_ALTER_LIMIT', 10);
|
|
Configuration::updateValue('ANT_ALTER_HOURS', 24);
|
|
Configuration::updateValue('ANT_ALTER_DATESEND', date('Y-m-d H:i:s'));
|
|
|
|
return true;
|
|
}
|
|
|
|
public function uninstall() {
|
|
|
|
if(parent::uninstall() == false) {
|
|
return false;
|
|
}
|
|
|
|
Configuration::deleteByName('ANT_ALTER_LIMIT');
|
|
Configuration::deleteByName('ANT_ALTER_HOURS');
|
|
Configuration::deleteByName('ANT_ALTER_DATESEND');
|
|
|
|
return true;
|
|
}
|
|
|
|
public function hookAnt_Alert($params) {
|
|
global $cookie;
|
|
|
|
$date = new Datetime(Configuration::get('ANT_ALTER_DATESEND'));
|
|
$now = new Datetime;
|
|
|
|
$dteDiff = $date->diff($now);
|
|
if ((int)$dteDiff->format("%H") >= (int)Configuration::get('ANT_ALTER_HOURS')) { // prod
|
|
$open_messages = Db::getInstance()->getRow('
|
|
SELECT COUNT(*) as total
|
|
FROM '._DB_PREFIX_.'customer_thread ct
|
|
WHERE ct.status = "open"
|
|
GROUP BY ct.id_contact HAVING COUNT(*) > 0 AND ct.id_contact = 4'
|
|
);
|
|
if ((int)$open_messages['total'] >= (int)Configuration::get('ANT_ALTER_LIMIT')) {
|
|
// dev
|
|
// $to = array('marion@antadis.com');
|
|
// prod
|
|
$to = array(
|
|
'frederic@bebeboutik.com',
|
|
'jacques@bebeboutik.com',
|
|
'valentin@bebeboutik.com',
|
|
);
|
|
$data = array(
|
|
'{limit}' => (int)Configuration::get('ANT_ALTER_LIMIT'),
|
|
'{hours}' => (int)Configuration::get('ANT_ALTER_HOURS'),
|
|
);
|
|
foreach ($to as $email) {
|
|
if(Mail::Send((int)$cookie->id_lang, 'ant_alert', 'Alert error', $data, $to)) {
|
|
Configuration::updateValue('ANT_ALTER_DATESEND', date('Y-m-d H:i:s'));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|