BxBaseModPaymentConfig.php 7.9 KB

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