BxAclConfig.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 PaidLevels Paid Levels
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAclConfig extends BxBaseModGeneralConfig
  12. {
  13. protected $_oDb;
  14. protected $_aHtmlIds;
  15. protected $_aCurrency;
  16. protected $_iOwner;
  17. protected $_bShowToUnauthenticated;
  18. protected $_iExpireNotificationDays;
  19. protected $_bExpireNotifyOnce;
  20. protected $_iRemoveExpiredFor;
  21. /**
  22. * Constructor
  23. */
  24. public function __construct($aModule)
  25. {
  26. parent::__construct($aModule);
  27. $this->CNF = array (
  28. // database tables
  29. 'TABLE_PRICES' => $aModule['db_prefix'] . 'level_prices',
  30. 'TABLE_LICENSES' => $aModule['db_prefix'] . 'licenses',
  31. // database fields
  32. 'FIELD_ID' => 'id',
  33. 'FIELD_LEVEL_ID' => 'level_id',
  34. 'FIELD_NAME' => 'name',
  35. 'FIELD_PRICE' => 'price',
  36. 'FIELD_TRIAL' => 'trial',
  37. 'FIELD_IMMEDIATE' => 'immediate',
  38. // page URIs
  39. 'URL_ADMINISTRATION' => 'page.php?i=acl-administration',
  40. 'URL_VIEW' => 'page.php?i=acl-view',
  41. // some params
  42. 'PARAM_DATE_FORMAT' => 'd.m.Y',
  43. 'PARAM_RECURRING_RESERVE' => 'bx_acl_recurring_reserve',
  44. 'PARAM_RECURRING_PRIORITIZE' => 'bx_acl_recurring_prioritize',
  45. 'PARAM_SHOW_TO_UNAUTHENTICATED' => 'bx_acl_show_to_unauthenticated',
  46. 'PARAM_ACTIONS_LIMIT_BLOCK' => 20,
  47. 'PARAM_ACTIONS_LIMIT_POPUP' => 10,
  48. // objects
  49. 'OBJECT_GRID_ADMINISTRATION' => 'bx_acl_administration',
  50. 'OBJECT_GRID_VIEW' => 'bx_acl_view',
  51. 'OBJECT_FORM_PRICE' => 'bx_acl_price',
  52. 'OBJECT_FORM_PRICE_DISPLAY_ADD' => 'bx_acl_price_add',
  53. 'OBJECT_FORM_PRICE_DISPLAY_EDIT' => 'bx_acl_price_edit',
  54. 'OBJECT_FORM_PRELISTS_PERIOD_UNITS' => 'bx_acl_period_units',
  55. // email templates
  56. 'ETEMPLATE_SBS_CANCEL_REQUIRED' => 'bx_acl_subscription_cancel_required',
  57. );
  58. $this->_aGridObjects = array(
  59. 'administration' => $this->CNF['OBJECT_GRID_ADMINISTRATION'],
  60. 'view' => $this->CNF['OBJECT_GRID_VIEW'],
  61. );
  62. $this->_aPrefixes = array(
  63. 'style' => 'bx-acl',
  64. 'option' => 'bx_acl_',
  65. );
  66. $this->_aJsClasses = array(
  67. 'main' => 'BxAclMain',
  68. 'form' => 'BxAclForm',
  69. 'administration' => 'BxAclAdministration',
  70. );
  71. $this->_aJsObjects = array(
  72. 'main' => 'oAclMain',
  73. 'form' => 'oAclForm',
  74. 'administration' => 'oAclAdministration',
  75. );
  76. $sHtmlPrefix = str_replace('_', '-', $this->_sName);
  77. $this->_aHtmlIds = [
  78. 'actions_popup' => $sHtmlPrefix . '-actions-popup-',
  79. 'actions_list' => $sHtmlPrefix . '-actions-list-',
  80. 'popup_price' => $sHtmlPrefix . '-popup-price'
  81. ];
  82. $this->_iOwner = 0;
  83. $this->_aCurrency = [];
  84. $this->_bExpireNotifyOnce = true;
  85. $this->_iExpireNotificationDays = 1;
  86. $this->_iRemoveExpiredFor = 30;
  87. }
  88. public function init(&$oDb)
  89. {
  90. $this->_oDb = &$oDb;
  91. $sOptionPrefix = $this->getPrefix('option');
  92. $this->_bShowToUnauthenticated = getParam($this->CNF['PARAM_SHOW_TO_UNAUTHENTICATED']) == 'on';
  93. //TODO: Looks like these 3 settings aren't used or work.
  94. $this->_iExpireNotificationDays = (int)getParam($sOptionPrefix . 'expire_notification_days');
  95. $this->_bExpireNotifyOnce = getParam($sOptionPrefix . 'expire_notify_once') == 'on';
  96. $this->_iRemoveExpiredFor = (int)getParam($sOptionPrefix . 'remove_expired_for');
  97. }
  98. public function isShowToUnauthenticated()
  99. {
  100. return $this->_bShowToUnauthenticated;
  101. }
  102. public function getExpireNotificationDays()
  103. {
  104. return $this->_iExpireNotificationDays;
  105. }
  106. public function isExpireNotifyOnce()
  107. {
  108. return $this->_bExpireNotifyOnce;
  109. }
  110. public function getRemoveExpiredFor()
  111. {
  112. return $this->_iRemoveExpiredFor;
  113. }
  114. public function getHtmlIds($sKey = '')
  115. {
  116. if(empty($sKey))
  117. return $this->_aHtmlIds;
  118. return isset($this->_aHtmlIds[$sKey]) ? $this->_aHtmlIds[$sKey] : '';
  119. }
  120. public function getOwner()
  121. {
  122. if(empty($this->_iOwner))
  123. $this->_iOwner = (int)BxDolPayments::getInstance()->getOption('site_admin');
  124. return $this->_iOwner;
  125. }
  126. public function getCurrency()
  127. {
  128. if(empty($this->_aCurrency) || !is_array($this->_aCurrency))
  129. $this->_aCurrency = BxDolPayments::getInstance()->getCurrencyInfo($this->getOwner());
  130. return $this->_aCurrency;
  131. }
  132. public function getPriceName($sName)
  133. {
  134. return uriGenerate($sName, $this->CNF['TABLE_PRICES'], $this->CNF['FIELD_NAME'], ['lowercase' => false]);
  135. }
  136. public function formatDate($iTs)
  137. {
  138. return gmdate($this->CNF['PARAM_DATE_FORMAT'], $iTs);
  139. }
  140. }
  141. /** @} */