Canned Responses - your own canned responses, offered to you * alone (first in the picker, as Yours), and the shared ones from Admin > * Canned Responses, offered to everyone. Yours are made here, copied from a * shared one, or saved from a reply on a ticket (Save your reply as a canned response, in * the picker); each can be changed, copied, archived - not offered - or * deleted. How often each went into a reply is yours alone. An admin can * share one of theirs with everyone (admin/post/canned_response.php). The * work is in functions/canned_response.php; the handlers are * agent/user/post/canned_response.php. */ // Default Column Sortby Filter $sort = "canned_response_name"; $order = "ASC"; require_once "includes/inc_all_user.php"; enforceUserPermission('module_support', 2); $user_id = intval($session_user_id); // The views: your own, archived or not, and the shared ones offered now $views = [ '' => ['label' => 'Yours', 'icon' => 'fa-user', 'where' => "canned_response_user_id = $user_id", 'title' => 'Offered to you alone - first in the picker'], 'shared' => ['label' => 'Shared', 'icon' => 'fa-users', 'where' => "canned_response_user_id = 0 AND canned_response_archived_at IS NULL", 'title' => 'Offered to everyone - copy one to make it yours'], ]; $show = (string) ($_GET['show'] ?? ''); $show = isset($views[$show]) ? $show : ''; $yours = $show === ''; // Where it is offered: any, every ticket (no category), or one ticket category $category_filter = (string) ($_GET['category'] ?? ''); $category_filter = $category_filter === 'every' || intval($category_filter) > 0 ? ($category_filter === 'every' ? 'every' : (string) intval($category_filter)) : ''; // Only these sort - an unknown column would take the page down $sortable_columns = [ 'canned_response_name' => "canned_response_name $order", 'use_count' => "use_count $order, canned_response_name ASC", 'last_used' => "last_used IS NULL, last_used $order, canned_response_name ASC", ]; if (!isset($sortable_columns[$sort])) { $sort = 'canned_response_name'; } $filters = "(canned_response_name LIKE '%$q%' OR canned_response_body LIKE '%$q%')"; if ($category_filter === 'every') { $filters .= " AND NOT EXISTS (SELECT 1 FROM canned_response_categories c WHERE c.canned_response_id = canned_responses.canned_response_id)"; } elseif ($category_filter !== '') { $filters .= " AND EXISTS (SELECT 1 FROM canned_response_categories c WHERE c.canned_response_id = canned_responses.canned_response_id AND c.category_id = " . intval($category_filter) . ")"; } // How often each went into a reply of yours $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS canned_responses.canned_response_id, canned_response_name, canned_response_body, canned_response_reply_type, canned_response_ticket_status, canned_response_minutes, canned_response_user_id, canned_response_created_at, canned_response_updated_at, canned_response_archived_at, COALESCE(used.use_count, 0) AS use_count, used.last_used FROM canned_responses LEFT JOIN ( SELECT canned_response_use_canned_response_id AS used_id, COUNT(*) AS use_count, MAX(canned_response_use_created_at) AS last_used FROM canned_response_uses WHERE canned_response_use_user_id = $user_id GROUP BY canned_response_use_canned_response_id ) used ON used.used_id = canned_responses.canned_response_id WHERE $filters AND {$views[$show]['where']} ORDER BY {$sortable_columns[$sort]}, canned_responses.canned_response_id ASC LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $responses = []; while ($row = mysqli_fetch_assoc($sql)) { $responses[intval($row['canned_response_id'])] = $row; } $response_categories = cannedResponseCategoriesFor(array_keys($responses)); $response_files = cannedResponseFilesFor(array_keys($responses)); $counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', array_map(function ($view) { return "COALESCE(SUM({$view['where']}), 0)"; }, $views)) . " FROM canned_responses WHERE $filters")); $view_counts = array_combine(array_keys($views), $counts); $sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) { return '' . $label . ($sort === $column ? " $order_icon" : '') . ''; }; $pill_url = function ($view) use ($category_filter) { return '?' . http_build_query(array_filter(['q' => $_GET['q'] ?? '', 'category' => $category_filter, 'show' => $view])); }; $add_url = 'modals/canned_response_add.php' . (intval($category_filter) > 0 ? '?category=' . intval($category_filter) : ''); $csrf = $_SESSION['csrf_token']; ?>
| = $sort_link('canned_response_name', 'Response') ?> | Offered on | = $sort_link('use_count', 'You used it') ?> | = $sort_link('last_used', 'Last used') ?> | |
|---|---|---|---|---|
|
= $name ?>
= $name ?>
= escapeHtml($preview) ?>
= $sets_up ?>
= count($files) ?> file= count($files) === 1 ? '' : 's' ?>
Archived = date('M j, Y', strtotime($row['canned_response_archived_at'])) ?> - not offered
= $offered_html ?>
= $use_count ? 'You used it ' . $used_text . ' ยท last ' . timeAgo($row['last_used']) : 'Not used by you yet' ?>
|
= $offered_html ?> | = $use_count ? $used_text : 'Not yet' ?> | >= $row['last_used'] ? timeAgo($row['last_used']) : '-' ?> |
|