';
/* Step 1 */
if ($step == 1)
echo '';
if ($id) {
echo '';
echo __('Step').' 1 : '.__('Conditions');
echo '';
} else {
echo __('Step').' 1 : '.__('Conditions');
}
if ($step == 1)
echo '';
/* Step 2 */
echo ' » ';
if ($step == 2)
echo '';
if ($id) {
echo '';
echo __('Step').' 2 : '.__('Firing');
echo '';
} else {
echo __('Step').' 2 : '.__('Firing');
}
if ($step == 2)
echo '';
/* Step 3 */
echo ' » ';
if ($step == 3)
echo '';
if ($id) {
echo '';
echo __('Step').' 3 : '.__('Recovery');
echo '';
} else {
echo __('Step').' 3 : '.__('Recovery');
}
if ($step == 3)
echo '';
echo '';
}
function print_alert_template_example ($id, $return = false) {
$output = '';
$is = false;
$is_not = false;
$matches = false;
$matches_not = false;
$between = false;
$between_not = false;
$under = false;
$over = false;
$max = false;
$min = false;
$value = false;
$output .= ' ';
$output .= '';
if ($id) {
$template = get_alert_template ($id);
switch ($template['type']) {
case 'not_equal':
/* Do not translate the HTML attributes */
$output .= __('The alert would fire when the value is ');
break;
case 'equal':
/* Do not translate the HTML attributes */
$output .= __('The alert would fire when the value is not ');
break;
case 'regex':
if ($template['matches_value'])
/* Do not translate the HTML attributes */
$output .= __('The alert would fire when the value matches ');
else
/* Do not translate the HTML attributes */
$output .= __('The alert would fire when the value doesn\'t match ');
$value = $template['value'];
break;
case 'max_min':
if ($template['matches_value'])
/* Do not translate the HTML attributes */
$output .= __('The alert would fire when the value is between and ');
else
/* Do not translate the HTML attributes */
$output .= __('The alert would fire when the value is not between and ');
break;
case 'max':
/* Do not translate the HTML attributes */
$output .= __('The alert would fire when the value is over ');
break;
case 'min':
/* Do not translate the HTML attributes */
$output .= __('The alert would fire when the value is under ');
break;
}
}
$output .= '';
if ($return)
return $output;
echo $output;
}
function update_template ($step) {
$id = (int) get_parameter ('id');
if (empty ($id))
return false;
if ($step == 1) {
$type = (string) get_parameter ('type');
$name = (string) get_parameter ('name');
$description = (string) get_parameter ('description');
$type = (string) get_parameter ('type');
$value = (string) get_parameter ('value');
$max = (float) get_parameter ('max');
$min = (float) get_parameter ('min');
$matches = (bool) get_parameter ('matches_value');
$result = update_alert_template ($id,
array ('type' => $type,
'description' => $description,
'value' => $value,
'max_value' => $max,
'min_value' => $min,
'matches_value' => $matches));
} elseif ($step == 2) {
$monday = (bool) get_parameter ('monday');
$tuesday = (bool) get_parameter ('tuesday');
$wednesday = (bool) get_parameter ('wednesday');
$thursday = (bool) get_parameter ('thursday');
$friday = (bool) get_parameter ('friday');
$saturday = (bool) get_parameter ('saturday');
$sunday = (bool) get_parameter ('sunday');
$time_from = (string) get_parameter ('time_from');
$time_from = date ("H:s:00", strtotime ($time_from));
$time_to = (string) get_parameter ('time_to');
$time_to = date ("H:s:00", strtotime ($time_to));
$threshold = (int) get_parameter ('threshold');
$max_alerts = (int) get_parameter ('max_alerts');
$min_alerts = (int) get_parameter ('min_alerts');
if ($threshold == -1)
$threshold = (int) get_parameter ('other_threshold');
$field1 = (string) get_parameter ('field1');
$field2 = (string) get_parameter ('field2');
$field3 = (string) get_parameter ('field3');
$default_action = (int) get_parameter ('default_action');
if (empty ($default_action)) {
$default_action = NULL;
$field1 = '';
$field2 = '';
$field3 = '';
}
$values = array ('monday' => $monday,
'tuesday' => $tuesday,
'wednesday' => $wednesday,
'thursday' => $thursday,
'friday' => $friday,
'saturday' => $saturday,
'sunday' => $sunday,
'time_from' => $time_from,
'time_to' => $time_to,
'time_threshold' => $threshold,
'default_action' => $default_action,
'field1' => $field1,
'field2' => $field2,
'field3' => $field3,
'max_alerts' => $max_alerts,
'min_alerts' => $min_alerts
);
if ($default_action) {
$values['id_alert_action'] = $default_action;
$values['field1'] = $field1;
$values['field2'] = $field2;
$values['field3'] = $field3;
}
$result = update_alert_template ($id, $values);
} elseif ($step == 3) {
$recovery_notify = (bool) get_parameter ('recovery_notify');
$field2_recovery = (bool) get_parameter ('field2_recovery');
$field3_recovery = (bool) get_parameter ('field3_recovery');
$result = update_alert_template ($id,
array ('recovery_notify' => $recovery_notify,
'field2_recovery' => $field2_recovery,
'field3_recovery' => $field3_recovery));
} else {
return false;
}
return $result;
}
$id = (int) get_parameter ('id');
/* We set here the number of steps */
define ('LAST_STEP', 3);
$step = (int) get_parameter ('step', 1);
$create_template = (bool) get_parameter ('create_template');
$update_template = (bool) get_parameter ('update_template');
$name = '';
$description = '';
$type = '';
$value = '';
$max = '';
$min = '';
$time_from = '12:00';
$time_to = '12:00';
$monday = true;
$tuesday = true;
$wednesday = true;
$thursday = true;
$friday = true;
$saturday = true;
$sunday = true;
$default_action = 0;
$field1 = '';
$field2 = '';
$field3 = '';
$min_alerts = 0;
$max_alerts = 1;
$threshold = 300;
$recovery_notify = false;
$field2_recovery = '';
$field3_recovery = '';
if ($create_template) {
$name = (string) get_parameter ('name');
$description = (string) get_parameter ('description');
$type = (string) get_parameter ('type');
$value = (string) get_parameter ('value');
$max = (float) get_parameter ('max');
$min = (float) get_parameter ('min');
$result = create_alert_template ($name, $type,
array ('description' => $description,
'value' => $value,
'max' => $max,
'min' => $min));
print_error_message ($result, __('Successfully created'),
__('Could not be created'));
/* Go to previous step in case of error */
if ($result === false)
$step = $step - 1;
else
$id = $result;
}
if ($update_template) {
$result = update_template ($step - 1);
print_error_message ($result, __('Successfully updated'),
__('Could not be updated'));
/* Go to previous step in case of error */
if ($result === false) {
$step = $step - 1;
}
}
if ($id && ! $create_template) {
$template = get_alert_template ($id);
$name = $template['name'];
$description = $template['description'];
$type = $template['type'];
$value = $template['value'];
$max = $template['max_value'];
$min = $template['min_value'];
$matches = $template['matches_value'];
$time_from = $template['time_from'];
$time_to = $template['time_to'];
$monday = (bool) $template['monday'];
$tuesday = (bool) $template['tuesday'];
$wednesday = (bool) $template['wednesday'];
$thursday = (bool) $template['thursday'];
$friday = (bool) $template['friday'];
$saturday = (bool) $template['saturday'];
$sunday = (bool) $template['sunday'];
$max_alerts = $template['max_alerts'];
$min_alerts = $template['min_alerts'];
$threshold = $template['time_threshold'];
$recovery_notify = $template['recovery_notify'];
$field2_recovery = $template['field2_recovery'];
$field3_recovery = $template['field3_recovery'];
$default_action = $template['id_alert_action'];
$field1 = $template['field1'];
$field2 = $template['field2'];
$field3 = $template['field3'];
}
echo '