first commit
This commit is contained in:
11
socket/.htaccess
Normal file
11
socket/.htaccess
Normal file
@@ -0,0 +1,11 @@
|
||||
php_value memory_limit 1024M
|
||||
php_value max_execution_time 90000
|
||||
php_value post_max_size 150M
|
||||
php_value upload_max_filesize 150M
|
||||
|
||||
php_value max_input_time 90000
|
||||
|
||||
#php_value display_errors 1
|
||||
php_value log_errors true
|
||||
|
||||
#php_value error_reporting 6143
|
||||
271
socket/Pohoda.Contacts.php
Normal file
271
socket/Pohoda.Contacts.php
Normal file
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
|
||||
function POHODA_Contacts($params)
|
||||
{
|
||||
$request = $params['request'];
|
||||
|
||||
switch ($request) {
|
||||
// odesilani zmen do POHODY
|
||||
case 'download':
|
||||
return POHODA_ContactsDownload($params);
|
||||
break;
|
||||
|
||||
// prijimani zmen z POHODY
|
||||
case 'upload':
|
||||
return POHODA_ContactsUpload($params);
|
||||
break;
|
||||
|
||||
// pokud je spatny pozadavek
|
||||
default:
|
||||
$response = [
|
||||
'status' => 400,
|
||||
'statusMessage' => getTextString('errors', 400),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// odesilani zmen do POHODY
|
||||
|
||||
function POHODA_ContactsDownload($params)
|
||||
{
|
||||
$params = $params['requestParams'];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
// pokud neni specifikovano datum od kdy hledat udaje vrati chybu
|
||||
if (!isset($params['dateFrom'])) {
|
||||
$response = [
|
||||
'status' => 406,
|
||||
'statusMessage' => getTextString('errors', 406),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
$response2 = php_xmlrpc_encode($response);
|
||||
|
||||
return new xmlrpcresp($response2);
|
||||
}
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
$query = 'SELECT * FROM '.getTableName('users')." WHERE date_updated >= '".date('Y-m-d H:i:s', iso8601_decode($params['dateFrom']))."'";
|
||||
|
||||
// logError(__FILE__, __LINE__, $query, true);
|
||||
|
||||
$SQL = sqlQuery($query);
|
||||
|
||||
if (sqlNumRows($SQL) == 0) {
|
||||
$response['status'] = 204;
|
||||
$response['statusMessage'] = getTextString('errors', 204);
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
while ($row = @mysql_fetch_assoc($SQL)) {
|
||||
// struktura pro vraceni
|
||||
$dataItem = [];
|
||||
$dataItem = [
|
||||
'contactId' => intval($row['id']),
|
||||
'address' => [
|
||||
'name' => cs_win2ascii($row['name']),
|
||||
'surname' => cs_win2ascii($row['surname']),
|
||||
'company' => cs_win2ascii($row['firm']),
|
||||
'division' => cs_win2ascii($row['']),
|
||||
'ico' => cs_win2ascii($row['ico']),
|
||||
'dic' => cs_win2ascii($row['dic']),
|
||||
'street' => cs_win2ascii($row['street']),
|
||||
'city' => cs_win2ascii($row['city']),
|
||||
'zip' => cs_win2ascii($row['zip']),
|
||||
'region' => '',
|
||||
'country' => cs_win2ascii($row['country']),
|
||||
'phone' => cs_win2ascii($row['phone']),
|
||||
'cellPhone' => cs_win2ascii($row['mobile']),
|
||||
'fax' => cs_win2ascii($row['fax']),
|
||||
'email' => cs_win2ascii($row['email']),
|
||||
'web' => '',
|
||||
'taxpayer' => false, ],
|
||||
'deliveryAddress' => [
|
||||
'name' => cs_win2ascii($row['delivery_name']),
|
||||
'surname' => cs_win2ascii($row['delivery_surname']),
|
||||
'company' => cs_win2ascii($row['delivery_firm']),
|
||||
'division' => '',
|
||||
'street' => cs_win2ascii($row['delivery_street']),
|
||||
'city' => cs_win2ascii($row['delivery_city']),
|
||||
'zip' => cs_win2ascii($row['delivery_zip']),
|
||||
'region' => '',
|
||||
'country' => cs_win2ascii($row['delivery_country']), ],
|
||||
'dateAdded' => iso8601_encode(strtotime($row['date_reg'])),
|
||||
'note' => '',
|
||||
'intNote' => '',
|
||||
'bankAccounts' => [
|
||||
0 => [
|
||||
'accountNo' => cs_win2ascii($row['account_no']),
|
||||
'code' => cs_win2ascii($row['account_bank']),
|
||||
'symVar' => cs_win2ascii($row['account_symbol']),
|
||||
'symConst' => '',
|
||||
'symSpec' => cs_win2ascii($row['account_symbol']),
|
||||
'bankName' => '', ], ], ];
|
||||
|
||||
$response['responseData'][$count] = $dataItem;
|
||||
// $response['responseData'][$count] = $row;
|
||||
++$count;
|
||||
// break;
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($response, true), true);
|
||||
|
||||
// $response2 = php_xmlrpc_encode($response);
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($response2, true), true);
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// prijimani zmen z POHODY
|
||||
|
||||
function POHODA_ContactsUpload($params)
|
||||
{
|
||||
$requestParams = $params['requestParams'];
|
||||
|
||||
$params = $params['requestData'];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
'requestedParams' => $requestParams,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
// logError(__FILE__, __LINE__, "pocet: ".count($params), true);
|
||||
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
// pokud se posle dataItemStatus deleted smaze polozku z databaze
|
||||
if (isset($params[$i]['dataItemStatus']) && ($params[$i]['dataItemStatus'] == 'deleted')) {
|
||||
if (isset($params[$i]['contactId']) && (!empty($params[$i]['contactId']) || $params[$i]['contactId'] != 0)) {
|
||||
$queryDelete = 'DELETE FROM '.getTableName('users').' WHERE id='.intval($params[$i]['contactId']).' ';
|
||||
|
||||
$SQLDelete = sqlQuery($queryDelete);
|
||||
|
||||
if (mysql_affected_rows() != 0) {
|
||||
$structItemDetails = POHODA_getDataItemDetails($params[$i]['contactId'], 'ok', 200, '');
|
||||
$response['responseData'][$i] = $structItemDetails;
|
||||
} else {
|
||||
$structItemDetails = POHODA_getDataItemDetails($params[$i]['contactId'], 'warning', 404, '');
|
||||
$response['responseData'][$i] = $structItemDetails;
|
||||
}
|
||||
|
||||
continue;
|
||||
} else {
|
||||
$structItemDetails = POHODA_getDataItemDetails(0, 'error', 400, '');
|
||||
$response['responseData'][$i] = $structItemDetails;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// pokud se preda contactId nebo neni nulove provede se update polozky, jinak se vlozi nova
|
||||
// queryHead je nutna pro pripad ze contactId predane v params neexistuje v databazi a nedojde k updatu ale provede se dodatecne nove vlozeni
|
||||
if (isset($params[$i]['contactId']) && ($params[$i]['contactId'] != 0)) {
|
||||
$update = true;
|
||||
$queryHead = 'UPDATE '.getTableName('users').' SET ';
|
||||
} else {
|
||||
$update = false;
|
||||
$queryHead = 'REPLACE INTO '.getTableName('users').' SET ';
|
||||
}
|
||||
|
||||
$query = '';
|
||||
|
||||
$query .= "login='".strtolower(cs_win2ascii(utf8ToWin1250($params[$i]['address']['name']).'-'.utf8ToWin1250($params[$i]['address']['surname']))).$i."', ";
|
||||
$query .= (isset($params[$i]['address']['name'])) ? "name='".utf8ToWin1250($params[$i]['address']['name'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['surname'])) ? "surname='".utf8ToWin1250($params[$i]['address']['surname'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['company'])) ? "firm='".utf8ToWin1250($params[$i]['address']['company'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['street'])) ? "street='".utf8ToWin1250($params[$i]['address']['street'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['city'])) ? "city='".utf8ToWin1250($params[$i]['address']['city'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['zip'])) ? "zip='".utf8ToWin1250($params[$i]['address']['zip'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['email'])) ? "email='".utf8ToWin1250($params[$i]['address']['email'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['country'])) ? "country='".utf8ToWin1250($params[$i]['address']['country'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['ico'])) ? "ico='".utf8ToWin1250($params[$i]['address']['ico'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['dic'])) ? "dic='".utf8ToWin1250($params[$i]['address']['dic'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['phone'])) ? "phone='".utf8ToWin1250($params[$i]['address']['phone'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['cellPhone'])) ? "mobile='".utf8ToWin1250($params[$i]['address']['cellPhone'])."', " : '';
|
||||
$query .= (isset($params[$i]['address']['fax'])) ? "fax='".utf8ToWin1250($params[$i]['address']['fax'])."', " : '';
|
||||
$query .= (isset($params[$i]['deliveryAddress']['name']) && !empty($params[$i]['deliveryAddress']['name'])) ? "delivery_name='".utf8ToWin1250($params[$i]['deliveryAddress']['name'])."', " : "delivery_name='".utf8ToWin1250($params[$i]['address']['name'])."', ";
|
||||
$query .= (isset($params[$i]['deliveryAddress']['surname']) && !empty($params[$i]['deliveryAddress']['surname'])) ? "delivery_surname='".utf8ToWin1250($params[$i]['deliveryAddress']['surname'])."', " : "delivery_surname='".utf8ToWin1250($params[$i]['address']['surname'])."', ";
|
||||
$query .= (isset($params[$i]['deliveryAddress']['company']) && !empty($params[$i]['deliveryAddress']['company'])) ? "delivery_firm='".utf8ToWin1250($params[$i]['deliveryAddress']['company'])."', " : "delivery_firm='".utf8ToWin1250($params[$i]['address']['company'])."', ";
|
||||
$query .= (isset($params[$i]['deliveryAddress']['street']) && !empty($params[$i]['deliveryAddress']['street'])) ? "delivery_street='".utf8ToWin1250($params[$i]['deliveryAddress']['street'])."', " : "delivery_street='".utf8ToWin1250($params[$i]['address']['street'])."', ";
|
||||
$query .= (isset($params[$i]['deliveryAddress']['city']) && !empty($params[$i]['deliveryAddress']['city'])) ? "delivery_city='".utf8ToWin1250($params[$i]['deliveryAddress']['city'])."', " : "delivery_city='".utf8ToWin1250($params[$i]['address']['city'])."', ";
|
||||
$query .= (isset($params[$i]['deliveryAddress']['zip']) && !empty($params[$i]['deliveryAddress']['zip'])) ? "delivery_zip='".utf8ToWin1250($params[$i]['deliveryAddress']['zip'])."', " : "delivery_zip='".utf8ToWin1250($params[$i]['address']['zip'])."', ";
|
||||
$query .= (isset($params[$i]['deliveryAddress']['country']) && !empty($params[$i]['deliveryAddress']['country'])) ? "delivery_country='".utf8ToWin1250($params[$i]['deliveryAddress']['country'])."', " : "delivery_country='".utf8ToWin1250($params[$i]['address']['country'])."', ";
|
||||
$query .= (isset($params[$i]['bankAccounts'][0]['accountNo'])) ? "account_no='".utf8ToWin1250($params[$i]['bankAccounts'][0]['accountNo'])."', " : '';
|
||||
$query .= (isset($params[$i]['bankAccounts'][0]['code'])) ? "account_bank='".utf8ToWin1250($params[$i]['bankAccounts'][0]['code'])."', " : '';
|
||||
$query .= (isset($params[$i]['bankAccounts'][0]['symSpec'])) ? "account_symbol='".utf8ToWin1250($params[$i]['bankAccounts'][0]['symSpec'])."', " : '';
|
||||
$query .= (isset($params[$i]['dateAdded'])) ? "date_reg='".date('Y-m-d H:i:s', iso8601_decode($params[$i]['dateAdded']))."', " : 'date_reg=NOW(), ';
|
||||
$query .= "date_updated='".date('Y-m-d H:i:s')."' ";
|
||||
|
||||
if ($update) {
|
||||
$queryEnd = 'WHERE id='.intval($params[$i]['contactId']);
|
||||
|
||||
/*if(isset($requestParams['dateFrom']))
|
||||
{
|
||||
//$query .= " AND date_updated <= '".date("Y-m-d H:i:s", iso8601_decode($requestParams['dateFrom']))."'";
|
||||
}*/
|
||||
} else {
|
||||
$queryEnd = '';
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, $queryHead.$query.$queryEnd, true);
|
||||
|
||||
$SQL = sqlQuery($queryHead.$query.$queryEnd);
|
||||
|
||||
// pokud byl vlozen nebo upraven radek vrati type "ok" a status 200 nebo "warning" a jiny status
|
||||
// pokud nedoslo k upraveni radky ani k vlozeni noveho vrati "error"
|
||||
if (mysql_affected_rows() != 0) {
|
||||
if ($update) {
|
||||
$structItemDetails = POHODA_getDataItemDetails($params[$i]['contactId'], 'ok', 200);
|
||||
} else {
|
||||
$values = POHODA_setDataItemValues('contactId', $params[$i]['contactId'], 'id', sqlInsertId());
|
||||
$structItemDetails = POHODA_getDataItemDetails(sqlInsertId(), 'ok', 200, $values);
|
||||
}
|
||||
} elseif ($update) {
|
||||
// byla pozadovana uprava polozky ale contactId predane v params neexistuje v databazi
|
||||
// vlozi se jako nova polozka a vrati se id nove polozky
|
||||
$queryHead = 'INSERT INTO '.getTableName('users').' SET ';
|
||||
|
||||
// logError(__FILE__, __LINE__, "spatne id pokus o vlozeni nove polozky: ".$queryHead.$query, true);
|
||||
|
||||
$SQL = sqlQuery($queryHead.$query);
|
||||
|
||||
if (mysql_affected_rows() != 0) {
|
||||
$values = POHODA_setDataItemValues('contactId', $params[$i]['contactId'], 'id', sqlInsertId());
|
||||
$structItemDetails = POHODA_getDataItemDetails(sqlInsertId(), 'warning', 206, $values);
|
||||
} else {
|
||||
$values = POHODA_setDataItemValues('contactId', $params[$i]['contactId'], 'id', 0);
|
||||
$structItemDetails = POHODA_getDataItemDetails($params[$i]['contactId'], 'error', 400, $values);
|
||||
}
|
||||
} else {
|
||||
$structItemDetails = POHODA_getDataItemDetails(0, 'error', 500, '');
|
||||
}
|
||||
|
||||
$response['responseData'][$i] = $structItemDetails;
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($response['responseData'], true), true);
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
224
socket/Pohoda.Functions.php
Normal file
224
socket/Pohoda.Functions.php
Normal file
@@ -0,0 +1,224 @@
|
||||
<?php
|
||||
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
|
||||
defined('VALID_INCLUDE') or exit('Restricted area');
|
||||
|
||||
function POHODA_getDataItemDetails($contactId = 0, $type, $status, $values = '')
|
||||
{
|
||||
if ($contactId == 0) {
|
||||
$structItemDetails['dataItemId'] = '';
|
||||
} else {
|
||||
$structItemDetails['dataItemId'] = $contactId;
|
||||
}
|
||||
$structItemDetails['dataItemDetails'][0]['type'] = $type;
|
||||
$structItemDetails['dataItemDetails'][0]['status'] = $status;
|
||||
$structItemDetails['dataItemDetails'][0]['statusMessage'] = getTextString('errors', $status);
|
||||
|
||||
if (!empty($values)) {
|
||||
$structItemDetails['dataItemDetails'][0]['valueRequested']['name'] = $values['requestedValueName'];
|
||||
$structItemDetails['dataItemDetails'][0]['valueRequested']['value'] = $values['requestedValue'];
|
||||
$structItemDetails['dataItemDetails'][0]['valueAssigned']['name'] = $values['assignedValueName'];
|
||||
$structItemDetails['dataItemDetails'][0]['valueAssigned']['value'] = $values['assignedValue'];
|
||||
}
|
||||
|
||||
return $structItemDetails;
|
||||
}
|
||||
|
||||
function POHODA_setDataItemValues($requestedValueName, $requestedValue, $assignedValueName, $assignedValue)
|
||||
{
|
||||
$values['requestedValueName'] = $requestedValueName;
|
||||
$values['requestedValue'] = $requestedValue;
|
||||
$values['assignedValueName'] = $assignedValueName;
|
||||
$values['assignedValue'] = $assignedValue;
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
function updatePass($password, $id)
|
||||
{
|
||||
$new_hash = password_hash($password, PASSWORD_BCRYPT);
|
||||
sqlQuery('UPDATE '.getTableName('admins')." SET password='{$new_hash}' WHERE id={$id}");
|
||||
|
||||
return $new_hash;
|
||||
}
|
||||
|
||||
function POHODA_login($params)
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$requestParams = $params['requestParams'];
|
||||
|
||||
$session = ServiceContainer::getService('session');
|
||||
|
||||
if (!empty($requestParams['userName']) && !empty($requestParams['userPassw'])) {
|
||||
// expirovane loginy znepristupnit
|
||||
sqlQuery('UPDATE '.getTableName('admins')." SET active='N' WHERE date_valid<>'' AND date_valid<=NOW()");
|
||||
|
||||
$SQL = sqlQuery('SELECT id, password, OLD_PASSWORD(:password) AS passwGet
|
||||
FROM '.getTableName('admins')."
|
||||
WHERE login=:login AND active='Y'
|
||||
LIMIT 1", ['login' => $requestParams['userName'], 'password' => $requestParams['userPassw']]);
|
||||
if (sqlNumRows($SQL) == 1) {
|
||||
$log = sqlFetchArray($SQL);
|
||||
|
||||
// --------------------------------------------------
|
||||
// data pro informaci o prihlaeni administratora
|
||||
|
||||
// IP ADRESA
|
||||
$log['ip'] = '';
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$explode_ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
|
||||
$log['ip'] = $explode_ip[0];
|
||||
} else {
|
||||
$log['ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
|
||||
// DOMENOVA ADRESA
|
||||
$log['ip_name'] = '';
|
||||
if (isset($_SERVER['REMOTE_HOST']) && $_SERVER['REMOTE_HOST'] != '') {
|
||||
$log['ip_name'] = $_SERVER['REMOTE_HOST'];
|
||||
} else {
|
||||
$log['ip_name'] = gethostbyaddr($log['ip']);
|
||||
}
|
||||
$log['ip_name'] = strtolower($log['ip_name']);
|
||||
// --------------------------------------------------
|
||||
|
||||
$password = $requestParams['userPassw'];
|
||||
|
||||
if ($log['passwGet'] == $log['password']) {
|
||||
$password = updatePass($password, $log['id']);
|
||||
}
|
||||
|
||||
// porovnani zadaneho hesla
|
||||
if (password_verify($password, $log['password'])) {
|
||||
if (password_needs_rehash($log['password'], PASSWORD_BCRYPT)) {
|
||||
updatePass($password, $log['id']);
|
||||
}
|
||||
|
||||
$session->set('_logged', true);
|
||||
$session->set('_ctrlString', md5(getShopUniqueName().':'.getIP()));
|
||||
$session->set('_expiry', ceil(time() + 120));
|
||||
$session->set('_adminID', $log['id']);
|
||||
$session->set('_eshopID', $cfg['Program']['licence']['ID']);
|
||||
|
||||
// --------------------------------------------------
|
||||
// ulozeni pristupu administratora
|
||||
sqlQuery('INSERT INTO '.getTableName('admins_accesses')." SET
|
||||
id_admin='".$log['id']."', date_access=NOW(), ip='".$log['ip']."',
|
||||
ip_name='".$log['ip_name']."', login_status='OK' ");
|
||||
// --------------------------------------------------
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
$response['responseData']['sessionId'] = session_id();
|
||||
} // neplatne zadane heslo
|
||||
else {
|
||||
$error = 3;
|
||||
$session->set('_logged', false);
|
||||
$password = '';
|
||||
|
||||
// --------------------------------------------------
|
||||
// ulozeni pristupu administratora
|
||||
sqlQuery('INSERT INTO '.getTableName('admins_accesses')." SET
|
||||
id_admin='".$log['id']."', date_access=NOW(), ip='".$log['ip']."',
|
||||
ip_name='".$log['ip_name']."', login_status='PASSW' ");
|
||||
// --------------------------------------------------
|
||||
|
||||
$response = [
|
||||
'status' => 403,
|
||||
'statusMessage' => getTextString('errors', 403).' - spatne heslo',
|
||||
];
|
||||
}
|
||||
} // uzivatel nebyl vubec nalezen
|
||||
else {
|
||||
$error = 2;
|
||||
$session->set('_logged', false);
|
||||
$login = '';
|
||||
$password = '';
|
||||
|
||||
$response = [
|
||||
'status' => 403,
|
||||
'statusMessage' => getTextString('errors', 403).' - uzivatel nebyl nalezen',
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$response = [
|
||||
'status' => 403,
|
||||
'statusMessage' => getTextString('errors', 403).' - prazdne prihlasovaci udaje',
|
||||
];
|
||||
}
|
||||
|
||||
$session->save();
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
function POHODA_logout($params)
|
||||
{
|
||||
$requestParams = $params['requestParams'];
|
||||
|
||||
$session = ServiceContainer::getService('session');
|
||||
|
||||
if (isset($requestParams['sessionId'])) {
|
||||
$session->set('_logged', false);
|
||||
$session->remove('_adminID');
|
||||
$session->remove('_ip');
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
];
|
||||
} else {
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
];
|
||||
}
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
function POHODA_checkSession($sessionId)
|
||||
{
|
||||
// tmp hotfix
|
||||
// return true;
|
||||
|
||||
if (!$sessionId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$session = ServiceContainer::getService('session');
|
||||
|
||||
if ($session->isStarted()) {
|
||||
$session->save();
|
||||
}
|
||||
|
||||
$session->setId($sessionId);
|
||||
|
||||
$ret = $session->start();
|
||||
|
||||
// logError(__FILE__, __LINE__, session_id(), true);
|
||||
|
||||
if ($session->get('_logged', false)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function POHODA_unauthorized($params = null)
|
||||
{
|
||||
$response = [
|
||||
'status' => 403,
|
||||
'statusMessage' => getTextString('errors', 403),
|
||||
'requestedParams' => [],
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
381
socket/Pohoda.Invoices.php
Normal file
381
socket/Pohoda.Invoices.php
Normal file
@@ -0,0 +1,381 @@
|
||||
<?php
|
||||
|
||||
function POHODA_Invoices($params)
|
||||
{
|
||||
$request = $params['request'];
|
||||
|
||||
switch ($request) {
|
||||
// odesilani zmen do POHODY
|
||||
case 'download':
|
||||
return POHODA_InvoicesDownload($params);
|
||||
break;
|
||||
|
||||
// prijimani zmen z POHODY
|
||||
case 'upload':
|
||||
return POHODA_InvoicesUpload($params);
|
||||
break;
|
||||
|
||||
// pokud je spatny pozadavek
|
||||
default:
|
||||
$response = [
|
||||
'status' => 400,
|
||||
'statusMessage' => getTextString('errors', 400),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// odesilani zmen do POHODY
|
||||
|
||||
function POHODA_InvoicesDownload($params)
|
||||
{
|
||||
$params = $params['requestParams'];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
// pokud neni specifikovano datum od kdy hledat udaje vrati chybu
|
||||
if (!isset($params['dateFrom'])) {
|
||||
$response = [
|
||||
'status' => 406,
|
||||
'statusMessage' => getTextString('errors', 406),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
$response2 = php_xmlrpc_encode($response);
|
||||
|
||||
return new xmlrpcresp($response2);
|
||||
}
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
$query = 'SELECT * FROM '.getTableName('invoices')." WHERE date_updated >= '".date('Y-m-d H:i:s', iso8601_decode($params['dateFrom']))."'";
|
||||
|
||||
$SQL = sqlQuery($query);
|
||||
|
||||
if (sqlNumRows($SQL) == 0) {
|
||||
$response['status'] = 204;
|
||||
$response['statusMessage'] = getTextString('errors', 204);
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
while ($row = @mysql_fetch_assoc($SQL)) {
|
||||
// struktura pro vraceni
|
||||
$items = [];
|
||||
$TOTAL_PRICE = 0.0;
|
||||
|
||||
// ---------------------------------------------------
|
||||
$query = 'SELECT * FROM '.getTableName('invoices_items').' WHERE id_invoice='.intval($row['id']).' ';
|
||||
$SQL2 = sqlQuery($query);
|
||||
while ($row2 = @mysql_fetch_assoc($SQL2)) {
|
||||
$priceUnit = doubleval($row2['piece_']);
|
||||
$priceTotal = doubleval($row2['total_price']);
|
||||
|
||||
// pokud se ma posilat cena uz s DPH
|
||||
if (isset($cfg['Pohoda']['payVAT']) && $cfg['Pohoda']['payVAT'] === true) {
|
||||
$priceTotal = calcPrice($priceTotal, $row2['tax']);
|
||||
}
|
||||
|
||||
$TOTAL_PRICE += $priceTotal;
|
||||
|
||||
$items[] = [
|
||||
'code' => cs_win2ascii($row2['code']),
|
||||
'text' => cs_win2ascii($row2['item_descr']),
|
||||
'quantity' => intval($row2['quantity']),
|
||||
'unit' => cs_win2ascii($row2['quantity_unit']),
|
||||
'discountPercentage' => 0.0,
|
||||
'note' => cs_win2ascii($row2['note']),
|
||||
'guaranteeQuantity' => intval($row2['guarantee']),
|
||||
'guaranteeType' => cs_win2ascii($row2['guarantee_type']),
|
||||
'currency' => cs_win2ascii($row2['currency']),
|
||||
'priceUnit' => doubleval($row2['piece_price']),
|
||||
'priceTotal' => doubleval($row2['total_price']),
|
||||
'rateVAT' => doubleval($row2['vat']),
|
||||
];
|
||||
// ---------------------------------------------------
|
||||
}
|
||||
|
||||
$currencyDetails = [];
|
||||
$currencyDetails[0] = [
|
||||
'code' => cs_win2ascii($row['currency']),
|
||||
'rate' => 1,
|
||||
'amount' => 100,
|
||||
];
|
||||
|
||||
$delivery = split("[[:space:]]\-[[:space:]]", $row['delivery_type'], 2);
|
||||
|
||||
$dataItem = [];
|
||||
$dataItem = [
|
||||
'header' => [
|
||||
'invoiceId' => intval($row['id']),
|
||||
'invoiceNumber' => cs_win2ascii($row['invoice_number']),
|
||||
'originalDocumentNumber' => cs_win2ascii($row['invoice_number_external']),
|
||||
'invoiceType' => 'issued',
|
||||
'dateCreated' => iso8601_encode(strtotime($row['date_created'])),
|
||||
'dateAccounting' => iso8601_encode(strtotime($row['date_accounting'])),
|
||||
'dateDue' => iso8601_encode(strtotime($row['date_maturity'])),
|
||||
'paymentType' => cs_win2ascii($delivery[0]),
|
||||
'note' => cs_win2ascii($row['note_user']),
|
||||
'customer' => [
|
||||
'name' => cs_win2ascii($row['customer_name']),
|
||||
'surname' => cs_win2ascii($row['customer_surname']),
|
||||
'company' => cs_win2ascii($row['customer_firm']),
|
||||
'ico' => cs_win2ascii(substr($row['customer_ico'], 0, 10)),
|
||||
'dic' => cs_win2ascii(substr($row['customer_dic'], 0, 12)),
|
||||
'street' => cs_win2ascii($row['customer_street']),
|
||||
'city' => cs_win2ascii($row['customer_city']),
|
||||
'zip' => cs_win2ascii(substr($row['customer_zip'], 0, 5)),
|
||||
'country' => cs_win2ascii($row['customer_country']),
|
||||
'phone' => cs_win2ascii($row['customer_phone']),
|
||||
'email' => cs_win2ascii($row['customer_email']),
|
||||
],
|
||||
'bank' => [
|
||||
'accountNo' => cs_win2ascii($row['bank_account_number']),
|
||||
'code' => cs_win2ascii($row['bank_code']),
|
||||
'symVar' => cs_win2ascii($row['bank_var_symbol']),
|
||||
'symConst' => cs_win2ascii($row['bank_konst_symbol']),
|
||||
'symSpec' => cs_win2ascii($row['bank_spec_symbol']),
|
||||
'bankName' => cs_win2ascii($row['bank_name']),
|
||||
],
|
||||
],
|
||||
'items' => $items,
|
||||
'summary' => [
|
||||
'priceRounding' => 0,
|
||||
'priceTotal' => doubleval($TOTAL_PRICE),
|
||||
'currency' => cs_win2ascii($row['currency']),
|
||||
'currencyDetails' => $currencyDetails,
|
||||
],
|
||||
];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($dataItem, true), true);
|
||||
|
||||
$response['responseData'][$count] = $dataItem;
|
||||
// $response['responseData'][$count] = $row;
|
||||
$count++;
|
||||
|
||||
unset($delivery);
|
||||
}
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// prijimani zmen z POHODY
|
||||
|
||||
function POHODA_InvoicesUpload($params)
|
||||
{
|
||||
$requestParams = $params['requestParams'];
|
||||
|
||||
$params = $params['requestData'];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
'requestedParams' => $requestParams,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
// logError(__FILE__, __LINE__, "pocet: ".count($params), true);
|
||||
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
// pokud se posle dataItemStatus deleted smaze polozku z databaze
|
||||
if (isset($params[$i]['dataItemStatus']) && ($params[$i]['dataItemStatus'] == 'deleted')) {
|
||||
if (isset($params[$i]['header']['invoiceId']) && (!empty($params[$i]['header']['invoiceId']) || $params[$i]['header']['invoiceId'] != 0)) {
|
||||
if (mysql_affected_rows() != 0) {
|
||||
$structItemDetails = POHODA_getDataItemDetails($params[$i]['header']['invoiceId'], 'ok', 200, '');
|
||||
$response['responseData'][$i] = $structItemDetails;
|
||||
} else {
|
||||
$structItemDetails = POHODA_getDataItemDetails($params[$i]['header']['invoiceId'], 'warning', 404, '');
|
||||
$response['responseData'][$i] = $structItemDetails;
|
||||
}
|
||||
|
||||
continue;
|
||||
} else {
|
||||
$structItemDetails = POHODA_getDataItemDetails(0, 'error', 400, '');
|
||||
$response['responseData'][$i] = $structItemDetails;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// pokud se preda invoiceId nebo neni nulove provede se update polozky, jinak se vlozi nova
|
||||
if (isset($params[$i]['header']['invoiceId']) && (!empty($params[$i]['header']['invoiceId']) || $params[$i]['header']['invoiceId'] != 0)) {
|
||||
$update = true;
|
||||
$queryHead = 'UPDATE '.getTableName('invoices').' SET ';
|
||||
} else {
|
||||
$update = false;
|
||||
$queryHead = 'INSERT INTO '.getTableName('invoices').' SET ';
|
||||
}
|
||||
|
||||
$query = '';
|
||||
$type = ($params[$i]['header']['invoiceType'] == 'issued') ? 'invoice_out' : 'invoice_in';
|
||||
|
||||
if (!$update) {
|
||||
$query .= 'type_counter='.intval($GLOBALS['invoices-'.$type.'-counter']).', ';
|
||||
}
|
||||
$query .= (isset($params[$i]['header']['invoiceNumber'])) ? "invoice_number='".utf8ToWin1250($params[$i]['header']['invoiceNumber'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['invoiceType'])) ? "type='".utf8ToWin1250($type)."', " : '';
|
||||
$query .= (isset($params[$i]['header']['paymentType'])) ? "settlement_method='".utf8ToWin1250($params[$i]['header']['paymentType'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['name'])) ? "customer_name='".utf8ToWin1250($params[$i]['header']['customer']['name'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['surname'])) ? "customer_surname='".utf8ToWin1250($params[$i]['header']['customer']['surname'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['company'])) ? "customer_firm='".utf8ToWin1250($params[$i]['header']['customer']['company'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['street'])) ? "customer_street='".utf8ToWin1250($params[$i]['header']['customer']['street'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['city'])) ? "customer_city='".utf8ToWin1250($params[$i]['header']['customer']['city'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['zip'])) ? "customer_zip='".utf8ToWin1250($params[$i]['header']['customer']['zip'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['email'])) ? "customer_email='".utf8ToWin1250($params[$i]['header']['customer']['email'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['country'])) ? "customer_country='".utf8ToWin1250($params[$i]['header']['customer']['country'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['ico'])) ? "customer_ico='".utf8ToWin1250($params[$i]['header']['customer']['ico'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['dic'])) ? "customer_dic='".utf8ToWin1250($params[$i]['header']['customer']['dic'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['customer']['phone'])) ? "customer_phone='".utf8ToWin1250($params[$i]['header']['customer']['phone'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['dateCreated'])) ? "date_created='".date('Y-m-d H:i:s', iso8601_decode($params[$i]['header']['dateCreated']))."', " : '';
|
||||
$query .= (isset($params[$i]['header']['dateAccounting'])) ? "date_accounting='".date('Y-m-d H:i:s', iso8601_decode($params[$i]['header']['dateAccounting']))."', " : '';
|
||||
$query .= "date_updated='".date('Y-m-d H:i:s')."', ";
|
||||
$query .= (isset($params[$i]['header']['dateDue'])) ? "date_maturity='".date('Y-m-d H:i:s', iso8601_decode($params[$i]['header']['dateDue']))."', " : '';
|
||||
$query .= (isset($params[$i]['summary']['priceTotal'])) ? "total_price='".utf8ToWin1250($params[$i]['summary']['priceTotal'])."', " : '';
|
||||
$query .= (isset($params[$i]['summary']['currency'])) ? "currency='".utf8ToWin1250($params[$i]['summary']['currency'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['bank']['accountNo'])) ? "bank_account_number='".utf8ToWin1250($params[$i]['header']['bank']['accountNo'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['bank']['code'])) ? "bank_code='".utf8ToWin1250($params[$i]['header']['bank']['code'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['bank']['symVar'])) ? "bank_var_symbol='".utf8ToWin1250($params[$i]['header']['bank']['symVar'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['bank']['symConst'])) ? "bank_konst_symbol='".utf8ToWin1250($params[$i]['header']['bank']['symConst'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['bank']['symSpec'])) ? "bank_spec_symbol='".utf8ToWin1250($params[$i]['header']['bank']['symSpec'])."', " : '';
|
||||
$query .= (isset($params[$i]['header']['bank']['bankName'])) ? "bank_name='".utf8ToWin1250($params[$i]['header']['bank']['bankName'])."', " : '';
|
||||
$query = substr($query, 0, -2);
|
||||
|
||||
if ($update) {
|
||||
$queryEnd = 'WHERE id='.intval($params[$i]['header']['invoiceId']);
|
||||
} else {
|
||||
$queryEnd = '';
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, $queryHead.$query.$queryEnd, true);
|
||||
|
||||
$SQL = sqlQuery($queryHead.$query.$queryEnd);
|
||||
|
||||
// pokud byl vlozen nebo upraven radek vrati type "ok" a status 200 nebo "warning" a jiny status
|
||||
// pokud nedoslo k upraveni radky ani k vlozeni noveho vrati "error"
|
||||
if (mysql_affected_rows() != 0) {
|
||||
// die("ASDAS");
|
||||
if ($update) {
|
||||
$invoiceId = $params[$i]['header']['invoiceId'];
|
||||
$structItemDetails = POHODA_getDataItemDetails($invoiceId, 'ok', 200);
|
||||
|
||||
// ulozeni polozek objednavky
|
||||
$results = POHODA_InvoicesItemsUpload($params[$i], $invoiceId);
|
||||
} else {
|
||||
$invoiceId = mysql_insert_id();
|
||||
|
||||
// ulozeni polozek objednavky
|
||||
$results = POHODA_InvoicesItemsUpload($params[$i], $invoiceId);
|
||||
|
||||
$values = POHODA_setDataItemValues('invoiceId', $params[$i]['header']['invoiceId'], 'id', $invoiceId);
|
||||
$structItemDetails = POHODA_getDataItemDetails($invoiceId, 'ok', 200, $values);
|
||||
}
|
||||
|
||||
for ($j = 1; $j <= count($results); $j++) {
|
||||
$structItemDetails['dataItemDetails'][$j]['type'] = $results[$j - 1]['type'];
|
||||
$structItemDetails['dataItemDetails'][$j]['status'] = $results[$j - 1]['status'];
|
||||
$structItemDetails['dataItemDetails'][$j]['statusMessage'] = getTextString('errors', $results[$j - 1]['status']);
|
||||
}
|
||||
} elseif ($update) {
|
||||
// byla pozadovana uprava polozky ale contactId predane v params neexistuje v databazi
|
||||
// vlozi se jako nova polozka a vrati se id nove polozky
|
||||
$queryHead = 'INSERT INTO '.getTableName('invoices').' SET ';
|
||||
|
||||
// logError(__FILE__, __LINE__, "spatne id pokus o vlozeni nove polozky: ".$queryHead.$query, true);
|
||||
|
||||
$SQL = sqlQuery($queryHead.$query);
|
||||
$invoiceId = mysql_insert_id();
|
||||
|
||||
if (mysql_affected_rows() != 0) {
|
||||
$ID = sqlInsertId();
|
||||
|
||||
// ulozeni polozek objednavky
|
||||
$result = POHODA_InvoicesItemsUpload($params[$i], $invoiceId);
|
||||
|
||||
$values = POHODA_setDataItemValues('invoiceId', $params[$i]['header']['invoiceId'], 'id', $invoiceId);
|
||||
$structItemDetails = POHODA_getDataItemDetails($ID, 'warning', 206, $values);
|
||||
|
||||
for ($j = 1; $j <= count($results); $j++) {
|
||||
$structItemDetails['dataItemDetails'][$j]['type'] = $results[$j - 1]['type'];
|
||||
$structItemDetails['dataItemDetails'][$j]['status'] = $results[$j - 1]['status'];
|
||||
$structItemDetails['dataItemDetails'][$j]['statusMessage'] = getTextString('errors', $results[$j - 1]['status']);
|
||||
}
|
||||
} else {
|
||||
$values = POHODA_setDataItemValues('invoiceId', $params[$i]['header']['invoiceId'], 'id', 0);
|
||||
$structItemDetails = POHODA_getDataItemDetails($params[$i]['header']['invoiceId'], 'error', 404, $values);
|
||||
}
|
||||
} else {
|
||||
$structItemDetails = POHODA_getDataItemDetails(0, 'error', 500, '');
|
||||
}
|
||||
|
||||
$response['responseData'][$i] = $structItemDetails;
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($response['responseData'], true), true);
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
// smaze dosavadni polozky objednavky a ulozi nove
|
||||
function POHODA_InvoicesItemsUpload($params, $invoiceId)
|
||||
{
|
||||
$params = $params['items'];
|
||||
|
||||
$result = [];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
// smazani dosavadnich polozek objednavky
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$query = '';
|
||||
|
||||
$priceUnit = doubleval($params[$i]['priceUnit']);
|
||||
$priceTotal = doubleval($params[$i]['priceTotal']);
|
||||
$vat = doubleval($params[$i]['rateVAT']);
|
||||
/*// pokud je sleva
|
||||
if(isset($params[$i]['discountPercentage']) && $params[$i]['discountPercentage'] > 0)
|
||||
{
|
||||
$priceUnit = doubleval(number_format((doubleval($params[$i]['priceUnit']) - (doubleval($params[$i]['priceUnit']) * (abs(doubleval($params[$i]['discountPercentage'])) / 100))), 3, ".", ""));
|
||||
$priceTotal = doubleval(number_format((doubleval($params[$i]['priceTotal']) - (doubleval($params[$i]['priceTotal']) * (abs(doubleval($params[$i]['discountPercentage'])) / 100))), 3, ".", ""));
|
||||
}*/
|
||||
|
||||
// pokud se ma posilat cena uz s DPH
|
||||
if (isset($cfg['Pohoda']['payVAT']) && $cfg['Pohoda']['payVAT'] === true && $vat > 0) {
|
||||
$priceUnit = doubleval(number_format($priceUnit / (1 + ($vat / 100)), 3, '.', ''));
|
||||
$priceTotal = doubleval(number_format($priceTotal / (1 + ($vat / 100)), 3, '.', ''));
|
||||
}
|
||||
|
||||
$query .= 'id_invoice='.intval($invoiceId).'';
|
||||
$query .= (isset($params[$i]['code'])) ? ", code='".utf8ToWin1250($params[$i]['code'])."'" : '';
|
||||
$query .= (isset($params[$i]['text'])) ? ", item_descr='".utf8ToWin1250($params[$i]['text'])."'" : '';
|
||||
$query .= (isset($params[$i]['quantity'])) ? ', quantity='.intval($params[$i]['quantity']).'' : '';
|
||||
$query .= (isset($params[$i]['unit'])) ? ", quantity_unit='".utf8ToWin1250($params[$i]['unit'])."'" : '';
|
||||
$query .= (isset($params[$i]['guaranteeQuantity'])) ? ", guarantee='".intval($params[$i]['guaranteeQuantity'])."'" : '';
|
||||
$query .= (isset($params[$i]['guaranteeType'])) ? ", guarantee_type='".utf8ToWin1250($params[$i]['guaranteeType'])."'" : '';
|
||||
$query .= (isset($params[$i]['currency'])) ? ", currency='".utf8ToWin1250($params[$i]['currency'])."'" : '';
|
||||
$query .= (isset($params[$i]['priceUnit'])) ? ", piece_price='".doubleval($priceUnit)."'" : '';
|
||||
$query .= (isset($params[$i]['priceTotal'])) ? ", total_price='".doubleval($priceTotal)."'" : '';
|
||||
$query .= (isset($params[$i]['rateVAT'])) ? ", vat='".doubleval($params[$i]['rateVAT'])."'" : '';
|
||||
|
||||
// logError(__FILE__, __LINE__, $queryHead.$query, true);
|
||||
|
||||
$SQL = sqlQuery($queryHead.$query);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
376
socket/Pohoda.Orders.php
Normal file
376
socket/Pohoda.Orders.php
Normal file
@@ -0,0 +1,376 @@
|
||||
<?php
|
||||
|
||||
// ##############################################################
|
||||
|
||||
use KupShop\OrderingBundle\Util\Order\OrderItemInfo;
|
||||
|
||||
function POHODA_Orders($params)
|
||||
{
|
||||
$request = $params['request'];
|
||||
|
||||
switch ($request) {
|
||||
// odesilani zmen do POHODY
|
||||
case 'download':
|
||||
return POHODA_OrdersDownload($params);
|
||||
break;
|
||||
|
||||
// prijimani zmen z POHODY
|
||||
case 'upload':
|
||||
return POHODA_OrdersUpload($params);
|
||||
break;
|
||||
|
||||
// pokud je spatny pozadavek
|
||||
default:
|
||||
$response = [
|
||||
'status' => 400,
|
||||
'statusMessage' => getTextString('errors', 400),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// odesilani zmen do POHODY
|
||||
|
||||
function formatPhoneNumber($phone)
|
||||
{
|
||||
return preg_replace('/^\+42\d/', '', $phone);
|
||||
}
|
||||
|
||||
function POHODA_OrdersDownload($params)
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$params = $params['requestParams'];
|
||||
|
||||
logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
// pokud neni specifikovano datum od kdy hledat udaje vrati chybu
|
||||
if (!isset($params['dateFrom'])) {
|
||||
$response = [
|
||||
'status' => 406,
|
||||
'statusMessage' => getTextString('errors', 406),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
$response2 = php_xmlrpc_encode($response);
|
||||
|
||||
return new xmlrpcresp($response2);
|
||||
}
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
$query = POHODA_OrdersQuery($params);
|
||||
|
||||
$SQL = sqlQuery($query);
|
||||
// logError(__FILE__, __LINE__, "Dotaz:$query, pocet radku: ".sqlNumRows($SQL), true);
|
||||
if (sqlNumRows($SQL) == 0) {
|
||||
$response['status'] = 204;
|
||||
$response['statusMessage'] = getTextString('errors', 204);
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
$POHODA_OSS_VAT_LEVELS = [
|
||||
OrderItemInfo::VAT_HIGH => 'historyHigh',
|
||||
OrderItemInfo::VAT_LOW => 'historyLow',
|
||||
OrderItemInfo::VAT_LOW2 => 'historyThird',
|
||||
OrderItemInfo::VAT_NONE => 'none',
|
||||
];
|
||||
|
||||
$count = 0;
|
||||
foreach ($SQL as $row) {
|
||||
// struktura pro vraceni
|
||||
$items = [];
|
||||
$TOTAL_PRICE = DecimalConstants::zero();
|
||||
|
||||
$order = new Order($row['id']);
|
||||
$order->createFromDB($row['id']);
|
||||
$flags = $order->getFlags();
|
||||
$oss = $flags['OSS'] ?? false;
|
||||
|
||||
$vats = [];
|
||||
$vatsSQL = sqlQueryBuilder()->select('*')->from('vats');
|
||||
if (findModule(\Modules::OSS_VATS)) {
|
||||
$vatsSQL->where(\Query\Operator::equals(['id_country' => $order->delivery_country]));
|
||||
}
|
||||
foreach ($vatsSQL->execute() as $vat) {
|
||||
$data = json_decode($vat['data'] ?: '', true);
|
||||
$vats[$vat['vat']] = $data['level'] ?? 'high';
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
$query = 'SELECT * FROM '.getTableName('order_items').' WHERE id_order='.intval($row['id']);
|
||||
$SQL2 = sqlQuery($query);
|
||||
foreach ($SQL2 as $row2) {
|
||||
$code = POHODA_CreateProductCode($row2['descr'], $row2);
|
||||
|
||||
$priceUnit = toDecimal($row2['piece_price']);
|
||||
$priceTotal = toDecimal($row2['total_price']);
|
||||
|
||||
// pokud se ma posilat cena uz s DPH
|
||||
if (isset($cfg['Pohoda']['payVAT']) && $cfg['Pohoda']['payVAT'] === true) {
|
||||
$priceUnit = calcPrice($priceUnit, $row2['tax']);
|
||||
$priceTotal = calcPrice($priceTotal, $row2['tax']);
|
||||
}
|
||||
|
||||
$TOTAL_PRICE = $TOTAL_PRICE->add($priceTotal);
|
||||
|
||||
$levelVat = $vats[$row2['tax']] ?? 'high';
|
||||
|
||||
if ($row2['tax'] == 0) {
|
||||
$levelVat = 'none';
|
||||
}
|
||||
|
||||
$items[] = [
|
||||
'code' => cs_win2ascii($code),
|
||||
'text' => cs_win2ascii($row2['descr']),
|
||||
'quantity' => intval($row2['pieces']),
|
||||
'unit' => 'ks',
|
||||
'discountPercentage' => 0.0,
|
||||
'note' => POHODA_OrdersNote($row2),
|
||||
'guaranteeQuantity' => null,
|
||||
'guaranteeType' => 'month',
|
||||
'currency' => $order->currency,
|
||||
'priceUnit' => $priceUnit->printFloatValue(),
|
||||
'priceTotal' => $priceTotal->printFloatValue(),
|
||||
'rateVAT' => doubleval($row2['tax']),
|
||||
'rawRateVAT' => doubleval($row2['tax']),
|
||||
'levelVAT' => $POHODA_OSS_VAT_LEVELS[$levelVat] ?? 'historyHigh',
|
||||
];
|
||||
unset($a);
|
||||
// ---------------------------------------------------
|
||||
}
|
||||
|
||||
$currencyDetails = [];
|
||||
$currencyDetails[0] = [
|
||||
'code' => $order->currency,
|
||||
'rate' => $order->currency_rate,
|
||||
'amount' => 1,
|
||||
];
|
||||
|
||||
$deliveryType = $order->getDeliveryType();
|
||||
|
||||
$deliveryName = $deliveryType->delivery ?? '';
|
||||
$paymentName = $deliveryType->payment ?? '';
|
||||
|
||||
if (findModule(Modules::PRICE_LEVELS) && !empty($order->id_user)) {
|
||||
$user = User::createFromId($order->id_user);
|
||||
$priceLevel = $user->getPriceLevel();
|
||||
if ($priceLevel) {
|
||||
$priceLevelName = $priceLevel->name;
|
||||
}
|
||||
}
|
||||
|
||||
$dataItem = [];
|
||||
$dataItem = [
|
||||
'header' => [
|
||||
'orderId' => intval($row['id']),
|
||||
'orderNumber' => cs_win2ascii($row['order_no']),
|
||||
'orderType' => 'received',
|
||||
'dateCreated' => iso8601_encode(strtotime($row['date_created'] ?? '')),
|
||||
'dateAccepted' => iso8601_encode(strtotime($row['date_accept'] ?? '')),
|
||||
'dateHandled' => iso8601_encode(strtotime($row['date_updated'] ?? '')),
|
||||
'status_payed' => cs_win2ascii($order->status_payed ? 'true' : 'false'),
|
||||
'paymentType' => cs_win2ascii($paymentName),
|
||||
'deliveryType' => cs_win2ascii($deliveryName),
|
||||
'note' => cs_win2ascii($row['note_user']),
|
||||
'priceLevel' => cs_win2ascii($priceLevelName ?? ''),
|
||||
'noteAdmin' => getNoteAdmin($order),
|
||||
'oss' => cs_win2ascii($oss ? 'true' : 'false'),
|
||||
'customer' => [
|
||||
'name' => cs_win2ascii($row['invoice_name']),
|
||||
'surname' => cs_win2ascii($row['invoice_surname']),
|
||||
'company' => cs_win2ascii($row['invoice_firm']),
|
||||
'ico' => cs_win2ascii(substr($row['invoice_ico'], 0, 10)),
|
||||
'dic' => cs_win2ascii(substr($row['invoice_dic'], 0, 18)),
|
||||
'street' => cs_win2ascii($row['invoice_street']),
|
||||
'city' => cs_win2ascii($row['invoice_city']),
|
||||
'zip' => cs_win2ascii(substr($row['invoice_zip'], 0, 10)),
|
||||
'country' => cs_win2ascii($row['invoice_country']),
|
||||
'phone' => cs_win2ascii(formatPhoneNumber($row['invoice_phone'])),
|
||||
'email' => cs_win2ascii($row['invoice_email']),
|
||||
'state' => cs_win2ascii($row['invoice_state']),
|
||||
],
|
||||
'delivery' => [
|
||||
'name' => cs_win2ascii($row['delivery_name']),
|
||||
'surname' => cs_win2ascii($row['delivery_surname']),
|
||||
'company' => cs_win2ascii($row['delivery_firm']),
|
||||
'street' => cs_win2ascii($row['delivery_street']),
|
||||
'city' => cs_win2ascii($row['delivery_city']),
|
||||
'zip' => cs_win2ascii(substr($row['delivery_zip'], 0, 10)),
|
||||
'country' => cs_win2ascii($row['delivery_country']),
|
||||
'phone' => cs_win2ascii(formatPhoneNumber($row['invoice_phone'])),
|
||||
'email' => cs_win2ascii($row['invoice_email']),
|
||||
'state' => cs_win2ascii($row['delivery_state']),
|
||||
],
|
||||
'bank' => [
|
||||
'accountNo' => cs_win2ascii($row['account_no'] ?? ''),
|
||||
'code' => '',
|
||||
'symVar' => cs_win2ascii($row['account_symbol'] ?? ''),
|
||||
'symConst' => '',
|
||||
'symSpec' => cs_win2ascii($row['account_symbol'] ?? ''),
|
||||
'bankName' => cs_win2ascii($row['account_bank'] ?? ''),
|
||||
],
|
||||
],
|
||||
'items' => $items,
|
||||
'summary' => [
|
||||
'priceRounding' => 0,
|
||||
'priceTotal' => $TOTAL_PRICE->printFloatValue(),
|
||||
'currency' => $order->currency,
|
||||
'currencyDetails' => $currencyDetails,
|
||||
],
|
||||
];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($dataItem, true), true);
|
||||
|
||||
$response['responseData'][$count] = $dataItem;
|
||||
// $response['responseData'][$count] = $row;
|
||||
$count++;
|
||||
|
||||
unset($delivery);
|
||||
}
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// prijimani zmen z POHODY
|
||||
|
||||
function POHODA_OrdersUpload($params)
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$requestParams = $params['requestParams'];
|
||||
|
||||
$params = $params['requestData'];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
'requestedParams' => $requestParams,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
foreach ($params as $item) {
|
||||
$order = $item['header'];
|
||||
|
||||
$orderRow = POHODA_FindOrderByCode($order['code'], $item);
|
||||
|
||||
if (!$orderRow) {
|
||||
$structItemDetails = POHODA_getDataItemDetails($order['code'], 'warning', 404, '');
|
||||
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Preskočit už vyřízené */
|
||||
if (!empty($cfg['Sync']['Orders']['isExecuted']) && $order['isExecuted'] == 'true' && $orderRow['status'] == $cfg['Sync']['Orders']['isExecuted']) {
|
||||
$structItemDetails = POHODA_getDataItemDetails(0, 'ok', 200, '');
|
||||
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($cfg['Sync']['Orders']['package_id']) && !empty($order['package_id']) && empty($orderRow['package_id'])) {
|
||||
sqlQuery('UPDATE orders set package_id=:package_id where id=:id', ['package_id' => $order['package_id'], 'id' => $orderRow['id']]);
|
||||
}
|
||||
|
||||
$orderObj = new Order($orderRow['id']);
|
||||
$orderObj->createFromDB($orderRow['id']);
|
||||
|
||||
/* Aktualizace do stavu "vyřízeno" - nastavuje se v configu do jakého stavu to má skočit */
|
||||
if (!empty($cfg['Sync']['Orders']['changeStatus'])) {
|
||||
POHODA_ChangeOrderStatus($orderObj, $item);
|
||||
}
|
||||
|
||||
$structItemDetails = POHODA_getDataItemDetails($orderRow['id'], 'ok', 200, '');
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
}
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
// smaze dosavadni polozky objednavky a ulozi nove
|
||||
function POHODA_OrdersItemsUpload($params, $orderId)
|
||||
{
|
||||
$params = $params['items'];
|
||||
|
||||
$result = [];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
// smazani dosavadnich polozek objednavky
|
||||
$queryDelete = 'DELETE FROM '.getTableName('order_items').' WHERE id_order='.intval($orderId).' ';
|
||||
|
||||
// logError(__FILE__, __LINE__, $queryDelete, true);
|
||||
|
||||
$SQLDelete = sqlQuery($queryDelete);
|
||||
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
// vyber id_product v shopden na zaklade code
|
||||
// pokud nenajde produkt s zadanym kodem ulozi do id_product 0
|
||||
$queryIdProduct = 'SELECT id FROM '.getTableName('products')." WHERE code='".utf8ToWin1250($params[$i]['code'])."'";
|
||||
|
||||
$SQL = sqlQuery($queryIdProduct);
|
||||
|
||||
if (sqlNumRows($SQL) != 0) {
|
||||
$productId = sqlResult($SQL, 0, 'id');
|
||||
$result[$i]['type'] = 'ok';
|
||||
$result[$i]['status'] = 200;
|
||||
$result[$i]['statusMessage'] = getTextString('errors', 200);
|
||||
} else {
|
||||
$productId = 0;
|
||||
$result[$i]['type'] = 'warning';
|
||||
$result[$i]['status'] = 200;
|
||||
$result[$i]['statusMessage'] = getTextString('errors', 200);
|
||||
}
|
||||
|
||||
$queryHead = 'INSERT INTO '.getTableName('order_items').' SET ';
|
||||
|
||||
$query = '';
|
||||
|
||||
$priceUnit = doubleval($params[$i]['priceUnit']);
|
||||
$priceTotal = doubleval($params[$i]['priceTotal']);
|
||||
$vat = doubleval($params[$i]['rateVAT']);
|
||||
// pokud je sleva
|
||||
if (isset($params[$i]['discountPercentage']) && $params[$i]['discountPercentage'] > 0) {
|
||||
$priceUnit = doubleval(number_format(doubleval($params[$i]['priceUnit']) - (doubleval($params[$i]['priceUnit']) * (abs(doubleval($params[$i]['discountPercentage'])) / 100)), 3, '.', ''));
|
||||
$priceTotal = doubleval(number_format(doubleval($params[$i]['priceTotal']) - (doubleval($params[$i]['priceTotal']) * (abs(doubleval($params[$i]['discountPercentage'])) / 100)), 3, '.', ''));
|
||||
}
|
||||
|
||||
// pokud se ma posilat cena uz s DPH
|
||||
if (isset($cfg['Pohoda']['payVAT']) && $cfg['Pohoda']['payVAT'] === true && $vat > 0) {
|
||||
$priceUnit = doubleval(number_format($priceUnit / (1 + ($vat / 100)), 3, '.', ''));
|
||||
$priceTotal = doubleval(number_format($priceTotal / (1 + ($vat / 100)), 3, '.', ''));
|
||||
}
|
||||
|
||||
$query .= 'id_order='.intval($orderId).', ';
|
||||
$query .= 'id_product='.intval($productId).', ';
|
||||
$query .= (isset($params[$i]['quantity'])) ? "pieces='".intval($params[$i]['quantity'])."', " : '';
|
||||
$query .= (isset($params[$i]['priceUnit'])) ? "piece_price='".doubleval($priceUnit)."', " : '';
|
||||
$query .= (isset($params[$i]['priceTotal'])) ? "total_price='".doubleval($priceTotal)."', " : '';
|
||||
$query .= (isset($params[$i]['text'])) ? "descr='".utf8ToWin1250($params[$i]['text'])."', " : '';
|
||||
$query .= (isset($params[$i]['rateVAT'])) ? "tax='".utf8ToWin1250($vat)."'" : '';
|
||||
|
||||
// logError(__FILE__, __LINE__, $queryHead.$query, true);
|
||||
|
||||
$SQL = sqlQuery($queryHead.$query);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
832
socket/Pohoda.Products.php
Normal file
832
socket/Pohoda.Products.php
Normal file
@@ -0,0 +1,832 @@
|
||||
<?php
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
use KupShop\CatalogBundle\Section\SectionTree;
|
||||
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
||||
|
||||
$vat = [];
|
||||
$SQL = sqlQuery('SELECT id, vat
|
||||
FROM '.getTableName('vats').' ');
|
||||
while ($row = sqlFetchArray($SQL)) {
|
||||
$GLOBALS['vat'][$row['id']] = $row['vat'];
|
||||
}
|
||||
unset($row);
|
||||
|
||||
// kontrola delky zpracovani skriptu
|
||||
controlTimeLimit();
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
$producer = [];
|
||||
$SQL = sqlQuery('SELECT id, name
|
||||
FROM '.getTableName('producers').' ');
|
||||
while ($row = sqlFetchArray($SQL)) {
|
||||
$GLOBALS['producer'][$row['id']] = strtolower(trim($row['name']));
|
||||
}
|
||||
unset($row);
|
||||
|
||||
function getVatID($val)
|
||||
{
|
||||
global $cfg;
|
||||
$key = 0;
|
||||
|
||||
if (($key = array_search($val, $GLOBALS['vat'])) == false) {
|
||||
$SQL = sqlQuery('INSERT INTO '.getTableName('vats')." (vat,is_default) VALUES ('".$val."','N')", '@');
|
||||
$key = sqlInsertId();
|
||||
$GLOBALS['vat'][$key] = $val;
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
function getProducer($val)
|
||||
{
|
||||
global $cfg;
|
||||
$key = 0;
|
||||
|
||||
$searchVal = strtolower(trim($val));
|
||||
if (($key = array_search($searchVal, $GLOBALS['producer'])) == false && $searchVal != '') {
|
||||
try {
|
||||
$SQL = sqlQuery('INSERT INTO '.getTableName('producers').' (name) VALUES (:val)', ['val' => $val]);
|
||||
$key = sqlInsertId();
|
||||
} catch (Exception $e) {
|
||||
$SQL = sqlFetchAssoc(sqlQuery('SELECT p.id FROM '.getTableName('producers').' AS p WHERE (p.name) = (:val)', ['val' => $val]));
|
||||
$key = $SQL['id'];
|
||||
}
|
||||
$GLOBALS['producer'][$key] = $searchVal;
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
function updatable(&$header, $field, $create)
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
if (empty($cfg['Sync']['Fields'])) {
|
||||
logError(__FILE__, __LINE__, 'Nejsou nastaveny pole pro synchronizaci!');
|
||||
}
|
||||
|
||||
if (isset($header[$field])) {
|
||||
if (isset($cfg['Sync']['Fields'][$field])) {
|
||||
$value = $cfg['Sync']['Fields'][$field];
|
||||
|
||||
return $create || (!$create && $value);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function POHODA_Products(&$params)
|
||||
{
|
||||
$request = $params['request'];
|
||||
|
||||
switch ($request) {
|
||||
// odesilani zmen do POHODY
|
||||
case 'download':
|
||||
return POHODA_ProductsDownload($params);
|
||||
break;
|
||||
|
||||
// prijimani zmen z POHODY
|
||||
case 'upload':
|
||||
return POHODA_ProductsUpload($params);
|
||||
break;
|
||||
|
||||
// pokud je spatny pozadavek
|
||||
default:
|
||||
$response = [
|
||||
'status' => 400,
|
||||
'statusMessage' => getTextString('errors', 400),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// odesilani zmen do POHODY
|
||||
|
||||
function POHODA_ProductsDownload(&$params)
|
||||
{
|
||||
$producer = [];
|
||||
$SQL = sqlQuery('SELECT id, name FROM '.getTableName('producers').' ');
|
||||
while ($row = sqlFetchArray($SQL)) {
|
||||
$producer[$row['id']] = $row['name'];
|
||||
}
|
||||
unset($row);
|
||||
|
||||
$params = $params['requestParams'];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
// pokud neni specifikovano datum od kdy hledat udaje vrati chybu
|
||||
if (!isset($params['dateFrom'])) {
|
||||
$response = [
|
||||
'status' => 406,
|
||||
'statusMessage' => getTextString('errors', 406),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
$response2 = php_xmlrpc_encode($response);
|
||||
|
||||
return new xmlrpcresp($response2);
|
||||
}
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
'serverTimestamp' => iso8601_encode(time()),
|
||||
'requestedParams' => $params,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
$query = 'SELECT pv.id, p.title, p.code, p.price, p.vat, p.discount, p.guarantee, p.producer, p.long_descr, p.parameters, pv.in_store, p.pieces_sold
|
||||
FROM '.getTableName('products').' p JOIN '.getTableName('products_variations')." pv ON p.id=pv.id_product
|
||||
WHERE updated >= '".date('Y-m-d H:i:s', iso8601_decode($params['dateFrom']))."'";
|
||||
|
||||
$SQL = sqlQuery($query);
|
||||
|
||||
if (sqlNumRows($SQL) == 0) {
|
||||
$response['status'] = 204;
|
||||
$response['statusMessage'] = getTextString('errors', 204);
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
while ($row = @sqlFetchAssoc($SQL)) {
|
||||
$pictures = [];
|
||||
|
||||
$dataItem = [
|
||||
'header' => [
|
||||
'productId' => intval($row['id']),
|
||||
'title' => cs_win2ascii($row['title']),
|
||||
'code' => cs_win2ascii(POHODA_CreateVariationCode($row['code'], $row['id'])),
|
||||
'price' => doubleval($row['price']),
|
||||
'rateVAT' => doubleval($row['vat']),
|
||||
'discount' => doubleval($row['discount']),
|
||||
'guaranteeType' => 'month',
|
||||
'guaranteeQuantity' => intval($row['guarantee']),
|
||||
'producer' => cs_win2ascii($producer[$row['producer']]),
|
||||
'description' => cs_win2ascii($row['long_descr']),
|
||||
'specification' => cs_win2ascii($row['parameters']),
|
||||
'stockQuantity' => intval($row['in_store']),
|
||||
'piecesSold' => intval($row['pieces_sold']),
|
||||
],
|
||||
'pictures' => $pictures,
|
||||
];
|
||||
|
||||
$response['responseData'][$count] = $dataItem;
|
||||
// $response['responseData'][$count] = $row;
|
||||
$count++;
|
||||
|
||||
unset($pictures);
|
||||
}
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------
|
||||
// prijimani zmen z POHODY
|
||||
|
||||
function POHODA_ProductsUpload(&$params)
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
$requestParams = &$params['requestParams'];
|
||||
$params = &$params['requestData'];
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($params, true), true);
|
||||
|
||||
$response = [
|
||||
'status' => 200,
|
||||
'statusMessage' => getTextString('errors', 200),
|
||||
'requestedParams' => $requestParams,
|
||||
'responseData' => [],
|
||||
];
|
||||
|
||||
// logError(__FILE__, __LINE__, 'Pohoda: pocet produktu: '.count($params), true);
|
||||
// logError(__FILE__, __LINE__, 'Prvni synchronizovany: '.print_r(reset($params), true), true);
|
||||
|
||||
$updated_codes = [];
|
||||
|
||||
foreach ($params as $param) {
|
||||
if (!empty($param['header']['type'])) {
|
||||
$response['responseData'][] = call_user_func("POHODA_ProductsUpload_{$param['header']['type']}", $param);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse product code and separate code/variants
|
||||
$product = POHODA_ParseProductCode($param['header']['code'], $param['header']);
|
||||
$param['header']['code'] = $product['code'];
|
||||
|
||||
if (!empty($product['productId'])) {
|
||||
$param['header']['productId'] = $product['productId'];
|
||||
}
|
||||
if (!empty($product['variationId'])) {
|
||||
$param['header']['variationId'] = $product['variationId'];
|
||||
}
|
||||
|
||||
if (!isset($param['header']['productId'])) {
|
||||
$param['header']['productId'] = 0;
|
||||
}
|
||||
|
||||
// handle variant ID in product ID
|
||||
if ($param['header']['productId'] < 0) {
|
||||
$query = 'SELECT p.id, p.code FROM products_variations pv LEFT JOIN '.getTableName('products').' p ON pv.id_product=p.id WHERE pv.id='.(-$param['header']['productId']);
|
||||
$SQL = sqlQuery($query);
|
||||
if ($row = sqlFetchAssoc($SQL)) {
|
||||
if ($row['code'] == $param['header']['code']) {
|
||||
$param['header']['variationId'] = -$param['header']['productId'];
|
||||
$param['header']['productId'] = $row['id'];
|
||||
} else {
|
||||
// logError(__FILE__, __LINE__, "Product code differ!: ".print_r($param, true)." != ".print_r($row, true), true);
|
||||
$param['header']['productId'] = 0;
|
||||
}
|
||||
} else {
|
||||
$param['header']['productId'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$param['header']['productIdOld'] = $param['header']['productId'];
|
||||
|
||||
$structItemDetails = null;
|
||||
|
||||
// pokud se posle dataItemStatus deleted smaze polozku z databaze
|
||||
if (isset($param['dataItemStatus']) && ($param['dataItemStatus'] == 'deleted')) {
|
||||
// logError(__FILE__, __LINE__, "Delete product: ".print_r($param, true)." - ".print_r($product, true), true);
|
||||
|
||||
if (!empty($cfg['Sync']['DeleteProducts']) && !empty($param['header']['productId'])) {
|
||||
$productObj = new Product($param['header']['productId']);
|
||||
|
||||
if (count($product['variants']) != 0 && !empty($param['header']['variationId'])) {
|
||||
// Delete variant
|
||||
// logError(__FILE__, __LINE__, "Deleting product: {$param['header']['productId']} variation: {$param['header']['variationId']}");
|
||||
$productObj->deleteVariation($param['header']['variationId']);
|
||||
|
||||
$structItemDetails = POHODA_getDataItemDetails($param['header']['productId'], 'ok', 200, '');
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
|
||||
continue;
|
||||
} elseif (count($product['variants']) == 0) {
|
||||
// Delete product without variants
|
||||
// logError(__FILE__, __LINE__, "Deleting product: {$param['header']['productId']}");
|
||||
$rows = $productObj->deleteVariation();
|
||||
|
||||
if ($rows != 0) {
|
||||
$structItemDetails = POHODA_getDataItemDetails($param['header']['productId'], 'ok', 200, '');
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
} else {
|
||||
$structItemDetails = POHODA_getDataItemDetails($param['header']['productId'], 'warning', 404, '');
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, "Not handled delete: ".print_r($params[$i], true)." - ".print_r($product, true));
|
||||
|
||||
$structItemDetails = POHODA_getDataItemDetails($param['header']['productId'], 'ok', 200, '');
|
||||
$structItemDetails['dataItemId'] = $param['header']['id'];
|
||||
// $structItemDetails = POHODA_getDataItemDetails(0, 'error', 400, '');
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($param['header']['code'])) {
|
||||
if (!isset($cfg['Sync']['skipErrors'])) {
|
||||
logError(__FILE__, __LINE__, 'Empty code: '.$param['header']['code'], true);
|
||||
}
|
||||
$structItemDetails = POHODA_getDataItemDetails(0, 'error', 400, '');
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($param['header']['productId'] == 0) {
|
||||
$query = 'SELECT id FROM '.getTableName('products')." WHERE code='".$param['header']['code']."'";
|
||||
$SQL = sqlQuery($query);
|
||||
if ($row = sqlFetchAssoc($SQL)) {
|
||||
$param['header']['productId'] = $row['id'];
|
||||
|
||||
/*if(!isset($updated_codes[$param['header']['code']])){
|
||||
//logError(__FILE__, __LINE__, "Deleting previous variations: ".$param['header']['productId'].", code: '".$param['header']['code']."'", true);
|
||||
sqlQuery("DELETE FROM ".getTableName("products_variations_choices_categorization")." WHERE id_product=".$param['header']['productId']);
|
||||
sqlQuery("DELETE FROM pv USING ".getTableName("products_variations")." pv LEFT JOIN ".getTableName("products_variations_combination")." pvc ON pv.id=pvc.id_variation WHERE pvc.id_variation IS NULL");
|
||||
}*/
|
||||
} else {
|
||||
if (empty($cfg['Sync']['CreateProducts'])) {
|
||||
// logError(__FILE__, __LINE__, "Unknown product: ".$param['header']['code'], true);
|
||||
$values = POHODA_setDataItemValues('productId', 0, 'id', 0);
|
||||
$structItemDetails = POHODA_getDataItemDetails(0, 'error', 400, $values);
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($updated_codes[$param['header']['code']])) {
|
||||
// pokud se preda productId nebo neni nulove provede se update polozky, jinak se vlozi nova
|
||||
// queryHead je nutna pro pripad ze productId predane v params neexistuje v databazi a nedojde k updatu ale provede se dodatecne nove vlozeni
|
||||
if (isset($param['header']['productId']) && (!empty($param['header']['productId']) || $param['header']['productId'] != 0)) {
|
||||
$update = true;
|
||||
$queryHead = 'UPDATE '.getTableName('products').' SET ';
|
||||
} else {
|
||||
$update = false;
|
||||
$queryHead = 'REPLACE INTO '.getTableName('products').' SET ';
|
||||
}
|
||||
|
||||
$query = POHODA_ProductsUpload_getQuery($param, $update);
|
||||
|
||||
if ($update) {
|
||||
$queryEnd = 'WHERE id='.intval($param['header']['productId']);
|
||||
} else {
|
||||
$queryEnd = '';
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, $queryHead.$query.$queryEnd);
|
||||
$SQL = sqlQuery($queryHead.$query.$queryEnd);
|
||||
|
||||
// pokud byl vlozen nebo upraven radek vrati type "ok" a status 200 nebo "warning" a jiny status
|
||||
// pokud nedoslo k upraveni radky ani k vlozeni noveho vrati "error"
|
||||
if (sqlAffectedRows($SQL) != 0) {
|
||||
if ($update) {
|
||||
if (!empty($cfg['Sync']['LogUpdateProduct'])) {
|
||||
static $logger = null;
|
||||
|
||||
$logger = $logger ?? ServiceContainer::getService('logger');
|
||||
$logger->error('PohodaSync', ['query' => $queryHead.$query.$queryEnd, 'params' => $param]);
|
||||
}
|
||||
// logError(__FILE__, __LINE__, "Update", true);
|
||||
$values = POHODA_setDataItemValues('productId', $param['header']['productId'], 'id', $param['header']['productId']);
|
||||
$structItemDetails = POHODA_getDataItemDetails($param['header']['productId'], 'ok', 200, $values);
|
||||
} else {
|
||||
// logError(__FILE__, __LINE__, "New one id:".sqlInsertId(), true);
|
||||
$values = POHODA_setDataItemValues('productId', $param['header']['productId'], 'id', sqlInsertId());
|
||||
$structItemDetails = POHODA_getDataItemDetails(sqlInsertId(), 'ok', 200, $values);
|
||||
$param['header']['productId'] = sqlInsertId();
|
||||
}
|
||||
} elseif ($update) {
|
||||
// byla pozadovana uprava polozky ale productId predane v params neexistuje v databazi
|
||||
// vlozi se jako nova polozka a vrati se id nove polozky
|
||||
if (!empty($cfg['Sync']['CreateProducts'])) {
|
||||
$queryHead = 'INSERT INTO '.getTableName('products').' SET ';
|
||||
|
||||
$query = POHODA_ProductsUpload_getQuery($param, false);
|
||||
|
||||
logError(__FILE__, __LINE__, 'spatne id pokus o vlozeni nove polozky: '.$param['header']['productId'].' inserting: '.$queryHead.$query.print_r($param, true), true);
|
||||
|
||||
$SQL = sqlQuery($queryHead.$query);
|
||||
|
||||
if (sqlAffectedRows($SQL) != 0) {
|
||||
/*$values = POHODA_setDataItemValues("productId", $param['header']['productId'], "id", sqlInsertId());
|
||||
$structItemDetails = POHODA_getDataItemDetails(sqlInsertId(), 'warning', 800, $values);*/
|
||||
$param['header']['productId'] = sqlInsertId();
|
||||
} else {
|
||||
$values = POHODA_setDataItemValues('productId', $param['header']['productId'], 'id', 0);
|
||||
$structItemDetails = POHODA_getDataItemDetails($param['header']['productId'], 'error', 404, $values);
|
||||
}
|
||||
} else {
|
||||
$structItemDetails = POHODA_getDataItemDetails(0, 'error', 500, '');
|
||||
}
|
||||
} else {
|
||||
$structItemDetails = POHODA_getDataItemDetails(0, 'error', 500, '');
|
||||
}
|
||||
|
||||
$updated_codes[$param['header']['code']] = $param['header']['productId'];
|
||||
}
|
||||
|
||||
// Make sure variant exists and update variant stock
|
||||
if (!empty($product['variants'])) {
|
||||
if (!empty($param['header']['variationId'])) {
|
||||
$variation_id = $param['header']['variationId'];
|
||||
} else {
|
||||
$variation_id = Variations::createProductVariation($param['header']['productId'], $product['variants']);
|
||||
}
|
||||
$param['header']['variationId'] = $variation_id;
|
||||
|
||||
// Finally update stock value
|
||||
$values = POHODA_ProductsUpload_getQuery($param, false, true);
|
||||
$query = 'UPDATE '.getTableName('products_variations').' SET '.$values.' WHERE id='.$variation_id;
|
||||
$SQL = sqlQuery($query);
|
||||
}
|
||||
/*else
|
||||
logError(__FILE__, __LINE__, "Nejsou varianty: ".$param['header']['productId'], true);*/
|
||||
|
||||
if (!isDevelopment() && !empty($cfg['Sync']['Photos']['url']) && !empty($param['header']['photos'])) {
|
||||
$photos = explode(';', rtrim($param['header']['photos'], ';'));
|
||||
|
||||
$downloader = new Downloader();
|
||||
$downloader->setMethod('curl');
|
||||
$photosIds = [];
|
||||
foreach ($photos as $photo) {
|
||||
$photosIds[] = $downloader->importProductImage($cfg['Sync']['Photos']['url'].$photo, true);
|
||||
}
|
||||
|
||||
$first = true;
|
||||
sqlStartTransaction();
|
||||
sqlQuery('DELETE FROM photos_products_relation WHERE id_product=:id_product', ['id_product' => $param['header']['productId']]);
|
||||
foreach ($photosIds as $photoId) {
|
||||
sqlQuery('INSERT IGNORE INTO '.getTableName('photos-products').' (id_photo, id_product, show_in_lead, active) VALUES (:id_photo, :id_product, :show_in_lead, :active)',
|
||||
[
|
||||
'id_photo' => $photoId,
|
||||
'id_product' => $param['header']['productId'],
|
||||
'show_in_lead' => $first ? 'Y' : 'N',
|
||||
'active' => 'Y',
|
||||
]);
|
||||
$first = false;
|
||||
}
|
||||
sqlFinishTransaction();
|
||||
}
|
||||
|
||||
if (!empty($param['header']['productId'])) {
|
||||
foreach ($cfg['Sync']['Languages'] ?? [] as $lang) {
|
||||
if (!empty($param['header']["title_{$lang}"] ?? null)) {
|
||||
$productsTranslations = ServiceContainer::getService(\KupShop\I18nBundle\Translations\ProductsTranslation::class);
|
||||
$productsTranslations->saveSingleObject($lang,
|
||||
$param['header']['productId'], [
|
||||
'title' => $param['header']["title_{$lang}"],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cfg['Sync']['Parameters'])) {
|
||||
global $listParameterAll;
|
||||
if (empty($listParameterAll)) {
|
||||
$listParameterAll = Parameter::get();
|
||||
}
|
||||
|
||||
foreach ($cfg['Sync']['Parameters'] ?? [] as $field_name => $id) {
|
||||
$existsValues = sqlFetchAll(sqlQuery('SELECT * FROM parameters_products WHERE id_product=:id_product and id_parameter=:id_parameter', ['id_product' => $param['header']['productId'], 'id_parameter' => $id]));
|
||||
|
||||
if ($existsValues) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sqlQuery('DELETE FROM parameters_products WHERE id_product=:id_product and id_parameter=:id_parameter', ['id_product' => $param['header']['productId'], 'id_parameter' => $id]);
|
||||
|
||||
$parameter = $listParameterAll[$id];
|
||||
|
||||
$values = explode(';', rtrim($param['header'][$field_name], ';'));
|
||||
|
||||
foreach ($values as $value) {
|
||||
if (!empty($param['header'][$field_name])) {
|
||||
$val = getParamValue($parameter, $value);
|
||||
$data = [
|
||||
"value_{$parameter->value_type}" => $val,
|
||||
'id_product' => $param['header']['productId'],
|
||||
'id_parameter' => $parameter->id,
|
||||
'value' => $val,
|
||||
'unit' => getVal(0, $parameter->unit),
|
||||
];
|
||||
$parameter->setValue($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (updatable($param['header'], 'section_ids', !$update)) {
|
||||
$section_ids = array_filter(explode(';', rtrim($param['header']['section_ids'], ';')));
|
||||
|
||||
if (count($section_ids) > 0) {
|
||||
POHODA_ProductsUpdateSections($section_ids, $param['header']['productId']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cfg['Sync']['ProductsOfSuppliers']) && !empty($param['header']['supplier'])) {
|
||||
$search_fields = [
|
||||
'id_supplier' => intval($param['header']['supplier']),
|
||||
'id_product' => $param['header']['productId'],
|
||||
];
|
||||
|
||||
$update_fields = [
|
||||
'in_store' => intval($param['header']['stockQuantity']),
|
||||
'code' => $param['header']['code'],
|
||||
];
|
||||
|
||||
$id = sqlQueryBuilder()
|
||||
->select('id')
|
||||
->from('products_of_suppliers')
|
||||
->where(\Query\Operator::equals($search_fields))
|
||||
->execute()->fetchColumn();
|
||||
|
||||
if ($id) {
|
||||
sqlQueryBuilder()
|
||||
->update('products_of_suppliers')
|
||||
->directValues($update_fields)
|
||||
->set('last_sync', 'NOW()')
|
||||
->where(\Query\Operator::equals(['id' => $id]))
|
||||
->execute();
|
||||
} else {
|
||||
sqlQueryBuilder()
|
||||
->insert('products_of_suppliers')
|
||||
->directValues(array_merge($search_fields, $update_fields))
|
||||
->set('last_sync', 'NOW()')
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cfg['Sync']['SubstractNewOrdersFromStore'])) {
|
||||
if (empty($param['header']['variationId'])) {
|
||||
sqlQuery('UPDATE products p
|
||||
JOIN (
|
||||
SELECT oi.id_product, SUM(pieces) pieces
|
||||
FROM order_items oi
|
||||
JOIN orders o ON o.id = oi.id_order
|
||||
WHERE o.status = 0 AND oi.id_product=:id_product AND oi.id_variation IS NULL
|
||||
GROUP BY oi.id_product
|
||||
) q ON q.id_product = p.id
|
||||
SET p.in_store = p.in_store - q.pieces', ['id_product' => $param['header']['productId']]);
|
||||
} else {
|
||||
sqlQuery('UPDATE products_variations pv
|
||||
JOIN (
|
||||
SELECT oi.id_variation, SUM(pieces) pieces
|
||||
FROM order_items oi
|
||||
JOIN orders o ON o.id = oi.id_order
|
||||
WHERE o.status = 0 AND oi.id_product=:id_product AND oi.id_variation=:id_variation
|
||||
GROUP BY oi.id_variation
|
||||
) q ON q.id_variation=pv.id
|
||||
SET pv.in_store = pv.in_store - q.pieces', [
|
||||
'id_product' => $param['header']['productId'],
|
||||
'id_variation' => $param['header']['variationId'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($cfg['Sync']['Stores'])) {
|
||||
foreach ($cfg['Sync']['Stores'] as $store) {
|
||||
if (isset($param['header']["store{$store}"])) {
|
||||
$storesService = ServiceContainer::getService(\KupShop\StoresBundle\Utils\StoresInStore::class);
|
||||
$storesService->updateStoreItem([
|
||||
'quantity' => $param['header']["store{$store}"],
|
||||
'id_store' => $store,
|
||||
'id_product' => $param['header']['productId'],
|
||||
'id_variation' => $param['header']['variationId'] ?? null,
|
||||
], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($structItemDetails == null) {
|
||||
// logError(__FILE__, __LINE__, "Last empty: ".$param['header']['productId']."-".$param['header']['productIdOld'] . ", code: '".$param['header']['code']."'", true);
|
||||
$values = '';
|
||||
if ($param['header']['productIdOld'] != $param['header']['productId']) {
|
||||
$values = POHODA_setDataItemValues('productId', $param['header']['productIdOld'], 'id', $param['header']['productId']);
|
||||
}
|
||||
$structItemDetails = POHODA_getDataItemDetails($param['header']['productId'], 'ok', 200, $values);
|
||||
}
|
||||
|
||||
if (!empty($product['variants'])) {
|
||||
$structItemDetails['dataItemId'] = -$variation_id;
|
||||
}
|
||||
|
||||
$response['responseData'][] = $structItemDetails;
|
||||
}
|
||||
|
||||
POHODA_UpdateProductsSupplier();
|
||||
|
||||
// Set product price from variations
|
||||
if (!empty($cfg['Sync']['SetProductPrice'])) {
|
||||
sqlQuery('UPDATE products p
|
||||
SET p.price=(
|
||||
SELECT COALESCE(MIN(pv.price), p.price)
|
||||
FROM products_variations pv
|
||||
WHERE pv.id_product=p.id AND pv.in_store > 0
|
||||
)');
|
||||
}
|
||||
|
||||
// Set product price from variations
|
||||
if (!empty($cfg['Sync']['Collections'])) {
|
||||
POHODA_SyncCollections();
|
||||
}
|
||||
|
||||
return new xmlrpcresp(php_xmlrpc_encode($response));
|
||||
}
|
||||
|
||||
function POHODA_ProductsUpload_section($item)
|
||||
{
|
||||
$cfg = \KupShop\KupShopBundle\Config::get();
|
||||
|
||||
$data = $item['header'];
|
||||
$id = $data['code'];
|
||||
|
||||
if (empty($cfg['Sync']['Sections'])) {
|
||||
return POHODA_getDataItemDetails($id, 'ok', 200, '');
|
||||
}
|
||||
|
||||
if ($param['dataItemStatus'] ?? null == 'deleted') {
|
||||
sqlQuery('UPDATE sections SET figure=\'N\' WHERE id=:code', $data);
|
||||
|
||||
return POHODA_getDataItemDetails($id, 'ok', 200, '');
|
||||
}
|
||||
|
||||
$exists = sqlQuery('SELECT * FROM sections WHERE id=:code', $data)->fetch();
|
||||
|
||||
$qb = sqlQueryBuilder()
|
||||
->{$exists ? 'update' : 'insert'}('sections')
|
||||
->andWhere(\Query\Operator::equals(['id' => $id]));
|
||||
|
||||
$values = [];
|
||||
if (isset($id)) {
|
||||
$values['id'] = $id;
|
||||
}
|
||||
|
||||
if (isset($data['title'])) {
|
||||
$values['name'] = $data['title'];
|
||||
}
|
||||
|
||||
if (isset($data['visible'])) {
|
||||
$values['figure'] = $data['visible'] == 'true' ? 'Y' : 'N';
|
||||
}
|
||||
|
||||
$qb->directValues($values)
|
||||
->execute();
|
||||
|
||||
if (!isDevelopment() && !empty($data['photo'])) {
|
||||
$downloader = new Downloader();
|
||||
$downloader->setMethod('curl');
|
||||
$picture = $downloader->downloadImage($cfg['Sync']['Photos']['url'].trim($data['photo']));
|
||||
|
||||
if ($picture) {
|
||||
$img = new Photos('section', $cfg['Path']['admin_to_root']);
|
||||
$img->newImage($id);
|
||||
$img->uploadImage($picture, false);
|
||||
|
||||
if ($img->checkFileType()) {
|
||||
$img->insertImageIntoDB();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['id_parent'])) {
|
||||
sqlQuery('DELETE FROM sections_relation WHERE id_section = :code', $data);
|
||||
|
||||
sqlQueryBuilder()->insert('sections_relation')
|
||||
->directValues(['id_section' => $id, 'id_topsection' => $data['id_parent'], 'position' => $data['position']])
|
||||
->execute();
|
||||
}
|
||||
|
||||
MenuSectionTree::invalidateCache();
|
||||
|
||||
return POHODA_getDataItemDetails($id, 'ok', 200, '');
|
||||
}
|
||||
|
||||
function POHODA_ProductsUpdateSections($section_ids, $product_id)
|
||||
{
|
||||
sqlStartTransaction();
|
||||
|
||||
sqlQuery('DELETE FROM products_in_sections WHERE id_product=:id_product', ['id_product' => $product_id]);
|
||||
|
||||
$sectionTree = ServiceContainer::getService(SectionTree::class);
|
||||
|
||||
foreach ($section_ids as $id) {
|
||||
$section = $sectionTree->getSectionById($id);
|
||||
|
||||
if ($section && count($section->getChildren()) == 0) {
|
||||
sqlQuery('INSERT INTO products_in_sections (id_product, id_section) VALUES (:id_product, :id_section)',
|
||||
['id_product' => $product_id, 'id_section' => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
sqlFinishTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
function POHODA_ProductsUpload_getQuery($param, $update, $variation = false)
|
||||
{
|
||||
global $cfg;
|
||||
$query = '';
|
||||
|
||||
$vat_id = getVatID($param['header']['rateVAT']);
|
||||
$producer_id = getProducer($param['header']['producer']);
|
||||
|
||||
if (updatable($param['header'], 'EAN', !$update)) {
|
||||
$query .= 'ean='.intval($param['header']['EAN']).', ';
|
||||
}
|
||||
if (updatable($param['header'], 'price', !$update)) {
|
||||
$query .= "price='".doubleval($param['header']['price'])."', ";
|
||||
}
|
||||
if (updatable($param['header'], 'stockQuantity', !$update)) {
|
||||
$query .= 'in_store='.intval($param['header']['stockQuantity']).', ';
|
||||
}
|
||||
|
||||
if (!$variation) {
|
||||
if (updatable($param['header'], 'code', !$update)) {
|
||||
$query .= "code='".sqlFormatInput($param['header']['code'])."', ";
|
||||
}
|
||||
if (updatable($param['header'], 'title', !$update)) {
|
||||
$query .= "title='".sqlFormatInput($param['header']['title'])."', ";
|
||||
}
|
||||
if (updatable($param['header'], 'rateVAT', !$update)) {
|
||||
$query .= 'vat='.intval($vat_id).', ';
|
||||
}
|
||||
if (updatable($param['header'], 'discount', !$update)) {
|
||||
$query .= 'discount='.doubleval($param['header']['discount']).', ';
|
||||
}
|
||||
if (updatable($param['header'], 'guaranteeQuantity', !$update)) {
|
||||
$query .= 'guarantee='.intval($param['header']['guaranteeQuantity']).', ';
|
||||
}
|
||||
if (updatable($param['header'], 'piecesSold', !$update)) {
|
||||
$query .= 'pieces_sold='.intval($param['header']['piecesSold']).', ';
|
||||
}
|
||||
if (updatable($param['header'], 'description', !$update)) {
|
||||
$query .= "long_descr='".sqlFormatInput($param['header']['description'])."', ";
|
||||
}
|
||||
if (updatable($param['header'], 'specification', !$update)) {
|
||||
$query .= "parameters='".sqlFormatInput($param['header']['specification'])."', ";
|
||||
}
|
||||
if (updatable($param['header'], 'producer', !$update) && $param['header']['producer'] != '') {
|
||||
$query .= 'producer='.intval($producer_id).', ';
|
||||
}
|
||||
if (updatable($param['header'], 'flags', !$update)) {
|
||||
$flags = trim($param['header']['flags'], ',');
|
||||
|
||||
$sync_flags = $cfg['Sync']['FlagsToSync'];
|
||||
|
||||
$query .= "campaign=ADD_TO_SET('".$flags."', ".recurseRemoveFlag($sync_flags).'), ';
|
||||
}
|
||||
if (!$update) {
|
||||
$query .= 'date_added=NOW(), ';
|
||||
}
|
||||
$query .= "updated='".date('Y-m-d H:i:s')."' ";
|
||||
} else {
|
||||
if (updatable($param['header'], 'variation_EAN', !$update)) {
|
||||
$query .= 'ean='.intval($param['header']['variation_EAN']).', ';
|
||||
}
|
||||
if (updatable($param['header'], 'variation_price', !$update)) {
|
||||
$query .= "price='".processVat(doubleval($param['header']['variation_price']), $vat_id)."', ";
|
||||
}
|
||||
if (updatable($param['header'], 'variation_code', !$update)) {
|
||||
$query .= "code='".sqlFormatInput($param['header']['variation_code'])."', ";
|
||||
}
|
||||
|
||||
if (updatable($param['header'], 'weight', !$update)) {
|
||||
$query .= "weight='".sqlFormatInput($param['header']['weight'])."', ";
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($cfg['Sync']['PriceLists'] ?? [] as $priceListFieldName => $idPriceList) {
|
||||
if (!empty($param['header']["{$priceListFieldName}Price"])) {
|
||||
$priceListWorker = \KupShop\KupShopBundle\Util\Compat\ServiceContainer::getService(\KupShop\PricelistBundle\Util\PriceListWorker::class);
|
||||
$priceListWorker->updatePricelists($idPriceList, [
|
||||
'price' => processVat($param['header']["{$priceListFieldName}Price"], $vat_id),
|
||||
'discount' => $param['header']["{$priceListFieldName}Discount"] ?? null,
|
||||
'showVat' => 'N',
|
||||
], $param['header']['productId'], getVat($vat_id), $param['header']['variationId'] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
return rtrim($query, ', ');
|
||||
}
|
||||
|
||||
function processVat($price, $vat_id)
|
||||
{
|
||||
global $cfg;
|
||||
|
||||
if (!empty($cfg['Sync']['PriceWithVat'])) {
|
||||
$price = calcPrice($price, -getVat($vat_id));
|
||||
}
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
function recurseRemoveFlag($flags)
|
||||
{
|
||||
if (empty($flags[0])) {
|
||||
return 'campaign';
|
||||
}
|
||||
|
||||
$flag = array_shift($flags);
|
||||
|
||||
return "REMOVE_FROM_SET('".$flag."', ".recurseRemoveFlag($flags).')';
|
||||
}
|
||||
|
||||
function getParamValue($parameter, $value)
|
||||
{
|
||||
foreach ($parameter->fetchListValues() as $listValue) {
|
||||
if (mb_strtolower($listValue['value'], 'utf-8') == mb_strtolower($value, 'utf-8')) {
|
||||
return $listValue['id'];
|
||||
}
|
||||
}
|
||||
|
||||
sqlQuery('INSERT INTO parameters_list (id_parameter, value) VALUES (:id_parameter, :value)', ['id_parameter' => $parameter->id, 'value' => $value]);
|
||||
$value = sqlInsertId();
|
||||
$parameter->fetchListValues(true);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/*
|
||||
* SELECT p.id, p.code, p.title, pv.title as variant FROM products_variations pv left join products p on p.id=pv.id_product where sync_count<5
|
||||
*/
|
||||
154
socket/Pohoda.php
Normal file
154
socket/Pohoda.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
// ##############################################################
|
||||
require_once '../include/config.php';
|
||||
require_once './functions.php';
|
||||
require_once 'Pohoda.Functions.php';
|
||||
require_once './common.php';
|
||||
// ##############################################################
|
||||
|
||||
// Allow NIL Extension
|
||||
// $GLOBALS['xmlrpc_null_extension']=true;
|
||||
|
||||
$POHODA_Request_sig = [['struct', 'struct']];
|
||||
$POHODA_Request_doc = '';
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function POHODA_InvoicesCall($params)
|
||||
{
|
||||
$val = $params->getparam(0);
|
||||
$param = php_xmlrpc_decode($val);
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($param, true), true);
|
||||
|
||||
if (!POHODA_checkSession($param['requestParams']['sessionId'])) {
|
||||
return POHODA_unauthorized();
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, "orders2", true);
|
||||
|
||||
include 'Pohoda.Invoices.php';
|
||||
|
||||
return POHODA_Invoices($param);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function POHODA_OrdersCall($params)
|
||||
{
|
||||
$val = $params->getparam(0);
|
||||
$param = php_xmlrpc_decode($val);
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($param, true), true);
|
||||
// logError(__FILE__, __LINE__, "orders", true);
|
||||
|
||||
if (!POHODA_checkSession($param['requestParams']['sessionId'])) {
|
||||
return POHODA_unauthorized();
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, "orders2", true);
|
||||
|
||||
include 'Pohoda.Orders.php';
|
||||
|
||||
return POHODA_Orders($param);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function POHODA_ContactsCall($params)
|
||||
{
|
||||
$val = $params->getparam(0);
|
||||
$param = php_xmlrpc_decode($val);
|
||||
|
||||
if (!POHODA_checkSession($param['requestParams']['sessionId'])) {
|
||||
return POHODA_unauthorized();
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($param, true), true);
|
||||
|
||||
include 'Pohoda.Contacts.php';
|
||||
|
||||
return POHODA_Contacts($param);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function POHODA_ProductsCall($params)
|
||||
{
|
||||
$val = $params->getparam(0);
|
||||
$param = php_xmlrpc_decode($val);
|
||||
|
||||
if (!POHODA_checkSession($param['requestParams']['sessionId'])) {
|
||||
return POHODA_unauthorized();
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($param, true), true);
|
||||
|
||||
include 'Pohoda.Products.php';
|
||||
|
||||
return POHODA_Products($param);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function POHODA_ClientLogin($params)
|
||||
{
|
||||
$val = $params->getparam(0);
|
||||
$param = php_xmlrpc_decode($val);
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($param, true), true);
|
||||
|
||||
return POHODA_login($param);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
function POHODA_ClientLogout($params)
|
||||
{
|
||||
$val = $params->getparam(0);
|
||||
$param = php_xmlrpc_decode($val);
|
||||
|
||||
if (!POHODA_checkSession($param['requestParams']['sessionId'])) {
|
||||
return POHODA_unauthorized();
|
||||
}
|
||||
|
||||
// logError(__FILE__, __LINE__, print_r($param, true), true);
|
||||
|
||||
return POHODA_logout($param);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
$server = new xmlrpc_server([
|
||||
'INVOICES' => [
|
||||
'function' => 'POHODA_InvoicesCall',
|
||||
'signature' => $POHODA_Request_sig,
|
||||
'docstring' => $POHODA_Request_doc,
|
||||
],
|
||||
'CONTACTS' => [
|
||||
'function' => 'POHODA_ContactsCall',
|
||||
'signature' => $POHODA_Request_sig,
|
||||
'docstring' => $POHODA_Request_doc,
|
||||
],
|
||||
'LOGIN' => [
|
||||
'function' => 'POHODA_ClientLogin',
|
||||
'signature' => $POHODA_Request_sig,
|
||||
'docstring' => $POHODA_Request_doc,
|
||||
],
|
||||
'LOGOUT' => [
|
||||
'function' => 'POHODA_ClientLogout',
|
||||
'signature' => $POHODA_Request_sig,
|
||||
'docstring' => $POHODA_Request_doc,
|
||||
],
|
||||
'ORDERS' => [
|
||||
'function' => 'POHODA_OrdersCall',
|
||||
'signature' => $POHODA_Request_sig,
|
||||
'docstring' => $POHODA_Request_doc,
|
||||
],
|
||||
'PRODUCTS' => [
|
||||
'function' => 'POHODA_ProductsCall',
|
||||
'signature' => $POHODA_Request_sig,
|
||||
'docstring' => $POHODA_Request_doc,
|
||||
],
|
||||
]);
|
||||
59
socket/common.php
Normal file
59
socket/common.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
defined('VALID_INCLUDE') or exit('Restricted area');
|
||||
|
||||
header('Cache-Control: no-cache');
|
||||
header('Pragma: no-cache');
|
||||
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
ini_set('memory_limit', '2G');
|
||||
ini_set('max_execution_time', '600');
|
||||
|
||||
// //////////////////// SOUBOR COMMON.PHP
|
||||
|
||||
// zacit pocitat cas provadeni skriptu
|
||||
setStartTime();
|
||||
|
||||
// ################################################################
|
||||
// SESSION
|
||||
// ################################################################
|
||||
|
||||
// session_start();
|
||||
|
||||
// ################################################################
|
||||
// ERROR REPORTING
|
||||
// ################################################################
|
||||
|
||||
set_error_handler('error_handler');
|
||||
|
||||
getRaven();
|
||||
|
||||
// ################################################################
|
||||
// VOLBA JAZYKA
|
||||
// ################################################################
|
||||
|
||||
$lng = (isset($cfg['Lang']['language'])) ? $cfg['Lang']['language'] : 'czech';
|
||||
// sestaveni jmena souboru
|
||||
$script = 'lang/lang.'.$lng.'.php';
|
||||
|
||||
if (file_exists($script)) {
|
||||
require_once $script;
|
||||
} else {
|
||||
$script = $cfg['Path']['admin_to_root'].$cfg['Path']['shared_version'].'socket/lang/lang.'.$lng.'.php';
|
||||
if (file_exists($script)) {
|
||||
require_once $script;
|
||||
} else {
|
||||
$script = $cfg['Path']['admin_to_root'].$cfg['Path']['shared_version'].'socket/lang/lang.czech.php';
|
||||
require_once $script;
|
||||
}
|
||||
}
|
||||
|
||||
// ################################################################
|
||||
// ZISKANI NASTAVENI Z DATABAZE
|
||||
// ################################################################
|
||||
|
||||
$dbcfg = Settings::getDefault();
|
||||
|
||||
// ################################################################
|
||||
//
|
||||
// ################################################################
|
||||
9
socket/connection.php
Normal file
9
socket/connection.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
defined('VALID_INCLUDE') or exit('Restricted area');
|
||||
|
||||
// pripojeni k databazi
|
||||
$cfg['Connection']['link'] = sqlConnect($cfg['Connection']['host'],
|
||||
$cfg['Connection']['user'],
|
||||
$cfg['Connection']['password'],
|
||||
$cfg['Connection']['database']);
|
||||
148
socket/functions.php
Normal file
148
socket/functions.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
defined('VALID_INCLUDE') or exit('Restricted area');
|
||||
|
||||
$cfg['Path']['admin_to_root'] = '../';
|
||||
|
||||
// Modify directories path
|
||||
$cfg['Path']['data'] = $cfg['Path']['admin_to_root'].$cfg['Path']['data'];
|
||||
$cfg['Path']['photos'] = $cfg['Path']['admin_to_root'].$cfg['Path']['photos'];
|
||||
$cfg['Path']['producers'] = $cfg['Path']['admin_to_root'].$cfg['Path']['producers'];
|
||||
$cfg['Path']['db_backup'] = $cfg['Path']['admin_to_root'].$cfg['Path']['db_backup'];
|
||||
$cfg['Path']['shared_dirs'] = $cfg['Path']['admin_to_root'].$cfg['Path']['shared_dirs'];
|
||||
$cfg['Path']['shared_version'] = $cfg['Path']['admin_to_root'].$cfg['Path']['shared_version'];
|
||||
$cfg['Path']['shared_class'] = $cfg['Path']['admin_to_root'].$cfg['Path']['shared_class'];
|
||||
$cfg['Path']['smarty'] = $cfg['Path']['admin_to_root'].$cfg['Path']['smarty'];
|
||||
$cfg['Path']['smarty_tpl']['templates'] = $cfg['Path']['admin_to_root'].$cfg['Path']['smarty_tpl']['templates'];
|
||||
$cfg['Path']['admin_to_root'] = '';
|
||||
|
||||
$cfg['Path']['web_root'] = '../';
|
||||
|
||||
require_once $cfg['Path']['shared_version'].'web/functions.common.php';
|
||||
|
||||
if (!defined('POHODA_SYMFONY')) {
|
||||
function translate_shop($key, $section = null, $silent = false)
|
||||
{
|
||||
return translate($key, $section, $silent);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('getTextString')) {
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
|
||||
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
|
||||
function getTextString($section, $key)
|
||||
{
|
||||
global $cfg, $txt_str;
|
||||
// kdyz neexistuje text, poslat to do chyboveho hlaseni
|
||||
if (!array_key_exists($key, $txt_str[$section] ?? [])) {
|
||||
// zalogovat chybu
|
||||
// $error = 'MISSING LANGUAGE STRING: Lang='.$cfg['Lang']['language']." String=\$txt_str['".$section."']['".$key."']";
|
||||
// logError(__FILE__, __LINE__, $error, false);
|
||||
}
|
||||
$str = $txt_str[$section][$key] ?? $key;
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
function cs_win2ascii($s)
|
||||
{
|
||||
if (!$s) {
|
||||
return $s;
|
||||
}
|
||||
|
||||
if (preg_match('#[\x80-\x{1FF}\x{2000}-\x{3FFF}]#u', $s)) {
|
||||
return $s;
|
||||
}
|
||||
|
||||
// detect WINDOWS-1250
|
||||
if (preg_match('#[\x7F-\x9F]#', $s)) {
|
||||
return strtr($s, ["\x80" => "\xe2\x82\xac", "\x81" => '', "\x82" => "\xe2\x80\x9a", "\x83" => '', "\x84" => "\xe2\x80\x9e", "\x85" => "\xe2\x80\xa6", "\x86" => "\xe2\x80\xa0", "\x87" => "\xe2\x80\xa1", "\x88" => '', "\x89" => "\xe2\x80\xb0", "\x8a" => "\xc5\xa0", "\x8b" => "\xe2\x80\xb9", "\x8c" => "\xc5\x9a", "\x8d" => "\xc5\xa4", "\x8e" => "\xc5\xbd", "\x8f" => "\xc5\xb9", "\x90" => '', "\x91" => "\xe2\x80\x98", "\x92" => "\xe2\x80\x99", "\x93" => "\xe2\x80\x9c", "\x94" => "\xe2\x80\x9d", "\x95" => "\xe2\x80\xa2", "\x96" => "\xe2\x80\x93", "\x97" => "\xe2\x80\x94", "\x98" => '', "\x99" => "\xe2\x84\xa2", "\x9a" => "\xc5\xa1", "\x9b" => "\xe2\x80\xba", "\x9c" => "\xc5\x9b", "\x9d" => "\xc5\xa5", "\x9e" => "\xc5\xbe", "\x9f" => "\xc5\xba", "\xa0" => "\xc2\xa0", "\xa1" => "\xcb\x87", "\xa2" => "\xcb\x98", "\xa3" => "\xc5\x81", "\xa4" => "\xc2\xa4", "\xa5" => "\xc4\x84", "\xa6" => "\xc2\xa6", "\xa7" => "\xc2\xa7", "\xa8" => "\xc2\xa8", "\xa9" => "\xc2\xa9", "\xaa" => "\xc5\x9e", "\xab" => "\xc2\xab", "\xac" => "\xc2\xac", "\xad" => "\xc2\xad", "\xae" => "\xc2\xae", "\xaf" => "\xc5\xbb", "\xb0" => "\xc2\xb0", "\xb1" => "\xc2\xb1", "\xb2" => "\xcb\x9b", "\xb3" => "\xc5\x82", "\xb4" => "\xc2\xb4", "\xb5" => "\xc2\xb5", "\xb6" => "\xc2\xb6", "\xb7" => "\xc2\xb7", "\xb8" => "\xc2\xb8", "\xb9" => "\xc4\x85", "\xba" => "\xc5\x9f", "\xbb" => "\xc2\xbb", "\xbc" => "\xc4\xbd", "\xbd" => "\xcb\x9d", "\xbe" => "\xc4\xbe", "\xbf" => "\xc5\xbc", "\xc0" => "\xc5\x94", "\xc1" => "\xc3\x81", "\xc2" => "\xc3\x82", "\xc3" => "\xc4\x82", "\xc4" => "\xc3\x84", "\xc5" => "\xc4\xb9", "\xc6" => "\xc4\x86", "\xc7" => "\xc3\x87", "\xc8" => "\xc4\x8c", "\xc9" => "\xc3\x89", "\xca" => "\xc4\x98", "\xcb" => "\xc3\x8b", "\xcc" => "\xc4\x9a", "\xcd" => "\xc3\x8d", "\xce" => "\xc3\x8e", "\xcf" => "\xc4\x8e", "\xd0" => "\xc4\x90", "\xd1" => "\xc5\x83", "\xd2" => "\xc5\x87", "\xd3" => "\xc3\x93", "\xd4" => "\xc3\x94", "\xd5" => "\xc5\x90", "\xd6" => "\xc3\x96", "\xd7" => "\xc3\x97", "\xd8" => "\xc5\x98", "\xd9" => "\xc5\xae", "\xda" => "\xc3\x9a", "\xdb" => "\xc5\xb0", "\xdc" => "\xc3\x9c", "\xdd" => "\xc3\x9d", "\xde" => "\xc5\xa2", "\xdf" => "\xc3\x9f", "\xe0" => "\xc5\x95", "\xe1" => "\xc3\xa1", "\xe2" => "\xc3\xa2", "\xe3" => "\xc4\x83", "\xe4" => "\xc3\xa4", "\xe5" => "\xc4\xba", "\xe6" => "\xc4\x87", "\xe7" => "\xc3\xa7", "\xe8" => "\xc4\x8d", "\xe9" => "\xc3\xa9", "\xea" => "\xc4\x99", "\xeb" => "\xc3\xab", "\xec" => "\xc4\x9b", "\xed" => "\xc3\xad", "\xee" => "\xc3\xae", "\xef" => "\xc4\x8f", "\xf0" => "\xc4\x91", "\xf1" => "\xc5\x84", "\xf2" => "\xc5\x88", "\xf3" => "\xc3\xb3", "\xf4" => "\xc3\xb4", "\xf5" => "\xc5\x91", "\xf6" => "\xc3\xb6", "\xf7" => "\xc3\xb7", "\xf8" => "\xc5\x99", "\xf9" => "\xc5\xaf", "\xfa" => "\xc3\xba", "\xfb" => "\xc5\xb1", "\xfc" => "\xc3\xbc", "\xfd" => "\xc3\xbd", "\xfe" => "\xc5\xa3", "\xff" => "\xcb\x99"]);
|
||||
}
|
||||
|
||||
// assume ISO-8859-2
|
||||
return strtr($s, ["\x80" => "\xc2\x80", "\x81" => "\xc2\x81", "\x82" => "\xc2\x82", "\x83" => "\xc2\x83", "\x84" => "\xc2\x84", "\x85" => "\xc2\x85", "\x86" => "\xc2\x86", "\x87" => "\xc2\x87", "\x88" => "\xc2\x88", "\x89" => "\xc2\x89", "\x8a" => "\xc2\x8a", "\x8b" => "\xc2\x8b", "\x8c" => "\xc2\x8c", "\x8d" => "\xc2\x8d", "\x8e" => "\xc2\x8e", "\x8f" => "\xc2\x8f", "\x90" => "\xc2\x90", "\x91" => "\xc2\x91", "\x92" => "\xc2\x92", "\x93" => "\xc2\x93", "\x94" => "\xc2\x94", "\x95" => "\xc2\x95", "\x96" => "\xc2\x96", "\x97" => "\xc2\x97", "\x98" => "\xc2\x98", "\x99" => "\xc2\x99", "\x9a" => "\xc2\x9a", "\x9b" => "\xc2\x9b", "\x9c" => "\xc2\x9c", "\x9d" => "\xc2\x9d", "\x9e" => "\xc2\x9e", "\x9f" => "\xc2\x9f", "\xa0" => "\xc2\xa0", "\xa1" => "\xc4\x84", "\xa2" => "\xcb\x98", "\xa3" => "\xc5\x81", "\xa4" => "\xc2\xa4", "\xa5" => "\xc4\xbd", "\xa6" => "\xc5\x9a", "\xa7" => "\xc2\xa7", "\xa8" => "\xc2\xa8", "\xa9" => "\xc5\xa0", "\xaa" => "\xc5\x9e", "\xab" => "\xc5\xa4", "\xac" => "\xc5\xb9", "\xad" => "\xc2\xad", "\xae" => "\xc5\xbd", "\xaf" => "\xc5\xbb", "\xb0" => "\xc2\xb0", "\xb1" => "\xc4\x85", "\xb2" => "\xcb\x9b", "\xb3" => "\xc5\x82", "\xb4" => "\xc2\xb4", "\xb5" => "\xc4\xbe", "\xb6" => "\xc5\x9b", "\xb7" => "\xcb\x87", "\xb8" => "\xc2\xb8", "\xb9" => "\xc5\xa1", "\xba" => "\xc5\x9f", "\xbb" => "\xc5\xa5", "\xbc" => "\xc5\xba", "\xbd" => "\xcb\x9d", "\xbe" => "\xc5\xbe", "\xbf" => "\xc5\xbc", "\xc0" => "\xc5\x94", "\xc1" => "\xc3\x81", "\xc2" => "\xc3\x82", "\xc3" => "\xc4\x82", "\xc4" => "\xc3\x84", "\xc5" => "\xc4\xb9", "\xc6" => "\xc4\x86", "\xc7" => "\xc3\x87", "\xc8" => "\xc4\x8c", "\xc9" => "\xc3\x89", "\xca" => "\xc4\x98", "\xcb" => "\xc3\x8b", "\xcc" => "\xc4\x9a", "\xcd" => "\xc3\x8d", "\xce" => "\xc3\x8e", "\xcf" => "\xc4\x8e", "\xd0" => "\xc4\x90", "\xd1" => "\xc5\x83", "\xd2" => "\xc5\x87", "\xd3" => "\xc3\x93", "\xd4" => "\xc3\x94", "\xd5" => "\xc5\x90", "\xd6" => "\xc3\x96", "\xd7" => "\xc3\x97", "\xd8" => "\xc5\x98", "\xd9" => "\xc5\xae", "\xda" => "\xc3\x9a", "\xdb" => "\xc5\xb0", "\xdc" => "\xc3\x9c", "\xdd" => "\xc3\x9d", "\xde" => "\xc5\xa2", "\xdf" => "\xc3\x9f", "\xe0" => "\xc5\x95", "\xe1" => "\xc3\xa1", "\xe2" => "\xc3\xa2", "\xe3" => "\xc4\x83", "\xe4" => "\xc3\xa4", "\xe5" => "\xc4\xba", "\xe6" => "\xc4\x87", "\xe7" => "\xc3\xa7", "\xe8" => "\xc4\x8d", "\xe9" => "\xc3\xa9", "\xea" => "\xc4\x99", "\xeb" => "\xc3\xab", "\xec" => "\xc4\x9b", "\xed" => "\xc3\xad", "\xee" => "\xc3\xae", "\xef" => "\xc4\x8f", "\xf0" => "\xc4\x91", "\xf1" => "\xc5\x84", "\xf2" => "\xc5\x88", "\xf3" => "\xc3\xb3", "\xf4" => "\xc3\xb4", "\xf5" => "\xc5\x91", "\xf6" => "\xc3\xb6", "\xf7" => "\xc3\xb7", "\xf8" => "\xc5\x99", "\xf9" => "\xc5\xaf", "\xfa" => "\xc3\xba", "\xfb" => "\xc5\xb1", "\xfc" => "\xc3\xbc", "\xfd" => "\xc3\xbd", "\xfe" => "\xc5\xa3", "\xff" => "\xcb\x99"]);
|
||||
|
||||
/*return strtr($s,
|
||||
"\xe1\xe4\xe8\xef\xe9\xec\xed\xbe\xe5\xf2\xf3\xf6\xf5\xf4\xf8\xe0\x9a\x9d\xfa\xf9\xfc\xfb\xfd\x9e\xc1\xc4\xc8\xcf\xc9\xcc\xcd\xbc\xc5\xd2\xd3\xd6\xd5\xd4\xd8\xc0\x8a\x8d\xda\xd9\xdc\xdb\xdd\x8e",
|
||||
"aacdeeillnoooorrstuuuuyzAACDEEILLNOOOORRSTUUUUYZ"
|
||||
);*/
|
||||
}
|
||||
|
||||
function utf8ToWin1250($s)
|
||||
{
|
||||
return sqlFormatInput(iconv('UTF-8', 'WINDOWS-1250', $s));
|
||||
}
|
||||
|
||||
// ======================================================================================================
|
||||
|
||||
function GetVariantCode($code, $label_id, $variant)
|
||||
{
|
||||
$query = 'SELECT pv.code
|
||||
FROM products_variations_choices_values AS pv
|
||||
WHERE id_label=:label_id AND value LIKE :variation';
|
||||
|
||||
$SQL = sqlQuery($query, ['variation' => $variant, 'label_id' => $label_id]);
|
||||
if (sqlNumRows($SQL) > 0) {
|
||||
$variant = sqlFetchAssoc($SQL);
|
||||
$variant = $variant['code'];
|
||||
} else {
|
||||
logError(__FILE__, __LINE__, "Cannot get variant code: product: {$code}, label {$label_id}: {$variant}", true);
|
||||
}
|
||||
|
||||
return $variant;
|
||||
}
|
||||
|
||||
function GetVariationValueCode($id_variation, $id_label)
|
||||
{
|
||||
$query = 'SELECT pvcv.code
|
||||
FROM products_variations_choices_values AS pvcv
|
||||
JOIN products_variations_combination pvc ON pvc.id_label = pvcv.id_label AND pvc.id_value = pvcv.id
|
||||
WHERE pvcv.id_label=:label_id AND pvc.id_variation = :id_variation';
|
||||
|
||||
return returnSQLResult($query, ['id_variation' => $id_variation, 'label_id' => $id_label]);
|
||||
}
|
||||
|
||||
if (!function_exists('getNoteAdmin')) {
|
||||
function getNoteAdmin($order)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('POHODA_OrdersQuery')) {
|
||||
function POHODA_OrdersQuery($params)
|
||||
{
|
||||
return 'SELECT * FROM '.getTableName('orders')." WHERE date_created >= '".date('Y-m-d H:i:s', iso8601_decode($params['dateFrom']))."'";
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('POHODA_OrdersNote')) {
|
||||
function POHODA_OrdersNote($row2)
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('POHODA_UpdateProductsSupplier')) {
|
||||
function POHODA_UpdateProductsSupplier()
|
||||
{
|
||||
if (empty($cfg['Sync']['ProductsOfSuppliers'])) {
|
||||
// Recalculate products in store
|
||||
sqlQuery('UPDATE '.getTableName('products').' p
|
||||
SET p.in_store=(
|
||||
SELECT COALESCE(SUM(GREATEST(pv.in_store, 0)), p.in_store)
|
||||
FROM '.getTableName('products_variations').' pv
|
||||
WHERE pv.id_product=p.id
|
||||
)');
|
||||
} else {
|
||||
// Move in_store from suppliers to products/variations
|
||||
sqlQuery('UPDATE '.getTableName('products').' p
|
||||
SET p.in_store=(
|
||||
SELECT SUM(pos.in_store)
|
||||
FROM '.getTableName('products_of_suppliers').' pos
|
||||
WHERE pos.id_product = p.id
|
||||
)');
|
||||
}
|
||||
}
|
||||
}
|
||||
26
socket/lang/lang.czech.php
Normal file
26
socket/lang/lang.czech.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
// ////////////////////// SOUBOR S TEXTY V ESHOPU ///////////////////////////
|
||||
// ********************************************************************** //
|
||||
// CONFIG SOUBOR JAZYKOVYCH TEXTU JE SOUBOREM PHP //
|
||||
// RADKY ZAKOMENTUJETE ZNACKAMI // NEBO # //
|
||||
// NEPOUZIVEJTE JEDNODUCHE UVOZOVKY, POUZE DVOJITE //
|
||||
// ********************************************************************** //
|
||||
// //////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* ======================================================================
|
||||
* obecne chybove hlasky
|
||||
* ======================================================================.
|
||||
*/
|
||||
$txt_str['errors'][200] = 'OK';
|
||||
$txt_str['errors'][204] = 'No data to respond';
|
||||
$txt_str['errors'][206] = 'Requested update but could not update item becasuse requested id does not exist. Item was inserted as new one.';
|
||||
$txt_str['errors'][400] = 'Bad request parameter';
|
||||
$txt_str['errors'][401] = 'Unauthorized';
|
||||
$txt_str['errors'][403] = 'Unauthorized user';
|
||||
$txt_str['errors'][404] = 'Not found';
|
||||
$txt_str['errors'][406] = 'Date from not specified';
|
||||
$txt_str['errors'][500] = 'Internal error';
|
||||
|
||||
require $cfg['Path']['shared_version'].'web/lang/lang.cs.php';
|
||||
43
socket/launch.php
Normal file
43
socket/launch.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
// ----------------------------------------------
|
||||
// vlozit XML-RPC tridy
|
||||
require_once $cfg['Path']['admin_to_root'].$cfg['Path']['shared_class'].'xmlrpc/xmlrpc.inc.php';
|
||||
require_once $cfg['Path']['admin_to_root'].$cfg['Path']['shared_class'].'xmlrpc/xmlrpcs.inc.php';
|
||||
// ----------------------------------------------
|
||||
|
||||
$script = '';
|
||||
if (isset($_GET['s'])) {
|
||||
$script = $_GET['s'];
|
||||
|
||||
// odstraneni relativnich adres
|
||||
$script = preg_replace('@^(\\.{0,2}/)+@', '', $script);
|
||||
$script = preg_replace('@\\.{1,2}/@', '', $script);
|
||||
|
||||
// odstraneni HTTP ze zacatku
|
||||
$script = preg_replace('@^(http|ftp|https|mms)\\://@', '', $script);
|
||||
|
||||
// pridani koncovky .php
|
||||
$script .= '.php';
|
||||
}
|
||||
|
||||
if ($script == '') {
|
||||
$script = 'Pohoda.php';
|
||||
}
|
||||
|
||||
if (file_exists($script)) {
|
||||
require_once $script;
|
||||
} else {
|
||||
$script = $cfg['Path']['admin_to_root'].$cfg['Path']['shared_version'].'socket/'.$script;
|
||||
if (file_exists($script)) {
|
||||
require_once $script;
|
||||
} else {
|
||||
// zalogovat chybu
|
||||
logError(__FILE__, __LINE__, 'SOCKET/LAUNCH.PHP INCLUDE ERROR s='.$_GET['s']);
|
||||
|
||||
$script = $cfg['Path']['admin_to_root'].$cfg['Path']['shared_version'].'socket/Pohoda.php';
|
||||
require_once $script;
|
||||
}
|
||||
}
|
||||
|
||||
// ##############################################################
|
||||
Reference in New Issue
Block a user