public static function printManifest($module_instance)
 {
     $cookie = Context::getContext()->cookie;
     if (isset($cookie->dpdpoland_packages_ids)) {
         if (version_compare(_PS_VERSION_, '1.5', '<')) {
             $package_ids = unserialize(Context::getContext()->cookie->dpdpoland_packages_ids);
         } else {
             $package_ids = Tools::unSerialize(Context::getContext()->cookie->dpdpoland_packages_ids);
         }
         unset($cookie->dpdpoland_packages_ids);
         $cookie->write();
         $separated_packages = DpdPolandPackage::separatePackagesBySession($package_ids);
         $international_packages = $separated_packages['INTERNATIONAL'];
         $domestic_packages = $separated_packages['DOMESTIC'];
         $manifest_ids = array();
         if ($international_packages) {
             $manifest_ids[] = DpdPolandManifest::getManifestIdWsByPackageIdWs($international_packages[0]);
         }
         if ($domestic_packages) {
             $manifest_ids[] = DpdPolandManifest::getManifestIdWsByPackageIdWs($domestic_packages[0]);
         }
         require_once _DPDPOLAND_CONTROLLERS_DIR_ . 'manifestList.controller.php';
         $manifest_controller = new DpdPolandManifestListController();
         return $manifest_controller->printManifest($manifest_ids);
     }
     if ($package_ids = Tools::getValue('PackagesBox')) {
         if (!DpdPolandManifest::validateSenderAddresses($package_ids)) {
             $error_message = $module_instance->l('Manifests can not have different sender addresses', self::FILENAME);
             $error = $module_instance->displayError($error_message);
             return $module_instance->outputHTML($error);
         }
         $separated_packages = DpdPolandPackage::separatePackagesBySession($package_ids);
         $international_packages = $separated_packages['INTERNATIONAL'];
         $domestic_packages = $separated_packages['DOMESTIC'];
         if ($international_packages) {
             $manifest = new DpdPolandManifest();
             if (!$manifest->generateMultiple($international_packages)) {
                 $error = $module_instance->displayError(reset(DpdPolandManifestWS::$errors));
                 return $module_instance->outputHTML($error);
             }
         }
         if ($domestic_packages) {
             $manifest = new DpdPolandManifest();
             if (!$manifest->generateMultiple($domestic_packages)) {
                 $error = $module_instance->displayError(reset(DpdPolandManifestWS::$errors));
                 return $module_instance->outputHTML($error);
             }
         }
         $cookie->dpdpoland_packages_ids = serialize($package_ids);
         $redirect_uri = $module_instance->module_url . '&menu=packages_list';
         die(Tools::redirectAdmin($redirect_uri));
     }
 }
