· 8 years ago · Feb 02, 2018, 10:50 AM
1<?php
2
3use PrestaShop\PrestaShop\Core\Module\WidgetInterface;
4
5if (!defined('_PS_VERSION_'))
6 exit;
7
8class AtchConfigurator extends Module implements WidgetInterface
9{
10 protected $max_image_size = 1048576;
11 protected $default_language;
12 protected $languages;
13
14 protected $default_theme_variables = array(
15 'color_scheme' => '#ffffff',
16 'layout_boxed' => 0,
17 'bg_body' => '#f0f0f0',
18 'full_header' => 1,
19 'style_banner' => 'dark',
20 'style_navbar' => 'light',
21 'style_menu' => 'white',
22 'boxed_menu' => 0,
23 'full_footer' => 1,
24 'style_footer_top' => 'light',
25 'style_footer' => 'white',
26 'border_list' => 1,
27 'add_to_cart' => 1
28 );
29 protected $theme_variables = array();
30
31
32 public function __construct()
33 {
34 $this->name = 'atchconfigurator';
35 $this->author = 'atchworks';
36 $this->version = '2.0.0';
37 $this->tab = 'front_office_features';
38 $this->bootstrap = true;
39 $this->secure_key = Tools::encrypt($this->name);
40 $this->default_language = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT'));
41 $this->languages = Language::getLanguages();
42 parent::__construct();
43 $this->displayName = $this->l('Theme configurator');
44 $this->description = $this->l('Configure the main elements of Atchworks theme.');
45 $this->ps_versions_compliancy = array('min' => '1.7.0.0', 'max' => _PS_VERSION_);
46 $this->module_path = _PS_MODULE_DIR_.$this->name.'/';
47 $this->uploads_path = _PS_MODULE_DIR_.$this->name.'/img/';
48 $this->admin_tpl_path = _PS_MODULE_DIR_.$this->name.'/views/templates/admin/';
49 $this->hooks_tpl_path = _PS_MODULE_DIR_.$this->name.'/views/templates/hooks/';
50
51 $this->theme_variable = $this->readThemesVariables();
52
53
54 }
55
56 protected function readThemesVariables () {
57 $config_serialized = Configuration::get('ATCH_VARIABLES', '');
58
59 $config = ($config_serialized)
60 ? unserialize($config_serialized)
61 :array();
62
63 return array_merge (
64 $this->default_theme_variables,
65 $config
66 );
67 }
68
69 protected function writeThemesVariables () {
70 return Configuration::updateValue('ATCH_VARIABLES', serialize($this->theme_variables));
71 }
72
73 public function createAjaxController()
74 {
75 $tab = new Tab();
76 $tab->active = 1;
77 $languages = Language::getLanguages(false);
78 if (is_array($languages))
79 foreach ($languages as $language)
80 $tab->name[$language['id_lang']] = 'atchconfigurator';
81 $tab->class_name = 'AdminAtchConfigurator';
82 $tab->module = $this->name;
83 $tab->id_parent = - 1;
84 return (bool)$tab->add();
85 }
86
87 private function _removeAjaxContoller()
88 {
89 if ($tab_id = (int)Tab::getIdFromClassName('AdminAtchConfigurator'))
90 {
91 $tab = new Tab($tab_id);
92 $tab->delete();
93 }
94 return true;
95 }
96
97 public function install()
98 {
99
100
101 if (!parent::install()
102 || !$this->installDB() ||
103 !$this->registerHook('displayHeader') ||
104 !$this->registerHook('displayHome') ||
105 !$this->registerHook('displayFooterBefore') ||
106 !$this->registerHook('displayFooterAfter') ||
107 !$this->registerHook('actionObjectLanguageAddAfter') ||
108 !$this->registerHook('displayProductListbuttons') ||
109 !$this->writeThemesVariables() ||
110 !$this->createAjaxController()
111
112 )
113 return false;
114
115 return true;
116 }
117
118 private function installDB()
119 {
120 return (
121 Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'atchconfigurator`') &&
122 Db::getInstance()->Execute('
123 CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'atchconfigurator` (
124 `id_item` int(10) unsigned NOT NULL AUTO_INCREMENT,
125 `id_shop` int(10) unsigned NOT NULL,
126 `id_lang` int(10) unsigned NOT NULL,
127 `item_order` int(10) unsigned NOT NULL,
128 `title` VARCHAR(100),
129 `title_use` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
130 `mobile` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
131 `hook` VARCHAR(100),
132 `url` TEXT,
133 `target` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
134 `image` VARCHAR(100),
135 `image_w` VARCHAR(10),
136 `image_h` VARCHAR(10),
137 `icon` VARCHAR(100),
138 `grid` VARCHAR(100),
139 `html` TEXT,
140 `active` tinyint(1) unsigned NOT NULL DEFAULT \'1\',
141 PRIMARY KEY (`id_item`)
142 ) ENGINE = '._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;')
143 );
144
145 }
146
147
148 public function uninstall()
149 {
150 if (!parent::uninstall() ||
151 !Db::getInstance()->Execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'atchconfigurator`') ||
152 !$this->_removeAjaxContoller() ||
153 !Configuration::deleteByName('ATCH_VARIABLES')
154 )
155 return false;
156
157 return true;
158 }
159
160 public function hookdisplayHeader()
161 {
162 $this->context->smarty->assign(array(
163 'atch_variables' => $this->readThemesVariables())
164 );
165 }
166
167
168 public function hookdisplayProductListbuttons($params)
169 {
170 $this->theme_variables = $this->readThemesVariables();
171
172 if ($this->theme_variables['add_to_cart'])
173 {
174 $this->link_cart = $this->context->link->getPageLink('cart', true);
175
176 $product = $params['product'];
177
178 $templateVars = array(
179 'static_token' => Tools::getToken(false),
180 'product' => $product,
181 'link_cart' => $this->link_cart
182 );
183 $this->context->smarty->assign($templateVars);
184
185 return $this->display(__FILE__, 'buttons_list.tpl');
186 }
187 return false;
188 }
189
190
191
192 public function renderWidget($hookName, array $params)
193 {
194
195 if( $hookName == 'displayHome'|| $hookName == 'displayHomeBefore'){
196 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
197 return $this->display(__FILE__, 'image_home.tpl');
198
199 } elseif ($hookName == 'displayLeftColumn' || $hookName == 'displayRightColumn') {
200 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
201 return $this->display(__FILE__, 'image_left.tpl');
202
203 } elseif ($hookName == 'displayHomeAfter') {
204 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
205 return $this->display(__FILE__, 'reinsurance_home.tpl');
206
207 } elseif ($hookName == 'displayReassurance') {
208 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
209 return $this->display(__FILE__, 'reinsurance_left.tpl');
210
211 } elseif ($hookName == 'displayReassuranceProduct') {
212 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
213 return $this->display(__FILE__, 'reinsurance_product.tpl');
214
215 } elseif ($hookName == 'displayFooterAfter') {
216 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
217 return $this->display(__FILE__, 'paiement_logo.tpl');
218 }
219
220 }
221
222
223 public function getWidgetVariables($hookName, array $params)
224 {
225
226 if( $hookName == 'displayLeftColumn' || $hookName == 'displayRightColumn' ){
227
228 return [
229 'htmlitems' => $this->getItemsFromHook('top'),
230 'hook' => 'top'
231 ];
232
233 } elseif ($hookName == 'displayHome'|| $hookName == 'displayHomeBefore') {
234
235 return [
236 'htmlitems' => $this->getItemsFromHook('home'),
237 'hook' => 'home'
238 ];
239 } elseif ($hookName == 'displayHomeAfter' || $hookName == 'displayReassurance') {
240
241 return [
242 'htmlitems' => $this->getItemsFromHook('left'),
243 'hook' => 'left'
244 ];
245 } elseif ($hookName == 'displayReassuranceProduct') {
246
247 return [
248 'htmlitems' => $this->getItemsFromHook('right'),
249 'hook' => 'right'
250 ];
251 } elseif ($hookName == 'displayFooterAfter') {
252
253 return [
254 'htmlitems' => $this->getItemsFromHook('footer'),
255 'hook' => 'footer'
256 ];
257 }
258 }
259
260 protected function getItemsFromHook($hook)
261 {
262 if (!$hook)
263 return false;
264
265 return Db::getInstance()->ExecuteS('
266 SELECT *
267 FROM `'._DB_PREFIX_.'atchconfigurator`
268 WHERE id_shop = '.(int)$this->context->shop->id.' AND id_lang = '.(int)$this->context->language->id.'
269 AND hook = \''.pSQL($hook).'\' AND active = 1
270 ORDER BY item_order ASC');
271 }
272
273 protected function deleteImage($image)
274 {
275 $file_name = $this->uploads_path.$image;
276
277 if (realpath(dirname($file_name)) != realpath($this->uploads_path))
278 Tools::dieOrLog(sprintf('Could not find upload directory'));
279
280 if ($image != '' && is_file($file_name) && !strpos($file_name, 'banner-img') && !strpos($file_name, 'bg-theme') && !strpos($file_name, 'footer-bg'))
281 unlink($file_name);
282 }
283
284 protected function removeItem()
285 {
286 $id_item = (int)Tools::getValue('item_id');
287
288 if ($image = Db::getInstance()->getValue('SELECT image FROM `'._DB_PREFIX_.'atchconfigurator` WHERE id_item = '.(int)$id_item))
289 $this->deleteImage($image);
290
291 Db::getInstance()->delete(_DB_PREFIX_.'atchconfigurator', 'id_item = '.(int)$id_item);
292
293 if (Db::getInstance()->Affected_Rows() == 1)
294 {
295 Db::getInstance()->execute('
296 UPDATE `'._DB_PREFIX_.'atchconfigurator`
297 SET item_order = item_order-1
298 WHERE (
299 item_order > '.(int)Tools::getValue('item_order').' AND
300 id_shop = '.(int)$this->context->shop->id.' AND
301 hook = \''.pSQL(Tools::getValue('item_hook')).'\')'
302 );
303 Tools::redirectAdmin('index.php?tab=AdminModules&configure='.$this->name.'&conf=6&token='.Tools::getAdminTokenLite('AdminModules'));
304 }
305 else
306 $this->context->smarty->assign('error', $this->l('Can\'t delete the slide.'));
307 }
308
309 protected function updateItem()
310 {
311 $id_item = (int)Tools::getValue('item_id');
312 $title = Tools::getValue('item_title');
313 $content = Tools::getValue('item_html');
314 $icon = Tools::getValue('item_icon');
315 $grid = Tools::getValue('item_grid');
316
317 if (!Validate::isCleanHtml($title, (int)Configuration::get('PS_ALLOW_HTML_IFRAME')) || !Validate::isCleanHtml($content, (int)Configuration::get('PS_ALLOW_HTML_IFRAME')))
318 {
319 $this->context->smarty->assign('error', $this->l('Invalid content'));
320 return false;
321 }
322
323 $new_image = '';
324 $image_w = (is_numeric(Tools::getValue('item_img_w'))) ? (int)Tools::getValue('item_img_w') : '';
325 $image_h = (is_numeric(Tools::getValue('item_img_h'))) ? (int)Tools::getValue('item_img_h') : '';
326
327 if (!empty($_FILES['item_img']['name']))
328 {
329 if ($old_image = Db::getInstance()->getValue('SELECT image FROM `'._DB_PREFIX_.'atchconfigurator` WHERE id_item = '.(int)$id_item))
330 if (file_exists(dirname(__FILE__).'/img/'.$old_image))
331 @unlink(dirname(__FILE__).'/img/'.$old_image);
332
333 if (!$image = $this->uploadImage($_FILES['item_img'], $image_w, $image_h))
334 return false;
335
336 $new_image = 'image = \''.pSQL($image).'\',';
337 }
338
339 if (!Db::getInstance()->execute('
340 UPDATE `'._DB_PREFIX_.'atchconfigurator` SET
341 title = \''.pSQL($title).'\',
342 title_use = '.(int)Tools::getValue('item_title_use').',
343 mobile = '.(int)Tools::getValue('item_mobile').',
344 hook = \''.pSQL(Tools::getValue('item_hook')).'\',
345 url = \''.pSQL(Tools::getValue('item_url')).'\',
346 target = '.(int)Tools::getValue('item_target').',
347 '.$new_image.'
348 image_w = '.(int)$image_w.',
349 image_h = '.(int)$image_h.',
350 active = '.(int)Tools::getValue('item_active').',
351 html = \''.pSQL($this->filterVar($content), true).'\',
352 icon = \''.pSQL(Tools::purifyHTML($icon), true).'\',
353 grid = \''.pSQL(Tools::getValue('item_grid')).'\'
354 WHERE id_item = '.(int)Tools::getValue('item_id')
355 ))
356 {
357 if ($image = Db::getInstance()->getValue('SELECT image FROM `'._DB_PREFIX_.'atchconfigurator` WHERE id_item = '.(int)Tools::getValue('item_id')))
358 $this->deleteImage($image);
359
360 $this->context->smarty->assign('error', $this->l('An error occurred while saving data.'));
361
362 return false;
363 }
364
365 $this->context->smarty->assign('confirmation', $this->l('Successfully updated.'));
366
367 return true;
368 }
369
370 protected function uploadImage($image, $image_w = '', $image_h = '')
371 {
372 $res = false;
373 if (is_array($image) && (ImageManager::validateUpload($image, $this->max_image_size) === false) && ($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) && move_uploaded_file($image['tmp_name'], $tmp_name))
374 {
375 $salt = sha1(microtime());
376 $pathinfo = pathinfo($image['name']);
377 $img_name = $salt.'_'.Tools::str2url($pathinfo['filename']).'.'.$pathinfo['extension'];
378
379 if (ImageManager::resize($tmp_name, dirname(__FILE__).'/img/'.$img_name, $image_w, $image_h))
380 $res = true;
381 }
382
383 if (!$res)
384 {
385 $this->context->smarty->assign('error', $this->l('An error occurred during the image upload.'));
386 return false;
387 }
388
389 return $img_name;
390 }
391
392 public function getContent()
393 {
394 if (Tools::isSubmit('submitModule'))
395 {
396 $this->theme_variables = array(
397 'color_scheme' => Tools::getValue('color_scheme'),
398 'layout_boxed' => Tools::getValue('layout_boxed' ),
399 'bg_body' => Tools::getValue('bg_body'),
400 'full_header' => Tools::getValue('full_header'),
401 'style_banner' => Tools::getValue('style_banner'),
402 'style_navbar' => Tools::getValue('style_navbar'),
403 'style_menu' => Tools::getValue('style_menu'),
404 'boxed_menu' => Tools::getValue('boxed_menu'),
405 'full_footer' => Tools::getValue('full_footer'),
406 'style_footer_top' => Tools::getValue('style_footer_top'),
407 'style_footer' => Tools::getValue('style_footer'),
408 'border_list' => Tools::getValue('border_list'),
409 'add_to_cart' => Tools::getValue('add_to_cart')
410 );
411 Configuration::updateValue('ATCH_VARIABLES', serialize($this->theme_variables));
412
413 }
414
415 $this->context->controller->addCSS($this->_path.'views/css/admin.css');
416 $this->context->controller->addJS($this->_path.'views/js/admin.js');
417
418 if (Tools::isSubmit('newItem'))
419 $this->addItem();
420 elseif (Tools::isSubmit('updateItem'))
421 $this->updateItem();
422 elseif (Tools::isSubmit('removeItem'))
423 $this->removeItem();
424
425 $html = $this->renderConfigurationForm();
426 $html .= $this->renderAtchConfiguratorForm();
427
428 return $html;
429 }
430
431 protected function addItem()
432 {
433 $title = Tools::getValue('item_title');
434 $content = Tools::getValue('item_html');
435 $icon = Tools::getValue('item_icon');
436 $grid = Tools::getValue('item_grid');
437
438 if (!Validate::isCleanHtml($title, (int)Configuration::get('PS_ALLOW_HTML_IFRAME'))
439 || !Validate::isCleanHtml($content, (int)Configuration::get('PS_ALLOW_HTML_IFRAME')))
440 {
441 $this->context->smarty->assign('error', $this->l('Invalid content'));
442 return false;
443 }
444
445 if (!$current_order = (int)Db::getInstance()->getValue('
446 SELECT item_order + 1
447 FROM `'._DB_PREFIX_.'atchconfigurator`
448 WHERE
449 id_shop = '.(int)$this->context->shop->id.'
450 AND id_lang = '.(int)Tools::getValue('id_lang').'
451 AND hook = \''.pSQL(Tools::getValue('item_hook')).'\'
452 ORDER BY item_order DESC'
453 ))
454 $current_order = 1;
455
456 $image_w = is_numeric(Tools::getValue('item_img_w')) ? (int)Tools::getValue('item_img_w') : '';
457 $image_h = is_numeric(Tools::getValue('item_img_h')) ? (int)Tools::getValue('item_img_h') : '';
458
459 if (!empty($_FILES['item_img']['name']))
460 {
461 if (!$image = $this->uploadImage($_FILES['item_img'], $image_w, $image_h))
462 return false;
463 }
464 else
465 {
466 $image = '';
467 $image_w = '';
468 $image_h = '';
469 }
470
471 if (!Db::getInstance()->Execute('
472 INSERT INTO `'._DB_PREFIX_.'atchconfigurator` (
473 `id_shop`, `id_lang`, `item_order`, `title`, `title_use`,`mobile`, `hook`, `url`, `target`, `image`, `image_w`, `image_h`, `html`, `icon`, `grid`, `active`
474 ) VALUES (
475 \''.(int)$this->context->shop->id.'\',
476 \''.(int)Tools::getValue('id_lang').'\',
477 \''.(int)$current_order.'\',
478 \''.pSQL($title).'\',
479 \''.(int)Tools::getValue('item_title_use').'\',
480 \''.(int)Tools::getValue('item_mobile').'\',
481 \''.pSQL(Tools::getValue('item_hook')).'\',
482 \''.pSQL(Tools::getValue('item_url')).'\',
483 \''.(int)Tools::getValue('item_target').'\',
484 \''.pSQL($image).'\',
485 \''.pSQL($image_w).'\',
486 \''.pSQL($image_h).'\',
487 \''.pSQL($this->filterVar($content), true).'\',
488 \''.pSQL($this->filterVar($icon), true).'\',
489 \''.pSQL(Tools::getValue('item_grid')).'\',
490 1)'
491 ))
492 {
493 if (!Tools::isEmpty($image))
494 $this->deleteImage($image);
495
496 $this->context->smarty->assign('error', $this->l('An error occurred while saving data.'));
497 return false;
498 }
499
500 $this->context->smarty->assign('confirmation', $this->l('New item successfully added.'));
501 return true;
502 }
503
504 public function renderConfigurationForm()
505 {
506
507 $options = array(
508 array(
509 'id_option' => 'white',
510 'name' => $this->l('Transparent background'),
511 ),
512 array(
513 'id_option' => 'light',
514 'name' => $this->l('Light background'),
515 ),
516 array(
517 'id_option' => 'colored',
518 'name' => $this->l('Colored background'),
519 ),
520 array(
521 'id_option' => 'dark',
522 'name' => $this->l('Dark background'),
523 ),
524 );
525
526 $fields_form = array(
527 'form' => array(
528 'legend' => array(
529 'title' => $this->l('Settings'),
530 'icon' => 'icon-cogs'
531 ),
532 'input' => array(
533 array(
534 'type' => 'color',
535 'label' => $this->l('Choose your Color scheme'),
536 'name' => 'color_scheme',
537 'class' => 'color mColorPickerInput'
538 ),
539 array(
540 'type' => 'switch',
541 'label' => $this->l('Boxed layout theme'),
542 'name' => 'layout_boxed',
543 'values' => array(
544 array(
545 'id' => 'active_on',
546 'value' => 1,
547 'label' => $this->l('Enabled')
548 ),
549 array(
550 'id' => 'active_off',
551 'value' => 0,
552 'label' => $this->l('Disabled')
553 )
554 ),
555 ),
556 array(
557 'type' => 'color',
558 'label' => $this->l('Choose a background color for body'),
559 'name' => 'bg_body',
560 'class' => 'color mColorPickerInput'
561 ),
562 array(
563 'type' => 'switch',
564 'label' => $this->l('Full header'),
565 'name' => 'full_header',
566 'values' => array(
567 array(
568 'id' => 'active_on',
569 'value' => 1,
570 'label' => $this->l('Enabled')
571 ),
572 array(
573 'id' => 'active_off',
574 'value' => 0,
575 'label' => $this->l('Disabled')
576 )
577 ),
578 ),
579 array(
580 'type' => 'select',
581 'label' => $this->l('Choose banner style'),
582 'name' => 'style_banner',
583 'options' => array(
584 'query' => $options,
585 'id' => 'id_option',
586 'name' => 'name'
587 )
588 ),
589 array(
590 'type' => 'select',
591 'label' => $this->l('Choose navbar style'),
592 'name' => 'style_navbar',
593 'options' => array(
594 'query' => $options,
595 'id' => 'id_option',
596 'name' => 'name'
597 )
598 ),
599 array(
600 'type' => 'select',
601 'label' => $this->l('Choose Menu style'),
602 'name' => 'style_menu',
603 'options' => array(
604 'query' => $options,
605 'id' => 'id_option',
606 'name' => 'name'
607 )
608 ),
609 array(
610 'type' => 'switch',
611 'label' => $this->l('Boxed menu when full header'),
612 'name' => 'boxed_menu',
613 'values' => array(
614 array(
615 'id' => 'active_on',
616 'value' => 1,
617 'label' => $this->l('Enabled')
618 ),
619 array(
620 'id' => 'active_off',
621 'value' => 0,
622 'label' => $this->l('Disabled')
623 )
624 ),
625 ),
626 array(
627 'type' => 'switch',
628 'label' => $this->l('Full Footer'),
629 'name' => 'full_footer',
630 'values' => array(
631 array(
632 'id' => 'active_on',
633 'value' => 1,
634 'label' => $this->l('Enabled')
635 ),
636 array(
637 'id' => 'active_off',
638 'value' => 0,
639 'label' => $this->l('Disabled')
640 )
641 ),
642 ),
643 array(
644 'type' => 'select',
645 'label' => $this->l('Choose top footer style'),
646 'name' => 'style_footer_top',
647 'options' => array(
648 'query' => $options,
649 'id' => 'id_option',
650 'name' => 'name'
651 )
652 ),
653 array(
654 'type' => 'select',
655 'label' => $this->l('Choose footer style'),
656 'name' => 'style_footer',
657 'options' => array(
658 'query' => $options,
659 'id' => 'id_option',
660 'name' => 'name'
661 )
662 ),
663 array(
664 'type' => 'switch',
665 'label' => $this->l('listing product with border'),
666 'name' => 'border_list',
667 'values' => array(
668 array(
669 'id' => 'active_on',
670 'value' => 1,
671 'label' => $this->l('Enabled')
672 ),
673 array(
674 'id' => 'active_off',
675 'value' => 0,
676 'label' => $this->l('Disabled')
677 )
678 ),
679 ),
680 array(
681 'type' => 'switch',
682 'label' => $this->l('Listing product with button add to cart'),
683 'name' => 'add_to_cart',
684 'values' => array(
685 array(
686 'id' => 'active_on',
687 'value' => 1,
688 'label' => $this->l('Enabled')
689 ),
690 array(
691 'id' => 'active_off',
692 'value' => 0,
693 'label' => $this->l('Disabled')
694 )
695 ),
696 ),
697 ),
698 'submit' => array(
699 'title' => $this->l('Save'),
700 'class' => 'btn btn-default pull-right'
701 )
702 ),
703 );
704
705 $helper = new HelperForm();
706 $helper->show_toolbar = false;
707 $helper->table = $this->table;
708 $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
709 $helper->default_form_language = $lang->id;
710 $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
711 $this->fields_form = array();
712
713 $helper->identifier = $this->identifier;
714 $helper->submit_action = 'submitModule';
715 $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
716 $helper->token = Tools::getAdminTokenLite('AdminModules');
717 $helper->tpl_vars = array(
718 'fields_value' => $this->getConfigFieldsValues(),
719 'languages' => $this->context->controller->getLanguages(),
720 'id_language' => $this->context->language->id
721 );
722
723 return $helper->generateForm(array($fields_form));
724 }
725
726 protected function renderAtchConfiguratorForm()
727 {
728 $id_shop = (int)$this->context->shop->id;
729 $items = array();
730 $hooks = array();
731
732 $this->context->smarty->assign('htmlcontent', array(
733 'admin_tpl_path' => $this->admin_tpl_path,
734 'hooks_tpl_path' => $this->hooks_tpl_path,
735
736 'info' => array(
737 'module' => $this->name,
738 'name' => $this->displayName,
739 'version' => $this->version,
740 'psVersion' => _PS_VERSION_,
741 'context' => (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 0) ? 1 : ($this->context->shop->getTotalShops() != 1) ? $this->context->shop->getContext() : 1
742 )
743 ));
744
745 foreach ($this->languages as $language)
746 {
747 $hooks[$language['id_lang']] = array(
748 'home',
749 'top',
750 'left',
751 'right',
752 'footer'
753 );
754
755 foreach ($hooks[$language['id_lang']] as $hook)
756 $items[$language['id_lang']][$hook] = Db::getInstance()->ExecuteS('
757 SELECT * FROM `'._DB_PREFIX_.'atchconfigurator`
758 WHERE id_shop = '.(int)$id_shop.'
759 AND id_lang = '.(int)$language['id_lang'].'
760 AND hook = \''.pSQL($hook).'\'
761 ORDER BY item_order ASC'
762 );
763 }
764
765 $this->context->smarty->assign('htmlitems', array(
766 'items' => $items,
767 'theme_url' => $this->context->link->getAdminLink('AdminAtchConfigurator'),
768 'lang' => array(
769 'default' => $this->default_language,
770 'all' => $this->languages,
771 'lang_dir' => _THEME_LANG_DIR_,
772 'user' => $this->context->language->id
773 ),
774 'postAction' => 'index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&tab_module=other&module_name='.$this->name.'',
775 'id_shop' => $id_shop
776 ));
777
778 $this->context->controller->addJqueryUI('ui.sortable');
779 return $this->display(__FILE__, 'views/templates/admin/admin.tpl');
780 }
781
782 public function getConfigFieldsValues()
783 {
784 return $this->theme_variables;
785 }
786
787
788 protected function filterVar($value)
789 {
790
791 return Tools::purifyHTML($value);
792 }
793}