public function postProcess()
 {
     $output_success = array();
     $output_error = array();
     // check existing licence and load it if valid
     if (Tools::isSubmit('submitCheckLoadLicence')) {
         // check licence
         $obLicence = new Licence();
         $obLicence->number = Configuration::get('ERP_LICENCE');
         $result = $obLicence->loadLicence();
         // no error
         if ($result['error'] == false) {
             // redirect to module configuration
             Tools::redirectAdmin('?controller=AdminModules&configure=erpillicopresta&conf=4&token=' . Tools::getAdminTokenLite('AdminModules'));
         } else {
             $output_error[] = $result['msg'];
         }
     } else {
         if (Tools::isSubmit('submitValidateHasLicence')) {
             $existing_license = Tools::getValue('erp_set_licence');
             $has_licence_number = Tools::getValue('erp_has_licence_number');
             // the merchant already has a license number
             if ($has_licence_number == 1) {
                 // check licence validation
                 if (!empty($existing_license)) {
                     // Check if licence exists in server
                     $obLicence = new Licence();
                     $obLicence->number = $existing_license;
                     $result = $obLicence->loadLicence();
                     // the licence exist we save it and install all controller
                     if ($result['error'] == false) {
                         // redirect to module configuration
                         Tools::redirectAdmin('?controller=AdminModules&configure=erpillicopresta&conf=4&token=' . Tools::getAdminTokenLite('AdminModules'));
                     } else {
                         $output_error[] = $result['msg'];
                     }
                 } else {
                     $output_error[] = $this->l('Please enter your existing license number.');
                 }
             } else {
                 $this->diplayFormHasLicence = false;
             }
         } elseif (Tools::isSubmit('submitCreateNewLicence')) {
             // get configuration value
             $email = Configuration::get('PS_SHOP_EMAIL');
             $licence_number = Configuration::get('ERP_NEW_LICENCE');
             // get activation form input
             $domaine_name = Tools::getValue('erp_licence_domaine_name');
             // entered domaine name
             $licence_password = Tools::getValue('erp_licence_password');
             // entered licence password
             $contact_name = Tools::getValue('erp_contact_name');
             // entered contact name
             $_erp_cgv = Tools::isSubmit('_erp_cgv');
             // entered CGV
             $selected_feature = Tools::getValue('selected_feature');
             // selected feature to create a new basket
             $contact_mail = Tools::getValue('erp_contact_mail');
             // entered contact mail
             // is a free licence or not
             $licence_is_free = Tools::getValue('erp_licence_is_free', null) === '1' ? true : false;
             // if contact mail is given
             if (!empty($contact_mail)) {
                 $email = $contact_mail;
                 Configuration::updateValue('ERP_CONTACT_MAIL', $email);
                 // save ontact mail in configuration
             }
             // check value
             if ($licence_number != '' && $email != '' && $domaine_name != '' && $licence_password != '' && $contact_name != '' && $_erp_cgv) {
                 // if feature not empty
                 if (!empty($selected_feature)) {
                     // if get checksum for each file
                     if (Licence::getChecksum(_PS_MODULE_DIR_ . 'erpillicopresta')) {
                         // Create global checksum
                         $checksum = md5(serialize(ErpIllicopresta::$checksum));
                         Configuration::updateValue('ERP_CHECKSUM', $checksum);
                         // create a new licence
                         $objLicence = new Licence();
                         $objLicence->number = $licence_number;
                         // Data to create a new licence
                         $objLicence->post_data = array('number' => $licence_number, 'mode' => 'purchase', 'email' => $email, 'password' => $licence_password, 'domain_name' => $domaine_name, 'active' => 1, 'blacklist' => 0, 'date_add' => date('Y-m-d H:i:s'), 'date_upd' => date('Y-m-d H:i:s'), 'date_end' => NULL);
                         // create a new licence
                         $result_add_licence = $objLicence->addLicence();
                         // if no error while creating licence
                         if ($result_add_licence['error'] == false) {
                             // To know when the module is properly configured
                             Configuration::updateValue('ERP_CONFIGURATION_OK', true);
                             //is free licence, redirect to module configuration
                             if ($licence_is_free === true) {
                                 Tools::redirectAdmin('?controller=AdminModules&configure=erpillicopresta&conf=4&token=' . Tools::getAdminTokenLite('AdminModules'));
                             } else {
                                 $url = ERP_URL_ESHOP . $this->iso_code . '/?passkeyUpdateCart=' . urlencode(base64_encode(sha1('updateCart') . '||' . PRIVATE_KEY . '||' . $licence_number . '||' . 'add' . '||' . implode(',', $selected_feature)));
                                 $url .= '&' . ERP_TAGS_GA_COMMANDE;
                                 $this->context->cookie->__set('erp_do_redirect_shop', $url);
                                 Tools::redirectAdmin('?controller=AdminModules&configure=erpillicopresta&conf=4&token=' . Tools::getAdminTokenLite('AdminModules'));
                             }
                         } else {
                             if ($result_add_licence['error'] == true) {
                                 $this->diplayFormHasLicence = false;
                                 $output_error[] = $result_add_licence['msg'];
                             }
                         }
                     } else {
                         $output_error[] = $this->l('Error while getting the checksum.') . '<br/>';
                     }
                 } else {
                     $output_error[] = $this->l('Error while getting the basket content.') . '<br/>';
                 }
             } else {
                 $output_error[] = $this->l('Dear merchant, please fill out the entire form above in order to finalise your order.') . '<br/>';
             }
         } elseif (Tools::isSubmit('submitUpdateBasket')) {
             $selected_feature = Tools::getValue('selected_feature');
             // selected feature to create a new basket
             $current_basket_ids = Tools::getValue('current_basket_ids');
             // list of current basket ids
             $licence_id = Configuration::get('ERP_LICENCE_ID');
             // if feature not empty
             if (!empty($selected_feature) && !empty($current_basket_ids) && !empty($licence_id)) {
                 // redirect to shop
                 $url = ERP_URL_ESHOP . $this->iso_code . '/?passkeyUpdateCart=' . urlencode(base64_encode(sha1('updateCart') . '||' . PRIVATE_KEY . '||' . Configuration::get('ERP_LICENCE') . '||' . 'update' . '||' . implode(',', $selected_feature)));
                 $url .= '&' . ERP_TAGS_GA_COMMANDE;
                 Tools::redirectLink($url);
             } else {
                 $output_error[] = $this->l('An error has occurred while retrieving the contents of your cart. ' . 'Either the ids of your current cart are empty or your license number is empty.') . '<br/>';
             }
         } else {
             if (Tools::isSubmit('submitGeneralSettings')) {
                 $result_general_setting = false;
                 // save enable/disable original menu of prestashop
                 if (Tools::getValue('erp_disable_original_menus') == 1) {
                     $result_general_setting = $this->changeStatusOfOriginalMenus(0);
                 } else {
                     $result_general_setting = $this->changeStatusOfOriginalMenus(1);
                 }
                 if ($result_general_setting) {
                     Configuration::updateValue('ERP_DISABLE_ORIGINAL_MENUS', (int) Tools::getValue('erp_disable_original_menus'));
                     $output_success[] = $this->l('General setting updated successfully') . '<br/>';
                 } else {
                     $output_error[] = $this->l('Error while saving general settings. Please try again.') . '<br/>';
                 }
             } else {
                 if (Tools::isSubmit('submitInventorySettings')) {
                     if (Configuration::get(self::getControllerStatusName('AdminInventory'))) {
                         // Get "gap" value
                         $gap_stock = (string) Tools::getValue('erp_gap_stock');
                         // If it is an unsigned int
                         if (!ctype_digit($gap_stock)) {
                             $output_error[] = $this->l('Invalid stock gap value ! The stock gap value must be a positive integer.') . '<br/>';
                         } else {
                             // if value "0", then we delete gap in database
                             if ((int) $gap_stock == 0) {
                                 $gap_stock = '';
                             }
                             // if ok we insert / update in configuration
                             Configuration::updateValue('ERP_GAP_STOCK', $gap_stock);
                             $output_success[] = $this->l('Inventory settings updated successfully') . '<br/>';
                         }
                     }
                 } else {
                     if (Tools::isSubmit('submitAdvancedOrderSettings')) {
                         // save stock level configuration
                         $erp_level_stock_alert = Tools::getValue('erp_level_stock_alert');
                         $erp_level_stock_normal = Tools::getValue('erp_level_stock_normal');
                         $sauve1 = Configuration::updateValue('ERP_LEVEL_STOCK_ALERT', $erp_level_stock_alert);
                         $sauve2 = Configuration::updateValue('ERP_LEVEL_STOCK_NORMAL', $erp_level_stock_normal);
                         // save status_warning_stock
                         $order_states = OrderState::getOrderStates((int) $this->context->language->id);
                         foreach ($order_states as $state) {
                             if (Tools::isSubmit('erp_status_warning_stock_' . $state['id_order_state'])) {
                                 Configuration::updateValue('ERP_STATUS_WARNING_STOCK_' . $state['id_order_state'], 'on');
                             } else {
                                 Configuration::updateValue('ERP_STATUS_WARNING_STOCK_' . $state['id_order_state'], '');
                             }
                         }
                         if ($sauve1 && $sauve2) {
                             $output_success[] = $this->l('Advanced order settings updated successfully');
                         } else {
                             $output_error[] = $this->l('Error while saving advanced order settings !');
                         }
                     } elseif (Tools::isSubmit('submitAdvancedSupplyOrderSettings')) {
                         foreach (array_keys($this->field_name_configuration) as $field_name) {
                             if (Tools::isSubmit($field_name)) {
                                 if (Tools::strtoupper($field_name) == 'ERP_COEFFICIENTS') {
                                     $regex = '/^([0-9]+([\\.,][0-9]+)?;){5}([0-9]+([\\.,][0-9]+)?)$/';
                                     if (!preg_match($regex, Tools::getValue($field_name))) {
                                         $output_error[] = $this->l('The weighting coefficients that you filled out do not fit the required syntax ! Please rewrite the weighting coefficients.') . '<br/>';
                                         continue;
                                     } elseif (array_sum(explode(';', Tools::getValue($field_name))) == 0) {
                                         $output_error[] = $this->l('All weigthing coefficients must not be null at the same time !') . '<br/>';
                                         continue;
                                     }
                                 } elseif (!Configuration::updateValue(Tools::strtoupper($field_name), Tools::getValue($field_name))) {
                                     $output_error[] = $this->l('Error while saving supplier orders settings : ' . $field_name) . '<br/>';
                                     continue;
                                 }
                             }
                         }
                         $output_success[] = $this->l('Supplier orders settings updated successfully') . '<br/>';
                     }
                 }
             }
         }
     }
     // user has licence but it's not valid
     // If user has a non-valid licence (expired or else)
     if (Configuration::hasKey('ERP_LICENCE') && Configuration::get('ERP_LICENCE') != '' && Configuration::get('ERP_LICENCE_VALIDITY') != '1' && empty($output_error)) {
         // do not display cart
         $this->blockLicence = true;
         // display error message
         if (!Configuration::hasKey('ERP_MSG_AFTER_PROCESS')) {
             $output_error[] = $this->l('A license number exists for your store but is invalid.') . ' ' . sprintf($this->l('Please contact our technical service to this email: %s'), ERP_EMAIL_SUPPORT);
         }
     }
     $output_error_str = $output_success_str = '';
     if (!empty($output_success)) {
         foreach ($output_success as $success) {
             $output_success_str .= $this->displayConfirmation($success);
         }
     }
     if (!empty($output_error)) {
         $output_error_str = $this->displayErrorList($output_error);
     }
     return $output_error_str . $output_success_str;
 }
 public static function getChecksum($source_dir)
 {
     $dir = opendir($source_dir);
     if ($dir && in_array($source_dir, self::getListToChecksum())) {
         while ($file = readdir($dir)) {
             if (!in_array($file, self::getExcludeList($file))) {
                 if (!is_dir($source_dir . $GLOBALS["JxnebyjdFidXdVzNqnEb"] . $file)) {
                     array_push(ErpIllicopresta::$checksum, md5_file($source_dir . '/' . $file));
                 } else {
                     Licence::getChecksum($source_dir . $GLOBALS["JxnebyjdFidXdVzNqnEb"] . $file);
                 }
             }
         }
         return true;
     }
     return false;
 }