_object = false; $this->controller = 'AdminModules'; $this->module_name = 'ant_alert'; $this->config_tab = (bool)$config_tab; if ($config_tab) { $this->controller = 'AdminAntAlert'; } $this->helperForm = new HelperFormBootstrap(); $this->helperForm->_select2 = true; $this->helperForm->_inputSwitch = true; } protected function _postProcess() { if (Tools::isSubmit('newAlert')) { } elseif (Tools::isSubmit('addAlert')) { $this->_addOrUpdateAlert(false); } elseif (Tools::isSubmit('editAlert')) { $this->_addOrUpdateAlert(true); } elseif (Tools::isSubmit('loadAlert') && Tools::getValue('id')) { $this->_object = new AntAlert((int)Tools::getValue('id')); } elseif (Tools::isSubmit('deleteAlert') && Tools::getValue('id')) { $deleted_alert = new AntAlert((int)Tools::getValue('id')); $res = $deleted_alert->delete(); if ($res) { $this->_html .= HelperFormBootstrap::displaySuccess($this->l('Alert deleted : #') . (int)Tools::getValue('id')); } else { $this->_html .= HelperFormBootstrap::displayErrors($this->l('Alert cannot be deleted : #') . (int)Tools::getValue('id')); } return $res; } } protected function _addOrUpdateAlert($edit = false) { if ($edit) { $alert = new AntAlert((int)Tools::getValue('id_alert')); } else { $alert = new AntAlert(); $alert->date_last_sent = date("Y-m-d H:i:s"); $alert->date_last_check = date("Y-m-d H:i:s"); } $alert->id_contact = (int)Tools::getValue('id_contact'); $alert->limit = (int)Tools::getValue('limit'); $alert->hours = (int)Tools::getValue('hours'); $alert->enabled = (int)Tools::getValue('enabled'); if ($alert->save()) { if ($edit) { $this->_html .= HelperFormBootstrap::displaySuccess($this->l('Alert has been updated')); } else { $this->_html .= HelperFormBootstrap::displaySuccess($this->l('Alert has been created')); } } else { $this->_html .= HelperFormBootstrap::displayErrors($this->l('Error occured while updating alert')); } } public function display() { parent::displayForm(); $this->_html = ''; $this->_postProcess(); $this->_addCss(); $this->_html .= $this->helperForm->renderStyle(); $this->_displayForm(); $this->_displayList(); $this->_html .='
'; $this->_addJs(); $this->_html .= $this->helperForm->renderScript(); echo $this->_html; } protected function _addJs() { $this->helperForm->_js .= ''; } protected function _addCss() { $this->helperForm->_css .=' .table tr th { background: #565485; background: rgba(86,84,133,0.9); color: #fff; font-size: 12px; } .table tr:nth-child(even) { background: #F1F1F1; } .table .input-group-btn .btn { padding: 4px 5px; color: #504d8b; } .table .input-group-btn .btn .anticon{ font-size: 12px; } .bg-grey{ background: #EFEFEF; border-radius:4px; } .bg-grey .div-title { border-bottom: 2px solid #504D8B; } '; } protected function _displayList() { global $cookie, $currentIndex; $id_lang = (int)$cookie->id_lang; $contacts = Contact::getContacts($cookie->id_lang); $alerts = AntAlert::getAlerts(false); $_current_index = ($this->config_tab ? $currentIndex . '&token=' . Tools::getAdminTokenLite($this->controller) : $_SERVER['REQUEST_URI']); $this->_html .=''.$this->l('ID').' | '.$this->l('Contact').' | '.$this->l('Limite par heures').' | '.$this->l('Dernier envoi').' | '.$this->l('Active').' | '.$this->l('Action').' |
---|---|---|---|---|---|
#'.$alert['id_alert'].' | '.$current_contact['name'].' | '.$alert['limit'].' / '.$alert['hours'].'h | '.date('d/m/Y H:i',strtotime($alert['date_last_sent'])).' | '.((int)$alert['enabled']?'':'').' |
La limite des messages est par heure et par type de contact.
Ici un mail d\'alerte se déclenche après 1h si 50 messages ou plus, concernant les Retour/Echange, ont été envoyés.
Une seule alerte par type de contact possible !
' ), ), 'actions' => array(), 'actions-class' => 'text-right', ) ); if (isset($alert)) { $this->helperForm->_forms[0]['sections'][0]['title'] = "Editer une alerte"; $this->helperForm->_forms[0]['sections'][0]['inputs'][] = array( 'type' => 'hidden', 'name' => 'id_alert', 'value' => $alert->id, 'class' => 'large' ); $this->helperForm->_forms[0]['sections'][0]['actions'] = array( array( 'type' => 'submit', 'class' => 'btn-default', 'name' => 'newAlert', 'value' => $this->l('Nouvelle Alerte') ), array( 'type' => 'submit', 'class' => 'btn-primary', 'name' => 'editAlert', 'value' => $this->l('Editer l\'alerte') ), ); } else { $this->helperForm->_forms[0]['sections'][0]['title'] = "Ajouter une alerte"; $this->helperForm->_forms[0]['sections'][0]['actions'] = array( array( 'type' => 'submit', 'class' => 'btn-primary', 'name' => 'addAlert', 'value' => $this->l('Ajouter l\'alerte') ), ); } $this->helperForm->renderForm(); } public function _search($array, $key, $value) { $results = array(); if (is_array($array)) { if (isset($array[$key]) && $array[$key] == $value) { return $array; } foreach ($array as $subarray) { $results = array_merge($results, $this->_search($subarray, $key, $value)); } } return $results; } }