Support: Comb the code

Also, now clicking on the name of the support agent does not display "false". There should be no other visible changes
This commit is contained in:
Maxim Leshchenko 2022-01-07 00:30:49 +02:00
parent 6c23be8b2b
commit f7fbda1e3c
No known key found for this signature in database
GPG key ID: BB9C44A8733FBEEE
4 changed files with 308 additions and 324 deletions

View file

@ -31,6 +31,7 @@ final class SupportPresenter extends OpenVKPresenter
$tickets = $this->tickets->getTicketsByuId($this->user->id); $tickets = $this->tickets->getTicketsByuId($this->user->id);
if($tickets) if($tickets)
$this->template->tickets = $tickets; $this->template->tickets = $tickets;
if($_SERVER["REQUEST_METHOD"] === "POST") { if($_SERVER["REQUEST_METHOD"] === "POST") {
if(!empty($this->postParam("name")) && !empty($this->postParam("text"))) { if(!empty($this->postParam("name")) && !empty($this->postParam("text"))) {
$this->assertNoCSRF(); $this->assertNoCSRF();
@ -111,11 +112,11 @@ final class SupportPresenter extends OpenVKPresenter
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 && !$this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) {
$this->notFound(); $this->notFound();
} else { } else {
header("HTTP/1.1 302 Found");
if($ticket->getUserId() !== $this->user->id && $this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0)) if($ticket->getUserId() !== $this->user->id && $this->hasPermission('openvk\Web\Models\Entities\TicketReply', 'write', 0))
header("Location: /support/tickets"); $this->redirect("/support/tickets");
else else
header("Location: /support"); $this->redirect("/support");
$ticket->delete(); $ticket->delete();
} }
} }
@ -183,12 +184,11 @@ final class SupportPresenter extends OpenVKPresenter
$ticket->setType($this->postParam("status")); $ticket->setType($this->postParam("status"));
$ticket->save(); $ticket->save();
$this->assertNoCSRF();
$comment = new TicketComment; $comment = new TicketComment;
$comment->setUser_id($this->user->id); $comment->setUser_id($this->user->id);
$comment->setUser_type(1); $comment->setUser_type(1);
$comment->setText($this->postParam("text")); $comment->setText($this->postParam("text"));
$comment->setTicket_id($id); $comment->setTicket_Id($id);
$comment->setCreated(time()); $comment->setCreated(time());
$comment->save(); $comment->save();
} elseif(empty($this->postParam("text"))) { } elseif(empty($this->postParam("text"))) {

View file

@ -6,138 +6,129 @@
{/block} {/block}
{block content} {block content}
<div class="post-author"> <div class="post-author">
<a href="#" style="font-size:13px;"> <a href="#" style="font-size: 13px;"><b>{$ticket->getName()}</b></a><br />
<b> {_author}: <a href="/id{$ticket->getUser()->getId()}">{$ticket->getUser()->getFullName()}</a> | {$ticket->getUser()->getRegistrationIP()} | {_status}: {$ticket->getStatus()}.
{$ticket->getName()} </div>
</b> <div class="text" style="padding-top: 10px; border-bottom: #ECECEC solid 1px;">
</a> {$ticket->getText()|noescape}
<br></b>{_author}: <a href="/id{$ticket->getUser()->getId()}">{$ticket->getUser()->getFullName()}</a> | {$ticket->getUser()->getRegistrationIP()} | {_status}: {$ticket->getStatus()}. <br /><br />
</div> </div>
<div class="text" style="padding-top: 10px;border-bottom: #ECECEC solid 1px;"> <div style="padding-top: 5px;">
{$ticket->getText()|noescape} {$ticket->getTime()}&nbsp;|&nbsp;
<br></br> <a href="/support/delete/{$id}?hash={$csrfToken}">{_delete}</a>
</div> </div>
<div style="padding-top: 5px;"> <br />
{$ticket->getTime()}&nbsp;|&nbsp; <div>
<a href="/support/delete/{$id}?hash={$csrfToken}">{_delete}</a> <form action="/al_comment/create/support/reply/{$id}" method="post" style="margin: 0;">
</div><br/> <textarea name="text" id="answer_text" style="width: 100%; resize: vertical;"></textarea>
<div> <br />
<form action="/al_comments/create/support/reply/{$id}" method="post" style="margin:0;"> <input type="hidden" name="hash" value="{$csrfToken}" />
<textarea name="text" id="answer_text" style="width: 100%;resize: vertical;"></textarea> <br />
<div> <div style="float: left;">
<!-- padding to fix <br/> bug --> <input type="submit" value="{_write}" class="button" />
</div> <select name="status" style="width: unset;">
<input type="hidden" name="hash" value="{$csrfToken}" /> <option value="1">{_support_status_1}</option>
<br /> <option value="2">{_support_status_2}</option>
<div style="float: left;"> <option value="0">{_support_status_0}</option>
<input type="submit" value="{_write}" class="button"> </select>
<select name="status" style="width: unset;">
<option value="1">{_support_status_1}</option>
<option value="2">{_support_status_2}</option>
<option value="0">{_support_status_0}</option>
</select>
</div>
<div n:if="!is_null($fastAnswers)" style="float: right;">
<a class="button" href="javascript:showSupportFastAnswerDialog(fastAnswers)">{_fast_answers}</a>
</div>
<br />
</form>
</div>
<br/>
<p n:if="!$comments">{_no_comments}</p>
{var $printedSupportGreeting = false}
<table n:foreach="$comments as $comment" border="0" style="font-size: 11px;" class="post">
<tbody>
<tr>
{if $comment->getUType() === 0}
<td width="54" valign="top">
<img src="{$comment->getUser()->getAvatarUrl()}" width="50">
</td>
{else}
<td width="54" valign="top">
<img
src="{$comment->getAvatar()}"
style="max-width: 50px; filter: hue-rotate({$comment->getColorRotation()}deg);" />
</td>
{/if}
<td width="645" valign="top">
{if $comment->getUType() === 0}
<div class="post-author">
<a href="{$comment->getUser()->getURL()}"><b>
{$comment->getUser()->getFullName()}
</b></a> {($comment->getUser()->isFemale() ? tr("post_writes_f") : tr("post_writes_m"))}<br>
<a href="#" class="date">{$comment->getTime()}</a>
</div> </div>
{elseif ($comment->getUType() === 1)} <div n:if="!is_null($fastAnswers)" style="float: right;">
<div class="post-author"> <a class="button" href="javascript:showSupportFastAnswerDialog(fastAnswers)">{_fast_answers}</a>
<a href="javascript:false">
<b>
{$comment->getAuthorName()}
</b>
</a>
{if $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)}
<a href="{$comment->getUser()->getURL()}">
<span class="nobold">
{var lastName = $comment->getUser()->getLastName()}
{if empty(trim($lastName))}
({$comment->getUser()->getFirstName()})
{else}
({$comment->getUser()->getFirstName()} {iconv_substr($lastName, 0, 1)}.)
{/if}
</span>
</a>
{/if}
{_post_writes_m}<br>
<a href="#" class="date">{$comment->getTime()}</a>
</div> </div>
{/if} <br />
<div class="post-content" id="{$comment->getId()}"> </form>
<div class="text" id="text{$comment->getId()}"> </div>
{if $comment->getUType() === 1 && !$printedSupportGreeting} <br />
{var $printedSupportGreeting = true} <p n:if="!$comments">{_no_comments}</p>
{tr("support_greeting_hi", $ticket->getUser()->getFullName())} {var $printedSupportGreeting = false}
<br/> <table n:foreach="$comments as $comment" border="0" style="font-size: 11px;" class="post">
<br/> <tbody>
<tr>
{if $comment->getUType() === 0}
<td width="54" valign="top">
<img src="{$comment->getUser()->getAvatarUrl()}" width="50" />
</td>
{else}
<td width="54" valign="top">
<img
src="{$comment->getAvatar()}"
style="max-width: 50px; filter: hue-rotate({$comment->getColorRotation()}deg);" />
</td>
{/if}
<td width="645" valign="top">
{if $comment->getUType() === 0}
<div class="post-author">
<a href="{$comment->getUser()->getURL()}"><b>
{$comment->getUser()->getFullName()}
</b></a> {($comment->getUser()->isFemale() ? tr("post_writes_f") : tr("post_writes_m"))}<br />
<a href="#" class="date">{$comment->getTime()}</a>
</div>
{elseif ($comment->getUType() === 1)}
<div class="post-author">
<a><b>{$comment->getAuthorName()}</b></a>
{if $thisUser->getChandlerUser()->can("write")->model('openvk\Web\Models\Entities\TicketReply')->whichBelongsTo(0)}
<a href="{$comment->getUser()->getURL()}">
<span class="nobold">
{var lastName = $comment->getUser()->getLastName()}
{if empty(trim($lastName))}
({$comment->getUser()->getFirstName()})
{else}
({$comment->getUser()->getFirstName()} {iconv_substr($lastName, 0, 1)}.)
{/if}
</span>
</a>
{/if}
{_post_writes_m}<br />
<a href="#" class="date">{$comment->getTime()}</a>
</div>
{/if}
<div class="post-content" id="{$comment->getId()}">
<div class="text" id="text{$comment->getId()}">
{if $comment->getUType() === 1 && !$printedSupportGreeting}
{var $printedSupportGreeting = true}
{tr("support_greeting_hi", $ticket->getUser()->getFullName())}
<br />
<br />
{$comment->getText()|noescape} {$comment->getText()|noescape}
<br/> <br />
<br/> <br />
{tr("support_greeting_regards", OPENVK_ROOT_CONF["openvk"]["appearance"]["name"])|noescape} {tr("support_greeting_regards", OPENVK_ROOT_CONF["openvk"]["appearance"]["name"])|noescape}
{else} {else}
{$comment->getText()|noescape} {$comment->getText()|noescape}
{/if} {/if}
</div> </div>
{if $comment->getUType() === 0} {if $comment->getUType() === 0}
<div class="post-menu"> <div class="post-menu">
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a> <a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
</div> </div>
{/if}
{if $comment->getUType() === 1 && !is_null($comment->isLikedByUser())}
<div class="post-menu">
<strong>
{if $comment->isLikedByUser()}
{_support_good_answer_agent}
{else}
{_support_bad_answer_agent}
{/if} {/if}
</strong>
</div>
{/if}
</div>
</td>
</tr>
</tbody>
</table>
<script> {if $comment->getUType() === 1 && !is_null($comment->isLikedByUser())}
const fastAnswers = [ <div class="post-menu">
{foreach $fastAnswers as $answer} <strong>
{$answer}, {if $comment->isLikedByUser()}
{/foreach} {_support_good_answer_agent}
]; {else}
</script> {_support_bad_answer_agent}
{/if}
</strong>
</div>
{/if}
</div>
</td>
</tr>
</tbody>
</table>
<script>
const fastAnswers = [
{foreach $fastAnswers as $answer}
{$answer},
{/foreach}
];
</script>
{/block} {/block}

