· 8 years ago · Feb 02, 2018, 09:30 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->default_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->theme_variables)
164 );
165 }
166
167
168 public function hookdisplayProductListbuttons($params)
169 {
170
171 $this->link_cart = $this->context->link->getPageLink('cart', true);
172
173 $product = $params['product'];
174
175
176 $templateVars = array(
177 'static_token' => Tools::getToken(false),
178 'product' => $product,
179 'link_cart' => $this->link_cart
180 );
181
182 $this->context->smarty->assign($templateVars);
183
184 return $this->display(__FILE__, 'buttons_list.tpl');
185 }
186
187
188
189 public function renderWidget($hookName, array $params)
190 {
191
192 if( $hookName == 'displayHome'|| $hookName == 'displayHomeBefore'){
193 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
194 return $this->display(__FILE__, 'image_home.tpl');
195
196 } elseif ($hookName == 'displayLeftColumn' || $hookName == 'displayRightColumn') {
197 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
198 return $this->display(__FILE__, 'image_left.tpl');
199
200 } elseif ($hookName == 'displayHomeAfter') {
201 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
202 return $this->display(__FILE__, 'reinsurance_home.tpl');
203
204 } elseif ($hookName == 'displayReassurance') {
205 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
206 return $this->display(__FILE__, 'reinsurance_left.tpl');
207
208 } elseif ($hookName == 'displayReassuranceProduct') {
209 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
210 return $this->display(__FILE__, 'reinsurance_product.tpl');
211
212 } elseif ($hookName == 'displayFooterAfter') {
213 $this->smarty->assign($this->getWidgetVariables($hookName, $params));
214 return $this->display(__FILE__, 'paiement_logo.tpl');
215 }
216
217 }
218
219
220 public function getWidgetVariables($hookName, array $params)
221 {
222
223 if( $hookName == 'displayLeftColumn' || $hookName == 'displayRightColumn' ){
224
225 return [
226 'htmlitems' => $this->getItemsFromHook('top'),
227 'hook' => 'top'
228 ];
229
230 } elseif ($hookName == 'displayHome'|| $hookName == 'displayHomeBefore') {
231
232 return [
233 'htmlitems' => $this->getItemsFromHook('home'),
234 'hook' => 'home'
235 ];
236 } elseif ($hookName == 'displayHomeAfter' || $hookName == 'displayReassurance') {
237
238 return [
239 'htmlitems' => $this->getItemsFromHook('left'),
240 'hook' => 'left'
241 ];
242 } elseif ($hookName == 'displayReassuranceProduct') {
243
244 return [
245 'htmlitems' => $this->getItemsFromHook('right'),
246 'hook' => 'right'
247 ];
248 } elseif ($hookName == 'displayFooterAfter') {
249
250 return [
251 'htmlitems' => $this->getItemsFromHook('footer'),
252 'hook' => 'footer'
253 ];
254 }
255 }
256
257 protected function getItemsFromHook($hook)
258 {
259 if (!$hook)
260 return false;
261
262 return Db::getInstance()->ExecuteS('
263 SELECT *
264 FROM `'._DB_PREFIX_.'atchconfigurator`
265 WHERE id_shop = '.(int)$this->context->shop->id.' AND id_lang = '.(int)$this->context->language->id.'
266 AND hook = \''.pSQL($hook).'\' AND active = 1
267 ORDER BY item_order ASC');
268 }
269
270 protected function deleteImage($image)
271 {
272 $file_name = $this->uploads_path.$image;
273
274 if (realpath(dirname($file_name)) != realpath($this->uploads_path))
275 Tools::dieOrLog(sprintf('Could not find upload directory'));
276
277 if ($image != '' && is_file($file_name) && !strpos($file_name, 'banner-img') && !strpos($file_name, 'bg-theme') && !strpos($file_name, 'footer-bg'))
278 unlink($file_name);
279 }
280
281 protected function removeItem()
282 {
283 $id_item = (int)Tools::getValue('item_id');
284
285 if ($image = Db::getInstance()->getValue('SELECT image FROM `'._DB_PREFIX_.'atchconfigurator` WHERE id_item = '.(int)$id_item))
286 $this->deleteImage($image);
287
288 Db::getInstance()->delete(_DB_PREFIX_.'atchconfigurator', 'id_item = '.(int)$id_item);
289
290 if (Db::getInstance()->Affected_Rows() == 1)
291 {
292 Db::getInstance()->execute('
293 UPDATE `'._DB_PREFIX_.'atchconfigurator`
294 SET item_order = item_order-1
295 WHERE (
296 item_order > '.(int)Tools::getValue('item_order').' AND
297 id_shop = '.(int)$this->context->shop->id.' AND
298 hook = \''.pSQL(Tools::getValue('item_hook')).'\')'
299 );
300 Tools::redirectAdmin('index.php?tab=AdminModules&configure='.$this->name.'&conf=6&token='.Tools::getAdminTokenLite('AdminModules'));
301 }
302 else
303 $this->context->smarty->assign('error', $this->l('Can\'t delete the slide.'));
304 }
305
306 protected function updateItem()
307 {
308 $id_item = (int)Tools::getValue('item_id');
309 $title = Tools::getValue('item_title');
310 $content = Tools::getValue('item_html');
311 $icon = Tools::getValue('item_icon');
312 $grid = Tools::getValue('item_grid');
313
314 if (!Validate::isCleanHtml($title, (int)Configuration::get('PS_ALLOW_HTML_IFRAME')) || !Validate::isCleanHtml($content, (int)Configuration::get('PS_ALLOW_HTML_IFRAME')))
315 {
316 $this->context->smarty->assign('error', $this->l('Invalid content'));
317 return false;
318 }
319
320 $new_image = '';
321 $image_w = (is_numeric(Tools::getValue('item_img_w'))) ? (int)Tools::getValue('item_img_w') : '';
322 $image_h = (is_numeric(Tools::getValue('item_img_h'))) ? (int)Tools::getValue('item_img_h') : '';
323
324 if (!empty($_FILES['item_img']['name']))
325 {
326 if ($old_image = Db::getInstance()->getValue('SELECT image FROM `'._DB_PREFIX_.'atchconfigurator` WHERE id_item = '.(int)$id_item))
327 if (file_exists(dirname(__FILE__).'/img/'.$old_image))
328 @unlink(dirname(__FILE__).'/img/'.$old_image);
329
330 if (!$image = $this->uploadImage($_FILES['item_img'], $image_w, $image_h))
331 return false;
332
333 $new_image = 'image = \''.pSQL($image).'\',';
334 }
335
336 if (!Db::getInstance()->execute('
337 UPDATE `'._DB_PREFIX_.'atchconfigurator` SET
338 title = \''.pSQL($title).'\',
339 title_use = '.(int)Tools::getValue('item_title_use').',
340 mobile = '.(int)Tools::getValue('item_mobile').',
341 hook = \''.pSQL(Tools::getValue('item_hook')).'\',
342 url = \''.pSQL(Tools::getValue('item_url')).'\',
343 target = '.(int)Tools::getValue('item_target').',
344 '.$new_image.'
345 image_w = '.(int)$image_w.',
346 image_h = '.(int)$image_h.',
347 active = '.(int)Tools::getValue('item_active').',
348 html = \''.pSQL($this->filterVar($content), true).'\',
349 icon = \''.pSQL(Tools::purifyHTML($icon), true).'\',
350 grid = \''.pSQL(Tools::getValue('item_grid')).'\'
351 WHERE id_item = '.(int)Tools::getValue('item_id')
352 ))
353 {
354 if ($image = Db::getInstance()->getValue('SELECT image FROM `'._DB_PREFIX_.'atchconfigurator` WHERE id_item = '.(int)Tools::getValue('item_id')))
355 $this->deleteImage($image);
356
357 $this->context->smarty->assign('error', $this->l('An error occurred while saving data.'));
358
359 return false;
360 }
361
362 $this->context->smarty->assign('confirmation', $this->l('Successfully updated.'));
363
364 return true;
365 }
366
367 protected function uploadImage($image, $image_w = '', $image_h = '')
368 {
369 $res = false;
370 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))
371 {
372 $salt = sha1(microtime());
373 $pathinfo = pathinfo($image['name']);
374 $img_name = $salt.'_'.Tools::str2url($pathinfo['filename']).'.'.$pathinfo['extension'];
375
376 if (ImageManager::resize($tmp_name, dirname(__FILE__).'/img/'.$img_name, $image_w, $image_h))
377 $res = true;
378 }
379
380 if (!$res)
381 {
382 $this->context->smarty->assign('error', $this->l('An error occurred during the image upload.'));
383 return false;
384 }
385
386 return $img_name;
387 }
388
389 public function getContent()
390 {
391 if (Tools::isSubmit('submitModule'))
392 {
393 $this->theme_variables = array(
394 'color_scheme' => Tools::getValue('color_scheme'),
395 'layout_boxed' => Tools::getValue('layout_boxed' ),
396 'bg_body' => Tools::getValue('bg_body'),
397 'full_header' => Tools::getValue('full_header'),
398 'style_banner' => Tools::getValue('style_banner'),
399 'style_navbar' => Tools::getValue('style_navbar'),
400 'style_menu' => Tools::getValue('style_menu'),
401 'boxed_menu' => Tools::getValue('boxed_menu'),
402 'full_footer' => Tools::getValue('full_footer'),
403 'style_footer_top' => Tools::getValue('style_footer_top'),
404 'style_footer' => Tools::getValue('style_footer'),
405 'border_list' => Tools::getValue('border_list'),
406 'add_to_cart' => Tools::getValue('add_to_cart')
407 );
408 Configuration::updateValue('ATCH_VARIABLES', serialize($this->theme_variables));
409
410 }
411
412 $this->context->controller->addCSS($this->_path.'views/css/admin.css');
413 $this->context->controller->addJS($this->_path.'views/js/admin.js');
414
415 if (Tools::isSubmit('newItem'))
416 $this->addItem();
417 elseif (Tools::isSubmit('updateItem'))
418 $this->updateItem();
419 elseif (Tools::isSubmit('removeItem'))
420 $this->removeItem();
421
422 $html = $this->renderConfigurationForm();
423 $html .= $this->renderAtchConfiguratorForm();
424
425 return $html;
426 }
427
428 protected function addItem()
429 {
430 $title = Tools::getValue('item_title');
431 $content = Tools::getValue('item_html');
432 $icon = Tools::getValue('item_icon');
433 $grid = Tools::getValue('item_grid');
434
435 if (!Validate::isCleanHtml($title, (int)Configuration::get('PS_ALLOW_HTML_IFRAME'))
436 || !Validate::isCleanHtml($content, (int)Configuration::get('PS_ALLOW_HTML_IFRAME')))
437 {
438 $this->context->smarty->assign('error', $this->l('Invalid content'));
439 return false;
440 }
441
442 if (!$current_order = (int)Db::getInstance()->getValue('
443 SELECT item_order + 1
444 FROM `'._DB_PREFIX_.'atchconfigurator`
445 WHERE
446 id_shop = '.(int)$this->context->shop->id.'
447 AND id_lang = '.(int)Tools::getValue('id_lang').'
448 AND hook = \''.pSQL(Tools::getValue('item_hook')).'\'
449 ORDER BY item_order DESC'
450 ))
451 $current_order = 1;
452
453 $image_w = is_numeric(Tools::getValue('item_img_w')) ? (int)Tools::getValue('item_img_w') : '';
454 $image_h = is_numeric(Tools::getValue('item_img_h')) ? (int)Tools::getValue('item_img_h') : '';
455
456 if (!empty($_FILES['item_img']['name']))
457 {
458 if (!$image = $this->uploadImage($_FILES['item_img'], $image_w, $image_h))
459 return false;
460 }
461 else
462 {
463 $image = '';
464 $image_w = '';
465 $image_h = '';
466 }
467
468 if (!Db::getInstance()->Execute('
469 INSERT INTO `'._DB_PREFIX_.'atchconfigurator` (
470 `id_shop`, `id_lang`, `item_order`, `title`, `title_use`,`mobile`, `hook`, `url`, `target`, `image`, `image_w`, `image_h`, `html`, `icon`, `grid`, `active`
471 ) VALUES (
472 \''.(int)$this->context->shop->id.'\',
473 \''.(int)Tools::getValue('id_lang').'\',
474 \''.(int)$current_order.'\',
475 \''.pSQL($title).'\',
476 \''.(int)Tools::getValue('item_title_use').'\',
477 \''.(int)Tools::getValue('item_mobile').'\',
478 \''.pSQL(Tools::getValue('item_hook')).'\',
479 \''.pSQL(Tools::getValue('item_url')).'\',
480 \''.(int)Tools::getValue('item_target').'\',
481 \''.pSQL($image).'\',
482 \''.pSQL($image_w).'\',
483 \''.pSQL($image_h).'\',
484 \''.pSQL($this->filterVar($content), true).'\',
485 \''.pSQL($this->filterVar($icon), true).'\',
486 \''.pSQL(Tools::getValue('item_grid')).'\',
487 1)'
488 ))
489 {
490 if (!Tools::isEmpty($image))
491 $this->deleteImage($image);
492
493 $this->context->smarty->assign('error', $this->l('An error occurred while saving data.'));
494 return false;
495 }
496
497 $this->context->smarty->assign('confirmation', $this->l('New item successfully added.'));
498 return true;
499 }
500
501 public function renderConfigurationForm()
502 {
503
504 $options = array(
505 array(
506 'id_option' => 'white',
507 'name' => $this->l('Transparent background'),
508 ),
509 array(
510 'id_option' => 'light',
511 'name' => $this->l('Light background'),
512 ),
513 array(
514 'id_option' => 'colored',
515 'name' => $this->l('Colored background'),
516 ),
517 array(
518 'id_option' => 'dark',
519 'name' => $this->l('Dark background'),
520 ),
521 );
522
523 $fields_form = array(
524 'form' => array(
525 'legend' => array(
526 'title' => $this->l('Settings'),
527 'icon' => 'icon-cogs'
528 ),
529 'input' => array(
530 array(
531 'type' => 'color',
532 'label' => $this->l('Choose your Color scheme'),
533 'name' => 'color_scheme',
534 'class' => 'color mColorPickerInput'
535 ),
536 array(
537 'type' => 'switch',
538 'label' => $this->l('Boxed layout theme'),
539 'name' => 'layout_boxed',
540 'values' => array(
541 array(
542 'id' => 'active_on',
543 'value' => 1,
544 'label' => $this->l('Enabled')
545 ),
546 array(
547 'id' => 'active_off',
548 'value' => 0,
549 'label' => $this->l('Disabled')
550 )
551 ),
552 ),
553 array(
554 'type' => 'color',
555 'label' => $this->l('Choose a background color for body'),
556 'name' => 'bg_body',
557 'class' => 'color mColorPickerInput'
558 ),
559 array(
560 'type' => 'switch',
561 'label' => $this->l('Full header'),
562 'name' => 'full_header',
563 'values' => array(
564 array(
565 'id' => 'active_on',
566 'value' => 1,
567 'label' => $this->l('Enabled')
568 ),
569 array(
570 'id' => 'active_off',
571 'value' => 0,
572 'label' => $this->l('Disabled')
573 )
574 ),
575 ),
576 array(
577 'type' => 'select',
578 'label' => $this->l('Choose banner style'),
579 'name' => 'style_banner',
580 'options' => array(
581 'query' => $options,
582 'id' => 'id_option',
583 'name' => 'name'
584 )
585 ),
586 array(
587 'type' => 'select',
588 'label' => $this->l('Choose navbar style'),
589 'name' => 'style_navbar',
590 'options' => array(
591 'query' => $options,
592 'id' => 'id_option',
593 'name' => 'name'
594 )
595 ),
596 array(
597 'type' => 'select',
598 'label' => $this->l('Choose Menu style'),
599 'name' => 'style_menu',
600 'options' => array(
601 'query' => $options,
602 'id' => 'id_option',
603 'name' => 'name'
604 )
605 ),
606 array(
607 'type' => 'switch',
608 'label' => $this->l('Boxed menu when full header'),
609 'name' => 'boxed_menu',
610 'values' => array(
611 array(
612 'id' => 'active_on',
613 'value' => 1,
614 'label' => $this->l('Enabled')
615 ),
616 array(
617 'id' => 'active_off',
618 'value' => 0,
619 'label' => $this->l('Disabled')
620 )
621 ),
622 ),
623 array(
624 'type' => 'switch',
625 'label' => $this->l('Full Footer'),
626 'name' => 'full_footer',
627 'values' => array(
628 array(
629 'id' => 'active_on',
630 'value' => 1,
631 'label' => $this->l('Enabled')
632 ),
633 array(
634 'id' => 'active_off',
635 'value' => 0,
636 'label' => $this->l('Disabled')
637 )
638 ),
639 ),
640 array(
641 'type' => 'select',
642 'label' => $this->l('Choose top footer style'),
643 'name' => 'style_footer_top',
644 'options' => array(
645 'query' => $options,
646 'id' => 'id_option',
647 'name' => 'name'
648 )
649 ),
650 array(
651 'type' => 'select',
652 'label' => $this->l('Choose footer style'),
653 'name' => 'style_footer',
654 'options' => array(
655 'query' => $options,
656 'id' => 'id_option',
657 'name' => 'name'
658 )
659 ),
660 array(
661 'type' => 'switch',
662 'label' => $this->l('listing product with border'),
663 'name' => 'border_list',
664 'values' => array(
665 array(
666 'id' => 'active_on',
667 'value' => 1,
668 'label' => $this->l('Enabled')
669 ),
670 array(
671 'id' => 'active_off',
672 'value' => 0,
673 'label' => $this->l('Disabled')
674 )
675 ),
676 ),
677 array(
678 'type' => 'switch',
679 'label' => $this->l('Listing product with button add to cart'),
680 'name' => 'add_to_cart',
681 'values' => array(
682 array(
683 'id' => 'active_on',
684 'value' => 1,
685 'label' => $this->l('Enabled')
686 ),
687 array(
688 'id' => 'active_off',
689 'value' => 0,
690 'label' => $this->l('Disabled')
691 )
692 ),
693 ),
694 ),
695 'submit' => array(
696 'title' => $this->l('Save'),
697 'class' => 'btn btn-default pull-right'
698 )
699 ),
700 );
701
702 $helper = new HelperForm();
703 $helper->show_toolbar = false;
704 $helper->table = $this->table;
705 $lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
706 $helper->default_form_language = $lang->id;
707 $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
708 $this->fields_form = array();
709
710 $helper->identifier = $this->identifier;
711 $helper->submit_action = 'submitModule';
712 $helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
713 $helper->token = Tools::getAdminTokenLite('AdminModules');
714 $helper->tpl_vars = array(
715 'fields_value' => $this->getConfigFieldsValues(),
716 'languages' => $this->context->controller->getLanguages(),
717 'id_language' => $this->context->language->id
718 );
719
720 return $helper->generateForm(array($fields_form));
721 }
722
723 protected function renderAtchConfiguratorForm()
724 {
725 $id_shop = (int)$this->context->shop->id;
726 $items = array();
727 $hooks = array();
728
729 $this->context->smarty->assign('htmlcontent', array(
730 'admin_tpl_path' => $this->admin_tpl_path,
731 'hooks_tpl_path' => $this->hooks_tpl_path,
732
733 'info' => array(
734 'module' => $this->name,
735 'name' => $this->displayName,
736 'version' => $this->version,
737 'psVersion' => _PS_VERSION_,
738 'context' => (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') == 0) ? 1 : ($this->context->shop->getTotalShops() != 1) ? $this->context->shop->getContext() : 1
739 )
740 ));
741
742 foreach ($this->languages as $language)
743 {
744 $hooks[$language['id_lang']] = array(
745 'home',
746 'top',
747 'left',
748 'right',
749 'footer'
750 );
751
752 foreach ($hooks[$language['id_lang']] as $hook)
753 $items[$language['id_lang']][$hook] = Db::getInstance()->ExecuteS('
754 SELECT * FROM `'._DB_PREFIX_.'atchconfigurator`
755 WHERE id_shop = '.(int)$id_shop.'
756 AND id_lang = '.(int)$language['id_lang'].'
757 AND hook = \''.pSQL($hook).'\'
758 ORDER BY item_order ASC'
759 );
760 }
761
762 $this->context->smarty->assign('htmlitems', array(
763 'items' => $items,
764 'theme_url' => $this->context->link->getAdminLink('AdminAtchConfigurator'),
765 'lang' => array(
766 'default' => $this->default_language,
767 'all' => $this->languages,
768 'lang_dir' => _THEME_LANG_DIR_,
769 'user' => $this->context->language->id
770 ),
771 'postAction' => 'index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules').'&tab_module=other&module_name='.$this->name.'',
772 'id_shop' => $id_shop
773 ));
774
775 $this->context->controller->addJqueryUI('ui.sortable');
776 return $this->display(__FILE__, 'views/templates/admin/admin.tpl');
777 }
778
779 public function getConfigFieldsValues()
780 {
781 return $this->theme_variables;
782 }
783
784
785 protected function filterVar($value)
786 {
787
788 return Tools::purifyHTML($value);
789 }
790}