Can now edit and save email templates 😀

merge-requests/2/head
Mike Koch 9 years ago
parent 685bf6b008
commit 5b68f5f926

@ -16,6 +16,21 @@ hesk_isLoggedIn();
// TODO Check permissions for this feature // TODO Check permissions for this feature
define('WYSIWYG',1); define('WYSIWYG',1);
// Are we performing an action?
$showEditPanel = false;
if (isset($_GET['action'])) {
if ($_GET['action'] == 'edit') {
$showEditPanel = true;
}
}
// Are we saving?
if (isset($_POST['action'])) {
if ($_POST['action'] == 'save') {
save();
}
}
/* Print header */ /* Print header */
require_once(HESK_PATH . 'inc/headerAdmin.inc.php'); require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
@ -78,6 +93,90 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
</li> </li>
</ul> </ul>
<div class="tab-content summaryList tabPadding"> <div class="tab-content summaryList tabPadding">
<?php if ($showEditPanel): ?>
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<h4>
<?php
$isHtml = ($_GET['html'] == 'true');
$class = 'plaintext-editor';
if ($isHtml) {
$class = 'htmlEditor';
echo sprintf($hesklang['editing_html_template'], $_GET['template']);
} else {
echo sprintf($hesklang['editing_plain_text_template'], $_GET['template']);
} ?>
</h4>
</div>
<div class="panel-body">
<?php
$fileContent = '';
if ($isHtml) {
$fileContent = file_get_contents(HESK_PATH . 'language/'.urldecode($_GET['language']).'/emails/html/'.$_GET['template']);
} else {
$fileContent = file_get_contents(HESK_PATH . 'language/'.urldecode($_GET['language']).'/emails/'.$_GET['template']);
}
if ($fileContent === false) {
//throw error
}
?>
<a href="#" id="showSpecialTags" onclick="toggleContainers(['specialTags'],['showSpecialTags'])">
<?php echo $hesklang['show_special_tags']; ?>
</a>
<div id="specialTags" style="display: none">
<a href="#" onclick="toggleContainers(['showSpecialTags'],['specialTags'])">
<?php echo $hesklang['hide_special_tags']; ?>
</a>
<table class="table table-striped table-responsive table-condensed">
<thead>
<tr>
<th><?php echo $hesklang['special_tag']; ?></th>
<th><?php echo $hesklang['description'] ?></th>
</tr>
</thead>
<tbody>
<?php
$tags = getSpecialTagMap();
foreach ($tags as $tag => $text): ?>
<tr>
<td><?php echo $tag; ?></td>
<td><?php echo $text; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<form action="manage_email_templates.php" method="post">
<textarea name="text" rows="15" class="form-control <?php echo $class; ?>"><?php echo $fileContent; ?></textarea>
<input type="hidden" name="action" value="save">
<input type="hidden" name="template" value="<?php echo htmlspecialchars($_GET['template']); ?>">
<input type="hidden" name="language" value="<?php echo htmlspecialchars($_GET['language']); ?>">
<input type="hidden" name="html" value="<?php echo $isHtml; ?>">
<br>
<?php
$fileWritable = false;
if ($isHtml) {
$fileWritable = is_writable(HESK_PATH.'language/'.$_GET['language'].'/emails/html/'.$_GET['template']);
} else {
$fileWritable = is_writable(HESK_PATH.'language/'.$_GET['language'].'/emails'.$_GET['template']);
}
if (!$fileWritable) {
echo '<div class="alert alert-danger">
<p>'.sprintf($hesklang['email_template_directory_not_writable'], $_GET['template']).'</p>
</div>';
} else {
echo '<input type="submit" class="btn btn-default" value="'.$hesklang['save'].'">';
}
?>
</form>
</div>
</div>
</div>
</div>
<?php endif; ?>
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">
<?php <?php
@ -104,8 +203,8 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
<thead> <thead>
<tr> <tr>
<th><?php echo $hesklang['file_name']; ?></th> <th><?php echo $hesklang['file_name']; ?></th>
<?php foreach ($languages as $key=>$value): ?> <?php foreach ($languages as $language => $languageCode): ?>
<th><?php echo $key; ?></th> <th><?php echo $language; ?></th>
<?php endforeach; ?> <?php endforeach; ?>
</tr> </tr>
</thead> </thead>
@ -113,15 +212,17 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
<?php foreach ($emailTemplates as $template): ?> <?php foreach ($emailTemplates as $template): ?>
<tr> <tr>
<td><?php echo $template; ?></td> <td><?php echo $template; ?></td>
<?php foreach ($languages as $language => $languageCode): ?>
<td> <td>
<?php <?php
echo getTemplateMarkup($template, 'en'); echo getTemplateMarkup($template, $languageCode);
echo '&nbsp;&nbsp;&nbsp;'; echo '&nbsp;&nbsp;&nbsp;';
if ($modsForHesk_settings['html_emails']) { if ($modsForHesk_settings['html_emails']) {
echo getTemplateMarkup($template, 'en', true); echo getTemplateMarkup($template, $languageCode, true);
} }
?> ?>
</td> </td>
<?php endforeach; ?>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
@ -130,13 +231,6 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
</div> </div>
</div> </div>
</div> </div>
<!-- Output markup for the modals -->
<?php foreach ($emailTemplates as $template) {
echo getModalMarkup($template, 'en');
if ($modsForHesk_settings['html_emails']) {
echo getModalMarkup($template, 'en', true);
}
} ?>
<?php <?php
require_once(HESK_PATH . 'inc/footer.inc.php'); require_once(HESK_PATH . 'inc/footer.inc.php');
@ -145,57 +239,64 @@ exit();
function getTemplateMarkup($template, $languageCode, $html = false) { function getTemplateMarkup($template, $languageCode, $html = false) {
global $hesklang; global $hesklang;
$templateId = str_replace('.', '-', $template); $templateUrl = urlencode($template);
$templateId = str_replace(' ', '-', $templateId); $languageCodeUrl = urlencode($languageCode);
$languageCodeId = str_replace('.', '-', $languageCode);
$languageCodeId = str_replace(' ', '-', $languageCodeId);
if ($html) { if ($html) {
$markup = '<a href="#" data-toggle="modal" data-target="#modal-html-'.$languageCodeId.'-'.$templateId.'">'; $markup = '<a href="manage_email_templates.php?action=edit&template='.$templateUrl.'&language='.$languageCodeUrl.'&html=true">';
$markup .= '<i class="fa fa-html5" style="font-size: 1.5em" data-toggle="tooltip" title="'.$hesklang['edit_html_template'].'"></i>'; $markup .= '<i class="fa fa-html5" style="font-size: 1.5em" data-toggle="tooltip" title="'.$hesklang['edit_html_template'].'"></i>';
$markup .= '</a>'; $markup .= '</a>';
return $markup; return $markup;
} else { } else {
$markup = '<a href="#" data-toggle="modal" data-target="#modal-'.$languageCodeId.'-'.$templateId.'">'; $markup = '<a href="manage_email_templates.php?action=edit&template='.$templateUrl.'&language='.$languageCodeUrl.'&html=false">';
$markup .= '<i class="fa fa-file-text-o" style="font-size: 1.5em" data-toggle="tooltip" title="'.$hesklang['edit_plain_text_template'].'"></i>'; $markup .= '<i class="fa fa-file-text-o" style="font-size: 1.5em" data-toggle="tooltip" title="'.$hesklang['edit_plain_text_template'].'"></i>';
$markup .= '</a>'; $markup .= '</a>';
return $markup; return $markup;
} }
} }
function getModalMarkup($template, $languageCode, $html = false) { function save() {
global $hesklang; global $hesklang;
$templateId = str_replace('.', '-', $template); $filePath = HESK_PATH . 'language/'.$_POST['language'].'/emails/'.$_POST['template'];
$templateId = str_replace(' ', '-', $templateId); if ($_POST['html'] == '1') {
$languageCodeId = str_replace('.', '-', $languageCode); $filePath = HESK_PATH . 'language/'.$_POST['language'].'/emails/html/'.$_POST['template'];
$languageCodeId = str_replace(' ', '-', $languageCodeId); }
$id = 'modal-html-'.$languageCodeId.'-'.$templateId;
$class = '';
if ($html) { $success = file_put_contents($filePath, $_POST['text']);
$title = sprintf($hesklang['editing_html_template'], $template); if ($success === false) {
$content = file_get_contents(HESK_PATH . 'language/'.$languageCode.'/emails/html/'.$template); hesk_process_messages($hesklang[''], 'manage_email_templates.php');
$class = 'htmlEditor';
} else { } else {
$id = str_replace('html-', '', $id); $message = sprintf($hesklang['email_template_saved'], $_POST['template']);
$title = sprintf($hesklang['editing_template'], $template); hesk_process_messages($message,'manage_email_templates.php','SUCCESS');
$content = file_get_contents(HESK_PATH . 'language/'.$languageCode.'/emails/'.$template);
} }
return ' }
<div class="modal fade" id="'.$id.'" tabindex="-1" role="dialog" aria-hidden="true" aria-labelledby="'.$id.'Label">
<div class="modal-dialog modal-lg"> function getSpecialTagMap() {
<div class="modal-content"> global $hesk_settings, $modsForHesk_settings, $hesklang;
<div class="modal-header">
<h4 class="modal-title" id="'.$id.'Label">'.$title.'</h4> $map = array();
</div> $map['%%NAME%%'] = $hesklang['customer_name'];
<div class="modal-body"> $map['%%EMAIL%%'] = $hesklang['customer_email'];
<textarea class="'.$class.' form-control">'.$content.'</textarea> $map['%%SUBJECT%%'] = $hesklang['ticket_subject'];
</div> $map['%%MESSAGE%%'] = $hesklang['ticket_message'];
<div class="modal-footer"> $map['%%CREATED%%'] = $hesklang['ticket_created'];
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> $map['%%UPDATED%%'] = $hesklang['ticket_updated'];
<button type="button" class="btn btn-primary">Save</button> $map['%%TRACK_ID%%'] = $hesklang['ticket_trackID'];
</div> $map['%%TRACK_URL%%'] = $hesklang['ticket_url'];
</div> $map['%%SITE_TITLE%%'] = $hesklang['wbst_title'];
</div> $map['%%SITE_URL%%'] = $hesklang['wbst_url'];
</div>'; $map['%%CATEGORY%%'] = $hesklang['ticket_category'];
$map['%%OWNER%%'] = $hesklang['ticket_owner'];
$map['%%PRIORITY%%'] = $hesklang['ticket_priority'];
$map['%%STATUS%%'] = $hesklang['ticket_status'];
$i = 1;
foreach ($hesk_settings['custom_fields'] as $key => $value) {
if ($value['use']) {
$uppercaseKey = strtoupper($key);
$map['%%'.$uppercaseKey.'%%'] = sprintf($hesklang['custom_field_x'], $i++);
}
}
return $map;
} }

@ -390,3 +390,7 @@ button.dropdown-submit {
max-width: 80px; max-width: 80px;
cursor: pointer; cursor: pointer;
} }
.plaintext-editor {
font-family: monospace;
}

