Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
        unset($cookie->dpdpoland_printout_format);
        $cookie->write();
        $package = new DpdPolandPackage((int) $package_id);
        $pdf_file_contents = $package->generateLabels('PDF', $printout_format);
        ob_end_clean();
        header('Content-type: application/pdf');
        header('Content-Disposition: attachment; filename="package_labels_' . (int) Tools::getValue('id_package_ws') . '.pdf"');
        echo $pdf_file_contents;
        exit;
    }
    $package = new DpdPolandPackage((int) Tools::getValue('id_package_ws'));
    if ($pdf_file_contents = $package->generateLabels()) {
        $cookie->dpdpoland_package_id = (int) Tools::getValue('id_package_ws');
        $printout_format = Tools::getValue('printout_format');
        if (!in_array($printout_format, array(DpdPolandConfiguration::PRINTOUT_FORMAT_A4, DpdPolandConfiguration::PRINTOUT_FORMAT_LABEL))) {
            $printout_format = DpdPolandConfiguration::PRINTOUT_FORMAT_A4;
        }
        $cookie->dpdpoland_printout_format = $printout_format;
        Tools::redirectAdmin(Tools::getValue('returnOnErrorTo') . '&scrollToShipment');
        exit;
    } else {
        DpdPoland::addFlashError(reset(DpdPolandPackageWS::$errors));
        Tools::redirectAdmin(Tools::getValue('returnOnErrorTo') . '&scrollToShipment');
        exit;
    }
}
if (Tools::isSubmit('downloadModuleCSVSettings')) {
    include_once _DPDPOLAND_CONTROLLERS_DIR_ . 'csv.controller.php';
    $controller = new DpdPolandCSVController();
    $controller->generateCSV();
}