'Internal note', 1 => 'Public note', 2 => 'Email reply', 3 => 'Text reply']; /** Whether the 4.0.1 update has run - the ticket_reply_drafts table. */ function ticketReplyDraftsReady() { global $mysqli; static $ready = null; if ($ready === null) { if (defined('CURRENT_DATABASE_VERSION')) { $version = CURRENT_DATABASE_VERSION; } else { $result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings WHERE company_id = 1"); $version = $result && ($row = mysqli_fetch_row($result)) ? (string) $row[0] : '0'; } $ready = version_compare($version, '4.0.1', '>='); } return $ready; } /** Whether the 4.4.0 update has run - a draft keeps how it was to go (draft_type). */ function ticketReplyDraftTypeReady() { global $mysqli; static $ready = null; if ($ready === null) { $version = defined('CURRENT_DATABASE_VERSION') ? CURRENT_DATABASE_VERSION : (string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT config_current_database_version FROM settings WHERE company_id = 1"))[0] ?? '0'); $ready = version_compare($version, '4.4.0', '>='); } return $ready; } /** An agent's draft on a ticket - ['body' (HTML, as typed), 'type' (public_reply_type, or null), 'updated_at'] - or null. */ function ticketReplyDraft($ticket_id, $user_id) { global $mysqli; if (!ticketReplyDraftsReady()) { return null; } $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT draft_body, " . (ticketReplyDraftTypeReady() ? 'draft_type' : 'NULL AS draft_type') . ", draft_updated_at FROM ticket_reply_drafts WHERE ticket_id = " . intval($ticket_id) . " AND user_id = " . intval($user_id) . " LIMIT 1")); return $row ? ['body' => (string) $row['draft_body'], 'type' => $row['draft_type'] !== null ? intval($row['draft_type']) : null, 'updated_at' => $row['draft_updated_at']] : null; } /* * Keep an agent's draft - made safe first - and how it was to go, $type (public_reply_type; null keeps what it had). * Nothing worth keeping (no words, no picture) drops it. */ function ticketReplyDraftSave($ticket_id, $user_id, $html, $type = null) { global $mysqli; if (!ticketReplyDraftsReady()) { return false; } $html = documentHtmlPurify((string) $html); $words = trim(html_entity_decode(strip_tags($html), ENT_QUOTES, 'UTF-8'), " \t\n\r\0\x0B\xC2\xA0"); if ($words === '' && stripos($html, '