scope('my', _t('@internalmail', 'Personal Messages')) ->methods(['listing','conv','ajax']) ->scope('users:users') ->method('listing') ->scope('spy', _t('@internalmail', 'Users Messaging View')) ->methods(['spy_lenta','spy_listing','spy_conv']) ; } /** * Список личных сообщений * @return string|mixed */ public function listing() { if (!($this->haveAccessTo('my') || $this->haveAccessTo('users-edit', 'users'))) { return $this->showAccessDenied(); } $userID = User::id(); $folderID = $this->input->getpost('f', TYPE_UINT); if (!$folderID) { $folderID = static::FOLDER_ALL; } if (!$this->foldersEnabled()) { $folderID = -1; } $listingUrl = __FUNCTION__ . '&f=' . $folderID; $data = ['f' => $folderID]; if ($this->isPOST()) { switch ($this->input->post('act', TYPE_STR)) { case 'send': # отправка сообщения { $recipientID = $this->input->post('recipient', TYPE_UINT); if (!$recipientID) { $this->errors->set(_t('@internalmail', 'Enter the recipient of the message'), 'recipient'); } $message = $this->model->cleanMessage($this->input->post('message', TYPE_STR)); if (!$message) { $this->errors->set(_t('@internalmail', 'Message text not specified'), 'message'); } if ($this->errors->no()) { $res = $this->model->sendMessage($userID, $recipientID, $message, ['attach' => $this->attachUpload()], ['minusWords' => false]); return $this->adminRedirect(($res ? Errors::SUCCESS : Errors::IMPOSSIBLE), $listingUrl); } } break; } } $total = $this->model->getContactsListingAdm($userID, 0, $folderID, true); $pages = new Pagination($total, 8, $this->adminLink($listingUrl . '&page=' . Pagination::PAGE_ID)); $data['contacts'] = $this->model->getContactsListingAdm($userID, 0, $folderID, false, $pages->getLimitOffset()); if (!empty($data['contacts'])) { foreach ($data['contacts'] as $k => $v) { $data['contacts'][$k]['avatar'] = UsersAvatar::url($v['user_id'], $v['avatar']); } } $data['pgn'] = $pages->view(); if ($this->foldersEnabled()) { $data['folders'] = $this->getFolders(); } return $this->template('admin/listing', $data); } /** * Просмотр личной переписки * @return string|mixed */ public function conv() { if (!$this->haveAccessTo('my')) { return $this->showAccessDenied(); } $listingUrl = 'listing&f=' . $this->input->get('f', TYPE_UINT); $userID = User::id(); $interlocutorID = $this->input->getpost('i', TYPE_UINT); $companyId = $this->input->getpost('company', TYPE_UINT); if (!$interlocutorID) { return $this->adminRedirect(Errors::IMPOSSIBLE, $listingUrl); } $data = ['admin' => true]; if ($this->isPOST() && !$this->isAJAX()) { $data['message'] = $this->model->cleanMessage($this->input->post('message', TYPE_STR)); if (!$data['message']) { $this->errors->set(_t('@internalmail', 'Message text not specified')); } if ($this->errors->no()) { $res = $this->model->sendMessage($userID, $interlocutorID, $data['message'], ['company_id' => $companyId, 'attach' => $this->attachUpload()], ['minusWords' => false]); return $this->adminRedirect(($res ? Errors::SUCCESS : Errors::IMPOSSIBLE), $listingUrl); } } $data['name'] = User::data('name'); $data['company_id'] = $companyId; $fields = [ 'user_id as id','name','email','login','avatar', 'im_noreply','blocked','admin','activated', ]; $data['i'] = Users::model()->userData($interlocutorID, $fields); if (empty($data['i'])) { return $this->adminRedirect(Errors::IMPOSSIBLE, $listingUrl); } $data['me'] = Users::model()->userData($userID, $fields); $data['i']['avatar'] = UsersAvatar::url($data['i']['id'], $data['i']['avatar']); $data['me']['avatar'] = UsersAvatar::url($data['me']['id'], $data['me']['avatar']); $total = $this->model->getConversationMessages($userID, $interlocutorID, $companyId, true); $pages = new Pagination($total, 10, '#'); $data['list'] = $this->model->getConversationMessages($userID, $interlocutorID, $companyId, false, $pages->getLimitOffset()); $data['list'] = $this->template('admin/conv.ajax', $data); $data['pgn'] = $pages->view([ 'pages.attr' => ['class' => 'j-page', 'data-page' => Pagination::PAGE_ID], 'arrows.attr' => ['class' => 'j-page', 'data-page' => Pagination::PAGE_ID], ]); if ($this->isAJAX()) { return $this->ajaxResponse([ 'list' => $data['list'], 'pgn' => $data['pgn'], ]); } $data['i']['avatar'] = UsersAvatar::url($interlocutorID, $data['i']['avatar']); # отмечаем как прочитанные все новые сообщения, в которых пользователь является получателем $this->model->setMessagesReaded($userID, $interlocutorID, $companyId); $data['ignored'] = (!$data['admin'] && $this->foldersEnabled() && $this->model->isUserInFolder($userID, $interlocutorID, $companyId, static::FOLDER_IGNORE)); $data['total'] = $total; $data['list_url'] = $this->adminLink($listingUrl); return $this->template('admin/conv', $data); } /** * Лента сообщений пользователей * @return string|mixed */ public function spy_lenta() { if (!$this->haveAccessTo('spy')) { return $this->showAccessDenied(); } # фильтр: пользователь $userID = $this->input->getpost('u', TYPE_UINT); if ($userID > 0) { $userData = Users::model()->userData($userID, ['user_id as id', 'email']); } if (empty($userData)) { $userID = 0; $userData = ['id' => 0, 'email' => '']; } $data['user'] = $userData; $total = $this->model->getMessagesSpyLenta($userID, true); $pages = new Pagination($total, 15, '#'); $data['list'] = $this->model->getMessagesSpyLenta($userID, false, $pages->getLimitOffset()); foreach ($data['list'] as &$v) { $v['from_avatar'] = UsersAvatar::url($v['from_id'], $v['from_avatar'], null, $v['from_sex']); $v['to_avatar'] = UsersAvatar::url($v['to_id'], $v['to_avatar'], null, $v['to_sex']); } unset($v); $data['list'] = $this->template('admin/spy.lenta.ajax', $data); $data['pgn'] = $pages->view([ 'pages.attr' => ['class' => 'j-page', 'data-page' => Pagination::PAGE_ID], 'arrows.attr' => ['class' => 'j-page', 'data-page' => Pagination::PAGE_ID], ]); if ($this->isAJAX()) { return $this->ajaxResponse([ 'list' => $data['list'], 'pgn' => $data['pgn'], ]); } return $this->template('admin/spy.lenta', $data); } /** * Список сообщений пользователя * @return string */ public function spy_listing() { if (!$this->haveAccessTo('spy')) { return $this->showAccessDenied(); } $folderID = -1; $userID = $this->input->get('u', TYPE_UINT); $companyId = $this->input->get('company', TYPE_UINT); if ($userID > 0) { $userData = Users::model()->userData($userID, ['user_id as id', 'email']); } if (empty($userData)) { $userID = 0; $userData = ['id' => 0, 'email' => '']; } $data = []; $total = $this->model->getContactsListingAdm($userID, $companyId, $folderID, true); $pages = new Pagination($total, 10, $this->adminLink('spy_listing&page=' . Pagination::PAGE_ID . '&u=' . $userID)); $data['contacts'] = $this->model->getContactsListingAdm($userID, $companyId, $folderID, false, $pages->getLimitOffset()); if (!empty($data['contacts'])) { foreach ($data['contacts'] as $k => $v) { $data['contacts'][$k]['avatar'] = UsersAvatar::url($v['user_id'], $v['avatar']); } } $data['pgn'] = $pages->view(); $data['page'] = $pages->getCurrentPage(); $data['folders'] = $this->getFolders(); $data['user'] = $userData; return $this->template('admin/spy.listing', $data); } /** * Просмотр переписки пользователя * @return string|mixed */ public function spy_conv() { if (!$this->haveAccessTo('spy')) { return $this->showAccessDenied(); } $userID = $this->input->get('u', TYPE_UINT); $companyId = $this->input->get('company', TYPE_UINT); $listingUrl = 'spy_listing&u=' . $userID . '&company=' . $companyId; $data = []; $data['u'] = Users::model()->userData($userID, [ 'user_id as id','name','email', 'login','avatar','activated', ]); if (empty($data['u'])) { return $this->adminRedirect(Errors::IMPOSSIBLE, $listingUrl); } $data['u']['avatar'] = UsersAvatar::url($data['u']['id'], $data['u']['avatar']); $interlocutorID = $this->input->get('i', TYPE_UINT); if (!$interlocutorID) { return $this->adminRedirect(Errors::IMPOSSIBLE, $listingUrl); } $data['i'] = Users::model()->userData($interlocutorID, [ 'user_id as id','name','email','login','avatar', 'im_noreply','blocked','admin','activated', ]); if (empty($data['i'])) { return $this->adminRedirect(Errors::IMPOSSIBLE, $listingUrl); } $data['i']['avatar'] = UsersAvatar::url($data['i']['id'], $data['i']['avatar']); $total = $this->model->getConversationMessages($userID, $interlocutorID, $companyId, true); $pages = new Pagination($total, 10, '#'); $data['list'] = $this->model->getConversationMessages($userID, $interlocutorID, $companyId, false, $pages->getLimitOffset()); $data['list'] = $this->template('admin/spy.conv.ajax', $data); $data['pgn'] = $pages->view([ 'pages.attr' => ['class' => 'j-page', 'data-page' => Pagination::PAGE_ID], 'arrows.attr' => ['class' => 'j-page', 'data-page' => Pagination::PAGE_ID], ]); if ($this->isAJAX()) { return $this->ajaxResponse([ 'list' => $data['list'], 'pgn' => $data['pgn'], ]); } $data['u']['avatar'] = UsersAvatar::url($userID, $data['u']['avatar']); $data['i']['avatar'] = UsersAvatar::url($interlocutorID, $data['i']['avatar']); $data['total'] = $total; $data['list_url'] = $this->adminLink($listingUrl); return $this->template('admin/spy.conv', $data); } /** * Обработчик ajax действий * @return \bff\http\Response */ public function ajax() { if (!$this->haveAccessTo('my')) { return $this->ajaxResponse(Errors::ACCESSDENIED); } $userID = User::id(); $response = []; $action = $this->input->postget('act', TYPE_STR); switch ($action) { case 'recipients': # autocomplete { $query = $this->input->post('q', TYPE_STR); $query = $this->input->cleanSearchString($query, 100); $recipientsList = $this->model->suggestInterlocutors($query, $userID); return $this->autocompleteResponse($recipientsList, 'id', 'email', 'ac'); } case 'move2folder': { $interlocutorID = $this->input->postget('iid', TYPE_UINT); $companyId = $this->input->postget('company', TYPE_UINT); $folderID = $this->input->postget('fid', TYPE_UINT); if (!$this->foldersEnabled() || !$interlocutorID || !$folderID) { $this->errors->impossible(); break; } $response['added'] = $this->model->interlocutorToFolder($userID, $interlocutorID, $companyId, $folderID); } break; case 'toggle-blocked': # блокировка / снятие блокировки { $messageID = $this->input->postget('id', TYPE_UINT); if (! $messageID) { $this->errors->unknownRecord(); break; } $this->model->messageToggle($messageID, 'blocked'); } break; case 'block-all': # блокировка всех сообщений пользователя { $userBlockID = $this->input->post('u', TYPE_UINT); if (!$userBlockID) { $this->errors->reloadPage(); break; } $response['total'] = $this->model->blockUserMessages($userBlockID); $response['message'] = tpl::declension($response['total'], _t('@internalmail', 'message;messages;messages')); $response['message'] = _t('@internalmail', 'Blocked: [messages]', [ 'messages' => $response['message'], ]); } break; default: { $this->app->hook('internalmail.admin.ajax.default.action', $action, $this); $this->errors->impossible(); } break; } return $this->ajaxResponseForm($response); } public function sysSpamMinuswordsPrepare($params = []) { if (!empty($params['value'])) { $prepared = serialize(TextParser::minuswordsPrepare('to_array', json_decode($params['value'], true))); config::save('internalmail.spam.minuswords.prepared', $prepared); } } }