BxInvGridRequests.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 Invites Invites
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolModule');
  12. bx_import('BxTemplGrid');
  13. class BxInvGridRequests extends BxTemplGrid
  14. {
  15. protected $_sModule;
  16. protected $_oModule;
  17. public function __construct ($aOptions, $oTemplate = false)
  18. {
  19. parent::__construct ($aOptions, $oTemplate);
  20. $this->_sModule = 'bx_invites';
  21. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  22. }
  23. public function performActionInfo()
  24. {
  25. $aIds = bx_get('ids');
  26. if(!$aIds || !is_array($aIds)) {
  27. $this->_echoResultJson(array());
  28. exit;
  29. }
  30. $aRequest = $this->_oModule->_oDb->getRequests(array('type' => 'by_id', 'value' => (int)array_shift($aIds)));
  31. if(empty($aRequest) || !is_array($aRequest)){
  32. $this->_echoResultJson(array());
  33. exit;
  34. }
  35. bx_import('BxTemplFunctions');
  36. $sContent = BxTemplFunctions::getInstance()->transBox('bx-invites-info-popup', $this->_oModule->_oTemplate->getBlockRequestText($aRequest));
  37. $this->_echoResultJson(array('popup' => array('html' => $sContent)), true);
  38. }
  39. public function performActionInvite($aParams = array())
  40. {
  41. $iProfileId = $this->_oModule->getProfileId();
  42. $mixedAllowed = $this->_oModule->isAllowedInvite($iProfileId);
  43. if($mixedAllowed !== true) {
  44. $this->_echoResultJson(array('msg' => $mixedAllowed));
  45. exit;
  46. }
  47. $iAffected = 0;
  48. $aIds = bx_get('ids');
  49. if(!$aIds || !is_array($aIds)) {
  50. $this->_echoResultJson(array());
  51. exit;
  52. }
  53. $sText = _t('_bx_invites_msg_invitation');
  54. bx_import('BxDolForm');
  55. $oForm = BxDolForm::getObjectInstance($this->_oModule->_oConfig->getObject('form_request'), $this->_oModule->_oConfig->getObject('form_display_request_send'));
  56. $aIdsAffected = array ();
  57. foreach($aIds as $iId) {
  58. $aRequest = $this->_oModule->_oDb->getRequests(array('type' => 'by_id', 'value' => $iId));
  59. if(empty($aRequest) || !is_array($aRequest))
  60. continue;
  61. $mixedResult = $this->_oModule->invite(BX_INV_TYPE_FROM_SYSTEM, $aRequest['email'], $sText);
  62. if($mixedResult === false)
  63. continue;
  64. $this->_oModule->isAllowedInvite($iProfileId, true);
  65. $oForm->delete($iId);
  66. $aIdsAffected[] = $iId;
  67. $iAffected++;
  68. }
  69. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected, 'msg' => _t('_bx_invites_msg_invitation_sent', $iAffected)) : array('msg' => _t('_bx_invites_err_invite')));
  70. }
  71. public function performActionDelete($aParams = array())
  72. {
  73. $iProfileId = $this->_oModule->getProfileId();
  74. $mixedAllowed = $this->_oModule->isAllowedDeleteRequest($iProfileId);
  75. if($mixedAllowed !== true) {
  76. $this->_echoResultJson(array('msg' => $mixedAllowed));
  77. exit;
  78. }
  79. $iAffected = 0;
  80. $aIds = bx_get('ids');
  81. if(!$aIds || !is_array($aIds)) {
  82. $this->_echoResultJson(array());
  83. exit;
  84. }
  85. bx_import('BxDolForm');
  86. $oForm = BxDolForm::getObjectInstance($this->_oModule->_oConfig->getObject('form_request'), $this->_oModule->_oConfig->getObject('form_display_request_send'));
  87. $aIdsAffected = array ();
  88. foreach($aIds as $iId) {
  89. if(!$oForm->delete($iId))
  90. continue;
  91. $this->_oModule->isAllowedDeleteRequest($iProfileId, true);
  92. $aIdsAffected[] = $iId;
  93. $iAffected++;
  94. }
  95. $this->_echoResultJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_bx_invites_err_delete_request')));
  96. }
  97. protected function _getCellNip($mixedValue, $sKey, $aField, $aRow)
  98. {
  99. return parent::_getCellDefault(long2ip($mixedValue), $sKey, $aField, $aRow);
  100. }
  101. protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
  102. {
  103. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  104. }
  105. }
  106. /** @} */