BxInvGridInvites.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. require_once('BxInvGrid.php');
  12. define('BX_INV_FILTER_STATUS_ACCEPTED', 1);
  13. define('BX_INV_FILTER_STATUS_NOT_ACCEPTED', 2);
  14. class BxInvGridInvites extends BxInvGrid
  15. {
  16. public function __construct ($aOptions, $oTemplate = false)
  17. {
  18. parent::__construct ($aOptions, $oTemplate);
  19. $this->_sDefaultSortingOrder = 'DESC';
  20. $this->_sFilter1Name = 'filter1';
  21. $this->_aFilter1Values = array(
  22. '' => _t('_bx_invites_invites_status_for_filter_all'),
  23. BX_INV_FILTER_STATUS_ACCEPTED => _t('_bx_invites_invites_status_for_filter_accepted'),
  24. BX_INV_FILTER_STATUS_NOT_ACCEPTED => _t('_bx_invites_invites_status_for_filter_not_accepted'),
  25. );
  26. $sFilter1 = bx_get($this->_sFilter1Name);
  27. if(!empty($sFilter1)) {
  28. $this->_sFilter1Value = bx_process_input($sFilter1);
  29. $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
  30. }
  31. }
  32. public function performActionDelete($aParams = array())
  33. {
  34. $iProfileId = $this->_oModule->getProfileId();
  35. $mixedAllowed = $this->_oModule->isAllowedDeleteInvite($iProfileId);
  36. if($mixedAllowed !== true) {
  37. echoJson(array('msg' => $mixedAllowed));
  38. exit;
  39. }
  40. $iAffected = 0;
  41. $aIds = bx_get('ids');
  42. if(!$aIds || !is_array($aIds)) {
  43. echoJson(array());
  44. exit;
  45. }
  46. $aIdsAffected = array ();
  47. foreach($aIds as $iId) {
  48. if(!$this->_oModule->_oDb->deleteInvites(array('id' => $iId)))
  49. continue;
  50. $this->_oModule->isAllowedDeleteInvite($iProfileId, true);
  51. $aIdsAffected[] = $iId;
  52. $iAffected++;
  53. }
  54. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_bx_invites_err_delete_invite')));
  55. }
  56. protected function _getCellEmail($mixedValue, $sKey, $aField, $aRow)
  57. {
  58. if((int)$aRow['email_use'] != 0) {
  59. $sTitle = bx_html_attribute(_t('_bx_invites_txt_email_use'));
  60. $mixedValue .= $this->_oModule->_oTemplate->parseIconInline('ui-alert.svg', ['alt' => $sTitle, 'title' => $sTitle]);
  61. }
  62. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  63. }
  64. protected function _getCellMulti($mixedValue, $sKey, $aField, $aRow)
  65. {
  66. return parent::_getCellDefault(_t((int)$mixedValue != 0 ? '_Yes' : '_No'), $sKey, $aField, $aRow);
  67. }
  68. protected function _getCellAj($mixedValue, $sKey, $aField, $aRow)
  69. {
  70. switch($aRow['aj_action']) {
  71. case 'redirect':
  72. $mixedValue = $this->_getAjLink($aRow['aj_action'], BxDolPermalinks::getInstance()->permalink($aRow['aj_params']));
  73. break;
  74. case 'invite_to_context':
  75. $mixedValue = '#';
  76. if(($oContext = BxDolProfile::getInstanceMagic((int)$aRow['aj_params'])) !== false)
  77. $mixedValue = $oContext->getUrl();
  78. $mixedValue = $this->_getAjLink($aRow['aj_action'], $mixedValue);
  79. break;
  80. default:
  81. $mixedValue = '';
  82. }
  83. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  84. }
  85. protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
  86. {
  87. if($this->_bIsApi)
  88. return ['type' => 'time', 'data' => (int)$mixedValue];
  89. return parent::_getCellDefault($mixedValue && $mixedValue != 'undefined' ? bx_time_js($mixedValue) : '', $sKey, $aField, $aRow);
  90. }
  91. protected function _getCellDateSeen($mixedValue, $sKey, $aField, $aRow)
  92. {
  93. return $this->_getCellDate($mixedValue, $sKey, $aField, $aRow);
  94. }
  95. protected function _getCellDateJoined($mixedValue, $sKey, $aField, $aRow)
  96. {
  97. return $this->_getCellDate($mixedValue, $sKey, $aField, $aRow);
  98. }
  99. protected function _getCellWhoSend($mixedValue, $sKey, $aField, $aRow)
  100. {
  101. if(($oProfile = BxDolProfile::getInstanceMagic($aRow['profile_id'])) !== false) {
  102. if ($this->_bIsApi)
  103. return ['type' => 'profile', 'data' => BxDolProfile::getData($aRow['profile_id'])];
  104. return $this->_getProfileCell($oProfile, $sKey, $aField, $aRow);
  105. }
  106. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  107. }
  108. protected function _getCellJoinedAccount($mixedValue, $sKey, $aField, $aRow)
  109. {
  110. if(($iAccountId = (int)$aRow['joined_account_id']) != 0 && ($oProfile = BxDolProfile::getInstanceAccountProfile($iAccountId)) !== false) {
  111. if($this->_bIsApi)
  112. return ['type' => 'profile', 'data' => BxDolProfile::getData($oProfile)];
  113. return $this->_getProfileCell($oProfile, $sKey, $aField, $aRow);
  114. }
  115. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  116. }
  117. protected function _getCellRequest($mixedValue, $sKey, $aField, $aRow)
  118. {
  119. $CNF = &$this->_oModule->_oConfig->CNF;
  120. if($aRow['request_id'] == '')
  121. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  122. $aRequest = $this->_oModule->_oDb->getRequests(['type' => 'by_id', 'value' => $aRow['request_id']]);
  123. if(!empty($aRequest) && is_array($aRequest)) {
  124. $sTitle = _t('_bx_invites_grid_txt_view_request');
  125. $sLink = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_REQUESTS'], ['filter' => $aRequest['email']]));
  126. if($this->_bIsApi)
  127. return ['type' => 'link', 'data' => ['url' => bx_api_get_relative_url($sLink), 'text' => $sTitle]];
  128. $sAddon = $this->_oTemplate->parseHtmlByName('account_link.html', [
  129. 'href' => $sLink,
  130. 'title' => bx_html_attribute($sTitle),
  131. 'content' => $sTitle,
  132. 'class' => ''
  133. ]);
  134. return parent::_getCellDefault($sAddon, $sKey, $aField, $aRow);
  135. }
  136. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  137. }
  138. protected function _getProfileCell($oProfile, $sKey, $aField, $aRow)
  139. {
  140. $sProfile = $oProfile->getDisplayName();
  141. $oAcl = BxDolAcl::getInstance();
  142. $sAccountEmail = '';
  143. $sManageAccountUrl = '';
  144. if($oProfile && $oProfile instanceof BxDolProfile && $oAcl->isMemberLevelInSet(128) && $oProfile->getAccountObject()) {
  145. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  146. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  147. }
  148. $sAddon = '';
  149. if(!empty($sManageAccountUrl))
  150. $sAddon = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  151. 'href' => $sManageAccountUrl,
  152. 'title' => _t('_bx_invites_grid_txt_account_manager'),
  153. 'content' => $sAccountEmail,
  154. 'class' => 'bx-def-font-grayed'
  155. ));
  156. $mixedValue = $oProfile->getUnit(0, array('template' => array('vars' => array('addon' => $sAddon))));
  157. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  158. }
  159. protected function _getManageAccountUrl($sFilter = '')
  160. {
  161. $sModuleAccounts = 'bx_accounts';
  162. if(!BxDolModuleQuery::getInstance()->isEnabledByName($sModuleAccounts))
  163. return '';
  164. $oModuleAccounts = BxDolModule::getInstance($sModuleAccounts);
  165. if(!$oModuleAccounts || empty($oModuleAccounts->_oConfig->CNF['URL_MANAGE_ADMINISTRATION']))
  166. return 'cccc';
  167. $sLink = $oModuleAccounts->_oConfig->CNF['URL_MANAGE_ADMINISTRATION'];
  168. $sLink = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($sLink));
  169. if(!empty($sFilter))
  170. $sLink = bx_append_url_params($sLink, array('filter' => $sFilter));
  171. return $sLink;
  172. }
  173. protected function _getAjLink($sAction, $sLink)
  174. {
  175. return $this->_oModule->_oTemplate->parseHtmlByName('invite_aj_link.html', [
  176. 'href' => $sLink,
  177. 'content' => _t('_bx_invites_invites_aj_' . $sAction)
  178. ]);
  179. }
  180. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  181. {
  182. $CNF = $this->_oModule->_oConfig->CNF;
  183. $sTableInvites = $CNF['TABLE_INVITES'];
  184. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  185. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  186. $sFilterSql = "";
  187. if(isset($this->_sFilter1Value) && $this->_sFilter1Value != ''){
  188. if ($this->_sFilter1Value == BX_INV_FILTER_STATUS_ACCEPTED){
  189. $sFilterSql = " AND " . $sTableInvites . ".`joined_account_id` IS NOT NULL";
  190. }
  191. else{
  192. $sFilterSql = " AND " . $sTableInvites . ".`joined_account_id` IS NULL";
  193. }
  194. }
  195. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString($sFilterSql);
  196. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  197. }
  198. }
  199. /** @} */