BxBaseModPaymentConfig.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 getKey($sType)
  110. {
  111. $sResult = '';
  112. if(empty($sType) || !isset($this->CNF[$sType]))
  113. return $sResult;
  114. return $this->CNF[$sType];
  115. }
  116. public function getUrl($sType, $aParams = array(), $bSsl = false)
  117. {
  118. $sResult = '';
  119. if(empty($sType) || !isset($this->CNF[$sType]))
  120. return $sResult;
  121. if(strncmp($this->CNF[$sType], BX_DOL_URL_ROOT, strlen(BX_DOL_URL_ROOT)) === 0)
  122. $sResult = bx_append_url_params($this->CNF[$sType], $aParams);
  123. else
  124. $sResult = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->CNF[$sType], $aParams);
  125. return $bSsl ? $this->http2https($sResult) : $sResult;
  126. }
  127. public function getDivider($sType)
  128. {
  129. $sResult = '';
  130. if(empty($sType) || !isset($this->CNF[$sType]))
  131. return $sResult;
  132. return $this->CNF[$sType];
  133. }
  134. public function getPerPage($sType = 'default')
  135. {
  136. if(empty($sType))
  137. return $this->_aPerPage;
  138. return isset($this->_aPerPage[$sType]) ? $this->_aPerPage[$sType] : '';
  139. }
  140. public function getHtmlIds($sType, $sKey = '')
  141. {
  142. if(empty($sKey))
  143. return isset($this->_aHtmlIds[$sType]) ? $this->_aHtmlIds[$sType] : array();
  144. return isset($this->_aHtmlIds[$sType][$sKey]) ? $this->_aHtmlIds[$sType][$sKey] : '';
  145. }
  146. public function getAnimationEffect()
  147. {
  148. return $this->_sAnimationEffect;
  149. }
  150. public function getAnimationSpeed()
  151. {
  152. return $this->_iAnimationSpeed;
  153. }
  154. public function getLicense()
  155. {
  156. list($fMilliSec, $iSec) = explode(' ', microtime());
  157. $fSeed = (float)$iSec + ((float)$fMilliSec * 100000);
  158. srand($fSeed);
  159. $sResult = '';
  160. for($i=0; $i < 16; ++$i) {
  161. switch(rand(1,2)) {
  162. case 1:
  163. $c = chr(rand(ord('A'),ord('Z')));
  164. break;
  165. case 2:
  166. $c = chr(rand(ord('0'),ord('9')));
  167. break;
  168. }
  169. $sResult .= $c;
  170. }
  171. return $sResult;
  172. }
  173. public function formatDate($iTs)
  174. {
  175. return gmdate($this->CNF['PARAM_CMSN_DATE_FORMAT'], $iTs);
  176. }
  177. public function formatDateTime($iTs)
  178. {
  179. return gmdate($this->CNF['PARAM_CMSN_DATE_TIME_FORMAT'], $iTs);
  180. }
  181. }
  182. /** @} */