BxBaseModPaymentConfig.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BasePayment Base classes for Payment like modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModPaymentConfig extends BxBaseModGeneralConfig
  12. {
  13. protected $_oDb;
  14. protected $_sCurrencySign;
  15. protected $_sCurrencyCode;
  16. protected $_iSiteAdmin;
  17. protected $_bSingleSeller;
  18. protected $_aPerPage;
  19. protected $_aHtmlIds;
  20. protected $_sAnimationEffect;
  21. protected $_iAnimationSpeed;
  22. function __construct($aModule)
  23. {
  24. parent::__construct($aModule);
  25. $this->CNF = array_merge($this->CNF, array(
  26. // some params
  27. 'PARAM_CURRENCY_CODE' => $this->_sName . '_default_currency_code',
  28. 'PARAM_CMSN_INVOICE_ISSUE_DAY' => 1, //the first day of month
  29. 'PARAM_CMSN_INVOICE_LIFETIME' => 4, //in days
  30. 'PARAM_CMSN_INVOICE_EXPIRATION_NOTIFY' => 1, //in days, before expiration date
  31. 'PARAM_CMSN_DATE_FORMAT' => 'd.m.Y',
  32. 'PARAM_CMSN_DATE_TIME_FORMAT' => 'd.m.Y H:i',
  33. // objects
  34. 'OBJECT_FORM_PRELISTS_CURRENCIES' => '',
  35. 'PROVIDER_GENERIC' => 'generic',
  36. 'KEY_SESSION_PENDING' => $this->_sName . '_pending_id',
  37. 'KEY_REQUEST_PENDING' => $this->_sName . '_pending_id',
  38. 'DIVIDER_DESCRIPTOR' => '_',
  39. 'DIVIDER_DESCRIPTORS' => ':',
  40. 'DIVIDER_GRID_FILTERS' => '#-#',
  41. ));
  42. $this->_aPrefixes = array(
  43. 'general' => $this->_sName . '_',
  44. 'langs' => '_' . $this->_sName . '_',
  45. 'options' => $this->_sName . '_'
  46. );
  47. $this->_aObjects = array_merge($this->_aObjects, array(
  48. 'form_details' => $this->_sName . '_form_details',
  49. 'form_display_details_edit' => $this->_sName . '_form_details_edit',
  50. 'form_pendings' => $this->_sName . '_form_pendings',
  51. 'form_processed' => $this->_sName . '_form_processed',
  52. 'form_display_pendings_process' => $this->_sName . '_form_pendings_process',
  53. 'form_display_processed_add' => $this->_sName . '_form_processed_add',
  54. 'form_commissions' => $this->_sName . '_form_commissions',
  55. 'form_display_commissions_add' => $this->_sName . '_form_commissions_add',
  56. 'form_display_commissions_edit' => $this->_sName . '_form_commissions_edit',
  57. 'form_invoices' => $this->_sName . '_form_invoices',
  58. 'form_display_invoices_edit' => $this->_sName . '_form_invoices_edit',
  59. 'menu_dashboard' => 'sys_account_dashboard',
  60. 'menu_cart_submenu' => $this->_sName . '_menu_cart_submenu',
  61. 'menu_orders_submenu' => $this->_sName . '_menu_orders_submenu',
  62. 'menu_sbs_submenu' => $this->_sName . '_menu_sbs_submenu',
  63. 'menu_sbs_actions' => $this->_sName . '_menu_sbs_actions',
  64. 'grid_providers' => $this->_sName . '_grid_providers',
  65. 'grid_history' => $this->_sName . '_grid_orders_history',
  66. 'grid_processed' => $this->_sName . '_grid_orders_processed',
  67. 'grid_pending' => $this->_sName . '_grid_orders_pending',
  68. 'grid_commissions' => $this->_sName . '_grid_commissions',
  69. 'grid_invoices' => $this->_sName . '_grid_invoices',
  70. 'grid_carts' => $this->_sName . '_grid_carts',
  71. 'grid_cart' => $this->_sName . '_grid_cart',
  72. 'grid_sbs_list_my' => $this->_sName . '_grid_sbs_list_my',
  73. 'grid_sbs_list_all' => $this->_sName . '_grid_sbs_list_all',
  74. 'grid_sbs_history' => $this->_sName . '_grid_sbs_history',
  75. ));
  76. $this->_aPerPage = array();
  77. $this->_aHtmlIds = array();
  78. $this->_sAnimationEffect = 'fade';
  79. $this->_iAnimationSpeed = 'slow';
  80. }
  81. public function init(&$oDb)
  82. {
  83. $this->_oDb = $oDb;
  84. $sPrefix = $this->getPrefix('options');
  85. $this->_sCurrencyCode = (string)$this->_oDb->getParam($this->CNF['PARAM_CURRENCY_CODE']);
  86. $this->_sCurrencySign = $this->retrieveCurrencySign($this->_sCurrencyCode);
  87. $this->_iSiteAdmin = (int)$this->_oDb->getParam($sPrefix . 'site_admin');
  88. $this->_bSingleSeller = $this->_oDb->getParam($sPrefix . 'single_seller') == 'on';
  89. }
  90. public function getDefaultCurrencySign()
  91. {
  92. return $this->_sCurrencySign;
  93. }
  94. public function getDefaultCurrencyCode()
  95. {
  96. return $this->_sCurrencyCode;
  97. }
  98. public function getSiteAdmin()
  99. {
  100. return $this->_iSiteAdmin;
  101. }
  102. public function isSiteAdmin($iProfileId = 0)
  103. {
  104. if(empty($iProfileId))
  105. $iProfileId = bx_get_logged_profile_id();
  106. return $iProfileId == $this->_iSiteAdmin;
  107. }
  108. public function isSingleSeller()
  109. {
  110. return $this->_bSingleSeller;
  111. }
  112. public function getInvoiceIssueDay()
  113. {
  114. $sKey = 'PARAM_CMSN_INVOICE_ISSUE_DAY';
  115. return is_numeric($this->CNF[$sKey]) ? $this->CNF[$sKey] : $this->_oDb->getParam($this->CNF[$sKey]);
  116. }
  117. public function getInvoiceLifetime()
  118. {
  119. $sKey = 'PARAM_CMSN_INVOICE_LIFETIME';
  120. return is_numeric($this->CNF[$sKey]) ? $this->CNF[$sKey] : $this->_oDb->getParam($this->CNF[$sKey]);
  121. }
  122. public function getInvoiceExpirationNotify()
  123. {
  124. $sKey = 'PARAM_CMSN_INVOICE_EXPIRATION_NOTIFY';
  125. return is_numeric($this->CNF[$sKey]) ? $this->CNF[$sKey] : $this->_oDb->getParam($this->CNF[$sKey]);
  126. }
  127. public function getKey($sType)
  128. {
  129. $sResult = '';
  130. if(empty($sType) || !isset($this->CNF[$sType]))
  131. return $sResult;
  132. return $this->CNF[$sType];
  133. }
  134. public function getUrl($sType, $aParams = array(), $bSsl = false)
  135. {
  136. $sResult = '';
  137. if(empty($sType) || !isset($this->CNF[$sType]))
  138. return $sResult;
  139. if(strncmp($this->CNF[$sType], BX_DOL_URL_ROOT, strlen(BX_DOL_URL_ROOT)) === 0)
  140. $sResult = bx_append_url_params($this->CNF[$sType], $aParams);
  141. else
  142. $sResult = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($this->CNF[$sType], $aParams));
  143. return $bSsl ? $this->http2https($sResult) : $sResult;
  144. }
  145. public function getDivider($sType)
  146. {
  147. $sResult = '';
  148. if(empty($sType) || !isset($this->CNF[$sType]))
  149. return $sResult;
  150. return $this->CNF[$sType];
  151. }
  152. public function getPerPage($sType = 'default')
  153. {
  154. if(empty($sType))
  155. return $this->_aPerPage;
  156. return isset($this->_aPerPage[$sType]) ? $this->_aPerPage[$sType] : '';
  157. }
  158. public function getHtmlIds($sType, $sKey = '')
  159. {
  160. if(empty($sKey))
  161. return isset($this->_aHtmlIds[$sType]) ? $this->_aHtmlIds[$sType] : array();
  162. return isset($this->_aHtmlIds[$sType][$sKey]) ? $this->_aHtmlIds[$sType][$sKey] : '';
  163. }
  164. public function getAnimationEffect()
  165. {
  166. return $this->_sAnimationEffect;
  167. }
  168. public function getAnimationSpeed()
  169. {
  170. return $this->_iAnimationSpeed;
  171. }
  172. public function getLicense()
  173. {
  174. list($fMilliSec, $iSec) = explode(' ', microtime());
  175. $fSeed = (float)$iSec + ((float)$fMilliSec * 100000);
  176. srand($fSeed);
  177. $sResult = '';
  178. for($i=0; $i < 16; ++$i) {
  179. switch(rand(1,2)) {
  180. case 1:
  181. $c = chr(rand(ord('A'),ord('Z')));
  182. break;
  183. case 2:
  184. $c = chr(rand(ord('0'),ord('9')));
  185. break;
  186. }
  187. $sResult .= $c;
  188. }
  189. return $sResult;
  190. }
  191. public function formatDate($iTs)
  192. {
  193. return gmdate($this->CNF['PARAM_CMSN_DATE_FORMAT'], $iTs);
  194. }
  195. public function formatDateTime($iTs)
  196. {
  197. return gmdate($this->CNF['PARAM_CMSN_DATE_TIME_FORMAT'], $iTs);
  198. }
  199. public function retrieveCurrencySign($sCode)
  200. {
  201. if(empty($sCode))
  202. return '';
  203. $aCurrencies = BxDolForm::getDataItems($this->CNF['OBJECT_FORM_PRELISTS_CURRENCIES'], false, BX_DATA_VALUES_ADDITIONAL);
  204. if(!isset($aCurrencies[$sCode]))
  205. return '';
  206. return $aCurrencies[$sCode];
  207. }
  208. }
  209. /** @} */