\n";
break;
case 'radio':
while (list($radio_index, $radio_array) = each($field_array['items'])) {
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 ' ';
}
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'));
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;
default:
print '' . htmlspecialchars($field_array['value'],ENT_QUOTES) . '';
form_hidden_box($field_name, $field_array['value'], '', true);
break;
}
}
/* form_button - draws a standard button form element
@arg $form_name - the name of this form element
@arg $value - the display value for the button
@arg $title - the hover title for the button
@arg $action - the onClick action for the button */
function form_button($form_name, $value, $title = '', $action = '') {
print "";
}
/* form_file - draws a standard html file input element
@arg $form_name - the name of this form element
@arg $form_size - the size (width) of the textbox */
function form_file($form_name, $form_size = 30) {
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
@arg $form_name - the name of this form element
@arg $form_previous_value - the current value of this form element
@arg $form_default_value - the value of this form element to use if there is
no current value available
@arg $form_max_length - the maximum number of characters that can be entered
into this textbox
@arg $form_size - the size (width) of the textbox
@arg $type - the type of textbox, either 'text' or 'password'
@arg $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_filepath_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 "";
}else if (is_dir(trim($form_previous_value))) {
$extra_data = "";
}else if (strlen($form_previous_value) == 0) {
$extra_data = '';
}else{
$extra_data = "";
}
print " id='$form_name' placeholder='" . __('Enter a valid file path') . "' name='$form_name' size='$form_size'" . (!empty($form_max_length) ? " maxlength='$form_max_length'" : '') . " value='" . htmlspecialchars($form_previous_value, ENT_QUOTES) . "'>" . $extra_data;
}
/* form_dirpath_box - draws a standard html textbox and provides status of a directories existence
@arg $form_name - the name of this form element
@arg $form_previous_value - the current value of this form element
@arg $form_default_value - the value of this form element to use if there is
no current value available
@arg $form_max_length - the maximum number of characters that can be entered
into this textbox
@arg $form_size - the size (width) of the textbox
@arg $type - the type of textbox, either 'text' or 'password'
@arg $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 "";
}else if (is_file($form_previous_value)) {
$extra_data = "";
}else if (strlen($form_previous_value) == 0) {
$extra_data = '';
}else{
$extra_data = "";
}
print " id='$form_name' name='$form_name' placeholder='" . __('Enter a valid directory path'). "' size='$form_size'" . (!empty($form_max_length) ? " maxlength='$form_max_length'" : '') . " value='" . htmlspecialchars($form_previous_value, ENT_QUOTES) . "'>" . $extra_data;
}
/* form_text_box - draws a standard html textbox
@arg $form_name - the name of this form element
@arg $form_previous_value - the current value of this form element
@arg $form_default_value - the value of this form element to use if there is
no current value available
@arg $form_max_length - the maximum number of characters that can be entered
into this textbox
@arg $form_size - the size (width) of the textbox
@arg $type - the type of textbox, either 'text' or 'password'
@arg $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_text_box($form_name, $form_previous_value, $form_default_value, $form_max_length, $form_size = 30, $type = 'text', $current_id = 0, $placeholder = '') {
if (($form_previous_value == '') && (empty($current_id))) {
$form_previous_value = $form_default_value;
}
print "\n";
}
/* form_hidden_box - draws a standard html hidden element
@arg $form_name - the name of this form element
@arg $form_previous_value - the current value of this form element
@arg $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 ($in_form) ? "
\n":'';
print "\n";
print ($in_form) ? "
\n":'';
}
/* form_dropdown - draws a standard html dropdown box
@arg $form_name - the name of this form element
@arg $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";
@arg $column_display - used to indentify the key to be used for display data. this
is only applicable if the array is formatted using the second method above
@arg $column_id - used to indentify the key to be used for id data. this
is only applicable if the array is formatted using the second method above
@arg $form_previous_value - the current value of this form element
@arg $form_none_entry - the name to use for a default 'none' element in the dropdown
@arg $form_default_value - the value of this form element to use if there is
no current value available
@arg $css_class - any css that needs to be applied to this form element
@arg $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 .= (strlen($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 (strlen($class)) {
$class = " class='$class' ";
}
if (strlen($on_change)) {
$on_change = " onChange='$on_change' ";
}
print "\n";
}
function form_callback($form_name, $classic_sql, $column_display, $column_id, $callback, $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 .= (strlen($class) ? ' ':'') . 'txtErrorTextBox';
unset($_SESSION['sess_error_fields'][$form_name]);
}
}
if (isset($_SESSION['sess_field_values'])) {
if (!empty($_SESSION['sess_field_values'][$form_name])) {
$previous_value = $_SESSION['sess_field_values'][$form_name];
}
}
if (strlen($class)) {
$class = " class='$class' ";
}
if (strlen($on_change)) {
$on_change = " onChange='$on_change' ";
}
$theme = get_selected_theme();
if ($theme == 'classic') {
print "\n";
}else{
$form_prefix = htmlspecialchars($form_name);
print "\n";
print "\n";
print "\n";
print "\n";
print "\n";
?>
" . ($form_caption != '' ? " \n":"");
}
/* form_radio_button - draws a standard html radio button
@arg $form_name - the name of this form element
@arg $form_previous_value - the current value of this form element (selected or not)
@arg $form_current_value - the current value of this form element (element id)
@arg $form_caption - the text to display to the right of the checkbox
@arg $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 (strlen($class)) {
$class = " class='$class' ";
}
if (strlen($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 "\n";
}
/* form_text_area - draws a standard html text area box
@arg $form_name - the name of this form element
@arg $form_previous_value - the current value of this form element (selected or not)
@arg $form_rows - the number of rows in the text area box
@arg $form_columns - the number of columns in the text area box
@arg $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 .= (strlen($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 (strlen($class)) {
$class = " class='$class' ";
}
if (strlen($on_change)) {
$on_change = " onChange='$on_change' ";
}
if (strlen($placeholder)) {
$placeholder = " placeholder='$placeholder'";
}
print "\n";
}
/* form_multi_dropdown - draws a standard html multiple select dropdown
@arg $form_name - the name of this form element
@arg $array_display - an array containing display values for this dropdown. it must
be formatted like:
$array[id] = display;
@arg $sql_previous_values - an array containing keys that should be marked as selected.
it must be formatted like:
$array[0][$column_id] = key
@arg $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("SELECT value FROM settings WHERE name='$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 .= (strlen($class) ? ' ':'') . 'txtErrorTextBox';
unset($_SESSION['sess_error_fields'][$form_name]);
}
}
$class = 'multiselect';
if (strlen($class)) {
$class .= " $class";
}
if (strlen($on_change)) {
$on_change = " onChange='$on_change' ";
}
print "\n";
}
/*
* Second level form elements
*/
/* 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
@arg $form_name - the name of this form element
@arg $form_previous_value - the current value of this form element
@arg $form_none_entry - the name to use for a default 'none' element in the dropdown
@arg $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 (strlen($class)) {
$class = " class='colordropdown $class' ";
}else{
$class = " class='colordropdown'";
}
$current_color = db_fetch_cell("SELECT hex FROM colors WHERE id=$form_previous_value");
if (strlen($on_change)) {
$on_change = ' ' . $on_change . ';';
}
$on_change = " onChange='this.style.backgroundColor=this.options[this.selectedIndex].style.backgroundColor;$on_change'";
$colors_list = db_fetch_assoc('SELECT * FROM colors ORDER BY hex DESC');
print "\n";
}
/* form_font_box - draws a standard html textbox and provides status of a fonts existence
@arg $form_name - the name of this form element
@arg $form_previous_value - the current value of this form element
@arg $form_default_value - the value of this form element to use if there is
no current value available
@arg $form_max_length - the maximum number of characters that can be entered
into this textbox
@arg $form_size - the size (width) of the textbox
@arg $type - the type of textbox, either 'text' or 'password'
@arg $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 " [" . __('OK: FILE FOUND') . ']';
}else if (is_dir($form_previous_value)) {
$extra_data = " [" . __('ERROR: IS DIR') . ']';
}else{
$extra_data = " [" . __('ERROR: FILE NOT FOUND') . ']';
}
} else { # rrdtool 1.3+ use fontconfig
/* verifying all possible pango font params is too complex to be tested here
* so we only escape the font
*/
$extra_data = " [" . __('NO FONT VERIFICATION POSSIBLE') . ']';
}
}
print " id='$form_name' " . ($placeholder != '' ? "placeholder='" . htmlspecialchars($placeholder) . "'":'') . " name='$form_name' size='$form_size'" . (!empty($form_max_length) ? " maxlength='$form_max_length'" : '') . " value='" . htmlspecialchars($form_previous_value, ENT_QUOTES) . "'>" . $extra_data;
}
/* form_confirm - draws a table presenting the user with some choice and allowing
them to either proceed (delete) or cancel
@arg $body_text - the text to prompt the user with on this form
@arg $cancel_url - the url to go to when the user clicks 'cancel'
@arg $action_url - the url to go to when the user clicks 'delete' */
function form_confirm($title_text, $body_text, $cancel_url, $action_url) { ?>
")' value=''>
&confirm=true")' value=''>
";
}else{
$cancel_action = '';
}
?>
\n";
} ?>
\n";
}
/* form_end - draws post form end. To be combined with form_start() */
function form_end($ajax = true) {
global $form_id, $form_action;
print "\n";
if ($ajax) { ?>