__('Delete')
);
/* set default action */
set_default_action();
switch (get_request_var('action')) {
case 'save':
form_save();
break;
case 'ajax_dnd':
automation_template_dnd();
break;
case 'actions':
form_actions();
break;
case 'movedown':
automation_movedown();
header('Location: automation_templates.php?header=false');
break;
case 'moveup':
automation_moveup();
header('Location: automation_templates.php?header=false');
break;
case 'remove':
automation_remove();
header('Location: automation_templates.php?header=false');
break;
case 'edit':
top_header();
template_edit();
bottom_footer();
break;
default:
top_header();
template();
bottom_footer();
break;
}
function automation_template_dnd() {
/* ================= Input validation ================= */
get_filter_request_var('id');
/* ================= Input validation ================= */
if (!isset_request_var('template_ids') || !is_array(get_nfilter_request_var('template_ids'))) exit;
/* template table contains one row defined as 'nodrag&nodrop' */
// unset($_REQUEST['template_ids'][0]);
/* delivered template ids has to be exactly the same like we have stored */
$old_order = array();
$i = 1;
foreach(get_nfilter_request_var('template_ids') as $sequence => $id) {
if (empty($id)) continue;
$new_order[$i] = str_replace('line', '', $id);
$i++;
}
$items = db_fetch_assoc('SELECT id, sequence FROM automation_templates ORDER BY sequence');
if (sizeof($items)) {
$i = 1;
foreach($items as $item) {
$old_order[$i] = $item['id'];
$i++;
}
} else {
header('Location: automation_templates.php?header=false');
exit;
}
/* perform some sanity checks */
if (sizeof(array_diff($new_order, $old_order)) > 0) {
header('Location: automation_templates.php?header=false');
exit;
}
if (sizeof(array_diff_key($new_order, $old_order))>0) {
header('Location: automation_templates.php?header=false');
exit;
}
foreach($new_order as $sequence => $id) {
input_validate_input_number($sequence);
input_validate_input_number($id);
db_execute_prepared('UPDATE automation_templates SET sequence = ? WHERE id = ?', array($sequence, $id));
}
header('Location: automation_templates.php?header=false');
exit;
}
function automation_movedown() {
move_item_down('automation_templates', get_filter_request_var('id'));
}
function automation_moveup() {
move_item_up('automation_templates', get_filter_request_var('id'));
}
function automation_remove() {
db_execute_prepared('DELETE FROM automation_templates WHERE id = ?', array(get_filter_request_var('id')));
}
function form_actions() {
global $at_actions;
/* ================= input validation ================= */
get_filter_request_var('drp_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-zA-Z0-9_]+)$/')));
/* ==================================================== */
/* if we are to save this form, instead of display it */
if (isset_request_var('selected_items')) {
$selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items'));
if ($selected_items != false) {
if (get_nfilter_request_var('drp_action') == '1') { /* delete */
db_execute('DELETE FROM automation_templates WHERE ' . array_to_sql_or($selected_items, 'id'));
}
}
header('Location: automation_templates.php?header=false');
exit;
}
/* setup some variables */
$at_list = ''; $i = 0;
foreach ($_POST as $var => $val) {
if (preg_match('/^chk_([0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
input_validate_input_number($matches[1]);
/* ==================================================== */
$at_list .= '
' . htmlspecialchars(db_fetch_cell_prepared('SELECT ht.name FROM automation_templates AS at INNER JOIN host_template AS ht ON ht.id=at.host_template WHERE at.id = ?', array($matches[1]))) . '
\n";
}
html_end_box(false);
if (sizeof($dts)) {
print $nav;
}
/* draw the dropdown containing a list of available actions for this form */
draw_actions_dropdown($at_actions);
form_end();
?>