BxCreditsFormCredit.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 Credits Credits
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Credit form
  13. */
  14. class BxCreditsFormCredit extends BxTemplFormView
  15. {
  16. protected $_sModule;
  17. protected $_oModule;
  18. protected $_fRate;
  19. protected $_iUserId;
  20. public function __construct($aInfo, $oTemplate = false)
  21. {
  22. $this->_sModule = 'bx_credits';
  23. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  24. parent::__construct($aInfo, $oTemplate);
  25. $CNF = &$this->_oModule->_oConfig->CNF;
  26. $this->_fRate = $this->_oModule->_oConfig->getConversionRateWithdraw();
  27. if(($iUserId = bx_get('user_id')) !== false)
  28. $this->_iUserId = (int)$iUserId;
  29. if(isset($this->aInputs[$CNF['FIELD_C_AMOUNT']])) {
  30. $sInfo = '_bx_credits_form_credit_input_amount_inf_';
  31. switch($this->aParams['display']) {
  32. case $CNF['OBJECT_FORM_CREDIT_DISPLAY_WITHDRAW_REQUEST']:
  33. $sInfo .= 'wr';
  34. break;
  35. default:
  36. $sInfo = '';
  37. }
  38. if($sInfo)
  39. $this->aInputs[$CNF['FIELD_C_AMOUNT']]['info'] = _t($sInfo);
  40. }
  41. if(isset($this->aInputs[$CNF['FIELD_C_MESSAGE']])) {
  42. $sInfo = '_bx_credits_form_credit_input_message_inf_';
  43. switch($this->aParams['display']) {
  44. case $CNF['OBJECT_FORM_CREDIT_DISPLAY_GRANT']:
  45. $sInfo .= 'g';
  46. break;
  47. case $CNF['OBJECT_FORM_CREDIT_DISPLAY_SEND']:
  48. $sInfo .= 's';
  49. break;
  50. case $CNF['OBJECT_FORM_CREDIT_DISPLAY_WITHDRAW_REQUEST']:
  51. $sInfo .= 'wr';
  52. break;
  53. }
  54. $this->aInputs[$CNF['FIELD_C_MESSAGE']]['info'] = _t($sInfo);
  55. }
  56. }
  57. public function initChecker($aValues = [], $aSpecificValues = [])
  58. {
  59. $CNF = &$this->_oModule->_oConfig->CNF;
  60. $aLimits = $this->_oModule->getProfileLimits($this->_iUserId);
  61. if(isset($this->aInputs[$CNF['FIELD_C_CLEARED']])) {
  62. $this->aInputs[$CNF['FIELD_C_CLEARED']]['info'] = bx_replace_markers($this->aInputs[$CNF['FIELD_C_CLEARED']]['info'], $aLimits);
  63. }
  64. if(isset($this->aInputs[$CNF['FIELD_C_AMOUNT']]))
  65. $this->aInputs[$CNF['FIELD_C_AMOUNT']]['info'] = bx_replace_markers($this->aInputs[$CNF['FIELD_C_AMOUNT']]['info'], $aLimits);
  66. parent::initChecker($aValues, $aSpecificValues);
  67. }
  68. public function setUserId($iUserId)
  69. {
  70. $this->_iUserId = $iUserId;
  71. }
  72. protected function genCustomRowRate(&$aInput)
  73. {
  74. if($this->_fRate == 1)
  75. return '';
  76. return $this->genRowStandard($aInput);
  77. }
  78. protected function genCustomRowResult(&$aInput)
  79. {
  80. if($this->_fRate == 1)
  81. return '';
  82. return $this->genRowStandard($aInput);
  83. }
  84. protected function genCustomInputBalance(&$aInput)
  85. {
  86. $aInput['value'] = $this->_oModule->getProfileBalance($this->_iUserId);
  87. return $this->genInputStandard($aInput);
  88. }
  89. protected function genCustomInputCleared(&$aInput)
  90. {
  91. $aInput['value'] = $this->_oModule->getProfileBalanceCleared($this->_iUserId);
  92. return $this->genInputStandard($aInput);
  93. }
  94. protected function genCustomInputRate(&$aInput)
  95. {
  96. $aInput['value'] = $this->_fRate;
  97. $aInput['attrs']['id'] = $this->_oModule->_oConfig->getHtmlIds('withdraw_field_rate');
  98. return $this->genInputStandard($aInput);
  99. }
  100. protected function genCustomInputAmount(&$aInput)
  101. {
  102. if($this->_fRate != 1)
  103. $aInput['attrs']['onblur'] = $this->_oModule->_oConfig->getJsObject('withdraw') . '.getResult(this)';
  104. $aInput['attrs']['id'] = $this->_oModule->_oConfig->getHtmlIds('withdraw_field_amount');
  105. return $this->genInputStandard($aInput);
  106. }
  107. protected function genCustomInputResult(&$aInput)
  108. {
  109. $aInput['attrs']['id'] = $this->_oModule->_oConfig->getHtmlIds('withdraw_field_result');
  110. return $this->genInputStandard($aInput);
  111. }
  112. protected function genCustomInputProfile(&$aInput)
  113. {
  114. if(empty($aInput['custom']) || !is_array($aInput['custom']))
  115. $aInput['custom'] = array();
  116. $aInput['custom']['only_once'] = 1;
  117. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . $this->_oModule->_oConfig->getBaseUri() . "get_profiles";
  118. return $this->genCustomInputUsernamesSuggestions($aInput);
  119. }
  120. }
  121. /** @} */