BxBaseModPaymentTemplate.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 BasePayment Base classes for Payment like modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModPaymentTemplate extends BxBaseModGeneralTemplate
  12. {
  13. function __construct($oConfig, $oDb)
  14. {
  15. parent::__construct($oConfig, $oDb);
  16. }
  17. public function displayJsCode($sType, $aParams = array(), $aRequestParams = array())
  18. {
  19. $sJsClass = $this->_oConfig->getJsClass($sType);
  20. $sJsObject = $this->_oConfig->getJsObject($sType);
  21. $aParams = array_merge(array(
  22. 'sActionUrl' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri(),
  23. 'sObjName' => $sJsObject,
  24. 'sAnimationEffect' => $this->_oConfig->getAnimationEffect(),
  25. 'iAnimationSpeed' => $this->_oConfig->getAnimationSpeed(),
  26. 'aHtmlIds' => $this->_oConfig->getHtmlIds($sType),
  27. 'oRequestParams' => $aRequestParams
  28. ), $aParams);
  29. return $this->_wrapInTagJsCode("var " . $sJsObject . " = new " . $sJsClass . "(" . json_encode($aParams) . ");");
  30. }
  31. public function displayPageCode(&$aParams)
  32. {
  33. check_logged();
  34. $oTemplate = BxDolTemplate::getInstance();
  35. $iIndex = isset($aParams['index']) ? (int)$aParams['index'] : BX_PAGE_DEFAULT;
  36. $oTemplate->setPageNameIndex($iIndex);
  37. if(isset($aParams['js']))
  38. $oTemplate->addJs($aParams['js']);
  39. if(isset($aParams['css']))
  40. $oTemplate->addCss($aParams['css']);
  41. if(isset($aParams['title']['page']))
  42. $oTemplate->setPageHeader($aParams['title']['page']);
  43. if(isset($aParams['title']['block']))
  44. $oTemplate->setPageParams(array('header_text' => $aParams['title']['block']));
  45. if(isset($aParams['content']))
  46. foreach($aParams['content'] as $sKey => $sValue)
  47. $oTemplate->setPageContent($sKey, $sValue);
  48. $oTemplate->getPageCode();
  49. }
  50. public function displayPageCodeResponse($sMessage, $bWrap = true)
  51. {
  52. $aParams = array(
  53. 'title' => array(
  54. 'page' => _t($this->_sLangsPrefix . 'page_title_response')
  55. ),
  56. 'content' => array(
  57. 'page_main_code' => $bWrap ? MsgBox(_t($sMessage)) : $sMessage
  58. )
  59. );
  60. $this->displayPageCode($aParams);
  61. }
  62. public function displayPageCodeError($sMessage, $bWrap = true)
  63. {
  64. $aParams = array(
  65. 'title' => array(
  66. 'page' => _t($this->_sLangsPrefix . 'page_title_error')
  67. ),
  68. 'content' => array(
  69. 'page_main_code' => $bWrap ? MsgBox(_t($sMessage)) : $sMessage
  70. )
  71. );
  72. $this->displayPageCode($aParams);
  73. }
  74. public function displayPageCodeRedirect($sUrl, $aData = array(), $sMethod = 'post', $sMessage = '', $bWrap = true)
  75. {
  76. if(empty($sMessage))
  77. $sMessage = $this->_sLangsPrefix . 'msg_redirecting';
  78. $aTmplVarsData = array();
  79. if(!empty($aData) && is_array($aData))
  80. foreach($aData as $sKey => $mixedValue)
  81. $aTmplVarsData[] = array('name' => bx_html_attribute($sKey), 'value' => bx_html_attribute($mixedValue));
  82. $aParams = array(
  83. 'index' => BX_PAGE_CLEAR,
  84. 'content' => array(
  85. 'page_main_code' => $this->parseHtmlByName('redirect.html', array(
  86. 'content' => $bWrap ? MsgBox(_t($sMessage)) : $sMessage,
  87. 'action' => $sUrl,
  88. 'method' => $sMethod,
  89. 'bx_repeat:items' => $aTmplVarsData
  90. ))
  91. )
  92. );
  93. $this->displayPageCode($aParams);
  94. }
  95. public function displayProfileLink($mixedProfile)
  96. {
  97. if(!is_array($mixedProfile))
  98. $mixedProfile = BxDolModule::getInstance($this->MODULE)->getProfileInfo((int)$mixedProfile);
  99. return $this->displayLink('link', array(
  100. 'href' => $mixedProfile['link'],
  101. 'title' => bx_html_attribute(!empty($mixedProfile['title']) ? $mixedProfile['title'] : $mixedProfile['name']),
  102. 'content' => $mixedProfile['name']
  103. ));
  104. }
  105. public function displayLink($sTemplate, $aParams)
  106. {
  107. return $this->parseHtmlByName($sTemplate . '.html', array(
  108. 'href' => $aParams['href'],
  109. 'title' => $aParams['title'],
  110. 'content' => $aParams['content']
  111. ));
  112. }
  113. }
  114. /** @} */