public function postProcess()
 {
     if (!$this->can_add_customer && $this->display == 'add') {
         $this->redirect_after = $this->context->link->getAdminLink('AdminCustomers');
     }
     parent::postProcess();
 }
 public function postProcess()
 {
     if (Tools::isSubmit('submitLocalizationPack')) {
         $version = str_replace('.', '', _PS_VERSION_);
         $version = substr($version, 0, 2);
         if (Validate::isFileName(Tools::getValue('iso_localization_pack'))) {
             $pack = @Tools::file_get_contents('http://api.prestashop.com/localization/' . $version . '/' . Tools::getValue('iso_localization_pack') . '.xml');
             if (!$pack && !($pack = @Tools::file_get_contents(dirname(__FILE__) . '/../../localization/' . Tools::getValue('iso_localization_pack') . '.xml'))) {
                 $this->errors[] = Tools::displayError('Cannot load the localization pack.');
             }
             if (!($selection = Tools::getValue('selection'))) {
                 $this->errors[] = Tools::displayError('Please select at least one item to import.');
             } else {
                 foreach ($selection as $selected) {
                     if (!Validate::isLocalizationPackSelection($selected)) {
                         $this->errors[] = Tools::displayError('Invalid selection');
                         return;
                     }
                 }
                 $localization_pack = new LocalizationPack();
                 if (!$localization_pack->loadLocalisationPack($pack, $selection)) {
                     $this->errors = array_merge($this->errors, $localization_pack->getErrors());
                 } else {
                     Tools::redirectAdmin(self::$currentIndex . '&conf=23&token=' . $this->token);
                 }
             }
         }
     }
     // Remove the module list cache if the default country changed
     if (Tools::isSubmit('submitOptionsconfiguration') && file_exists(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST)) {
         @unlink(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST);
     }
     parent::postProcess();
 }
 public function postProcess()
 {
     if (Tools::isSubmit('submitLocalizationPack')) {
         $version = str_replace('.', '', _PS_VERSION_);
         $version = substr($version, 0, 2);
         if (Validate::isFileName(Tools::getValue('iso_localization_pack'))) {
             $pack = @Tools::file_get_contents('http://api.prestashop.com/localization/' . $version . '/' . Tools::getValue('iso_localization_pack') . '.xml');
             if (!$pack && !($pack = @Tools::file_get_contents(dirname(__FILE__) . '/../../localization/' . Tools::getValue('iso_localization_pack') . '.xml'))) {
                 $this->errors[] = Tools::displayError('Cannot load localization pack (from prestashop.com and from your local folder "localization")');
             }
             if (!($selection = Tools::getValue('selection'))) {
                 $this->errors[] = Tools::displayError('Please select at least one item to import.');
             } else {
                 foreach ($selection as $selected) {
                     if (!Validate::isLocalizationPackSelection($selected)) {
                         $this->errors[] = Tools::displayError('Invalid selection');
                         return;
                     }
                 }
                 $localization_pack = new LocalizationPack();
                 if (!$localization_pack->loadLocalisationPack($pack, $selection)) {
                     $this->errors = array_merge($this->errors, $localization_pack->getErrors());
                 } else {
                     Tools::redirectAdmin(self::$currentIndex . '&conf=23&token=' . $this->token);
                 }
             }
         }
     }
     parent::postProcess();
 }
Ejemplo n.º 4
0
 public function postProcess()
 {
     /* PrestaShop demo mode */
     if (_PS_MODE_DEMO_) {
         $this->errors[] = Tools::displayError('This functionality has been disabled.');
         return;
     }
     return parent::postProcess();
 }
Ejemplo n.º 5
0
 public function postProcess()
 {
     if ($this->tabAccess['edit'] === '1' && Tools::getValue('submitAdd' . $this->table)) {
         if (($id = (int) Tools::getValue($this->identifier)) && ($obj = new $this->className($id)) && Validate::isLoadedObject($obj)) {
             $obj->setProducts($_POST['products']);
         }
     }
     return parent::postProcess();
 }
Ejemplo n.º 6
0
 public function postProcess()
 {
     /* PrestaShop demo mode */
     if (_PS_MODE_DEMO_) {
         $this->errors[] = Tools::displayError('This functionality has been disabled.');
         return;
     }
     /* PrestaShop demo mode*/
     if (isset($_GET['delete' . $this->table]) && $_GET[$this->identifier] == (int) _PS_ADMIN_PROFILE_) {
         $this->errors[] = $this->l('For security reasons, you cannot delete the Administrator\'s profile.');
     } else {
         parent::postProcess();
     }
 }
 public function postProcess()
 {
     if (_PS_MODE_DEMO_) {
         $this->errors[] = $this->trans('This functionality has been disabled.', array(), 'Admin.Notifications.Error');
         return;
     }
     if (!extension_loaded('openssl')) {
         $this->displayWarning($this->l('Importing a new language may fail without the OpenSSL module. Please enable "openssl.so" on your server configuration.'));
     }
     if (Tools::isSubmit('submitLocalizationPack')) {
         $version = str_replace('.', '', _PS_VERSION_);
         $version = substr($version, 0, 2);
         if (($iso_localization_pack = Tools::getValue('iso_localization_pack')) && Validate::isFileName($iso_localization_pack)) {
             if (Tools::getValue('download_updated_pack') == '1' || defined('_PS_HOST_MODE_')) {
                 $pack = @Tools::file_get_contents(_PS_API_URL_ . '/localization/' . $version . '/' . $iso_localization_pack . '.xml');
             } else {
                 $pack = false;
             }
             if (defined('_PS_HOST_MODE_')) {
                 $path = _PS_CORE_DIR_ . '/localization/' . $iso_localization_pack . '.xml';
             } else {
                 $path = _PS_ROOT_DIR_ . '/localization/' . $iso_localization_pack . '.xml';
             }
             if (!$pack && !($pack = @Tools::file_get_contents($path))) {
                 $this->errors[] = $this->trans('Cannot load the localization pack.', array(), 'Admin.International.Notification');
             }
             if (!($selection = Tools::getValue('selection'))) {
                 $this->errors[] = $this->trans('Please select at least one item to import.', array(), 'Admin.International.Notification');
             } else {
                 foreach ($selection as $selected) {
                     if (!Validate::isLocalizationPackSelection($selected)) {
                         $this->errors[] = $this->trans('Invalid selection', array(), 'Admin.Notifications.Error');
                         return;
                     }
                 }
                 $localization_pack = new LocalizationPack();
                 if (!$localization_pack->loadLocalisationPack($pack, $selection, false, $iso_localization_pack)) {
                     $this->errors = array_merge($this->errors, $localization_pack->getErrors());
                 } else {
                     Tools::redirectAdmin(self::$currentIndex . '&conf=23&token=' . $this->token);
                 }
             }
         }
     }
     // Remove the module list cache if the default country changed
     if (Tools::isSubmit('submitOptionsconfiguration') && file_exists(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST)) {
         @unlink(Module::CACHE_FILE_DEFAULT_COUNTRY_MODULES_LIST);
     }
     parent::postProcess();
 }
