From a76dd668feaea09a3e55fd7e73701ca7c2dc2df1 Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Mon, 28 Aug 2017 14:30:30 +0200 Subject: [PATCH] addition of resetbopassword module --- adm/helpers/HelperFormBootstrap.php | 6 +- adm/helpers/includes/css/custom.css | 6 + .../ant_resetbopassword.php | 124 ++++++++++++++++++ modules/ant_resetbopassword/cron.php | 47 +++++++ override/classes/Employee.php | 14 ++ 5 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 modules/ant_resetbopassword/ant_resetbopassword.php create mode 100644 modules/ant_resetbopassword/cron.php diff --git a/adm/helpers/HelperFormBootstrap.php b/adm/helpers/HelperFormBootstrap.php index 53f088e4..29805157 100644 --- a/adm/helpers/HelperFormBootstrap.php +++ b/adm/helpers/HelperFormBootstrap.php @@ -206,6 +206,9 @@ class HelperFormBootstrap{ case 'simpleText': $this->inputSimpleText($input); break; + case 'textAddon': + $this->inputTextAddon($input); + break; case 'tag': $this->inputTag($input); break; @@ -309,9 +312,10 @@ class HelperFormBootstrap{ '.(isset($p['label']) && $p['label'] ?'':'').'
'.(isset($p['before']) && $p['before'] ?'
'.$p['before'].'
':'').' - + '.(isset($p['after']) && $p['after'] ?'
'.$p['after'].'
':'').'
+ ' . ((isset($p['help']) && $p['help']) ? ''.$p['help'].'' : '') . ' '; } diff --git a/adm/helpers/includes/css/custom.css b/adm/helpers/includes/css/custom.css index 6402752f..47292bb2 100644 --- a/adm/helpers/includes/css/custom.css +++ b/adm/helpers/includes/css/custom.css @@ -392,6 +392,12 @@ table.table tr th { .table tr td { color: #000; } +.table th a{ + color:#fff; +} +.table tbody tr th:first-child span{ + color: #E36EA2!important; +} /* Select2 */ .select2-results ul li{ diff --git a/modules/ant_resetbopassword/ant_resetbopassword.php b/modules/ant_resetbopassword/ant_resetbopassword.php new file mode 100644 index 00000000..ba06a1b9 --- /dev/null +++ b/modules/ant_resetbopassword/ant_resetbopassword.php @@ -0,0 +1,124 @@ +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; + } + + # 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; + } + + Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'employee` ADD `date_passwd_upd` DATETIME DEFAULT "'.pSQL(date("Y-m-d H:i:s")).'"'); + 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 hookObjectEmployeeUpdateAfter($params) + { + + } +} diff --git a/modules/ant_resetbopassword/cron.php b/modules/ant_resetbopassword/cron.php new file mode 100644 index 00000000..67ec2e9c --- /dev/null +++ b/modules/ant_resetbopassword/cron.php @@ -0,0 +1,47 @@ +diff($last_sent); + +if($diff->format("")>=(int)$frequency){ + + $employees = Db::getInstance()->ExecuteS(' + SELECT `id_employee`, CONCAT(`firstname`, \' \', `lastname`) AS "name", email + FROM `'._DB_PREFIX_.'employee` + WHERE `active` = 1 + ORDER BY `email` + '); + foreach ($employees as $key => $employee) { + // sending email + } + + Configuration::updateValue('ANT_RESETBOPASSWORD_DATE', date('Y-m-d H:i:s')); +} + +$employees = Db::getInstance()->ExecuteS(' + SELECT `id_employee`, CONCAT(`firstname`, \' \', `lastname`) AS "name", `email`, `date_passwd_upd` + FROM `'._DB_PREFIX_.'employee` + WHERE `active` = 1 AND + ORDER BY `email` +'); + +foreach ($employees as $key => $employee) { + $date_passwd_upd = new Datetime($employee['date_passwd_upd']); + $diff_limit = $now->diff($date_passwd_upd); + if($diff->format("%D")>=(int)$limit){ + // resending a mail + } +} + +exit; diff --git a/override/classes/Employee.php b/override/classes/Employee.php index 52c8a666..6c4c25e7 100644 --- a/override/classes/Employee.php +++ b/override/classes/Employee.php @@ -12,4 +12,18 @@ class Employee extends EmployeeCore { ORDER BY `email`'); } + public function update($nullValues = false) + { + $result = parent::update(); + + if($_POST('passwd')!==null && $result){ + Db::getInstance()->ExecuteS(' + UPDATE `'._DB_PREFIX_.'employee` + SET `date_passwd_upd` = "'.pSQL(date('Y-m-d H:i:s')).'" + WHERE `id_employee` = '.(int)$this->id.' + '); + } + return $result; + } + } \ No newline at end of file