first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
<?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
*/

View File

@@ -0,0 +1,579 @@
<?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/ShipX.php';
require_once __DIR__.'/../../classes/InpostPoint.php';
require_once __DIR__.'/../../classes/InpostPack.php';
require_once __DIR__.'/../../classes/InpostDispatch.php';
require_once __DIR__.'/../../classes/AuthDS.php';
class AdminInpostshipPackageController extends ModuleAdminController
{
private $nameModule = 'inpostship';
public $shipx;
private $debug;
private $debug_shop;
private $perPage = 10;
private $plPage = 0;
public function __construct()
{
$this->bootstrap = true;
$this->className = 'AdminInpostshipPackage';
parent::__construct();
$this->debug = Configuration::get('INPOSTSHIP_DEBUG');
$this->debug_shop = Configuration::get('INPOSTSHIP_DEBUG_SHOP');
if ($this->debug_shop == 1) {
@ini_set('display_errors', 'on');
@error_reporting(E_ALL | E_STRICT);
}
$this->perPage = Configuration::get('INPOSTSHIP_PL_PERPAGE');
//echo $this->perPage;
$this->shipx = new ShipX(Configuration::get('INPOSTSHIP_API_KEY'), (bool)Configuration::get('INPOSTSHIP_SANDBOX'), $this->debug);
}
private function isActiveModule()
{
$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
);
}
public function initPageHeaderToolbar()
{
parent::initPageHeaderToolbar();
}
public function initHeader()
{
parent::initHeader();
}
public function display()
{
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
$tpl = 'package-list.tpl';
} else {
$tpl = 'nolic.tpl';
}
$this->context->smarty->assign(array(
'content' => $this->context->smarty->fetch($this->getTemplatePath().$tpl)
));
parent::display();
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
}
public function initContent()
{
parent::initContent();
$activeted = $this->isActiveModule();
if ($activeted['actived'] == 1) {
$this->addJqueryUI('ui.tooltip');
$this->addJqueryUI('ui.popover');
$this->addJqueryUI('ui.datepicker');
$this->addCSS(__DIR__ . '/../../assets/css/phelp.css');
// $this->addCSS('//min.gitcdn.xyz/repo/wintercounter/Protip/master/protip.min.css');
$token = Tools::getAdminTokenLite('AdminOrders');
$tokenCustomer = Tools::getAdminTokenLite('AdminCustomers');
$tokenCusrrent = Tools::getAdminTokenLite('AdminInpostshipPackage');
$statusesApi = $this->shipx->getStatuses();
if (isset($statusesApi['result']->items)) {
$statuses = $statusesApi['result']->items;
} else {
$statuses = array();
}
if (Tools::getIsset('plPage')) {
$this->plPage = (int)Tools::getValue('plPage', 1) - 1;
}
$start = $this->plPage * $this->perPage;
$filter = array();
if (Tools::getIsset('submitFilter')) {
$filter = $_POST;
}
$package_list = InpostPack::getPaginPackageList((int)$start, (int)$this->perPage, $filter);
$package_list_all = InpostPack::getAllPackageList();
$pages_all = ceil(count($package_list_all) / $this->perPage);
if (!empty($package_list)) {
foreach ($package_list as &$pl) {
$order = new Order((int)$pl['id_order']);
$pl['order_ref'] = $order->reference;
$ol = Tools::getProtocol() . $this->context->shop->domain . '/' . basename(_PS_ADMIN_DIR_) . '/index.php?controller=AdminOrders&id_order=' . (int)$pl['id_order'] . '&vieworder&token=' . $token;
if (_PS_VERSION_ > '1.6.9.9') {
$ol = $this->context->link->getAdminLink('AdminOrders', true, null, array('id_order' => (int)$pl['id_order'], 'vieworder' => ''));
}
$pl['order_link'] = $ol;
$address = new Address($order->id_address_delivery);
$pl['customer'] = $address->firstname . ' ' . $address->lastname;
$cl = Tools::getProtocol() . $this->context->shop->domain . '/' . basename(_PS_ADMIN_DIR_) . '/index.php?controller=AdminCustomers&id_customer=' . (int)$order->id_customer . '&viewcustomer&token=' . $tokenCustomer;
if (_PS_VERSION_ > '1.6.9.9') {
$cl = $this->context->link->getAdminLink('AdminCustomers', true, null, array('id_customer' => (int)$order->id_customer, 'viewcustomer' => ''));
}
$pl['customer_link'] = $cl;
$id_cart = (int)$order->id_cart;
$inpost_cart = InpostPack::getInpostShipCart((int)$id_cart);
$pl['image'] = '';
$c1 = Configuration::get('INPOSTSHIP_CARRIER_1');
$c1i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_1');
$c2 = Configuration::get('INPOSTSHIP_CARRIER_2');
$c2i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_2');
$c3 = Configuration::get('INPOSTSHIP_CARRIER_3');
$c3i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_3');
$c4 = Configuration::get('INPOSTSHIP_CARRIER_4');
$c4i = Configuration::get('INPOSTSHIP_INSTALL_CARRIER_4');
$c5 = Configuration::get('INPOSTSHIP_CARRIER_5');
$c6 = Configuration::get('INPOSTSHIP_CARRIER_6');
$service = 0;
$c_type = 0;
$id_carrier = (int)$inpost_cart['id_carrier'];
if ($id_carrier != $order->id_carrier) {
$id_carrier = (int)$order->id_carrier;
}
$carrier = new Carrier((int)$id_carrier);
$cref = $carrier->id_reference;
$image = '';
if ($c1i == 1) {
if ($cref == $c1) {
$image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg';
$service = 1;
}
}
if ($c2i == 1) {
if ($cref == $c2) {
$image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg';
$service = 1;
$c_type = 1;
}
}
if ($c3i == 1) {
if ($c3 == $cref) {
$image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg';
$service = 2;
}
}
if ($c4i == 1) {
if ($c4 == $cref) {
$image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc2.jpg';
$service = 2;
$c_type = 1;
}
}
if ($c5 == $cref) {
$image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg';
$service = 5;
}
if ($c6 == $cref) {
$image = Tools::getProtocol(true) . $this->context->shop->domain . '/modules/inpostship/views/img/isc1.jpg';
$service = 6;
$c_type = 1;
}
$pl['image'] = $image;
$pl['service'] = $service;
$pl['c_type'] = $c_type;
$name = 'Nadanie w paczkomacie';
switch ($pl['sendtype']) {
case 'parcel_locker':
$name = 'Nadanie w paczkomacie';
break;
case 'pop':
$name = 'Nadam przesyłkę w Punkcie Obsługi Przesyłek';
break;
case 'dispatch_order':
$name = 'Odbiór przez kuriera';
break;
}
$pl['dispatch_name'] = $name;
$state = array();
if (!empty($pl['reference_number'])) {
$status = $this->shipx->getTracking($pl['reference_number']);
$state = $this->separateStatus($statuses, $status['result']->status);
}
$pl['current_state'] = $state;
$dispatch = 0;
if ($pl['sendtype'] == 'dispatch_order') {
$dispatch = 1;
}
$pl['dispatch'] = $dispatch;
if ((int)$pl['dispatch_id'] > 0) {
$dispatch_info = $this->shipx->getDispatchInfo((int)$pl['dispatch_id']);
if (empty($dispatch_info['error'])) {
$status = $dispatch_info['result']->status;
$pl['dispatch_status'] = InpostDispatch::getDispatchStatus($status);
$pl['dispatch_status_org'] = $status;
}
}
}
}
$module = Module::getInstanceByName('inpostship');
$mversion = $module->version;
$ssl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://';
/* prestahelp API - do not remove! */
$auth = new AuthDS('inpostship');
$chlogInfo = $auth->getChangelog();
$chlogInfoOther = $auth->getChangelogOther();
$currentVersion = $auth->getCurrentModuleVersion();
/* prestahelp API - do not remove! */
$banersHtml = AuthDS::getBanersHtml();
$phelpTop = __DIR__ . '/../../views/templates/admin/phelp-top.tpl';
$phelpBtm = __DIR__ . '/../../views/templates/admin/phelp-bottom.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/';
$ssl = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$request_uri = explode('&plPage', $_SERVER['REQUEST_URI']);
$currentPage = $ssl . $_SERVER['HTTP_HOST'] . $request_uri[0];
$pagination = array(
10, 25, 50, 100, 300
);
$this->context->smarty->assign(array(
'package_list' => $package_list,
'token' => $token,
'trackingUrl' => ShipX::TRACKING_PACKAGE_URL,
'printUrl' => Tools::getProtocol() . $this->context->shop->domain . '/' . basename(_PS_ADMIN_DIR_) . '/index.php?controller=AdminInpostShipPackage&token=' . $tokenCusrrent . '&printLabel=',
'dispatchUrl' => Tools::getProtocol() . $this->context->shop->domain . '/' . basename(_PS_ADMIN_DIR_) . '/index.php?controller=AdminInpostShipPackage&token=' . $tokenCusrrent . '&orderCourier=',
'banersHtml' => $banersHtml,
'phelpTop' => $phelpTop,
'phelpBtm' => $phelpBtm,
'chlogInfo' => $chlogInfo,
'chlogInfoOther' => $chlogInfoOther,
'moduleAssets' => $moduleAssets,
'lastestVersion' => $lastestVersion,
'updateLink' => $updateLink,
'indexLink' => $indexLink,
'moduleName' => $module->displayName,
'moduleNameInfo' => $module->name,
'moduleVersion' => $mversion,
'currentModuleVersion' => $currentVersion['version'],
'pages_all' => $pages_all,
'currentPage' => $currentPage,
'plPage' => $this->plPage + 1,
'allPackageCount' => count($package_list_all),
'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'],
'list_total' => count($package_list_all),
'pagination' => $pagination,
'selected_pagination' => (int)Configuration::get('INPOSTSHIP_PL_PERPAGE'),
'filter' => $filter
));
}
}
public function postProcess()
{
parent::postProcess();
if (Tools::getIsset('submitGenerateLabels')) {
$labels = Tools::getValue('actions', array());
if (!empty($labels)) {
$format = Configuration::get('INPOSTSHIP_PRINT_FORMAT');
$file_name = 'etykiety-'.(date('Y-m-d-H-i-s'));
$content = $this->shipx->getMultiLabels((int)Configuration::get('INPOSTSHIP_API_ORGANIZATION'), $labels, Configuration::get('INPOSTSHIP_PRINT_TYPE'), $format);
$contents = $this->GetHeaders($content);
//print_r($contents);exit();
if (!empty($contents['file_type'])) {
switch ($contents['file_type']) {
case 'zip':
$file = time() . '-' . $contents['file'];
$dir = __DIR__ . '/../../files/' . $file;
file_put_contents($dir, $contents['http_code']);
$size = filesize($dir);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: public');
header('Content-Type: application/zip');
header('Content-Transfer-Encoding: Binary');
header('Content-Length: ' . $size);
header('Content-Disposition: attachment; filename="' . basename($contents['file']) . '"');
ob_end_flush();
@readfile($dir);
exit();
break;
case 'pdf':
$dir = __DIR__ . '/../../files/' . $contents['file'];
file_put_contents($dir, $contents['http_code']);
$size = filesize($dir);
header('Content-Type: application/pdf');
header('Content-Length: ' . $size);
header('Content-Disposition: attachment; filename="' . basename($contents['file']) . '"');
ob_end_flush();
@readfile($dir);
exit();
break;
case 'epl':
$dir = __DIR__ . '/../../files/' . $contents['file'];
file_put_contents($dir, $contents['http_code']);
$size = filesize($dir);
header('Content-Type: application/octet-stream');
header('Content-Length: ' . $size);
header('Content-Disposition: attachment; filename="' . basename($contents['file']) . '"');
ob_end_flush();
@readfile($dir);
exit();
break;
}
} else {
$this->context->smarty->assign(array(
'errors' => 'Brak pliku do pobrania!'
));
}
/*ob_start();
if ($format == 'PDF') {
$file_type = 'pdf';
header('Content-Type: application/pdf');
} else {
$file_type = 'epl';
header('Content-Type: application/octet-stream');
}
header("Content-Disposition: attachment; filename=\"$file_name.$file_type\"");
exit($content);*/
} else {
$this->context->smarty->assign(array(
'errors' => 'Brak wybranych przesyłek!'
));
}
}
if (Tools::getIsset('submitGenerateDispatches')) {
$dispatches = Tools::getValue('actions', array());
if (!empty($dispatches)) {
$dispatches_ids = array();
foreach ($dispatches as $d) {
$dispatches_ids[] = $d;
}
$format = Configuration::get('INPOSTSHIP_PRINT_FORMAT');
$file_name = 'listy-'.(date('Y-m-d-H-i-s'));
$content = $this->shipx->getMultiDispatchOrder((int)Configuration::get('INPOSTSHIP_API_ORGANIZATION'), $dispatches_ids, Configuration::get('INPOSTSHIP_PRINT_TYPE'), $format);
if (!empty($content)) {
ob_start();
$file_type = 'pdf';
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename=\"$file_name.$file_type\"");
exit($content);
} else {
$result = json_decode($content);
$error = Tools::displayError($result->message.''.$result->details);
$this->context->smarty->assign(array(
'error' => $error
));
}
} else {
$this->context->smarty->assign(array(
'errors' => 'Brak wybranych przesyłek!'
));
}
}
if (Tools::getIsset('submitPickupDispatches')) {
$pickups = Tools::getValue('actions', array());
if (!empty($pickups)) {
$dispatch = $this->shipx->setDispatchOrders($pickups, (int)Configuration::get('INPOSTSHIP_DISPATCH_POINT'), (int)Configuration::get('INPOSTSHIP_API_ORGANIZATION'));
if (empty($dispatch['error'])) {
/*$info = (array)$dispatch['result'];
foreach ($pickups as $p) {
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'fusioninpost SET dispatch_id = "'.(int)$info['id'].'" WHERE packcode = '.(int)$p);
}*/
} else {
$this->context->smarty->assign(array(
'error' => $dispatch['error']
));
}
} else {
$this->context->smarty->assign(array(
'errors' => 'Brak wybranych przesyłek!'
));
}
}
if (Tools::getIsset('printLabel')) {
$label = (int)Tools::getValue('printLabel');
if (!empty($label) && $label > 0) {
$format = Configuration::get('INPOSTSHIP_PRINT_FORMAT');
$pack = InpostPack::getInpostShipByIdPack((int)$label);
$content = $this->shipx->getLabel($pack['packcode'], $format, Configuration::get('INPOSTSHIP_PRINT_TYPE'));
$file_name = $pack['reference_number'];
// ob_end_clean();
ob_start();
if ($format == 'PDF') {
$file_type = 'pdf';
header('Content-Type: application/pdf');
} else {
$file_type = 'epl';
header('Content-Type: application/octet-stream');
}
header("Content-Disposition: attachment; filename=\"$file_name.$file_type\"");
exit($content);
}
}
if (Tools::getIsset('orderCourier')) {
$pickups = (array)Tools::getValue('orderCourier', array());
if (!empty($pickups)) {
$dispatch = $this->shipx->setDispatchOrders($pickups, (int)Configuration::get('INPOSTSHIP_DISPATCH_POINT'), (int)Configuration::get('INPOSTSHIP_API_ORGANIZATION'));
if (empty($dispatch['error'])) {
/*$info = (array)$dispatch['result'];
foreach ($pickups as $p) {
Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'fusioninpost SET dispatch_id = "'.(int)$info['id'].'" WHERE packcode = '.(int)$p);
}*/
} else {
$this->context->smarty->assign(array(
'error' => $dispatch['error']
));
}
}
}
if (Tools::getIsset('INPOSTSHIP_PL_PERPAGE')) {
Configuration::updateValue('INPOSTSHIP_PL_PERPAGE', (int)Tools::getValue('INPOSTSHIP_PL_PERPAGE'));
Tools::redirect($_SERVER['HTTP_REFERER']);
}
if (isset($_POST['plPage'])) {
$url = Tools::getValue('plUrl').'&plPage='.(int)Tools::getValue('plPage');
Tools::redirectLink($url);
}
}
private function GetHeaders($response) {
$headers = [];
$xx = explode("\r\n\r\n", $response);
foreach($xx as $i => $line) {
if($i == 1) {
$headers['http_code'] = $line;
} else {
$xxx2 = nl2br($line);
$xxx = explode('<br />', $xxx2);
if (!empty($xxx)) {
foreach ($xxx as $x) {
$hd = explode(':', $x);
if (count($hd) > 1) {
$headers[trim($hd[0])] = $hd[1];
if (trim($hd[0]) == 'Content-Disposition') {
$file2 = explode('=', $hd[1]);
$file = str_replace('"', '', $file2[1]);
$headers['file'] = $file;
$ext2 = explode('.', $file);
$ext = $ext2[1];
switch ($ext2[1]) {
case 'zip':
$ext = 'zip';
break;
case 'pdf':
$ext = 'pdf';
break;
}
$headers['file_type'] = $ext;
}
} else {
$headers['file'] = '';
$headers['file_type'] = '';
}
}
}
$headers['head'] = $line;
}
}
return $headers;
}
private function getInpostCart($statuses)
{
// $result = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'fusioninpost WHERE `status` IS NOT NULL ORDER BY date_add DESC');
$result = Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'fusioninpost WHERE dispatch_order_id IS NOT NULL ORDER BY date_add DESC');
if (!empty($result)) {
foreach ($result as &$r) {
$r['state'] = !empty($r['status']) ? $this->separateStatus($statuses, $r['status']) : '';
if (!empty($r['dispatch_order_id']) && $r['dispatch_order_id'] > 0) {
$order = new Order((int)$r['dispatch_order_id']);
$r['reference_order'] = $order->reference;
} else {
$r['reference_order'] = '';
}
if (!empty($r['reference_number'])) {
$status = $this->inpostapi->getTracking($r['reference_number']);
} else {
$status = array();
}
$r['current_state'] = $status;
$package_type = 'Inpost Paczkomaty';
if ($r['courier'] > 0) {
$package_type = 'Inpost Kurier';
}
$r['package_type'] = $package_type;
switch ($r['self_send']) {
case 'dispatch_order':
$r['package_send'] = 'Odbiór przez kuriera';
break;
case 'pop':
$r['package_send'] = 'Nadanie w POP';
break;
case 'parcel_locker':
$r['package_send'] = 'Nadanie w paczkomacie';
break;
default:
$r['package_send'] = '';
break;
}
}
}
return $result;
}
private function separateStatus($statuses, $state)
{
$return = array();
if (is_array($statuses)) {
foreach ($statuses as $s) {
if ($s->name == trim($state)) {
$return['title'] = $s->title;
$return['description'] = $s->description;
return $return;
}
}
}
return $return;
}
}

View File

@@ -0,0 +1,679 @@
<?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
));
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* 2007-2016 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2016 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;