| 1 |
<?php |
| 2 |
|
| 3 |
use SyncBasalam\Services\TicketServiceManager; |
| 4 |
use SyncBasalam\Utilities\DateConverter; |
| 5 |
use SyncBasalam\Admin\Components\CommonComponents; |
| 6 |
use SyncBasalam\Utilities\TicketUserResolver; |
| 7 |
|
| 8 |
defined('ABSPATH') || exit; |
| 9 |
|
| 10 |
$ticket_id = isset($_GET['ticket_id']) ? intval($_GET['ticket_id']) : 0; |
| 11 |
|
| 12 |
$ticketManager = new TicketServiceManager(); |
| 13 |
$fetchTicket = $ticketManager->fetchTicket($ticket_id); |
| 14 |
|
| 15 |
if (TicketServiceManager::isUnauthorized($fetchTicket)) { |
| 16 |
CommonComponents::renderUnauthorizedError(); |
| 17 |
return; |
| 18 |
} |
| 19 |
|
| 20 |
$ticket = isset($fetchTicket['body']) ? json_decode($fetchTicket['body'], true) : null; |
| 21 |
|
| 22 |
if (empty($ticket)) { |
| 23 |
echo 'تیکت یافت نشد.'; |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
$isTicketClosed = TicketServiceManager::isTicketClosed($ticket); |
| 28 |
$isTicketSiteAccessRejected = TicketServiceManager::isTicketSiteAccessRejected($ticket); |
| 29 |
|
| 30 |
?> |
| 31 |
<div class="basalam-container"> |
| 32 |
<div class="ticket-items__answer"> |
| 33 |
<header class="ticket-items__answer-header"> |
| 34 |
<h2 class="basalam-h">پاسخ تیکت</h2> |
| 35 |
<a class="basalam-p" style="color: black !important;direction: ltr;display:flex" href=" <?php echo esc_url(add_query_arg(['page' => 'sync_basalam_tickets', 'paged' => 1,], admin_url('admin.php'))); ?>">بازگشت به لیست تیکت ها</a> |
| 36 |
</header> |
| 37 |
<?php if ($isTicketClosed): ?> |
| 38 |
<div class="ticket-items__answer-closed" role="status" aria-live="polite"> |
| 39 |
<span class="ticket-items__answer-closed-icon" aria-hidden="true"> |
| 40 |
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> |
| 41 |
<rect x="3" y="11" width="18" height="10" rx="2"></rect> |
| 42 |
<path d="M7 11V7a5 5 0 0 1 10 0v4"></path> |
| 43 |
</svg> |
| 44 |
</span> |
| 45 |
<p class="ticket-items__answer-closed-text basalam-p">این تیکت بسته شده است و ا� |
| 46 |
کان ارسال پاسخ جدید وجود ندارد.</p> |
| 47 |
</div> |
| 48 |
<?php else: ?> |
| 49 |
<form action="<?php echo esc_url(admin_url('admin-post.php')); ?>" method="post" class="Basalam-form"> |
| 50 |
<?php wp_nonce_field('create_ticket_item_nonce', '_wpnonce'); ?> |
| 51 |
<input type="hidden" name="action" value="create_ticket_item"> |
| 52 |
<input type="hidden" name="ticket_id" value="<?php echo esc_attr($ticket_id); ?>"> |
| 53 |
<div class="ticket-items__answer-inputs"> |
| 54 |
<div class="ticket-items__answer-control"> |
| 55 |
<label for="ticket-answer-textarea" class="ticket-items__answer-control-label basalam-p">� |
| 56 |
تن پاسخ خود را وارد کنید</label> |
| 57 |
<textarea id="ticket-answer-textarea" name="content" class="basalam-input ticket-items__answer-input"></textarea> |
| 58 |
</div> |
| 59 |
|
| 60 |
<?php if ($isTicketSiteAccessRejected): ?> |
| 61 |
<div class="create-ticket__extra-info"> |
| 62 |
<p class="create-ticket__extra-info-title basalam-p">اطلاعات دسترسی (اختیاری)</p> |
| 63 |
<div class="ticket-access-grid"> |
| 64 |
<div class="ticket-access-card ticket-access-card--dashboard"> |
| 65 |
<p class="ticket-access-card__title basalam-p">اطلاعات پیشخوان</p> |
| 66 |
<div class="create-ticket__control"> |
| 67 |
<label for="ticket-dashboard-login-url" class="create-ticket__label basalam-p">آدرس لاگین پیشخوان</label> |
| 68 |
<input type="text" name="dashboard_login_url" id="ticket-dashboard-login-url" class="basalam-input create-ticket__input"> |
| 69 |
</div> |
| 70 |
<div class="create-ticket__control"> |
| 71 |
<label for="ticket-dashboard-username" class="create-ticket__label basalam-p">نا� |
| 72 |
کاربری پیشخوان</label> |
| 73 |
<input type="text" name="dashboard_username" id="ticket-dashboard-username" class="basalam-input create-ticket__input"> |
| 74 |
</div> |
| 75 |
<div class="create-ticket__control"> |
| 76 |
<label for="ticket-dashboard-password" class="create-ticket__label basalam-p">ر� |
| 77 |
ز عبور پیشخوان</label> |
| 78 |
<input type="password" name="dashboard_password" id="ticket-dashboard-password" class="basalam-input create-ticket__input" autocomplete="new-password" spellcheck="false"> |
| 79 |
</div> |
| 80 |
</div> |
| 81 |
|
| 82 |
<div class="ticket-access-card ticket-access-card--host-panel"> |
| 83 |
<p class="ticket-access-card__title basalam-p">کنترل پنل هاست</p> |
| 84 |
<div class="create-ticket__control"> |
| 85 |
<label for="ticket-host-panel-login-url" class="create-ticket__label basalam-p">آدرس لاگین کنترل پنل هاست</label> |
| 86 |
<input type="text" name="host_panel_login_url" id="ticket-host-panel-login-url" class="basalam-input create-ticket__input"> |
| 87 |
</div> |
| 88 |
<div class="create-ticket__control"> |
| 89 |
<label for="ticket-host-panel-username" class="create-ticket__label basalam-p">نا� |
| 90 |
کاربری کنترل پنل هاست</label> |
| 91 |
<input type="text" name="host_panel_username" id="ticket-host-panel-username" class="basalam-input create-ticket__input"> |
| 92 |
</div> |
| 93 |
<div class="create-ticket__control"> |
| 94 |
<label for="ticket-host-panel-password" class="create-ticket__label basalam-p">ر� |
| 95 |
ز عبور کنترل پنل هاست</label> |
| 96 |
<input type="password" name="host_panel_password" id="ticket-host-panel-password" class="basalam-input create-ticket__input" autocomplete="new-password" spellcheck="false"> |
| 97 |
</div> |
| 98 |
</div> |
| 99 |
</div> |
| 100 |
</div> |
| 101 |
<?php endif; ?> |
| 102 |
|
| 103 |
<div class="ticket-items__answer-control"> |
| 104 |
<label class="ticket-items__answer-control-label basalam-p">پیوست تصویر (اختیاری)</label> |
| 105 |
<div class="ticket-file-upload" id="ticket-file-upload-reply"> |
| 106 |
<label for="ticket-file-reply" class="ticket-file-upload__label"> |
| 107 |
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> |
| 108 |
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" /> |
| 109 |
<polyline points="17 8 12 3 7 8" /> |
| 110 |
<line x1="12" y1="3" x2="12" y2="15" /> |
| 111 |
</svg> |
| 112 |
انتخاب تصویر |
| 113 |
</label> |
| 114 |
<input type="file" name="_ticket_file" id="ticket-file-reply" class="ticket-file-upload__input" accept="image/jpeg,image/png,image/webp,image/bmp,image/avif"> |
| 115 |
<div class="ticket-file-upload__previews"></div> |
| 116 |
</div> |
| 117 |
</div> |
| 118 |
<div class="ticket-items__answer-actions"> |
| 119 |
<button type="submit" class="ticket-items__answer-submit basalam-primary-button">ارسال</button> |
| 120 |
</div> |
| 121 |
</div> |
| 122 |
</form> |
| 123 |
<?php endif; ?> |
| 124 |
</div> |
| 125 |
<div class="ticket-items"> |
| 126 |
<?php |
| 127 |
foreach ($ticket['data']['items'] as $ticketItem) { |
| 128 |
if ($ticketItem['type'] != 'content') continue; |
| 129 |
$isAdmin = $ticketItem['user']['is_admin']; |
| 130 |
$creatorUser = TicketUserResolver::getLabel($ticketItem['user']); |
| 131 |
?> |
| 132 |
<div class="ticket-items__item-wrapper"> |
| 133 |
<div class="ticket-items__item <?php if ($isAdmin) echo 'ticket-items__item--admin' ?>"> |
| 134 |
<div class="ticket-items__item-stats"> |
| 135 |
<p class="ticket-items__item-name basalam-p"><?php echo esc_html($creatorUser); ?></p> |
| 136 |
|
| 137 |
<p class="ticket-items__item-date basalam-p"> |
| 138 |
<?php echo esc_html(DateConverter::utcToJalaliDateTime($ticketItem['created_at'])) ?> |
| 139 |
</p> |
| 140 |
</div> |
| 141 |
|
| 142 |
<div class="ticket-items__item-content-wrapper"> |
| 143 |
<p class="ticket-items__item-content basalam-p"> |
| 144 |
<?php echo esc_html($ticketItem['content']) ?> |
| 145 |
</p> |
| 146 |
<?php |
| 147 |
$itemFiles = $ticketItem['files'] ?? $ticketItem['media'] ?? $ticketItem['attachments'] ?? []; |
| 148 |
if (!empty($itemFiles)): |
| 149 |
?> |
| 150 |
<div class="ticket-items__item-files"> |
| 151 |
<?php foreach ($itemFiles as $file): |
| 152 |
$fileUrl = $file['url'] ?? $file['path'] ?? null; |
| 153 |
if (!$fileUrl) continue; |
| 154 |
?> |
| 155 |
<a href="<?php echo esc_url($fileUrl); ?>" target="_blank" class="ticket-items__item-file-link"> |
| 156 |
<img src="<?php echo esc_url($fileUrl); ?>" alt="" class="ticket-items__item-file-img"> |
| 157 |
</a> |
| 158 |
<?php endforeach; ?> |
| 159 |
</div> |
| 160 |
<?php endif; ?> |
| 161 |
</div> |
| 162 |
</div> |
| 163 |
</div> |
| 164 |
<?php |
| 165 |
} |
| 166 |
?> |
| 167 |
</div> |
| 168 |
</div> |
| 169 |
<?php if (!$isTicketClosed): ?> |
| 170 |
<script> |
| 171 |
document.addEventListener('DOMContentLoaded', function() { |
| 172 |
ticketFileUpload('ticket-file-reply', '<?php echo esc_attr(wp_create_nonce('upload_ticket_media_nonce')); ?>'); |
| 173 |
}); |
| 174 |
</script> |
| 175 |
<?php endif; ?> |
| 176 |
|