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