BxBaseModPaymentConfig.php 7.7 KB

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