View file

@ -6,63 +6,68 @@
{/block} {/block}
{block content} {block content}
{var isMain = $mode === 'faq'}
{var isNew = $mode === 'new'}
{var isList = $mode === 'list'}
{var isMain = $mode === 'faq'} {if $thisUser}
{var isNew = $mode === 'new'} <div class="tabs">
{var isList = $mode === 'list'} <div n:attr="id => ($isMain ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => ($isMain ? 'act_tab_a' : 'ki')" href="/support">{_support_faq}</a>
{if $thisUser}
<div class="tabs">
<div n:attr="id => ($isMain ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => ($isMain ? 'act_tab_a' : 'ki')" href="/support">{_support_faq}</a>
</div>
<div n:attr="id => ($isList ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => ($isList ? 'act_tab_a' : 'ki')" href="/support?act=list">{_support_list}</a>
</div>
<div n:attr="id => ($isNew ? 'activetabs' : 'ki')" class="tab">
<a n:attr="id => ($isNew ? 'act_tab_a' : 'ki')" href="/support?act=new">{_support_new}</a>
</div>
</div>
<br>
{if $isNew}
<div class="new">
<form action="/support" method="post" style="margin:0;">
<center><input name="name" style="width: 80%;resize: vertical;" placeholder="{_support_new_title}"></center><br>
<center><textarea name="text" style="width: 80%;resize: vertical;" placeholder="{_support_new_content}"></textarea></center><br>
<input type="hidden" name="hash" value="{$csrfToken}" />
<center><input type="submit" value="{_write}" class="button" style="margin-left:70%;"></center><br>
</form>
</div>
{/if}{/if}
{if $isMain}
<h4>{_support_faq}</h4><br>
<div class="faq">
<div id="faqhead">{_support_faq_title}</div>
<div id="faqcontent">{_support_faq_content}</div>
</div>
{/if}
{if $isList}
<table n:foreach="$tickets as $ticket" border="0" style="font-size:11px;width: 610px;" class="post">
<tbody>
<tr>
<td width="54" valign="top">
<center><img src="/assets/packages/static/openvk/img/note_icon.png" alt="{_support_ticket}" style="margin-top: 17px;"></center>
</td>
<td width="345" valign="top">
<div class="post-author">
<a href="/support/view/{$ticket->getId()}">
<b>{$ticket->getName()}</b>
</a>
</div> </div>
<div class="post-content" style="padding: 4px;font-size: 11px;"> <div n:attr="id => ($isList ? 'activetabs' : 'ki')" class="tab">
{_status}: {$ticket->getStatus()} <a n:attr="id => ($isList ? 'act_tab_a' : 'ki')" href="/support?act=list">{_support_list}</a>
</div> </div>
</td> <div n:attr="id => ($isNew ? 'activetabs' : 'ki')" class="tab">
</tr> <a n:attr="id => ($isNew ? 'act_tab_a' : 'ki')" href="/support?act=new">{_support_new}</a>
</tbody> </div>
</table> </div>
{/if}
<br />
{if $isNew}
<div class="new">
<form action="/support" method="post" style="margin:0;">
<center>
<input name="name" style="width: 80%; resize: vertical;" placeholder="{_support_new_title}" /><br /><br />
<textarea name="text" style="width: 80%; resize: vertical;" placeholder="{_support_new_content}"></textarea><br /><br />
<input type="hidden" name="hash" value="{$csrfToken}" />
<input type="submit" value="{_write}" class="button" style="margin-left: 70%;" /><br /><br />
</center>
</form>
</div>
{/if}
{/if}
{if $isMain}
<h4>{_support_faq}</h4><br />
<div class="faq">
<div id="faqhead">{_support_faq_title}</div>
<div id="faqcontent">{_support_faq_content}</div>
</div>
{/if}
{if $isList}
<table n:foreach="$tickets as $ticket" border="0" style="font-size: 11px; width: 610px;" class="post">
<tbody>
<tr>
<td width="54" valign="top">
<center>
<img src="/assets/packages/static/openvk/img/note_icon.png" alt="{_support_ticket}" style="margin-top: 17px;" />
</center>
</td>
<td width="345" valign="top">
<div class="post-author">
<a href="/support/view/{$ticket->getId()}">
<b>{$ticket->getName()}</b>
</a>
</div>
<div class="post-content" style="padding: 4px; font-size: 11px;">
{_status}: {$ticket->getStatus()}
</div>
</td>
</tr>
</tbody>
</table>
{/if}
{/block} {/block}

