bebeboutik/modules/ant_resetbopassword/ant_resetbopassword.php
2017-10-24 10:27:38 +02:00

142 lines
5.9 KiB
PHP

<?php
if (!defined('_PS_VERSION_'))
exit;
if (defined('PS_ADMIN_DIR'))
{
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
} else {
require_once(realpath(dirname(__FILE__) .'/../../').'/adm/helpers/HelperFormBootstrap.php');
}
class Ant_Resetbopassword extends Module
{
public $_html = '';
public function __construct()
{
$this->name = 'ant_resetbopassword';
$this->tab = 'administration';
$this->author = 'Antadis';
$this->version = '1.0';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->l('Sécurité BO');
$this->description = $this->l('Envoi, tous les X mois, une demande de changement de mot de passe aux employés');
}
public function install()
{
if(!(parent::install())) {
return false;
}
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'employee` ADD `date_passwd_upd` DATETIME DEFAULT "'.pSQL(date("Y-m-d H:i:s")).'"');
# Set default configuration values
Configuration::updateValue('ANT_RESETBOPASSWORD_FREQ', 3); // month
Configuration::updateValue('ANT_RESETBOPASSWORD_LIMIT', 7); // day
Configuration::updateValue('ANT_RESETBOPASSWORD_DATE', date('Y-m-d H:i:s')); // last date of updating
return true;
}
public function uninstall()
{
if(parent::uninstall() == false) {
return false;
}
Configuration::deleteByName('ANT_RESETBOPASSWORD_FREQ');
Configuration::deleteByName('ANT_RESETBOPASSWORD_LIMIT');
Configuration::deleteByName('ANT_RESETBOPASSWORD_DATE');
return true;
}
public function getContent()
{
global $cookie, $currentIndex;
if(Tools::isSubmit('submitUpdate')) {
Configuration::updateValue('ANT_RESETBOPASSWORD_FREQ', Tools::getValue('frequency'));
Configuration::updateValue('ANT_RESETBOPASSWORD_LIMIT', Tools::getValue('limit'));
}
$helper = new HelperFormBootstrap();
$this->_html .= $helper->renderStyle();
$this->_html .= '
<div class="row">
<div class="col-md-12">
<div class="panel">
<div class="panel-title">
<h2 style="font-size:24px;"><span class="anticon anticon-cog text-rose" style="font-size:24px;"></span> '.$this->l('Reset Bo Password - Configurations').'</h2>
<div class="clearfix"></div>
</div>
<div class="panel-content">
<form method="POST" action="">
<div class="col-sm-3 col-sm-offset-4">';
$input = array(
'type' => 'textAddon',
'label' => $this->l('Frequency :'),
'lang' => true,
'name' => 'frequency',
'id' => 'frequency',
'required' => true,
'after' => $this->l('Months'),
'help' => $this->l('Mail sending frequency'),
'default' => Configuration::get('ANT_RESETBOPASSWORD_FREQ')
);
$this->_html .= $helper->generateInput($input);
$this->_html .= '<div class="clearfix"></div>';
$input = array(
'type' => 'textAddon',
'label' => $this->l('Limit :'),
'lang' => true,
'name' => 'limit',
'id' => 'limit',
'required' => true,
'after' => $this->l('Days'),
'help' => $this->l('Nb of day limited to change the password'),
'default' => Configuration::get('ANT_RESETBOPASSWORD_LIMIT')
);
$this->_html .= $helper->generateInput($input);
$this->_html .= '<div class="clearfix"></div>';
$this->_html .='
</div>
<div class="clear"></div>
<div class="ln_solid-small"></div>
<div class="text-right">
<input type="submit" class="btn btn-primary" name="submitUpdate" value="'.$this->l('Save').'" />
</div>
</form>
</div>
</div>
</div>
</div>';
$this->_html .= $helper->renderScript();
return $this->_html;
}
public function hookAnt_Initadmin($params)
{
$now = new Datetime("now");
$date_passwd_upd = new Datetime($params['employee']->date_passwd_upd);
$updated_date_send = new Datetime(Configuration::get('ANT_RESETBOPASSWORD_DATE'));
$limit = (int)Configuration::get('ANT_RESETBOPASSWORD_LIMIT');
$limit_day = $day_limit = $limit>1?$limit.' days':'1 day';
$date_send = $updated_date_send;
$date_send->modify("+".$limit_day."");
$now->modify("-".$limit_day."");
if($now > $date_send && $date_passwd_upd < $updated_date_send){
$destination = substr($_SERVER['REQUEST_URI'], strlen(dirname($_SERVER['SCRIPT_NAME'])) + 1);
Tools::redirectAdmin('resetpasswd.php'.(empty($destination) || ($destination == 'index.php?logout') ? '' : '?redirect='.$destination));
}
return true;
}
}