From ffcd4b5e50eed56f0722da8eb9c10ffa9c693218 Mon Sep 17 00:00:00 2001 From: JediKev <kevin@enhancesoft.com> Date: Mon, 19 Nov 2018 10:05:09 -0600 Subject: [PATCH] feature: Complete Thread Variable Support using %{ticket.thread} to export the entire ticket thread correspondence between agents and end users (owner + collaborators). --- include/class.file.php | 12 +++ include/class.thread.php | 19 ++++ .../client/templates/thread-export.tmpl.php | 93 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 include/client/templates/thread-export.tmpl.php diff --git a/include/class.file.php b/include/class.file.php index 5bbd3d885..419a28209 100644 --- a/include/class.file.php +++ b/include/class.file.php @@ -197,6 +197,18 @@ class AttachmentFile extends VerySimpleModel { $options); } + // Generates full download URL for external sources. + // e.g. https://domain.tld/file.php?args=123 + function getExternalDownloadUrl($options=array()) { + global $cfg; + + $download = self::getDownloadUrl($options); + // Separate URL handle and args + list($handle, $args) = explode('file.php?', $download); + + return (string) rtrim($cfg->getBaseUrl(), '/').'/file.php?'.$args; + } + static function generateDownloadUrl($id, $key, $hash, $options = array()) { // Expire at the nearest midnight, allow at least12 hrs access diff --git a/include/class.thread.php b/include/class.thread.php index 9488835a3..343b3e900 100644 --- a/include/class.thread.php +++ b/include/class.thread.php @@ -2964,6 +2964,14 @@ implements TemplateVariable { return $resp; } + function __toString() { + return $this->asVar(); + } + + function asVar() { + return $this->getVar('complete'); + } + function getVar($name) { switch ($name) { case 'original': @@ -2983,12 +2991,23 @@ implements TemplateVariable { if ($entry) return $entry->getBody(); + break; + case 'complete': + $content = ''; + $thread = $this; + ob_start(); + include INCLUDE_DIR.'client/templates/thread-export.tmpl.php'; + $content = ob_get_contents(); + ob_end_clean(); + return $content; + break; } } static function getVarScope() { return array( + 'complete' => __('Thread Correspondence'), 'original' => array('class' => 'MessageThreadEntry', 'desc' => __('Original Message')), 'lastmessage' => array('class' => 'MessageThreadEntry', 'desc' => __('Last Message')), ); diff --git a/include/client/templates/thread-export.tmpl.php b/include/client/templates/thread-export.tmpl.php new file mode 100644 index 000000000..5914a88da --- /dev/null +++ b/include/client/templates/thread-export.tmpl.php @@ -0,0 +1,93 @@ +<?php +global $cfg; + +$entryTypes = array( + 'M' => array('color' => '#0088cc'), + 'R' => array('color' => '#e65524'), + ); + +AttachmentFile::objects()->filter(array( + 'attachments__thread_entry__thread__id' => $thread->getId(), + 'attachments__thread_entry__type__in' => array_keys($entryTypes) + ))->all(); + +$entries = $thread->getEntries(); +$entries->filter(array('type__in' => array_keys($entryTypes))); +?> +<style type="text/css"> + div {font-family: sans-serif;} +</style> +<div style="width: 100%; margin: 0; padding: 0;"> + <div style="padding:10px;"> + <p style="font-family: sans-serif; font-size:12px; color:#999;"> </p> + </div> + <table width="100%" cellpadding="0" cellspacing="0" border="0"> + <tbody> + <tr> + <td></td> + </tr> + <?php + foreach ($entries as $entry) { + $user = $entry->getUser() ?: $entry->getStaff(); + $name = $user ? $user->getName() : $entry->poster; + $color = $entryTypes[$entry->type]['color']; + ?> + <tr> + <td style=" border-top: 1px dashed #999;"> + <div style="background-color:#f7f7f7; padding:10px 20px;"> + <p style="font-family: sans-serif; padding:0; margin:0; color:<?php echo $color; ?>;"> + <strong><?php echo $name; ?></strong> + <span style="color:#888; font-size:12px; padding-left: 20px;"><?php + echo $entry->title; + ?> + </span> + </p> + <p style="font-family: sans-serif; padding:0; margin:0; color:#888; font-size:12px;"> + <?php + echo Format::daydatetime($entry->created); + ?> + </p> + </div> + <div style="padding:2px 20px;"> + <p style="font-family: sans-serif; font-size:14px; color:#555;"> + <?php + echo $entry->getBody()->display('email'); + ?> + </p> + <?php + if ($entry->has_attachments) { ?> + <p style="font-family: sans-serif; font-size:12px; line-height:20px; color:#888;"> + <?php echo __('Attachments'); ?> + <br /> + <?php + foreach ($entry->attachments as $a) { + if ($a->inline) continue; + $size = ''; + if ($a->file->size) + $size = sprintf('<small style="color:#ccc;"> (%s)</small>', + Format::file_size($a->file->size)); + + $filename = Format::htmlchars($a->getFilename()); + echo sprintf('<a href="%s" download="%s" + style="font-size:11px; color:#0088cc;" + target="_blank">%s</a> %s<br/>', + $a->file->getExternalDownloadUrl(), + $filename, + $filename, + $size); + } + ?> + </p> + <?php + } ?> + </div> + </td> + </tr> + <?php + } ?> + </tbody> + </table> + <div style="font-family: sans-serif; margin: 2px 0 14px 0; padding: 10px ; border-top: 1px solid #999; font-size:12px; color:#888;"> + + </div> +</div> -- GitLab