BxInvGridRequests.php 3.9 KB

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