BxPaymentGridCommissions.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 Payment Payment
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxPaymentGridCommissions extends BxBaseModPaymentGridCommissions
  12. {
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. $this->_sModule = 'bx_payment';
  16. parent::__construct ($aOptions, $oTemplate);
  17. }
  18. public function performActionAdd()
  19. {
  20. $CNF = &$this->_oModule->_oConfig->CNF;
  21. $sAction = 'add';
  22. $oForm = $this->_getFormObject($sAction);
  23. $oForm->initChecker();
  24. if($oForm->isSubmittedAndValid()) {
  25. $sFormMethod = $oForm->aFormAttrs['method'];
  26. $sLanguage = BxDolStudioLanguagesUtils::getInstance()->getCurrentLangName(false);
  27. $sName = BxDolForm::getSubmittedValue('caption-' . $sLanguage, $sFormMethod);
  28. $sName = uriGenerate(strtolower($sName), $CNF['TABLE_COMMISSIONS'], 'name', 'commission');
  29. $aValsToAdd = array(
  30. 'name' => $sName,
  31. 'active' => 1,
  32. 'order' => $this->_oModule->_oDb->getCommissions(array('type' => 'max_order')) + 1
  33. );
  34. if(($iId = $oForm->insert($aValsToAdd)) !== false)
  35. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  36. else
  37. $aRes = array('msg' => _t('_bx_payment_err_cannot_perform'));
  38. return echoJson($aRes);
  39. }
  40. $sId = $this->_oModule->_oConfig->getHtmlIds('commission', 'popup_' . $sAction);
  41. $sTitle = _t($this->_sLangsPrefix . 'popup_title_cms_' . $sAction);
  42. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($sId, $sTitle, $this->_oModule->_oTemplate->parseHtmlByName('commission_form.html', array(
  43. 'form_id' => $oForm->aFormAttrs['id'],
  44. 'form' => $oForm->getCode(true),
  45. 'object' => $this->_sObject,
  46. 'action' => $sAction
  47. )));
  48. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  49. }
  50. public function performActionEdit()
  51. {
  52. $CNF = &$this->_oModule->_oConfig->CNF;
  53. $aIds = bx_get('ids');
  54. if(!$aIds || !is_array($aIds)) {
  55. $iId = (int)bx_get('id');
  56. if(!$iId)
  57. return echoJson(array());
  58. $aIds = array($iId);
  59. }
  60. $iId = (int)array_shift($aIds);
  61. $aCommission = $this->_oModule->_oDb->getCommissions(array('type' => 'id', 'id' => $iId));
  62. if(empty($aCommission) || !is_array($aCommission))
  63. return echoJson(array());
  64. $sAction = 'edit';
  65. $oForm = $this->_getFormObject($sAction, $iId);
  66. $oForm->initChecker($aCommission);
  67. if($oForm->isSubmittedAndValid()) {
  68. if($oForm->update($iId) !== false)
  69. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  70. else
  71. $aRes = array('msg' => _t('_bx_payment_err_cannot_perform'));
  72. return echoJson($aRes);
  73. }
  74. $sId = $this->_oModule->_oConfig->getHtmlIds('commission', 'popup_' . $sAction);
  75. $sTitle = _t($this->_sLangsPrefix . 'popup_title_cms_' . $sAction);
  76. $sContent = BxTemplStudioFunctions::getInstance()->popupBox($sId, $sTitle, $this->_oModule->_oTemplate->parseHtmlByName('commission_form.html', array(
  77. 'form_id' => $oForm->aFormAttrs['id'],
  78. 'form' => $oForm->getCode(true),
  79. 'object' => $this->_sObject,
  80. 'action' => $sAction
  81. )));
  82. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))));
  83. }
  84. protected function _delete($mixedId)
  85. {
  86. $aCommission = $this->_oModule->_oDb->getCommissions(array('type' => 'id', 'id' => $mixedId));
  87. if(empty($aCommission) || !is_array($aCommission))
  88. return false;
  89. $mixedResult = parent::_delete($mixedId);
  90. if($mixedResult !== false) {
  91. $oLanguage = BxDolStudioLanguagesUtils::getInstance();
  92. $oLanguage->deleteLanguageString($aCommission['caption']);
  93. $oLanguage->deleteLanguageString($aCommission['description']);
  94. }
  95. return $mixedResult;
  96. }
  97. protected function _getFormObject($sAction, $iId = 0)
  98. {
  99. $sFormObject = $this->_oModule->_oConfig->getObject('form_commissions');
  100. $sFormDisplay = $this->_oModule->_oConfig->getObject('form_display_commissions_' . $sAction);
  101. $aParams = array('o' => $this->_sObject, 'a' => $sAction);
  102. if(!empty($iId))
  103. $aParams['id'] = $iId;
  104. $oForm = BxDolForm::getObjectInstance($sFormObject, $sFormDisplay);
  105. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . bx_append_url_params('grid.php', $aParams);
  106. return $oForm;
  107. }
  108. }
  109. /** @} */