BxAdsFormSourcesDetails.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAdsSourcesDetailsFormCheckerHelper extends BxDolFormCheckerHelper
  12. {
  13. function checkHttps ($s)
  14. {
  15. return empty($s) || substr(BX_DOL_URL_ROOT, 0, 5) == 'https';
  16. }
  17. }
  18. class BxAdsFormSourcesDetails extends BxTemplFormView
  19. {
  20. protected $_sModule;
  21. protected $_oModule;
  22. protected $_bCollapseFirst;
  23. protected $_iProfileId;
  24. function __construct($aInfo, $oTemplate = false)
  25. {
  26. parent::__construct($aInfo, $oTemplate);
  27. $this->_sModule = 'bx_ads';
  28. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  29. $this->_bCollapseFirst = false;
  30. $this->_iProfileId = $this->_oModule->getProfileId();
  31. $this->init();
  32. }
  33. public function setProfileId($iProfileId = 0)
  34. {
  35. if(!empty($iProfileId))
  36. $this->_iProfileId = $iProfileId;
  37. }
  38. public function init()
  39. {
  40. $aInputs = $this->_oModule->_oDb->getSourcesDetailsForm();
  41. if(empty($aInputs))
  42. return false;
  43. $bCollapsed = $this->_bCollapseFirst;
  44. $iSource = 0;
  45. $sSource = "";
  46. $oSource = null;
  47. foreach($aInputs as $aInput) {
  48. if($iSource != $aInput['source_id']) {
  49. $sBlockHeaderName = 'source_' . $aInput['source_id'] . '_begin';
  50. $this->aInputs[$sBlockHeaderName] = [
  51. 'type' => 'block_header',
  52. 'name' => $sBlockHeaderName,
  53. 'caption' => _t($aInput['source_caption']),
  54. 'info' => _t($aInput['source_description']),
  55. 'collapsable' => true,
  56. 'collapsed' => $bCollapsed
  57. ];
  58. $iSource = $aInput['source_id'];
  59. $sSource = $aInput['source_name'];
  60. $oSource = $this->_oModule->getObjectSource($sSource, $this->_iProfileId);
  61. $bCollapsed = true;
  62. }
  63. $this->aInputs[$aInput['name']] = [
  64. 'type' => $aInput['type'],
  65. 'name' => $aInput['name'],
  66. 'caption' => _t($aInput['caption']),
  67. 'value' => $oSource->getOption($aInput['name']),
  68. 'info' => _t($aInput['description']),
  69. 'attrs' => [
  70. 'bx-data-source' => $iSource
  71. ],
  72. 'checker' => [
  73. 'func' => $aInput['check_type'],
  74. 'params' => $aInput['check_params'],
  75. 'error' => _t($aInput['check_error']),
  76. ]
  77. ];
  78. //--- Make some field dependent actions ---//
  79. switch($aInput['type']) {
  80. case 'select':
  81. if(empty($aInput['extra']))
  82. break;
  83. $aAddon = ['values' => []];
  84. if(BxDolService::isSerializedService($aInput['extra']))
  85. $aAddon['values'] = BxDolService::callSerialized($aInput['extra']);
  86. else {
  87. $aPairs = explode(',', $aInput['extra']);
  88. foreach($aPairs as $sPair) {
  89. $aPair = explode('|', $sPair);
  90. $aAddon['values'][] = ['key' => $aPair[0], 'value' => _t($aPair[1])];
  91. }
  92. }
  93. break;
  94. case 'checkbox':
  95. $this->aInputs[$aInput['name']]['value'] = '1';
  96. $aAddon = array('checked' => $oSource->getOption($aInput['name']) == '1');
  97. break;
  98. case 'value':
  99. $sName = str_replace($aInput['source_option_prefix'], '', $aInput['name']);
  100. if(!in_array($sName, array('return_data_url', 'notify_url')))
  101. break;
  102. $sMethod = 'get' . bx_gen_method_name($sName);
  103. if(method_exists($oSource, $sMethod))
  104. $this->aInputs[$aInput['name']]['value'] = $oSource->$sMethod($this->_iProfileId);
  105. break;
  106. }
  107. if(!empty($aAddon) && is_array($aAddon))
  108. $this->aInputs[$aInput['name']] = array_merge($this->aInputs[$aInput['name']], $aAddon);
  109. }
  110. $this->aInputs['source_' . $iSource . '_end'] = [
  111. 'type' => 'block_end'
  112. ];
  113. $this->aInputs['submit'] = [
  114. 'type' => 'submit',
  115. 'name' => 'submit',
  116. 'value' => _t('_bx_ads_form_sources_details_input_do_submit'),
  117. ];
  118. return true;
  119. }
  120. }
  121. /** @} */