BxAccntGridAdministration.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 Accounts Accounts
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxAccntGridAdministration extends BxBaseModProfileGridAdministration
  12. {
  13. public function __construct ($aOptions, $oTemplate = false)
  14. {
  15. $this->MODULE = 'bx_accounts';
  16. parent::__construct ($aOptions, $oTemplate);
  17. $this->_aQueryReset = array('order_field', 'order_dir', $this->_aOptions['paginate_get_start'], $this->_aOptions['paginate_get_per_page']);
  18. }
  19. public function getCode($isDisplayHeader = true)
  20. {
  21. return $this->_oModule->_oTemplate->getJsCode('main', array(
  22. 'aHtmlIds' => $this->_oModule->_oConfig->getHtmlIds()
  23. )) . parent::getCode($isDisplayHeader);
  24. }
  25. public function performActionActivate()
  26. {
  27. $this->_performActionEnable(true);
  28. }
  29. public function performActionSuspend()
  30. {
  31. $this->_performActionEnable(false);
  32. }
  33. public function performActionEditEmail()
  34. {
  35. $CNF = &$this->_oModule->_oConfig->CNF;
  36. $aIds = bx_get('ids');
  37. if(!$aIds || !is_array($aIds)) {
  38. $iId = (int)bx_get('id');
  39. if(!$iId)
  40. return echoJson(array());
  41. $aIds = array($iId);
  42. }
  43. $iId = $aIds[0];
  44. $oAccount = BxDolAccount::getInstance($iId);
  45. if(!$oAccount)
  46. return echoJson(array());
  47. $aAccount = $oAccount->getInfo();
  48. $sAction = 'edit_email';
  49. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ACCOUNT'], $CNF['OBJECT_FORM_ACCOUNT_DISPLAY_SETTINGS_EMAIL']);
  50. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?o=' . $this->_sObject . '&a=' . $sAction . '&id=' . $iId;
  51. $oForm->initChecker($aAccount);
  52. if($oForm->isSubmittedAndValid()) {
  53. $sEmail = $oForm->getCleanValue('email');
  54. if(strcmp($aAccount['email'], $sEmail) !== 0 && BxDolAccountQuery::getInstance()->getIdByEmail($sEmail))
  55. return echoJson(array('msg' => _t('_sys_form_account_input_email_uniq_error_loggedin')));
  56. if($oForm->update($aAccount['id'])) {
  57. bx_alert('account', 'edited', $aAccount['id'], BxDolAccount::getInstance()->id(), array('display' => $CNF['OBJECT_FORM_ACCOUNT_DISPLAY_SETTINGS_EMAIL']));
  58. $aRes = array('grid' => $this->getCode(false), 'blink' => $iId);
  59. }
  60. else
  61. $aRes = array('msg' => _t('_sys_txt_error_account_update'));
  62. echoJson($aRes);
  63. }
  64. else {
  65. $sContent = BxTemplStudioFunctions::getInstance()->popupBox('bx-account-edit-email-popup', _t('_bx_accounts_form_display_account_settings_email_popup'), $this->_oModule->_oTemplate->parseHtmlByName('edit_email.html', array(
  66. 'form_id' => $oForm->id,
  67. 'form' => $oForm->getCode(true),
  68. 'object' => $this->_sObject,
  69. 'action' => $sAction
  70. )));
  71. echoJson(array('popup' => array('html' => $sContent, 'options' => array())));
  72. }
  73. }
  74. public function performActionResendCemail()
  75. {
  76. $CNF = &$this->_oModule->_oConfig->CNF;
  77. $aIds = bx_get('ids');
  78. if(!$aIds || !is_array($aIds)) {
  79. echoJson(array());
  80. return;
  81. }
  82. $oAccount = BxDolAccount::getInstance();
  83. $iAffected = 0;
  84. $aIdsAffected = array();
  85. foreach($aIds as $iId)
  86. if($oAccount->sendConfirmationEmail($iId)) {
  87. $aIdsAffected[] = $iId;
  88. $iAffected++;
  89. }
  90. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_perform'])));
  91. }
  92. public function performActionResetPassword()
  93. {
  94. $aIds = bx_get('ids');
  95. if(!$aIds || !is_array($aIds)) {
  96. echoJson(array());
  97. return;
  98. }
  99. $iId = $aIds[0];
  100. $oAccount = BxDolAccount::getInstance($iId);
  101. if(!$oAccount)
  102. return echoJson(array());
  103. $sPwd = genRndPwd();
  104. $sSalt = genRndSalt();
  105. $sPasswordHash = encryptUserPwd($sPwd, $sSalt);
  106. $aRes = array();
  107. if((int)BxDolAccountQuery::getInstance()->updatePassword($sPasswordHash, $sSalt, $iId) > 0) {
  108. bx_alert('account', 'edited', $iId, BxDolAccount::getInstance()->id(), array('action' => 'reset_password'));
  109. $sPopupId = $this->_oModule->_oConfig->getHtmlIds('password_popup');
  110. $sPopupTitle = _t('_bx_accounts_form_display_account_settings_password_popup');
  111. $sPopupContent = $this->_oModule->_oTemplate->parseHtmlByName('reset_password.html', array(
  112. 'js_object' => $this->_oModule->_oConfig->getJsObject('main'),
  113. 'html_id_text' => $this->_oModule->_oConfig->getHtmlIds('password_text'),
  114. 'html_id_button' => $this->_oModule->_oConfig->getHtmlIds('password_button'),
  115. 'password' => $sPwd,
  116. ));
  117. $aRes = array('popup' => BxTemplStudioFunctions::getInstance()->popupBox($sPopupId, $sPopupTitle, $sPopupContent));
  118. }
  119. else
  120. $aRes = array('msg' => _t('_bx_accnt_grid_action_err_perform'));
  121. return echoJson($aRes);
  122. }
  123. public function performActionMakeOperator()
  124. {
  125. $this->_performActionChangeRole(3);
  126. }
  127. public function performActionUnmakeOperator()
  128. {
  129. $this->_performActionChangeRole(1);
  130. }
  131. protected function _performActionChangeRole($iRole)
  132. {
  133. $CNF = &$this->_oModule->_oConfig->CNF;
  134. $aIds = bx_get('ids');
  135. if(!$aIds || !is_array($aIds)) {
  136. echoJson(array());
  137. return;
  138. }
  139. $iAffected = 0;
  140. $aIdsAffected = array();
  141. foreach($aIds as $iId)
  142. if($this->_oModule->_oDb->updateAccount(array('role' => $iRole), array('id' => $iId))) {
  143. $aIdsAffected[] = $iId;
  144. $iAffected++;
  145. }
  146. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_perform'])));
  147. }
  148. protected function _performActionEnable($isChecked)
  149. {
  150. $CNF = &$this->_oModule->_oConfig->CNF;
  151. $aIds = bx_get('ids');
  152. if(!$aIds || !is_array($aIds)) {
  153. echoJson(array());
  154. return;
  155. }
  156. $iAffected = 0;
  157. $aIdsAffected = array();
  158. foreach($aIds as $iId)
  159. if($this->_enable($iId, $isChecked)) {
  160. $aIdsAffected[] = $iId;
  161. $iAffected++;
  162. }
  163. echoJson($iAffected ? array('grid' => $this->getCode(false), 'blink' => $aIdsAffected) : array('msg' => _t($CNF['T']['grid_action_err_perform'])));
  164. }
  165. protected function _enable($mixedId, $isChecked)
  166. {
  167. $oProfile = BxDolProfile::getInstanceAccountProfile($mixedId);
  168. if(!$oProfile)
  169. return false;
  170. $iAction = BX_PROFILE_ACTION_MANUAL;
  171. $sMethod = $isChecked ? 'activate' : 'suspend';
  172. if(!$oProfile->$sMethod($iAction))
  173. return false;
  174. $aProfiles = $oProfile->getAccountObject()->getProfiles();
  175. foreach($aProfiles as $aProfile)
  176. BxDolProfile::getInstance($aProfile['id'])->$sMethod($iAction);
  177. return true;
  178. }
  179. //--- Layout methods ---//
  180. protected function _getActionEditEmail($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  181. {
  182. return '';
  183. }
  184. protected function _getCellEmailConfirmed($mixedValue, $sKey, $aField, $aRow)
  185. {
  186. $mixedValue = (int)$mixedValue == 1 ? '_Yes' : '_No';
  187. return parent::_getCellDefault(_t($mixedValue), $sKey, $aField, $aRow);
  188. }
  189. protected function _getActionResetPassword($sType, $sKey, $a, $isSmall = false, $isDisabled = false, $aRow = array())
  190. {
  191. return '';
  192. }
  193. protected function _getCellName($mixedValue, $sKey, $aField, $aRow)
  194. {
  195. $oAccount = BxDolAccount::getInstance($aRow['id']);
  196. if ($oAccount)
  197. $s = $oAccount->getDisplayName();
  198. return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
  199. }
  200. protected function _getCellProfiles($mixedValue, $sKey, $aField, $aRow)
  201. {
  202. $s = $this->_oModule->_oTemplate->getProfilesByAccount($aRow);
  203. return parent::_getCellDefault ($s, $sKey, $aField, $aRow);
  204. }
  205. protected function _getCellLogged($mixedValue, $sKey, $aField, $aRow)
  206. {
  207. return parent::_getCellDefault(bx_time_js($mixedValue), $sKey, $aField, $aRow);
  208. }
  209. protected function _getCellIsConfirmed($mixedValue, $sKey, $aField, $aRow)
  210. {
  211. $oAccount = BxDolAccount::getInstance($aRow['id']);
  212. $s = "";
  213. if ($oAccount)
  214. $s = $oAccount->ConfirmationStatus();
  215. return parent::_getCellDefault(_t('_bx_accnt_grid_confirmation_status_' . $s), $sKey, $aField, $aRow);
  216. }
  217. protected function _isCheckboxDisabled($aRow)
  218. {
  219. return false;
  220. }
  221. protected function _getContentInfo($iId)
  222. {
  223. return BxDolAccountQuery::getInstance()->getInfoById($iId);
  224. }
  225. protected function _doDelete($iId, $aParams = array())
  226. {
  227. return BxDolAccount::getInstance($iId)->delete(isset($aParams['with_content']) && $aParams['with_content'] === true);
  228. }
  229. protected function _addJsCss()
  230. {
  231. parent::_addJsCss();
  232. $this->_oTemplate->addJs(array(
  233. 'main.css'
  234. ));
  235. $this->_oTemplate->addJs(array(
  236. 'jquery.form.min.js',
  237. 'clipboard.min.js',
  238. 'main.js'
  239. ));
  240. }
  241. protected function _isVisibleGrid($a)
  242. {
  243. if(isAdmin())
  244. return true;
  245. return parent::_isVisibleGrid($a);
  246. }
  247. }
  248. /** @} */