diff --git a/modules/watermark/watermark.php b/modules/watermark/watermark.php
index 3d07d25dd..eb9e8a612 100644
--- a/modules/watermark/watermark.php
+++ b/modules/watermark/watermark.php
@@ -93,7 +93,12 @@ class Watermark extends Module
$yalign = Tools::getValue('yalign');
$xalign = Tools::getValue('xalign');
$transparency = (int)(Tools::getValue('transparency'));
- $image_types = Tools::getValue('image_types');
+
+ $types = ImageType::getImagesTypes('products');
+ $id_image_type = array();
+ foreach ($types as $type)
+ if (!is_null(Tools::getValue('WATERMARK_TYPES_'.(int)$type['id_image_type'])))
+ $id_image_type['WATERMARK_TYPES_'.(int)$type['id_image_type']] = true;
if (empty($transparency))
$this->_postErrors[] = $this->l('Transparency required.');
@@ -109,7 +114,7 @@ class Watermark extends Module
$this->_postErrors[] = $this->l('X-Align is required.');
elseif (!in_array($xalign, $this->xaligns))
$this->_postErrors[] = $this->l('X-Align is not in allowed range.');
- if (empty($image_types))
+ if (!count($id_image_type))
$this->_postErrors[] = $this->l('At least one image type is required.');
if (isset($_FILES['PS_WATERMARK']['tmp_name']) && !empty($_FILES['PS_WATERMARK']['tmp_name']))
@@ -123,7 +128,13 @@ class Watermark extends Module
private function _postProcess()
{
- Configuration::updateValue('WATERMARK_TYPES', implode(',', Tools::getValue('image_types')));
+ $types = ImageType::getImagesTypes('products');
+ $id_image_type = array();
+ foreach ($types as $type)
+ if (Tools::getValue('WATERMARK_TYPES_'.(int)$type['id_image_type']))
+ $id_image_type[] = $type['id_image_type'];
+
+ Configuration::updateValue('WATERMARK_TYPES', implode(',', $id_image_type));
Configuration::updateValue('WATERMARK_Y_ALIGN', Tools::getValue('yalign'));
Configuration::updateValue('WATERMARK_X_ALIGN', Tools::getValue('xalign'));
Configuration::updateValue('WATERMARK_TRANSPARENCY', Tools::getValue('transparency'));
@@ -145,69 +156,9 @@ class Watermark extends Module
if ($this->_errors)
foreach ($this->_errors as $error)
- $this->_html .= '

'.$this->l($error).'
';
+ $this->_html .= $this->displayError($this->l($error));
else
- $this->_html .= ''.$this->l('Settings updated').'
';
- }
-
- private function _displayForm()
- {
- $imageTypes = ImageType::getImagesTypes('products');
- $str_shop = '-'.(int)$this->context->shop->id;
- if (Shop::getContext() != Shop::CONTEXT_SHOP || !Tools::file_exists_cache(dirname(__FILE__).'/watermark'.$str_shop.'.gif'))
- $str_shop = '';
-
- $this->_html .=
- '';
+ $this->_html .= $this->displayConfirmation($this->l('Settings updated'));
}
public function getAdminDir()
@@ -254,7 +205,7 @@ RewriteRule [0-9/]+/[0-9]+\\.jpg$ - [F]
$this->removeHtaccessSection();
$this->writeHtaccessSection();
- $this->_html = ''.$this->displayName.'
';
+ $this->_html = '';
if (Tools::isSubmit('btnSubmit'))
{
@@ -263,12 +214,10 @@ RewriteRule [0-9/]+/[0-9]+\\.jpg$ - [F]
$this->_postProcess();
else
foreach ($this->_postErrors as $err)
- $this->_html .= ''.$err.'
';
+ $this->_html .= $this->displayError($err);
}
- else
- $this->_html .= '
';
- $this->_displayForm();
+ $this->_html .= $this->renderForm();
return $this->_html;
}
@@ -326,6 +275,155 @@ RewriteRule [0-9/]+/[0-9]+\\.jpg$ - [F]
if (!imagecopymerge($image, $imagew, $xpos, $ypos, 0, 0, $watermarkWidth, $watermarkHeight, $this->transparency))
return false;
return imagejpeg($image, $outputpath, 100);
- }
-}
+ }
+
+ public function renderForm()
+ {
+ $types = ImageType::getImagesTypes('products');
+ foreach ($types as $key => $type)
+ $types[$key]['label'] = $type['name'].' ('.$type['width'].' x '.$type['height'].')';
+ $fields_form = array(
+ 'form' => array(
+ 'legend' => array(
+ 'title' => $this->l('Settings'),
+ 'icon' => 'icon-cogs'
+ ),
+ 'description' => $this->l('Once you have set up the module, regenerate the images using the "Images" tool in Preferences. However, the watermark will be added automatically to new images.'),
+ 'input' => array(
+ array(
+ 'type' => 'file',
+ 'label' => $this->l('Watermark file:'),
+ 'name' => 'PS_WATERMARK',
+ 'desc' => $this->l('Must be in GIF format'),
+ 'thumb' => '../modules/'.$this->name.'/'.$this->name.'.gif?t='.rand(0, time()),
+ ),
+ array(
+ 'type' => 'text',
+ 'label' => $this->l('Watermark transparency (0-100)'),
+ 'name' => 'transparency',
+ 'class' => 'fixed-width-md',
+ ),
+ array(
+ 'type' => 'select',
+ 'label' => $this->l('Watermark X align:'),
+ 'name' => 'xalign',
+ 'class' => 'fixed-width-md',
+ 'options' => array(
+ 'query' => array(
+ array(
+ 'id' => 'left',
+ 'name' => $this->l('left')
+ ),
+ array(
+ 'id' => 'middle',
+ 'name' => $this->l('middle')
+ ),
+ array(
+ 'id' => 'right',
+ 'name' => $this->l('right')
+ )
+ ),
+ 'id' => 'id',
+ 'name' => 'name',
+ )
+ ),
+ array(
+ 'type' => 'select',
+ 'label' => $this->l('Watermark X align:'),
+ 'name' => 'yalign',
+ 'class' => 'fixed-width-md',
+ 'options' => array(
+ 'query' => array(
+ array(
+ 'id' => 'top',
+ 'name' => $this->l('top')
+ ),
+ array(
+ 'id' => 'middle',
+ 'name' => $this->l('middle')
+ ),
+ array(
+ 'id' => 'bottom',
+ 'name' => $this->l('bottom')
+ )
+ ),
+ 'id' => 'id',
+ 'name' => 'name',
+ )
+ ),
+ array(
+ 'type' => 'checkbox',
+ 'name' => 'WATERMARK_TYPES',
+ 'label' => $this->l('Choose image types for watermark protection:'),
+ 'values' => array(
+ 'query' => $types,
+ 'id' => 'id_image_type',
+ 'name' => 'label'
+ )
+ ),
+ ),
+ 'submit' => array(
+ 'title' => $this->l('Save'),
+ 'class' => 'btn btn-default')
+ ),
+ );
+
+ $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;
+ $helper->identifier = $this->identifier;
+ $helper->submit_action = 'btnSubmit';
+ $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()
+ {
+ $config_fields = array(
+ 'PS_WATERMARK' => Tools::getValue('PS_WATERMARK', Configuration::get('PS_WATERMARK')),
+ 'transparency' => Tools::getValue('transparency', Configuration::get('WATERMARK_TRANSPARENCY')),
+ 'xalign' => Tools::getValue('xalign', Configuration::get('WATERMARK_X_ALIGN')),
+ 'yalign' => Tools::getValue('yalign', Configuration::get('WATERMARK_Y_ALIGN')),
+ );
+ //get all images type available
+ $types = ImageType::getImagesTypes('products');
+ $id_image_type = array();
+ foreach ($types as $type)
+ $id_image_type[] = $type['id_image_type'];
+
+ //get images type from $_POST
+ $id_image_type_post = array();
+ foreach ($id_image_type as $id)
+ if (Tools::getValue('WATERMARK_TYPES_'.(int)$id))
+ $id_image_type_post['WATERMARK_TYPES_'.(int)$id] = true;
+
+ //get images type from Configuration
+ $id_image_type_config = array();
+ if ($confs = Configuration::get('WATERMARK_TYPES'))
+ $confs = explode(',', Configuration::get('WATERMARK_TYPES'));
+ else
+ $confs = array();
+
+ foreach ($confs as $conf)
+ $id_image_type_config['WATERMARK_TYPES_'.(int)$conf] = true;
+
+ //return only common values and value from post
+ if (Tools::isSubmit('btnSubmit'))
+ $config_fields = array_merge($config_fields, array_intersect($id_image_type_post, $id_image_type_config));
+ else
+ $config_fields = array_merge($config_fields, $id_image_type_config);
+
+ return $config_fields;
+ }
+}
\ No newline at end of file