@ -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=> $valu e) : ?>
<?php foreach ( $languages as $ language => $languageCod e) : ?>
< 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 ' ';
echo ' ';
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;
}
}