Files
poll/templates/result.tpl
2026-03-29 18:38:12 +05:00

197 lines
11 KiB
Smarty

<script type="text/javascript" src="/modules/poll/templates/js/common.js"></script>
<div class="poll-container container my-4">
<h2 class="mb-4 text-dark border-bottom pb-2">{$poll->poll_title|escape}</h2>
<div class="row">
<div class="col-md-8">
<div class="card shadow-sm mb-4">
<div class="card-header bg-dark text-white">
<h5 class="mb-0 small text-uppercase fw-bold">{#POLL_QUESTION_LIST#}</h5>
</div>
<div class="card-body p-0">
<ul class="list-group list-group-flush">
{foreach from=$poll->items item=item}
<li class="list-group-item py-3">
<div class="d-flex justify-content-between mb-1">
<span class="fw-medium">{$item->poll_item_title|escape}</span>
<span class="badge bg-secondary">{$item->poll_item_hits} {#POLL_RESULT_INFO#} ({$item->sum}%)</span>
</div>
<div class="progress" style="height: 10px;">
<div class="progress-bar bg-dark" role="progressbar"
style="width: {if $item->sum!=''}{$item->sum}%{else}1%{/if}; background-color:{$item->poll_item_color} !important;">
</div>
</div>
</li>
{/foreach}
</ul>
</div>
</div>
{if $poll->poll_can_comment == 1}
<div class="mt-5">
<div class="d-flex justify-content-between align-items-center mb-3">
<h4 class="mb-0 text-secondary">{#POLL_PUB_COMMENTS#}</h4>
<span class="badge rounded-pill bg-light text-dark border">{$poll->count_comments}</span>
</div>
{foreach from=$poll->comments item=comment}
<div class="card mb-3 border-0 shadow-sm bg-light" id="{$comment->id}">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center mb-2 border-bottom pb-1">
<span class="fw-bold text-dark small">{$comment->lastname|escape} {$comment->firstname|escape}</span>
<small class="text-muted">{$comment->poll_comment_time|date_format:$TIME_FORMAT|pretty_date}</small>
</div>
<h6 class="card-title fw-bold">{$comment->poll_comment_title|escape}</h6>
<p class="card-text text-muted small mb-0">{$comment->poll_comment_text|nl2br}</p>
</div>
</div>
{/foreach}
{if $poll->can_comment == 1}
<div class="card mt-4 border-dark shadow-sm">
<div class="card-body">
<h5 class="card-title mb-3 text-uppercase small fw-bold text-dark">{#POLL_PUB_ADD_COMMENT#}</h5>
<div id="poll-error-container"></div>
<form id="new" method="post">
<input name="sub" type="hidden" value="new" />
<div class="mb-3">
<label class="form-label small fw-bold text-muted">{#POLL_COMMENT_TITEL#}</label>
<input type="text" name="comment_title" id="post_title" class="form-control"
value="{$smarty.post.comment_title|default:''|escape|stripslashes}" placeholder="{#POLL_COMMENT_TITEL_PL#}">
</div>
<div class="mb-3">
<label class="form-label small fw-bold text-muted text-end w-100 mb-1" id="markItUpPost">
{#POLL_CHARSET_LEFT#} <span class="badge bg-secondary" id="charsLeft_new"></span>
</label>
<textarea id="post" name="comment_text" class="form-control" rows="5" placeholder="{#POLL_COMMENT_TITEL_PLS#}">{$smarty.post.comment_text|default:''|escape|stripslashes}</textarea>
</div>
<div class="d-flex align-items-center justify-content-between bg-light p-3 rounded border">
{if $poll->anti_spam == 1}
<div class="d-flex align-items-center gap-3">
<div id="captcha-container">
<img src="{$ABS_PATH}inc/captcha.php?v={$smarty.now}"
alt="captcha"
class="rounded shadow-sm"
style="height: 45px; cursor: pointer;"
onclick="this.src='{$ABS_PATH}inc/captcha.php?v='+Math.random();"
title="{#POLL_CAPTCHA_UPD_IMG#}">
</div>
<input name="securecode" type="text" id="securecode"
class="form-control form-control-sm"
style="width: 100px;"
placeholder="{#POLL_CAPTCHA_PL#}"
autocomplete="off">
</div>
{/if}
<button name="submit" type="submit" class="btn btn-dark px-4">
{#POLL_BUTTON_ADD_C#}
</button>
</div>
</form>
</div>
</div>
{/if}
</div>
{/if}
</div>
<div class="col-md-4">
<div class="card mb-4 bg-light border-0 shadow-sm">
<div class="card-header bg-secondary text-white fw-bold small">{#POLL_INFOS#}</div>
<div class="card-body p-0">
<table class="table table-sm table-borderless mb-0 small">
<tr class="border-bottom"><td class="ps-3 py-2 text-muted">{#POLL_ALL_HITS#}</td><td class="pe-3 text-end fw-bold">{$poll->votes}</td></tr>
<tr class="border-bottom"><td class="ps-3 py-2 text-muted">{#POLL_PUB_STATUS#}</td><td class="pe-3 text-end fw-bold text-uppercase fs-xs">{if $poll->poll_end > $smarty.now}<span class="text-success small">{#POLL_ACTIVE_INFO#}</span>{else}<span class="text-danger small">{#POLL_INACTIVE_INFO#}</span>{/if}</td></tr>
<tr class="border-bottom"><td class="ps-3 py-2 text-muted">{#POLL_STARTED#}</td><td class="pe-3 text-end fw-light">{$poll->poll_start|date_format:$TIME_FORMAT|pretty_date}</td></tr>
<tr class="border-bottom"><td class="ps-3 py-2 text-muted">{#POLL_ENDED#}</td><td class="pe-3 text-end fw-light">{$poll->poll_end|date_format:$TIME_FORMAT|pretty_date}</td></tr>
</table>
</div>
</div>
{if $poll->can_vote == 1}
<div class="card border-primary shadow-sm">
<div class="card-body">
<h6 class="fw-bold mb-3">{#POLL_BUTTON_VOTE#}</h6>
<form method="post" action="{$poll->formaction}">
{foreach from=$poll->items item=item}
<div class="form-check mb-2">
<input class="form-check-input" type="radio" name="p_item" id="p_{$item->id}" value="{$item->id}">
<label class="form-check-label small" for="p_{$item->id}">{$item->poll_item_title|escape}</label>
</div>
{/foreach}
<button type="submit" class="btn btn-primary btn-sm w-100 mt-2 fw-bold">{#POLL_BUTTON_VOTE#}</button>
</form>
</div>
</div>
{/if}
</div>
</div>
</div>
<script type="text/javascript">
(function waitJQ() {ldelim}
if (window.jQuery) {ldelim}
$(document).ready(function() {ldelim}
var maxChars = parseInt("{$poll->comment_max_chars}") || 1000;
if (typeof $.fn.limit == 'function') {ldelim}
$('#post').limit(maxChars, '#charsLeft_new');
{rdelim}
var showError = function(message) {ldelim}
var html = '<div class="alert alert-danger alert-dismissible fade show shadow-sm mb-3">' +
'<strong>{#POLL_CAPTCHA_P_ERR#}</strong> ' + message +
'<button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>';
$('#poll-error-container').html(html);
$('html, body').animate({ldelim}scrollTop: $('#poll-error-container').offset().top - 120{rdelim}, 300);
{rdelim};
$('#new').off('submit').on('submit', function(e) {ldelim}
e.preventDefault();
$('#poll-error-container').empty();
var title = $('#post_title').val() ? $('#post_title').val().trim() : '';
var text = $('#post').val() ? $('#post').val().trim() : '';
var code = $('#securecode').val() ? $('#securecode').val().trim() : '';
if (title === '') {ldelim} showError('{#POLL_ERROR_NO_TITLE#}'); return false; {rdelim}
if (text.length < 10) {ldelim} showError('{#POLL_ERROR_NO_TEXT#}'); return false; {rdelim}
if ($('#securecode').length > 0 && code === '') {ldelim} showError('{#POLL_ERROR_NO_SCODE#}'); return false; {rdelim}
var $form = $(this);
$.ajax({ldelim}
url: '{$ABS_PATH}index.php?module=poll&action=result&pid={$poll->id}&ajax=1',
type: 'POST',
data: $form.serialize(),
success: function(response) {ldelim}
if (response.indexOf('###OK###') !== -1) {ldelim}
window.location.reload();
{rdelim}
else if (response.indexOf('###ERR###') !== -1) {ldelim}
var errorMsg = response.split('###ERR###')[1] || '{#POLL_ENTER_CODE_ERR#}';
showError(errorMsg);
if ($('img[alt="captcha"]').length) $('img[alt="captcha"]').trigger('click');
$('#securecode').val('');
{rdelim}
else {ldelim}
// Фолбэк на случай если сервер вернул ***
window.location.reload();
{rdelim}
{rdelim},
error: function(xhr) {ldelim}
showError('Системная ошибка: ' + xhr.status);
{rdelim}
{rdelim});
return false;
{rdelim});
{rdelim});
{rdelim} else {ldelim}
setTimeout(waitJQ, 50);
{rdelim}
{rdelim})();
</script>