';
form_hidden_box($field_name, $field_array['value'], ((isset($field_array['default'])) ? $field_array['default'] : ''), true);
print '
';
} elseif ($field_array['method'] == 'hidden_zero') {
if (!isset($field_array['value'])) {
cacti_log("WARNING: Cacti Form field '$field_name' does not include a 'value' Column. Using default", false);
cacti_debug_backtrace('form_edit');
$field_array['value'] = $field_array['default'];
}
print '';
form_hidden_box($field_name, $field_array['value'], '0', true);
print '
';
} elseif ($field_array['method'] == 'spacer') {
$collapsible = (isset($field_array['collapsible']) && $field_array['collapsible'] == 'true');
print "';
} else {
// Make a row using a div
if (isset($config_array['force_row_color'])) {
print "";
} else {
print "
';
}
$i++;
}
if (isset($_SESSION['sess_error_fields'])) {
kill_session_var('sess_error_fields');
}
}
}
/**
* draw_edit_control - draws a single control to be used on an html edit form
*
* @param $field_name - the name of the control
* @param $field_array - an array containing data for this control. see include/global_form.php
* for more specific syntax
*/
function draw_edit_control($field_name, &$field_array) {
switch ($field_array['method']) {
case 'textbox':
form_text_box(
$field_name,
$field_array['value'],
((isset($field_array['default'])) ? $field_array['default'] : ''),
$field_array['max_length'],
((isset($field_array['size'])) ? $field_array['size'] : '40'),
((isset($field_array['type'])) ? $field_array['type'] : 'text'),
((isset($field_array['form_id'])) ? $field_array['form_id'] : ''),
((isset($field_array['placeholder'])) ? $field_array['placeholder'] : '')
);
break;
case 'filepath':
form_filepath_box(
$field_name,
$field_array['value'],
((isset($field_array['default'])) ? $field_array['default'] : ''),
$field_array['max_length'],
((isset($field_array['size'])) ? $field_array['size'] : '40'),
'text',
((isset($field_array['form_id'])) ? $field_array['form_id'] : '')
);
break;
case 'dirpath':
form_dirpath_box(
$field_name,
$field_array['value'],
((isset($field_array['default'])) ? $field_array['default'] : ''),
$field_array['max_length'],
((isset($field_array['size'])) ? $field_array['size'] : '40'),
'text',
((isset($field_array['form_id'])) ? $field_array['form_id'] : '')
);
break;
case 'textbox_password':
form_text_box(
$field_name,
$field_array['value'],
((isset($field_array['default'])) ? $field_array['default'] : ''),
$field_array['max_length'],
((isset($field_array['size'])) ? $field_array['size'] : '40'),
'password',
((isset($field_array['form_id'])) ? $field_array['form_id'] : ''),
'********'
);
print '
';
form_text_box(
$field_name . '_confirm',
$field_array['value'],
((isset($field_array['default'])) ? $field_array['default'] : ''),
$field_array['max_length'],
((isset($field_array['size'])) ? $field_array['size'] : '40'),
'password',
((isset($field_array['form_id'])) ? $field_array['form_id'] : ''),
'********'
);
break;
case 'textarea':
form_text_area(
$field_name,
$field_array['value'],
$field_array['textarea_rows'],
$field_array['textarea_cols'],
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : ''),
((isset($field_array['placeholder'])) ? $field_array['placeholder'] : '')
);
break;
case 'drop_array':
form_dropdown(
$field_name,
$field_array['array'],
'',
'',
$field_array['value'],
((isset($field_array['none_value'])) ? $field_array['none_value'] : ''),
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : '')
);
break;
case 'drop_language':
form_droplanguage(
$field_name,
'',
'',
$field_array['value'],
((isset($field_array['none_value'])) ? $field_array['none_value'] : ''),
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : '')
);
break;
case 'drop_files':
$array_files = array();
if (isset($field_array['directory'])) {
$dir = $field_array['directory'];
if (is_dir($dir) && is_readable($dir)) {
if (function_exists('scandir')) {
$files = scandir($dir);
} elseif ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
$files[] = $file;
}
closedir($dh);
}
if (cacti_sizeof($files)) {
foreach ($files as $file) {
if (is_readable($dir . '/' . $file) && $file != '.' && $file != '..') {
if (!in_array($file, $field_array['exclusions'], true)) {
$array_files[basename($file)] = basename($file);
}
}
}
}
}
}
form_dropdown(
$field_name,
$array_files,
'',
'',
$field_array['value'],
((isset($field_array['none_value'])) ? $field_array['none_value'] : ''),
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : '')
);
break;
case 'drop_sql':
form_dropdown(
$field_name,
db_fetch_assoc($field_array['sql']),
'name',
'id',
$field_array['value'],
((isset($field_array['none_value'])) ? $field_array['none_value'] : ''),
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : '')
);
break;
case 'drop_callback':
form_callback(
$field_name,
$field_array['sql'],
'name',
'id',
$field_array['action'],
$field_array['id'],
$field_array['value'],
((isset($field_array['none_value'])) ? $field_array['none_value'] : ''),
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : '')
);
break;
case 'drop_multi':
form_multi_dropdown(
$field_name,
$field_array['array'],
(isset($field_array['sql']) ? db_fetch_assoc($field_array['sql']) : $field_array['value']),
'id',
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : '')
);
break;
case 'drop_tree':
grow_dropdown_tree(
$field_array['tree_id'],
'0',
$field_name,
$field_array['value']
);
break;
case 'drop_color':
form_color_dropdown(
$field_name,
$field_array['value'],
__('None'),
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : '')
);
break;
case 'checkbox':
form_checkbox(
$field_name,
$field_array['value'],
$field_array['friendly_name'],
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['form_id'])) ? $field_array['form_id'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : ''),
$field_array['friendly_name']
);
break;
case 'checkbox_group':
if (isset($field_array['type']) && $field_array['type'] == 'flex') {
print "
" . PHP_EOL;
} else {
print " " . PHP_EOL;
}
foreach ($field_array['items'] as $check_name => $check_array) {
if (isset($field_array['type']) && $field_array['type'] == 'flex') {
print ' ';
}
form_checkbox(
$check_name,
$check_array['value'],
$check_array['friendly_name'],
((isset($check_array['default'])) ? $check_array['default'] : ''),
((isset($check_array['form_id'])) ? $check_array['form_id'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($check_array['on_change'])) ? $check_array['on_change'] : (((isset($field_array['on_change'])) ? $field_array['on_change'] : ''))),
$field_array['friendly_name'],
true
);
if (isset($field_array['type']) && $field_array['type'] == 'flex') {
print ' ';
} else {
print ' ';
}
}
if (isset($field_array['type']) && $field_array['type'] == 'flex') {
print ' ' . PHP_EOL;
} else {
print ' ' . PHP_EOL;
}
break;
case 'radio':
print "" . PHP_EOL;
foreach ($field_array['items'] as $radio_index => $radio_array) {
form_radio_button(
$field_name,
$field_array['value'],
$radio_array['radio_value'],
$radio_array['radio_caption'],
((isset($field_array['default'])) ? $field_array['default'] : ''),
((isset($field_array['class'])) ? $field_array['class'] : ''),
((isset($field_array['on_change'])) ? $field_array['on_change'] : '')
);
print ' ';
}
print ' ' . PHP_EOL;
break;
case 'custom':
print $field_array['value'];
break;
case 'template_checkbox':
print '' . html_boolean_friendly($field_array['value']) . '';
form_hidden_box($field_name, $field_array['value'], '', true);
break;
case 'template_drop_array':
print '' . $field_array['array'][$field_array['value']] . '';
form_hidden_box($field_name, $field_array['value'], '', true);
break;
case 'font':
form_font_box(
$field_name,
$field_array['value'],
((isset($field_array['default'])) ? $field_array['default'] : ''),
$field_array['max_length'],
((isset($field_array['size'])) ? $field_array['size'] : '40'),
'text',
((isset($field_array['form_id'])) ? $field_array['form_id'] : ''),
((isset($field_array['placeholder'])) ? $field_array['placeholder'] : '')
);
break;
case 'file':
form_file(
$field_name,
((isset($field_array['size'])) ? $field_array['size'] : '40'),
((isset($field_array['accept'])) ? $field_array['accept'] : '')
);
break;
case 'button':
form_button(
$field_name,
((isset($field_array['value'])) ? $field_array['value'] : ''),
((isset($field_array['title'])) ? $field_array['title'] : ''),
((isset($field_array['on_click'])) ? $field_array['on_click'] : '')
);
break;
case 'submit':
form_submit(
$field_name,
((isset($field_array['value'])) ? $field_array['value'] : ''),
((isset($field_array['title'])) ? $field_array['title'] : ''),
((isset($field_array['on_click'])) ? $field_array['on_click'] : '')
);
break;
default:
if (isset($field_array['value'])) {
print '' . html_escape($field_array['value']) . '';
form_hidden_box($field_name, $field_array['value'], '', true);
} else {
cacti_log('ERROR: Field Name: ' . $field_name . ' includes Method: ' . $field_array['method'] . ' does not include a value \'value\' element.', false);
}
break;
}
}
/**
* form_button - draws a standard button form element
*
* @param $form_name - the name of this form element
* @param $value - the display value for the button
* @param $title - the hover title for the button
* @param $action - the onClick action for the button
*/
function form_button($form_name, $value, $title = '', $action = '') {
print "';
}
/**
* form_button - draws a standard button form element
*
* @param $form_name - the name of this form element
* @param $value - the display value for the button
* @param $title - the hover title for the button
* @param $action - the onClick action for the button
*/
function form_submit($form_name, $value, $title = '', $action = '') {
print "';
}
/**
* form_file - draws a standard html file input element
*
* @param $form_name - the name of this form element
* @param $form_size - the size (width) of the textbox
* @param $form_accept - the file types permitted
*/
function form_file($form_name, $form_size = 30, $form_accept = '') {
print "\n";
print "\n";
print "\n";
print "\n";
print " \n";
}
/**
* form_filepath_box - draws a standard html textbox and provides status of a files existence
*
* @param $form_name - the name of this form element
* @param $form_previous_value - the current value of this form element
* @param $form_default_value - the value of this form element to use if there is
* no current value available
* @param $form_max_length - the maximum number of characters that can be entered
* into this textbox
* @param $form_size - the size (width) of the textbox
* @param $type - the type of textbox, either 'text' or 'password'
* @param $current_id - used to determine if a current value for this form element
* exists or not. a $current_id of '0' indicates that no current value exists,
* a non-zero value indicates that a current value does exist
* @param data - array containing 'text' element for display and if 'error' element present, shows failure
*/
function form_filepath_box($form_name, $form_previous_value, $form_default_value, $form_max_length, $form_size = 30, $type = 'text', $current_id = 0, $data = false) {
if (($form_previous_value == '') && (empty($current_id))) {
$form_previous_value = $form_default_value;
}
print "";
}
print " class='ui-state-default ui-corner-all$error_class'";
print " id='$form_name' placeholder='" . __esc('Enter a valid file path') . "' name='$form_name' size='$form_size'" . (!empty($form_max_length) ? " maxlength='$form_max_length'" : '') . " value='" . html_escape($form_previous_value) . "'>" . $extra_data;
}
/**
* form_dirpath_box - draws a standard html textbox and provides status of a directories existence
*
* @param $form_name - the name of this form element
* @param $form_previous_value - the current value of this form element
* @param $form_default_value - the value of this form element to use if there is
* no current value available
* @param $form_max_length - the maximum number of characters that can be entered
* into this textbox
* @param $form_size - the size (width) of the textbox
* @param $type - the type of textbox, either 'text' or 'password'
* @param $current_id - used to determine if a current value for this form element
* exists or not. a $current_id of '0' indicates that no current value exists,
* a non-zero value indicates that a current value does exist
*/
function form_dirpath_box($form_name, $form_previous_value, $form_default_value, $form_max_length, $form_size = 30, $type = 'text', $current_id = 0) {
if (($form_previous_value == '') && (empty($current_id))) {
$form_previous_value = $form_default_value;
}
print "";
} elseif (is_file($form_previous_value)) {
$extra_data = "';
} elseif ($form_previous_value == '') {
$extra_data = '';
} else {
$extra_data = "";
}
print " id='$form_name' name='$form_name' placeholder='" . __esc('Enter a valid directory path') . "' size='$form_size'" . (!empty($form_max_length) ? " maxlength='$form_max_length'" : '') . " value='" . html_escape($form_previous_value) . "'>" . $extra_data;
}
/**
* form_text_box - draws a standard html textbox
*
* @param $form_name - the name of this form element
* @param $form_previous_value - the current value of this form element
* @param $form_default_value - the value of this form element to use if there is
* no current value available
* @param $form_max_length - the maximum number of characters that can be entered
* into this textbox
* @param $form_size - the size (width) of the textbox
* @param $type - the type of textbox, either 'text' or 'password'
* @param $current_id - used to determine if a current value for this form element
* exists or not. a $current_id of '0' indicates that no current value exists,
* a non-zero value indicates that a current value does exist
* @param $placeholder - place a placeholder over an empty field
* @param $title - use a title attribute when hovering over the textbox
*/
function form_text_box($form_name, $form_previous_value, $form_default_value, $form_max_length, $form_size = 30, $type = 'text', $current_id = 0, $placeholder = '', $title = '') {
if (($form_previous_value == '') && (empty($current_id))) {
$form_previous_value = $form_default_value;
}
if ($type == 'password') {
print "";
}
print "\n";
}
/**
* form_hidden_box - draws a standard html hidden element
*
* @param $form_name - the name of this form element
* @param $form_previous_value - the current value of this form element
* @param $form_default_value - the value of this form element to use if there is
* no current value available
*/
function form_hidden_box($form_name, $form_previous_value, $form_default_value, $in_form = false) {
if ($form_previous_value == '') {
$form_previous_value = $form_default_value;
}
print "";
}
/**
* form_dropdown - draws a standard html dropdown box
*
* @param $form_name - the name of this form element
* @param $form_data - an array containing data for this dropdown. it can be formatted
* in one of two ways:
* $array["id"] = "value";
* -- or --
* $array[0]["id"] = 43;
* $array[0]["name"] = "Red";
* @param $column_display - used to identify the key to be used for display data. this
* is only applicable if the array is formatted using the second method above
* @param $column_id - used to identify the key to be used for id data. this
* is only applicable if the array is formatted using the second method above
* @param $form_previous_value - the current value of this form element
* @param $form_none_entry - the name to use for a default 'none' element in the dropdown
* @param $form_default_value - the value of this form element to use if there is
* no current value available
* @param $css_class - any css that needs to be applied to this form element
* @param $on_change - onChange modifier
*/
function form_dropdown($form_name, $form_data, $column_display, $column_id, $form_previous_value, $form_none_entry, $form_default_value, $class = '', $on_change = '') {
if ($form_previous_value == '') {
$form_previous_value = $form_default_value;
}
if (isset($_SESSION[SESS_ERROR_FIELDS])) {
if (!empty($_SESSION[SESS_ERROR_FIELDS][$form_name])) {
$class .= ($class != '' ? ' ' : '') . 'txtErrorTextBox';
unset($_SESSION[SESS_ERROR_FIELDS][$form_name]);
}
}
if (isset($_SESSION[SESS_FIELD_VALUES])) {
if (!empty($_SESSION[SESS_FIELD_VALUES][$form_name])) {
$form_previous_value = $_SESSION[SESS_FIELD_VALUES][$form_name];
}
}
if ($class != '') {
$class = " class='$class' ";
}
if ($on_change != '') {
$on_change = " onChange='$on_change' ";
}
print "\n";
}
function form_droplanguage($form_name, $column_display, $column_id, $form_previous_value, $form_none_entry, $form_default_value, $class = '', $on_change = '') {
if ($form_previous_value == '') {
$form_previous_value = $form_default_value;
}
if (isset($_SESSION[SESS_ERROR_FIELDS])) {
if (!empty($_SESSION[SESS_ERROR_FIELDS][$form_name])) {
$class .= ($class != '' ? ' ' : '') . 'txtErrorTextBox';
unset($_SESSION[SESS_ERROR_FIELDS][$form_name]);
}
}
if (isset($_SESSION[SESS_FIELD_VALUES])) {
if (!empty($_SESSION[SESS_FIELD_VALUES][$form_name])) {
$form_previous_value = $_SESSION[SESS_FIELD_VALUES][$form_name];
}
}
if ($class != '') {
$class = " class='$class' ";
}
if ($on_change != '') {
$on_change = " onChange='$on_change' ";
}
$languages = get_installed_locales();
print "';
}
function form_callback($form_name, $classic_sql, $column_display, $column_id, $action, $previous_id, $previous_value, $none_entry, $default_value, $class = '', $on_change = '') {
if ($previous_value == '') {
$previous_value = $default_value;
}
if (isset($_SESSION[SESS_ERROR_FIELDS])) {
if (!empty($_SESSION[SESS_ERROR_FIELDS][$form_name])) {
$class .= ($class != '' ? ' ' : '') . 'txtErrorTextBox';
unset($_SESSION[SESS_ERROR_FIELDS][$form_name]);
}
}
if ($class != '') {
$class = " class='$class' ";
}
$theme = get_selected_theme();
if ($theme == 'classic' || read_config_option('autocomplete') > 0) {
print "\n";
} else {
if (empty($previous_id) && $previous_value == '') {
$previous_value = $none_entry;
}
print "";
}
}
/**
* form_checkbox - draws a standard html checkbox
*
* @param string $form_name - the name of this form element
* @param string $form_previous_value - the current value of this form element
* @param string $form_caption - the text to display to the right of the checkbox
* @param string $form_default_value - the value of this form element to use if there is
* no current value available
* @param int $current_id - used to determine if a current value for this form element
* exists or not. a $current_id of '0' indicates that no current value exists,
* a non-zero value indicates that a current value does exist
* @param string $class - specify a css class
* @param string $on_change - specify a javascript onchange action
* @param string $title - specify a title for the checkbox on hover
* @param boolean $show_label - show the form caption in the checkbox
*/
function form_checkbox($form_name, $form_previous_value, $form_caption, $form_default_value, $current_id = 0, $class = '', $on_change = '', $title = '', $show_label = false) {
if (($form_previous_value == '') && (empty($current_id))) {
$form_previous_value = $form_default_value;
}
if (isset($_SESSION[SESS_FIELD_VALUES])) {
if (!empty($_SESSION[SESS_FIELD_VALUES][$form_name])) {
$form_previous_value = $_SESSION[SESS_FIELD_VALUES][$form_name];
}
}
if ($class != '') {
$class = ' ' . trim($class);
}
if ($on_change != '') {
$on_change = " onChange='$on_change'";
}
if ($form_previous_value == 'on') {
$checked = " checked aria-checked='true'";
} else {
$checked = " aria-checked='false'";
}
$labelClass = '';
if ($show_label) {
$labelClass = ' checkboxLabelWanted';
}
print "";
print "";
print "';
print '';
}
/**
* form_radio_button - draws a standard html radio button
*
* @param $form_name - the name of this form element
* @param $form_previous_value - the current value of this form element (selected or not)
* @param $form_current_value - the current value of this form element (element id)
* @param $form_caption - the text to display to the right of the checkbox
* @param $form_default_value - the value of this form element to use if there is
* no current value available
*/
function form_radio_button($form_name, $form_previous_value, $form_current_value, $form_caption, $form_default_value, $class = '', $on_change = '') {
if ($form_previous_value == '') {
$form_previous_value = $form_default_value;
}
if (isset($_SESSION[SESS_FIELD_VALUES])) {
if (!empty($_SESSION[SESS_FIELD_VALUES][$form_name])) {
$form_previous_value = $_SESSION[SESS_FIELD_VALUES][$form_name];
}
}
if ($class != '') {
$class = " $class";
}
if ($on_change != '') {
$on_change = " onChange='$on_change' ";
}
if ($form_previous_value == $form_current_value) {
$checked = " checked aria-checked='true'";
} else {
$checked = " aria-checked='false'";
}
$css_id = $form_name . '_' . $form_current_value;
print "";
print "";
print "';
print '';
}
/**
* form_text_area - draws a standard html text area box
*
* @param $form_name - the name of this form element
* @param $form_previous_value - the current value of this form element (selected or not)
* @param $form_rows - the number of rows in the text area box
* @param $form_columns - the number of columns in the text area box
* @param $form_default_value - the value of this form element to use if there is
* no current value available
*/
function form_text_area($form_name, $form_previous_value, $form_rows, $form_columns, $form_default_value, $class = '', $on_change = '', $placeholder = '') {
if ($form_previous_value == '') {
$form_previous_value = $form_default_value;
}
if (isset($_SESSION[SESS_ERROR_FIELDS])) {
if (!empty($_SESSION[SESS_ERROR_FIELDS][$form_name])) {
$class .= ($class != '' ? ' ' : '') . 'txtErrorTextBox';
unset($_SESSION[SESS_ERROR_FIELDS][$form_name]);
}
}
if (isset($_SESSION[SESS_FIELD_VALUES])) {
if (!empty($_SESSION[SESS_FIELD_VALUES][$form_name])) {
$form_previous_value = $_SESSION[SESS_FIELD_VALUES][$form_name];
}
}
if ($on_change != '') {
$on_change = " onChange='$on_change' ";
}
if ($placeholder != '') {
$placeholder = " placeholder='" . html_escape($placeholder) . "'";
}
print "\n";
}
/**
* form_multi_dropdown - draws a standard html multiple select dropdown
*
* @param $form_name - the name of this form element
* @param $array_display - an array containing display values for this dropdown. it must
* be formatted like:
* $array[id] = display;
* @param $sql_previous_values - an array containing keys that should be marked as selected.
* it must be formatted like:
* $array[0][$column_id] = key
* @param $column_id - the name of the key used to reference the keys above
*/
function form_multi_dropdown($form_name, $array_display, $sql_previous_values, $column_id, $class = '', $on_change = '') {
if (!is_array($sql_previous_values) && $sql_previous_values != '') {
$values = explode(',', $sql_previous_values);
$sql_previous_values = array();
foreach ($values as $value) {
$sql_previous_values[][$column_id] = $value;
}
} elseif ($sql_previous_values == '') {
$values = db_fetch_cell_prepared('SELECT value FROM settings WHERE name = ?', array($form_name));
if ($values != '') {
$values = explode(',', $values);
foreach ($values as $value) {
$sql_previous_values[][$column_id] = $value;
}
}
}
if (isset($_SESSION[SESS_ERROR_FIELDS])) {
if (!empty($_SESSION[SESS_ERROR_FIELDS][$form_name])) {
$class .= ($class != '' ? ' ' : '') . 'txtErrorTextBox';
unset($_SESSION[SESS_ERROR_FIELDS][$form_name]);
}
}
$class = 'multiselect';
if ($class != '') {
$class .= " $class";
}
if ($on_change != '') {
$on_change = " onChange='$on_change' ";
}
print "\n";
}
/**
* form_color_dropdown - draws a dropdown containing a list of colors that uses a bit
* of css magic to make the dropdown item background color represent each color in
* the list
*
* @param $form_name - the name of this form element
* @param $form_previous_value - the current value of this form element
* @param $form_none_entry - the name to use for a default 'none' element in the dropdown
* @param $form_default_value - the value of this form element to use if there is
* no current value available
*/
function form_color_dropdown($form_name, $form_previous_value, $form_none_entry, $form_default_value, $class = '', $on_change = '') {
if ($form_previous_value == '') {
$form_previous_value = $form_default_value;
}
if ($class != '') {
$class = " class='colordropdown $class' ";
} else {
$class = " class='colordropdown'";
}
$current_color = db_fetch_cell_prepared(
'SELECT hex
FROM colors
WHERE id = ?',
array($form_previous_value)
);
if ($on_change != '') {
$on_change = ' ' . $on_change . ';';
}
$on_change = " onChange='this.style.backgroundColor=this.options[this.selectedIndex].style.backgroundColor;$on_change'";
$colors_sql = 'SELECT *
FROM colors
ORDER BY
SUBSTRING(hex,0,2) ASC,
SUBSTRING(hex,2,2) ASC,
SUBSTRING(hex,4,2) ASC';
$colors_list = db_fetch_assoc($colors_sql);
print "';
}
/**
* form_font_box - draws a standard html textbox and provides status of a fonts existence
*
* @param $form_name - the name of this form element
* @param $form_previous_value - the current value of this form element
* @param $form_default_value - the value of this form element to use if there is
* no current value available
* @param $form_max_length - the maximum number of characters that can be entered
* into this textbox
* @param $form_size - the size (width) of the textbox
* @param $type - the type of textbox, either 'text' or 'password'
* @param $current_id - used to determine if a current value for this form element
* exists or not. a $current_id of '0' indicates that no current value exists,
* a non-zero value indicates that a current value does exist
*/
function form_font_box($form_name, $form_previous_value, $form_default_value, $form_max_length, $form_size = 30, $type = 'text', $current_id = 0, $placeholder = '') {
global $config;
if (($form_previous_value == '') && (empty($current_id))) {
$form_previous_value = $form_default_value;
}
print " [" . __('NO FONT VERIFICATION POSSIBLE') . ']';
}
print " id='$form_name' " . ($placeholder != '' ? "placeholder='" . html_escape($placeholder) . "'" : '') . " name='$form_name' size='$form_size'" . (!empty($form_max_length) ? " maxlength='$form_max_length'" : '') . " value='" . html_escape($form_previous_value) . "'>" . $extra_data;
}
/**
* form_continue_confirmation - given as set of form options in the form of an array
* generate a continuation form confirm dialog for the user.
*
* @param array - Options to present to the users depending on the drop action
*
* The options array has two sections 'general' and 'options'. The 'general' option
* must includes the following 4 variables:
* - page: The page that is being rendered or returnedd to in case of a cancel
* - actions: An array of legal actions that we can construct a title for
* - eaction: An action to add to the form save when there are more than one on a page
* - optvar: A request variable to pull the selected option from. Normally 'drp_action'
* - item_array: An array of selected items that have been pre-processed
* - item_list: An string of list items "Title" that have been pre-processed
* - header: A paragraph that is placed before the options and after the message text
* - footer: A paragraph that is placed after the options and just before the Continue button
*
* The 'options' array should have a matching value array for each of the approved
* actions. For each action, you need one of the following formats variables:
* - scont - Singular continuation string
* - pcont - Plural continuation string
* - cont - Generic continuation string
* - smessage - Singular confirmation message to the user.
* - pmessage - Plural confirmation message to the user.
* - message - Generic confirmation message to the user.
* - extra - An array of general form input. The supported methods include:
* textbox, other, drop_array, checkbox
* additional options include: title, default, width, and array for drop_arrays
*
* An example might look like the following:
*
* $form_data = array(
* 'general' => array(
* 'page' => 'user_domains.php',
* 'actions' => $actions,
* 'eaction' => 'action_variable', // Extra Action
* 'optvar' => 'drp_action'
* 'header' => 'some header text',
* 'item_array' => $d_array,
* 'item_list' => $d_list,
* 'footer' => 'some footer text'
* ),
* 'options' => array(
* 1 => array(
* 'header' => 'some header text',
* 'smessage' => __('Click \'Continue\' to Delete the following User Domain.'),
* 'pmessage' => __('Click \'Continue\' to Delete following User Domains.'),
* 'scont' => __('Delete User Domain'),
* 'pcont' => __('Delete User Domains')
* 'footer' => 'some footer text'
* ),
* 2 => array(
* 'header' => 'some header text',
* 'smessage' => __('Click \'Continue\' to Disable the following User Domain.'),
* 'pmessage' => __('Click \'Continue\' to Disable following User Domains.'),
* 'scont' => __('Disable User Domain'),
* 'pcont' => __('Disable User Domains'),
* 'extra' => array(
* 'group_prefix' => array(
* 'method' => 'textbox',
* 'title' => __('Group Prefix:'),
* 'default' => __('New Group'),
* 'width' => 25,
* 'size' => 25
* )
* ),
* 'footer' => 'some footer text'
* )
* );
*
* @return null - Data is streamed through stdout
*/
function form_continue_confirmation($form_data) {
top_header();
$page = $form_data['general']['page'];
$actions = $form_data['general']['actions'];
$drpvar = $form_data['general']['optvar'];
$iarray = $form_data['general']['item_array'];
$ilist = $form_data['general']['item_list'];
$drpval = get_nfilter_request_var($drpvar);
form_start($page);
html_start_box($actions[$drpval], '60%', '', '3', 'center', '');
if (cacti_sizeof($iarray)) {
$data = $form_data['options'][$drpval];
if (cacti_sizeof($iarray) > 1) {
if (isset($data['pmessage'])) {
$message = $data['pmessage'];
} elseif (isset($data['message'])) {
$message = $data['message'];
}
if (isset($data['pcont'])) {
$title = $data['pcont'];
} elseif (isset($data['cont'])) {
$title = $data['cont'];
}
} else {
if (isset($data['smessage'])) {
$message = $data['smessage'];
} elseif (isset($data['message'])) {
$message = $data['message'];
}
if (isset($data['scont'])) {
$title = $data['scont'];
} elseif (isset($data['cont'])) {
$title = $data['cont'];
}
}
} else {
raise_message(40);
header('Location: ' . $page);
exit;
}
print " |
| ";
print " $message ";
if (isset($form_data['general']['header'])) {
print " |
";
print $form_data['general']['header'];
print " |
";
}
if (isset($data['header'])) {
print "
";
print $data['header'];
print " |
";
}
if ($ilist != '') {
print "
";
}
print "";
if (isset($data['extra'])) {
foreach($data['extra'] as $field_name => $field_array) {
if (!isset($field_array['width'])) {
$field_array['width'] = 25;
}
if (!isset($field_array['size'])) {
$field_array['size'] = 25;
}
print "
";
switch($field_array['method']) {
case 'other':
print "| {$field_array['title']} | ";
print "{$field_array['default']} | ";
break;
case 'textbox':
print "{$field_array['title']} | ";
print "";
form_text_box($field_name, $field_array['default'], '', $field_array['width'], $field_array['size']);
print " | ";
break;
case 'drop_array':
if (!isset($field_array['default'])) {
$field_array['default'] = '';
}
if (!isset($field_array['variable'])) {
$field_array['variable'] = '';
}
if (!isset($field_array['id'])) {
$field_array['id'] = '';
}
print "{$field_array['title']} | ";
print "";
form_dropdown($field_name, $field_array['array'], $field_array['variable'], $field_array['id'], $field_array['default'], '', 0);
print " | ";
break;
case 'drop_branch':
print "{$field_array['title']} | ";
print "";
grow_dropdown_tree($field_array['id'], '0', $field_name, '0');
print " | ";
break;
case 'checkbox':
break;
default:
cacti_log("WARNING: Form continuation method {$field_array['method']} not understood");
}
print "
";
}
if (isset($data['footer'])) {
print "
";
print $data['footer'];
print " |
";
}
if (isset($form_data['general']['footer'])) {
print "
";
print $form_data['general']['footer'];
print " |
";
}
}
print "
| ";
print "";
if (isset($form_data['general']['eaction'])) {
if (!isset($form_data['general']['eactionid'])) {
$form_data['eactionid'] = 1;
}
print "";
}
if (isset($data['eaction'])) {
if (!isset($data['eactionid'])) {
$data['eactionid'] = 1;
}
print "";
}
print "";
print "";
print " ";
print "";
print " |
";
html_end_box();
form_end();
bottom_footer();
}
/**
* form_confirm - draws a table presenting the user with some choice and allowing
* them to either proceed (delete) or cancel
*
* @param $body_text - the text to prompt the user with on this form
* @param $cancel_url - the url to go to when the user clicks 'cancel'
* @param $action_url - the url to go to when the user clicks 'delete'
*
* @return null
*/
function form_confirm($title_text, $body_text, $cancel_url, $action_url) { ?>
|
'>
")' value=''>
|
";
} else {
$cancel_action = '';
}
?>
\n";
}
/* form_end - draws post form end. To be combined with form_start() */
function form_end($ajax = true) {
global $form_id, $form_action;
print '' . PHP_EOL;
if ($ajax) {
if ($form_id == null) {
cacti_log('WARNING: Function: form_end() called without a form_start() called first', false);
cacti_debug_backtrace('FORM', false, true);
$form_id = 'empty';
}
?>