BxSitesGridOverview.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <?php
  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 DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. defined('BX_DOL') or die('hack attempt');
  10. require_once(BX_DIRECTORY_PATH_INC . 'design.inc.php');
  11. bx_import('BxTemplGrid');
  12. bx_import('BxDolForm');
  13. bx_import('BxDolPermalinks');
  14. class BxSitesGridOverview extends BxTemplGrid {
  15. protected $_oModule;
  16. protected $_aAccount;
  17. public function __construct ($aOptions, $oTemplate = false) {
  18. parent::__construct ($aOptions, $oTemplate);
  19. bx_import('BxDolModule');
  20. $this->_oModule = BxDolModule::getInstance('bx_sites');
  21. }
  22. public function setAccount(&$aAccount)
  23. {
  24. $this->_aAccount = $aAccount;
  25. $this->_aQueryAppend['account'] = $aAccount['id'];
  26. }
  27. public function performActionUnconfirmed()
  28. {
  29. $sAction = 'unconfirmed';
  30. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_confirm');
  31. if(!$oForm) {
  32. $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
  33. return;
  34. }
  35. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&_r=' . time();
  36. $oForm->aParams['db']['submit_name'] = 'do_confirm';
  37. $iAccountId = (int)bx_get('account');
  38. if($iAccountId !== false)
  39. $oForm->aInputs['id']['value'] = $iAccountId;
  40. $oForm->aInputs['info']['content'] = _t('_bx_sites_form_site_input_info_unconfirmed');
  41. $oPermalinks = BxDolPermalinks::getInstance();
  42. $sUrl = BX_DOL_URL_ROOT . $oPermalinks->permalink('page.php?i=site-delete&id=' . $iAccountId);
  43. foreach($oForm->aInputs['confirm_block'] as $iKey => $aInput)
  44. if(is_int($iKey) && !empty($aInput) && $aInput['name'] == 'do_delete')
  45. $oForm->aInputs['confirm_block'][$iKey]['attrs']['onclick'] = 'javascript:window.open(\'' . $sUrl . '\',\'_self\');';
  46. $oForm->initChecker();
  47. if(!$oForm->isSubmittedAndValid()) {
  48. bx_import('BxTemplFunctions');
  49. $sContent = BxTemplFunctions::getInstance()->popupBox('bx-sites-site-unconfirmed-popup', _t('_bx_sites_grid_overview_popup_unconfirmed'), $this->_oModule->_oTemplate->parseHtmlByName('block_unconfirmed.html', array(
  50. 'form_id' => $oForm->aFormAttrs['id'],
  51. 'form' => $oForm->getCode(true),
  52. 'object' => $this->_sObject,
  53. 'action' => $sAction
  54. )));
  55. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  56. return;
  57. }
  58. $iAccount = $oForm->getCleanValue('id');
  59. $aAccount = $this->_oModule->_oDb->getAccount(array('type' => 'id', 'value' => $iAccount));
  60. if(empty($aAccount) || !is_array($aAccount)) {
  61. $this->_echoResultJson(array('msg' => _t('_bx_sites_txt_err_site_is_not_defined')), true);
  62. return;
  63. }
  64. $sUrl = $this->_oModule->startSubscription($iAccount);
  65. if(empty($sUrl)) {
  66. $this->_echoResultJson(array('msg' => _t('_bx_sites_txt_err_cannot_perform')), true);
  67. return;
  68. }
  69. $this->_echoResultJson(array('eval' => 'window.open(\'' . $sUrl . '\', \'_self\');', 'popup_not_hide' => 1), true);
  70. }
  71. public function performActionPending()
  72. {
  73. $sAction = 'pending';
  74. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_pending');
  75. if(!$oForm) {
  76. $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
  77. return;
  78. }
  79. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&_r=' . time();
  80. $iAccountId = (int)bx_get('account');
  81. if($iAccountId !== false)
  82. $oForm->aInputs['id']['value'] = $iAccountId;
  83. $oForm->aInputs['info']['content'] = _t('_bx_sites_form_site_input_info_pending');
  84. $oForm->initChecker();
  85. if(!$oForm->isSubmittedAndValid()) {
  86. bx_import('BxTemplFunctions');
  87. $sContent = BxTemplFunctions::getInstance()->popupBox('bx-sites-site-pending-popup', _t('_bx_sites_grid_overview_popup_pending'), $this->_oModule->_oTemplate->parseHtmlByName('block_pending.html', array(
  88. 'form_id' => $oForm->aFormAttrs['id'],
  89. 'form' => $oForm->getCode(true),
  90. 'object' => $this->_sObject,
  91. 'action' => $sAction
  92. )));
  93. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  94. return;
  95. }
  96. //Note: Place onSubmit code here if it's needed.
  97. }
  98. public function performActionActive()
  99. {
  100. $sAction = 'active';
  101. bx_import('BxDolForm');
  102. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_cancel');
  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. $oForm->aFormAttrs['onsubmit'] = 'return ' . $this->_oModule->_oConfig->getJsObject() . '.onCancelSubscription(this);';
  109. $oForm->aParams['db']['submit_name'] = 'do_cancel';
  110. $iAccountId = (int)bx_get('account');
  111. if($iAccountId !== false)
  112. $oForm->aInputs['id']['value'] = $iAccountId;
  113. $oForm->aInputs['info']['content'] = _t('_bx_sites_form_site_input_info_active');
  114. $oForm->initChecker();
  115. if(!$oForm->isSubmittedAndValid()) {
  116. bx_import('BxTemplFunctions');
  117. $sContent = BxTemplFunctions::getInstance()->popupBox('bx-sites-site-active-popup', _t('_bx_sites_grid_overview_popup_active'), $this->_oModule->_oTemplate->parseHtmlByName('block_active.html', array(
  118. 'form_id' => $oForm->aFormAttrs['id'],
  119. 'form' => $oForm->getCode(true),
  120. 'object' => $this->_sObject,
  121. 'action' => $sAction
  122. )));
  123. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  124. return;
  125. }
  126. $iAccount = $oForm->getCleanValue('id');
  127. $aAccount = $this->_oModule->_oDb->getAccount(array('type' => 'id', 'value' => $iAccount));
  128. if(empty($aAccount) || !is_array($aAccount)) {
  129. $this->_echoResultJson(array('msg' => _t('_bx_sites_txt_err_site_is_not_defined')), true);
  130. return;
  131. }
  132. $bResult = $this->_oModule->cancelSubscription($aAccount['pd_profile_id']);
  133. if(!$bResult) {
  134. $this->_echoResultJson(array('msg' => _t('_bx_sites_txt_err_cannot_perform')), true);
  135. return;
  136. }
  137. bx_import('BxDolPermalinks');
  138. $oPermalinks = BxDolPermalinks::getInstance();
  139. $sUrl = BX_DOL_URL_ROOT . $oPermalinks->permalink('page.php?i=site-view&id=' . $aAccount['id']);
  140. $this->_echoResultJson(array('eval' => 'window.open(\'' . $sUrl . '\',\'_self\');'), true);
  141. }
  142. public function performActionCanceled()
  143. {
  144. $sAction = 'canceled';
  145. bx_import('BxDolForm');
  146. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_reactivate');
  147. if(!$oForm) {
  148. $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
  149. return;
  150. }
  151. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&_r=' . time();
  152. $oForm->aParams['db']['submit_name'] = 'do_reactivate';
  153. $iAccountId = (int)bx_get('account');
  154. if($iAccountId !== false)
  155. $oForm->aInputs['id']['value'] = $iAccountId;
  156. $oForm->aInputs['info']['content'] = _t('_bx_sites_form_site_input_info_canceled');
  157. $oForm->initChecker();
  158. if(!$oForm->isSubmittedAndValid()) {
  159. bx_import('BxTemplFunctions');
  160. $sContent = BxTemplFunctions::getInstance()->popupBox('bx-sites-site-canceled-popup', _t('_bx_sites_grid_overview_popup_canceled'), $this->_oModule->_oTemplate->parseHtmlByName('block_canceled.html', array(
  161. 'form_id' => $oForm->aFormAttrs['id'],
  162. 'form' => $oForm->getCode(true),
  163. 'object' => $this->_sObject,
  164. 'action' => $sAction
  165. )));
  166. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  167. return;
  168. }
  169. $iAccount = $oForm->getCleanValue('id');
  170. $aAccount = $this->_oModule->_oDb->getAccount(array('type' => 'id', 'value' => $iAccount));
  171. if(empty($aAccount) || !is_array($aAccount)) {
  172. $this->_echoResultJson(array('msg' => _t('_bx_sites_txt_err_site_is_not_defined')), true);
  173. return;
  174. }
  175. $sUrl = $this->_oModule->startSubscription($iAccount);
  176. if(empty($sUrl)) {
  177. $this->_echoResultJson(array('msg' => _t('_bx_sites_txt_err_cannot_perform')), true);
  178. return;
  179. }
  180. $this->_echoResultJson(array('eval' => 'window.open(\'' . $sUrl . '\', \'_self\');', 'popup_not_hide' => 1), true);
  181. }
  182. public function performActionSuspended()
  183. {
  184. $sAction = 'suspended';
  185. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_suspended');
  186. if(!$oForm) {
  187. $this->_echoResultJson(array('msg' => _t('_sys_txt_error_occured')), true);
  188. return;
  189. }
  190. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&_r=' . time();
  191. $iAccountId = (int)bx_get('account');
  192. if($iAccountId !== false)
  193. $oForm->aInputs['id']['value'] = $iAccountId;
  194. $oForm->aInputs['info']['content'] = _t('_bx_sites_form_site_input_info_suspended');
  195. $oForm->initChecker();
  196. if(!$oForm->isSubmittedAndValid()) {
  197. bx_import('BxTemplFunctions');
  198. $sContent = BxTemplFunctions::getInstance()->popupBox('bx-sites-site-suspended-popup', _t('_bx_sites_grid_overview_popup_suspended'), $this->_oModule->_oTemplate->parseHtmlByName('block_suspended.html', array(
  199. 'form_id' => $oForm->aFormAttrs['id'],
  200. 'form' => $oForm->getCode(true),
  201. 'object' => $this->_sObject,
  202. 'action' => $sAction
  203. )));
  204. $this->_echoResultJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => false))), true);
  205. return;
  206. }
  207. //Note: Place onSubmit code here if it's needed.
  208. }
  209. public function getCode($isDisplayHeader = true)
  210. {
  211. 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)))
  212. $this->_oTemplate = $this->_oModule->_oTemplate;
  213. return parent::getCode($isDisplayHeader);
  214. }
  215. protected function _addJsCss() {
  216. parent::_addJsCss();
  217. $this->_oTemplate->addJs(array('jquery.form.js'));
  218. $this->_oTemplate->addJsTranslation(array('_bx_sites_form_site_input_do_cancel_confirm'));
  219. bx_import('BxTemplFormView');
  220. $oForm = new BxTemplFormView(array());
  221. $oForm->addCssJs();
  222. }
  223. protected function _getDataArray($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  224. {
  225. $this->_aOptions['source'] = array();
  226. $sCurrency = $this->_oModule->_oConfig->getCurrencyCode();
  227. $iNextPayment = $this->_aAccount['paid'];
  228. $aPayment = $this->_oModule->_oDb->getPaymentHistory(array('type' => 'account_id_last', 'value' => $this->_aAccount['id']));
  229. if(!empty($aPayment) && is_array($aPayment))
  230. $this->_aOptions['source'][] = array(
  231. 'id' => 'last',
  232. 'title' => '_bx_sites_grid_overview_txt_payment_last',
  233. 'type' => '_bx_sites_txt_payment_type_' . $aPayment['type'],
  234. 'transaction' => $aPayment['transaction'],
  235. 'when' => bx_time_js($aPayment['when']),
  236. 'amount' => number_format($aPayment['amount'], 2) . ' ' .$sCurrency
  237. );
  238. if(!empty($iNextPayment)) {
  239. $aAmount = 0;
  240. $fAmountTrial = $this->_oModule->_oConfig->getPaymentPrice(BX_SITES_PP_PERIOD_TRIAL);
  241. $fAmountRegular = $this->_oModule->_oConfig->getPaymentPrice(BX_SITES_PP_PERIOD_REGULAR);
  242. switch($this->_aAccount['status']) {
  243. case BX_SITES_ACCOUNT_STATUS_PENDING:
  244. $aAmount = $fAmountTrial != 0 ? $fAmountTrial : $fAmountRegular;
  245. break;
  246. case BX_SITES_ACCOUNT_STATUS_TRIAL:
  247. $aAmount = $fAmountRegular;
  248. break;
  249. case BX_SITES_ACCOUNT_STATUS_ACTIVE:
  250. $aAmount = $fAmountRegular;
  251. break;
  252. }
  253. $this->_aOptions['source'][] = array(
  254. 'id' => 'next',
  255. 'title' => '_bx_sites_grid_overview_txt_payment_next',
  256. 'type' => '',
  257. 'transaction' => '',
  258. 'when' => bx_time_js($iNextPayment),
  259. 'amount' => number_format($aAmount, 2) . ' ' .$sCurrency
  260. );
  261. }
  262. return parent::_getDataArray($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  263. }
  264. protected function _getFilterControls ()
  265. {
  266. $sAction = $this->_aAccount['status'];
  267. if($sAction == BX_SITES_ACCOUNT_STATUS_TRIAL)
  268. $sAction = BX_SITES_ACCOUNT_STATUS_ACTIVE;
  269. $sStatus = _t('_bx_sites_txt_status_' . $this->_aAccount['status']);
  270. 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))) {
  271. $sStatus = $this->_oModule->_oTemplate->parseHtmlByName('bx_a.html', array(
  272. 'href' => 'javascript:void(0)',
  273. 'title' => _t('_bx_sites_grid_overview_btn_' . $sAction),
  274. 'bx_repeat:attrs' => array(
  275. array('key' => 'bx_grid_action_independent', 'value' => $sAction),
  276. array('key' => 'bx_grid_action_data', 'value' => $this->_aAccount['id'])
  277. ),
  278. 'content' => $sStatus,
  279. ));
  280. }
  281. return $this->_oModule->_oTemplate->parseHtmlByName('block_overview_status.html', array(
  282. 'status' => $sStatus,
  283. 'bx_if:show_reactivate' => array(
  284. 'condition' => false,
  285. 'content' => array()
  286. )
  287. ));
  288. }
  289. protected function _getActionUnconfirmed($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  290. return '';
  291. }
  292. protected function _getActionPending($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  293. return '';
  294. }
  295. protected function _getActionActive($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  296. return '';
  297. }
  298. protected function _getActionCanceled($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  299. return '';
  300. }
  301. protected function _getActionSuspended($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array()) {
  302. return '';
  303. }
  304. }
  305. /** @} */