Service messages page can now retrieve service messages via AJAX
This commit is contained in:
parent
6bef518ffa
commit
c00d5641e4
@ -15,6 +15,7 @@ define('IN_SCRIPT', 1);
|
|||||||
define('HESK_PATH', '../');
|
define('HESK_PATH', '../');
|
||||||
define('PAGE_TITLE', 'ADMIN_SERVICE_MESSAGES');
|
define('PAGE_TITLE', 'ADMIN_SERVICE_MESSAGES');
|
||||||
define('MFH_PAGE_LAYOUT', 'TOP_ONLY');
|
define('MFH_PAGE_LAYOUT', 'TOP_ONLY');
|
||||||
|
define('EXTRA_JS', '<script src="'.HESK_PATH.'internal-api/js/service-messages.js"></script>');
|
||||||
|
|
||||||
/* Get all the required files and functions */
|
/* Get all the required files and functions */
|
||||||
require(HESK_PATH . 'hesk_settings.inc.php');
|
require(HESK_PATH . 'hesk_settings.inc.php');
|
||||||
@ -31,26 +32,8 @@ hesk_isLoggedIn();
|
|||||||
hesk_checkPermission('can_service_msg');
|
hesk_checkPermission('can_service_msg');
|
||||||
|
|
||||||
// Define required constants
|
// Define required constants
|
||||||
define('LOAD_TABS', 1);
|
|
||||||
define('WYSIWYG', 1);
|
define('WYSIWYG', 1);
|
||||||
|
|
||||||
// What should we do?
|
|
||||||
if ($action = hesk_REQUEST('a')) {
|
|
||||||
if ($action == 'edit_sm') {
|
|
||||||
edit_sm();
|
|
||||||
} elseif (defined('HESK_DEMO')) {
|
|
||||||
hesk_process_messages($hesklang['ddemo'], 'service_messages.php', 'NOTICE');
|
|
||||||
} elseif ($action == 'new_sm') {
|
|
||||||
new_sm();
|
|
||||||
} elseif ($action == 'save_sm') {
|
|
||||||
save_sm();
|
|
||||||
} elseif ($action == 'order_sm') {
|
|
||||||
order_sm();
|
|
||||||
} elseif ($action == 'remove_sm') {
|
|
||||||
remove_sm();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print header */
|
/* Print header */
|
||||||
require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
|
require_once(HESK_PATH . 'inc/headerAdmin.inc.php');
|
||||||
|
|
||||||
@ -60,638 +43,293 @@ require_once(HESK_PATH . 'inc/show_admin_nav.inc.php');
|
|||||||
<div class="content-wrapper">
|
<div class="content-wrapper">
|
||||||
<section class="content">
|
<section class="content">
|
||||||
<div class="box">
|
<div class="box">
|
||||||
|
<div class="box-header with-border">
|
||||||
|
<h1 class="box-title">
|
||||||
|
<?php echo $hesklang['manage_service_messages']; ?> <a href="javascript:void(0)"
|
||||||
|
onclick="alert('<?php echo hesk_makeJsString($hesklang['sm_intro']); ?>')"><i
|
||||||
|
class="fa fa-question-circle settingsquestionmark"></i></a>
|
||||||
|
</h1>
|
||||||
|
<div class="box-tools pull-right">
|
||||||
|
<button type="button" class="btn btn-box-tool" data-widget="collapse">
|
||||||
|
<i class="fa fa-minus"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<div class="nav-tabs-custom">
|
<div class="row">
|
||||||
<ul class="nav nav-tabs" role="tablist">
|
<div class="col-sm-12">
|
||||||
<?php
|
<?php
|
||||||
// Show a link to banned_emails.php if user has permission to do so
|
|
||||||
if (hesk_checkPermission('can_ban_emails', 0)) {
|
if ($hesk_settings['kb_wysiwyg']) {
|
||||||
echo '
|
?>
|
||||||
<li role="presentation">
|
<script type="text/javascript">
|
||||||
<a title="' . $hesklang['banemail'] . '" href="banned_emails.php">' . $hesklang['banemail'] . '</a>
|
tinyMCE.init({
|
||||||
</li>';
|
mode: "exact",
|
||||||
}
|
elements: "content",
|
||||||
if (hesk_checkPermission('can_ban_ips', 0)) {
|
theme: "advanced",
|
||||||
echo '
|
convert_urls: false,
|
||||||
<li role="presentation">
|
gecko_spellcheck: true,
|
||||||
<a title="' . $hesklang['banip'] . '" href="banned_ips.php">' . $hesklang['banip'] . '</a>
|
plugins: "autolink",
|
||||||
</li>';
|
|
||||||
|
theme_advanced_buttons1: "cut,copy,paste,|,undo,redo,|,formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
|
||||||
|
theme_advanced_buttons2: "sub,sup,|,charmap,|,bullist,numlist,|,outdent,indent,insertdate,inserttime,preview,|,forecolor,backcolor,|,hr,removeformat,visualaid,|,link,unlink,anchor,image,cleanup,code",
|
||||||
|
theme_advanced_buttons3: "",
|
||||||
|
|
||||||
|
theme_advanced_toolbar_location: "top",
|
||||||
|
theme_advanced_toolbar_align: "left",
|
||||||
|
theme_advanced_statusbar_location: "bottom",
|
||||||
|
theme_advanced_resizing: true
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<li role="presentation" class="active">
|
<table class="table table-hover">
|
||||||
<a href="#"><?php echo $hesklang['sm_title']; ?> <i class="fa fa-question-circle settingsquestionmark"
|
<thead>
|
||||||
onclick="javascript:alert('<?php echo hesk_makeJsString($hesklang['sm_intro']); ?>')"></i></a>
|
<tr>
|
||||||
</li>
|
<th><?php echo $hesklang['sm_mtitle']; ?></th>
|
||||||
<?php
|
<th><?php echo $hesklang['sm_author']; ?></th>
|
||||||
// Show a link to email tpl management if user has permission to do so
|
<th><?php echo $hesklang['sm_type']; ?></th>
|
||||||
if (hesk_checkPermission('can_man_email_tpl', 0)) {
|
<th><?php echo $hesklang['opt']; ?></th>
|
||||||
echo '
|
</tr>
|
||||||
<li role="presentation">
|
</thead>
|
||||||
<a title="' . $hesklang['email_templates'] . '" href="manage_email_templates.php">' . $hesklang['email_templates'] . '</a>
|
<tbody id="table-body">
|
||||||
</li>
|
</tbody>
|
||||||
';
|
</table>
|
||||||
}
|
<div class="panel panel-default">
|
||||||
if (hesk_checkPermission('can_man_ticket_statuses', 0)) {
|
<div class="panel-heading">
|
||||||
echo '
|
<h4><a name="new_article"></a><?php echo hesk_SESSION('edit_sm') ? $hesklang['edit_sm'] : $hesklang['new_sm']; ?></h4>
|
||||||
<li role="presentation">
|
</div>
|
||||||
<a title="' . $hesklang['statuses'] . '" href="manage_statuses.php">' . $hesklang['statuses'] . '</a>
|
<div class="panel-body">
|
||||||
</li>
|
<form action="service_messages.php" method="post" name="form1" role="form" class="form-horizontal" data-toggle="validator">
|
||||||
';
|
<div class="form-group">
|
||||||
}
|
<label for="style"
|
||||||
// Show a link to custom_fields.php if user has permission to do so
|
class="col-md-2 control-label"><?php echo $hesklang['sm_style']; ?></label>
|
||||||
if ( hesk_checkPermission('can_man_settings',0) ) {
|
|
||||||
echo '
|
|
||||||
<li role="presentation">
|
|
||||||
<a title="' . $hesklang['tab_4'] . '" href="custom_fields.php">' . $hesklang['tab_4'] . '</a>
|
|
||||||
</li>
|
|
||||||
';
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</ul>
|
|
||||||
<div class="tab-content summaryList tabPadding">
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-sm-12">
|
|
||||||
<?php
|
|
||||||
/* This will handle error, success and notice messages */
|
|
||||||
hesk_handle_messages();
|
|
||||||
|
|
||||||
if (isset($_SESSION['new_sm']) && !isset($_SESSION['edit_sm'])) {
|
<div class="col-md-2">
|
||||||
$_SESSION['new_sm'] = hesk_stripArray($_SESSION['new_sm']);
|
<div class="radio alert pad-5" style="box-shadow: none; border-radius: 4px;">
|
||||||
}
|
<label>
|
||||||
|
<input type="radio" name="style" value="0" onclick="setIcon('')"
|
||||||
if (isset($_SESSION['preview_sm'])) {
|
<?php if (!isset($_SESSION['new_sm']['style']) || (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 0)) {
|
||||||
hesk_service_message($_SESSION['new_sm']);
|
echo 'checked';
|
||||||
}
|
} ?>>
|
||||||
|
<?php echo $hesklang['sm_none']; ?>
|
||||||
if ($hesk_settings['kb_wysiwyg']) {
|
</label>
|
||||||
?>
|
</div>
|
||||||
<script type="text/javascript">
|
</div>
|
||||||
tinyMCE.init({
|
<div class="col-md-2">
|
||||||
mode: "exact",
|
<div class="radio alert alert-success pad-5">
|
||||||
elements: "content",
|
<label style="margin-top: -5px">
|
||||||
theme: "advanced",
|
<input type="radio" name="style" value="1"
|
||||||
convert_urls: false,
|
onclick="setIcon('fa fa-check-circle')"
|
||||||
gecko_spellcheck: true,
|
<?php if (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 1) {
|
||||||
plugins: "autolink",
|
echo 'checked';
|
||||||
|
} ?>>
|
||||||
theme_advanced_buttons1: "cut,copy,paste,|,undo,redo,|,formatselect,fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
|
<?php echo $hesklang['sm_success']; ?>
|
||||||
theme_advanced_buttons2: "sub,sup,|,charmap,|,bullist,numlist,|,outdent,indent,insertdate,inserttime,preview,|,forecolor,backcolor,|,hr,removeformat,visualaid,|,link,unlink,anchor,image,cleanup,code",
|
</label>
|
||||||
theme_advanced_buttons3: "",
|
</div>
|
||||||
|
</div>
|
||||||
theme_advanced_toolbar_location: "top",
|
<div class="col-md-2">
|
||||||
theme_advanced_toolbar_align: "left",
|
<div class="radio alert alert-info pad-5" onclick="setIcon('fa fa-comment')">
|
||||||
theme_advanced_statusbar_location: "bottom",
|
<label style="margin-top: -5px">
|
||||||
theme_advanced_resizing: true
|
<input type="radio" name="style" value="2"
|
||||||
});
|
<?php if (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 2) {
|
||||||
</script>
|
echo 'checked';
|
||||||
<?php
|
} ?>>
|
||||||
}
|
<?php echo $hesklang['sm_info']; ?>
|
||||||
?>
|
</label>
|
||||||
<div class="panel panel-default">
|
</div>
|
||||||
<div class="panel-heading">
|
</div>
|
||||||
<h4><?php echo $hesklang['ex_sm']; ?></h4>
|
<div class="col-md-2">
|
||||||
|
<div class="radio alert alert-warning pad-5"
|
||||||
|
onclick="setIcon('fa fa-exclamation-triangle')">
|
||||||
|
<label style="margin-top: -5px">
|
||||||
|
<input type="radio" name="style" value="3"
|
||||||
|
<?php if (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 3) {
|
||||||
|
echo 'checked';
|
||||||
|
} ?>>
|
||||||
|
<?php echo $hesklang['sm_notice']; ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<div class="radio alert alert-danger pad-5" onclick="setIcon('fa fa-times-circle')">
|
||||||
|
<label style="margin-top: -5px">
|
||||||
|
<input type="radio" name="style" value="4"
|
||||||
|
<?php if (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 4) {
|
||||||
|
echo 'checked';
|
||||||
|
} ?> >
|
||||||
|
<?php echo $hesklang['sm_error']; ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="form-group">
|
||||||
|
<label for="icon" class="col-md-2 control-label"><?php echo $hesklang['sm_icon']; ?></label>
|
||||||
<?php
|
<?php
|
||||||
|
$icon = '';
|
||||||
// Get service messages from database
|
if (isset($_SESSION['new_sm']['icon'])) {
|
||||||
$res = hesk_dbQuery('SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'service_messages` ORDER BY `order` ASC');
|
$icon = $_SESSION['new_sm']['icon'];
|
||||||
$num = hesk_dbNumRows($res);
|
|
||||||
|
|
||||||
if ($num < 1) {
|
|
||||||
echo '<p>' . $hesklang['no_sm'] . '</p>';
|
|
||||||
} else {
|
|
||||||
// List of staff
|
|
||||||
if (!isset($admins)) {
|
|
||||||
$admins = array();
|
|
||||||
$res2 = hesk_dbQuery("SELECT `id`,`name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users`");
|
|
||||||
while ($row = hesk_dbFetchAssoc($res2)) {
|
|
||||||
$admins[$row['id']] = $row['name'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
<table class="table table-hover">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th><?php echo $hesklang['sm_mtitle']; ?></th>
|
|
||||||
<th><?php echo $hesklang['sm_author']; ?></th>
|
|
||||||
<th><?php echo $hesklang['sm_type']; ?></th>
|
|
||||||
<th> <?php echo $hesklang['opt']; ?> </th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<?php
|
|
||||||
$j = 1;
|
|
||||||
$k = 1;
|
|
||||||
|
|
||||||
while ($sm = hesk_dbFetchAssoc($res)) {
|
|
||||||
$faIcon = $sm['icon'];
|
|
||||||
switch ($sm['style']) {
|
|
||||||
case 1:
|
|
||||||
$sm_style = "alert alert-success";
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
$sm_style = "alert alert-info";
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$sm_style = "alert alert-warning";
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
$sm_style = "alert alert-danger";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$sm_style = "none";
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = $sm['type'] ? $hesklang['sm_draft'] : $hesklang['sm_published'];
|
|
||||||
|
|
||||||
?>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<div class="<?php echo $sm_style; ?>">
|
|
||||||
<i class="<?php echo $faIcon; ?>"></i>
|
|
||||||
<b><?php echo $sm['title']; ?></b>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
<td><?php echo(isset($admins[$sm['author']]) ? $admins[$sm['author']] : $hesklang['e_udel']); ?></td>
|
|
||||||
<td><?php echo $type; ?></td>
|
|
||||||
<td>
|
|
||||||
<?php
|
|
||||||
if ($num > 1) {
|
|
||||||
if ($k == 1) {
|
|
||||||
?>
|
|
||||||
<img src="../img/blank.gif" width="16" height="16" alt=""
|
|
||||||
style="padding:3px;border:none;"/>
|
|
||||||
<a href="service_messages.php?a=order_sm&id=<?php echo $sm['id']; ?>&move=15&token=<?php hesk_token_echo(); ?>">
|
|
||||||
<i class="fa fa-arrow-down font-size-16p green"
|
|
||||||
data-toggle="tooltip" data-placement="top"
|
|
||||||
data-original-title="<?php echo $hesklang['move_dn']; ?>"></i></a>
|
|
||||||
<?php
|
|
||||||
} elseif ($k == $num) {
|
|
||||||
?>
|
|
||||||
<a href="service_messages.php?a=order_sm&id=<?php echo $sm['id']; ?>&move=-15&token=<?php hesk_token_echo(); ?>">
|
|
||||||
<i class="fa fa-arrow-up font-size-16p green" data-toggle="tooltip"
|
|
||||||
data-placement="top"
|
|
||||||
data-original-title="<?php echo $hesklang['move_up']; ?>"></i></a>
|
|
||||||
<img src="../img/blank.gif" width="16" height="16" alt=""
|
|
||||||
style="padding:3px;border:none;"/>
|
|
||||||
<?php
|
|
||||||
} else {
|
|
||||||
?>
|
|
||||||
<a href="service_messages.php?a=order_sm&id=<?php echo $sm['id']; ?>&move=-15&token=<?php hesk_token_echo(); ?>">
|
|
||||||
<i class="fa fa-arrow-up font-size-16p green" data-toggle="tooltip"
|
|
||||||
data-placement="top"
|
|
||||||
data-original-title="<?php echo $hesklang['move_up']; ?>"></i></a>
|
|
||||||
<a href="service_messages.php?a=order_sm&id=<?php echo $sm['id']; ?>&move=15&token=<?php hesk_token_echo(); ?>">
|
|
||||||
<i class="fa fa-arrow-down font-size-16p green"
|
|
||||||
data-toggle="tooltip" data-placement="top"
|
|
||||||
data-original-title="<?php echo $hesklang['move_dn']; ?>"></i></a>
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<a href="service_messages.php?a=edit_sm&id=<?php echo $sm['id']; ?>">
|
|
||||||
<i class="fa fa-pencil font-size-16p orange" data-toggle="tooltip"
|
|
||||||
data-placement="top"
|
|
||||||
data-original-title="<?php echo $hesklang['edit']; ?>"></i></a>
|
|
||||||
<a href="service_messages.php?a=remove_sm&id=<?php echo $sm['id']; ?>&token=<?php hesk_token_echo(); ?>"
|
|
||||||
onclick="return hesk_confirmExecute('<?php echo hesk_makeJsString($hesklang['del_sm']); ?>');">
|
|
||||||
<i class="fa fa-times font-size-16p red" data-toggle="tooltip"
|
|
||||||
data-placement="top"
|
|
||||||
data-original-title="<?php echo $hesklang['delete']; ?>"></i></a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
<?php
|
|
||||||
$j++;
|
|
||||||
$k++;
|
|
||||||
} // End while
|
|
||||||
|
|
||||||
?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<?php
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
<div class="col-md-10">
|
||||||
|
<p style="display:none" id="no-icon"><?php echo $hesklang['sm_no_icon']; ?></p>
|
||||||
|
|
||||||
|
<p style="display:none" id="search-icon"><?php echo $hesklang['sm_search_icon']; ?></p>
|
||||||
|
|
||||||
|
<p style="display:none"
|
||||||
|
id="footer-icon"><?php echo $hesklang['sm_iconpicker_footer_label']; ?></p>
|
||||||
|
|
||||||
|
<div name="icon" class="btn btn-default iconpicker-container" data-toggle="iconpicker"
|
||||||
|
data-icon="<?php echo $icon; ?>"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="form-group">
|
||||||
|
<label for="type" class="col-md-2 control-label"><?php echo $hesklang['sm_type']; ?></label>
|
||||||
|
|
||||||
<div class="panel panel-default">
|
<div class="col-md-2">
|
||||||
<div class="panel-heading">
|
<div class="radio pad-5">
|
||||||
<h4><a name="new_article"></a><?php echo hesk_SESSION('edit_sm') ? $hesklang['edit_sm'] : $hesklang['new_sm']; ?></h4>
|
<label>
|
||||||
|
<input type="radio" name="type" value="0"
|
||||||
|
<?php if (!isset($_SESSION['new_sm']['type']) || (isset($_SESSION['new_sm']['type']) && $_SESSION['new_sm']['type'] == 0)) {
|
||||||
|
echo 'checked';
|
||||||
|
} ?> >
|
||||||
|
<?php echo $hesklang['sm_published']; ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2">
|
||||||
|
<div class="radio pad-5">
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="type" value="1"
|
||||||
|
<?php if (isset($_SESSION['new_sm']['type']) && $_SESSION['new_sm']['type'] == 1) {
|
||||||
|
echo 'checked';
|
||||||
|
} ?> >
|
||||||
|
<?php echo $hesklang['sm_draft']; ?>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="form-group">
|
||||||
<form action="service_messages.php" method="post" name="form1" role="form" class="form-horizontal" data-toggle="validator">
|
<label for="title"
|
||||||
<div class="form-group">
|
class="col-md-2 control-label"><?php echo $hesklang['sm_mtitle']; ?></label>
|
||||||
<label for="style"
|
|
||||||
class="col-md-2 control-label"><?php echo $hesklang['sm_style']; ?></label>
|
|
||||||
|
|
||||||
<div class="col-md-2">
|
<div class="col-md-10">
|
||||||
<div class="radio alert pad-5" style="box-shadow: none; border-radius: 4px;">
|
<input class="form-control"
|
||||||
<label>
|
placeholder="<?php echo htmlspecialchars($hesklang['sm_mtitle']); ?>"
|
||||||
<input type="radio" name="style" value="0" onclick="setIcon('')"
|
type="text" name="title" size="70" maxlength="255"
|
||||||
<?php if (!isset($_SESSION['new_sm']['style']) || (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 0)) {
|
<?php if (isset($_SESSION['new_sm']['title'])) {
|
||||||
echo 'checked';
|
echo 'value="' . $_SESSION['new_sm']['title'] . '"';
|
||||||
} ?>>
|
} ?> data-error="<?php echo htmlspecialchars($hesklang['sm_e_title']); ?>" required>
|
||||||
<?php echo $hesklang['sm_none']; ?>
|
<div class="help-block with-errors"></div>
|
||||||
</label>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="form-group">
|
||||||
<div class="col-md-2">
|
<label for="message"
|
||||||
<div class="radio alert alert-success pad-5">
|
class="col-md-2 control-label"><?php echo $hesklang['sm_msg']; ?></label>
|
||||||
<label style="margin-top: -5px">
|
|
||||||
<input type="radio" name="style" value="1"
|
|
||||||
onclick="setIcon('fa fa-check-circle')"
|
|
||||||
<?php if (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 1) {
|
|
||||||
echo 'checked';
|
|
||||||
} ?>>
|
|
||||||
<?php echo $hesklang['sm_success']; ?>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<div class="radio alert alert-info pad-5" onclick="setIcon('fa fa-comment')">
|
|
||||||
<label style="margin-top: -5px">
|
|
||||||
<input type="radio" name="style" value="2"
|
|
||||||
<?php if (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 2) {
|
|
||||||
echo 'checked';
|
|
||||||
} ?>>
|
|
||||||
<?php echo $hesklang['sm_info']; ?>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<div class="radio alert alert-warning pad-5"
|
|
||||||
onclick="setIcon('fa fa-exclamation-triangle')">
|
|
||||||
<label style="margin-top: -5px">
|
|
||||||
<input type="radio" name="style" value="3"
|
|
||||||
<?php if (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 3) {
|
|
||||||
echo 'checked';
|
|
||||||
} ?>>
|
|
||||||
<?php echo $hesklang['sm_notice']; ?>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<div class="radio alert alert-danger pad-5" onclick="setIcon('fa fa-times-circle')">
|
|
||||||
<label style="margin-top: -5px">
|
|
||||||
<input type="radio" name="style" value="4"
|
|
||||||
<?php if (isset($_SESSION['new_sm']['style']) && $_SESSION['new_sm']['style'] == 4) {
|
|
||||||
echo 'checked';
|
|
||||||
} ?> >
|
|
||||||
<?php echo $hesklang['sm_error']; ?>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="icon" class="col-md-2 control-label"><?php echo $hesklang['sm_icon']; ?></label>
|
|
||||||
<?php
|
|
||||||
$icon = '';
|
|
||||||
if (isset($_SESSION['new_sm']['icon'])) {
|
|
||||||
$icon = $_SESSION['new_sm']['icon'];
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
<div class="col-md-10">
|
|
||||||
<p style="display:none" id="no-icon"><?php echo $hesklang['sm_no_icon']; ?></p>
|
|
||||||
|
|
||||||
<p style="display:none" id="search-icon"><?php echo $hesklang['sm_search_icon']; ?></p>
|
<div class="col-md-10">
|
||||||
|
|
||||||
<p style="display:none"
|
|
||||||
id="footer-icon"><?php echo $hesklang['sm_iconpicker_footer_label']; ?></p>
|
|
||||||
|
|
||||||
<div name="icon" class="btn btn-default iconpicker-container" data-toggle="iconpicker"
|
|
||||||
data-icon="<?php echo $icon; ?>"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="type" class="col-md-2 control-label"><?php echo $hesklang['sm_type']; ?></label>
|
|
||||||
|
|
||||||
<div class="col-md-2">
|
|
||||||
<div class="radio pad-5">
|
|
||||||
<label>
|
|
||||||
<input type="radio" name="type" value="0"
|
|
||||||
<?php if (!isset($_SESSION['new_sm']['type']) || (isset($_SESSION['new_sm']['type']) && $_SESSION['new_sm']['type'] == 0)) {
|
|
||||||
echo 'checked';
|
|
||||||
} ?> >
|
|
||||||
<?php echo $hesklang['sm_published']; ?>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="col-md-2">
|
|
||||||
<div class="radio pad-5">
|
|
||||||
<label>
|
|
||||||
<input type="radio" name="type" value="1"
|
|
||||||
<?php if (isset($_SESSION['new_sm']['type']) && $_SESSION['new_sm']['type'] == 1) {
|
|
||||||
echo 'checked';
|
|
||||||
} ?> >
|
|
||||||
<?php echo $hesklang['sm_draft']; ?>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="title"
|
|
||||||
class="col-md-2 control-label"><?php echo $hesklang['sm_mtitle']; ?></label>
|
|
||||||
|
|
||||||
<div class="col-md-10">
|
|
||||||
<input class="form-control"
|
|
||||||
placeholder="<?php echo htmlspecialchars($hesklang['sm_mtitle']); ?>"
|
|
||||||
type="text" name="title" size="70" maxlength="255"
|
|
||||||
<?php if (isset($_SESSION['new_sm']['title'])) {
|
|
||||||
echo 'value="' . $_SESSION['new_sm']['title'] . '"';
|
|
||||||
} ?> data-error="<?php echo htmlspecialchars($hesklang['sm_e_title']); ?>" required>
|
|
||||||
<div class="help-block with-errors"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label for="message"
|
|
||||||
class="col-md-2 control-label"><?php echo $hesklang['sm_msg']; ?></label>
|
|
||||||
|
|
||||||
<div class="col-md-10">
|
|
||||||
<textarea placeholder="<?php echo htmlspecialchars($hesklang['sm_msg']); ?>"
|
<textarea placeholder="<?php echo htmlspecialchars($hesklang['sm_msg']); ?>"
|
||||||
class="form-control" name="message" rows="25" cols="70" id="content">
|
class="form-control" name="message" rows="25" cols="70" id="content">
|
||||||
<?php if (isset($_SESSION['new_sm']['message'])) {
|
<?php if (isset($_SESSION['new_sm']['message'])) {
|
||||||
echo $_SESSION['new_sm']['message'];
|
echo $_SESSION['new_sm']['message'];
|
||||||
} ?>
|
} ?>
|
||||||
</textarea>
|
</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<?php echo isset($_SESSION['edit_sm']) ? '<input type="hidden" name="a" value="save_sm" /><input type="hidden" name="id" value="' . intval($_SESSION['new_sm']['id']) . '" />' : '<input type="hidden" name="a" value="new_sm" />'; ?>
|
|
||||||
<input type="hidden" name="token" value="<?php hesk_token_echo(); ?>"/>
|
|
||||||
|
|
||||||
<div class="col-md-10 col-md-offset-2">
|
|
||||||
<div class="btn-group" role="group">
|
|
||||||
<input type="submit" name="sm_save" value="<?php echo $hesklang['sm_save']; ?>"
|
|
||||||
class="btn btn-primary">
|
|
||||||
<input type="submit" name="sm_preview"
|
|
||||||
value="<?php echo $hesklang['sm_preview']; ?>" class="btn btn-default">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="form-group">
|
||||||
|
<?php echo isset($_SESSION['edit_sm']) ? '<input type="hidden" name="a" value="save_sm" /><input type="hidden" name="id" value="' . intval($_SESSION['new_sm']['id']) . '" />' : '<input type="hidden" name="a" value="new_sm" />'; ?>
|
||||||
|
<input type="hidden" name="token" value="<?php hesk_token_echo(); ?>"/>
|
||||||
|
|
||||||
|
<div class="col-md-10 col-md-offset-2">
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<input type="submit" name="sm_save" value="<?php echo $hesklang['sm_save']; ?>"
|
||||||
|
class="btn btn-primary">
|
||||||
|
<input type="submit" name="sm_preview"
|
||||||
|
value="<?php echo $hesklang['sm_preview']; ?>" class="btn btn-default">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="overlay" id="overlay">
|
||||||
|
<i class="fa fa-spinner fa-spin"></i>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
<?php
|
||||||
|
echo mfh_get_hidden_fields_for_language(array(
|
||||||
|
'sm_published',
|
||||||
|
'sm_draft',
|
||||||
|
));
|
||||||
|
|
||||||
|
echo '<script>var users = [];';
|
||||||
|
$usersRs = hesk_dbQuery("SELECT `id`, `name` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `active` = '1'");
|
||||||
|
$users = array();
|
||||||
|
while ($row = hesk_dbFetchAssoc($usersRs)) {
|
||||||
|
$users[] = $row;
|
||||||
|
echo "users[" . $row['id'] . "] = {
|
||||||
|
id: ".$row['id'].",
|
||||||
|
name: '".$row['name']."'
|
||||||
|
}\n";
|
||||||
|
}
|
||||||
|
echo '</script>';
|
||||||
|
?>
|
||||||
|
<script type="text/html" id="service-message-title-template">
|
||||||
|
<div class="{{CLASS}}">
|
||||||
|
<i data-property="icon"></i>
|
||||||
|
<b data-property="title"></b>
|
||||||
|
</div>
|
||||||
|
</script>
|
||||||
|
<script type="text/html" id="service-message-preview-template">
|
||||||
|
<?php
|
||||||
|
$sm = array(
|
||||||
|
'icon' => 'fa',
|
||||||
|
'style' => 0,
|
||||||
|
'title' => '{{TITLE}}',
|
||||||
|
'message' => '{{MESSAGE}}'
|
||||||
|
);
|
||||||
|
hesk_service_message($sm);
|
||||||
|
?>
|
||||||
|
</script>
|
||||||
|
<script type="text/html" id="service-message-template">
|
||||||
|
<tr data-property="id" data-value="x">
|
||||||
|
<td><span data-property="title"></span></td>
|
||||||
|
<td><span data-property="author"></span></td>
|
||||||
|
<td><span data-property="type"></span></td>
|
||||||
|
<td>
|
||||||
|
<span class="sort-arrows">
|
||||||
|
<a href="#" data-action="sort"
|
||||||
|
data-direction="up">
|
||||||
|
<i class="fa fa-fw fa-arrow-up icon-link green"
|
||||||
|
data-toggle="tooltip" title="<?php echo $hesklang['move_up']; ?>"></i>
|
||||||
|
</a>
|
||||||
|
<a href="#" data-action="sort"
|
||||||
|
data-direction="down">
|
||||||
|
<i class="fa fa-fw fa-arrow-down icon-link green"
|
||||||
|
data-toggle="tooltip" title="<?php echo $hesklang['move_dn'] ?>"></i>
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
|
<a href="#" data-action="edit">
|
||||||
|
<i class="fa fa-fw fa-pencil icon-link orange"
|
||||||
|
data-toggle="tooltip" title="<?php echo $hesklang['edit']; ?>"></i>
|
||||||
|
</a>
|
||||||
|
<a href="#" data-action="delete">
|
||||||
|
<i class="fa fa-fw fa-times icon-link red"
|
||||||
|
data-toggle="tooltip" title="<?php echo $hesklang['delete']; ?>"></i>
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</script>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
hesk_cleanSessionVars(array('new_sm', 'preview_sm', 'edit_sm'));
|
|
||||||
|
|
||||||
require_once(HESK_PATH . 'inc/footer.inc.php');
|
require_once(HESK_PATH . 'inc/footer.inc.php');
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
|
|
||||||
/*** START FUNCTIONS ***/
|
|
||||||
|
|
||||||
|
|
||||||
function save_sm()
|
|
||||||
{
|
|
||||||
global $hesk_settings, $hesklang, $listBox;
|
|
||||||
global $hesk_error_buffer;
|
|
||||||
|
|
||||||
// A security check
|
|
||||||
# hesk_token_check('POST');
|
|
||||||
|
|
||||||
$hesk_error_buffer = array();
|
|
||||||
|
|
||||||
// Get service messageID
|
|
||||||
$id = intval(hesk_POST('id')) or hesk_error($hesklang['sm_e_id']);
|
|
||||||
|
|
||||||
$style = intval(hesk_POST('style', 0));
|
|
||||||
if ($style > 4 || $style < 0) {
|
|
||||||
$style = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = empty($_POST['type']) ? 0 : 1;
|
|
||||||
$icon = hesk_POST('icon');
|
|
||||||
$title = hesk_input(hesk_POST('title')) or $hesk_error_buffer[] = $hesklang['sm_e_title'];
|
|
||||||
$message = hesk_getHTML(hesk_POST('message'));
|
|
||||||
|
|
||||||
// Clean the HTML code
|
|
||||||
require(HESK_PATH . 'inc/htmlpurifier/HeskHTMLPurifier.php');
|
|
||||||
$purifier = new HeskHTMLPurifier($hesk_settings['cache_dir']);
|
|
||||||
$message = $purifier->heskPurify($message);
|
|
||||||
|
|
||||||
// Any errors?
|
|
||||||
if (count($hesk_error_buffer)) {
|
|
||||||
$_SESSION['edit_sm'] = true;
|
|
||||||
|
|
||||||
$_SESSION['new_sm'] = array(
|
|
||||||
'id' => $id,
|
|
||||||
'style' => $style,
|
|
||||||
'type' => $type,
|
|
||||||
'title' => $title,
|
|
||||||
'icon' => $icon,
|
|
||||||
'message' => hesk_input(hesk_POST('message')),
|
|
||||||
);
|
|
||||||
|
|
||||||
$tmp = '';
|
|
||||||
foreach ($hesk_error_buffer as $error) {
|
|
||||||
$tmp .= "<li>$error</li>\n";
|
|
||||||
}
|
|
||||||
$hesk_error_buffer = $tmp;
|
|
||||||
|
|
||||||
$hesk_error_buffer = $hesklang['rfm'] . '<br /><br /><ul>' . $hesk_error_buffer . '</ul>';
|
|
||||||
hesk_process_messages($hesk_error_buffer, 'service_messages.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just preview the message?
|
|
||||||
if (isset($_POST['sm_preview'])) {
|
|
||||||
$_SESSION['preview_sm'] = true;
|
|
||||||
$_SESSION['edit_sm'] = true;
|
|
||||||
|
|
||||||
$_SESSION['new_sm'] = array(
|
|
||||||
'id' => $id,
|
|
||||||
'style' => $style,
|
|
||||||
'type' => $type,
|
|
||||||
'title' => $title,
|
|
||||||
'message' => $message,
|
|
||||||
'icon' => $icon,
|
|
||||||
);
|
|
||||||
|
|
||||||
header('Location: service_messages.php');
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the service message in the database
|
|
||||||
hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages` SET
|
|
||||||
`author` = '" . intval($_SESSION['id']) . "',
|
|
||||||
`title` = '" . hesk_dbEscape($title) . "',
|
|
||||||
`message` = '" . hesk_dbEscape($message) . "',
|
|
||||||
`style` = '{$style}',
|
|
||||||
`type` = '{$type}',
|
|
||||||
`icon` = '{$icon}'
|
|
||||||
WHERE `id`={$id}");
|
|
||||||
|
|
||||||
$_SESSION['smord'] = $id;
|
|
||||||
hesk_process_messages($hesklang['sm_mdf'], 'service_messages.php', 'SUCCESS');
|
|
||||||
|
|
||||||
} // End save_sm()
|
|
||||||
|
|
||||||
|
|
||||||
function edit_sm()
|
|
||||||
{
|
|
||||||
global $hesk_settings, $hesklang;
|
|
||||||
|
|
||||||
// Get service messageID
|
|
||||||
$id = intval(hesk_GET('id')) or hesk_error($hesklang['sm_e_id']);
|
|
||||||
|
|
||||||
// Get details from the database
|
|
||||||
$res = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages` WHERE `id`={$id} LIMIT 1");
|
|
||||||
if (hesk_dbNumRows($res) != 1) {
|
|
||||||
hesk_error($hesklang['sm_not_found']);
|
|
||||||
}
|
|
||||||
$sm = hesk_dbFetchAssoc($res);
|
|
||||||
|
|
||||||
$_SESSION['new_sm'] = $sm;
|
|
||||||
$_SESSION['edit_sm'] = true;
|
|
||||||
|
|
||||||
} // End edit_sm()
|
|
||||||
|
|
||||||
|
|
||||||
function order_sm()
|
|
||||||
{
|
|
||||||
global $hesk_settings, $hesklang;
|
|
||||||
|
|
||||||
// A security check
|
|
||||||
hesk_token_check();
|
|
||||||
|
|
||||||
// Get ID and move parameters
|
|
||||||
$id = intval(hesk_GET('id')) or hesk_error($hesklang['sm_e_id']);
|
|
||||||
$move = intval(hesk_GET('move'));
|
|
||||||
$_SESSION['smord'] = $id;
|
|
||||||
|
|
||||||
// Update article details
|
|
||||||
hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages` SET `order`=`order`+" . intval($move) . " WHERE `id`={$id}");
|
|
||||||
|
|
||||||
// Update order of all service messages
|
|
||||||
update_sm_order();
|
|
||||||
|
|
||||||
// Finish
|
|
||||||
header('Location: service_messages.php');
|
|
||||||
exit();
|
|
||||||
|
|
||||||
} // End order_sm()
|
|
||||||
|
|
||||||
|
|
||||||
function update_sm_order()
|
|
||||||
{
|
|
||||||
global $hesk_settings, $hesklang;
|
|
||||||
|
|
||||||
// Get list of current service messages
|
|
||||||
$res = hesk_dbQuery("SELECT `id` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages` ORDER BY `order` ASC");
|
|
||||||
|
|
||||||
// Update database
|
|
||||||
$i = 10;
|
|
||||||
while ($sm = hesk_dbFetchAssoc($res)) {
|
|
||||||
hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages` SET `order`=" . intval($i) . " WHERE `id`='" . intval($sm['id']) . "'");
|
|
||||||
$i += 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
} // END update_sm_order()
|
|
||||||
|
|
||||||
|
|
||||||
function remove_sm()
|
|
||||||
{
|
|
||||||
global $hesk_settings, $hesklang;
|
|
||||||
|
|
||||||
// A security check
|
|
||||||
hesk_token_check();
|
|
||||||
|
|
||||||
// Get ID
|
|
||||||
$id = intval(hesk_GET('id')) or hesk_error($hesklang['sm_e_id']);
|
|
||||||
|
|
||||||
// Delete the service message
|
|
||||||
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "service_messages` WHERE `id`={$id}");
|
|
||||||
|
|
||||||
// Were we successful?
|
|
||||||
if (hesk_dbAffectedRows() == 1) {
|
|
||||||
hesk_process_messages($hesklang['sm_deleted'], './service_messages.php', 'SUCCESS');
|
|
||||||
} else {
|
|
||||||
hesk_process_messages($hesklang['sm_not_found'], './service_messages.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
} // End remove_sm()
|
|
||||||
|
|
||||||
|
|
||||||
function new_sm()
|
|
||||||
{
|
|
||||||
global $hesk_settings, $hesklang, $listBox;
|
|
||||||
global $hesk_error_buffer;
|
|
||||||
|
|
||||||
// A security check
|
|
||||||
# hesk_token_check('POST');
|
|
||||||
|
|
||||||
$hesk_error_buffer = array();
|
|
||||||
|
|
||||||
$style = intval(hesk_POST('style', 0));
|
|
||||||
if ($style > 4 || $style < 0) {
|
|
||||||
$style = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = empty($_POST['type']) ? 0 : 1;
|
|
||||||
$icon = hesk_POST('icon');
|
|
||||||
$title = hesk_input(hesk_POST('title')) or $hesk_error_buffer[] = $hesklang['sm_e_title'];
|
|
||||||
$message = hesk_getHTML(hesk_POST('message'));
|
|
||||||
|
|
||||||
// Clean the HTML code
|
|
||||||
require(HESK_PATH . 'inc/htmlpurifier/HeskHTMLPurifier.php');
|
|
||||||
$purifier = new HeskHTMLPurifier($hesk_settings['cache_dir']);
|
|
||||||
$message = $purifier->heskPurify($message);
|
|
||||||
|
|
||||||
// Any errors?
|
|
||||||
if (count($hesk_error_buffer)) {
|
|
||||||
$_SESSION['new_sm'] = array(
|
|
||||||
'style' => $style,
|
|
||||||
'type' => $type,
|
|
||||||
'title' => $title,
|
|
||||||
'icon' => $icon,
|
|
||||||
'message' => hesk_input(hesk_POST('message')),
|
|
||||||
);
|
|
||||||
|
|
||||||
$tmp = '';
|
|
||||||
foreach ($hesk_error_buffer as $error) {
|
|
||||||
$tmp .= "<li>$error</li>\n";
|
|
||||||
}
|
|
||||||
$hesk_error_buffer = $tmp;
|
|
||||||
|
|
||||||
$hesk_error_buffer = $hesklang['rfm'] . '<br /><br /><ul>' . $hesk_error_buffer . '</ul>';
|
|
||||||
hesk_process_messages($hesk_error_buffer, 'service_messages.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just preview the message?
|
|
||||||
if (isset($_POST['sm_preview'])) {
|
|
||||||
$_SESSION['preview_sm'] = true;
|
|
||||||
|
|
||||||
$_SESSION['new_sm'] = array(
|
|
||||||
'style' => $style,
|
|
||||||
'type' => $type,
|
|
||||||
'title' => $title,
|
|
||||||
'icon' => $icon,
|
|
||||||
'message' => $message,
|
|
||||||
);
|
|
||||||
|
|
||||||
header('Location: service_messages.php');
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$_SESSION['smord'] = hesk_dbInsertID();
|
|
||||||
hesk_process_messages($hesklang['sm_added'], 'service_messages.php', 'SUCCESS');
|
|
||||||
|
|
||||||
} // End new_sm()
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -5,6 +5,7 @@ namespace BusinessLogic\ServiceMessages;
|
|||||||
|
|
||||||
// TODO Test
|
// TODO Test
|
||||||
use BusinessLogic\Exceptions\ValidationException;
|
use BusinessLogic\Exceptions\ValidationException;
|
||||||
|
use BusinessLogic\Navigation\Direction;
|
||||||
use BusinessLogic\ValidationModel;
|
use BusinessLogic\ValidationModel;
|
||||||
use DataAccess\ServiceMessages\ServiceMessagesGateway;
|
use DataAccess\ServiceMessages\ServiceMessagesGateway;
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ class ServiceMessageHandler extends \BaseClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createServiceMessage($serviceMessage, $heskSettings) {
|
function createServiceMessage($serviceMessage, $heskSettings) {
|
||||||
$this->validate($serviceMessage);
|
$this->validate($serviceMessage, $heskSettings);
|
||||||
|
|
||||||
if ($serviceMessage->icon === null) {
|
if ($serviceMessage->icon === null) {
|
||||||
switch ($serviceMessage->style) {
|
switch ($serviceMessage->style) {
|
||||||
@ -47,7 +48,7 @@ class ServiceMessageHandler extends \BaseClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function editServiceMessage($serviceMessage, $heskSettings) {
|
function editServiceMessage($serviceMessage, $heskSettings) {
|
||||||
$this->validate($serviceMessage, false);
|
$this->validate($serviceMessage, $heskSettings, false);
|
||||||
|
|
||||||
if ($serviceMessage->icon === null) {
|
if ($serviceMessage->icon === null) {
|
||||||
switch ($serviceMessage->style) {
|
switch ($serviceMessage->style) {
|
||||||
@ -72,19 +73,52 @@ class ServiceMessageHandler extends \BaseClass {
|
|||||||
return $this->serviceMessageGateway->updateServiceMessage($serviceMessage, $heskSettings);
|
return $this->serviceMessageGateway->updateServiceMessage($serviceMessage, $heskSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteServiceMessage($id, $heskSettings) {
|
||||||
|
$this->serviceMessageGateway->deleteServiceMessage($id, $heskSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortServiceMessage($id, $direction, $heskSettings) {
|
||||||
|
$serviceMessages = $this->serviceMessageGateway->getServiceMessages($heskSettings);
|
||||||
|
$serviceMessage = null;
|
||||||
|
foreach ($serviceMessages as $innerServiceMessage) {
|
||||||
|
if ($innerServiceMessage->id === intval($id)) {
|
||||||
|
$serviceMessage = $innerServiceMessage;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($serviceMessage === null) {
|
||||||
|
throw new \BaseException("Could not find category with ID {$id}!");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($direction === Direction::UP) {
|
||||||
|
$serviceMessage->order -= 15;
|
||||||
|
} else {
|
||||||
|
$serviceMessage->order += 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->serviceMessageGateway->updateServiceMessage($serviceMessage, $heskSettings);
|
||||||
|
$this->serviceMessageGateway->resortAllServiceMessages($heskSettings);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $serviceMessage ServiceMessage
|
* @param $serviceMessage ServiceMessage
|
||||||
* @param bool $isNew
|
* @param bool $isNew
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
private function validate($serviceMessage, $isNew = true) {
|
private function validate($serviceMessage, $heskSettings, $isNew = true) {
|
||||||
$validationModel = new ValidationModel();
|
$validationModel = new ValidationModel();
|
||||||
if ($isNew && $serviceMessage->createdBy < 1) {
|
if ($isNew && $serviceMessage->createdBy < 1) {
|
||||||
$validationModel->errorKeys[] = 'MISSING_CREATOR';
|
$validationModel->errorKeys[] = 'MISSING_CREATOR';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($serviceMessage->message === null || trim($serviceMessage->message) === '') {
|
if ($serviceMessage->message === null || trim($serviceMessage->message) === '') {
|
||||||
$validationModel->errorKeys[] = 'MISSING_MESSAGE';
|
$validationModel->errorKeys[] = 'MISSING_MESSAGE';
|
||||||
|
} else {
|
||||||
|
$htmlPurifier = new \HeskHTMLPurifier($heskSettings['cache_dir']);
|
||||||
|
$serviceMessage->message = $htmlPurifier->heskPurify($serviceMessage->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($serviceMessage->title === null || trim($serviceMessage->title) === '') {
|
if ($serviceMessage->title === null || trim($serviceMessage->title) === '') {
|
||||||
$validationModel->errorKeys[] = 'MISSING_TITLE';
|
$validationModel->errorKeys[] = 'MISSING_TITLE';
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ use BusinessLogic\Security\UserContext;
|
|||||||
use BusinessLogic\ServiceMessages\ServiceMessage;
|
use BusinessLogic\ServiceMessages\ServiceMessage;
|
||||||
use BusinessLogic\ServiceMessages\ServiceMessageHandler;
|
use BusinessLogic\ServiceMessages\ServiceMessageHandler;
|
||||||
use Controllers\JsonRetriever;
|
use Controllers\JsonRetriever;
|
||||||
|
use Symfony\Component\EventDispatcher\Tests\Service;
|
||||||
|
|
||||||
class ServiceMessagesController extends \BaseClass {
|
class ServiceMessagesController extends \BaseClass {
|
||||||
function get() {
|
function get() {
|
||||||
@ -41,6 +42,17 @@ class ServiceMessagesController extends \BaseClass {
|
|||||||
return output($element);
|
return output($element);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function delete($id) {
|
||||||
|
global $applicationContext, $hesk_settings;
|
||||||
|
|
||||||
|
/* @var $handler ServiceMessageHandler */
|
||||||
|
$handler = $applicationContext->get(ServiceMessageHandler::clazz());
|
||||||
|
|
||||||
|
$handler->deleteServiceMessage($id, $hesk_settings);
|
||||||
|
|
||||||
|
return http_response_code(204);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $data array
|
* @param $data array
|
||||||
* @param $userContext UserContext
|
* @param $userContext UserContext
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace DataAccess\ServiceMessages;
|
namespace DataAccess\ServiceMessages;
|
||||||
|
|
||||||
|
|
||||||
use BusinessLogic\DateTimeHelpers;
|
|
||||||
use BusinessLogic\ServiceMessages\ServiceMessage;
|
use BusinessLogic\ServiceMessages\ServiceMessage;
|
||||||
use BusinessLogic\ServiceMessages\ServiceMessageStyle;
|
use BusinessLogic\ServiceMessages\ServiceMessageStyle;
|
||||||
use DataAccess\CommonDao;
|
use DataAccess\CommonDao;
|
||||||
@ -49,6 +48,10 @@ class ServiceMessagesGateway extends CommonDao {
|
|||||||
return $serviceMessage;
|
return $serviceMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $heskSettings
|
||||||
|
* @return ServiceMessage[]
|
||||||
|
*/
|
||||||
function getServiceMessages($heskSettings) {
|
function getServiceMessages($heskSettings) {
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
@ -100,4 +103,31 @@ class ServiceMessagesGateway extends CommonDao {
|
|||||||
|
|
||||||
return $serviceMessage;
|
return $serviceMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteServiceMessage($id, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "service_messages`
|
||||||
|
WHERE `id` = " . intval($id));
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function resortAllServiceMessages($heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
$rs = hesk_dbQuery("SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "service_messages`
|
||||||
|
ORDER BY `order` ASC");
|
||||||
|
|
||||||
|
$sortValue = 10;
|
||||||
|
while ($row = hesk_dbFetchAssoc($rs)) {
|
||||||
|
hesk_dbQuery("UPDATE `" . hesk_dbEscape($heskSettings['db_pfix']) . "service_messages`
|
||||||
|
SET `order` = " . intval($sortValue) . "
|
||||||
|
WHERE `id` = " . intval($row['id']));
|
||||||
|
|
||||||
|
$sortValue += 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
}
|
}
|
@ -12,6 +12,7 @@ require_once(__DIR__ . '/Core/output.php');
|
|||||||
require_once(__DIR__ . '/../hesk_settings.inc.php');
|
require_once(__DIR__ . '/../hesk_settings.inc.php');
|
||||||
require_once(__DIR__ . '/http_response_code.php');
|
require_once(__DIR__ . '/http_response_code.php');
|
||||||
require_once(__DIR__ . '/../inc/admin_functions.inc.php');
|
require_once(__DIR__ . '/../inc/admin_functions.inc.php');
|
||||||
|
require_once(__DIR__ . '/../inc/htmlpurifier/HeskHTMLPurifier.php');
|
||||||
|
|
||||||
hesk_load_api_database_functions();
|
hesk_load_api_database_functions();
|
||||||
|
|
||||||
|
@ -203,7 +203,15 @@ Link::all(array(
|
|||||||
// Settings
|
// Settings
|
||||||
'/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()),
|
'/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()),
|
||||||
// Service Messages
|
// Service Messages
|
||||||
'/v1/service-messages' => action(\Controllers\ServiceMessages\ServiceMessagesController::clazz(), array(RequestMethod::GET, RequestMethod::POST, RequestMethod::PUT)),
|
'/v1/service-messages' => action(\Controllers\ServiceMessages\ServiceMessagesController::clazz(),
|
||||||
|
array(RequestMethod::GET, RequestMethod::POST, RequestMethod::PUT),
|
||||||
|
SecurityHandler::INTERNAL_OR_AUTH_TOKEN),
|
||||||
|
'/v1/service-messages/{i}' => action(\Controllers\ServiceMessages\ServiceMessagesController::clazz(),
|
||||||
|
array(RequestMethod::DELETE),
|
||||||
|
SecurityHandler::INTERNAL_OR_AUTH_TOKEN),
|
||||||
|
'/v1/service-messages/{i}/sort/{s}' => action(\Controllers\ServiceMessages\ServiceMessagesController::clazz() . '::sort',
|
||||||
|
array(RequestMethod::POST),
|
||||||
|
SecurityHandler::INTERNAL),
|
||||||
|
|
||||||
/* Internal use only routes */
|
/* Internal use only routes */
|
||||||
// Resend email response
|
// Resend email response
|
||||||
|
362
internal-api/js/service-messages.js
Normal file
362
internal-api/js/service-messages.js
Normal file
@ -0,0 +1,362 @@
|
|||||||
|
var serviceMessages = [];
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
loadTable();
|
||||||
|
bindEditModal();
|
||||||
|
bindModalCancelCallback();
|
||||||
|
bindFormSubmit();
|
||||||
|
bindDeleteButton();
|
||||||
|
bindCreateModal();
|
||||||
|
bindSortButtons();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function loadTable() {
|
||||||
|
$('#overlay').show();
|
||||||
|
var heskUrl = $('p#hesk-path').text();
|
||||||
|
var $tableBody = $('#table-body');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: 'GET',
|
||||||
|
url: heskUrl + 'api/index.php/v1/service-messages',
|
||||||
|
headers: { 'X-Internal-Call': true },
|
||||||
|
success: function(data) {
|
||||||
|
$tableBody.html('');
|
||||||
|
|
||||||
|
if (data.length === 0) {
|
||||||
|
// TODO "No Service Messages Found"
|
||||||
|
$('#overlay').hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var first = true;
|
||||||
|
var lastElement = null;
|
||||||
|
$.each(data, function() {
|
||||||
|
var $template = $($('#service-message-template').html());
|
||||||
|
|
||||||
|
$template.find('span[data-property="id"]').attr('data-value', this.id);
|
||||||
|
$template.find('span[data-property="title"]').html(
|
||||||
|
getFormattedTitle(this.icon, this.title, this.style));
|
||||||
|
$template.find('span[data-property="author"]').text(users[this.createdBy].name);
|
||||||
|
if (this.published) {
|
||||||
|
$template.find('span[data-property="type"]').text(mfhLang.text('sm_published'));
|
||||||
|
} else {
|
||||||
|
$template.find('span[data-property="type"]').text(mfhLang.text('sm_draft'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$tableBody.append($template);
|
||||||
|
|
||||||
|
serviceMessages[this.id] = this;
|
||||||
|
|
||||||
|
lastElement = this;
|
||||||
|
|
||||||
|
if (first) {
|
||||||
|
$template.find('[data-direction="up"]').css('visibility', 'hidden');
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (lastElement) {
|
||||||
|
//-- Hide the down arrow on the last element
|
||||||
|
$('[data-value="' + lastElement.id + '"]').parent().parent()
|
||||||
|
.find('[data-direction="down"]').css('visibility', 'hidden');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
mfhAlert.errorWithLog(mfhLang.text('error_retrieving_categories'), data.responseJSON);
|
||||||
|
console.error(data);
|
||||||
|
},
|
||||||
|
complete: function() {
|
||||||
|
refreshBackgroundVolatileItems();
|
||||||
|
$('[data-toggle="popover"]').popover({
|
||||||
|
trigger: 'hover',
|
||||||
|
container: 'body'
|
||||||
|
});
|
||||||
|
$('#overlay').hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFormattedTitle(icon, title, style) {
|
||||||
|
var $template = $($('#service-message-title-template').html());
|
||||||
|
|
||||||
|
var alertClass = 'none';
|
||||||
|
switch (style) {
|
||||||
|
case 'ERROR':
|
||||||
|
alertClass = 'alert alert-danger';
|
||||||
|
break;
|
||||||
|
case 'NOTICE':
|
||||||
|
alertClass = 'alert alert-warning';
|
||||||
|
break;
|
||||||
|
case 'INFO':
|
||||||
|
alertClass = 'alert alert-info';
|
||||||
|
break;
|
||||||
|
case 'SUCCESS':
|
||||||
|
alertClass = 'alert alert-success';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$template.addClass(alertClass)
|
||||||
|
.find('[data-property="icon"]').addClass(icon).end()
|
||||||
|
.find('[data-property="title"]').text(title);
|
||||||
|
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getServiceMessagePreview(icon, title, message, style) {
|
||||||
|
var $template = $('#service-message-preview-template').html();
|
||||||
|
|
||||||
|
var alertClass = 'none';
|
||||||
|
switch (style) {
|
||||||
|
case 'ERROR':
|
||||||
|
alertClass = 'alert alert-danger';
|
||||||
|
break;
|
||||||
|
case 'NOTICE':
|
||||||
|
alertClass = 'alert alert-warning';
|
||||||
|
break;
|
||||||
|
case 'INFO':
|
||||||
|
alertClass = 'alert alert-info';
|
||||||
|
break;
|
||||||
|
case 'SUCCESS':
|
||||||
|
alertClass = 'alert alert-success';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$template = $template.replace('none', alertClass)
|
||||||
|
.replace('{{TITLE}}', title)
|
||||||
|
.replace('{{MESSAGE}}', message);
|
||||||
|
$template = $($template);
|
||||||
|
if (icon !== '') {
|
||||||
|
$template.find('i.fa').removeClass('fa').addClass(icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindEditModal() {
|
||||||
|
$(document).on('click', '[data-action="edit"]', function() {
|
||||||
|
var element = categories[$(this).parent().parent().find('[data-property="id"]').text()];
|
||||||
|
var $modal = $('#category-modal');
|
||||||
|
|
||||||
|
$modal.find('#edit-label').show();
|
||||||
|
$modal.find('#create-label').hide();
|
||||||
|
|
||||||
|
$modal.find('input[name="name"]').val(element.name).end()
|
||||||
|
.find('select[name="priority"]').val(element.priority).end()
|
||||||
|
.find('select[name="manager"]').val(element.manager === null ? 0 : element.manager).end()
|
||||||
|
.find('input[name="id"]').val(element.id).end()
|
||||||
|
.find('select[name="usage"]').val(element.usage).end()
|
||||||
|
.find('input[name="display-border"][value="' + (element.displayBorder ? 1 : 0) + '"]')
|
||||||
|
.prop('checked', 'checked').end();
|
||||||
|
|
||||||
|
var backgroundColor = element.backgroundColor;
|
||||||
|
var foregroundColor = element.foregroundColor;
|
||||||
|
var colorpickerOptions = {
|
||||||
|
format: 'hex',
|
||||||
|
color: backgroundColor
|
||||||
|
};
|
||||||
|
$modal.find('input[name="background-color"]')
|
||||||
|
.colorpicker(colorpickerOptions).end().modal('show');
|
||||||
|
|
||||||
|
colorpickerOptions = {
|
||||||
|
format: 'hex'
|
||||||
|
};
|
||||||
|
if (foregroundColor != '' && foregroundColor !== 'AUTO') {
|
||||||
|
colorpickerOptions.color = foregroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
$modal.find('input[name="foreground-color"]')
|
||||||
|
.colorpicker(colorpickerOptions).end().modal('show');
|
||||||
|
|
||||||
|
if (foregroundColor === '' || foregroundColor === 'AUTO') {
|
||||||
|
$modal.find('input[name="foreground-color"]').colorpicker('setValue', '#fff');
|
||||||
|
$modal.find('input[name="foreground-color"]').val('');
|
||||||
|
}
|
||||||
|
|
||||||
|
$modal.find('input[name="cat-order"]').val(element.catOrder);
|
||||||
|
$modal.find('input[name="autoassign"][value="' + (element.autoAssign ? 1 : 0) + '"]')
|
||||||
|
.prop('checked', 'checked');
|
||||||
|
$modal.find('input[name="type"][value="' + (element.type ? 1 : 0) + '"]')
|
||||||
|
.prop('checked', 'checked');
|
||||||
|
$modal.find('textarea[name="description"]').val(element.description === null ? '' : element.description);
|
||||||
|
|
||||||
|
$modal.modal('show');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindCreateModal() {
|
||||||
|
$('#create-button').click(function() {
|
||||||
|
var $modal = $('#category-modal');
|
||||||
|
$modal.find('#edit-label').hide();
|
||||||
|
$modal.find('#create-label').show();
|
||||||
|
|
||||||
|
$modal.find('input[name="name"]').val('');
|
||||||
|
$modal.find('select[name="priority"]').val(3); // Low priority
|
||||||
|
$modal.find('select[name="usage"]').val(0); // Tickets and events
|
||||||
|
$modal.find('input[name="id"]').val(-1);
|
||||||
|
$modal.find('textarea[name="description"]').val('');
|
||||||
|
$modal.find('input[name="cat-order"]').val('');
|
||||||
|
$modal.find('input[name="type"][value="0"]').prop('checked', 'checked');
|
||||||
|
$modal.find('input[name="autoassign"][value="0"]').prop('checked', 'checked');
|
||||||
|
$modal.find('input[name="display-border"][value="0"]')
|
||||||
|
.prop('checked', 'checked');
|
||||||
|
|
||||||
|
var colorpickerOptions = {
|
||||||
|
format: 'hex',
|
||||||
|
color: '#fff'
|
||||||
|
};
|
||||||
|
$modal.find('input[name="background-color"]')
|
||||||
|
.colorpicker(colorpickerOptions).end().modal('show');
|
||||||
|
$modal.find('input[name="background-color"]').val('');
|
||||||
|
$modal.find('input[name="foreground-color"]')
|
||||||
|
.colorpicker(colorpickerOptions).end().modal('show');
|
||||||
|
$modal.find('input[name="foreground-color"]').val('');
|
||||||
|
|
||||||
|
$modal.modal('show');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindModalCancelCallback() {
|
||||||
|
$('.cancel-callback').click(function() {
|
||||||
|
var $editCategoryModal = $('#category-modal');
|
||||||
|
|
||||||
|
$editCategoryModal.find('input[name="background-color"]').val('').colorpicker('destroy').end();
|
||||||
|
$editCategoryModal.find('input[name="foreground-color"]').val('').colorpicker('destroy').end();
|
||||||
|
$editCategoryModal.find('input[name="display-border"][value="1"]').prop('checked');
|
||||||
|
$editCategoryModal.find('input[name="display-border"][value="0"]').prop('checked');
|
||||||
|
$editCategoryModal.find('input[name="autoassign"][value="1"]').prop('checked');
|
||||||
|
$editCategoryModal.find('input[name="autoassign"][value="0"]').prop('checked');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindFormSubmit() {
|
||||||
|
$('form#manage-category').submit(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var heskUrl = $('p#hesk-path').text();
|
||||||
|
|
||||||
|
var $modal = $('#category-modal');
|
||||||
|
|
||||||
|
var foregroundColor = $modal.find('input[name="foreground-color"]').val();
|
||||||
|
var manager = parseInt($modal.find('select[name="manager"]').val());
|
||||||
|
var data = {
|
||||||
|
autoassign: $modal.find('input[name="autoassign"]').val() === 'true',
|
||||||
|
backgroundColor: $modal.find('input[name="background-color"]').val(),
|
||||||
|
description: $modal.find('textarea[name="description"]').val(),
|
||||||
|
displayBorder: $modal.find('input[name="display-border"]:checked').val() === '1',
|
||||||
|
foregroundColor: foregroundColor === '' ? 'AUTO' : foregroundColor,
|
||||||
|
name: $modal.find('input[name="name"]').val(),
|
||||||
|
priority: parseInt($modal.find('select[name="priority"]').val()),
|
||||||
|
manager: manager === 0 ? null : manager,
|
||||||
|
type: parseInt($modal.find('input[name="type"]:checked').val()),
|
||||||
|
usage: parseInt($modal.find('select[name="usage"]').val()),
|
||||||
|
catOrder: parseInt($modal.find('input[name="cat-order"]').val())
|
||||||
|
};
|
||||||
|
|
||||||
|
var url = heskUrl + 'api/index.php/v1/categories/';
|
||||||
|
var method = 'POST';
|
||||||
|
|
||||||
|
var categoryId = parseInt($modal.find('input[name="id"]').val());
|
||||||
|
if (categoryId !== -1) {
|
||||||
|
url += categoryId;
|
||||||
|
method = 'PUT';
|
||||||
|
}
|
||||||
|
|
||||||
|
$modal.find('#action-buttons').find('.cancel-button').attr('disabled', 'disabled');
|
||||||
|
$modal.find('#action-buttons').find('.save-button').attr('disabled', 'disabled');
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
url: url,
|
||||||
|
headers: {
|
||||||
|
'X-Internal-Call': true,
|
||||||
|
'X-HTTP-Method-Override': method
|
||||||
|
},
|
||||||
|
data: JSON.stringify(data),
|
||||||
|
success: function(data) {
|
||||||
|
var format = undefined;
|
||||||
|
if (categoryId === -1) {
|
||||||
|
format = mfhLang.html('cat_name_added');
|
||||||
|
mfhAlert.success(format.replace('%s', data.name));
|
||||||
|
} else {
|
||||||
|
format = mfhLang.html('category_updated');
|
||||||
|
mfhAlert.success(format.replace('%s', data.name));
|
||||||
|
}
|
||||||
|
$modal.modal('hide');
|
||||||
|
loadTable();
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
mfhAlert.errorWithLog(mfhLang.text('error_saving_updating_category'), data.responseJSON);
|
||||||
|
console.error(data);
|
||||||
|
},
|
||||||
|
complete: function(data) {
|
||||||
|
$modal.find('#action-buttons').find('.cancel-button').removeAttr('disabled');
|
||||||
|
$modal.find('#action-buttons').find('.save-button').removeAttr('disabled');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindDeleteButton() {
|
||||||
|
$(document).on('click', '[data-action="delete"]', function() {
|
||||||
|
$('#overlay').show();
|
||||||
|
|
||||||
|
var heskUrl = $('p#hesk-path').text();
|
||||||
|
var element = categories[$(this).parent().parent().find('[data-property="id"]').text()];
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
url: heskUrl + 'api/index.php/v1/categories/' + element.id,
|
||||||
|
headers: {
|
||||||
|
'X-Internal-Call': true,
|
||||||
|
'X-HTTP-Method-Override': 'DELETE'
|
||||||
|
},
|
||||||
|
success: function() {
|
||||||
|
mfhAlert.success(mfhLang.text('cat_removed'));
|
||||||
|
loadTable();
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
$('#overlay').hide();
|
||||||
|
mfhAlert.errorWithLog(mfhLang.text('error_deleting_category'), data.responseJSON);
|
||||||
|
console.error(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindGenerateLinkModal() {
|
||||||
|
var $modal = $('#generate-link-modal');
|
||||||
|
|
||||||
|
$modal.find('.input-group-addon').click(function() {
|
||||||
|
clipboard.copy($modal.find('input[type="text"]').val());
|
||||||
|
mfhAlert.success(mfhLang.text('copied_to_clipboard'));
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('click', '[data-property="generate-link"] i.fa-code', function () {
|
||||||
|
var heskUrl = $('p#hesk-url').text();
|
||||||
|
|
||||||
|
var url = heskUrl + '/index.php?a=add&catid=' + $(this).parent().data('category-id');
|
||||||
|
|
||||||
|
$modal.find('input[type="text"]').val(url).end().modal('show');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindSortButtons() {
|
||||||
|
$(document).on('click', '[data-action="sort"]', function() {
|
||||||
|
$('#overlay').show();
|
||||||
|
var heskUrl = $('p#hesk-path').text();
|
||||||
|
var direction = $(this).data('direction');
|
||||||
|
var element = categories[$(this).parent().parent().parent().find('[data-property="id"]').text()];
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
url: heskUrl + 'api/index.php/v1-internal/categories/' + element.id + '/sort/' + direction,
|
||||||
|
headers: { 'X-Internal-Call': true },
|
||||||
|
success: function() {
|
||||||
|
loadTable();
|
||||||
|
},
|
||||||
|
error: function(data) {
|
||||||
|
mfhAlert.errorWithLog(mfhLang.text('error_sorting_categories'), data.responseJSON);
|
||||||
|
console.error(data);
|
||||||
|
$('#overlay').hide();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user