BxSitesForms.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 Sites Sites
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Note forms functions
  13. */
  14. class BxSitesForms extends BxDolProfileForms
  15. {
  16. protected $_oModule;
  17. public function __construct(&$oModule)
  18. {
  19. parent::__construct();
  20. $this->_oModule = $oModule;
  21. }
  22. /**
  23. * @return add data html
  24. */
  25. public function addDataForm()
  26. {
  27. $sMsg = $this->_oModule->isAllowedAdd();
  28. if($sMsg !== CHECK_ACTION_RESULT_ALLOWED)
  29. return MsgBox($sMsg);
  30. $oForm = BxDolForm::getObjectInstance('bx_sites', 'bx_sites_site_add');
  31. if(!$oForm)
  32. return MsgBox(_t('_sys_txt_error_occured'));
  33. unset($oForm->aInputs['submit_block'][1]);
  34. $oForm->initChecker();
  35. if(!$oForm->isSubmittedAndValid())
  36. return $oForm->getCode();
  37. $sDomain = $oForm->getCleanValue('domain');
  38. if($this->_oModule->_oDb->isAccount(array('domain' => $sDomain)))
  39. return MsgBox(_t('_bx_sites_txt_err_site_exists'));
  40. $iAccountId = $oForm->insert(array(
  41. 'owner_id' => bx_get_logged_profile_id(),
  42. 'created' => time(),
  43. 'status' => BX_SITES_ACCOUNT_STATUS_UNCONFIRMED
  44. ));
  45. if(!$iAccountId)
  46. return MsgBox(_t('_bx_sites_txt_err_site_creation'));
  47. $oAccount = $this->_oModule->getObject('Account');
  48. $oAccount->onAccountCreated($iAccountId);
  49. $sUrl = $this->_oModule->startSubscription($iAccountId);
  50. header('Location: ' . $sUrl);
  51. exit;
  52. }
  53. /**
  54. * @return edit data html
  55. */
  56. public function editDataForm($aAccount, $sDisplay = 'bx_sites_site_edit')
  57. {
  58. $sMsg = $this->_oModule->isAllowedEdit($aAccount);
  59. if($sMsg !== CHECK_ACTION_RESULT_ALLOWED)
  60. return MsgBox($sMsg);
  61. // check and display form
  62. $oForm = BxDolForm::getObjectInstance('bx_sites', $sDisplay);
  63. if(!$oForm)
  64. return MsgBox(_t('_sys_txt_error_occured'));
  65. $oForm->aInputs['domain']['required'] = false;
  66. $oForm->aInputs['domain']['attrs'] = array(
  67. 'disabled' => 'disabled'
  68. );
  69. unset($oForm->aInputs['domain']['checker'], $oForm->aInputs['domain']['db']);
  70. $oForm->initChecker($aAccount);
  71. $oForm->aInputs['domain']['value'] = $this->_oModule->getDomain($oForm->aInputs['domain']['value']);
  72. if (!$oForm->isSubmittedAndValid())
  73. return $oForm->getCode();
  74. if(!$oForm->update($aAccount['id'])) {
  75. if (!$oForm->isValid())
  76. return $oForm->getCode();
  77. else
  78. return MsgBox(_t('_bx_sites_txt_err_site_update'));
  79. }
  80. // perform action
  81. $this->_oModule->isAllowedEdit($aAccount, true);
  82. // create an alert
  83. bx_alert($this->_oModule->getName(), 'edited', $aAccount['id']);
  84. // redirect
  85. $this->_redirectAndExit('page.php?i=site-view&id=' . $aAccount['id']);
  86. }
  87. /**
  88. * @return delete data html
  89. */
  90. public function deleteDataForm($aAccount, $sDisplay = 'bx_sites_site_delete')
  91. {
  92. $sMsg = $this->_oModule->isAllowedDelete($aAccount);
  93. if($sMsg !== CHECK_ACTION_RESULT_ALLOWED)
  94. return MsgBox($sMsg);
  95. // check and display form
  96. $oForm = BxDolForm::getObjectInstance('bx_sites', $sDisplay);
  97. if(!$oForm)
  98. return MsgBox(_t('_sys_txt_error_occured'));
  99. $oForm->initChecker($aAccount);
  100. if(!$oForm->isSubmittedAndValid())
  101. return $oForm->getCode();
  102. if(!$oForm->delete($aAccount['id'], $aAccount))
  103. return MsgBox(_t('_bx_sites_txt_err_site_delete'));
  104. //delete payment details and history
  105. if(!empty($aAccount['id'])) {
  106. $this->_oModule->_oDb->deletePaymentDetails(array('account_id' => $aAccount['id']));
  107. $this->_oModule->_oDb->deletePaymentHistory(array('account_id' => $aAccount['id']));
  108. }
  109. // cancel subscription
  110. if(!empty($aAccount['pd_profile_id'])) {
  111. bx_import('Paypal', $this->_oModule->_aModule);
  112. $oPaypal = new BxSitesPaypal($this->_oModule);
  113. $oPaypal->performAction($aAccount['pd_profile_id']);
  114. }
  115. // perform action
  116. $this->_oModule->isAllowedDelete($aAccount, true);
  117. // create an alert
  118. bx_alert($this->_oModule->getName(), 'deleted', $aAccount['id']);
  119. // redirect
  120. $this->_redirectAndExit('page.php?i=sites-home');
  121. }
  122. }
  123. /** @} */