Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

manage_email_templates.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?php
  2. define('IN_SCRIPT', 1);
  3. define('HESK_PATH', '../');
  4. define('PAGE_TITLE', 'ADMIN_EMAIL_TEMPLATES');
  5. define('MFH_PAGE_LAYOUT', 'TOP_ONLY');
  6. /* Get all the required files and functions */
  7. require(HESK_PATH . 'hesk_settings.inc.php');
  8. require(HESK_PATH . 'inc/common.inc.php');
  9. require(HESK_PATH . 'inc/admin_functions.inc.php');
  10. require(HESK_PATH . 'inc/mail_functions.inc.php');
  11. require(HESK_PATH . 'inc/custom_fields.inc.php');
  12. hesk_load_database_functions();
  13. hesk_session_start();
  14. hesk_dbConnect();
  15. hesk_isLoggedIn();
  16. hesk_checkPermission('can_man_email_tpl');
  17. define('WYSIWYG', 1);
  18. // Are we performing an action?
  19. $showEditPanel = false;
  20. if (isset($_GET['action'])) {
  21. if ($_GET['action'] == 'edit') {
  22. $showEditPanel = true;
  23. }
  24. }
  25. // Are we saving?
  26. if (isset($_POST['action'])) {
  27. if ($_POST['action'] == 'save') {
  28. save();
  29. }
  30. }
  31. /* Print header */
  32. require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
  33. if ($modsForHesk_settings['html_emails']) {
  34. ?>
  35. <script type="text/javascript">
  36. /* <![CDATA[ */
  37. $(document).ready(function() {
  38. $('.htmlEditor').summernote({
  39. height: 200,
  40. toolbar: [
  41. ['style', ['bold', 'italic', 'underline', 'clear']],
  42. ['font', ['strikethrough', 'superscript', 'subscript']],
  43. ['para', ['ul', 'ol']]
  44. ]
  45. });
  46. });
  47. /* ]]> */
  48. </script>
  49. <?php
  50. }
  51. /* Print main manage users page */
  52. require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
  53. ?>
  54. <div class="content-wrapper">
  55. <section class="content">
  56. <div class="box">
  57. <div class="box-body">
  58. <div class="nav-tabs-custom">
  59. <ul class="nav nav-tabs" role="tablist">
  60. <?php
  61. // Show a link to banned_emails.php if user has permission
  62. if (hesk_checkPermission('can_ban_emails', 0)) {
  63. echo '
  64. <li role="presentation">
  65. <a title="' . $hesklang['banemail'] . '" href="banned_emails.php">' . $hesklang['banemail'] . '</a>
  66. </li>
  67. ';
  68. }
  69. if (hesk_checkPermission('can_ban_ips', 0)) {
  70. echo '
  71. <li role="presentation">
  72. <a title="' . $hesklang['banip'] . '" href="banned_ips.php">' . $hesklang['banip'] . '</a>
  73. </li>';
  74. }
  75. // Show a link to status_message.php if user has permission to do so
  76. if (hesk_checkPermission('can_service_msg', 0)) {
  77. echo '
  78. <li role="presentation">
  79. <a title="' . $hesklang['sm_title'] . '" href="service_messages.php">' . $hesklang['sm_title'] . '</a>
  80. </li>';
  81. }
  82. ?>
  83. <li role="presentation" class="active">
  84. <a href="#"><?php echo $hesklang['email_templates']; ?> <i
  85. class="fa fa-question-circle settingsquestionmark" data-toggle="popover"
  86. title="<?php echo $hesklang['email_templates']; ?>"
  87. data-content="<?php echo $hesklang['email_templates_intro']; ?>"></i></a>
  88. </li>
  89. <?php
  90. if (hesk_checkPermission('can_man_ticket_statuses', 0)) {
  91. echo '
  92. <li role="presentation">
  93. <a title="' . $hesklang['statuses'] . '" href="manage_statuses.php">' . $hesklang['statuses'] . '</a>
  94. </li>
  95. ';
  96. }
  97. if (hesk_checkPermission('can_man_settings', 0)) {
  98. echo '
  99. <li role="presentation">
  100. <a title="' . $hesklang['tab_4'] . '" href="custom_fields.php">' .
  101. $hesklang['tab_4']
  102. . '</a>
  103. </li>
  104. ';
  105. }
  106. ?>
  107. </ul>
  108. <div class="tab-content summaryList tabPadding">
  109. <?php if ($showEditPanel): ?>
  110. <div class="row">
  111. <div class="col-md-12">
  112. <div class="panel panel-default">
  113. <div class="panel-heading">
  114. <h4>
  115. <?php
  116. $isHtml = ($_GET['html'] == 'true');
  117. $class = 'plaintext-editor';
  118. if ($isHtml) {
  119. $class = 'htmlEditor';
  120. echo sprintf($hesklang['editing_html_template'], $_GET['template']);
  121. } else {
  122. echo sprintf($hesklang['editing_plain_text_template'], $_GET['template']);
  123. } ?>
  124. </h4>
  125. </div>
  126. <div class="panel-body">
  127. <?php
  128. $fileContent = '';
  129. if ($isHtml) {
  130. $fileContent = file_get_contents(HESK_PATH . 'language/' . urldecode($_GET['language']) . '/emails/html/' . $_GET['template']);
  131. } else {
  132. $fileContent = file_get_contents(HESK_PATH . 'language/' . urldecode($_GET['language']) . '/emails/' . $_GET['template']);
  133. }
  134. if ($fileContent === false) {
  135. //throw error
  136. }
  137. ?>
  138. <a href="#" id="showSpecialTags"
  139. onclick="toggleContainers(['specialTags'],['showSpecialTags'])">
  140. <?php echo $hesklang['show_special_tags']; ?>
  141. </a>
  142. <div id="specialTags" style="display: none">
  143. <a href="#" onclick="toggleContainers(['showSpecialTags'],['specialTags'])">
  144. <?php echo $hesklang['hide_special_tags']; ?>
  145. </a>
  146. <table class="table table-striped table-responsive table-condensed">
  147. <thead>
  148. <tr>
  149. <th><?php echo $hesklang['special_tag']; ?></th>
  150. <th><?php echo $hesklang['description'] ?></th>
  151. </tr>
  152. </thead>
  153. <tbody>
  154. <?php
  155. $tags = getSpecialTagMap();
  156. foreach ($tags as $tag => $text): ?>
  157. <tr>
  158. <td><?php echo $tag; ?></td>
  159. <td><?php echo $text; ?></td>
  160. </tr>
  161. <?php endforeach; ?>
  162. </tbody>
  163. </table>
  164. </div>
  165. <form action="manage_email_templates.php" method="post">
  166. <textarea name="text" rows="15"
  167. class="form-control <?php echo $class; ?>"><?php echo $fileContent; ?></textarea>
  168. <input type="hidden" name="action" value="save">
  169. <input type="hidden" name="template"
  170. value="<?php echo htmlspecialchars($_GET['template']); ?>">
  171. <input type="hidden" name="language"
  172. value="<?php echo htmlspecialchars($_GET['language']); ?>">
  173. <input type="hidden" name="html" value="<?php echo $isHtml; ?>">
  174. <br>
  175. <?php
  176. $fileWritable = false;
  177. if ($isHtml) {
  178. $fileWritable = is_writable(HESK_PATH . 'language/' . $_GET['language'] . '/emails/html/' . $_GET['template']);
  179. } else {
  180. $fileWritable = is_writable(HESK_PATH . 'language/' . $_GET['language'] . '/emails/' . $_GET['template']);
  181. }
  182. if (!$fileWritable) {
  183. echo '<div class="alert alert-danger">
  184. <p>' . sprintf($hesklang['email_template_directory_not_writable'], $_GET['template']) . '</p>
  185. </div>';
  186. } else {
  187. echo '<input type="submit" class="btn btn-default" value="' . $hesklang['save'] . '">';
  188. }
  189. ?>
  190. </form>
  191. </div>
  192. </div>
  193. </div>
  194. </div>
  195. <?php endif; ?>
  196. <div class="row">
  197. <div class="col-md-12">
  198. <?php
  199. /* This will handle error, success and notice messages */
  200. hesk_handle_messages();
  201. // Output list of templates, and provide links to edit the plaintext and HTML versions for each language
  202. // First get list of languages
  203. $languages = array();
  204. foreach ($hesk_settings['languages'] as $key => $value) {
  205. $languages[$key] = $hesk_settings['languages'][$key]['folder'];
  206. }
  207. // Get all files, but don't worry about index.htm, items beginning with '.', or the html folder
  208. // We'll also assume the template file exists in all language folders and in the html folder
  209. reset($languages);
  210. $firstKey = key($languages);
  211. $firstDirectory = HESK_PATH . 'language/' . $languages[$firstKey] . '/emails';
  212. $directoryListing = preg_grep('/^([^.])/', scandir($firstDirectory));
  213. $emailTemplates = array_diff($directoryListing, array('html', 'index.htm'));
  214. ?>
  215. <table class="table table-striped table-responsive">
  216. <thead>
  217. <tr>
  218. <th><?php echo $hesklang['file_name']; ?></th>
  219. <?php foreach ($languages as $language => $languageCode): ?>
  220. <th><?php echo $language; ?></th>
  221. <?php endforeach; ?>
  222. </tr>
  223. </thead>
  224. <tbody>
  225. <?php foreach ($emailTemplates as $template): ?>
  226. <tr>
  227. <td><?php echo $template; ?></td>
  228. <?php foreach ($languages as $language => $languageCode): ?>
  229. <td>
  230. <?php
  231. echo getTemplateMarkup($template, $languageCode);
  232. echo '&nbsp;&nbsp;&nbsp;';
  233. if ($modsForHesk_settings['html_emails']) {
  234. echo getTemplateMarkup($template, $languageCode, true);
  235. }
  236. ?>
  237. </td>
  238. <?php endforeach; ?>
  239. </tr>
  240. <?php endforeach; ?>
  241. </tbody>
  242. </table>
  243. </div>
  244. </div>
  245. </div>
  246. </div>
  247. </div>
  248. </div>
  249. </section>
  250. </div>
  251. <?php
  252. require_once(HESK_PATH . 'inc/footer.inc.php');
  253. exit();
  254. function getTemplateMarkup($template, $languageCode, $html = false)
  255. {
  256. global $hesklang;
  257. $templateUrl = urlencode($template);
  258. $languageCodeUrl = urlencode($languageCode);
  259. if ($html) {
  260. $markup = '<a name="Edit '.$templateUrl.'" href="manage_email_templates.php?action=edit&template=' . $templateUrl . '&language=' . $languageCodeUrl . '&html=true">';
  261. $markup .= '<i class="fa fa-html5 font-size-150" data-toggle="tooltip" title="' . $hesklang['edit_html_template'] . '"></i>';
  262. $markup .= '</a>';
  263. return $markup;
  264. } else {
  265. $markup = '<a name="Edit '.$templateUrl.'" href="manage_email_templates.php?action=edit&template=' . $templateUrl . '&language=' . $languageCodeUrl . '&html=false">';
  266. $markup .= '<i class="fa fa-file-text-o font-size-150" data-toggle="tooltip" title="' . $hesklang['edit_plain_text_template'] . '"></i>';
  267. $markup .= '</a>';
  268. return $markup;
  269. }
  270. }
  271. function save()
  272. {
  273. global $hesklang;
  274. $filePath = HESK_PATH . 'language/' . $_POST['language'] . '/emails/' . $_POST['template'];
  275. if ($_POST['html'] == '1') {
  276. $filePath = HESK_PATH . 'language/' . $_POST['language'] . '/emails/html/' . $_POST['template'];
  277. }
  278. $success = file_put_contents($filePath, $_POST['text']);
  279. if ($success === false) {
  280. hesk_process_messages($hesklang['email_template_not_saved'], 'manage_email_templates.php');
  281. } else {
  282. $message = sprintf($hesklang['email_template_saved'], $_POST['template']);
  283. hesk_process_messages($message, 'manage_email_templates.php', 'SUCCESS');
  284. }
  285. }
  286. function getSpecialTagMap()
  287. {
  288. global $hesk_settings, $modsForHesk_settings, $hesklang;
  289. $map = array();
  290. $map['%%NAME%%'] = $hesklang['customer_name'];
  291. $map['%%FIRST_NAME%%'] = $hesklang['fname'];
  292. $map['%%EMAIL%%'] = $hesklang['customer_email'];
  293. $map['%%SUBJECT%%'] = $hesklang['ticket_subject'];
  294. $map['%%MESSAGE%%'] = $hesklang['ticket_message'];
  295. $map['%%MESSAGE_NO_ATTACHMENTS%%'] = $hesklang['ticket_message_no_attachments'];
  296. $map['%%CREATED%%'] = $hesklang['ticket_created'];
  297. $map['%%UPDATED%%'] = $hesklang['ticket_updated'];
  298. $map['%%TRACK_ID%%'] = $hesklang['ticket_trackID'];
  299. $map['%%TRACK_URL%%'] = $hesklang['ticket_url'];
  300. $map['%%SITE_TITLE%%'] = $hesklang['wbst_title'];
  301. $map['%%SITE_URL%%'] = $hesklang['wbst_url'];
  302. $map['%%CATEGORY%%'] = $hesklang['ticket_category'];
  303. $map['%%OWNER%%'] = $hesklang['ticket_owner'];
  304. $map['%%PRIORITY%%'] = $hesklang['ticket_priority'];
  305. $map['%%STATUS%%'] = $hesklang['ticket_status'];
  306. $map['%%LAST_REPLY_BY%%'] = $hesklang['last_replier'];
  307. $map['%%TIME_WORKED%%'] = $hesklang['ts'];
  308. $i = 1;
  309. foreach ($hesk_settings['custom_fields'] as $key => $value) {
  310. if ($value['use']) {
  311. $uppercaseKey = strtoupper($key);
  312. $map['%%' . $uppercaseKey . '%%'] = sprintf($hesklang['custom_field_x'], $i++);
  313. }
  314. }
  315. return $map;
  316. }