@ -1,10 +1,7 @@
<p>Hello,</p> <p>Hello,</p>
<p>A new support ticket has been moved to your category. Ticket details:</p> <p>A new support ticket has been moved to your category. Ticket details:</p>
<p>Ticket subject: %%SUBJECT%%<br> <p>Ticket subject: %%SUBJECT%%<br /> Tracking ID: %%TRACK_ID%%</p>
Tracking ID: %%TRACK_ID%%</p> <p>You can manage this ticket here: %%TRACK_URL%%</p>
<p>You can manage this ticket here: <p>&nbsp;</p>
%%TRACK_URL%%</p>
<br>
<p>Regards,</p> <p>Regards,</p>
%%SITE_TITLE%% <br> <p>%%SITE_TITLE%% <br /> %%SITE_URL%%</p>
%%SITE_URL%%

@ -26,8 +26,27 @@ $hesklang['email_templates'] = 'Email templates';
$hesklang['email_templates_intro'] = 'You can edit your plaintext and HTML email templates here.'; $hesklang['email_templates_intro'] = 'You can edit your plaintext and HTML email templates here.';
$hesklang['edit_plain_text_template'] = 'Edit plain text template'; $hesklang['edit_plain_text_template'] = 'Edit plain text template';
$hesklang['edit_html_template'] = 'Edit HTML template'; $hesklang['edit_html_template'] = 'Edit HTML template';
$hesklang['editing_template'] = 'Editing plain text template <code>%s</code>'; // %s: The name of the template file (XXXX.txt) $hesklang['editing_plain_text_template'] = 'Editing plain text template <code>%s</code>'; // %s: The name of the template file (XXXX.txt)
$hesklang['editing_html_template'] = 'Editing HTML template <code>%s</code>'; // %s: The name of the template file $hesklang['editing_html_template'] = 'Editing HTML template <code>%s</code>'; // %s: The name of the template file
$hesklang['show_special_tags'] = 'Show Special Tags';
$hesklang['hide_special_tags'] = 'Hide Special Tags';
$hesklang['special_tag'] = 'Special Tag';
$hesklang['description'] = 'Description';
$hesklang['customer_name'] = 'Customer name';
$hesklang['customer_email'] = 'Customer email';
$hesklang['ticket_subject'] = 'Ticket subject';
$hesklang['ticket_message'] = 'Ticket/Reply message';
$hesklang['ticket_created'] = 'Date and time of ticket submission';
$hesklang['ticket_updated'] = 'Date and time of ticket last update';
$hesklang['ticket_url'] = 'Ticket URL address';
$hesklang['ticket_category'] = 'Ticket category';
$hesklang['ticket_owner'] = 'Staff member assigned to the ticket';
$hesklang['ticket_priority'] = 'Ticket priority';
$hesklang['custom_field_x'] = 'Custom field %s'; // %s: Custom field #1-20
$hesklang['email_template_saved'] = 'The email template <b>%s</b> has been saved.'; // %s: Template file name
$hesklang['error_saving_template'] = 'An error occurred when trying to save the email template!';
$hesklang['email_template_directory_not_writable'] = 'The email template <b>%s</b> is not writable by HESK. Please CHMOD it to 0666.'; // %s: template file name
// ADDED OR MODIFIED IN Mods for HESK 2.1.1 // ADDED OR MODIFIED IN Mods for HESK 2.1.1
$hesklang['new_article_default_type'] = 'Default Type for New Articles'; $hesklang['new_article_default_type'] = 'Default Type for New Articles';

Loading…
Cancel
Save