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