18 function float2sdnum($dNumber)
20 return (
int) round(((
double) $dNumber) * 100.00);
29 function sdnum2float($nSellerDeckNumber)
31 return (
double) ((double) $nSellerDeckNumber) / 100.00;
40 function SellerDeckDate($sDate = null)
45 return date(SELLERDECK_DATE_FORMAT);
48 $sDate = preg_replace(
'/([0-9]{4}-[0-9]{2}-[0-9]{2}).([0-9]{2}:[0-9]{2}:[0-9]{2}).*/',
'$1 $2', $sDate);
50 return date(SELLERDECK_DATE_FORMAT, strtotime($sDate));
61 function select_get($oQueryResult, $key, $default = null)
63 if (!is_object($oQueryResult))
67 return arr_get($oQueryResult->fetch(\PDO::FETCH_ASSOC), $key, $default);
76 function get_wsdl($sWsdlUrl = WSDL_URL)
79 $oConnection = curl_init();
80 curl_setopt_array($oConnection, array(
81 CURLOPT_URL => $sWsdlUrl,
82 CURLOPT_BINARYTRANSFER => 1,
83 CURLOPT_RETURNTRANSFER => 1,
84 CURLOPT_TIMEOUT => 10,
86 $sResponsemXml = curl_exec($oConnection);
87 if (empty($sResponsemXml))
89 throw new \SDExtension\SDException\SDException(
"Can't get WSDL.");
91 return 'data://text/plain;base64,' . base64_encode($sResponsemXml);
100 function CreateSDApiSoapJobs()
103 $sWsdlURL =
\SDExtension\CConfig::get(
'sdd-configuration.notificationsapi.apiwsdl',
'http://localhost:54385/ActinicNotificationService?wsdl');
104 $oFileData = get_wsdl($sWsdlURL);
105 $oSyncService = new \SoapClient($oFileData, array(
'exceptions' =>
false));
106 return new \SDExtension\CSDApiSoapJobs($oSyncService, $sApiKey);
115 function save_config($aSdeConfigData = [], $bMergeWithOriginal =
true, $sSdeConfigFile = EXTENSION_CONFIG_FILE)
117 if ($bMergeWithOriginal && file_exists($sSdeConfigFile))
119 $aOriginalSdeConfigData = include $sSdeConfigFile;
120 $aSdeConfigData = array_merge($aOriginalSdeConfigData, $aSdeConfigData);
122 $sConfigPHPCode = sprintf(CONFIG_PHP_HEADER, basename($sSdeConfigFile)) .
123 var_export($aSdeConfigData,
true) .
125 file_put_contents($sSdeConfigFile, $sConfigPHPCode);
133 function GetTableClassFolderByDBType()
136 $sTableClassFolder =
"access";
137 if (DB_TYPE_SQLSERVER == $sDbType)
139 $sTableClassFolder =
"sqlserver";
141 return $sTableClassFolder;
150 function sd_encrypt($sData)
152 return encrypt_decrypt(
'encrypt', $sData);
161 function sd_decrypt($sData)
163 return encrypt_decrypt(
'decrypt', $sData);
173 function get_setting($sSettingKey, $vDefault = null)
175 $aSettings = parse_ini_file(SETTINGS_INI);
176 return arr_get($aSettings, $sSettingKey, $vDefault);
186 function set_setting($sSettingKey, $vValue)
188 $aSettings = parse_ini_file(SETTINGS_INI);
189 $aSettings[$sSettingKey] = $vValue;
190 write_ini_file([
'extension' => $aSettings], SETTINGS_INI,
true);
215 function encrypt_decrypt($sAction, $sData)
218 $sEncryptMethod =
"AES-256-CBC";
219 $sSecretKey =
'This is my secret key';
220 $sSecretIV =
'This is my secret iv';
224 $sKey = hash(
'sha256', $sSecretKey);
228 $sIV = substr(hash(
'sha256', $sSecretIV), 0, 16);
229 if ($sAction ==
'encrypt')
231 $sOutput = base64_encode(openssl_encrypt($sData, $sEncryptMethod, $sKey, 0, $sIV));
233 else if ($sAction ==
'decrypt')
235 $sOutput = openssl_decrypt(base64_decode($sData), $sEncryptMethod, $sKey, 0, $sIV);
246 function valid_date($sDate)
248 list($nY, $sM, $sD) = explode(
'-', $sDate);
249 return checkdate($sM, $sD, $nY);
258 function valid_date_format($sDate)
260 if (preg_match(
"/^([0-9]{4})-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2][0-9]|3[0-1])$/", $sDate))
275 function between($vInput, $vParam1, $vParam2)
277 if (($vInput >= $vParam1) && ($vInput <= $vParam2))
290 function CreateLock($sDownloadLockFile = null)
292 if ($sDownloadLockFile == null)
294 $sDownloadLockFile = get_setting(
'extension_program_data',
"./") . LOCK_FILE;
296 if (!file_exists($sDownloadLockFile) || ((time() - filemtime($sDownloadLockFile)) > LOCK_FILE_MAX_AGE))
298 file_put_contents($sDownloadLockFile,
"");
310 function RemoveLock($sDownloadLockFile = null)
312 if ($sDownloadLockFile == null)
314 $sDownloadLockFile = get_setting(
'extension_program_data',
"./") . LOCK_FILE;
316 if (file_exists($sDownloadLockFile))
318 unlink($sDownloadLockFile);
static get($sName=null, $vDefault=[])