diff --git a/admin-dev/themes/default/template/controllers/products/helpers/uploader/ajax.tpl b/admin-dev/themes/default/template/controllers/products/helpers/uploader/ajax.tpl new file mode 100644 index 000000000..4795b3f3f --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/uploader/ajax.tpl @@ -0,0 +1,180 @@ +{* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +
+
+ + + +
+
+ + + + \ No newline at end of file diff --git a/admin-dev/themes/default/template/controllers/products/helpers/uploader/index.php b/admin-dev/themes/default/template/controllers/products/helpers/uploader/index.php new file mode 100644 index 000000000..c9b153f1b --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/uploader/index.php @@ -0,0 +1,35 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../../../../../../../../'); +exit; \ No newline at end of file diff --git a/admin-dev/themes/default/template/controllers/products/images.tpl b/admin-dev/themes/default/template/controllers/products/images.tpl index caa7686c7..dc9458b16 100644 --- a/admin-dev/themes/default/template/controllers/products/images.tpl +++ b/admin-dev/themes/default/template/controllers/products/images.tpl @@ -35,40 +35,52 @@
- {l s='File:'} -
- -
-
- - - {if Tools::getValue('id_image')} - - {/if} + {$image_uploader}
-
- {foreach from=$languages item=language} -
- id}disabled="disabled"{/if} id="legend_{$language.id_lang}" name="legend_{$language.id_lang}" value="{$product->name[$language.id_lang]|escape:'htmlall':'UTF-8'}"/> -
{l s='Invalid characters:'} <>;=#{}
+ {foreach from=$languages item=language} + {if $languages|count > 1} +
+
+ {/if} + id}disabled="disabled"{/if} /> + {if $languages|count > 1} +
+
+ + +
- {/foreach} -
+ {/if} + {/foreach}
@@ -95,7 +107,7 @@ - image_id + legend legend @@ -129,6 +141,28 @@ var current_shop_id = {$current_shop_id|intval}; {literal} //Ready Function + + function imageLine(id, path, position, cover, shops, legend) + { + line = $("#lineType").html(); + line = line.replace(/image_id/g, id); + line = line.replace(/[a-z]{0,2}-default-small_default/g, path+'-small_default'); + line = line.replace(/image_path/g, path); + line = line.replace(/image_position/g, position); + line = line.replace(/legend/g, legend); + line = line.replace(/icon-check-empty/g, cover); + line = line.replace(//gi, ""); + line = line.replace(/<\/tbody>/gi, ""); + if (shops != false) + { + $.each(shops, function(key, value){ + if (value == 1) + line = line.replace('id="' + key + '' + id + '"','id="' + key + '' + id + '" checked=checked'); + }); + } + $("#imageList").append(line); + } + $(document).ready(function(){ {/literal} {foreach from=$images item=image} @@ -165,66 +199,6 @@ updateImagePosition(image_up); } }); - var filecheck = 1; - var params = new Array; - params['id_product'] = {/literal}{$id_product|intval}{literal}; - params['id_category'] = {/literal}{$id_category_default|intval}{literal}; - params['token'] = "{/literal}{$token}{literal}"; - params['tab'] = "AdminProducts"; - params['action'] = "addImage"; - params['ajax'] = 1; - uploader = new qq.FileUploader( - { - element: document.getElementById("file-uploader"), - action: "ajax-tab.php", - debug: false, - onComplete: function(id, fileName, responseJSON) - { - var percent = ((filecheck * 100) / nbfile); - $("#progressBarImage").progressbar({value: percent}); - if (percent != 100) - { - $("#imageUpload").html(parseInt(filecheck)); - $("#imageTotal").html(" / " + parseInt(nbfile) + " {/literal}{l s='Images'}{literal}"); - $("#progressBarImage").show(); - $("#showCounter").show(); - } - else - { - $("#progressBarImage").progressbar({value: 0}); - $("#progressBarImage").hide(); - $("#showCounter").hide(); - nbfile = 0; - filecheck = 0; - } - if (responseJSON.status == 'ok') - { - cover = "icon-check-empty"; - if (responseJSON.cover == "1") - cover = "icon-check-sign"; - imageLine(responseJSON.id, responseJSON.path, responseJSON.position, cover, responseJSON.shops, responseJSON.legend[{/literal}{$default_language|intval}{literal}]) - $("#imageTable tr:last").after(responseJSON.html); - $("#countImage").html(parseInt($("#countImage").html()) + 1); - $("#img" + id).remove(); - $("#imageTable").tableDnDUpdate(); - showSuccessMessage(responseJSON.name + " " + success_add); - } - else - showErrorMessage(responseJSON.error); - filecheck++; - }, - onSubmit: function(id, filename) - { - $('input[id^="legend_"]').each(function() - { - id = $(this).prop("id").replace("legend_", "legend[") + "]"; - params[id] = $(this).val(); - }); - uploader.setParams(params); - $("#imageTable").show(); - $("#listImage").append("
  • " + filename + "
  • "); - } - }); /** * on success function @@ -327,28 +301,11 @@ $("#img" + id).remove(); } - function imageLine(id, path, position, cover, shops, legend) - { - line = $("#lineType").html(); - line = line.replace(/image_id/g, legend); - line = line.replace(/[a-z]{0,2}-default-small_default/g, path+'-small_default'); - line = line.replace(/image_path/g, path); - line = line.replace(/image_position/g, position); - line = line.replace(/legend/g, legend); - line = line.replace(/icon-check-empty/g, cover); - line = line.replace(//gi, ""); - line = line.replace(/<\/tbody>/gi, ""); - if (shops != false) - { - $.each(shops, function(key, value){ - if (value == 1) - line = line.replace('id="' + key + '' + id + '"','id="' + key + '' + id + '" checked=checked'); - }); - } - $("#imageList").append(line); - } + $('.fancybox').fancybox(); }); + + hideOtherLanguage(default_language); {/literal} diff --git a/cache/class_index.php b/cache/class_index.php index 6eb35fa3f..aaa444638 100644 --- a/cache/class_index.php +++ b/cache/class_index.php @@ -366,6 +366,8 @@ 'HelperFormCore' => 'classes/helper/HelperForm.php', 'HelperHelpAccess' => '', 'HelperHelpAccessCore' => 'classes/helper/HelperHelpAccess.php', + 'HelperImageUploader' => '', + 'HelperImageUploaderCore' => 'classes/helper/HelperImageUploader.php', 'HelperKpi' => '', 'HelperKpiCore' => 'classes/helper/HelperKpi.php', 'HelperKpiRow' => '', diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 3c5bdae86..2b299146a 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -1331,42 +1331,6 @@ class AdminProductsControllerCore extends AdminController } } - /* @todo rename to processaddproductimage */ - public function ajaxProcessAddImage() - { - self::$currentIndex = 'index.php?tab=AdminProducts'; - $allowedExtensions = array('jpeg', 'gif', 'png', 'jpg'); - // max file size in bytes - $uploader = new FileUploader($allowedExtensions, $this->max_image_size); - $result = $uploader->handleUpload(); - if (isset($result['success'])) - { - $obj = new Image((int)$result['success']['id_image']); - // Associate image to shop from context - $shops = Shop::getContextListShopID(); - $obj->associateTo($shops); - $json_shops = array(); - foreach ($shops as $id_shop) - $json_shops[$id_shop] = true; - - $json = array( - 'name' => $result['success']['name'], - 'status' => 'ok', - 'id'=>$obj->id, - 'path' => $obj->getExistingImgPath(), - 'position' => $obj->position, - 'legend' => $obj->legend, - 'cover' => $obj->cover, - 'shops' => $json_shops, - ); - @unlink(_PS_TMP_IMG_DIR_.'product_'.(int)$obj->id_product.'.jpg'); - @unlink(_PS_TMP_IMG_DIR_.'product_mini_'.(int)$obj->id_product.'_'.$this->context->shop->id.'.jpg'); - die(Tools::jsonEncode($json)); - } - else - die(Tools::jsonEncode($result)); - } - public function ajaxProcessDeleteProductAttribute() { if (!Combination::isFeatureActive()) @@ -3650,6 +3614,108 @@ class AdminProductsControllerCore extends AdminController } } + public function ajaxProcessaddProductImage() + { + self::$currentIndex = 'index.php?tab=AdminProducts'; + $product = new Product((int)Tools::getValue('id_product')); + $legends = Tools::getValue('legend'); + + if (!is_array($legends)) + $legends = (array)$legends; + + if (!Validate::isLoadedObject($product)) + { + $files = array(); + $files[0]['error'] = Tools::displayError('Cannot add image because product creation failed.'); + } + + $image_uploader = new HelperImageUploader('file'); + $image_uploader->setAcceptTypes(array('jpeg', 'gif', 'png', 'jpg'))->setMaxSize($this->max_image_size); + $files = $image_uploader->process(); + + foreach ($files as &$file) + { + $image = new Image(); + $image->id_product = (int)($product->id); + $image->position = Image::getHighestPosition($product->id) + 1; + + foreach ($legends as $key => $legend) + if (!empty($legend)) + $image->legend[(int)$key] = $legend; + + if (!Image::getCover($image->id_product)) + $image->cover = 1; + else + $image->cover = 0; + + if (!$image->add()) + $file['error'] = Tools::displayError('Error while creating additional image'); + else + { + if (!$new_path = $image->getPathForCreation()) + { + $file['error'] = Tools::displayError('An error occurred during new folder creation'); + continue; + } + + if (!ImageManager::resize($file['save_path'], $new_path.'.'.$image->image_format)) + { + $file['error'] = Tools::displayError('An error occurred while copying image.'); + continue; + } + else + { + $imagesTypes = ImageType::getImagesTypes('products'); + foreach ($imagesTypes as $imageType) + { + /* + $theme = (Shop::isFeatureActive() ? '-'.$imageType['id_theme'] : ''); + if (!ImageManager::resize($tmpName, $new_path.'-'.stripslashes($imageType['name']).$theme.'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) + return array('error' => Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name'])); + */ + if (!ImageManager::resize($file['save_path'], $new_path.'-'.stripslashes($imageType['name']).'.'.$image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) + { + $file['error'] = Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']); + continue; + } + } + } + + unlink($file['save_path']); + //Necesary to prevent hacking + unset($file['save_path']); + Hook::exec('actionWatermark', array('id_image' => $image->id, 'id_product' => $product->id)); + + if (!$image->update()) + { + $file['error'] = Tools::displayError('Error while updating status'); + continue; + } + + // Associate image to shop from context + $shops = Shop::getContextListShopID(); + $image->associateTo($shops); + $json_shops = array(); + + foreach ($shops as $id_shop) + $json_shops[$id_shop] = true; + + $file['status'] = 'ok'; + $file['id'] = $image->id; + $file['position'] = $image->position; + $file['cover'] = $image->cover; + $file['legend'] = $image->legend; + $file['path'] = $image->getExistingImgPath(); + $file['shops'] = $json_shops; + + @unlink(_PS_TMP_IMG_DIR_.'product_'.(int)$product->id.'.jpg'); + @unlink(_PS_TMP_IMG_DIR_.'product_mini_'.(int)$product->id.'_'.$this->context->shop->id.'.jpg'); + } + } + + die(Tools::jsonEncode(array($image_uploader->getName() => $files))); + } + public function initFormImages($obj) { $data = $this->createTemplate($this->tpl_form); @@ -3688,6 +3754,10 @@ class AdminProductsControllerCore extends AdminController $current_shop_id = 0; $languages = Language::getLanguages(true); + $image_uploader = new HelperImageUploader('file'); + $image_uploader->setMultiple(true)->setUseAjax(true)->setUrl( + Context::getContext()->link->getAdminLink('AdminProducts').'&ajax=1&id_product='.(int)$obj->id + .'&action=addProductImage'); $data->assign(array( 'countImages' => $count_images, @@ -3702,7 +3772,8 @@ class AdminProductsControllerCore extends AdminController 'currency' => $this->context->currency, 'current_shop_id' => $current_shop_id, 'languages' => $this->_languages, - 'default_language' => (int)Configuration::get('PS_LANG_DEFAULT') + 'default_language' => (int)Configuration::get('PS_LANG_DEFAULT'), + 'image_uploader' => $image_uploader->render() )); $type = ImageType::getByNameNType('%', 'products', 'height');