diff --git a/modules/producttooltip/producttooltip.php b/modules/producttooltip/producttooltip.php index 45c86973c..8778a3d73 100644 --- a/modules/producttooltip/producttooltip.php +++ b/modules/producttooltip/producttooltip.php @@ -72,62 +72,21 @@ class ProductToolTip extends Module public function getContent() { + $html = ''; /* Update values in DB */ if (Tools::isSubmit('SubmitToolTip')) { - Configuration::updateValue('PS_PTOOLTIP_PEOPLE', (int)(Tools::getValue('ps_ptooltip_people'))); - Configuration::updateValue('PS_PTOOLTIP_DATE_CART', (int)(Tools::getValue('ps_ptooltip_date_cart'))); - Configuration::updateValue('PS_PTOOLTIP_DATE_ORDER', (int)(Tools::getValue('ps_ptooltip_date_order'))); - Configuration::updateValue('PS_PTOOLTIP_DAYS', ((int)(Tools::getValue('ps_ptooltip_days') < 0 ? 0 : (int)Tools::getValue('ps_ptooltip_days')))); - Configuration::updateValue('PS_PTOOLTIP_LIFETIME', ((int)(Tools::getValue('ps_ptooltip_lifetime') < 0 ? 0 : (int)Tools::getValue('ps_ptooltip_lifetime')))); + Configuration::updateValue('PS_PTOOLTIP_PEOPLE', (int)(Tools::getValue('PS_PTOOLTIP_PEOPLE'))); + Configuration::updateValue('PS_PTOOLTIP_DATE_CART', (int)(Tools::getValue('PS_PTOOLTIP_DATE_CART'))); + Configuration::updateValue('PS_PTOOLTIP_DATE_ORDER', (int)(Tools::getValue('PS_PTOOLTIP_DATE_ORDER'))); + Configuration::updateValue('PS_PTOOLTIP_DAYS', ((int)(Tools::getValue('PS_PTOOLTIP_DAYS') < 0 ? 0 : (int)Tools::getValue('PS_PTOOLTIP_DAYS')))); + Configuration::updateValue('PS_PTOOLTIP_LIFETIME', ((int)(Tools::getValue('PS_PTOOLTIP_LIFETIME') < 0 ? 0 : (int)Tools::getValue('PS_PTOOLTIP_LIFETIME')))); - echo $this->displayConfirmation($this->l('Settings updated')); + $html .= $this->displayConfirmation($this->l('Settings updated')); } /* Configuration form */ - $output = ' -
-
- '.$this->l('Product tooltips').' -

- '.$this->l('Display the number of people who are currently watching this product?').'

- '.$this->l('Yes').' -   '.$this->l('No').'
-

-

- '.$this->l('Lifetime:').' - '.$this->l('minutes').'
-

-

- '.$this->l('If you activate the option above, you must activate the first option of StatData module').' -

-
-

- '.$this->l('Display the last time the product has been ordered?').'

- '.$this->l('Yes').' -   '.$this->l('No').'

-

-

- '.$this->l('If not ordered yet, display the last time the product has been added to a cart?').'

- '.$this->l('Yes').' -   '.$this->l('No').'

- -

-

- '.$this->l('Do not display events older than:').' - '.$this->l('days').'
-

-
-
-
-

- '.$this->l('Sample:').'
- -

-
-
'; - - return $output; + return $html.$this->renderForm(); } public function hookHeader($params) @@ -188,6 +147,133 @@ class ProductToolTip extends Module if ((isset($nbPeople['nb']) AND $nbPeople['nb'] > 0) OR isset($order['date_add']) OR isset($cart['date_add'])) return $this->display(__FILE__, 'producttooltip.tpl'); } + + public function renderForm() + { + $fields_form = array( + 'form' => array( + 'legend' => array( + 'title' => $this->l('Settings'), + 'icon' => 'icon-cogs' + ), + 'input' => array( + array( + 'type' => 'switch', + 'label' => $this->l('Number of people:'), + 'desc' => $this->l('Display the number of people who are currently watching this product?').'
'. + $this->l('If you activate the option above, you must activate the first option of StatData module'), + 'name' => 'PS_PTOOLTIP_PEOPLE', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + ), + array( + 'type' => 'text', + 'label' => $this->l('Lifetime:'), + 'name' => 'PS_PTOOLTIP_LIFETIME', + 'suffix' => 'minutes', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + ), + array( + 'type' => 'switch', + 'label' => $this->l('Product ordered:'), + 'desc' => $this->l('Display the last time the product has been ordered?'), + 'name' => 'PS_PTOOLTIP_DATE_ORDER', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + ), + array( + 'type' => 'switch', + 'label' => $this->l('Added to a cart:'), + 'label' => $this->l('If not ordered yet, display the last time the product has been added to a cart?'), + 'name' => 'PS_PTOOLTIP_DATE_CART', + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + ), + array( + 'type' => 'text', + 'label' => $this->l('Do not display events older than:'), + 'name' => 'PS_PTOOLTIP_DAYS', + 'suffix' => 'days' + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + 'class' => 'btn btn-primary') + ), + ); + + $helper = new HelperForm(); + $helper->show_toolbar = false; + $helper->table = $this->table; + $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT')); + $helper->default_form_language = $lang->id; + $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0; + $this->fields_form = array(); + + $helper->identifier = $this->identifier; + $helper->submit_action = 'SubmitToolTip'; + $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name; + $helper->token = Tools::getAdminTokenLite('AdminModules'); + $helper->tpl_vars = array( + 'fields_value' => $this->getConfigFieldsValues(), + 'languages' => $this->context->controller->getLanguages(), + 'id_language' => $this->context->language->id + ); + + return $helper->generateForm(array($fields_form)); + } + + public function getConfigFieldsValues() + { + return array( + 'PS_PTOOLTIP_PEOPLE' => Tools::getValue('PS_PTOOLTIP_PEOPLE', Configuration::get('PS_PTOOLTIP_PEOPLE')), + 'PS_PTOOLTIP_LIFETIME' => Tools::getValue('PS_PTOOLTIP_LIFETIME', Configuration::get('PS_PTOOLTIP_LIFETIME')), + 'PS_PTOOLTIP_DATE_ORDER' => Tools::getValue('PS_PTOOLTIP_DATE_ORDER', Configuration::get('PS_PTOOLTIP_DATE_ORDER')), + 'PS_PTOOLTIP_DATE_CART' => Tools::getValue('PS_PTOOLTIP_DATE_CART', Configuration::get('PS_PTOOLTIP_DATE_CART')), + 'PS_PTOOLTIP_DAYS' => Tools::getValue('PS_PTOOLTIP_DAYS', Configuration::get('PS_PTOOLTIP_DAYS')), + ); + } }