Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(support): add questions from support #944

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Web/Models/Entities/SupportAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ function isShowNumber(): int
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();
}
}
11 changes: 11 additions & 0 deletions Web/Models/Entities/Ticket.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php declare(strict_types=1);
namespace openvk\Web\Models\Entities;
use openvk\Web\Models\Repositories\SupportAgents;
use openvk\Web\Util\DateTime;
use openvk\Web\Models\RowModel;
use openvk\Web\Models\Repositories\Users;
Expand Down Expand Up @@ -64,5 +65,15 @@ function isAd(): bool /* Эх, костыли... */
return false;
}

function getSupportSender(): ?SupportAgent
{
return (new SupportAgents)->get((int) $this->getRecord()->support_sender);
}

function isFromSupport(): bool
{
return $this->getSupportSender() !== NULL;
}

use Traits\TRichText;
}
2 changes: 1 addition & 1 deletion Web/Models/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ function changeEmail(string $email): void

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)))
Expand Down
35 changes: 34 additions & 1 deletion Web/Presenters/SupportPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function renderDelete(int $id): void

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))
Expand Down Expand Up @@ -396,4 +396,37 @@ function renderEditAgent(int $id): void
$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()]);
}
}
11 changes: 9 additions & 2 deletions Web/Presenters/templates/Support/AnswerTicket.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
{block content}
<div class="post-author">
<a href="#" style="font-size: 13px;"><b>{$ticket->getName()}</b></a><br />
{_author}: <a href="/id{$ticket->getUser()->getId()}">{$ticket->getUser()->getFullName()}</a> | {$ticket->getUser()->getRegistrationIP()} | {_status}: {$ticket->getStatus()}.
{$ticket->isFromSupport() ? tr("user") : tr("author")}: <a href="/id{$ticket->getUser()->getId()}">{$ticket->getUser()->getFullName()}</a>
{if $ticket->isFromSupport()}
| {_author}:
<a href="{$ticket->getSupportSender()->getUser()->getURL()}">
{$ticket->getSupportSender()->getUser()->getCanonicalName()}
</a>
{/if}
| {$ticket->getUser()->getRegistrationIP()} | {_status}: {$ticket->getStatus()}.
</div>
<div class="text" style="padding-top: 10px; border-bottom: #ECECEC solid 1px;">
<div class="text" style="padding-top: 10px; border-bottom: #ECECEC solid 1px;" n:if="!$ticket->isFromSupport()">
{$ticket->getText()|noescape}
<br /><br />
</div>
Expand Down
11 changes: 7 additions & 4 deletions Web/Presenters/templates/Support/View.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@
<a href="#" style="font-size:13px;"><b>{$ticket->getName()}</b></a>
<br />{_status}: {$ticket->getStatus()}
</div>
<div class="text" style="padding-top: 10px; border-bottom: #ECECEC solid 1px;">
<div class="text" style="padding-top: 10px; border-bottom: #ECECEC solid 1px;" n:if="!$ticket->isFromSupport()">
{$ticket->getText()|noescape}
<br /></br>
<br /><br />
</div>
<div style="padding-top: 5px;">
{$ticket->getTime()}&nbsp;|&nbsp;
<a href="/support/delete/{$id}?hash={$csrfToken}">{_delete}</a>
{$ticket->getTime()}
<span n:if="!$ticket->isFromSupport()">
&nbsp;|&nbsp;
<a href="/support/delete/{$id}?hash={$csrfToken}">{_delete}</a>
</span>
</div>
{if $ticket->getType() !== 2}
<br />
Expand Down
37 changes: 37 additions & 0 deletions Web/Presenters/templates/User/View.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
{_ban_in_support_user_action}
{/if}
</a>
<a href="javascript:newSupportTicketToUser()" class="profile_link" style="width: 194px;">
Вопрос от Поддержки
</a>
{/if}

<a style="width: 194px;" n:if="OPENVK_ROOT_CONF['openvk']['preferences']['commerce'] && $user->getGiftCount() == 0" href="/gifts?act=pick&user={$user->getId()}" class="profile_link">{_send_gift}</a>
Expand Down Expand Up @@ -688,6 +691,40 @@
]);
}
{/if}

function newSupportTicketToUser() {
uTicketMsgTxt = "Вы собираетесь связаться с пользователем <b>" + {$user->getCanonicalName()} + "</b> от имени Поддержки. Он получит об этом оповещение от имени служебного аккаунта.";
uTicketMsgTxt += "<br/><br/><b>Название</b>: <input type='text' id='uTicketTitle' placeholder='В начале будет добавлено \"[Вопрос от Поддержки]\"' />";
uTicketMsgTxt += "<br/><br/><b>Текст</b>: <textarea type='text' id='uTicketText' placeholder='Текст без приветствия и завершения' style='resize: vertical; height: 185px;'></textarea>";

MessageBox("Отправить вопрос", uTicketMsgTxt, ["Отправить", "Отмена"], [
(function () {
title = $("#uTicketTitle").val();
text = $("#uTicketText").val()

$.ajax({
type: "POST",
url: "/al_helpdesk/sendTicket",
data: {
uid: {$user->getId()},
title: title,
text: text,
hash: {=$csrfToken}
},
success: (response) => {
if (response.success) {
MessageBox("Успех", "Пользователь получил вопрос и оповещения<br/><br/><a href='/support/reply/" + response.payload + "' target='_blank'>Перейти к вопросу</a>", ["OK"], [Function.noop]);
} else {
MessageBox("Ошибка", "При отправке запроса произошла ошибка: " + (response?.error ?? "Неизвестная ошибка"), ["OK"], [Function.noop]);
}
}
})
}),
Function.noop
])

$(".ovk-diag-cont").width("650px");
}
</script>

<script n:if="isset($thisUser) && $user->getId() == $thisUser->getId()" n:syntax="off">
Expand Down
2 changes: 2 additions & 0 deletions Web/routes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ routes:
handler: "Support->agent"
- url: "/support/agent{num}/edit"
handler: "Support->editAgent"
- url: "/al_helpdesk/sendTicket"
handler: "Support->sendUserTicket"
- url: "/language"
handler: "About->language"
- url: "/language/{text}.js"
Expand Down
2 changes: 2 additions & 0 deletions install/sqls/00038-support-tickets-from-agents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `tickets`
ADD `support_sender` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `created`;
2 changes: 2 additions & 0 deletions locales/en.strings
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,8 @@
"banned_in_support_1" = "Sorry, <b>$1</b>, but now you can't create tickets.";
"banned_in_support_2" = "And the reason for this is simple: <b>$1</b>. Unfortunately, this time we had to take away this opportunity from you forever.";

"user" = "User";

/* Invite */

"invite" = "Invite";
Expand Down
1 change: 1 addition & 0 deletions locales/ru.strings
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@
"ticket_changed_comment" = "Изменения вступят силу через несколько секунд.";
"banned_in_support_1" = "Извините, <b>$1</b>, но теперь вам нельзя создавать обращения.";
"banned_in_support_2" = "А причина этому проста: <b>$1</b>. К сожалению, на этот раз нам пришлось отобрать у вас эту возможность навсегда.";
"user" = "Пользователь";

/* Invite */

Expand Down