View file

@ -6,144 +6,132 @@
{/block} {/block}
{block content} {block content}
<script> <script>
function markAnswer(id, mark) { function markAnswer(id, mark) {
let url = "/support/comment/" + id + "/rate/" + mark + "?hash=" + {urlencode($csrfToken)}; let url = "/support/comment/" + id + "/rate/" + mark + "?hash=" + {urlencode($csrfToken)};
$.ajax(url, { $.ajax(url, {
error: errorHandler, error: errorHandler,
success: success(id, mark) success: success(id, mark)
}); });
} }
function success(id, mark) { function success(id, mark) {
if(mark == 1) if(mark == 1)
document.getElementById("markText-" + id).innerHTML = {_support_good_answer_user}; document.getElementById("markText-" + id).innerHTML = {_support_good_answer_user};
else else
document.getElementById("markText-" + id).innerHTML = {_support_bad_answer_user}; document.getElementById("markText-" + id).innerHTML = {_support_bad_answer_user};
document.getElementById("markLinks-" + id).remove(); document.getElementById("markLinks-" + id).remove();
} }
function errorHandler(id, mark) { function errorHandler(id, mark) {
document.getElementById("markText-" + id).innerHTML = {_error}; document.getElementById("markText-" + id).innerHTML = {_error};
} }
</script> </script>
{if $ticket->isDeleted() == 0 }
<div class="post-author"> {if $ticket->isDeleted() == 0}
<a href="#" style="font-size:13px;"> <div class="post-author">
<b> <a href="#" style="font-size:13px;"><b>{$ticket->getName()}</b></a>
{$ticket->getName()} <br />{_status}: {$ticket->getStatus()}
</b>
</a>
<br></b>{_status}: {$ticket->getStatus()}
</div>
<div class="text" style="padding-top: 10px;border-bottom: #ECECEC solid 1px;">
{$ticket->getText()|noescape}
<br></br>
</div>
<div style="padding-top: 5px;">
{$ticket->getTime()}&nbsp;|&nbsp;
<a href="/support/delete/{$id}?hash={$csrfToken}">{_delete}</a>
</div>
{if $ticket->getType() !== 2}
<br>
<div>
<form action="/al_comments/create/support/{$id}" method="post" style="margin:0;">
<textarea name="text" style="width: 100%;resize: vertical;"></textarea>
<div>
<!-- padding to fix <br/> bug -->
</div>
<input type="hidden" name="hash" value="{$csrfToken}" />
<br>
<input type="submit" value="{_write}" class="button">
</form>
</div> </div>
{/if} <div class="text" style="padding-top: 10px; border-bottom: #ECECEC solid 1px;">
</br> {$ticket->getText()|noescape}
<p n:if="!$comments">{_no_comments}</p> <br /></br>
{var $printedSupportGreeting = false} </div>
<table n:foreach="$comments as $comment" border="0" style="font-size: 11px;" class="post"> <div style="padding-top: 5px;">
<tbody> {$ticket->getTime()}&nbsp;|&nbsp;
<tr> <a href="/support/delete/{$id}?hash={$csrfToken}">{_delete}</a>
{if $comment->getUType() === 0} </div>
<td width="54" valign="top"> {if $ticket->getType() !== 2}
<img src="{$comment->getUser()->getAvatarUrl()}" width="50"> <br />
</td> <div>
{else} <form action="/al_comments/create/support/{$id}" method="post" style="margin:0;">
<td width="54" valign="top"> <textarea name="text" style="width: 100%;resize: vertical;"></textarea><br />
<img <input type="hidden" name="hash" value="{$csrfToken}" /><br />
src="{$comment->getAvatar()}" <input type="submit" value="{_write}" class="button" />
style="max-width: 50px; filter: hue-rotate({$comment->getColorRotation()}deg);" /> </form>
</td>
{/if}
<td width="645" valign="top">
{if $comment->getUType() === 0}
<div class="post-author">
<a href="{$comment->getUser()->getURL()}"><b>
{$comment->getUser()->getFullName()}
</b></a> {($comment->getUser()->isFemale() ? tr("post_writes_f") : tr("post_writes_m"))}<br>
<a href="#" class="date">{$comment->getTime()}</a>
</div> </div>
{elseif ($comment->getUType() === 1)} {/if}
<div class="post-author"> <br />
<a href="javascript:false"> <p n:if="!$comments">{_no_comments}</p>
<b> {var $printedSupportGreeting = false}
{$comment->getAuthorName()} <table n:foreach="$comments as $comment" border="0" style="font-size: 11px;" class="post">
</b> <tbody>
</a> <tr>
{_post_writes_m}<br> {if $comment->getUType() === 0}
<a href="#" class="date">{$comment->getTime()}</a> <td width="54" valign="top">
</div> <img src="{$comment->getUser()->getAvatarUrl()}" width="50" />
{/if} </td>
<div class="post-content" id="{$comment->getId()}"> {else}
<div class="text" id="text{$comment->getId()}"> <td width="54" valign="top">
{if $comment->getUType() === 1 && !$printedSupportGreeting} <img
{var $printedSupportGreeting = true} src="{$comment->getAvatar()}"
{tr("support_greeting_hi", $ticket->getUser()->getFullName())} style="max-width: 50px; filter: hue-rotate({$comment->getColorRotation()}deg);" />
<br/> </td>
<br/> {/if}
<td width="645" valign="top">
{$comment->getText()|noescape} {if $comment->getUType() === 0}
<br/> <div class="post-author">
<br/> <a href="{$comment->getUser()->getURL()}"><b>{$comment->getUser()->getFullName()}</b></a>
{($comment->getUser()->isFemale() ? tr("post_writes_f") : tr("post_writes_m"))}<br />
{tr("support_greeting_regards", OPENVK_ROOT_CONF["openvk"]["appearance"]["name"])|noescape} <a href="#" class="date">{$comment->getTime()}</a>
{else} </div>
{$comment->getText()|noescape} {elseif ($comment->getUType() === 1)}
{/if} <div class="post-author">
</div> <a><b>{$comment->getAuthorName()}</b></a>
{_post_writes_m}<br />
{if $comment->getUType() === 0} <a href="#" class="date">{$comment->getTime()}</a>
<div class="post-menu"> </div>
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
</div>
{/if}
{if $comment->getUType() === 1}
<div class="post-menu">
{var isLikedByUser = $comment->isLikedByUser()}
<strong id="markText-{$comment->getId()}">
{if !is_null($isLikedByUser)}
{if $comment->isLikedByUser()}
{_support_good_answer_user}
{else}
{_support_bad_answer_user}
{/if} {/if}
{/if} <div class="post-content" id="{$comment->getId()}">
</strong> <div class="text" id="text{$comment->getId()}">
<div id="markLinks-{$comment->getId()}"> {if $comment->getUType() === 1 && !$printedSupportGreeting}
{if is_null($isLikedByUser)} {var $printedSupportGreeting = true}
<a onClick="markAnswer({$comment->getId()}, 1)">{_support_rate_good_answer}</a> {tr("support_greeting_hi", $ticket->getUser()->getFullName())}
| <br />
<a onClick="markAnswer({$comment->getId()}, 2)">{_support_rate_bad_answer}</a> <br />
{/if}
</div> {$comment->getText()|noescape}
{/if} <br />
</div> <br />
</div>
</td> {tr("support_greeting_regards", OPENVK_ROOT_CONF["openvk"]["appearance"]["name"])|noescape}
</tr> {else}
</tbody> {$comment->getText()|noescape}
</table> {/if}
{/if} </div>
{if $comment->getUType() === 0}
<div class="post-menu">
<a href="/support/comment/{$comment->getId()}/delete">{_delete}</a>
</div>
{/if}
{if $comment->getUType() === 1}
<div class="post-menu">
{var isLikedByUser = $comment->isLikedByUser()}
<strong id="markText-{$comment->getId()}">
{if !is_null($isLikedByUser)}
{if $comment->isLikedByUser()}
{_support_good_answer_user}
{else}
{_support_bad_answer_user}
{/if}
{/if}
</strong>
<div id="markLinks-{$comment->getId()}">
{if is_null($isLikedByUser)}
<a onClick="markAnswer({$comment->getId()}, 1)">{_support_rate_good_answer}</a>
|
<a onClick="markAnswer({$comment->getId()}, 2)">{_support_rate_bad_answer}</a>
{/if}
</div>
</div>
{/if}
</div>
</td>
</tr>
</tbody>
</table>
{/if}
{/block} {/block}