diff --git a/admin-dev/themes/default/template/controllers/categories/helpers/form/form.tpl b/admin-dev/themes/default/template/controllers/categories/helpers/form/form.tpl index 9d56fd617..38726a546 100644 --- a/admin-dev/themes/default/template/controllers/categories/helpers/form/form.tpl +++ b/admin-dev/themes/default/template/controllers/categories/helpers/form/form.tpl @@ -64,6 +64,7 @@ }); }); + {$displayBackOfficeCategory} {else} {$smarty.block.parent} {/if} diff --git a/controllers/admin/AdminCategoriesController.php b/controllers/admin/AdminCategoriesController.php index 612febe0b..a31a674a0 100644 --- a/controllers/admin/AdminCategoriesController.php +++ b/controllers/admin/AdminCategoriesController.php @@ -494,9 +494,10 @@ class AdminCategoriesControllerCore extends AdminController 'class' => 'btn-default' ) ); - + $this->tpl_form_vars['shared_category'] = Validate::isLoadedObject($obj) && $obj->hasMultishopEntries(); $this->tpl_form_vars['PS_ALLOW_ACCENTED_CHARS_URL'] = (int)Configuration::get('PS_ALLOW_ACCENTED_CHARS_URL'); + $this->tpl_form_vars['displayBackOfficeCategory'] = Hook::exec('displayBackOfficeCategory'); // Display this field only if multistore option is enabled if (Configuration::get('PS_MULTISHOP_FEATURE_ACTIVE') && Tools::isSubmit('add'.$this->table.'root')) @@ -574,6 +575,8 @@ class AdminCategoriesControllerCore extends AdminController if (Tools::isSubmit('forcedeleteImage')) Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminCategories').'&conf=7'); } + + Hook::exec('actionBackOfficeCategory'); return parent::postProcess(); } diff --git a/install-dev/data/xml/hook.xml b/install-dev/data/xml/hook.xml index 36f90f85a..cd26919da 100644 --- a/install-dev/data/xml/hook.xml +++ b/install-dev/data/xml/hook.xml @@ -68,7 +68,7 @@ actionOrderStatusUpdateOrder status update - EventThis hook launches modules when the status of an order changes. - displayAdminOrderDisplay new elements in the Back Office, tab AdminOrderThis hook launches modules when the AdminOrder" tab is displayed in the Back Office" + displayAdminOrderDisplay new elements in the Back Office, tab AdminOrderThis hook launches modules when the AdminOrder tab is displayed in the Back Office displayFooterFooterThis hook displays new blocks in the footer @@ -77,7 +77,7 @@ displayPDFInvoicePDF InvoiceThis hook allows you to display additional information on PDF invoices - displayAdminCustomersDisplay new elements in the Back Office, tab AdminCustomersThis hook launches modules when the AdminCustomers" tab is displayed in the Back Office" + displayAdminCustomersDisplay new elements in the Back Office, tab AdminCustomersThis hook launches modules when the AdminCustomers tab is displayed in the Back Office displayOrderConfirmationOrder confirmation pageThis hook is called within an order's confirmation page @@ -279,6 +279,12 @@ displayHomeTabContentHome Page Tabs ContentThis hook displays new elements on the homepage tabs content - + + + displayBackOfficeCategoryDisplay new elements in the Back Office, tab AdminCategoriesThis hook launches modules when the AdminCategories tab is displayed in the Back Office + + + actionBackOfficeCategoryProcess new elements in the Back Office, tab AdminCategoriesThis hook process modules when the AdminCategories tab is displayed in the Back Office + diff --git a/install-dev/upgrade/sql/1.6.0.1.sql b/install-dev/upgrade/sql/1.6.0.1.sql index d6b40b1d7..ba5833bd6 100644 --- a/install-dev/upgrade/sql/1.6.0.1.sql +++ b/install-dev/upgrade/sql/1.6.0.1.sql @@ -69,6 +69,8 @@ ALTER TABLE `PREFIX_employee` ADD `stats_compare_from` DATE NULL DEFAULT NULL INSERT INTO `PREFIX_hook` (`id_hook` , `name` , `title` , `description` , `position` , `live_edit`) VALUES (NULL , 'displayHomeTab', 'Home Page Tabs', 'This hook displays new elements on the homepage tabs', '1', '1'), -(NULL , 'displayHomeTabContent', 'Home Page Tabs Content', 'This hook displays new elements on the homepage tabs content', '1', '1'); +(NULL , 'displayHomeTabContent', 'Home Page Tabs Content', 'This hook displays new elements on the homepage tabs content', '1', '1'), +(NULL , 'displayBackOfficeCategory', 'Display new elements in the Back Office, tab AdminCategories', 'This hook launches modules when the AdminCategories tab is displayed in the Back Office', '1', '1'), +(NULL , 'actionBackOfficeCategory', 'Process new elements in the Back Office, tab AdminCategories', 'This hook process modules when the AdminCategories tab is displayed in the Back Office', '1', '1'); ALTER TABLE `PREFIX_employee` ADD `stats_compare_option` INT( 1 ) NOT NULL DEFAULT '1' AFTER `stats_compare_to`; \ No newline at end of file diff --git a/modules/blockcategories/blockcategories.php b/modules/blockcategories/blockcategories.php index e4c212688..6304ecb28 100644 --- a/modules/blockcategories/blockcategories.php +++ b/modules/blockcategories/blockcategories.php @@ -33,7 +33,7 @@ class BlockCategories extends Module { $this->name = 'blockcategories'; $this->tab = 'front_office_features'; - $this->version = '2.0'; + $this->version = '2.1'; $this->author = 'PrestaShop'; parent::__construct(); @@ -54,6 +54,8 @@ class BlockCategories extends Module !$this->registerHook('categoryDeletion') || !$this->registerHook('actionAdminMetaControllerUpdate_optionsBefore') || !$this->registerHook('actionAdminLanguagesControllerStatusBefore') || + !$this->registerHook('displayBackOfficeCategory') || + !$this->registerHook('actionBackOfficeCategory') || !Configuration::updateValue('BLOCK_CATEG_MAX_DEPTH', 4) || !Configuration::updateValue('BLOCK_CATEG_DHTML', 1)) return false; @@ -113,6 +115,56 @@ class BlockCategories extends Module return $return; } + public function hookDisplayBackOfficeCategory($params) + { + $this->smarty->assign(array( + 'name' => 'thumb', + 'images' => array() + )); + + return $this->display(__FILE__, 'views/blockcategories_admin.tpl'); + } + + public function hookActionBackOfficeCategory($params) + { + $total_errors = array(); + + for ($i=0; $i<3; $i++) + if (isset($_FILES['thumb-'.$i]) && $_FILES['thumb-'.$i]['size'] > 0) + { + $errors = array(); + // Check image validity + $max_size = (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE'); + + if ($error = ImageManager::validateUpload($_FILES['thumb-'.$i], Tools::getMaxUploadSize($max_size))) + $errors[] = $error; + + $tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS'); + + if (!$tmp_name) + $errors[] = Tools::displayError('Invalid Temporary directory'); + + if (!move_uploaded_file($_FILES['thumb-'.$i]['tmp_name'], $tmp_name)) + $errors[] = Tools::displayError('Error uploading thumbnail image'); + + // Evaluate the memory required to resize the image: if it's too much, you can't resize it. + if (!ImageManager::checkImageMemoryLimit($tmp_name)) + $errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. '); + + // Copy new image + if (empty($errors) && !ImageManager::resize($tmp_name, _PS_CAT_IMG_DIR_.Tools::getValue('id_category').'-'.$i.'_thumb.jpg')) + $errors[] = Tools::displayError('An error occurred while uploading the image.'); + + if (count($errors)) + $total_errors = array_merge($total_errors, $errors); + + unlink($tmp_name); + } + + if (count($total_errors)) + ;//TODO : Show errors + } + public function hookLeftColumn($params) { if (!$this->isCached('blockcategories.tpl', $this->getCacheId())) diff --git a/modules/blockcategories/config.xml b/modules/blockcategories/config.xml index 5d3e12494..65a8cb054 100755 --- a/modules/blockcategories/config.xml +++ b/modules/blockcategories/config.xml @@ -1,9 +1,9 @@ blockcategories - - - + + + 1 diff --git a/modules/blockcategories/upgrade/install-2.1.php b/modules/blockcategories/upgrade/install-2.1.php new file mode 100644 index 000000000..ee2cddb04 --- /dev/null +++ b/modules/blockcategories/upgrade/install-2.1.php @@ -0,0 +1,9 @@ +registerHook('displayBackOfficeCategory') && $object->registerHook('actionBackOfficeCategory')); +} diff --git a/modules/blockcategories/views/blockcategories_admin.tpl b/modules/blockcategories/views/blockcategories_admin.tpl new file mode 100644 index 000000000..727d46539 --- /dev/null +++ b/modules/blockcategories/views/blockcategories_admin.tpl @@ -0,0 +1,44 @@ +{for $foo=0 to 2} +
+ +
+ + + + + +
+{if isset($images.$foo) && $images.$foo} +
 
+
+ {$images.$foo.image} + +
+{/if} +
+{/for} + +