BxBaseModPaymentTemplate.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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, $bCenter = false)
  51. {
  52. $this->displayPageCodeText($this->_sLangsPrefix . 'page_title_response', $sMessage, $bWrap, $bCenter);
  53. }
  54. public function displayPageCodeError($sMessage, $bWrap = true, $bCenter = false)
  55. {
  56. $this->displayPageCodeText($this->_sLangsPrefix . 'page_title_error', $sMessage, $bWrap, $bCenter);
  57. }
  58. public function displayPageCodeRedirect($sUrl, $aData = array(), $sMethod = 'post', $sMessage = '', $bWrap = true)
  59. {
  60. if(empty($sMessage))
  61. $sMessage = $this->_sLangsPrefix . 'msg_redirecting';
  62. $aTmplVarsData = array();
  63. if(!empty($aData) && is_array($aData))
  64. foreach($aData as $sKey => $mixedValue)
  65. $aTmplVarsData[] = array('name' => bx_html_attribute($sKey), 'value' => bx_html_attribute($mixedValue));
  66. $aParams = array(
  67. 'index' => BX_PAGE_CLEAR,
  68. 'content' => array(
  69. 'page_main_code' => $this->parseHtmlByName('redirect.html', array(
  70. 'content' => $bWrap ? MsgBox(_t($sMessage)) : $sMessage,
  71. 'action' => $sUrl,
  72. 'method' => $sMethod,
  73. 'bx_repeat:items' => $aTmplVarsData
  74. ))
  75. )
  76. );
  77. $this->displayPageCode($aParams);
  78. }
  79. public function displayProfileLink($mixedProfile)
  80. {
  81. if(!is_array($mixedProfile))
  82. $mixedProfile = BxDolModule::getInstance($this->MODULE)->getProfileInfo((int)$mixedProfile);
  83. return $this->displayLink('link', array(
  84. 'href' => $mixedProfile['link'],
  85. 'title' => bx_html_attribute(!empty($mixedProfile['title']) ? $mixedProfile['title'] : $mixedProfile['name']),
  86. 'content' => $mixedProfile['name']
  87. ));
  88. }
  89. public function displayLink($sTemplate, $aParams)
  90. {
  91. return $this->parseHtmlByName($sTemplate . '.html', array(
  92. 'href' => $aParams['href'],
  93. 'title' => $aParams['title'],
  94. 'content' => $aParams['content']
  95. ));
  96. }
  97. protected function displayPageCodeText($sTitle, $sText, $bWrap = true, $bCenter = false)
  98. {
  99. if($bWrap)
  100. $sText = MsgBox(_t($sText));
  101. if($bCenter)
  102. $sText = $this->parsePageByName('center.html', array(
  103. 'content' => $sText
  104. ));
  105. $aParams = array(
  106. 'title' => array(
  107. 'page' => _t($sTitle)
  108. ),
  109. 'content' => array(
  110. 'page_main_code' => $sText
  111. )
  112. );
  113. $this->displayPageCode($aParams);
  114. }
  115. }
  116. /** @} */