Пример #2
0
 public function getContent()
 {
     $this->html .= $this->getContentHeader();
     if (!$this->soapClientExists()) {
         return $this->adminDisplayWarning($this->l('SoapClient class is missing'));
     }
     if (_DPDPOLAND_DEBUG_MODE_) {
         $this->displayDebugInfo();
     }
     $this->displayFlashMessagesIfIsset();
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         $this->addJS(_DPDPOLAND_JS_URI_ . 'backoffice.js');
         $this->addCSS(_DPDPOLAND_CSS_URI_ . 'backoffice.css');
         $this->addCSS(_DPDPOLAND_CSS_URI_ . 'toolbar.css');
     } else {
         $this->context->controller->addJS(_DPDPOLAND_JS_URI_ . 'backoffice.js');
         $this->context->controller->addCSS(_DPDPOLAND_CSS_URI_ . 'backoffice.css');
     }
     $this->setGlobalVariablesForAjax();
     $this->html .= $this->context->smarty->fetch(_DPDPOLAND_TPL_DIR_ . 'admin/global_variables.tpl');
     $country_currency_error_message_text = $this->l('PL country and PLN currency must be installed; CURL must be enabled');
     $configuration_error_message_text = $this->l('Module is not configured yet. Please check required settings');
     $current_page = Tools::getValue('menu');
     $required_configuration = DpdPolandConfiguration::checkRequiredConfiguration();
     if (!$current_page && !$required_configuration) {
         $current_page = 'configuration';
     }
     switch ($current_page) {
         case 'arrange_pickup':
             $this->addDateTimePickerPlugins();
             require_once _DPDPOLAND_CONTROLLERS_DIR_ . 'arrange_pickup.controller.php';
             $controller = new DpdPolandArrangePickUpController();
             if (Tools::isSubmit('requestPickup')) {
                 $data = $controller->getData();
                 if ($controller->validate()) {
                     $pickup = new DpdPolandPickup();
                     foreach ($data as $element => $value) {
                         $pickup->{$element} = $value;
                     }
                     if (!$pickup->arrange()) {
                         $this->html .= $this->displayError(reset(DpdPolandPickup::$errors));
                     } else {
                         $error_message = sprintf($this->l('Pickup was successfully arranged. Number of order is: %d'), $pickup->id_pickup);
                         self::addFlashMessage($error_message);
                         $redirect_uri = $this->module_url . '&menu=arrange_pickup';
                         die(Tools::redirectAdmin($redirect_uri));
                     }
                 } else {
                     $this->html .= $this->displayError(reset(DpdPolandArrangePickUpController::$errors));
                 }
             }
             $this->context->smarty->assign('breadcrumb', array($this->displayName, $this->l('Arrange PickUp')));
             $this->displayNavigation();
             if (!$this->checkModuleAvailability()) {
                 return $this->html .= $this->displayErrors(array($country_currency_error_message_text));
             }
             if (!$required_configuration) {
                 return $this->html .= $this->displayErrors(array($configuration_error_message_text));
             }
             $this->html .= $controller->getPage();
             break;
         case 'configuration':
             require_once _DPDPOLAND_CONTROLLERS_DIR_ . 'configuration.controller.php';
             $controller = new DpdPolandConfigurationController();
             if (Tools::isSubmit(DpdPolandConfigurationController::SETTINGS_SAVE_ACTION)) {
                 $controller->validateSettings();
                 $controller->createDeleteCarriers();
                 if (!DpdPolandConfigurationController::$errors) {
                     $controller->saveSettings();
                 } else {
                     $this->html .= $this->displayErrors(DpdPolandConfigurationController::$errors);
                 }
             }
             $this->context->smarty->assign('breadcrumb', array($this->displayName, $this->l('Settings')));
             $this->displayNavigation();
             if (!$this->checkModuleAvailability()) {
                 return $this->html .= $this->displayErrors(array($country_currency_error_message_text));
             }
             if (!$required_configuration) {
                 $this->html .= $this->displayErrors(array($configuration_error_message_text));
             }
             if (!version_compare(_PS_VERSION_, '1.5', '<')) {
                 $this->displayShopRestrictionWarning();
             }
             $this->html .= $controller->getSettingsPage();
             break;
         case 'csv':
             require_once _DPDPOLAND_CONTROLLERS_DIR_ . 'csv.controller.php';
             $controller = new DpdPolandCSVController();
             if (Tools::isSubmit(DpdPolandCSVController::SETTINGS_SAVE_CSV_ACTION)) {
                 $csv_data = $controller->readCSVData();
                 if ($csv_data === false) {
                     self::addFlashError($this->l('Wrong CSV file'));
                     Tools::redirectAdmin($this->module_url . '&menu=csv');
                 }
                 $message = $controller->validateCSVData($csv_data);
                 if ($message !== true) {
                     $this->html .= $this->displayErrors($message);
                 } else {
                     if ($controller->saveCSVData($csv_data)) {
                         self::addFlashMessage($this->l('CSV data was successfully saved'));
                     } else {
                         self::addFlashError($this->l('CSV data could not be saved'));
                     }
                     Tools::redirectAdmin($this->module_url . '&menu=csv');
                 }
             }
             if (Tools::isSubmit(DpdPolandCSVController::SETTINGS_DELETE_CSV_ACTION)) {
                 $controller->deleteCSV();
             }
             $this->context->smarty->assign('breadcrumb', array($this->displayName, $this->l('CSV prices import')));
             $this->displayNavigation();
             if (!$this->checkModuleAvailability()) {
                 return $this->html .= $this->displayErrors(array($country_currency_error_message_text));
             }
             if (!$required_configuration) {
                 return $this->html .= $this->displayErrors(array($configuration_error_message_text));
             }
             if (!version_compare(_PS_VERSION_, '1.5', '<') && Shop::getContext() != Shop::CONTEXT_SHOP) {
                 $this->html .= $this->displayWarnings(array($this->l('CSV management is disabled when all shops or group of shops are selected')));
                 break;
             }
             $this->html .= $controller->getCSVPage();
             break;
         case 'help':
             $this->context->smarty->assign('breadcrumb', array($this->displayName, $this->l('Help')));
             $this->displayNavigation();
             $this->html .= $this->displayHelp();
             break;
         case 'manifest_list':
             $this->context->smarty->assign('breadcrumb', array($this->displayName, $this->l('Manifest list')));
             $this->displayNavigation();
             if (!$this->checkModuleAvailability()) {
                 return $this->html .= $this->displayErrors(array($country_currency_error_message_text));
             }
             if (!$required_configuration) {
                 return $this->html .= $this->displayErrors(array($configuration_error_message_text));
             }
             if (!version_compare(_PS_VERSION_, '1.5', '<') && Shop::getContext() != Shop::CONTEXT_SHOP) {
                 $this->html .= $this->displayWarnings(array($this->l('Manifests functionality is disabled when all shops or group of shops are chosen')));
                 break;
             }
             $this->addDateTimePickerPlugins();
             require_once _DPDPOLAND_CONTROLLERS_DIR_ . 'manifestList.controller.php';
             $manifest_list_controller = new DpdPolandManifestListController();
             if (Tools::isSubmit('printManifest')) {
                 $id_manifest_ws = (int) Tools::getValue('id_manifest_ws');
                 $manifest_list_controller->printManifest((int) $id_manifest_ws);
             }
             $this->html .= $manifest_list_controller->getListHTML();
             break;
         case 'parcel_history_list':
             $this->context->smarty->assign('breadcrumb', array($this->displayName, $this->l('Parcels history')));
             $this->displayNavigation();
             if (!$this->checkModuleAvailability()) {
                 return $this->html .= $this->displayErrors(array($country_currency_error_message_text));
             }
             if (!$required_configuration) {
                 return $this->html .= $this->displayErrors(array($configuration_error_message_text));
             }
             if (!version_compare(_PS_VERSION_, '1.5', '<') && Shop::getContext() != Shop::CONTEXT_SHOP) {
                 $this->html .= $this->displayWarnings(array($this->l('Parcels functionality is disabled when all shops or group of shops are chosen')));
                 break;
             }
             $this->addDateTimePickerPlugins();
             require_once _DPDPOLAND_CONTROLLERS_DIR_ . 'parcelHistoryList.controller.php';
             $parcel_history_list_controller = new DpdPolandParcelHistoryController();
             $this->html .= $parcel_history_list_controller->getList();
             break;
         case 'country_list':
             $this->context->smarty->assign('breadcrumb', array($this->displayName, $this->l('Shipment countries')));
             $this->displayNavigation();
             if (!$this->checkModuleAvailability()) {
                 return $this->html .= $this->displayErrors(array($country_currency_error_message_text));
             }
             if (!$required_configuration) {
                 return $this->html .= $this->displayErrors(array($configuration_error_message_text));
             }
             if (!version_compare(_PS_VERSION_, '1.5', '<') && Shop::getContext() != Shop::CONTEXT_SHOP) {
                 $this->html .= $this->displayWarnings(array($this->l('Countries functionality is disabled when all shops or group of shops are chosen')));
                 break;
             }
             require_once _DPDPOLAND_CONTROLLERS_DIR_ . 'countryList.controller.php';
             $country_list_controller = new DpdPolandCountryListController();
             if (Tools::getValue('disable_country') && ($id_country = Tools::getValue('id_country'))) {
                 if ($country_list_controller->changeEnabled((int) $id_country, true)) {
                     $country_list_controller->displaySuccessStatusChangingMessage();
                 } else {
                     $this->displayError($this->l('Could not change country status'));
                 }
             }
             if (Tools::getValue('enable_country') && ($id_country = Tools::getValue('id_country'))) {
                 if ($country_list_controller->changeEnabled((int) $id_country)) {
                     $country_list_controller->displaySuccessStatusChangingMessage();
                 } else {
                     $this->displayError($this->l('Could not change country status'));
                 }
             }
             if (Tools::isSubmit('disableCountries')) {
                 if ($countries = Tools::getValue('CountriesBox')) {
                     $country_list_controller->changeEnabledMultipleCountries($countries, true);
                 } else {
                     $this->html .= $this->displayError($this->l('No selected countries'));
                 }
             }
             if (Tools::isSubmit('enableCountries')) {
                 if ($countries = Tools::getValue('CountriesBox')) {
                     $country_list_controller->changeEnabledMultipleCountries($countries);
                 } else {
                     $this->html .= $this->displayError($this->l('No selected countries'));
                 }
             }
             $this->html .= $country_list_controller->getListHTML();
             break;
         case 'packages_list':
         default:
             $this->context->smarty->assign('breadcrumb', array($this->displayName, $this->l('Packages')));
             $this->displayNavigation();
             if (!$this->checkModuleAvailability()) {
                 return $this->html .= $this->displayErrors(array($country_currency_error_message_text));
             }
             if (!$required_configuration) {
                 return $this->html .= $this->displayErrors(array($configuration_error_message_text));
             }
             if (!version_compare(_PS_VERSION_, '1.5', '<') && Shop::getContext() != Shop::CONTEXT_SHOP) {
                 $this->html .= $this->displayWarnings(array($this->l('Packages functionality is disabled when all shops or group of shops are chosen')));
                 break;
             }
             $this->addDateTimePickerPlugins();
             require_once _DPDPOLAND_CONTROLLERS_DIR_ . 'packageList.controller.php';
             if (Tools::isSubmit('printManifest')) {
                 DpdPolandPackageListController::printManifest($this);
             }
             if (Tools::isSubmit('printLabelsA4Format')) {
                 DpdPolandPackageListController::printLabels(DpdPolandConfiguration::PRINTOUT_FORMAT_A4);
             }
             if (Tools::isSubmit('printLabelsLabelFormat')) {
                 DpdPolandPackageListController::printLabels(DpdPolandConfiguration::PRINTOUT_FORMAT_LABEL);
             }
             $package_list_controller = new DpdPolandPackageListController();
             $this->html .= $package_list_controller->getList();
             break;
     }
     return $this->html;
 }