Ejemplo n.º 8
0
 public function postProcess()
 {
     /* Shipping fees */
     if (Tools::isSubmit('submitFees' . $this->table)) {
         if ($this->tabAccess['edit'] === '1') {
             if (($id_carrier = (int) Tools::getValue('id_carrier')) && $id_carrier == ($id_carrier2 = (int) Tools::getValue('id_carrier2'))) {
                 $carrier = new Carrier($id_carrier);
                 if (Validate::isLoadedObject($carrier)) {
                     /* Get configuration values */
                     $shipping_method = $carrier->getShippingMethod();
                     $rangeTable = $carrier->getRangeTable();
                     $carrier->deleteDeliveryPrice($rangeTable);
                     $currentList = Carrier::getDeliveryPriceByRanges($rangeTable, $id_carrier);
                     /* Build prices list */
                     $priceList = array();
                     foreach ($_POST as $key => $value) {
                         if (strstr($key, 'fees_')) {
                             $tmpArray = explode('_', $key);
                             $price = number_format(abs(str_replace(',', '.', $value)), 6, '.', '');
                             $current = 0;
                             foreach ($currentList as $item) {
                                 if ($item['id_zone'] == $tmpArray[1] && $item['id_' . $rangeTable] == $tmpArray[2]) {
                                     $current = $item;
                                 }
                             }
                             if ($current && $price == $current['price']) {
                                 continue;
                             }
                             $priceList[] = array('id_range_price' => $shipping_method == Carrier::SHIPPING_METHOD_PRICE ? (int) $tmpArray[2] : null, 'id_range_weight' => $shipping_method == Carrier::SHIPPING_METHOD_WEIGHT ? (int) $tmpArray[2] : null, 'id_carrier' => (int) $carrier->id, 'id_zone' => (int) $tmpArray[1], 'price' => $price);
                         }
                     }
                     /* Update delivery prices */
                     $carrier->addDeliveryPrice($priceList);
                     Tools::redirectAdmin(self::$currentIndex . '&conf=6&id_carrier=' . $carrier->id . '&token=' . $this->token);
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while attempting to update fees (cannot load carrier object).');
                 }
             } elseif (isset($id_carrier2)) {
                 $_POST['id_carrier'] = $id_carrier2;
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while attempting to update fees (cannot load carrier object).');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } else {
         return parent::postProcess();
     }
 }
Ejemplo n.º 9
0
 public function postProcess()
 {
     $id = (int) Tools::getValue('id_' . $this->table);
     if (Tools::getValue('submitAdd' . $this->table)) {
         if (Tools::getValue('delimiter1') >= Tools::getValue('delimiter2')) {
             $this->errors[] = Tools::displayError('Invalid range');
         } elseif (!$id && RangeWeight::rangeExist((int) Tools::getValue('id_carrier'), (double) Tools::getValue('delimiter1'), (double) Tools::getValue('delimiter2'))) {
             $this->errors[] = Tools::displayError('The range already exists');
         } elseif (RangeWeight::isOverlapping((int) Tools::getValue('id_carrier'), (double) Tools::getValue('delimiter1'), (double) Tools::getValue('delimiter2'), $id ? (int) $id : null)) {
             $this->errors[] = Tools::displayError('Error: Ranges are overlapping');
         } elseif (!count($this->errors)) {
             parent::postProcess();
         }
     } else {
         parent::postProcess();
     }
 }
 public function postProcess()
 {
     $upload_max_size = (int) str_replace('M', '', ini_get('upload_max_filesize'));
     $post_max_size = (int) str_replace('M', '', ini_get('post_max_size'));
     $max_size = $upload_max_size < $post_max_size ? $upload_max_size : $post_max_size;
     if (Tools::getValue('PS_LIMIT_UPLOAD_FILE_VALUE') > $max_size || Tools::getValue('PS_LIMIT_UPLOAD_IMAGE_VALUE') > $max_size) {
         $this->errors[] = Tools::displayError('The limit chosen is larger than the server\'s maximum upload limit. Please increase the limits of your server.');
         return;
     }
     if (Tools::getIsset('PS_LIMIT_UPLOAD_FILE_VALUE') && !Tools::getValue('PS_LIMIT_UPLOAD_FILE_VALUE')) {
         $_POST['PS_LIMIT_UPLOAD_FILE_VALUE'] = 1;
     }
     if (Tools::getIsset('PS_LIMIT_UPLOAD_IMAGE_VALUE') && !Tools::getValue('PS_LIMIT_UPLOAD_IMAGE_VALUE')) {
         $_POST['PS_LIMIT_UPLOAD_IMAGE_VALUE'] = 1;
     }
     parent::postProcess();
 }
Ejemplo n.º 11
0
 public function postProcess()
 {
     if ($this->tabAccess['edit'] === '1' && Tools::getValue('submitAdd' . $this->table)) {
         if (($id = (int) Tools::getValue($this->identifier)) && ($obj = new $this->className($id)) && Validate::isLoadedObject($obj)) {
             $previousProducts = $obj->getProducts();
             $removedProducts = array();
             foreach ($previousProducts as $product) {
                 if (!in_array($product['id_product'], $_POST['products'])) {
                     $removedProducts[] = $product['id_product'];
                 }
             }
             if (Configuration::get('PS_SEARCH_INDEXATION')) {
                 Search::removeProductsSearchIndex($removedProducts);
             }
             $obj->setProducts($_POST['products']);
         }
     }
     return parent::postProcess();
 }
 public function postProcess()
 {
     if (Tools::isSubmit('submitAdddelivery')) {
         if (!Validate::isDate(Tools::getValue('date_from'))) {
             $this->errors[] = Tools::displayError('Invalid \'from\' date');
         }
         if (!Validate::isDate(Tools::getValue('date_to'))) {
             $this->errors[] = Tools::displayError('Invalid \'to\' date');
         }
         if (!count($this->errors)) {
             if (count(OrderInvoice::getByDeliveryDateInterval(Tools::getValue('date_from'), Tools::getValue('date_to')))) {
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf') . '&submitAction=generateDeliverySlipsPDF&date_from=' . urlencode(Tools::getValue('date_from')) . '&date_to=' . urlencode(Tools::getValue('date_to')));
             } else {
                 $this->errors[] = Tools::displayError('No delivery slip was found for this period.');
             }
         }
     } else {
         parent::postProcess();
     }
 }
Ejemplo n.º 13
0
 public function postProcess()
 {
     if (Tools::getValue('submitAddorder_slip')) {
         if (!Validate::isDate(Tools::getValue('date_from'))) {
             $this->errors[] = $this->l('Invalid "From" date');
         }
         if (!Validate::isDate(Tools::getValue('date_to'))) {
             $this->errors[] = $this->l('Invalid "To" date');
         }
         if (!count($this->errors)) {
             $order_slips = OrderSlip::getSlipsIdByDate(Tools::getValue('date_from'), Tools::getValue('date_to'));
             if (count($order_slips)) {
                 Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf') . '&submitAction=generateOrderSlipsPDF&date_from=' . urlencode(Tools::getValue('date_from')) . '&date_to=' . urlencode(Tools::getValue('date_to')));
             }
             $this->errors[] = $this->l('No order slips were found for this period.');
         }
     } else {
         return parent::postProcess();
     }
 }
Ejemplo n.º 14
0
 public function postProcess()
 {
     // When moving images, if duplicate images were found they are moved to a folder named duplicates/
     if (file_exists(_PS_PROD_IMG_DIR_ . 'duplicates/')) {
         $this->warnings[] = $this->l('Duplicate images were found when moving the product images. This is likely caused by unused demonstration images. Please make sure that the folder ') . _PS_PROD_IMG_DIR_ . 'duplicates/' . $this->l('only contains demonstration images, and then delete this folder.');
     }
     if (Tools::getValue('submitRegenerate' . $this->table)) {
         if ($this->tabAccess['edit'] === '1') {
             if ($this->_regenerateThumbnails(Tools::getValue('type'), Tools::getValue('erase'))) {
                 Tools::redirectAdmin(self::$currentIndex . '&conf=9' . '&token=' . $this->token);
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } elseif (Tools::getValue('submitMoveImages' . $this->table)) {
         if ($this->tabAccess['edit'] === '1') {
             if ($this->_moveImagesToNewFileSystem()) {
                 Tools::redirectAdmin(self::$currentIndex . '&conf=25' . '&token=' . $this->token);
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } elseif (Tools::getValue('submitImagePreferences')) {
         if ($this->tabAccess['edit'] === '1') {
             if ((int) Tools::getValue('PS_JPEG_QUALITY') < 0 || (int) Tools::getValue('PS_JPEG_QUALITY') > 100) {
                 $this->errors[] = Tools::displayError('Incorrect value for JPEG image quality.');
             } elseif ((int) Tools::getValue('PS_PNG_QUALITY') < 0 || (int) Tools::getValue('PS_PNG_QUALITY') > 9) {
                 $this->errors[] = Tools::displayError('Incorrect value for PNG image quality.');
             } elseif (!Configuration::updateValue('PS_IMAGE_QUALITY', Tools::getValue('PS_IMAGE_QUALITY')) || !Configuration::updateValue('PS_JPEG_QUALITY', Tools::getValue('PS_JPEG_QUALITY')) || !Configuration::updateValue('PS_PNG_QUALITY', Tools::getValue('PS_PNG_QUALITY'))) {
                 $this->errors[] = Tools::displayError('Unknown error.');
             } else {
                 return parent::postProcess();
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit here.');
         }
     } else {
         return parent::postProcess();
     }
 }
 public function postProcess()
 {
     if (Tools::isSubmit('submitAddcart_rule') || Tools::isSubmit('submitAddcart_ruleAndStay')) {
         // If the reduction is associated to a specific product, then it must be part of the product restrictions
         if ((int) Tools::getValue('reduction_product') && Tools::getValue('apply_discount_to') == 'specific' && Tools::getValue('apply_discount') != 'off') {
             $reduction_product = (int) Tools::getValue('reduction_product');
             // First, check if it is not already part of the restrictions
             $already_restricted = false;
             if (is_array($rule_group_array = Tools::getValue('product_rule_group')) && count($rule_group_array) && Tools::getValue('product_restriction')) {
                 foreach ($rule_group_array as $rule_group_id) {
                     if (is_array($rule_array = Tools::getValue('product_rule_' . $rule_group_id)) && count($rule_array)) {
                         foreach ($rule_array as $rule_id) {
                             if (Tools::getValue('product_rule_' . $rule_group_id . '_' . $rule_id . '_type') == 'products' && in_array($reduction_product, Tools::getValue('product_rule_select_' . $rule_group_id . '_' . $rule_id))) {
                                 $already_restricted = true;
                                 break 2;
                             }
                         }
                     }
                 }
             }
             if ($already_restricted == false) {
                 // Check the product restriction
                 $_POST['product_restriction'] = 1;
                 // Add a new rule group
                 $rule_group_id = 1;
                 if (is_array($rule_group_array)) {
                     // Empty for (with a ; at the end), that just find the first rule_group_id available in rule_group_array
                     for ($rule_group_id = 1; in_array($rule_group_id, $rule_group_array); ++$rule_group_id) {
                         42;
                     }
                     $_POST['product_rule_group'][] = $rule_group_id;
                 } else {
                     $_POST['product_rule_group'] = array($rule_group_id);
                 }
                 // Set a quantity of 1 for this new rule group
                 $_POST['product_rule_group_' . $rule_group_id . '_quantity'] = 1;
                 // Add one rule to the new rule group
                 $_POST['product_rule_' . $rule_group_id] = array(1);
                 // Set a type 'product' for this 1 rule
                 $_POST['product_rule_' . $rule_group_id . '_1_type'] = 'products';
                 // Add the product in the selected products
                 $_POST['product_rule_select_' . $rule_group_id . '_1'] = array($reduction_product);
             }
         }
         // These are checkboxes (which aren't sent through POST when they are not check), so they are forced to 0
         foreach (array('country', 'carrier', 'group', 'cart_rule', 'product', 'shop') as $type) {
             if (!Tools::getValue($type . '_restriction')) {
                 $_POST[$type . '_restriction'] = 0;
             }
         }
         // Remove the gift if the radio button is set to "no"
         if (!(int) Tools::getValue('free_gift')) {
             $_POST['gift_product'] = 0;
         }
         // Retrieve the product attribute id of the gift (if available)
         if ($id_product = (int) Tools::getValue('gift_product')) {
             $_POST['gift_product_attribute'] = (int) Tools::getValue('ipa_' . $id_product);
         }
         // Idiot-proof control
         if (strtotime(Tools::getValue('date_from')) > strtotime(Tools::getValue('date_to'))) {
             $this->errors[] = Tools::displayError('The voucher cannot end before it begins.');
         }
         if ((int) Tools::getValue('minimum_amount') < 0) {
             $this->errors[] = Tools::displayError('The minimum amount cannot be lower than zero.');
         }
         if ((double) Tools::getValue('reduction_percent') < 0 || (double) Tools::getValue('reduction_percent') > 100) {
             $this->errors[] = Tools::displayError('Reduction percent must be between 0% and 100%');
         }
         if ((int) Tools::getValue('reduction_amount') < 0) {
             $this->errors[] = Tools::displayError('Reduction amount cannot be lower than zero.');
         }
         if (Tools::getValue('code') && ($same_code = (int) CartRule::getIdByCode(Tools::getValue('code'))) && $same_code != Tools::getValue('id_cart_rule')) {
             $this->errors[] = sprintf(Tools::displayError('This cart rule code is already used (conflict with cart rule %d)'), $same_code);
         }
         if (Tools::getValue('apply_discount') == 'off' && !Tools::getValue('free_shipping') && !Tools::getValue('free_gift')) {
             $this->errors[] = Tools::displayError('An action is required for this cart rule.');
         }
     }
     return parent::postProcess();
 }
 public function postProcess()
 {
     if (!Tools::getValue('id_' . $this->table)) {
         if (Validate::isLanguageIsoCode(Tools::getValue('iso_code')) && Country::getByIso(Tools::getValue('iso_code'))) {
             $this->errors[] = Tools::displayError('This ISO code already exists.You cannot create two countries with the same ISO code.');
         }
     } else {
         if (Validate::isLanguageIsoCode(Tools::getValue('iso_code'))) {
             $id_country = Country::getByIso(Tools::getValue('iso_code'));
             if (!is_null($id_country) && $id_country != Tools::getValue('id_' . $this->table)) {
                 $this->errors[] = Tools::displayError('This ISO code already exists.You cannot create two countries with the same ISO code.');
             }
         }
     }
     return parent::postProcess();
 }
    public function postProcess()
    {
        if ($id_customer_thread = (int) Tools::getValue('id_customer_thread')) {
            if ($id_contact = (int) Tools::getValue('id_contact')) {
                Db::getInstance()->execute('
					UPDATE ' . _DB_PREFIX_ . 'customer_thread
					SET id_contact = ' . (int) $id_contact . '
					WHERE id_customer_thread = ' . (int) $id_customer_thread);
            }
            if ($id_status = (int) Tools::getValue('setstatus')) {
                $status_array = array(1 => 'open', 2 => 'closed', 3 => 'pending1', 4 => 'pending2');
                Db::getInstance()->execute('
					UPDATE ' . _DB_PREFIX_ . 'customer_thread
					SET status = "' . $status_array[$id_status] . '"
					WHERE id_customer_thread = ' . (int) $id_customer_thread . ' LIMIT 1
				');
            }
            if (isset($_POST['id_employee_forward'])) {
                $messages = Db::getInstance()->getRow('
					SELECT ct.*, cm.*, cl.name subject, CONCAT(e.firstname, \' \', e.lastname) employee_name,
						CONCAT(c.firstname, \' \', c.lastname) customer_name, c.firstname
					FROM ' . _DB_PREFIX_ . 'customer_thread ct
					LEFT JOIN ' . _DB_PREFIX_ . 'customer_message cm
						ON (ct.id_customer_thread = cm.id_customer_thread)
					LEFT JOIN ' . _DB_PREFIX_ . 'contact_lang cl
						ON (cl.id_contact = ct.id_contact AND cl.id_lang = ' . (int) $this->context->language->id . ')
					LEFT OUTER JOIN ' . _DB_PREFIX_ . 'employee e
						ON e.id_employee = cm.id_employee
					LEFT OUTER JOIN ' . _DB_PREFIX_ . 'customer c
						ON (c.email = ct.email)
					WHERE ct.id_customer_thread = ' . (int) Tools::getValue('id_customer_thread') . '
					ORDER BY cm.date_add DESC
				');
                $output = $this->displayMessage($messages, true, (int) Tools::getValue('id_employee_forward'));
                $cm = new CustomerMessage();
                $cm->id_employee = (int) $this->context->employee->id;
                $cm->id_customer_thread = (int) Tools::getValue('id_customer_thread');
                $cm->ip_address = (int) ip2long(Tools::getRemoteAddr());
                $current_employee = $this->context->employee;
                $id_employee = (int) Tools::getValue('id_employee_forward');
                $employee = new Employee($id_employee);
                $email = Tools::getValue('email');
                $message = Tools::getValue('message_forward');
                if (($error = $cm->validateField('message', $message, null, array(), true)) !== true) {
                    $this->errors[] = $error;
                } elseif ($id_employee && $employee && Validate::isLoadedObject($employee)) {
                    $params = array('{messages}' => stripslashes($output), '{employee}' => $current_employee->firstname . ' ' . $current_employee->lastname, '{comment}' => stripslashes(Tools::nl2br($_POST['message_forward'])), '{firstname}' => $employee->firstname, '{lastname}' => $employee->lastname);
                    if (Mail::Send($this->context->language->id, 'forward_msg', Mail::l('Fwd: Customer message', $this->context->language->id), $params, $employee->email, $employee->firstname . ' ' . $employee->lastname, $current_employee->email, $current_employee->firstname . ' ' . $current_employee->lastname, null, null, _PS_MAIL_DIR_, true)) {
                        $cm->private = 1;
                        $cm->message = $this->l('Message forwarded to') . ' ' . $employee->firstname . ' ' . $employee->lastname . "\n" . $this->l('Comment:') . ' ' . $message;
                        $cm->add();
                    }
                } elseif ($email && Validate::isEmail($email)) {
                    $params = array('{messages}' => Tools::nl2br(stripslashes($output)), '{employee}' => $current_employee->firstname . ' ' . $current_employee->lastname, '{comment}' => stripslashes($_POST['message_forward']));
                    if (Mail::Send($this->context->language->id, 'forward_msg', Mail::l('Fwd: Customer message', $this->context->language->id), $params, $email, null, $current_employee->email, $current_employee->firstname . ' ' . $current_employee->lastname, null, null, _PS_MAIL_DIR_, true)) {
                        $cm->message = $this->l('Message forwarded to') . ' ' . $email . "\n" . $this->l('Comment:') . ' ' . $message;
                        $cm->add();
                    }
                } else {
                    $this->errors[] = '<div class="alert error">' . Tools::displayError('The email address is invalid.') . '</div>';
                }
            }
            if (Tools::isSubmit('submitReply')) {
                $ct = new CustomerThread($id_customer_thread);
                ShopUrl::cacheMainDomainForShop((int) $ct->id_shop);
                $cm = new CustomerMessage();
                $cm->id_employee = (int) $this->context->employee->id;
                $cm->id_customer_thread = $ct->id;
                $cm->ip_address = (int) ip2long(Tools::getRemoteAddr());
                $cm->message = Tools::getValue('reply_message');
                if (($error = $cm->validateField('message', $cm->message, null, array(), true)) !== true) {
                    $this->errors[] = $error;
                } elseif (isset($_FILES) && !empty($_FILES['joinFile']['name']) && $_FILES['joinFile']['error'] != 0) {
                    $this->errors[] = Tools::displayError('An error occurred during the file upload process.');
                } elseif ($cm->add()) {
                    $file_attachment = null;
                    if (!empty($_FILES['joinFile']['name'])) {
                        $file_attachment['content'] = file_get_contents($_FILES['joinFile']['tmp_name']);
                        $file_attachment['name'] = $_FILES['joinFile']['name'];
                        $file_attachment['mime'] = $_FILES['joinFile']['type'];
                    }
                    $customer = new Customer($ct->id_customer);
                    $params = array('{reply}' => Tools::nl2br(Tools::getValue('reply_message')), '{link}' => Tools::url($this->context->link->getPageLink('contact', true), 'id_customer_thread=' . (int) $ct->id . '&token=' . $ct->token), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname);
                    //#ct == id_customer_thread    #tc == token of thread   <== used in the synchronization imap
                    $contact = new Contact((int) $ct->id_contact, (int) $ct->id_lang);
                    if (Validate::isLoadedObject($contact)) {
                        $from_name = $contact->name;
                        $from_email = $contact->email;
                    } else {
                        $from_name = null;
                        $from_email = null;
                    }
                    if (Mail::Send((int) $ct->id_lang, 'reply_msg', sprintf(Mail::l('An answer to your message is available #ct%1$s #tc%2$s', $ct->id_lang), $ct->id, $ct->token), $params, Tools::getValue('msg_email'), null, $from_email, $from_name, $file_attachment, null, _PS_MAIL_DIR_, true)) {
                        $ct->status = 'closed';
                        $ct->update();
                    }
                    Tools::redirectAdmin(self::$currentIndex . '&id_customer_thread=' . (int) $id_customer_thread . '&viewcustomer_thread&token=' . Tools::getValue('token'));
                } else {
                    $this->errors[] = Tools::displayError('An error occurred. Your message was not sent. Please contact your system administrator.');
                }
            }
        }
        return parent::postProcess();
    }
 public function postProcess()
 {
     if (!in_array($this->display, array('edit', 'add'))) {
         $this->multishop_context_group = false;
     }
     if (Tools::isSubmit('forcedeleteImage') || isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
         $this->processForceDeleteImage();
         if (Tools::isSubmit('forcedeleteImage')) {
             Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminCategories') . '&conf=7');
         }
     }
     return parent::postProcess();
 }
Ejemplo n.º 19
0
 public function postProcess()
 {
     // If id_order is sent, we instanciate a new Order object
     if (Tools::isSubmit('id_order') && Tools::getValue('id_order') > 0) {
         $order = new Order(Tools::getValue('id_order'));
         if (!Validate::isLoadedObject($order)) {
             $this->errors[] = Tools::displayError('The order cannot be found within your database.');
         }
         ShopUrl::cacheMainDomainForShop((int) $order->id_shop);
     }
     /* Update shipping number */
     if (Tools::isSubmit('submitShippingNumber') && isset($order)) {
         if ($this->tabAccess['edit'] === '1') {
             $order_carrier = new OrderCarrier(Tools::getValue('id_order_carrier'));
             if (!Validate::isLoadedObject($order_carrier)) {
                 $this->errors[] = Tools::displayError('The order carrier ID is invalid.');
             } elseif (!Validate::isTrackingNumber(Tools::getValue('tracking_number'))) {
                 $this->errors[] = Tools::displayError('The tracking number is incorrect.');
             } else {
                 // update shipping number
                 // Keep these two following lines for backward compatibility, remove on 1.6 version
                 $order->shipping_number = Tools::getValue('tracking_number');
                 $order->update();
                 // Update order_carrier
                 $order_carrier->tracking_number = pSQL(Tools::getValue('tracking_number'));
                 if ($order_carrier->update()) {
                     // Send mail to customer
                     $customer = new Customer((int) $order->id_customer);
                     $carrier = new Carrier((int) $order->id_carrier, $order->id_lang);
                     if (!Validate::isLoadedObject($customer)) {
                         throw new PrestaShopException('Can\'t load Customer object');
                     }
                     if (!Validate::isLoadedObject($carrier)) {
                         throw new PrestaShopException('Can\'t load Carrier object');
                     }
                     $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url), '{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{id_order}' => $order->id, '{shipping_number}' => $order->shipping_number, '{order_name}' => $order->getUniqReference());
                     if (@Mail::Send((int) $order->id_lang, 'in_transit', Mail::l('Package in transit', (int) $order->id_lang), $templateVars, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop)) {
                         Hook::exec('actionAdminOrdersTrackingNumberUpdate', array('order' => $order, 'customer' => $customer, 'carrier' => $carrier), null, false, true, false, $order->id_shop);
                         Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token);
                     } else {
                         $this->errors[] = Tools::displayError('An error occurred while sending an email to the customer.');
                     }
                 } else {
                     $this->errors[] = Tools::displayError('The order carrier cannot be updated.');
                 }
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitState') && isset($order)) {
         if ($this->tabAccess['edit'] === '1') {
             $order_state = new OrderState(Tools::getValue('id_order_state'));
             if (!Validate::isLoadedObject($order_state)) {
                 $this->errors[] = Tools::displayError('The new order status is invalid.');
             } else {
                 $current_order_state = $order->getCurrentOrderState();
                 if ($current_order_state->id != $order_state->id) {
                     // Create new OrderHistory
                     $history = new OrderHistory();
                     $history->id_order = $order->id;
                     $history->id_employee = (int) $this->context->employee->id;
                     $use_existings_payment = false;
                     if (!$order->hasInvoice()) {
                         $use_existings_payment = true;
                     }
                     $history->changeIdOrderState((int) $order_state->id, $order, $use_existings_payment);
                     $carrier = new Carrier($order->id_carrier, $order->id_lang);
                     $templateVars = array();
                     if ($history->id_order_state == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number) {
                         $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url));
                     }
                     // Save all changes
                     if ($history->addWithemail(true, $templateVars)) {
                         // synchronizes quantities if needed..
                         if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                             foreach ($order->getProducts() as $product) {
                                 if (StockAvailable::dependsOnStock($product['product_id'])) {
                                     StockAvailable::synchronize($product['product_id'], (int) $product['id_shop']);
                                 }
                             }
                         }
                         Tools::redirectAdmin(self::$currentIndex . '&id_order=' . (int) $order->id . '&vieworder&token=' . $this->token);
                     }
                     $this->errors[] = Tools::displayError('An error occurred while changing order status, or we were unable to send an email to the customer.');
                 } else {
                     $this->errors[] = Tools::displayError('The order has already been assigned this status.');
                 }
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitMessage') && isset($order)) {
         if ($this->tabAccess['edit'] === '1') {
             $customer = new Customer(Tools::getValue('id_customer'));
             if (!Validate::isLoadedObject($customer)) {
                 $this->errors[] = Tools::displayError('The customer is invalid.');
             } elseif (!Tools::getValue('message')) {
                 $this->errors[] = Tools::displayError('The message cannot be blank.');
             } else {
                 /* Get message rules and and check fields validity */
                 $rules = call_user_func(array('Message', 'getValidationRules'), 'Message');
                 foreach ($rules['required'] as $field) {
                     if (($value = Tools::getValue($field)) == false && (string) $value != '0') {
                         if (!Tools::getValue('id_' . $this->table) || $field != 'passwd') {
                             $this->errors[] = sprintf(Tools::displayError('field %s is required.'), $field);
                         }
                     }
                 }
                 foreach ($rules['size'] as $field => $maxLength) {
                     if (Tools::getValue($field) && Tools::strlen(Tools::getValue($field)) > $maxLength) {
                         $this->errors[] = sprintf(Tools::displayError('field %1$s is too long (%2$d chars max).'), $field, $maxLength);
                     }
                 }
                 foreach ($rules['validate'] as $field => $function) {
                     if (Tools::getValue($field)) {
                         if (!Validate::$function(htmlentities(Tools::getValue($field), ENT_COMPAT, 'UTF-8'))) {
                             $this->errors[] = sprintf(Tools::displayError('field %s is invalid.'), $field);
                         }
                     }
                 }
                 if (!count($this->errors)) {
                     //check if a thread already exist
                     $id_customer_thread = CustomerThread::getIdCustomerThreadByEmailAndIdOrder($customer->email, $order->id);
                     if (!$id_customer_thread) {
                         $customer_thread = new CustomerThread();
                         $customer_thread->id_contact = 0;
                         $customer_thread->id_customer = (int) $order->id_customer;
                         $customer_thread->id_shop = (int) $this->context->shop->id;
                         $customer_thread->id_order = (int) $order->id;
                         $customer_thread->id_lang = (int) $this->context->language->id;
                         $customer_thread->email = $customer->email;
                         $customer_thread->status = 'open';
                         $customer_thread->token = Tools::passwdGen(12);
                         $customer_thread->add();
                     } else {
                         $customer_thread = new CustomerThread((int) $id_customer_thread);
                     }
                     $customer_message = new CustomerMessage();
                     $customer_message->id_customer_thread = $customer_thread->id;
                     $customer_message->id_employee = (int) $this->context->employee->id;
                     $customer_message->message = Tools::getValue('message');
                     $customer_message->private = Tools::getValue('visibility');
                     if (!$customer_message->add()) {
                         $this->errors[] = Tools::displayError('An error occurred while saving the message.');
                     } elseif ($customer_message->private) {
                         Tools::redirectAdmin(self::$currentIndex . '&id_order=' . (int) $order->id . '&vieworder&conf=11&token=' . $this->token);
                     } else {
                         $message = $customer_message->message;
                         if (Configuration::get('PS_MAIL_TYPE', null, null, $order->id_shop) != Mail::TYPE_TEXT) {
                             $message = Tools::nl2br($customer_message->message);
                         }
                         $varsTpl = array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order}' => $order->id, '{order_name}' => $order->getUniqReference(), '{message}' => $message);
                         if (@Mail::Send((int) $order->id_lang, 'order_merchant_comment', Mail::l('New message regarding your order', (int) $order->id_lang), $varsTpl, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop)) {
                             Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=11' . '&token=' . $this->token);
                         }
                     }
                     $this->errors[] = Tools::displayError('An error occurred while sending an email to the customer.');
                 }
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('partialRefund') && isset($order)) {
         if ($this->tabAccess['edit'] == '1') {
             if (is_array($_POST['partialRefundProduct'])) {
                 $amount = 0;
                 $order_detail_list = array();
                 foreach ($_POST['partialRefundProduct'] as $id_order_detail => $amount_detail) {
                     $order_detail_list[$id_order_detail]['quantity'] = (int) $_POST['partialRefundProductQuantity'][$id_order_detail];
                     if (empty($amount_detail)) {
                         $order_detail = new OrderDetail((int) $id_order_detail);
                         $order_detail_list[$id_order_detail]['amount'] = $order_detail->unit_price_tax_incl * $order_detail_list[$id_order_detail]['quantity'];
                     } else {
                         $order_detail_list[$id_order_detail]['amount'] = (double) str_replace(',', '.', $amount_detail);
                     }
                     $amount += $order_detail_list[$id_order_detail]['amount'];
                     $order_detail = new OrderDetail((int) $id_order_detail);
                     if (!$order->hasBeenDelivered() || $order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities') && $order_detail_list[$id_order_detail]['quantity'] > 0) {
                         $this->reinjectQuantity($order_detail, $order_detail_list[$id_order_detail]['quantity']);
                     }
                 }
                 $shipping_cost_amount = (double) str_replace(',', '.', Tools::getValue('partialRefundShippingCost'));
                 if ($shipping_cost_amount > 0) {
                     $amount += $shipping_cost_amount;
                 }
                 $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier());
                 if (Validate::isLoadedObject($order_carrier)) {
                     $order_carrier->weight = (double) $order->getTotalWeight();
                     if ($order_carrier->update()) {
                         $order->weight = sprintf("%.3f " . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight);
                     }
                 }
                 if ($amount > 0) {
                     if (!OrderSlip::createPartialOrderSlip($order, $amount, $shipping_cost_amount, $order_detail_list)) {
                         $this->errors[] = Tools::displayError('You cannot generate a partial credit slip.');
                     }
                     // Generate voucher
                     if (Tools::isSubmit('generateDiscountRefund') && !count($this->errors)) {
                         $cart_rule = new CartRule();
                         $cart_rule->description = sprintf($this->l('Credit slip for order #%d'), $order->id);
                         $languages = Language::getLanguages(false);
                         foreach ($languages as $language) {
                             // Define a temporary name
                             $cart_rule->name[$language['id_lang']] = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
                         }
                         // Define a temporary code
                         $cart_rule->code = sprintf('V0C%1$dO%2$d', $order->id_customer, $order->id);
                         $cart_rule->quantity = 1;
                         $cart_rule->quantity_per_user = 1;
                         // Specific to the customer
                         $cart_rule->id_customer = $order->id_customer;
                         $now = time();
                         $cart_rule->date_from = date('Y-m-d H:i:s', $now);
                         $cart_rule->date_to = date('Y-m-d H:i:s', $now + 3600 * 24 * 365.25);
                         /* 1 year */
                         $cart_rule->partial_use = 1;
                         $cart_rule->active = 1;
                         $cart_rule->reduction_amount = $amount;
                         $cart_rule->reduction_tax = true;
                         $cart_rule->minimum_amount_currency = $order->id_currency;
                         $cart_rule->reduction_currency = $order->id_currency;
                         if (!$cart_rule->add()) {
                             $this->errors[] = Tools::displayError('You cannot generate a voucher.');
                         } else {
                             // Update the voucher code and name
                             foreach ($languages as $language) {
                                 $cart_rule->name[$language['id_lang']] = sprintf('V%1$dC%2$dO%3$d', $cart_rule->id, $order->id_customer, $order->id);
                             }
                             $cart_rule->code = sprintf('V%1$dC%2$dO%3$d', $cart_rule->id, $order->id_customer, $order->id);
                             if (!$cart_rule->update()) {
                                 $this->errors[] = Tools::displayError('You cannot generate a voucher.');
                             } else {
                                 $currency = $this->context->currency;
                                 $customer = new Customer((int) $order->id_customer);
                                 $params['{lastname}'] = $customer->lastname;
                                 $params['{firstname}'] = $customer->firstname;
                                 $params['{id_order}'] = $order->id;
                                 $params['{order_name}'] = $order->getUniqReference();
                                 $params['{voucher_amount}'] = Tools::displayPrice($cart_rule->reduction_amount, $currency, false);
                                 $params['{voucher_num}'] = $cart_rule->code;
                                 $customer = new Customer((int) $order->id_customer);
                                 @Mail::Send((int) $order->id_lang, 'voucher', sprintf(Mail::l('New voucher regarding your order %s', (int) $order->id_lang), $order->reference), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop);
                             }
                         }
                     }
                 } else {
                     $this->errors[] = Tools::displayError('You have to enter an amount if you want to create a partial credit slip.');
                 }
                 // Redirect if no errors
                 if (!count($this->errors)) {
                     Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=30&token=' . $this->token);
                 }
             } else {
                 $this->errors[] = Tools::displayError('The partial refund data is incorrect.');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('cancelProduct') && isset($order)) {
         if ($this->tabAccess['delete'] === '1') {
             if (!Tools::isSubmit('id_order_detail') && !Tools::isSubmit('id_customization')) {
                 $this->errors[] = Tools::displayError('You must select a product.');
             } elseif (!Tools::isSubmit('cancelQuantity') && !Tools::isSubmit('cancelCustomizationQuantity')) {
                 $this->errors[] = Tools::displayError('You must enter a quantity.');
             } else {
                 $productList = Tools::getValue('id_order_detail');
                 if ($productList) {
                     $productList = array_map('intval', $productList);
                 }
                 $customizationList = Tools::getValue('id_customization');
                 if ($customizationList) {
                     $customizationList = array_map('intval', $customizationList);
                 }
                 $qtyList = Tools::getValue('cancelQuantity');
                 if ($qtyList) {
                     $qtyList = array_map('intval', $qtyList);
                 }
                 $customizationQtyList = Tools::getValue('cancelCustomizationQuantity');
                 if ($customizationQtyList) {
                     $customizationQtyList = array_map('intval', $customizationQtyList);
                 }
                 $full_product_list = $productList;
                 $full_quantity_list = $qtyList;
                 if ($customizationList) {
                     foreach ($customizationList as $key => $id_order_detail) {
                         $full_product_list[(int) $id_order_detail] = $id_order_detail;
                         if (isset($customizationQtyList[$key])) {
                             $full_quantity_list[(int) $id_order_detail] += $customizationQtyList[$key];
                         }
                     }
                 }
                 if ($productList || $customizationList) {
                     if ($productList) {
                         $id_cart = Cart::getCartIdByOrderId($order->id);
                         $customization_quantities = Customization::countQuantityByCart($id_cart);
                         foreach ($productList as $key => $id_order_detail) {
                             $qtyCancelProduct = abs($qtyList[$key]);
                             if (!$qtyCancelProduct) {
                                 $this->errors[] = Tools::displayError('No quantity has been selected for this product.');
                             }
                             $order_detail = new OrderDetail($id_order_detail);
                             $customization_quantity = 0;
                             if (array_key_exists($order_detail->product_id, $customization_quantities) && array_key_exists($order_detail->product_attribute_id, $customization_quantities[$order_detail->product_id])) {
                                 $customization_quantity = (int) $customization_quantities[$order_detail->product_id][$order_detail->product_attribute_id];
                             }
                             if ($order_detail->product_quantity - $customization_quantity - $order_detail->product_quantity_refunded - $order_detail->product_quantity_return < $qtyCancelProduct) {
                                 $this->errors[] = Tools::displayError('An invalid quantity was selected for this product.');
                             }
                         }
                     }
                     if ($customizationList) {
                         $customization_quantities = Customization::retrieveQuantitiesFromIds(array_keys($customizationList));
                         foreach ($customizationList as $id_customization => $id_order_detail) {
                             $qtyCancelProduct = abs($customizationQtyList[$id_customization]);
                             $customization_quantity = $customization_quantities[$id_customization];
                             if (!$qtyCancelProduct) {
                                 $this->errors[] = Tools::displayError('No quantity has been selected for this product.');
                             }
                             if ($qtyCancelProduct > $customization_quantity['quantity'] - ($customization_quantity['quantity_refunded'] + $customization_quantity['quantity_returned'])) {
                                 $this->errors[] = Tools::displayError('An invalid quantity was selected for this product.');
                             }
                         }
                     }
                     if (!count($this->errors) && $productList) {
                         foreach ($productList as $key => $id_order_detail) {
                             $qty_cancel_product = abs($qtyList[$key]);
                             $order_detail = new OrderDetail((int) $id_order_detail);
                             if (!$order->hasBeenDelivered() || $order->hasBeenDelivered() && Tools::isSubmit('reinjectQuantities') && $qty_cancel_product > 0) {
                                 $this->reinjectQuantity($order_detail, $qty_cancel_product);
                             }
                             // Delete product
                             $order_detail = new OrderDetail((int) $id_order_detail);
                             if (!$order->deleteProduct($order, $order_detail, $qty_cancel_product)) {
                                 $this->errors[] = Tools::displayError('An error occurred while attempting to delete the product.') . ' <span class="bold">' . $order_detail->product_name . '</span>';
                             }
                             // Update weight SUM
                             $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier());
                             if (Validate::isLoadedObject($order_carrier)) {
                                 $order_carrier->weight = (double) $order->getTotalWeight();
                                 if ($order_carrier->update()) {
                                     $order->weight = sprintf("%.3f " . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight);
                                 }
                             }
                             Hook::exec('actionProductCancel', array('order' => $order, 'id_order_detail' => (int) $id_order_detail), null, false, true, false, $order->id_shop);
                         }
                     }
                     if (!count($this->errors) && $customizationList) {
                         foreach ($customizationList as $id_customization => $id_order_detail) {
                             $order_detail = new OrderDetail((int) $id_order_detail);
                             $qtyCancelProduct = abs($customizationQtyList[$id_customization]);
                             if (!$order->deleteCustomization($id_customization, $qtyCancelProduct, $order_detail)) {
                                 $this->errors[] = Tools::displayError('An error occurred while attempting to delete product customization.') . ' ' . $id_customization;
                             }
                         }
                     }
                     // E-mail params
                     if ((Tools::isSubmit('generateCreditSlip') || Tools::isSubmit('generateDiscount')) && !count($this->errors)) {
                         $customer = new Customer((int) $order->id_customer);
                         $params['{lastname}'] = $customer->lastname;
                         $params['{firstname}'] = $customer->firstname;
                         $params['{id_order}'] = $order->id;
                         $params['{order_name}'] = $order->getUniqReference();
                     }
                     // Generate credit slip
                     if (Tools::isSubmit('generateCreditSlip') && !count($this->errors)) {
                         if (!OrderSlip::createOrderSlip($order, $full_product_list, $full_quantity_list, Tools::isSubmit('shippingBack'))) {
                             $this->errors[] = Tools::displayError('A credit slip cannot be generated. ');
                         } else {
                             Hook::exec('actionOrderSlipAdd', array('order' => $order, 'productList' => $full_product_list, 'qtyList' => $full_quantity_list), null, false, true, false, $order->id_shop);
                             @Mail::Send((int) $order->id_lang, 'credit_slip', Mail::l('New credit slip regarding your order', (int) $order->id_lang), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop);
                         }
                     }
                     // Generate voucher
                     if (Tools::isSubmit('generateDiscount') && !count($this->errors)) {
                         $cartrule = new CartRule();
                         $languages = Language::getLanguages($order);
                         $cartrule->description = sprintf($this->l('Credit card slip for order #%d'), $order->id);
                         foreach ($languages as $language) {
                             // Define a temporary name
                             $cartrule->name[$language['id_lang']] = 'V0C' . (int) $order->id_customer . 'O' . (int) $order->id;
                         }
                         // Define a temporary code
                         $cartrule->code = 'V0C' . (int) $order->id_customer . 'O' . (int) $order->id;
                         $cartrule->quantity = 1;
                         $cartrule->quantity_per_user = 1;
                         // Specific to the customer
                         $cartrule->id_customer = $order->id_customer;
                         $now = time();
                         $cartrule->date_from = date('Y-m-d H:i:s', $now);
                         $cartrule->date_to = date('Y-m-d H:i:s', $now + 3600 * 24 * 365.25);
                         /* 1 year */
                         $cartrule->active = 1;
                         $products = $order->getProducts(false, $full_product_list, $full_quantity_list);
                         $total = 0;
                         foreach ($products as $product) {
                             $total += $product['unit_price_tax_incl'] * $product['product_quantity'];
                         }
                         if (Tools::isSubmit('shippingBack')) {
                             $total += $order->total_shipping;
                         }
                         $cartrule->reduction_amount = $total;
                         $cartrule->reduction_tax = true;
                         $cartrule->minimum_amount_currency = $order->id_currency;
                         $cartrule->reduction_currency = $order->id_currency;
                         if (!$cartrule->add()) {
                             $this->errors[] = Tools::displayError('You cannot generate a voucher.');
                         } else {
                             // Update the voucher code and name
                             foreach ($languages as $language) {
                                 $cartrule->name[$language['id_lang']] = 'V' . (int) $cartrule->id . 'C' . (int) $order->id_customer . 'O' . $order->id;
                             }
                             $cartrule->code = 'V' . (int) $cartrule->id . 'C' . (int) $order->id_customer . 'O' . $order->id;
                             if (!$cartrule->update()) {
                                 $this->errors[] = Tools::displayError('You cannot generate a voucher.');
                             } else {
                                 $currency = $this->context->currency;
                                 $params['{voucher_amount}'] = Tools::displayPrice($cartrule->reduction_amount, $currency, false);
                                 $params['{voucher_num}'] = $cartrule->code;
                                 @Mail::Send((int) $order->id_lang, 'voucher', sprintf(Mail::l('New voucher regarding your order %s', (int) $order->id_lang), $order->reference), $params, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop);
                             }
                         }
                     }
                 } else {
                     $this->errors[] = Tools::displayError('No product or quantity has been selected.');
                 }
                 // Redirect if no errors
                 if (!count($this->errors)) {
                     Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=31&token=' . $this->token);
                 }
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('messageReaded')) {
         Message::markAsReaded(Tools::getValue('messageReaded'), $this->context->employee->id);
     } elseif (Tools::isSubmit('submitAddPayment') && isset($order)) {
         if ($this->tabAccess['edit'] === '1') {
             $amount = str_replace(',', '.', Tools::getValue('payment_amount'));
             $currency = new Currency(Tools::getValue('payment_currency'));
             $order_has_invoice = $order->hasInvoice();
             if ($order_has_invoice) {
                 $order_invoice = new OrderInvoice(Tools::getValue('payment_invoice'));
             } else {
                 $order_invoice = null;
             }
             if (!Validate::isLoadedObject($order)) {
                 $this->errors[] = Tools::displayError('The order cannot be found');
             } elseif (!Validate::isNegativePrice($amount) || !(double) $amount) {
                 $this->errors[] = Tools::displayError('The amount is invalid.');
             } elseif (!Validate::isGenericName(Tools::getValue('payment_method'))) {
                 $this->errors[] = Tools::displayError('The selected payment method is invalid.');
             } elseif (!Validate::isString(Tools::getValue('payment_transaction_id'))) {
                 $this->errors[] = Tools::displayError('The transaction ID is invalid.');
             } elseif (!Validate::isLoadedObject($currency)) {
                 $this->errors[] = Tools::displayError('The selected currency is invalid.');
             } elseif ($order_has_invoice && !Validate::isLoadedObject($order_invoice)) {
                 $this->errors[] = Tools::displayError('The invoice is invalid.');
             } elseif (!Validate::isDate(Tools::getValue('payment_date'))) {
                 $this->errors[] = Tools::displayError('The date is invalid');
             } else {
                 if (!$order->addOrderPayment($amount, Tools::getValue('payment_method'), Tools::getValue('payment_transaction_id'), $currency, Tools::getValue('payment_date'), $order_invoice)) {
                     $this->errors[] = Tools::displayError('An error occurred during payment.');
                 } else {
                     Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token);
                 }
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitEditNote')) {
         $note = Tools::getValue('note');
         $order_invoice = new OrderInvoice((int) Tools::getValue('id_order_invoice'));
         if (Validate::isLoadedObject($order_invoice) && Validate::isCleanHtml($note)) {
             if ($this->tabAccess['edit'] === '1') {
                 $order_invoice->note = $note;
                 if ($order_invoice->save()) {
                     Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order_invoice->id_order . '&vieworder&conf=4&token=' . $this->token);
                 } else {
                     $this->errors[] = Tools::displayError('The invoice note was not saved.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('You do not have permission to edit this.');
             }
         } else {
             $this->errors[] = Tools::displayError('The invoice for edit note was unable to load. ');
         }
     } elseif (Tools::isSubmit('submitAddOrder') && ($id_cart = Tools::getValue('id_cart')) && ($module_name = Tools::getValue('payment_module_name')) && ($id_order_state = Tools::getValue('id_order_state')) && Validate::isModuleName($module_name)) {
         if ($this->tabAccess['edit'] === '1') {
             $payment_module = Module::getInstanceByName($module_name);
             $cart = new Cart((int) $id_cart);
             Context::getContext()->currency = new Currency((int) $cart->id_currency);
             Context::getContext()->customer = new Customer((int) $cart->id_customer);
             $employee = new Employee((int) Context::getContext()->cookie->id_employee);
             $payment_module->validateOrder((int) $cart->id, (int) $id_order_state, $cart->getOrderTotal(true, Cart::BOTH), $payment_module->displayName, $this->l('Manual order -- Employee:') . ' ' . substr($employee->firstname, 0, 1) . '. ' . $employee->lastname, array(), null, false, $cart->secure_key);
             if ($payment_module->currentOrder) {
                 Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $payment_module->currentOrder . '&vieworder' . '&token=' . $this->token);
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to add this.');
         }
     } elseif ((Tools::isSubmit('submitAddressShipping') || Tools::isSubmit('submitAddressInvoice')) && isset($order)) {
         if ($this->tabAccess['edit'] === '1') {
             $address = new Address(Tools::getValue('id_address'));
             if (Validate::isLoadedObject($address)) {
                 // Update the address on order
                 if (Tools::isSubmit('submitAddressShipping')) {
                     $order->id_address_delivery = $address->id;
                 } elseif (Tools::isSubmit('submitAddressInvoice')) {
                     $order->id_address_invoice = $address->id;
                 }
                 $order->update();
                 Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token);
             } else {
                 $this->errors[] = Tools::displayError('This address can\'t be loaded');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitChangeCurrency') && isset($order)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Tools::getValue('new_currency') != $order->id_currency && !$order->valid) {
                 $old_currency = new Currency($order->id_currency);
                 $currency = new Currency(Tools::getValue('new_currency'));
                 if (!Validate::isLoadedObject($currency)) {
                     throw new PrestaShopException('Can\'t load Currency object');
                 }
                 // Update order detail amount
                 foreach ($order->getOrderDetailList() as $row) {
                     $order_detail = new OrderDetail($row['id_order_detail']);
                     $fields = array('ecotax', 'product_price', 'reduction_amount', 'total_shipping_price_tax_excl', 'total_shipping_price_tax_incl', 'total_price_tax_incl', 'total_price_tax_excl', 'product_quantity_discount', 'purchase_supplier_price', 'reduction_amount', 'reduction_amount_tax_incl', 'reduction_amount_tax_excl', 'unit_price_tax_incl', 'unit_price_tax_excl', 'original_product_price');
                     foreach ($fields as $field) {
                         $order_detail->{$field} = Tools::convertPriceFull($order_detail->{$field}, $old_currency, $currency);
                     }
                     $order_detail->update();
                     $order_detail->updateTaxAmount($order);
                 }
                 $id_order_carrier = (int) $order->getIdOrderCarrier();
                 if ($id_order_carrier) {
                     $order_carrier = $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier());
                     $order_carrier->shipping_cost_tax_excl = (double) Tools::convertPriceFull($order_carrier->shipping_cost_tax_excl, $old_currency, $currency);
                     $order_carrier->shipping_cost_tax_incl = (double) Tools::convertPriceFull($order_carrier->shipping_cost_tax_incl, $old_currency, $currency);
                     $order_carrier->update();
                 }
                 // Update order && order_invoice amount
                 $fields = array('total_discounts', 'total_discounts_tax_incl', 'total_discounts_tax_excl', 'total_discount_tax_excl', 'total_discount_tax_incl', 'total_paid', 'total_paid_tax_incl', 'total_paid_tax_excl', 'total_paid_real', 'total_products', 'total_products_wt', 'total_shipping', 'total_shipping_tax_incl', 'total_shipping_tax_excl', 'total_wrapping', 'total_wrapping_tax_incl', 'total_wrapping_tax_excl');
                 $invoices = $order->getInvoicesCollection();
                 if ($invoices) {
                     foreach ($invoices as $invoice) {
                         foreach ($fields as $field) {
                             if (isset($invoice->{$field})) {
                                 $invoice->{$field} = Tools::convertPriceFull($invoice->{$field}, $old_currency, $currency);
                             }
                         }
                         $invoice->save();
                     }
                 }
                 foreach ($fields as $field) {
                     if (isset($order->{$field})) {
                         $order->{$field} = Tools::convertPriceFull($order->{$field}, $old_currency, $currency);
                     }
                 }
                 // Update currency in order
                 $order->id_currency = $currency->id;
                 // Update exchange rate
                 $order->conversion_rate = (double) $currency->conversion_rate;
                 $order->update();
             } else {
                 $this->errors[] = Tools::displayError('You cannot change the currency.');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitGenerateInvoice') && isset($order)) {
         if (!Configuration::get('PS_INVOICE', null, null, $order->id_shop)) {
             $this->errors[] = Tools::displayError('Invoice management has been disabled.');
         } elseif ($order->hasInvoice()) {
             $this->errors[] = Tools::displayError('This order already has an invoice.');
         } else {
             $order->setInvoice(true);
             Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token);
         }
     } elseif (Tools::isSubmit('submitDeleteVoucher') && isset($order)) {
         if ($this->tabAccess['edit'] === '1') {
             $order_cart_rule = new OrderCartRule(Tools::getValue('id_order_cart_rule'));
             if (Validate::isLoadedObject($order_cart_rule) && $order_cart_rule->id_order == $order->id) {
                 if ($order_cart_rule->id_order_invoice) {
                     $order_invoice = new OrderInvoice($order_cart_rule->id_order_invoice);
                     if (!Validate::isLoadedObject($order_invoice)) {
                         throw new PrestaShopException('Can\'t load Order Invoice object');
                     }
                     // Update amounts of Order Invoice
                     $order_invoice->total_discount_tax_excl -= $order_cart_rule->value_tax_excl;
                     $order_invoice->total_discount_tax_incl -= $order_cart_rule->value;
                     $order_invoice->total_paid_tax_excl += $order_cart_rule->value_tax_excl;
                     $order_invoice->total_paid_tax_incl += $order_cart_rule->value;
                     // Update Order Invoice
                     $order_invoice->update();
                 }
                 // Update amounts of order
                 $order->total_discounts -= $order_cart_rule->value;
                 $order->total_discounts_tax_incl -= $order_cart_rule->value;
                 $order->total_discounts_tax_excl -= $order_cart_rule->value_tax_excl;
                 $order->total_paid += $order_cart_rule->value;
                 $order->total_paid_tax_incl += $order_cart_rule->value;
                 $order->total_paid_tax_excl += $order_cart_rule->value_tax_excl;
                 // Delete Order Cart Rule and update Order
                 $order_cart_rule->delete();
                 $order->update();
                 Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token);
             } else {
                 $this->errors[] = Tools::displayError('You cannot edit this cart rule.');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitNewVoucher') && isset($order)) {
         if ($this->tabAccess['edit'] === '1') {
             if (!Tools::getValue('discount_name')) {
                 $this->errors[] = Tools::displayError('You must specify a name in order to create a new discount.');
             } else {
                 if ($order->hasInvoice()) {
                     // If the discount is for only one invoice
                     if (!Tools::isSubmit('discount_all_invoices')) {
                         $order_invoice = new OrderInvoice(Tools::getValue('discount_invoice'));
                         if (!Validate::isLoadedObject($order_invoice)) {
                             throw new PrestaShopException('Can\'t load Order Invoice object');
                         }
                     }
                 }
                 $cart_rules = array();
                 $discount_value = (double) str_replace(',', '.', Tools::getValue('discount_value'));
                 switch (Tools::getValue('discount_type')) {
                     // Percent type
                     case 1:
                         if ($discount_value < 100) {
                             if (isset($order_invoice)) {
                                 $cart_rules[$order_invoice->id]['value_tax_incl'] = Tools::ps_round($order_invoice->total_paid_tax_incl * $discount_value / 100, 2);
                                 $cart_rules[$order_invoice->id]['value_tax_excl'] = Tools::ps_round($order_invoice->total_paid_tax_excl * $discount_value / 100, 2);
                                 // Update OrderInvoice
                                 $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']);
                             } elseif ($order->hasInvoice()) {
                                 $order_invoices_collection = $order->getInvoicesCollection();
                                 foreach ($order_invoices_collection as $order_invoice) {
                                     $cart_rules[$order_invoice->id]['value_tax_incl'] = Tools::ps_round($order_invoice->total_paid_tax_incl * $discount_value / 100, 2);
                                     $cart_rules[$order_invoice->id]['value_tax_excl'] = Tools::ps_round($order_invoice->total_paid_tax_excl * $discount_value / 100, 2);
                                     // Update OrderInvoice
                                     $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']);
                                 }
                             } else {
                                 $cart_rules[0]['value_tax_incl'] = Tools::ps_round($order->total_paid_tax_incl * $discount_value / 100, 2);
                                 $cart_rules[0]['value_tax_excl'] = Tools::ps_round($order->total_paid_tax_excl * $discount_value / 100, 2);
                             }
                         } else {
                             $this->errors[] = Tools::displayError('The discount value is invalid.');
                         }
                         break;
                         // Amount type
                     // Amount type
                     case 2:
                         if (isset($order_invoice)) {
                             if ($discount_value > $order_invoice->total_paid_tax_incl) {
                                 $this->errors[] = Tools::displayError('The discount value is greater than the order invoice total.');
                             } else {
                                 $cart_rules[$order_invoice->id]['value_tax_incl'] = Tools::ps_round($discount_value, 2);
                                 $cart_rules[$order_invoice->id]['value_tax_excl'] = Tools::ps_round($discount_value / (1 + $order->getTaxesAverageUsed() / 100), 2);
                                 // Update OrderInvoice
                                 $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']);
                             }
                         } elseif ($order->hasInvoice()) {
                             $order_invoices_collection = $order->getInvoicesCollection();
                             foreach ($order_invoices_collection as $order_invoice) {
                                 if ($discount_value > $order_invoice->total_paid_tax_incl) {
                                     $this->errors[] = Tools::displayError('The discount value is greater than the order invoice total.') . $order_invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int) $order->id_shop) . ')';
                                 } else {
                                     $cart_rules[$order_invoice->id]['value_tax_incl'] = Tools::ps_round($discount_value, 2);
                                     $cart_rules[$order_invoice->id]['value_tax_excl'] = Tools::ps_round($discount_value / (1 + $order->getTaxesAverageUsed() / 100), 2);
                                     // Update OrderInvoice
                                     $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']);
                                 }
                             }
                         } else {
                             if ($discount_value > $order->total_paid_tax_incl) {
                                 $this->errors[] = Tools::displayError('The discount value is greater than the order total.');
                             } else {
                                 $cart_rules[0]['value_tax_incl'] = Tools::ps_round($discount_value, 2);
                                 $cart_rules[0]['value_tax_excl'] = Tools::ps_round($discount_value / (1 + $order->getTaxesAverageUsed() / 100), 2);
                             }
                         }
                         break;
                         // Free shipping type
                     // Free shipping type
                     case 3:
                         if (isset($order_invoice)) {
                             if ($order_invoice->total_shipping_tax_incl > 0) {
                                 $cart_rules[$order_invoice->id]['value_tax_incl'] = $order_invoice->total_shipping_tax_incl;
                                 $cart_rules[$order_invoice->id]['value_tax_excl'] = $order_invoice->total_shipping_tax_excl;
                                 // Update OrderInvoice
                                 $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']);
                             }
                         } elseif ($order->hasInvoice()) {
                             $order_invoices_collection = $order->getInvoicesCollection();
                             foreach ($order_invoices_collection as $order_invoice) {
                                 if ($order_invoice->total_shipping_tax_incl <= 0) {
                                     continue;
                                 }
                                 $cart_rules[$order_invoice->id]['value_tax_incl'] = $order_invoice->total_shipping_tax_incl;
                                 $cart_rules[$order_invoice->id]['value_tax_excl'] = $order_invoice->total_shipping_tax_excl;
                                 // Update OrderInvoice
                                 $this->applyDiscountOnInvoice($order_invoice, $cart_rules[$order_invoice->id]['value_tax_incl'], $cart_rules[$order_invoice->id]['value_tax_excl']);
                             }
                         } else {
                             $cart_rules[0]['value_tax_incl'] = $order->total_shipping_tax_incl;
                             $cart_rules[0]['value_tax_excl'] = $order->total_shipping_tax_excl;
                         }
                         break;
                     default:
                         $this->errors[] = Tools::displayError('The discount type is invalid.');
                 }
                 $res = true;
                 foreach ($cart_rules as &$cart_rule) {
                     $cartRuleObj = new CartRule();
                     $cartRuleObj->date_from = date('Y-m-d H:i:s', strtotime('-1 hour', strtotime($order->date_add)));
                     $cartRuleObj->date_to = date('Y-m-d H:i:s', strtotime('+1 hour'));
                     $cartRuleObj->name[Configuration::get('PS_LANG_DEFAULT')] = Tools::getValue('discount_name');
                     $cartRuleObj->quantity = 0;
                     $cartRuleObj->quantity_per_user = 1;
                     if (Tools::getValue('discount_type') == 1) {
                         $cartRuleObj->reduction_percent = $discount_value;
                     } elseif (Tools::getValue('discount_type') == 2) {
                         $cartRuleObj->reduction_amount = $cart_rule['value_tax_excl'];
                     } elseif (Tools::getValue('discount_type') == 3) {
                         $cartRuleObj->free_shipping = 1;
                     }
                     $cartRuleObj->active = 0;
                     if ($res = $cartRuleObj->add()) {
                         $cart_rule['id'] = $cartRuleObj->id;
                     } else {
                         break;
                     }
                 }
                 if ($res) {
                     foreach ($cart_rules as $id_order_invoice => $cart_rule) {
                         // Create OrderCartRule
                         $order_cart_rule = new OrderCartRule();
                         $order_cart_rule->id_order = $order->id;
                         $order_cart_rule->id_cart_rule = $cart_rule['id'];
                         $order_cart_rule->id_order_invoice = $id_order_invoice;
                         $order_cart_rule->name = Tools::getValue('discount_name');
                         $order_cart_rule->value = $cart_rule['value_tax_incl'];
                         $order_cart_rule->value_tax_excl = $cart_rule['value_tax_excl'];
                         $res &= $order_cart_rule->add();
                         $order->total_discounts += $order_cart_rule->value;
                         $order->total_discounts_tax_incl += $order_cart_rule->value;
                         $order->total_discounts_tax_excl += $order_cart_rule->value_tax_excl;
                         $order->total_paid -= $order_cart_rule->value;
                         $order->total_paid_tax_incl -= $order_cart_rule->value;
                         $order->total_paid_tax_excl -= $order_cart_rule->value_tax_excl;
                     }
                     // Update Order
                     $res &= $order->update();
                 }
                 if ($res) {
                     Tools::redirectAdmin(self::$currentIndex . '&id_order=' . $order->id . '&vieworder&conf=4&token=' . $this->token);
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred during the OrderCartRule creation');
                 }
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     }
     parent::postProcess();
 }
Ejemplo n.º 20
0
 public function postProcess()
 {
     $this->admin_cms->postProcess();
     $this->admin_cms_categories->postProcess();
     parent::postProcess();
     if ((Tools::isSubmit('submitAddcms_category') || Tools::isSubmit('submitAddcms_categoryAndStay')) && count($this->admin_cms_categories->errors) || Tools::isSubmit('updatecms_category') || Tools::isSubmit('addcms_category')) {
         $this->display = 'edit_category';
     } elseif ((Tools::isSubmit('submitAddcms') || Tools::isSubmit('submitAddcmsAndStay')) && count($this->admin_cms->errors) || Tools::isSubmit('updatecms') || Tools::isSubmit('addcms')) {
         $this->display = 'edit_page';
     } else {
         $this->display = 'list';
         $this->id_cms_category = (int) Tools::getValue('id_cms_category');
     }
     if (isset($this->admin_cms->errors)) {
         $this->errors = array_merge($this->errors, $this->admin_cms->errors);
     }
     if (isset($this->admin_cms_categories->errors)) {
         $this->errors = array_merge($this->errors, $this->admin_cms_categories->errors);
     }
 }
 /**
  * AdminController::postProcess() override
  * @see AdminController::postProcess()
  */
 public function postProcess()
 {
     parent::postProcess();
     // Checks access
     if (Tools::isSubmit('addStock') && !($this->tabAccess['add'] === '1')) {
         $this->errors[] = Tools::displayError('You do not have the required permission to add stock.');
     }
     if (Tools::isSubmit('removeStock') && !($this->tabAccess['delete'] === '1')) {
         $this->errors[] = Tools::displayError('You do not have the required permission to delete stock');
     }
     if (Tools::isSubmit('transferStock') && !($this->tabAccess['edit'] === '1')) {
         $this->errors[] = Tools::displayError('You do not have the required permission to transfer stock.');
     }
     if (count($this->errors)) {
         return;
     }
     // Global checks when add / remove / transfer product
     if ((Tools::isSubmit('addstock') || Tools::isSubmit('removestock') || Tools::isSubmit('transferstock')) && Tools::isSubmit('is_post')) {
         // get product ID
         $id_product = (int) Tools::getValue('id_product', 0);
         if ($id_product <= 0) {
             $this->errors[] = Tools::displayError('The selected product is not valid.');
         }
         // get product_attribute ID
         $id_product_attribute = (int) Tools::getValue('id_product_attribute', 0);
         // check the product hash
         $check = Tools::getValue('check', '');
         $check_valid = md5(_COOKIE_KEY_ . $id_product . $id_product_attribute);
         if ($check != $check_valid) {
             $this->errors[] = Tools::displayError('The selected product is not valid.');
         }
         // get quantity and check that the post value is really an integer
         // If it's not, we have nothing to do
         $quantity = Tools::getValue('quantity', 0);
         if (!is_numeric($quantity) || (int) $quantity <= 0) {
             $this->errors[] = Tools::displayError('The quantity value is not valid.');
         }
         $quantity = (int) $quantity;
         $token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
         $redirect = self::$currentIndex . '&token=' . $token;
     }
     // Global checks when add / remove product
     if ((Tools::isSubmit('addstock') || Tools::isSubmit('removestock')) && Tools::isSubmit('is_post')) {
         // get warehouse id
         $id_warehouse = (int) Tools::getValue('id_warehouse', 0);
         if ($id_warehouse <= 0 || !Warehouse::exists($id_warehouse)) {
             $this->errors[] = Tools::displayError('The selected warehouse is not valid.');
         }
         // get stock movement reason id
         $id_stock_mvt_reason = (int) Tools::getValue('id_stock_mvt_reason', 0);
         if ($id_stock_mvt_reason <= 0 || !StockMvtReason::exists($id_stock_mvt_reason)) {
             $this->errors[] = Tools::displayError('The reason is not valid.');
         }
         // get usable flag
         $usable = Tools::getValue('usable', null);
         if (is_null($usable)) {
             $this->errors[] = Tools::displayError('You have to specify whether the product quantity is usable for sale on shops or not.');
         }
         $usable = (bool) $usable;
     }
     if (Tools::isSubmit('addstock') && Tools::isSubmit('is_post')) {
         // get product unit price
         $price = str_replace(',', '.', Tools::getValue('price', 0));
         if (!is_numeric($price)) {
             $this->errors[] = Tools::displayError('The product price is not valid.');
         }
         $price = round(floatval($price), 6);
         // get product unit price currency id
         $id_currency = (int) Tools::getValue('id_currency', 0);
         if ($id_currency <= 0 || (!($result = Currency::getCurrency($id_currency)) || empty($result))) {
             $this->errors[] = Tools::displayError('The selected currency is not valid.');
         }
         // if all is ok, add stock
         if (count($this->errors) == 0) {
             $warehouse = new Warehouse($id_warehouse);
             // convert price to warehouse currency if needed
             if ($id_currency != $warehouse->id_currency) {
                 // First convert price to the default currency
                 $price_converted_to_default_currency = Tools::convertPrice($price, $id_currency, false);
                 // Convert the new price from default currency to needed currency
                 $price = Tools::convertPrice($price_converted_to_default_currency, $warehouse->id_currency, true);
             }
             // add stock
             $stock_manager = StockManagerFactory::getManager();
             if ($stock_manager->addProduct($id_product, $id_product_attribute, $warehouse, $quantity, $id_stock_mvt_reason, $price, $usable)) {
                 // Create warehouse_product_location entry if we add stock to a new warehouse
                 $id_wpl = (int) WarehouseProductLocation::getIdByProductAndWarehouse($id_product, $id_product_attribute, $id_warehouse);
                 if (!$id_wpl) {
                     $wpl = new WarehouseProductLocation();
                     $wpl->id_product = (int) $id_product;
                     $wpl->id_product_attribute = (int) $id_product_attribute;
                     $wpl->id_warehouse = (int) $id_warehouse;
                     $wpl->save();
                 }
                 StockAvailable::synchronize($id_product);
                 if (Tools::isSubmit('addstockAndStay')) {
                     $redirect = self::$currentIndex . '&id_product=' . (int) $id_product;
                     if ($id_product_attribute) {
                         $redirect .= '&id_product_attribute=' . (int) $id_product_attribute;
                     }
                     $redirect .= '&addstock&token=' . $token;
                 }
                 Tools::redirectAdmin($redirect . '&conf=1');
             } else {
                 $this->errors[] = Tools::displayError('An error occurred. No stock was added.');
             }
         }
     }
     if (Tools::isSubmit('removestock') && Tools::isSubmit('is_post')) {
         // if all is ok, remove stock
         if (count($this->errors) == 0) {
             $warehouse = new Warehouse($id_warehouse);
             // remove stock
             $stock_manager = StockManagerFactory::getManager();
             $removed_products = $stock_manager->removeProduct($id_product, $id_product_attribute, $warehouse, $quantity, $id_stock_mvt_reason, $usable);
             if (count($removed_products) > 0) {
                 StockAvailable::synchronize($id_product);
                 Tools::redirectAdmin($redirect . '&conf=2');
             } else {
                 $physical_quantity_in_stock = (int) $stock_manager->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), false);
                 $usable_quantity_in_stock = (int) $stock_manager->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), true);
                 $not_usable_quantity = $physical_quantity_in_stock - $usable_quantity_in_stock;
                 if ($usable_quantity_in_stock < $quantity) {
                     $this->errors[] = sprintf(Tools::displayError('You don\'t have enough usable quantity. Cannot remove %d items out of %d.'), (int) $quantity, (int) $usable_quantity_in_stock);
                 } elseif ($not_usable_quantity < $quantity) {
                     $this->errors[] = sprintf(Tools::displayError('You don\'t have enough usable quantity. Cannot remove %d items out of %d.'), (int) $quantity, (int) $not_usable_quantity);
                 } else {
                     $this->errors[] = Tools::displayError('It is not possible to remove the specified quantity. Therefore no stock was removed.');
                 }
             }
         }
     }
     if (Tools::isSubmit('transferstock') && Tools::isSubmit('is_post')) {
         // get source warehouse id
         $id_warehouse_from = (int) Tools::getValue('id_warehouse_from', 0);
         if ($id_warehouse_from <= 0 || !Warehouse::exists($id_warehouse_from)) {
             $this->errors[] = Tools::displayError('The source warehouse is not valid.');
         }
         // get destination warehouse id
         $id_warehouse_to = (int) Tools::getValue('id_warehouse_to', 0);
         if ($id_warehouse_to <= 0 || !Warehouse::exists($id_warehouse_to)) {
             $this->errors[] = Tools::displayError('The destination warehouse is not valid.');
         }
         // get usable flag for source warehouse
         $usable_from = Tools::getValue('usable_from', null);
         if (is_null($usable_from)) {
             $this->errors[] = Tools::displayError('You have to specify whether the product quantity in your source warehouse(s) is ready for sale or not.');
         }
         $usable_from = (bool) $usable_from;
         // get usable flag for destination warehouse
         $usable_to = Tools::getValue('usable_to', null);
         if (is_null($usable_to)) {
             $this->errors[] = Tools::displayError('You have to specify whether the product quantity in your destination warehouse(s) is ready for sale or not.');
         }
         $usable_to = (bool) $usable_to;
         // if we can process stock transfers
         if (count($this->errors) == 0) {
             // transfer stock
             $stock_manager = StockManagerFactory::getManager();
             $is_transfer = $stock_manager->transferBetweenWarehouses($id_product, $id_product_attribute, $quantity, $id_warehouse_from, $id_warehouse_to, $usable_from, $usable_to);
             StockAvailable::synchronize($id_product);
             if ($is_transfer) {
                 Tools::redirectAdmin($redirect . '&conf=3');
             } else {
                 $this->errors[] = Tools::displayError('It is not possible to transfer the specified quantity. No stock was transferred.');
             }
         }
     }
 }
Ejemplo n.º 22
0
 public function postProcess()
 {
     if (Tools::isSubmit('submitAddmeta')) {
         $langs = Language::getLanguages(false);
         $default_language = Configuration::get('PS_LANG_DEFAULT');
         if (Tools::getValue('page') != 'index') {
             $defaultLangIsValidated = Validate::isLinkRewrite(Tools::getValue('url_rewrite_' . $default_language));
             $englishLangIsValidated = Validate::isLinkRewrite(Tools::getValue('url_rewrite_1'));
         } else {
             // index.php can have empty rewrite rule
             $defaultLangIsValidated = !Tools::getValue('url_rewrite_' . $default_language) || Validate::isLinkRewrite(Tools::getValue('url_rewrite_' . $default_language));
             $englishLangIsValidated = !Tools::getValue('url_rewrite_1') || Validate::isLinkRewrite(Tools::getValue('url_rewrite_1'));
         }
         if (!$defaultLangIsValidated && !$englishLangIsValidated) {
             $this->errors[] = Tools::displayError('The URL rewrite field must be filled in either the default or English language.');
             return false;
         }
         foreach ($langs as $lang) {
             $current = Tools::getValue('url_rewrite_' . $lang['id_lang']);
             if (strlen($current) == 0) {
                 // Prioritize default language first
                 if ($defaultLangIsValidated) {
                     $_POST['url_rewrite_' . $lang['id_lang']] = Tools::getValue('url_rewrite_' . $default_language);
                 } else {
                     $_POST['url_rewrite_' . $lang['id_lang']] = Tools::getValue('url_rewrite_1');
                 }
             }
         }
         Hook::exec('actionAdminMetaSave');
     } else {
         if (Tools::isSubmit('submitRobots')) {
             $this->generateRobotsFile();
         }
     }
     if (Tools::isSubmit('PS_ROUTE_product_rule')) {
         Tools::clearCache($this->context->smarty);
     }
     return parent::postProcess();
 }
Ejemplo n.º 23
0
 public function postProcess()
 {
     if (isset($_GET['delete' . $this->table])) {
         if ($this->tabAccess['delete'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject()) && isset($this->fieldImageSettings)) {
                 // English is needed by the system (ex. translations)
                 if ($object->id == Language::getIdByIso('en')) {
                     $this->errors[] = $this->l('You cannot delete the English language because it is a system requirement, you can only deactivate it.');
                 }
                 if ($object->id == Configuration::get('PS_LANG_DEFAULT')) {
                     $this->errors[] = $this->l('You cannot delete the default language');
                 } else {
                     if ($object->id == $this->context->language->id) {
                         $this->errors[] = $this->l('You cannot delete the language currently in use. Please change languages before deleting.');
                     } else {
                         if ($this->deleteNoPictureImages((int) Tools::getValue('id_lang')) && $object->delete()) {
                             Tools::redirectAdmin(self::$currentIndex . '&conf=1' . '&token=' . $this->token);
                         }
                     }
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while deleting object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete here.');
         }
     } else {
         if (Tools::getValue('submitDel' . $this->table) && isset($_POST[$this->table . 'Box'])) {
             if ($this->tabAccess['delete'] === '1') {
                 if (in_array(Configuration::get('PS_LANG_DEFAULT'), $_POST[$this->table . 'Box'])) {
                     $this->errors[] = $this->l('You cannot delete the default language');
                 } else {
                     if (in_array($this->context->language->id, $_POST[$this->table . 'Box'])) {
                         $this->errors[] = $this->l('you cannot delete the language currently in use, please change languages before deleting');
                     } else {
                         foreach ($_POST[$this->table . 'Box'] as $language) {
                             $this->deleteNoPictureImages($language);
                         }
                         parent::postProcess();
                     }
                 }
             } else {
                 $this->errors[] = Tools::displayError('You do not have permission to delete here.');
             }
         } else {
             if (Tools::isSubmit('submitAddlang')) {
                 /* New language */
                 if ((int) Tools::getValue('id_' . $this->table) == 0) {
                     if ($this->tabAccess['add'] === '1') {
                         if (isset($_POST['iso_code']) && !empty($_POST['iso_code']) && Validate::isLanguageIsoCode(Tools::getValue('iso_code')) && Language::getIdByIso($_POST['iso_code'])) {
                             $this->errors[] = Tools::displayError('This ISO code is already linked to another language.');
                         }
                         if ((!empty($_FILES['no-picture']['tmp_name']) || !empty($_FILES['flag']['tmp_name'])) && Validate::isLanguageIsoCode(Tools::getValue('iso_code'))) {
                             if ($_FILES['no-picture']['error'] == UPLOAD_ERR_OK) {
                                 $this->copyNoPictureImage(strtolower(Tools::getValue('iso_code')));
                             }
                             // class AdminTab deal with every $_FILES content, don't do that for no-picture
                             unset($_FILES['no-picture']);
                             parent::postProcess();
                         } else {
                             $this->validateRules();
                             $this->errors[] = Tools::displayError('Flag and "No picture" image fields are required.');
                         }
                     } else {
                         $this->errors[] = Tools::displayError('You do not have permission to add here.');
                     }
                 } else {
                     if ($this->tabAccess['edit'] === '1') {
                         if ((isset($_FILES['no-picture']) && !$_FILES['no-picture']['error'] || isset($_FILES['flag']) && !$_FILES['flag']['error']) && Validate::isLanguageIsoCode(Tools::getValue('iso_code'))) {
                             if ($_FILES['no-picture']['error'] == UPLOAD_ERR_OK) {
                                 $this->copyNoPictureImage(strtolower(Tools::getValue('iso_code')));
                             }
                             // class AdminTab deal with every $_FILES content, don't do that for no-picture
                             unset($_FILES['no-picture']);
                             parent::postProcess();
                         }
                         if (!Validate::isLoadedObject($object = $this->loadObject())) {
                             $this->errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
                         }
                         if ((int) $object->id == (int) Configuration::get('PS_LANG_DEFAULT') && (int) $_POST['active'] != (int) $object->active) {
                             $this->errors[] = Tools::displayError('You cannot change the status of the default language.');
                         } else {
                             parent::postProcess();
                         }
                         $this->validateRules();
                     } else {
                         $this->errors[] = Tools::displayError('You do not have permission to edit here.');
                     }
                 }
             } else {
                 if (isset($_GET['status' . $this->table]) && isset($_GET['id_lang'])) {
                     if ($this->tabAccess['edit'] === '1') {
                         if (!Validate::isLoadedObject($object = $this->loadObject())) {
                             $this->errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
                         }
                         if ((int) $object->id == (int) Configuration::get('PS_LANG_DEFAULT')) {
                             $this->errors[] = Tools::displayError('You cannot change the status of the default language.');
                         } else {
                             return parent::postProcess();
                         }
                     } else {
                         $this->errors[] = Tools::displayError('You do not have permission to edit here.');
                     }
                 } else {
                     return parent::postProcess();
                 }
             }
         }
     }
 }
Ejemplo n.º 24
0
 /**
  * This functions make checks about AdminThemes configuration edition only.
  *
  * @since 1.4
  */
 public function postProcess()
 {
     if (Tools::isSubmit('submitOptionstheme') && Tools::isSubmit('id_theme') && !Tools::isSubmit('deletetheme') && Tools::getValue('action') != 'ThemeInstall' && $this->context->shop->id_theme != Tools::getValue('id_theme')) {
         $this->display = "ChooseThemeModule";
     } else {
         // new check compatibility theme feature (1.4) :
         $val = Tools::getValue('PS_THEME');
         Configuration::updateValue('PS_IMG_UPDATE_TIME', time());
         if (!empty($val) && !$this->_isThemeCompatible($val)) {
             // don't submit if errors
             unset($_POST['submitThemes' . $this->table]);
         }
         Tools::clearCache($this->context->smarty);
         return parent::postProcess();
     }
 }
Ejemplo n.º 25
0
 public function postProcess()
 {
     $this->context = Context::getContext();
     if (Tools::isSubmit('deleteorder_return_detail')) {
         if ($this->tabAccess['delete'] === '1') {
             if (($id_order_detail = (int) Tools::getValue('id_order_detail')) && Validate::isUnsignedId($id_order_detail)) {
                 if (($id_order_return = (int) Tools::getValue('id_order_return')) && Validate::isUnsignedId($id_order_return)) {
                     $orderReturn = new OrderReturn($id_order_return);
                     if (!Validate::isLoadedObject($orderReturn)) {
                         die(Tools::displayError());
                     }
                     if ((int) $orderReturn->countProduct() > 1) {
                         if (OrderReturn::deleteOrderReturnDetail($id_order_return, $id_order_detail, (int) Tools::getValue('id_customization', 0))) {
                             Tools::redirectAdmin(self::$currentIndex . '&conf=4token=' . $this->token);
                         } else {
                             $this->errors[] = Tools::displayError('An error occurred while deleting the details of your order return.');
                         }
                     } else {
                         $this->errors[] = Tools::displayError('You need at least one product.');
                     }
                 } else {
                     $this->errors[] = Tools::displayError('The order return is invalid.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('The order return content is invalid.');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('submitAddorder_return') || Tools::isSubmit('submitAddorder_returnAndStay')) {
         if ($this->tabAccess['edit'] === '1') {
             if (($id_order_return = (int) Tools::getValue('id_order_return')) && Validate::isUnsignedId($id_order_return)) {
                 $orderReturn = new OrderReturn($id_order_return);
                 $order = new Order($orderReturn->id_order);
                 $customer = new Customer($orderReturn->id_customer);
                 $orderReturn->state = (int) Tools::getValue('state');
                 if ($orderReturn->save()) {
                     $orderReturnState = new OrderReturnState($orderReturn->state);
                     $vars = array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order_return}' => $id_order_return, '{state_order_return}' => isset($orderReturnState->name[(int) $order->id_lang]) ? $orderReturnState->name[(int) $order->id_lang] : $orderReturnState->name[(int) Configuration::get('PS_LANG_DEFAULT')]);
                     Mail::Send((int) $order->id_lang, 'order_return_state', Mail::l('Your order return status has changed', $order->id_lang), $vars, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, true, (int) $order->id_shop);
                     if (Tools::isSubmit('submitAddorder_returnAndStay')) {
                         Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token . '&updateorder_return&id_order_return=' . (int) $id_order_return);
                     } else {
                         Tools::redirectAdmin(self::$currentIndex . '&conf=4&token=' . $this->token);
                     }
                 }
             } else {
                 $this->errors[] = Tools::displayError('No order return ID has been specified.');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     }
     parent::postProcess();
 }
Ejemplo n.º 26
0
 public function postProcess()
 {
     if (_PS_MODE_DEMO_) {
         $this->errors[] = $this->trans('This functionality has been disabled.', array(), 'Admin.Notifications.Error');
         return;
     }
     if (Tools::isSubmit('submitAdd' . $this->table)) {
         $id = (int) Tools::getValue('id_attachment');
         if ($id && ($a = new Attachment($id))) {
             $_POST['file'] = $a->file;
             $_POST['mime'] = $a->mime;
         }
         if (!count($this->errors)) {
             if (isset($_FILES['file']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
                 if ($_FILES['file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) {
                     $this->errors[] = $this->trans('The file is too large. Maximum size allowed is: %1$d kB. The file you are trying to upload is %2$d kB.', array('%1$d' => Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024, '%2$d' => number_format($_FILES['file']['size'] / 1024, 2, '.', '')), 'Admin.Notifications.Error');
                 } else {
                     do {
                         $uniqid = sha1(microtime());
                     } while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid));
                     if (!move_uploaded_file($_FILES['file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) {
                         $this->errors[] = $this->trans('Failed to copy the file.', array(), 'Admin.Catalog.Notification');
                     }
                     $_POST['file_name'] = $_FILES['file']['name'];
                     @unlink($_FILES['file']['tmp_name']);
                     if (!sizeof($this->errors) && isset($a) && file_exists(_PS_DOWNLOAD_DIR_ . $a->file)) {
                         unlink(_PS_DOWNLOAD_DIR_ . $a->file);
                     }
                     $_POST['file'] = $uniqid;
                     $_POST['mime'] = $_FILES['file']['type'];
                 }
             } elseif (array_key_exists('file', $_FILES) && (int) $_FILES['file']['error'] === 1) {
                 $max_upload = (int) ini_get('upload_max_filesize');
                 $max_post = (int) ini_get('post_max_size');
                 $upload_mb = min($max_upload, $max_post);
                 $this->errors[] = sprintf($this->trans('The file %1$s exceeds the size allowed by the server. The limit is set to %2$d MB.', array(), 'Admin.Catalog.Notification'), '<b>' . $_FILES['file']['name'] . '</b> ', '<b>' . $upload_mb . '</b>');
             } elseif (!isset($a) || isset($a) && !file_exists(_PS_DOWNLOAD_DIR_ . $a->file)) {
                 $this->errors[] = $this->trans('Upload error. Please check your server configurations for the maximum upload size allowed.', array(), 'Admin.Catalog.Notification');
             }
         }
         $this->validateRules();
     }
     $return = parent::postProcess();
     if (!$return && isset($uniqid) && file_exists(_PS_DOWNLOAD_DIR_ . $uniqid)) {
         unlink(_PS_DOWNLOAD_DIR_ . $uniqid);
     }
     return $return;
 }
 /**
  * AdminController::postProcess() override
  * @see AdminController::postProcess()
  */
 public function postProcess()
 {
     // SupplyOrderState
     if (Tools::isSubmit('submitAddsupply_order_state') || Tools::isSubmit('deletesupply_order_state') || Tools::isSubmit('submitUpdatesupply_order_state')) {
         if (Tools::isSubmit('deletesupply_order_state')) {
             $this->action = 'delete';
         } else {
             $this->action = 'save';
         }
         $this->table = 'supply_order_state';
         $this->className = 'SupplyOrderState';
         $this->identifier = 'id_supply_order_state';
         $this->_defaultOrderBy = 'id_supply_order_state';
     } else {
         if (Tools::isSubmit('delete' . $this->table)) {
             $this->deleted = true;
         }
     }
     return parent::postProcess();
 }
 public function postProcess()
 {
     if (Tools::isSubmit('viewcms') && ($id_cms = (int) Tools::getValue('id_cms')) && ($cms = new CMS($id_cms, $this->context->language->id)) && Validate::isLoadedObject($cms)) {
         $redir = $this->context->link->getCMSLink($cms);
         if (!$cms->active) {
             $admin_dir = dirname($_SERVER['PHP_SELF']);
             $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
             $redir .= '?adtoken=' . Tools::getAdminTokenLite('AdminCmsContent') . '&ad=' . $admin_dir . '&id_employee=' . (int) $this->context->employee->id;
         }
         Tools::redirectAdmin($redir);
     } elseif (Tools::isSubmit('deletecms')) {
         if (Tools::getValue('id_cms') == Configuration::get('PS_CONDITIONS_CMS_ID')) {
             Configuration::updateValue('PS_CONDITIONS', 0);
             Configuration::updateValue('PS_CONDITIONS_CMS_ID', 0);
         }
         $cms = new CMS((int) Tools::getValue('id_cms'));
         $cms->cleanPositions($cms->id_cms_category);
         if (!$cms->delete()) {
             $this->errors[] = Tools::displayError('An error occurred while deleting the object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=1&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::getValue('submitDel' . $this->table)) {
         if ($this->tabAccess['delete'] === '1') {
             if (Tools::isSubmit($this->table . 'Box')) {
                 $cms = new CMS();
                 $result = true;
                 $result = $cms->deleteSelection(Tools::getValue($this->table . 'Box'));
                 if ($result) {
                     $cms->cleanPositions((int) Tools::getValue('id_cms_category'));
                     $token = Tools::getAdminTokenLite('AdminCmsContent');
                     Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . $token . '&id_cms_category=' . (int) Tools::getValue('id_cms_category'));
                 }
                 $this->errors[] = Tools::displayError('An error occurred while deleting this selection.');
             } else {
                 $this->errors[] = Tools::displayError('You must select at least one element to delete.');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('submitAddcms') || Tools::isSubmit('submitAddcmsAndPreview')) {
         parent::validateRules();
         if (count($this->errors)) {
             return false;
         }
         if (!($id_cms = (int) Tools::getValue('id_cms'))) {
             $cms = new CMS();
             $this->copyFromPost($cms, 'cms');
             if (!$cms->add()) {
                 $this->errors[] = Tools::displayError('An error occurred while creating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         } else {
             $cms = new CMS($id_cms);
             $this->copyFromPost($cms, 'cms');
             if (!$cms->update()) {
                 $this->errors[] = Tools::displayError('An error occurred while updating an object.') . ' <b>' . $this->table . ' (' . Db::getInstance()->getMsgError() . ')</b>';
             } else {
                 $this->updateAssoShop($cms->id);
             }
         }
         if (Tools::isSubmit('submitAddcmsAndPreview')) {
             $alias = $this->getFieldValue($cms, 'link_rewrite', $this->context->language->id);
             $preview_url = $this->context->link->getCMSLink($cms, $alias, $this->context->language->id);
             if (!$cms->active) {
                 $admin_dir = dirname($_SERVER['PHP_SELF']);
                 $admin_dir = substr($admin_dir, strrpos($admin_dir, '/') + 1);
                 $params = http_build_query(array('adtoken' => Tools::getAdminTokenLite('AdminCmsContent'), 'ad' => $admin_dir, 'id_employee' => (int) $this->context->employee->id));
                 if (Configuration::get('PS_REWRITING_SETTINGS')) {
                     $params = '?' . $params;
                 } else {
                     $params = '&' . $params;
                 }
                 $preview_url .= $cms->active ? '' : $params;
             }
             Tools::redirectAdmin($preview_url);
         } elseif (Tools::isSubmit('submitAdd' . $this->table . 'AndStay')) {
             Tools::redirectAdmin(self::$currentIndex . '&' . $this->identifier . '=' . $cms->id . '&conf=4&update' . $this->table . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&id_cms_category=' . $cms->id_cms_category . '&conf=4&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('way') && Tools::isSubmit('id_cms') && Tools::isSubmit('position')) {
         if ($this->tabAccess['edit'] !== '1') {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         } elseif (!Validate::isLoadedObject($object = $this->loadObject())) {
             $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
         } elseif (!$object->updatePosition((int) Tools::getValue('way'), (int) Tools::getValue('position'))) {
             $this->errors[] = Tools::displayError('Failed to update the position.');
         } else {
             Tools::redirectAdmin(self::$currentIndex . '&' . $this->table . 'Orderby=position&' . $this->table . 'Orderway=asc&conf=4&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getAdminTokenLite('AdminCmsContent'));
         }
     } elseif (Tools::isSubmit('statuscms') && Tools::isSubmit($this->identifier)) {
         if ($this->tabAccess['edit'] === '1') {
             if (Validate::isLoadedObject($object = $this->loadObject())) {
                 if ($object->toggleStatus()) {
                     Tools::redirectAdmin(self::$currentIndex . '&conf=5&id_cms_category=' . (int) $object->id_cms_category . '&token=' . Tools::getValue('token'));
                 } else {
                     $this->errors[] = Tools::displayError('An error occurred while updating the status.');
                 }
             } else {
                 $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitBulkdeletecms')) {
         if ($this->tabAccess['delete'] === '1') {
             $this->action = 'bulkdelete';
             $this->boxes = Tools::getValue($this->table . 'Box');
             if (is_array($this->boxes) && array_key_exists(0, $this->boxes)) {
                 $firstCms = new CMS((int) $this->boxes[0]);
                 $id_cms_category = (int) $firstCms->id_cms_category;
                 if (!($res = parent::postProcess(true))) {
                     return $res;
                 }
                 Tools::redirectAdmin(self::$currentIndex . '&conf=2&token=' . Tools::getAdminTokenLite('AdminCmsContent') . '&id_cms_category=' . $id_cms_category);
             }
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } else {
         parent::postProcess(true);
     }
 }
Ejemplo n.º 29
0
 public function postProcess()
 {
     if (Tools::getValue('key') && strlen(Tools::getValue('key')) < 32) {
         $this->errors[] = Tools::displayError($this->l('Key length must be 32 character long.'));
     }
     if (WebserviceKey::keyExists(Tools::getValue('key')) && !Tools::getValue('id_webservice_account')) {
         $this->errors[] = Tools::displayError($this->l('This key already exists.'));
     }
     return parent::postProcess();
 }
 public function postProcess()
 {
     if (Tools::isSubmit('delete' . $this->table) || Tools::isSubmit('status') || Tools::isSubmit('status' . $this->table)) {
         $object = $this->loadObject();
         if (ShopGroup::getTotalShopGroup() == 1) {
             $this->errors[] = Tools::displayError('You cannot delete or disable the last shop group.');
         } elseif ($object->haveShops()) {
             $this->errors[] = Tools::displayError('You cannot delete or disable a shop group in use.');
         }
         if (count($this->errors)) {
             return false;
         }
     }
     return parent::postProcess();
 }