Files
wyczarujprezent.pl/modules/inpostship/controllers/admin/AdminInpostshipSettingsController.php
2024-10-28 22:14:22 +01:00

680 lines
39 KiB
PHP

<?php
/**
* NOTICE OF LICENSE
*
* This file is licenced under the Software License Agreement.
* With the purchase or the installation of the software in your application
* you accept the licence agreement.
*
* You must not modify, adapt or create derivative works of this source code
*
* @author PrestaHelp.com
* @copyright 2019 PrestaHelp
* @license LICENSE.txt
*/
require_once __DIR__.'/../../classes/AuthDS.php';
require_once __DIR__.'/../../classes/ShipX.php';
require_once __DIR__.'/../../classes/InpostPoint.php';
class AdminInpostshipSettingsController extends ModuleAdminController
{
private $nameModule = 'inpostship';
public $shipx;
private $checkouts = array(
'default' => 'Standardowy koszyk',
'steasycheckout' => 'Easy checkout by sunnytoo.com',
'onepagecheckoutps' => 'One Page Checkout PrestaShop by PresTeamShop',
'spstepcheckout' => 'Sp One Step Checkout by MagenTech',
'supercheckout' => 'SuperCheckout by Knowband',
'onepagecheckout' => 'Zakupy na jednej stronie by Zelarg',
'thecheckout' => 'Szybkie zakupy Pro by Zelarg',
);
public function __construct()
{
$this->bootstrap = true;
$this->className = 'AdminInpostshipSettings';
$this->shipx = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'));
parent::__construct();
}
private function isActiveModule()
{
return array(
'active' => $licence,
'actived' => 1
);
$shop = new Shop((int)$this->context->shop->id);
$auth = new AuthDS($this->nameModule);
$licence = $auth->isActive($shop->getBaseURL());
if (empty($licence)) {
$domain = AuthDS::clearDomain($shop->getBaseURL());
$licence = $auth->getStaticLicence($domain, 'Integracja Inpost', Configuration::get('INPOSTSHIP_LICENCE'));
}
return array(
'active' => $licence,
'actived' => $licence['licence']->licence
);
}
private function getMessages()
{
$shop = new Shop((int)$this->context->shop->id);
$auth = new AuthDS($this->nameModule);
$licence = $auth->isActive($shop->getBaseURL());
if (empty($licence)) {
$domain = AuthDS::clearDomain($shop->getBaseURL());
$licence = $auth->getStaticLicence($domain, 'Integracja Inpost', Configuration::get('INPOSTSHIP_LICENCE'));
}
$id_key = (int)$licence['licence']->id_key;
$messages = $auth->getMessageInfo((int)$id_key);
$this->context->smarty->assign(array(
'messagesApi' => $messages
));
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
}
public function initHeader()
{
parent::initHeader();
}
public function initContent()
{
parent::initContent();
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
if (Tools::getIsset('updateInpostship')) {
$this->update();
} else {
$this->getMessages();
$this->addCSS(__DIR__ . '/../../assets/css/phelp.css');
$updateModule = false;
$module = Module::getInstanceByName('inpostship');
$mversion = $module->version;
/* prestahelp API - do not remove! */
$auth = new AuthDS('inpostship');
$productsShow = $auth->getBaners();
$authorInfo = $auth->getAuthor();
$chlogInfo = $auth->getChangelog();
// echo "<pre>";print_r($chlogInfo);exit();
$chlogInfoOther = $auth->getChangelogOther();
$currentVersion = $auth->getCurrentModuleVersion();
/* prestahelp API - do not remove! */
$ssl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://';
$cron_link = $ssl . $this->context->shop->domain . '/modules/inpostship/cron.php';
$cron_link2 = $ssl . $this->context->shop->domain . '/modules/inpostship/cron/tracking.php';
$points = array();
$carriers = Carrier::getCarriers($this->context->cookie->id_lang, true, false, false, null, 5); // 2 - is only module
$points = InpostPoint::getAllPoints(null, 0);
$inpost_points = $this->shipx->getNumberOfPoints();
$inpost_points_count = 0;
if (isset($inpost_points['result']->count)) {
$inpost_points_count = (int)$inpost_points['result']->count;
}
//pop points
$popInBase = count(InpostPoint::getPopPointsAll());
$inpostPopPoints = $this->shipx->getNumberOfPopPoints();
$inpostPopPointsCount = 0;
if (isset($inpostPopPoints['result']->count)) {
$inpostPopPointsCount = (int)$inpostPopPoints['result']->count;
}
$pointsPop = InpostPoint::getPopPointsAll();
$org = (int)Configuration::get('INPOSTSHIP_API_ORGANIZATION');
$org_info = array();
$org_info['result'] = array();
if (!empty($org)) {
$org_info = (array)$this->shipx->getOrganizationsInfo((int)$org);
if (!empty($org_info['result'])) {
$oi = (array)$org_info['result'];
if (isset($oi['carriers'])) {
foreach ($oi['carriers'] as $key => &$c) {
$oi['carriers_info'][$key]['type'] = $c;
switch ($c) {
case 'inpost_locker':
$name = 'Usługa paczkomatowa';
break;
case 'inpost_letter':
$name = 'Usługa listowa Allegro';
break;
case 'inpost_courier':
$name = 'Usługa kurierska';
break;
}
$oi['carriers_info'][$key]['name'] = $name;
}
}
if (isset($oi['services'])) {
foreach ($oi['services'] as $key => &$c) {
$oi['services_info'][$key]['type'] = $c;
switch ($c) {
case 'inpost_locker_standard':
$name = 'Przesyłka paczkomatowa standardowa';
break;
case 'inpost_locker_allegro':
$name = 'Przesyłka paczkomatowa Allegro Paczkomaty InPost';
break;
case 'inpost_locker_pass_thru':
$name = 'Przesyłka podaj dalej';
break;
case 'inpost_letter_allegro':
$name = 'Przesyłka listowa Allegro Polecony InPost';
break;
case 'inpost_courier_palette':
$name = 'Przesyłka kurierska Paleta Standard';
break;
case 'inpost_courier_allegro':
$name = 'Przesyłka kurierska Allegro Kurier InPost';
break;
case 'inpost_courier_standard':
$name = 'Przesyłka kurierska standardowa';
break;
case 'inpost_courier_express_1000':
$name = 'Przesyłka kurierska z doręczeniem do godziny 10:00 następnego dnia';
break;
case 'inpost_courier_express_1200':
$name = 'Przesyłka kurierska z doręczeniem do godziny 12:00 następnego dnia';
break;
case 'inpost_courier_express_1700':
$name = 'Przesyłka kurierska z doręczeniem do godziny 17:00 następnego dnia';
break;
case 'inpost_courier_local_standard':
$name = 'Przesyłka kurierska Lokalna Standardowa';
break;
case 'inpost_courier_local_express':
$name = 'Przesyłka kurierska Lokalna Expresowa';
break;
case 'inpost_courier_local_super_express':
$name = 'Przesyłka kurierska Lokalna Super Expresowa';
break;
case 'inpost_courier_c2c':
$name = 'Przesyłka kurierska c2c';
break;
}
$oi['services_info'][$key]['name'] = $name;
}
}
$org_info['result'] = $oi;
}
}
$dispatches = $this->shipx->getSendingMethods();
$dispatch_point = $this->shipx->searchDispatchPoints2((int)$org);
$variables = "{point_code} - " . $this->l('Point number') . ",<br />{point_address} - " . $this->l('Point address') . ",<br />{point_description} - " . $this->l('Point description') . ",<br />{point_lat} - " . $this->l('Point latitude') . ",<br />{point_lng} - " . $this->l('Point longitude');
$variables .= "<br />{firstname} - Imię klienta,<br />{lastname} - Nazwisko klienta,<br />{id_order} - ID zamówienia,<br />{order_reference} - Numer zamówienia,<br />{carrier} - Nazwa przewoźnika,<br />{order_total} - Wartość zamówienia";
$phelpBtm = __DIR__ . '/../../views/templates/admin/phelp-bottom.tpl';
$phelpTop = __DIR__ . '/../../views/templates/admin/phelp-top.tpl';
$moduleAssets = $ssl . $this->context->shop->domain . $this->context->shop->physical_uri . 'modules/inpostship/assets/';
$lastestVersion = $currentVersion['version'] == $mversion ? true : false;
$updateLink = 'https://modules.prestahelp.com/moduly/inpostship/inpostship' . $currentVersion['version'] . '.zip';
$indexLink = 'https://modules.prestahelp.com/moduly/inpostship/';
$banersHtml = AuthDS::getBanersHtml();
$this->checkUpdate();
// $statusy = $this->shipx->getStatuses();
$orderState = OrderState::getOrderStates((int)$this->context->cookie->id_lang);
$pType = 0;
$pTypes = Configuration::get('INPOSTSHIP_POINT_TYPE');
$pTypes = explode(',', $pTypes);
foreach ($pTypes as $pT) {
if ($pT == 'pop') {
$pType = 1;
}
}
$this->context->smarty->assign(array(
'api_user' => Configuration::get('INPOSTSHIP_API_USER'),
'api_pass' => Configuration::get('INPOSTSHIP_API_PASSWD'),
'api_key' => Configuration::get('INPOSTSHIP_API_KEY'),
'api_sand' => Configuration::get('INPOSTSHIP_SANDBOX'),
'api_org' => Configuration::get('INPOSTSHIP_API_ORGANIZATION'),
'base_points' => (int)InpostPoint::getCountBasePoints(),
'inpost_points' => (int)$inpost_points_count,
'points_count' => ceil($inpost_points_count / 100),
'cron_link' => $cron_link,
'cron_link2' => $cron_link2,
'org_info' => $org_info['result'],
'state' => OrderState::getOrderStates($this->context->cookie->id_lang),
'print_type' => Configuration::get('INPOSTSHIP_PRINT_TYPE'),
'print_format' => Configuration::get('INPOSTSHIP_PRINT_FORMAT'),
'points' => $points,
'carriers' => $carriers,
'paczkomaty' => Configuration::get('INPOSTSHIP_CARRIER_1'),
'paczkomaty_cod' => Configuration::get('INPOSTSHIP_CARRIER_2'),
'courier' => Configuration::get('INPOSTSHIP_CARRIER_3'),
'courier_cod' => Configuration::get('INPOSTSHIP_CARRIER_4'),
'paczkomaty_week' => Configuration::get('INPOSTSHIP_CARRIER_5'),
'paczkomaty_week_cod' => Configuration::get('INPOSTSHIP_CARRIER_6'),
'packtypes' => $this->shipx->locker,
'packtype' => Configuration::get('INPOSTSHIP_PACK_SIZE'),
'dispatch' => Configuration::get('INPOSTSHIP_DISPATCH'),
'dispatches' => $dispatches['result']->items,
'dispatch_point' => isset($dispatch_point['result']->items) ? $dispatch_point['result']->items : array(),
'tracking_save' => Configuration::get('INPOSTSHIP_TRACKING_SAVE'),
'deltab' => Configuration::get('INPOSTSHIP_DELETE_DATABASE'),
'stateo' => Configuration::get('INPOSTSHIP_ORDER_STATUS'),
'osc' => Configuration::get('INPOSTSHIP_ORDER_STATUS_CHANGE'),
'adp' => Configuration::get('INPOSTSHIP_SEND_POINT_ADMIN'),
'cdp' => Configuration::get('INPOSTSHIP_SEND_POINT_CUSTOMER'),
'st' => Configuration::get('INPOSTSHIP_SEND_TRACKING'),
'posbox' => Configuration::get('INPOSTSHIP_POSITION_BOX'),
'courier_1' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_1'),
'courier_2' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2'),
'courier_3' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_3'),
'courier_4' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4'),
'courier_5' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_5'),
'courier_6' => Configuration::get('INPOSTSHIP_INSTALL_CARRIER_6'),
'sender_name' => Configuration::get('INPOSTSHIP_SENDER_NAME'),
'sender_company_name' => Configuration::get('INPOSTSHIP_SENDER_COMPANY_NAME'),
'sender_firstname' => Configuration::get('INPOSTSHIP_SENDER_FIRSTNAME'),
'sender_lastname' => Configuration::get('INPOSTSHIP_SENDER_LASTNAME'),
'sender_email' => Configuration::get('INPOSTSHIP_SENDER_EMAIL'),
'sender_phone' => Configuration::get('INPOSTSHIP_SENDER_PHONE'),
'sender_street' => Configuration::get('INPOSTSHIP_SENDER_STREET'),
'sender_building_number' => Configuration::get('INPOSTSHIP_SENDER_BUILDING_NR'),
'sender_city' => Configuration::get('INPOSTSHIP_SENDER_CITY'),
'sender_postcode' => Configuration::get('INPOSTSHIP_SENDER_POSTCODE'),
'sender_machine' => Configuration::get('INPOSTSHIP_SENDER_MACHINE'),
'variables' => $variables,
'near' => Configuration::get('INPOSTSHIP_NEAR'),
'mdebug' => Configuration::get('INPOSTSHIP_DEBUG'),
'sdebug' => Configuration::get('INPOSTSHIP_DEBUG_SHOP'),
'shop_debug' => _PS_MODE_DEV_,
'moduleVersion' => $mversion,
'reset' => Configuration::get('INPOSTSHIP_RESET'),
'step1url' => $ssl . $this->context->shop->domain . '/modules/inpostship/ajax.php',
'dpt' => Configuration::get('INPOSTSHIP_DISPATCH_POINT'),
'sfi' => Configuration::get('INPOSTSHIP_SHOW_SFI'),
'scod' => Configuration::get('INPOSTSHIP_SHOW_COD_VALUE'),
'imap' => Configuration::get('INPOSTSHIP_MAP_TYPE'),
'igma' => Configuration::get('INPOSTSHIP_GOOGLE_MAPS_API'),
'updateModule' => $updateModule,
'moduleAssets' => $moduleAssets,
'phelpBtm' => $phelpBtm,
'phelpTop' => $phelpTop,
'productsShow' => (array)$productsShow,
'authorInfo' => $authorInfo,
'chlogInfo' => $chlogInfo,
'moduleName' => $module->displayName,
'moduleNameInfo' => $module->name,
'currentModuleVersion' => $currentVersion['version'],
'lastestVersion' => $lastestVersion,
'updateLink' => $updateLink,
'chlogInfoOther' => $chlogInfoOther,
'indexLink' => $indexLink,
'popInBase' => $popInBase,
'inpostPopPoints' => $inpostPopPointsCount,
'pointsPop' => $pointsPop,
'selPopPoint' => Configuration::get('INPOSTSHIP_SENDER_MACHINE_POP'),
'banersHtml' => $banersHtml,
'x13a' => Configuration::get('INPOSTSHIP_INTEGRATION_X13ALLEGRO'),
'ion' => Configuration::get('INPOSTSHIP_ORDER_NUMBER'),
'plpp' => Configuration::get('INPOSTSHIP_PL_PERPAGE'),
'ioa' => Configuration::get('INPOSTSHIP_ORDER_ADD'),
'ipw' => Configuration::get('INPOSTSHIP_PACKAGE_WEIGHT'),
'ipi' => Configuration::get('INPOSTSHIP_PACKAGE_INSURANCE'),
'insurance' => $this->shipx->insurance,
'packweek' => Configuration::get('INPOSTSHIP_WEEKPACK'),
'wpst' => Configuration::get('INPOSTSHIP_WEEKPACK_START_DAY'),
'wpet' => Configuration::get('INPOSTSHIP_WEEKPACK_END_DAY'),
'wpsh' => Configuration::get('INPOSTSHIP_WEEKPACK_START_HOUR'),
'wpeh' => Configuration::get('INPOSTSHIP_WEEKPACK_END_HOUR'),
'wpp' => !empty(Configuration::get('INPOSTSHIP_WEEKPACK_PRICE')) ? Configuration::get('INPOSTSHIP_WEEKPACK_PRICE') : '4.99',
'updated_date' => date('d-m-Y', strtotime($activeted['active']['licence']->date_expire_update)),
'licence_update' => $activeted['active']['licence']->licence_update,
'support_date' =>date('d-m-Y', strtotime($activeted['active']['licence']->date_expire_support)),
'licence_date' => date('d-m-Y', strtotime($activeted['active']['licence']->date_expire)),
'activeted' => $activeted,
'licence' => $activeted['active']['licence'],
'isTable' => Configuration::get('INPOSTSHIP_IS_TABLE'),
'checkout' => Configuration::get('INPOSTSHIP_CHECKOUT'),
'checkouts' => $this->checkouts,
'moduleViewsLink' => __DIR__.'/../../views/templates/admin/_partial/',
// 'statusy' => $statusy['result']->items,
'track_end' => Configuration::get('INPOSTSHIP_TRACKING_END'),
'tse' => (int)Configuration::get('INPOSTSHIP_TRACKING_SETEND'),
'track_stat' => (int)Configuration::get('INPOSTSHIP_TRACKING_STATUS'),
'orderState' => $orderState,
'imb' => (int)Configuration::get('INPOSTSHIP_MAP_BOX'),
'ims' => (int)Configuration::get('INPOSTSHIP_MAP_SHOW'),
'pType' => $pType,
));
}
}
}
public function postProcess()
{
parent::postProcess();
if (Tools::getIsset('submitSaveUser')) {
Configuration::updateValue('INPOSTSHIP_API_USER', trim(Tools::getValue('INPOSTSHIP_API_USER')));
Configuration::updateValue('INPOSTSHIP_API_PASSWD', trim(Tools::getValue('INPOSTSHIP_API_PASSWD')));
Configuration::updateValue('INPOSTSHIP_API_KEY', trim(Tools::getValue('INPOSTSHIP_API_KEY')));
Configuration::updateValue('INPOSTSHIP_SANDBOX', trim(Tools::getValue('INPOSTSHIP_SANDBOX')));
Configuration::updateValue('INPOSTSHIP_API_ORGANIZATION', trim(Tools::getValue('INPOSTSHIP_API_ORGANIZATION')));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveInpost')) {
Configuration::updateValue('INPOSTSHIP_PRINT_TYPE', Tools::getValue('INPOSTSHIP_PRINT_TYPE'));
Configuration::updateValue('INPOSTSHIP_PRINT_FORMAT', Tools::getValue('INPOSTSHIP_PRINT_FORMAT'));
Configuration::updateValue('INPOSTSHIP_TRACK', Tools::getValue('INPOSTSHIP_TRACK'));
Configuration::updateValue('INPOSTSHIP_SEND', Tools::getValue('INPOSTSHIP_SEND'));
Configuration::updateValue('INPOSTSHIP_STATUS', Tools::getValue('INPOSTSHIP_STATUS'));
Configuration::updateValue('INPOSTSHIP_STATUS_TYPE', Tools::getValue('INPOSTSHIP_STATUS_TYPE'));
if (Tools::getValue('INPOSTSHIP_SENDER_MACHINE')) {
Configuration::updateValue('INPOSTSHIP_SENDER_MACHINE', Tools::getValue('INPOSTSHIP_SENDER_MACHINE'));
}
if (Tools::getValue('INPOSTSHIP_SENDER_MACHINE_POP')) {
Configuration::updateValue('INPOSTSHIP_SENDER_MACHINE_POP', Tools::getValue('INPOSTSHIP_SENDER_MACHINE_POP'));
}
Configuration::updateValue('INPOSTSHIP_PACK_SIZE', Tools::getValue('INPOSTSHIP_PACK_SIZE'));
Configuration::updateValue('INPOSTSHIP_DISPATCH', Tools::getValue('INPOSTSHIP_DISPATCH'));
Configuration::updateValue('INPOSTSHIP_DISPATCH_POINT', Tools::getValue('INPOSTSHIP_DISPATCH_POINT'));
Configuration::updateValue('INPOSTSHIP_TRACKING_SAVE', Tools::getValue('INPOSTSHIP_TRACKING_SAVE'));
Configuration::updateValue('INPOSTSHIP_ORDER_STATUS', Tools::getValue('INPOSTSHIP_ORDER_STATUS'));
Configuration::updateValue('INPOSTSHIP_ORDER_STATUS_CHANGE', Tools::getValue('INPOSTSHIP_ORDER_STATUS_CHANGE'));
Configuration::updateValue('INPOSTSHIP_SEND_POINT_ADMIN', Tools::getValue('INPOSTSHIP_SEND_POINT_ADMIN'));
Configuration::updateValue('INPOSTSHIP_SEND_POINT_CUSTOMER', Tools::getValue('INPOSTSHIP_SEND_POINT_CUSTOMER'));
Configuration::updateValue('INPOSTSHIP_SEND_TRACKING', Tools::getValue('INPOSTSHIP_SEND_TRACKING'));
// Configuration::updateValue('INPOSTSHIP_NEAR', (int)Tools::getValue('INPOSTSHIP_NEAR'));
Configuration::updateValue('INPOSTSHIP_SHOW_SFI', Tools::getValue('INPOSTSHIP_SHOW_SFI'));
Configuration::updateValue('INPOSTSHIP_SHOW_COD_VALUE', Tools::getValue('INPOSTSHIP_SHOW_COD_VALUE'));
Configuration::updateValue('INPOSTSHIP_ORDER_NUMBER', (int)Tools::getValue('INPOSTSHIP_ORDER_NUMBER'));
Configuration::updateValue('INPOSTSHIP_PL_PERPAGE', (int)Tools::getValue('INPOSTSHIP_PL_PERPAGE'));
Configuration::updateValue('INPOSTSHIP_ORDER_ADD', (int)Tools::getValue('INPOSTSHIP_ORDER_ADD'));
Configuration::updateValue('INPOSTSHIP_PACKAGE_WEIGHT', (int)Tools::getValue('INPOSTSHIP_PACKAGE_WEIGHT'));
Configuration::updateValue('INPOSTSHIP_PACKAGE_INSURANCE', (int)Tools::getValue('INPOSTSHIP_PACKAGE_INSURANCE'));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveInpostDelivery')) {
Configuration::updateValue('INPOSTSHIP_CARRIER_1', Tools::getValue('INPOSTSHIP_CARRIER_PACZKOMATY'));
Configuration::updateValue('INPOSTSHIP_CARRIER_2', Tools::getValue('INPOSTSHIP_CARRIER_PACZKOMATY_COD'));
Configuration::updateValue('INPOSTSHIP_CARRIER_3', Tools::getValue('INPOSTSHIP_CARRIER_COURIER'));
Configuration::updateValue('INPOSTSHIP_CARRIER_4', Tools::getValue('INPOSTSHIP_CARRIER_COURIER_COD'));
Configuration::updateValue('INPOSTSHIP_CARRIER_5', Tools::getValue('INPOSTSHIP_CARRIER_PACZKOMATY_WEEK'));
Configuration::updateValue('INPOSTSHIP_CARRIER_6', Tools::getValue('INPOSTSHIP_CARRIER_PACZKOMATY_WEEK_COD'));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveInpostMap')) {
Configuration::updateValue('INPOSTSHIP_MAP_TYPE', Tools::getValue('INPOSTSHIP_MAP_TYPE'));
Configuration::updateValue('INPOSTSHIP_GOOGLE_MAPS_API', Tools::getValue('INPOSTSHIP_GOOGLE_MAPS_API'));
Configuration::updateValue('INPOSTSHIP_MAP_BOX', Tools::getValue('INPOSTSHIP_MAP_BOX', 1));
Configuration::updateValue('INPOSTSHIP_MAP_SHOW', Tools::getValue('INPOSTSHIP_MAP_SHOW', 1));
Configuration::updateValue('INPOSTSHIP_IS_TABLE', (int)Tools::getValue('INPOSTSHIP_IS_TABLE'));
Configuration::updateValue('INPOSTSHIP_CHECKOUT', Tools::getValue('INPOSTSHIP_CHECKOUT'));
Configuration::updateValue('INPOSTSHIP_POSITION_BOX', Tools::getValue('INPOSTSHIP_POSITION_BOX'));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveInpostPointsType')) {
$machineType = Tools::getValue('machineType');
$machineType[] = 'parcel_locker';
Configuration::updateValue('INPOSTSHIP_POINT_TYPE', implode(',', $machineType));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveSender')) {
Configuration::updateValue('INPOSTSHIP_SENDER_NAME', trim(Tools::getValue('sender_name')));
Configuration::updateValue('INPOSTSHIP_SENDER_COMPANY_NAME', trim(Tools::getValue('sender_company_name')));
Configuration::updateValue('INPOSTSHIP_SENDER_FIRSTNAME', trim(Tools::getValue('sender_firstname')));
Configuration::updateValue('INPOSTSHIP_SENDER_LASTNAME', trim(Tools::getValue('sender_lastname')));
Configuration::updateValue('INPOSTSHIP_SENDER_EMAIL', trim(Tools::getValue('sender_email')));
Configuration::updateValue('INPOSTSHIP_SENDER_PHONE', trim(Tools::getValue('sender_phone')));
Configuration::updateValue('INPOSTSHIP_SENDER_STREET', trim(Tools::getValue('sender_street')));
Configuration::updateValue('INPOSTSHIP_SENDER_BUILDING_NR', trim(Tools::getValue('sender_building_number')));
Configuration::updateValue('INPOSTSHIP_SENDER_CITY', trim(Tools::getValue('sender_city')));
Configuration::updateValue('INPOSTSHIP_SENDER_POSTCODE', trim(Tools::getValue('sender_postcode')));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveInpostPoints')) {
$this->updatePoints();
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveInpostPopPoints')) {
$this->updatePopPoints();
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveIntegration')) {
Configuration::updateValue('INPOSTSHIP_INTEGRATION_X13ALLEGRO', Tools::getValue('INPOSTSHIP_INTEGRATION_X13ALLEGRO'));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveDelete')) {
Configuration::updateValue('INPOSTSHIP_DELETE_DATABASE', Tools::getValue('INPOSTSHIP_DELETE_DATABASE'));
Configuration::updateValue('INPOSTSHIP_DEBUG', Tools::getValue('INPOSTSHIP_DEBUG'));
Configuration::updateValue('INPOSTSHIP_DEBUG_SHOP', Tools::getValue('INPOSTSHIP_DEBUG_SHOP'));
Configuration::updateValue('INPOSTSHIP_RESET', Tools::getValue('INPOSTSHIP_RESET'));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveInpostWeek')) {
$price = trim(Tools::getValue('INPOSTSHIP_WEEKPACK_PRICE'));
$price = (float)str_replace(',','.', $price);
$price = number_format($price, 2, '.', '');
Configuration::updateValue('INPOSTSHIP_WEEKPACK', (int)Tools::getValue('INPOSTSHIP_WEEKPACK'));
Configuration::updateValue('INPOSTSHIP_WEEKPACK_START_DAY', Tools::getValue('INPOSTSHIP_WEEKPACK_START_DAY', ''));
Configuration::updateValue('INPOSTSHIP_WEEKPACK_START_HOUR', trim(Tools::getValue('INPOSTSHIP_WEEKPACK_START_HOUR')));
Configuration::updateValue('INPOSTSHIP_WEEKPACK_END_DAY', Tools::getValue('INPOSTSHIP_WEEKPACK_END_DAY', ''));
Configuration::updateValue('INPOSTSHIP_WEEKPACK_END_HOUR', trim(Tools::getValue('INPOSTSHIP_WEEKPACK_END_HOUR')));
Configuration::updateValue('INPOSTSHIP_WEEKPACK_PRICE', $price);
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveUpdate')) {
$update340_sql = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'inpostship_cart` WHERE `Field` = "week"');
if (empty($update340_sql)) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'inpostship_cart` ADD `week` DOUBLE(20, 6) NOT NULL AFTER `cod`');
}
$carr1 = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'carrier` WHERE name = "InPost Paczkomaty 24 Paczka w weekend"');
if (empty($carr1)) {
InpostSettings::createCarrier('INPOSTSHIP_CARRIER_5', 'INPOST Paczkomaty 24 - Paczka w weekend');
}
$carr2 = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'carrier` WHERE name = "InPost Paczkomaty 24 Paczka w weekend - za pobraniem"');
if (empty($carr2)) {
InpostSettings::createCarrier('INPOSTSHIP_CARRIER_6', 'INPOST Paczkomaty 24 - Paczka w weekend za pobraniem');
}
$update341_sql = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'inpostship` WHERE `Field` = "sizes"');
if (empty($update341_sql)) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'inpostship` ADD `sizes` varchar(11) NULL AFTER `packtype`');
}
$update345_sql = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'inpostship` WHERE `Field` = "statue"');
if (empty($update345_sql)) {
Db::getInstance()->execute('ALTER TABLE `'._DB_PREFIX_.'inpostship` ADD `statue` varchar(150) NULL AFTER `dispatch_id`');
}
$sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME = '" . _DB_PREFIX_ . "inpostship_pack_state';";
$update3451_sql = Db::getInstance()->getRow($sql);
if (empty($update3451_sql)) {
Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'inpostship_pack_state` (
`id_state` int(11) NOT NULL AUTO_INCREMENT,
`id_pack` int(11),
`state` varchar(255),
`state_id` int(11),
`date_state` datetime,
`date_add` datetime,
PRIMARY KEY (`id_state`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');
}
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (Tools::getIsset('submitSaveTracking')) {
Configuration::updateValue('INPOSTSHIP_TRACKING_END', trim(Tools::getValue('INPOSTSHIP_TRACKING_END')));
Configuration::updateValue('INPOSTSHIP_TRACKING_SETEND', (int)(Tools::getValue('INPOSTSHIP_TRACKING_SETEND')));
Configuration::updateValue('INPOSTSHIP_TRACKING_STATUS', (int)(Tools::getValue('INPOSTSHIP_TRACKING_STATUS')));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
}
public function display()
{
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
$tpl = $this->getTemplatePath() . 'settings' . (self::ps15() ? '-15' : '') . '.tpl';
if (Tools::getIsset('updateInpostship')) {
$tpl = $this->getTemplatePath() . 'update.tpl';
}
} else {
$tpl = $this->getTemplatePath() . 'nolic.tpl';
}
$this->context->smarty->assign(array(
'content' => $this->context->smarty->fetch($tpl)
));
parent::display();
}
private static function ps17()
{
return Tools::version_compare(_PS_VERSION_, '1.7.0.0', '>=');
}
private static function ps15()
{
return Tools::version_compare(_PS_VERSION_, '1.6.0.0', '<=');
}
private function updatePoints()
{
set_time_limit(0);
@ini_set('max_execution_time', '0');
Db::getInstance()->execute('TRUNCATE TABLE '._DB_PREFIX_.'inpostship_points');
$points = $this->shipx->getPoints();
if (!empty($points)) {
foreach ($points as $p) {
$p = (array)$p;
// if (!InpostPoint::checkPoint($p['name'])) {
$location = (array)$p['location'];
$address = (array)$p['address'];
$type = implode(',', (array)$p['type']);
$cod_pay = (array)$p['payment_type'];
$cod = 1;
if (array_key_exists(0, $cod_pay)) {
$cod = 0;
} else {
foreach ($cod_pay as $cp) {
if (trim($cp) == 'Brak obsługi płatności') {
$cod = 0;
}
}
}
Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'inpostship_points(`point_code`, `point_address1`, `point_address2`, `point_lat`, `point_lng`, `point_desc`, `point_payment`, `point_cod`, `point_type`)
VALUES("' . $p['name'] . '", "' . addslashes($address['line1']) . '", "' . $address['line2'] . '", "' . $location['latitude'] . '", "' . $location['longitude'] . '", "' . addslashes($p['location_description']) . '", "' . $p['payment_available'] . '", "'.(int)$cod.'", "'.$type.'")');
// }
}
}
}
private function updatePopPoints()
{
set_time_limit(0);
@ini_set('max_execution_time', '0');
Db::getInstance()->execute('TRUNCATE TABLE '._DB_PREFIX_.'inpostship_points_pop');
$points = $this->shipx->getPoints(2000, 'pop', 1);
if (!empty($points)) {
foreach ($points as $p) {
$p = (array)$p;
if (!InpostPoint::checkPointPop($p['name'])) {
$location = (array)$p['location'];
$address = (array)$p['address'];
$type = implode(',', (array)$p['type']);
$cod_pay = (array)$p['payment_type'];
$cod = 1;
if (array_key_exists(0, $cod_pay)) {
$cod = 0;
} else {
foreach ($cod_pay as $cp) {
if (trim($cp) == 'Brak obsługi płatności') {
$cod = 0;
}
}
}
Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'inpostship_points_pop`(`point_code`, `point_address1`, `point_address2`, `point_lat`, `point_lng`, `point_desc`, `point_payment`, `point_cod`, `point_type`)
VALUES("' . $p['name'] . '", "' . str_replace('"', "'", $address['line1']) . '", "' . $address['line2'] . '", "' . $location['latitude'] . '", "' . $location['longitude'] . '", "' . addslashes($p['location_description']) . '", "' . $p['payment_available'] . '", "'.(int)$cod.'", "'.$type.'")');
}
}
}
}
public function checkUpdate()
{
$update340_sql = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'inpostship_cart` WHERE `Field` = "week"');
$update340 = false;
$updateLink2 = $this->context->link->getAdminLink('AdminInpostshipSettings').'&updateInpostship=1';
if (empty($update340_sql)) {
$update340 = '3.4.0';
} else {
$carr1 = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'carrier` WHERE name = "INPOST Paczkomaty 24 - Paczka w weekend"');
$carr2 = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'carrier` WHERE name = "INPOST Paczkomaty 24 - Paczka w weekend za pobraniem"');
if (empty($carr1) || empty($carr2)) {
$update340 = '3.4.0';
}
}
$update341_sql = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'inpostship` WHERE `Field` = "sizes"');
$update341 = false;
if (empty($update341_sql)) {
$update341 = '3.4.1';
}
$update345_sql = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'inpostship` WHERE `Field` = "statue"');
$update345 = false;
if (empty($update345_sql)) {
$update345 = '3.4.5';
}
$this->context->smarty->assign(array(
'updateLink2' => $updateLink2,
'update340' => $update340,
'update341' => $update341,
'update345' => $update345,
));
}
public function update()
{
$update = array();
$update340_sql = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'inpostship_cart` WHERE `Field` = "week"');
if (empty($update340_sql)) {
$update[] = '3.4.0';
} else {
$carr1 = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'carrier` WHERE name = "INPOST Paczkomaty 24 - Paczka w weekend"');
$carr2 = Db::getInstance()->getRow('SELECT * FROM `'._DB_PREFIX_.'carrier` WHERE name = "INPOST Paczkomaty 24 - Paczka w weekend za pobraniem"');
if (empty($carr1) || empty($carr2)) {
$update[] = '3.4.0';
}
}
$update341_sql = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'inpostship` WHERE `Field` = "sizes"');
if (empty($update341_sql)) {
$update[] = '3.4.1';
}
$update345_sql = Db::getInstance()->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'inpostship` WHERE `Field` = "statue"');
if (empty($update345_sql)) {
$update[] = '3.4.5';
} else {
$sql = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME = '" . _DB_PREFIX_ . "inpostship_pack_state';";
$update3451_sql = Db::getInstance()->getRow($sql);
if (empty($update3451_sql)) {
$update[] = '3.4.5';
}
}
$this->context->smarty->assign(array(
'update' => $update
));
}
}