BxBaseModPaymentTemplate.php 4.2 KB

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