Beispiel #1
0
 /**
  * module configuration page
  * @return page HTML code
  */
 public function getContent()
 {
     $this->displayFlashMessagesIfIsset();
     if (!$this->ps_14) {
         $this->context->controller->addJS(_DPDGROUP_JS_URI_ . 'backoffice.js');
         if (!$this->bootstrap || Tools::getValue('menu') && Tools::getValue('menu') != 'shipment_list') {
             $this->context->controller->addCSS(_DPDGROUP_CSS_URI_ . 'backoffice.css');
         }
     }
     $this->setGlobalVariablesForAjax();
     $this->context->smarty->assign('dpd_geopost_other_country', DpdGroupConfiguration::OTHER_COUNTRY);
     $this->html .= $this->context->smarty->fetch(_DPDGROUP_TPL_DIR_ . 'admin/global_variables.tpl');
     if ($this->bootstrap) {
         $this->html .= $this->getBootstrapMenu();
     }
     $this->displayModuleWarnings();
     switch (Tools::getValue('menu')) {
         case 'configuration':
             require_once _DPDGROUP_CONTROLLERS_DIR_ . 'Configuration.controller.php';
             DpdGroupConfigurationController::init();
             if (!$this->bootstrap) {
                 $this->context->smarty->assign('path', array($this->displayName, $this->l('Settings')));
                 $this->displayNavigation();
             }
             if (!$this->ps_14) {
                 $this->displayShopRestrictionWarning();
             }
             $configuration_controller = new DpdGroupConfigurationController();
             $this->html .= $configuration_controller->getSettingsPage();
             break;
         case 'csv':
             require_once _DPDGROUP_CONTROLLERS_DIR_ . 'Csv.controller.php';
             DpdGroupCSVController::init();
             if (!$this->bootstrap) {
                 $this->context->smarty->assign('path', array($this->displayName, $this->l('Price rules')));
                 $this->displayNavigation();
             }
             if (!$this->ps_14) {
                 if (Shop::getContext() != Shop::CONTEXT_SHOP) {
                     $this->displayAdminWarning($this->l('CSV management is disabled when all shops or group of shops are selected'));
                     break;
                 }
             }
             $csv_controller = new DpdGroupCSVController();
             $this->html .= $csv_controller->getCSVPage();
             break;
         case 'postcode':
             require_once _DPDGROUP_CONTROLLERS_DIR_ . 'Postcode.controller.php';
             DpdGroupPostcodeController::init();
             if (!$this->bootstrap) {
                 $this->context->smarty->assign('path', array($this->displayName, $this->l('Postcodes update')));
                 $this->displayNavigation();
             }
             if (!$this->ps_14) {
                 if (Shop::getContext() != Shop::CONTEXT_SHOP) {
                     $this->displayAdminWarning($this->l('Postcodes management is disabled when all shops or group of shops are selected'));
                     break;
                 }
             }
             $psotcode_controller = new DpdGroupPostcodeController();
             $this->html .= $psotcode_controller->getPostcodePage();
             break;
         case 'help':
             if (!$this->bootstrap) {
                 $this->context->smarty->assign('path', array($this->displayName, $this->l('Help')));
                 $this->displayNavigation();
             }
             if (Tools::isSubmit('print_pdf')) {
                 $filename = 'dpdgroup_eng.pdf';
                 ob_end_clean();
                 header('Content-type: application/pdf');
                 header('Content-Disposition: attachment; filename="' . $this->l('manual') . '.pdf"');
                 readfile(_PS_MODULE_DIR_ . $this->name . '/manual/' . $filename);
                 exit;
             }
             $this->context->smarty->assign('module_link', $this->module_url);
             $this->html .= $this->context->smarty->fetch(_DPDGROUP_TPL_DIR_ . 'admin/help.tpl');
             break;
         case 'shipment_list':
         default:
             if ($this->ps_14) {
                 includeDatepicker(null);
             } else {
                 $this->context->controller->addJqueryUI(array('ui.slider', 'ui.datepicker'));
                 $this->context->controller->addJS(array(_DPDGROUP_JS_URI_ . 'jquery.bpopup.min.js', _PS_JS_DIR_ . 'jquery/plugins/timepicker/jquery-ui-timepicker-addon.js'));
                 $this->context->controller->addCSS(_PS_JS_DIR_ . 'jquery/plugins/timepicker/jquery-ui-timepicker-addon.css');
                 // for datetimepicker
             }
             if (!$this->bootstrap) {
                 $this->context->smarty->assign('path', array($this->displayName, $this->l('Shipments')));
                 $this->displayNavigation();
             } else {
                 $this->context->controller->addCSS(_DPDGROUP_CSS_URI_ . 'backoffice_16.css');
             }
             require_once _DPDGROUP_CONTROLLERS_DIR_ . 'ShipmentsList.controller.php';
             if (!$this->ps_14 && Configuration::getGlobalValue('PS_MULTISHOP_FEATURE_ACTIVE') && count(Shop::getShops(0)) > 1 && Shop::getContext() != Shop::CONTEXT_SHOP) {
                 $this->displayAdminWarning($this->l('Shipments functionality is disabled when all shops or group of shops are chosen'));
                 break;
             }
             $shipment_controller = new DpdGroupShipmentController();
             $this->html .= $shipment_controller->getShipmentList();
             break;
     }
     return $this->html;
 }
 public static function init()
 {
     $controller = new DpdGroupPostcodeController();
     if (Tools::isSubmit(DpdGroupPostcodeController::SETTINGS_SAVE_POSTCODE_ACTION)) {
         $csv_data = $controller->readCSVData();
         if ($csv_data === false) {
             DpdGroup::addFlashError($controller->l('Wrong CSV file'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         }
         $message = $controller->validatePostcodeData($csv_data);
         if ($message !== true) {
             return $controller->module_instance->outputHTML($controller->module_instance->displayError(implode('<br />', $message)));
         }
         if ($controller->saveCSVData($csv_data)) {
             DpdGroup::addFlashMessage($controller->l('CSV data was successfully saved'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         } else {
             DpdGroup::addFlashError($controller->l('CSV data could not be saved'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         }
     }
     if (Tools::isSubmit(DpdGroupPostcodeController::SETTINGS_DOWNLOAD_POSTCODE_ACTION)) {
         $controller->generateCSV();
     }
     if (Tools::isSubmit('submitBulkdeletepostcode')) {
         $postcodes_ids = Tools::getValue('postcodeBox');
         if (empty($postcodes_ids)) {
             DpdGroup::addFlashError($controller->l('No postcodes selected'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         }
         $errors = array();
         foreach ($postcodes_ids as $id_postcode) {
             $postcode = new DpdGroupPostcode((int) $id_postcode);
             if (!$postcode->delete()) {
                 $errors[] = $controller->l('Could not delete postcode, #') . (int) $id_postcode;
             }
         }
         if (empty($errors)) {
             DpdGroup::addFlashMessage($controller->l('Selected postcodes deleted successfully'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         } else {
             DpdGroup::addFlashError(implode('<br />', $errors));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         }
     }
     if (Tools::isSubmit('delete_postcode')) {
         $postcode = new DpdGroupPostcode((int) Tools::getValue('id_postcode'));
         if ($postcode->delete()) {
             DpdGroup::addFlashMessage($controller->l('Postcode was deleted successfully'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         } else {
             DpdGroup::addFlashError($controller->l('Could not delete postcode'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         }
     }
     if (Tools::isSubmit(self::SETTINGS_DELETE_POSTCODE_ACTION)) {
         $postcode = new DpdGroupPostcode();
         if ($postcode->deleteAllData()) {
             DpdGroup::addFlashMessage($controller->l('All postcodes deleted successfully'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         } else {
             DpdGroup::addFlashError($controller->l('Could not delete all postcodes'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         }
     }
     if (Tools::isSubmit(self::SETTINGS_RESTORE_POSTCODE_ACTION)) {
         $postcode = new DpdGroupPostcode();
         if (!$postcode->deleteAllData()) {
             DpdGroup::addFlashError($controller->l('Could not delete all postcodes'));
             Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
         }
         $sql = array();
         $postcodes = Tools::file_get_contents(_DPDGROUP_SQL_DIR_ . 'data.sql');
         $postcodes = str_replace('zitec_dpd_postcodes', _DB_PREFIX_ . _DPDGROUP_POSTCODE_DB_, $postcodes);
         $postcodes = explode(';', $postcodes);
         foreach ($postcodes as $query) {
             if ($query) {
                 $sql[] = $query . ';';
             }
         }
         foreach ($sql as $query) {
             if (Db::getInstance()->execute($query) == false) {
                 DpdGroup::addFlashError($controller->l('Could not restore default postcodes data'));
                 Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
             }
         }
         DpdGroup::addFlashMessage($controller->l('Default postcodes data restored successfully'));
         Tools::redirectAdmin($controller->module_instance->module_url . '&menu=postcode');
     }
     return null;
 }