{_status}: {$ticket->getStatus()}
diff --git a/Web/Models/Entities/SupportAgent.php b/Web/Models/Entities/SupportAgent.php index 2f7fc21b..00f06457 100644 --- a/Web/Models/Entities/SupportAgent.php +++ b/Web/Models/Entities/SupportAgent.php @@ -32,8 +32,13 @@ class SupportAgent extends RowModel return $this->getRecord()->numerate; } + function getUser(): User + { + return (new Users)->get((int) $this->getAgentId()); + } + function getRealName(): string { - return (new Users)->get($this->getAgentId())->getCanonicalName(); + return $this->getUser()->getCanonicalName(); } } \ No newline at end of file diff --git a/Web/Models/Entities/Ticket.php b/Web/Models/Entities/Ticket.php index 31690ce3..f197cf6e 100644 --- a/Web/Models/Entities/Ticket.php +++ b/Web/Models/Entities/Ticket.php @@ -1,5 +1,6 @@ get((int) $this->getRecord()->support_sender); + } + + function isFromSupport(): bool + { + return $this->getSupportSender() !== NULL; + } + use Traits\TRichText; } diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 348631e4..0653cd2b 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -1031,7 +1031,7 @@ class User extends RowModel function adminNotify(string $message): bool { - $admId = OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["adminAccount"]; + $admId = (int) OPENVK_ROOT_CONF["openvk"]["preferences"]["support"]["adminAccount"]; if(!$admId) return false; else if(is_null($admin = (new Users)->get($admId))) diff --git a/Web/Presenters/SupportPresenter.php b/Web/Presenters/SupportPresenter.php index c4d729ea..251076a2 100644 --- a/Web/Presenters/SupportPresenter.php +++ b/Web/Presenters/SupportPresenter.php @@ -152,7 +152,7 @@ final class SupportPresenter extends OpenVKPresenter if(!empty($id)) { $ticket = $this->tickets->get($id); - if(!$ticket || $ticket->isDeleted() != 0 || $ticket->getUserId() !== $this->user->id && !$this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) { + if(!$ticket || $ticket->isDeleted() != 0 || (($ticket->getUserId() !== $this->user->id || $ticket->isFromSupport()) && !$this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0))) { $this->notFound(); } else { if($ticket->getUserId() !== $this->user->id && $this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) @@ -396,4 +396,37 @@ final class SupportPresenter extends OpenVKPresenter $this->flashFail("succ", "Успех", "Профиль создан. Теперь пользователи видят Ваши псевдоним и аватарку вместо стандартных аватарки и номера."); } } + + function renderSendUserTicket(): void + { + $this->assertPermission("openvk\Web\Models\Entities\TicketReply", "write", 0); + $this->assertNoCSRF(); + + if (!$this->postParam("uid") || !$this->postParam("text")) + $this->returnJson(["success" => false, "error" => "Один или несколько обязательных параметров не были переданы"]); + + $user = (new Users)->get((int) $this->postParam("uid")); + if (!$user) $this->returnJson(["success" => false, "error" => "Пользователь не найден"]); + + $ticket = new Ticket; + $ticket->setType(1); + $ticket->setUser_Id($user->getId()); + $ticket->setName("[Вопрос от Поддержки]" . ($this->postParam("title") ? " " . $this->postParam("title") : "")); + $ticket->setText($this->postParam("text")); + $ticket->setCreated(time()); + $ticket->setSupport_Sender($this->user->id); + $ticket->save(); + + $comment = new TicketComment; + $comment->setUser_Id($this->user->id); + $comment->setUser_Type(1); + $comment->setText($this->postParam("text")); + $comment->setCreated(time()); + $comment->setTicket_Id($ticket->getId()); + $comment->save(); + + $user->adminNotify(($user->isFemale() ? "Дорогая " : "Дорогой ") . $user->getFirstName() . "!\n\nВы получили новый вопрос (https://$_SERVER[SERVER_NAME]/support/view/{$ticket->getId()}) от Команды Поддержки " . OPENVK_ROOT_CONF["openvk"]["appearance"]["name"]); + + $this->returnJson(["success" => true, "payload" => $ticket->getId()]); + } } diff --git a/Web/Presenters/templates/Support/AnswerTicket.xml b/Web/Presenters/templates/Support/AnswerTicket.xml index 7f577f9d..841fe69b 100644 --- a/Web/Presenters/templates/Support/AnswerTicket.xml +++ b/Web/Presenters/templates/Support/AnswerTicket.xml @@ -8,9 +8,16 @@ {block content}
-