BxBaseModPaymentConfig.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. 'OBJECT_FORM_PRELISTS_CURRENCIES' => '',
  27. 'KEY_SESSION_PENDING' => $this->_sName . '_pending_id',
  28. 'KEY_REQUEST_PENDING' => $this->_sName . '_pending_id',
  29. 'DIVIDER_DESCRIPTOR' => '_',
  30. 'DIVIDER_DESCRIPTORS' => ':',
  31. 'DIVIDER_GRID_FILTERS' => '#-#',
  32. ));
  33. $this->_aPrefixes = array(
  34. 'general' => $this->_sName . '_',
  35. 'langs' => '_' . $this->_sName . '_',
  36. 'options' => $this->_sName . '_'
  37. );
  38. $this->_aObjects = array_merge($this->_aObjects, array(
  39. 'form_pendings' => $this->_sName . '_form_pendings',
  40. 'form_processed' => $this->_sName . '_form_processed',
  41. 'display_pendings_process' => $this->_sName . '_form_pendings_process',
  42. 'display_processed_add' => $this->_sName . '_form_processed_add',
  43. 'menu_dashboard' => 'sys_account_dashboard',
  44. 'menu_cart_submenu' => $this->_sName . '_menu_cart_submenu',
  45. 'menu_orders_submenu' => $this->_sName . '_menu_orders_submenu',
  46. 'menu_sbs_submenu' => $this->_sName . '_menu_sbs_submenu',
  47. 'menu_sbs_actions' => $this->_sName . '_menu_sbs_actions',
  48. 'grid_providers' => $this->_sName . '_grid_providers',
  49. 'grid_history' => $this->_sName . '_grid_orders_history',
  50. 'grid_processed' => $this->_sName . '_grid_orders_processed',
  51. 'grid_pending' => $this->_sName . '_grid_orders_pending',
  52. 'grid_carts' => $this->_sName . '_grid_carts',
  53. 'grid_cart' => $this->_sName . '_grid_cart',
  54. 'grid_sbs_list_my' => $this->_sName . '_grid_sbs_list_my',
  55. 'grid_sbs_list_all' => $this->_sName . '_grid_sbs_list_all',
  56. 'grid_sbs_history' => $this->_sName . '_grid_sbs_history',
  57. ));
  58. $this->_aPerPage = array();
  59. $this->_aHtmlIds = array();
  60. $this->_sAnimationEffect = 'fade';
  61. $this->_iAnimationSpeed = 'slow';
  62. }
  63. public function init(&$oDb)
  64. {
  65. $this->_oDb = $oDb;
  66. $sPrefix = $this->getPrefix('options');
  67. $aCurrencies = BxDolForm::getDataItems($this->CNF['OBJECT_FORM_PRELISTS_CURRENCIES'], false, BX_DATA_VALUES_ADDITIONAL);
  68. $this->_sCurrencyCode = (string)$this->_oDb->getParam($sPrefix . 'default_currency_code');
  69. $this->_sCurrencySign = !empty($this->_sCurrencyCode) && isset($aCurrencies[$this->_sCurrencyCode]) ? $aCurrencies[$this->_sCurrencyCode] : '';
  70. $this->_iSiteAdmin = (int)$this->_oDb->getParam($sPrefix . 'site_admin');
  71. $this->_bSingleSeller = $this->_oDb->getParam($sPrefix . 'single_seller') == 'on';
  72. }
  73. public function getDefaultCurrencySign()
  74. {
  75. return $this->_sCurrencySign;
  76. }
  77. public function getDefaultCurrencyCode()
  78. {
  79. return $this->_sCurrencyCode;
  80. }
  81. public function getSiteAdmin()
  82. {
  83. return $this->_iSiteAdmin;
  84. }
  85. public function isSiteAdmin($iProfileId = 0)
  86. {
  87. if(empty($iProfileId))
  88. $iProfileId = bx_get_logged_profile_id();
  89. return $iProfileId == $this->_iSiteAdmin;
  90. }
  91. public function isSingleSeller()
  92. {
  93. return $this->_bSingleSeller;
  94. }
  95. public function getKey($sType)
  96. {
  97. $sResult = '';
  98. if(empty($sType) || !isset($this->CNF[$sType]))
  99. return $sResult;
  100. return $this->CNF[$sType];
  101. }
  102. public function getUrl($sType, $aParams = array(), $bSsl = false)
  103. {
  104. $sResult = '';
  105. if(empty($sType) || !isset($this->CNF[$sType]))
  106. return $sResult;
  107. if(strncmp($this->CNF[$sType], BX_DOL_URL_ROOT, strlen(BX_DOL_URL_ROOT)) === 0)
  108. $sResult = bx_append_url_params($this->CNF[$sType], $aParams);
  109. else
  110. $sResult = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->CNF[$sType], $aParams);
  111. return $bSsl ? $this->http2https($sResult) : $sResult;
  112. }
  113. public function getDivider($sType)
  114. {
  115. $sResult = '';
  116. if(empty($sType) || !isset($this->CNF[$sType]))
  117. return $sResult;
  118. return $this->CNF[$sType];
  119. }
  120. public function getPerPage($sType = 'default')
  121. {
  122. if(empty($sType))
  123. return $this->_aPerPage;
  124. return isset($this->_aPerPage[$sType]) ? $this->_aPerPage[$sType] : '';
  125. }
  126. public function getHtmlIds($sType, $sKey = '')
  127. {
  128. if(empty($sKey))
  129. return isset($this->_aHtmlIds[$sType]) ? $this->_aHtmlIds[$sType] : array();
  130. return isset($this->_aHtmlIds[$sType][$sKey]) ? $this->_aHtmlIds[$sType][$sKey] : '';
  131. }
  132. public function getAnimationEffect()
  133. {
  134. return $this->_sAnimationEffect;
  135. }
  136. public function getAnimationSpeed()
  137. {
  138. return $this->_iAnimationSpeed;
  139. }
  140. public function getLicense()
  141. {
  142. list($fMilliSec, $iSec) = explode(' ', microtime());
  143. $fSeed = (float)$iSec + ((float)$fMilliSec * 100000);
  144. srand($fSeed);
  145. $sResult = '';
  146. for($i=0; $i < 16; ++$i) {
  147. switch(rand(1,2)) {
  148. case 1:
  149. $c = chr(rand(ord('A'),ord('Z')));
  150. break;
  151. case 2:
  152. $c = chr(rand(ord('0'),ord('9')));
  153. break;
  154. }
  155. $sResult .= $c;
  156. }
  157. return $sResult;
  158. }
  159. }
  160. /** @} */