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 .= '

'.$this->l('Reset Bo Password - Configurations').'

'; $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 .= '
'; $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 .= '
'; $this->_html .='
'; $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; } }