BxSitesGridOverview.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Sites Sites
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. require_once(BX_DIRECTORY_PATH_INC . 'design.inc.php');
  12. bx_import('BxTemplGrid');
  13. bx_import('BxDolForm');
  14. bx_import('BxDolPermalinks');
  15. class BxSitesGridOverview extends BxTemplGrid {
  16. protected $_oModule;
  17. protected $_aAccount;
  18. public function __construct ($aOptions, $oTemplate = false) {
  19. parent::__construct ($aOptions, $oTemplate);
  20. bx_import('BxDolModule');
  21. $this->_oModule = BxDolModule::getInstance('bx_sites');
  22. }
  23. public function setAccount(&$aAccount)
  24. {
  25. $this->_aAccount = $aAccount;
  26. $this->_aQueryAppend['account'] = $aAccount['id'];
  27. }
  28. public function performActionUnconfirmed()
  29. {
  30. $sAction = 'unconfirmed';
  31. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_confirm');
  32. if(!$oForm) {
  33. $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
  34. return;
  35. }
  36. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&_r=' . time();
  37. $oForm->aParams['db']['submit_name'] = 'do_confirm';
  38. $oPermalinks = BxDolPermalinks::getInstance();
  39. $sUrl = BX_DOL_URL_ROOT . $oPermalinks->permalink('page.php?i=site-delete&id=' . (int)bx_get('account'));
  40. foreach($oForm->aInputs['confirm_block'] as $iKey => $aInput)
  41. if(is_int($iKey) && !empty($aInput) && $aInput['name'] == 'do_delete')
  42. $oForm->aInputs['confirm_block'][$iKey]['attrs']['onclick'] = 'javascript:window.open(\'' . $sUrl . '\',\'_self\');';
  43. $aAccount = $this->_performAction($oForm, $sAction);
  44. if(!empty($aAccount) && is_array($aAccount))
  45. $this->_startSubscription($aAccount);
  46. }
  47. public function performActionPending()
  48. {
  49. $sAction = 'pending';
  50. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_pending');
  51. if(!$oForm) {
  52. $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
  53. return;
  54. }
  55. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&_r=' . time();
  56. $this->_performAction($oForm, $sAction, false);
  57. //Note: Place onSubmit code here if it's needed.
  58. }
  59. public function performActionActive()
  60. {
  61. $sAction = 'active';
  62. bx_import('BxDolForm');
  63. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_cancel');
  64. if(!$oForm) {
  65. $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
  66. return;
  67. }
  68. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&_r=' . time();
  69. $oForm->aFormAttrs['onsubmit'] = 'return ' . $this->_oModule->_oConfig->getJsObject() . '.onCancelSubscription(this);';
  70. $oForm->aParams['db']['submit_name'] = 'do_cancel';
  71. $aAccount = $this->_performAction($oForm, $sAction);
  72. if(empty($aAccount) || !is_array($aAccount))
  73. return;
  74. $bResult = $this->_oModule->cancelSubscription($aAccount['pd_profile_id']);
  75. if(!$bResult) {
  76. $this->_echoResultJson(array('msg' => _t('_bx_sites_txt_err_cannot_perform')), true);
  77. return;
  78. }
  79. bx_import('BxDolPermalinks');
  80. $oPermalinks = BxDolPermalinks::getInstance();
  81. $sUrl = BX_DOL_URL_ROOT . $oPermalinks->permalink('page.php?i=site-view&id=' . $aAccount['id']);
  82. $this->_echoResultJson(array('eval' => 'window.open(\'' . $sUrl . '\',\'_self\');'), true);
  83. }
  84. public function performActionCanceled()
  85. {
  86. $sAction = 'canceled';
  87. bx_import('BxDolForm');
  88. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_reactivate');
  89. if(!$oForm) {
  90. $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
  91. return;
  92. }
  93. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&_r=' . time();
  94. $oForm->aParams['db']['submit_name'] = 'do_reactivate';
  95. $aAccount = $this->_performAction($oForm, $sAction);
  96. if(!empty($aAccount) && is_array($aAccount))
  97. $this->_startSubscription($aAccount);
  98. }
  99. public function performActionSuspended()
  100. {
  101. $sAction = 'suspended';
  102. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_suspended');
  103. if(!$oForm) {
  104. $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
  105. return;
  106. }
  107. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&_r=' . time();
  108. $this->_performAction($oForm, $sAction, false);
  109. //Note: Place onSubmit code here if it's needed.
  110. }
  111. public function getCode($isDisplayHeader = true)
  112. {
  113. if(in_array($this->_aAccount['status'], array(BX_SITES_ACCOUNT_STATUS_UNCONFIRMED, BX_SITES_ACCOUNT_STATUS_PENDING, BX_SITES_ACCOUNT_STATUS_CANCELED, BX_SITES_ACCOUNT_STATUS_SUSPENDED)))
  114. $this->_oTemplate = $this->_oModule->_oTemplate;
  115. return parent::getCode($isDisplayHeader);
  116. }
  117. protected function _addJsCss() {
  118. parent::_addJsCss();
  119. $this->_oTemplate->addJs(array('jquery.form.min.js'));
  120. $this->_oTemplate->addJsTranslation(array('_bx_sites_form_site_input_do_cancel_confirm'));
  121. bx_import('BxTemplFormView');
  122. $oForm = new BxTemplFormView(array());
  123. $oForm->addCssJs();
  124. }
  125. protected function _getDataArray($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  126. {
  127. $this->_aOptions['source'] = array();
  128. $sCurrency = $this->_oModule->_oConfig->getCurrencyCode();
  129. $iNextPayment = $this->_aAccount['paid'];
  130. $aPayment = $this->_oModule->_oDb->getPaymentHistory(array('type' => 'account_id_last', 'value' => $this->_aAccount['id']));
  131. if(!empty($aPayment) && is_array($aPayment))
  132. $this->_aOptions['source'][] = array(
  133. 'id' => 'last',
  134. 'title' => '_bx_sites_grid_overview_txt_payment_last',
  135. 'type' => '_bx_sites_txt_payment_type_' . $aPayment['type'],
  136. 'transaction' => $aPayment['transaction'],
  137. 'when' => bx_time_js($aPayment['when']),
  138. 'amount' => number_format($aPayment['amount'], 2) . ' ' .$sCurrency
  139. );
  140. if(!empty($iNextPayment)) {
  141. $aAmount = 0;
  142. $fAmountTrial = $this->_oModule->_oConfig->getPaymentPrice(BX_SITES_PP_PERIOD_TRIAL);
  143. $fAmountRegular = $this->_oModule->_oConfig->getPaymentPrice(BX_SITES_PP_PERIOD_REGULAR);
  144. switch($this->_aAccount['status']) {
  145. case BX_SITES_ACCOUNT_STATUS_PENDING:
  146. $aAmount = $fAmountTrial != 0 ? $fAmountTrial : $fAmountRegular;
  147. break;
  148. case BX_SITES_ACCOUNT_STATUS_TRIAL:
  149. $aAmount = $fAmountRegular;
  150. break;
  151. case BX_SITES_ACCOUNT_STATUS_ACTIVE:
  152. $aAmount = $fAmountRegular;
  153. break;
  154. }
  155. $this->_aOptions['source'][] = array(
  156. 'id' => 'next',
  157. 'title' => '_bx_sites_grid_overview_txt_payment_next',
  158. 'type' => '',
  159. 'transaction' => '',
  160. 'when' => bx_time_js($iNextPayment),
  161. 'amount' => number_format($aAmount, 2) . ' ' .$sCurrency
  162. );
  163. }
  164. return parent::_getDataArray($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  165. }
  166. protected function _getFilterControls ()
  167. {
  168. $sAction = $this->_aAccount['status'];
  169. if($sAction == BX_SITES_ACCOUNT_STATUS_TRIAL)
  170. $sAction = BX_SITES_ACCOUNT_STATUS_ACTIVE;
  171. $sStatus = _t('_bx_sites_txt_status_' . $this->_aAccount['status']);
  172. if(in_array($sAction, array(BX_SITES_ACCOUNT_STATUS_UNCONFIRMED, BX_SITES_ACCOUNT_STATUS_PENDING, BX_SITES_ACCOUNT_STATUS_ACTIVE, BX_SITES_ACCOUNT_STATUS_CANCELED, BX_SITES_ACCOUNT_STATUS_SUSPENDED))) {
  173. $sStatus = $this->_oModule->_oTemplate->parseHtmlByName('bx_a.html', array(
  174. 'href' => 'javascript:void(0)',
  175. 'title' => _t('_bx_sites_grid_overview_btn_' . $sAction),
  176. 'bx_repeat:attrs' => array(
  177. array('key' => 'bx_grid_action_independent', 'value' => $sAction),
  178. array('key' => 'bx_grid_action_data', 'value' => $this->_aAccount['id'])
  179. ),
  180. 'content' => $sStatus,
  181. ));
  182. }
  183. return $this->_oModule->_oTemplate->parseHtmlByName('block_overview_status.html', array(
  184. 'status' => $sStatus,
  185. 'bx_if:show_reactivate' => array(
  186. 'condition' => false,
  187. 'content' => array()
  188. )
  189. ));
  190. }
  191. protected function _getActionUnconfirmed($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  192. return '';
  193. }
  194. protected function _getActionPending($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  195. return '';
  196. }
  197. protected function _getActionActive($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  198. return '';
  199. }
  200. protected function _getActionCanceled($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  201. return '';
  202. }
  203. protected function _getActionSuspended($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  204. return '';
  205. }
  206. protected function _performAction(&$oForm, $sAction, $bReturnAccount = true)
  207. {
  208. $iAccountId = (int)bx_get('account');
  209. if($iAccountId !== false)
  210. $oForm->aInputs['id']['value'] = $iAccountId;
  211. $oForm->aInputs['info']['content'] = _t('_bx_sites_form_site_input_info_' . $sAction);
  212. $oForm->initChecker();
  213. if(!$oForm->isSubmittedAndValid()) {
  214. bx_import('BxTemplFunctions');
  215. $sContent = BxTemplFunctions::getInstance()->popupBox('bx-sites-site-' . $sAction . '-popup', _t('_bx_sites_grid_overview_popup_' . $sAction), $this->_oModule->_oTemplate->parseHtmlByName('block_' . $sAction . '.html', array(
  216. 'form_id' => $oForm->aFormAttrs['id'],
  217. 'form' => $oForm->getCode(true),
  218. 'object' => $this->_sObject,
  219. 'action' => $sAction
  220. )));
  221. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  222. return;
  223. }
  224. if(!$bReturnAccount)
  225. return;
  226. $iAccount = $oForm->getCleanValue('id');
  227. $aAccount = $this->_oModule->_oDb->getAccount(array('type' => 'id', 'value' => $iAccount));
  228. if(empty($aAccount) || !is_array($aAccount)) {
  229. $this->_echoResultJson(array('msg' => _t('_bx_sites_txt_err_site_is_not_defined')), true);
  230. return;
  231. }
  232. return $aAccount;
  233. }
  234. protected function _startSubscription($aAccount)
  235. {
  236. $sUrl = $this->_oModule->startSubscription($aAccount['id']);
  237. if(empty($sUrl)) {
  238. $this->_echoResultJson(array('msg' => _t('_bx_sites_txt_err_cannot_perform')), true);
  239. return;
  240. }
  241. $this->_echoResultJson(array('eval' => 'window.open(\'' . $sUrl . '\', \'_self\');', 'popup_not_hide' => 1), true);
  242. }
  243. }
  244. /** @} */