diff --git a/admin-dev/themes/default/template/controllers/carrier_wizard/logo.tpl b/admin-dev/themes/default/template/controllers/carrier_wizard/logo.tpl new file mode 100644 index 000000000..7e397c572 --- /dev/null +++ b/admin-dev/themes/default/template/controllers/carrier_wizard/logo.tpl @@ -0,0 +1,57 @@ +{* +* 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 +*} + + +
+ +

+ + +

+

+ {l s='Format:'} JPG, GIF, PNG. {l s='Filesize:'} {$max_image_size|string_format:"%.2f"} {l s='MB max.'} +

+
\ No newline at end of file diff --git a/controllers/admin/AdminCarrierWizardController.php b/controllers/admin/AdminCarrierWizardController.php index ec0e926ac..87b66104d 100644 --- a/controllers/admin/AdminCarrierWizardController.php +++ b/controllers/admin/AdminCarrierWizardController.php @@ -97,7 +97,7 @@ class AdminCarrierWizardControllerCore extends AdminController $carrier = new Carrier(); $this->tpl_view_vars = array( - 'enableAllSteps' => (int)Validate::isLoadedObject($carrier), + 'enableAllSteps' => Validate::isLoadedObject($carrier), 'wizard_steps' => $this->wizard_steps, 'validate_url' => $this->context->link->getAdminLink('AdminCarrierWizard'), 'carrierlist_url' => $this->context->link->getAdminLink('AdminCarriers').'&conf='.((int)Validate::isLoadedObject($carrier) ? 4 : 3), @@ -113,6 +113,13 @@ class AdminCarrierWizardControllerCore extends AdminController if (Shop::isFeatureActive()) array_splice($this->tpl_view_vars['wizard_contents']['contents'], 1, 0, array(0 => $this->renderStepTwo($carrier))); + + $this->context->smarty->assign(array( + 'max_image_size' => (int)Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE') / 1024 / 1024, + 'carrier_logo' => (Validate::isLoadedObject($carrier) && file_exists(_PS_SHIP_IMG_DIR_.$carrier->id.'.jpg') ? _THEME_SHIP_DIR_.$carrier->id.'.jpg' : false) + )); + $this->content .= $this->createTemplate('logo.tpl')->fetch(); + $this->addjQueryPlugin(array('ajaxfileupload')); return parent::renderView(); } @@ -170,12 +177,6 @@ class AdminCarrierWizardControllerCore extends AdminController 'size' => 1, 'desc' => $this->l('Enter "0" for a longest shipping delay, or "9" for the shortest shipping delay.') ), - array( - 'type' => 'file', - 'label' => $this->l('Logo:'), - 'name' => 'logo', - 'desc' => $this->l('Upload a logo from your computer.').' (.gif, .jpg, .jpeg '.$this->l('or').' .png)' - ), array( 'type' => 'text', 'label' => $this->l('URL:'), @@ -443,7 +444,6 @@ class AdminCarrierWizardControllerCore extends AdminController 'name' => $this->getFieldValue($carrier, 'name'), 'delay' => $this->getFieldValue($carrier, 'delay'), 'grade' => $this->getFieldValue($carrier, 'grade'), - 'logo' => '', 'url' => $this->getFieldValue($carrier, 'url'), ); } @@ -539,6 +539,28 @@ class AdminCarrierWizardControllerCore extends AdminController } } + public function ajaxProcessUploadLogo() + { + $allowedExtensions = array('jpeg', 'gif', 'png', 'jpg'); + + $logo = (isset($_FILES['carrier_logo_input']) ? $_FILES['carrier_logo_input'] : false); + if ($logo && !empty($logo['tmp_name']) && $logo['tmp_name'] != 'none' + && (!isset($logo['error']) || !$logo['error']) + && preg_match('/\.(jpe?g|gif|png)$/', $logo['name']) + && is_uploaded_file($logo['tmp_name'])) + { + $file = $logo['tmp_name']; + do $tmp_name = uniqid().'.jpg'; + while (file_exists(_PS_TMP_IMG_DIR_.$tmp_name)); + if (!ImageManager::resize($file, _PS_TMP_IMG_DIR_.$tmp_name)) + die (''); + @unlink($file); + die (''); + } + else + die (''); + } + public function ajaxProcessFinishStep() { $return = array('has_error' => false); @@ -573,7 +595,7 @@ class AdminCarrierWizardControllerCore extends AdminController } } - if(Validate::isLoadedObject($carrier)) + if (Validate::isLoadedObject($carrier)) { if (!$this->changeGroups((int)$carrier->id)) { @@ -599,21 +621,20 @@ class AdminCarrierWizardControllerCore extends AdminController $return['errors'][] = $this->l('An error occurred while saving the tax rules group.'); } - if (!$this->postImage((int)$carrier->id)) + if (Tools::getValue('logo')) { - $return['has_error'] = true; - $return['errors'][] = $this->l('An error occurred while saving carrier logo.'); + $logo = basename(Tools::getValue('logo')); + if (!file_exists(_PS_TMP_IMG_DIR_.$logo) || !copy(_PS_TMP_IMG_DIR_.$logo, _PS_SHIP_IMG_DIR_.$carrier->id.'.jpg')) + { + $return['has_error'] = true; + $return['errors'][] = $this->l('An error occurred while saving carrier logo.'); + } } $return['id_carrier'] = $carrier->id; } die(Tools::jsonEncode($return)); } - - protected function updateCarrierAsso($id_carrier) - { - - } - + protected function changeGroups($id_carrier, $delete = true) { if ($delete) diff --git a/js/admin_carrier_wizard.js b/js/admin_carrier_wizard.js index 73f8d5039..8e1e6d7cc 100644 --- a/js/admin_carrier_wizard.js +++ b/js/admin_carrier_wizard.js @@ -50,6 +50,7 @@ function onShowStepCallback() $(this).parent('li').addClass($(this).attr('class')); }); resizeWizard(); + $('#carrier_logo_block').prependTo($('#fieldset_form')); } function onFinishCallback(obj, context) @@ -60,12 +61,11 @@ function onFinishCallback(obj, context) url : validate_url, async: false, dataType: 'json', - data : $('#carrier_wizard .stepContainer .content form').serialize()+'&action=finish_step&ajax=1', - success : function(datas) - { - if (datas.has_error) + data : $('#carrier_wizard .stepContainer .content form').serialize() + '&action=finish_step&ajax=1', + success : function(data) { + if (data.has_error) { - displayError(datas.errors, context.fromStep); + displayError(data.errors, context.fromStep); resizeWizard(); } else