BxInvConfig.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 Invites Invites
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxInvConfig extends BxBaseModGeneralConfig
  12. {
  13. protected $_oDb;
  14. protected $_oSession;
  15. protected $_iCountPerUser;
  16. protected $_sKeyCode;
  17. protected $_iKeyLifetime;
  18. protected $_bRequestInvite;
  19. protected $_sRequestsEmail;
  20. protected $_bRegistrationByInvitation;
  21. protected $_bContextAutoJoin;
  22. protected $_iContextKeyLength;
  23. /**
  24. * Constructor
  25. */
  26. public function __construct($aModule)
  27. {
  28. parent::__construct($aModule);
  29. $this->_oSession = BxDolSession::getInstance();
  30. $this->CNF = array (
  31. 'URL_INVITE' => 'page.php?i=invites-invite',
  32. 'URL_REQUEST' => 'page.php?i=invites-request',
  33. 'URL_REQUESTS' => 'page.php?i=invites-requests',
  34. 'URL_INVITES' => 'page.php?i=invites-invites',
  35. 'TABLE_REQUESTS' => $aModule['db_prefix'] . 'requests',
  36. 'TABLE_INVITES' => $aModule['db_prefix'] . 'invites',
  37. 'TABLE_ENTRIES' => $aModule['db_prefix'] . 'invites',
  38. 'FIELD_ADDED' => 'date'
  39. );
  40. $this->_aObjects = array(
  41. 'alert' => $this->_sName,
  42. 'grid_requests' => $this->_sName . '_requests',
  43. 'grid_invites' => $this->_sName . '_invites',
  44. 'form_invite' => $this->_sName . '_invite',
  45. 'form_request' => $this->_sName . '_request',
  46. 'form_display_invite_send' => $this->_sName . '_invite_send',
  47. 'form_display_invite_accept_by_code' => $this->_sName . '_invite_accept_by_code',
  48. 'form_display_request_send' => $this->_sName . '_request_send',
  49. );
  50. $this->_aPrefixes = array(
  51. 'style' => 'bx-inv',
  52. 'option' => 'bx_invites_',
  53. );
  54. $this->_iCountPerUser = 0;
  55. $this->_sKeyCode = 'icode';
  56. $this->_iKeyLifetime = 86400;
  57. $this->_bRequestInvite = true;
  58. $this->_sRequestsEmail = '';
  59. $this->_bRegistrationByInvitation = true;
  60. $this->_bContextAutoJoin = false;
  61. $this->_aJsClasses = [
  62. 'main' => 'BxInvMain',
  63. ];
  64. $this->_aJsObjects = [
  65. 'main' => 'oInvMain',
  66. ];
  67. $sHtmlPrefix = str_replace('_', '-', $this->_sName);
  68. $this->_aHtmlIds = [
  69. 'link_popup' => $sHtmlPrefix . '-link-popup',
  70. 'link_input' => $sHtmlPrefix . '-link-input',
  71. 'code_popup' => $sHtmlPrefix . '-code-popup',
  72. 'code_input' => $sHtmlPrefix . '-code-input',
  73. 'code_link_input' => $sHtmlPrefix . '-code-link-input'
  74. ];
  75. }
  76. public function init(&$oDb)
  77. {
  78. $this->_oDb = &$oDb;
  79. $sOptionPrefix = $this->getPrefix('option');
  80. $this->_iCountPerUser = (int)getParam($sOptionPrefix . 'count_per_user');
  81. $this->_iKeyLifetime = 86400 * (int)getParam($sOptionPrefix . 'key_lifetime');
  82. $this->_bRequestInvite = getParam($sOptionPrefix . 'enable_request_invite') == 'on';
  83. $this->_sRequestsEmail = getParam($sOptionPrefix . 'requests_email');
  84. $this->_bRegistrationByInvitation = getParam($sOptionPrefix . 'enable_reg_by_inv') == 'on';
  85. $this->_bContextAutoJoin = getParam($sOptionPrefix . 'context_auto_join') == 'on';
  86. $this->_iContextKeyLength = (int)getParam($sOptionPrefix . 'context_key_length');
  87. }
  88. public function getCountPerUser()
  89. {
  90. return getActionNumberLeftModule(bx_get_logged_profile_id(), 'invite', $this->_sName);
  91. }
  92. public function getKeyCode()
  93. {
  94. return $this->_sKeyCode;
  95. }
  96. public function getKeyLifetime()
  97. {
  98. return $this->_iKeyLifetime;
  99. }
  100. public function setKey($sKey)
  101. {
  102. return $this->_oSession->setValue($this->_sKeyCode, $sKey);
  103. }
  104. public function getKey()
  105. {
  106. return $this->_oSession->getValue($this->_sKeyCode);
  107. }
  108. public function getUnsetKey()
  109. {
  110. return $this->_oSession->getUnsetValue($this->_sKeyCode);
  111. }
  112. public function unsetKey()
  113. {
  114. return $this->_oSession->unsetValue($this->_sKeyCode);
  115. }
  116. public function isRequestInvite()
  117. {
  118. return $this->_bRequestInvite;
  119. }
  120. public function getRequestsEmail()
  121. {
  122. return $this->_sRequestsEmail;
  123. }
  124. public function isRegistrationByInvitation()
  125. {
  126. return $this->_bRegistrationByInvitation;
  127. }
  128. public function isContextAutoJoin()
  129. {
  130. return $this->_bContextAutoJoin;
  131. }
  132. public function getContextKeyLength()
  133. {
  134. return $this->_iContextKeyLength;
  135. }
  136. public function getHtmlIds($sKey = '')
  137. {
  138. if(empty($sKey))
  139. return $this->_aHtmlIds;
  140. return isset($this->_aHtmlIds[$sKey]) ? $this->_aHtmlIds[$sKey] : '';
  141. }
  142. public function urlEncode($s)
  143. {
  144. return urlencode(base64_encode($s));
  145. }
  146. public function urlDecode($s)
  147. {
  148. return base64_decode(urldecode($s));
  149. }
  150. }
  151. /** @} */