BxInvGridInvites.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. define('BX_INV_FILTER_STATUS_ACCEPTED', 1);
  12. define('BX_INV_FILTER_STATUS_NOT_ACCEPTED', 2);
  13. class BxInvGridInvites extends BxTemplGrid
  14. {
  15. protected $_sModule;
  16. protected $_oModule;
  17. protected $_sFilter1Name;
  18. protected $_sFilter1Value;
  19. protected $_aFilter1Values;
  20. protected $_sParamsDivider;
  21. public function __construct ($aOptions, $oTemplate = false)
  22. {
  23. parent::__construct ($aOptions, $oTemplate);
  24. $this->_sModule = 'bx_invites';
  25. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  26. $this->_sFilter1Name = 'filter1';
  27. $this->_aFilter1Values = array(
  28. '' => _t('_bx_invites_invites_status_for_filter_all'),
  29. BX_INV_FILTER_STATUS_ACCEPTED => _t('_bx_invites_invites_status_for_filter_accepted'),
  30. BX_INV_FILTER_STATUS_NOT_ACCEPTED => _t('_bx_invites_invites_status_for_filter_not_accepted'),
  31. );
  32. $sFilter1 = bx_get($this->_sFilter1Name);
  33. if(!empty($sFilter1)) {
  34. $this->_sFilter1Value = bx_process_input($sFilter1);
  35. $this->_aQueryAppend['filter1'] = $this->_sFilter1Value;
  36. }
  37. $this->_sParamsDivider = '#-#';
  38. }
  39. protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
  40. {
  41. $CNF = $this->_oModule->_oConfig->CNF;
  42. $sTableInvites = $CNF['TABLE_INVITES'];
  43. if(strpos($sFilter, $this->_sParamsDivider) !== false)
  44. list($this->_sFilter1Value, $sFilter) = explode($this->_sParamsDivider, $sFilter);
  45. $sFilterSql = "";
  46. if(isset($this->_sFilter1Value) && $this->_sFilter1Value != ''){
  47. if ($this->_sFilter1Value == BX_INV_FILTER_STATUS_ACCEPTED){
  48. $sFilterSql = " AND " . $sTableInvites . ".`joined_account_id` IS NOT NULL";
  49. }
  50. else{
  51. $sFilterSql = " AND " . $sTableInvites . ".`joined_account_id` IS NULL";
  52. }
  53. }
  54. $this->_aOptions['source'] .= $this->_oModule->_oDb->prepareAsString($sFilterSql);
  55. return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);
  56. }
  57. public function performActionAdd()
  58. {
  59. $sAction = 'add';
  60. $oForm = $this->_oModule->getFormObjectInvite();
  61. if (!$oForm)
  62. return '';
  63. $oForm->aInputs['text']['value'] = _t('_bx_invites_msg_invitation');
  64. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r'));
  65. $oForm->initChecker();
  66. if($oForm->isSubmittedAndValid()) {
  67. $sResult = $this->_oModule->processFormObjectInvite($oForm);
  68. $aRes = array('msg' => $sResult);
  69. echoJson($aRes);
  70. }
  71. else {
  72. $sContent = BxTemplFunctions::getInstance()->popupBox('_bx_invites_form_invite', _t('_bx_invites_form_invite'), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', array(
  73. 'form_id' => $oForm->id,
  74. 'form' => $oForm->getCode(true),
  75. 'object' => $this->_sObject,
  76. 'action' => $sAction
  77. )));
  78. echoJson(array('popup' => array('html' => $sContent, 'options' => array('closeOnOuterClick' => true))));
  79. }
  80. }
  81. public function performActionDelete($aParams = array())
  82. {
  83. $iProfileId = $this->_oModule->getProfileId();
  84. $mixedAllowed = $this->_oModule->isAllowedDeleteInvite($iProfileId);
  85. if($mixedAllowed !== true) {
  86. echoJson(array('msg' => $mixedAllowed));
  87. exit;
  88. }
  89. $iAffected = 0;
  90. $aIds = bx_get('ids');
  91. if(!$aIds || !is_array($aIds)) {
  92. echoJson(array());
  93. exit;
  94. }
  95. $aIdsAffected = array ();
  96. foreach($aIds as $iId) {
  97. if(!$this->_oModule->_oDb->deleteInvites(array('id' => $iId)))
  98. continue;
  99. $this->_oModule->isAllowedDeleteInvite($iProfileId, true);
  100. $aIdsAffected[] = $iId;
  101. $iAffected++;
  102. }
  103. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t('_bx_invites_err_delete_invite')));
  104. }
  105. protected function _getFilterControls ()
  106. {
  107. parent::_getFilterControls();
  108. return $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
  109. }
  110. protected function _getSearchInput()
  111. {
  112. $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
  113. $aInputSearch = array(
  114. 'type' => 'text',
  115. 'name' => 'search',
  116. 'attrs' => array(
  117. 'id' => 'bx-grid-search-' . $this->_sObject,
  118. 'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter(this)',
  119. 'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter(this)',
  120. )
  121. );
  122. $oForm = new BxTemplFormView(array());
  123. return $oForm->genRow($aInputSearch);
  124. }
  125. protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
  126. {
  127. if(empty($sFilterName) || empty($aFilterValues))
  128. return '';
  129. $CNF = &$this->_oModule->_oConfig->CNF;
  130. $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
  131. foreach($aFilterValues as $sKey => $sValue)
  132. $aFilterValues[$sKey] = _t($sValue);
  133. $aInputModules = array(
  134. 'type' => 'select',
  135. 'name' => $sFilterName,
  136. 'attrs' => array(
  137. 'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
  138. 'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
  139. ),
  140. 'value' => $sFilterValue,
  141. 'values' => $aFilterValues
  142. );
  143. $oForm = new BxTemplFormView(array());
  144. return $oForm->genRow($aInputModules);
  145. }
  146. protected function _getCellDate($mixedValue, $sKey, $aField, $aRow)
  147. {
  148. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  149. }
  150. protected function _getCellDateSeen($mixedValue, $sKey, $aField, $aRow)
  151. {
  152. if ($mixedValue == 'undefined')
  153. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  154. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  155. }
  156. protected function _getCellDateJoined($mixedValue, $sKey, $aField, $aRow)
  157. {
  158. if ($mixedValue == 'undefined')
  159. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  160. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  161. }
  162. protected function _getCellWhoSend($mixedValue, $sKey, $aField, $aRow)
  163. {
  164. $oProfile = BxDolProfile::getInstanceMagic($aRow['profile_id']);
  165. if ($oProfile)
  166. return $this->_getProfileCell($oProfile, $sKey, $aField, $aRow);
  167. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  168. }
  169. protected function _getCellJoinedAccount($mixedValue, $sKey, $aField, $aRow)
  170. {
  171. if ($aRow['joined_account_id'] == '')
  172. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  173. $oProfile = BxDolProfile::getInstanceAccountProfile($aRow['joined_account_id']);
  174. if ($oProfile)
  175. return $this->_getProfileCell($oProfile, $sKey, $aField, $aRow);
  176. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  177. }
  178. protected function _getCellRequest($mixedValue, $sKey, $aField, $aRow)
  179. {
  180. if ($aRow['request_id'] == '')
  181. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  182. $aRequest = $this->_oModule->_oDb->getRequests(array('type' => 'by_id', 'value' => $aRow['request_id']));
  183. if ($aRequest || true){
  184. $CNF = &$this->_oModule->_oConfig->CNF;
  185. $sLink = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_REQUESTS']));
  186. $sLink = bx_append_url_params($sLink, array('filter' => $aRequest['email']));
  187. $sAddon = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  188. 'href' => $sLink,
  189. 'title' => _t('_bx_invites_grid_txt_view_request'),
  190. 'content' => _t('_bx_invites_grid_txt_view_request'),
  191. 'class' => ''
  192. ));
  193. return parent::_getCellDefault($sAddon, $sKey, $aField, $aRow);
  194. }
  195. return parent::_getCellDefault('', $sKey, $aField, $aRow);
  196. }
  197. protected function _getProfileCell($oProfile, $sKey, $aField, $aRow)
  198. {
  199. $sProfile = $oProfile->getDisplayName();
  200. $oAcl = BxDolAcl::getInstance();
  201. $sAccountEmail = '';
  202. $sManageAccountUrl = '';
  203. if($oProfile && $oProfile instanceof BxDolProfile && $oAcl->isMemberLevelInSet(128)) {
  204. $sAccountEmail = $oProfile->getAccountObject()->getEmail();
  205. $sManageAccountUrl = $this->_getManageAccountUrl($sAccountEmail);
  206. }
  207. $sAddon = '';
  208. if(!empty($sManageAccountUrl))
  209. $sAddon = $this->_oTemplate->parseHtmlByName('account_link.html', array(
  210. 'href' => $sManageAccountUrl,
  211. 'title' => _t('_bx_invites_grid_txt_account_manager'),
  212. 'content' => $sAccountEmail,
  213. 'class' => 'bx-def-font-grayed'
  214. ));
  215. $mixedValue = $oProfile->getUnit(0, array('template' => array('vars' => array('addon' => $sAddon))));
  216. return parent::_getCellDefault($mixedValue, $sKey, $aField, $aRow);
  217. }
  218. protected function _getManageAccountUrl($sFilter = '')
  219. {
  220. $sModuleAccounts = 'bx_accounts';
  221. if(!BxDolModuleQuery::getInstance()->isEnabledByName($sModuleAccounts))
  222. return '';
  223. $oModuleAccounts = BxDolModule::getInstance($sModuleAccounts);
  224. if(!$oModuleAccounts || empty($oModuleAccounts->_oConfig->CNF['URL_MANAGE_ADMINISTRATION']))
  225. return 'cccc';
  226. $sLink = $oModuleAccounts->_oConfig->CNF['URL_MANAGE_ADMINISTRATION'];
  227. $sLink = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($sLink));
  228. if(!empty($sFilter))
  229. $sLink = bx_append_url_params($sLink, array('filter' => $sFilter));
  230. return $sLink;
  231. }
  232. }
  233. /** @} */