BxAclFormPrice.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 BxAclFormPrice extends BxTemplStudioFormView
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. protected $_bDisplayEdit;
  16. public function __construct($aInfo, $oTemplate = false)
  17. {
  18. $this->_sModule = 'bx_acl';
  19. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  20. parent::__construct($aInfo, $oTemplate);
  21. $CNF = &$this->_oModule->_oConfig->CNF;
  22. $this->_bDisplayEdit = $this->aParams['display'] == $CNF['OBJECT_FORM_PRICE_DISPLAY_EDIT'];
  23. if(isset($this->aInputs[$CNF['FIELD_LEVEL_ID']])) {
  24. $aLevels = $this->_oModule->_oDb->getLevels(['type' => 'for_selector']);
  25. $this->aInputs[$CNF['FIELD_LEVEL_ID']]['values'][] = ['key' => 0, 'value' => _t('_sys_please_select')];
  26. foreach($aLevels as $iId => $sTitle)
  27. if($iId != MEMBERSHIP_ID_STANDARD)
  28. $this->aInputs[$CNF['FIELD_LEVEL_ID']]['values'][] = [
  29. 'key' => $iId,
  30. 'value' => _t($sTitle)
  31. ];
  32. }
  33. if(isset($this->aInputs[$CNF['FIELD_NAME']])) {
  34. $sJsObject = $this->_oModule->_oConfig->getJsObject('form');
  35. $iId = $this->getId();
  36. $aMask = array('mask' => "javascript:%s.checkName('%s');", $sJsObject, $CNF['FIELD_NAME']);
  37. if(!empty($iId) && $this->_bDisplayEdit) {
  38. $aMask['mask'] = "javascript:%s.checkName('%s', %d);";
  39. $aMask[] = $iId;
  40. }
  41. $sOnBlur = call_user_func_array('sprintf', array_values($aMask));
  42. $this->aInputs[$CNF['FIELD_NAME']]['attrs']['onblur'] = $sOnBlur;
  43. }
  44. }
  45. public function setAction($sAction)
  46. {
  47. $this->aFormAttrs['action'] = $sAction;
  48. }
  49. public function setLevelId($iLevelId)
  50. {
  51. $CNF = &$this->_oModule->_oConfig->CNF;
  52. $this->aInputs[$CNF['FIELD_LEVEL_ID']]['value'] = $iLevelId;
  53. if(!empty($iLevelId) && empty($this->aInputs[$CNF['FIELD_NAME']]['value'])) {
  54. $aLevel = $this->_oModule->_oDb->getLevels(array('type' => 'by_id', 'value' => $iLevelId));
  55. $this->aInputs[$CNF['FIELD_NAME']]['value'] = $this->_oModule->_oConfig->getPriceName(_t($aLevel['name']));
  56. }
  57. }
  58. public function getCode($bDynamicMode = false)
  59. {
  60. $sJs = $this->_oModule->_oTemplate->addJs(array('form.js'), $bDynamicMode);
  61. $sCode = '';
  62. if($bDynamicMode)
  63. $sCode .= $sJs;
  64. $sCode .= $this->_oModule->_oTemplate->getJsCode('form');
  65. $sCode .= parent::getCode($bDynamicMode);
  66. return $sCode;
  67. }
  68. public function initChecker($aValues = [], $aSpecificValues = [])
  69. {
  70. $CNF = &$this->_oModule->_oConfig->CNF;
  71. parent::initChecker($aValues, $aSpecificValues);
  72. if($this->_bDisplayEdit) {
  73. if(($aValues['level_id'] ?? 0) == MEMBERSHIP_ID_STANDARD) {
  74. foreach([$CNF['FIELD_LEVEL_ID'], $CNF['FIELD_NAME'], $CNF['FIELD_PRICE'], $CNF['FIELD_TRIAL'], $CNF['FIELD_IMMEDIATE']] as $sField)
  75. if(isset($this->aInputs[$sField]))
  76. $this->aInputs[$sField]['type'] = 'hidden';
  77. }
  78. }
  79. }
  80. public function insert ($aValsToAdd = array(), $isIgnore = false)
  81. {
  82. $CNF = &$this->_oModule->_oConfig->CNF;
  83. if(isset($this->aInputs[$CNF['FIELD_NAME']])) {
  84. $sName = BxDolForm::getSubmittedValue($CNF['FIELD_NAME'], $this->aFormAttrs['method'], $this->_aSpecificValues);
  85. $sName = $this->_oModule->_oConfig->getPriceName($sName);
  86. BxDolForm::setSubmittedValue($CNF['FIELD_NAME'], $sName, $this->aFormAttrs['method'], $this->_aSpecificValues);
  87. }
  88. return parent::insert ($aValsToAdd, $isIgnore);
  89. }
  90. public function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  91. {
  92. $CNF = &$this->_oModule->_oConfig->CNF;
  93. $sNameKey = $CNF['FIELD_NAME'];
  94. if(isset($this->aInputs[$sNameKey])) {
  95. $sName = $this->getCleanValue($sNameKey);
  96. $aContentInfo = $this->_oModule->_oDb->getPrices(array('type' => 'by_id', 'value' => $iContentId));
  97. if($aContentInfo[$sNameKey] != $sName) {
  98. $sName = $this->_oModule->_oConfig->getPriceName($sName);
  99. BxDolForm::setSubmittedValue($sNameKey, $sName, $this->aFormAttrs['method'], $this->_aSpecificValues);
  100. }
  101. }
  102. return parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  103. }
  104. public function getId()
  105. {
  106. $iResult = 0;
  107. $aIds = bx_get('ids');
  108. if(!$aIds || !is_array($aIds)) {
  109. $sId = bx_get('id');
  110. if(!empty($sId))
  111. $iResult = $sId;
  112. }
  113. else
  114. $iResult = array_shift($aIds);
  115. return (int)$iResult;
  116. }
  117. }
  118. /** @} */