示例#1
0
function draw_nontemplated_fields_custom_data($data_template_data_id, $field_name_format = "|field|", $header_title = "", $alternate_colors = true, $include_hidden_fields = true, $snmp_query_id = 0) {
	global $colors;

	$data = db_fetch_row("select id,data_input_id,data_template_id,name,local_data_id from data_template_data where id=$data_template_data_id");
	$host_id = db_fetch_cell("select host.id from data_local,host where data_local.host_id=host.id and data_local.id=" . $data["local_data_id"]);
	$template_data = db_fetch_row("select id,data_input_id from data_template_data where data_template_id=" . $data["data_template_id"] . " and local_data_id=0");

	$draw_any_items = false;

	/* get each INPUT field for this data input source */
	$fields = db_fetch_assoc("select * from data_input_fields where data_input_id=" . $data["data_input_id"] . " and input_output='in' order by name");

	/* loop through each field found */
	$i = 0;
	if (sizeof($fields) > 0) {
	foreach ($fields as $field) {
		$data_input_data = db_fetch_row("select * from data_input_data where data_template_data_id=" . $data["id"] . " and data_input_field_id=" . $field["id"]);

		if (sizeof($data_input_data) > 0) {
			$old_value = $data_input_data["value"];
		}else{
			$old_value = "";
		}

		/* if data template then get t_value from template, else always allow user input */
		if (empty($data["data_template_id"])) {
			$can_template = "on";
		}else{
			$can_template = db_fetch_cell("select t_value from data_input_data where data_template_data_id=" . $template_data["id"] . " and data_input_field_id=" . $field["id"]);
		}

		/* find our field name */
		$form_field_name = str_replace("|id|", $field["id"], $field_name_format);

		if ((!empty($host_id)) && (eregi('^' . VALID_HOST_FIELDS . '$', $field["type_code"])) && (empty($can_template))) { /* no host fields */
			if ($include_hidden_fields == true) {
				form_hidden_box($form_field_name, $old_value, "");
			}
		}elseif ((!empty($snmp_query_id)) && (eregi('^(index_type|index_value|output_type)$', $field["type_code"]))) { /* no data query fields */
			if ($include_hidden_fields == true) {
				form_hidden_box($form_field_name, $old_value, "");
			}
		}elseif (empty($can_template)) { /* no templated fields */
			if ($include_hidden_fields == true) {
				form_hidden_box($form_field_name, $old_value, "");
			}
		}else{
			if (($draw_any_items == false) && ($header_title != "")) {
				print "<tr bgcolor='#" . $colors["header_panel"] . "'><td colspan='2' style='font-size: 10px; color: white;'>$header_title</td></tr>\n";
			}

			if ($alternate_colors == true) {
				form_alternate_row_color($colors["form_alternate1"],$colors["form_alternate2"],$i);
			}else{
				print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
			}

			print "<td width='50%'><strong>" . $field["name"] . "</strong></td>\n";
			print "<td>";

			draw_custom_data_row($form_field_name, $field["id"], $data["id"], $old_value);

			print "</td>";
			print "</tr>\n";

			$draw_any_items = true;
			$i++;
		}
	}
	}

	return $i;
}
示例#2
0
function data_edit()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var("id"));
    /* ==================================================== */
    global $config, $colors;
    if (!empty($_GET["id"])) {
        $data = db_fetch_row("select id,data_input_id,data_template_id,name,local_data_id from data_template_data where local_data_id=" . $_GET["id"]);
        $template_data = db_fetch_row("select id,data_input_id from data_template_data where data_template_id=" . $data["data_template_id"] . " and local_data_id=0");
        $host = db_fetch_row("select host.id,host.hostname from (data_local,host) where data_local.host_id=host.id and data_local.id=" . $_GET["id"]);
        $header_label = "[edit: " . $data["name"] . "]";
    } else {
        $header_label = "[new]";
    }
    print "<form method='post' action='data_sources.php'>\n";
    $i = 0;
    if (!empty($data["data_input_id"])) {
        /* get each INPUT field for this data input source */
        $fields = db_fetch_assoc("select * from data_input_fields where data_input_id=" . $data["data_input_id"] . " and input_output='in' order by sequence");
        html_start_box("<strong>Custom Data</strong> [data input: " . db_fetch_cell("select name from data_input where id=" . $data["data_input_id"]) . "]", "100%", $colors["header"], "3", "center", "");
        /* loop through each field found */
        if (sizeof($fields) > 0) {
            foreach ($fields as $field) {
                $data_input_data = db_fetch_row("select * from data_input_data where data_template_data_id=" . $data["id"] . " and data_input_field_id=" . $field["id"]);
                if (sizeof($data_input_data) > 0) {
                    $old_value = $data_input_data["value"];
                } else {
                    $old_value = "";
                }
                /* if data template then get t_value from template, else always allow user input */
                if (empty($data["data_template_id"])) {
                    $can_template = "on";
                } else {
                    $can_template = db_fetch_cell("select t_value from data_input_data where data_template_data_id=" . $template_data["id"] . " and data_input_field_id=" . $field["id"]);
                }
                form_alternate_row_color($colors["form_alternate1"], $colors["form_alternate2"], $i);
                if (!empty($host["id"]) && eregi('^' . VALID_HOST_FIELDS . '$', $field["type_code"])) {
                    print "<td width='50%'><strong>" . $field["name"] . "</strong> (From Host: " . $host["hostname"] . ")</td>\n";
                    print "<td><em>{$old_value}</em></td>\n";
                } elseif (empty($can_template)) {
                    print "<td width='50%'><strong>" . $field["name"] . "</strong> (From Data Template)</td>\n";
                    print "<td><em>" . (empty($old_value) ? "Nothing Entered" : $old_value) . "</em></td>\n";
                } else {
                    print "<td width='50%'><strong>" . $field["name"] . "</strong></td>\n";
                    print "<td>";
                    draw_custom_data_row("value_" . $field["id"], $field["id"], $data["id"], $old_value);
                    print "</td>";
                }
                print "</tr>\n";
                $i++;
            }
        } else {
            print "<tr><td><em>No Input Fields for the Selected Data Input Source</em></td></tr>";
        }
        html_end_box();
    }
    form_hidden_box("local_data_id", isset($data) ? $data["local_data_id"] : "0", "");
    form_hidden_box("data_template_data_id", isset($data) ? $data["id"] : "0", "");
    form_hidden_box("save_component_data", "1", "");
}
示例#3
0
/** draw_nontemplated_fields_custom_data - draws a form that consists of all non-templated custom data fields
     associated with a particular data template
   @param int $data_template_id	 			- the id of the data template to base the form after
   @param string $field_name_format 		- all fields on the form will be named using the following format, the following
     										  variables can be used:
      										  |id| - the id of the current field
   @param string $header_title 				- the title to use on the header for this form
   @param bool $draw_title_for_each_item 	- should a separate header be drawn for each data source item, or
     										  should all data source items be drawn under one header?
   @param bool $alternate_colors 			- whether to alternate colors for each row on the form or not
   @param bool $include_hidden_fields 		- should elements that are not to be displayed be represented as hidden
     										  html input elements or omitted altogether?
   @param int $snmp_query_id 				- if this graph template is part of a data query, specify the data query id here. this
     										  will be used to determine if a given field is associated with a suggested value */
function draw_nontemplated_fields_custom_data($data_template_data_id, $field_name_format = "|field|", $header_title = "", $alternate_colors = true, $include_hidden_fields = true, $snmp_query_id = 0) {
	global $colors;

	$data = db_fetch_row("select id,data_input_id,data_template_id,name,local_data_id from data_template_data where id=$data_template_data_id");
	$device_id = db_fetch_cell("select device.id from (data_local,device) where data_local.device_id=device.id and data_local.id=" . $data["local_data_id"]);
	$template_data = db_fetch_row("select id,data_input_id from data_template_data where data_template_id=" . $data["data_template_id"] . " and local_data_id=0");

	$draw_any_items = false;

	/* get each INPUT field for this data input source */
	$fields = db_fetch_assoc("select * from data_input_fields where data_input_id=" . $data["data_input_id"] . " and input_output='in' order by sequence");

	/* loop through each field found */
	$i = 0;
	if (sizeof($fields) > 0) {
	foreach ($fields as $field) {
		$data_input_data = db_fetch_row("select * from data_input_data where data_template_data_id=" . $data["id"] . " and data_input_field_id=" . $field["id"]);

		if (sizeof($data_input_data) > 0) {
			$old_value = $data_input_data["value"];
		}else{
			$old_value = "";
		}

		/* if data template then get t_value from template, else always allow user input */
		if (empty($data["data_template_id"])) {
			$can_template = CHECKED;
		}else{
			$can_template = db_fetch_cell("select t_value from data_input_data where data_template_data_id=" . $template_data["id"] . " and data_input_field_id=" . $field["id"]);
		}

		/* find our field name */
		$form_field_name = str_replace("|id|", $field["id"], $field_name_format);

		if ((!empty($device_id)) && (preg_match('/^' . VALID_HOST_FIELDS . '$/i', $field["type_code"])) && (empty($can_template))) { /* no device fields */
			if ($include_hidden_fields == true) {
				form_hidden_box($form_field_name, $old_value, "");
			}
		}elseif ((!empty($snmp_query_id)) && (preg_match('/^(index_type|index_value|output_type)$/', $field["type_code"]))) { /* no data query fields */
			if ($include_hidden_fields == true) {
				form_hidden_box($form_field_name, $old_value, "");
			}
		}elseif (empty($can_template)) { /* no templated fields */
			if ($include_hidden_fields == true) {
				form_hidden_box($form_field_name, $old_value, "");
			}
		}else{
			if (($draw_any_items == false) && ($header_title != "")) {
				$header_items = array($header_title, "");
				print "<tr><td>";
				html_header($header_items, 1, true, 'template_custom_data');
			}

			if ($alternate_colors == true) {
				form_alternate_row_color();
			}else{
				print "<tr bgcolor='#" . $colors["form_alternate1"] . "'>\n";
			}

			print "<td width='50%'><strong>" . $field["name"] . "</strong></td>\n";
			print "<td>";

			draw_custom_data_row($form_field_name, $field["id"], $data["id"], $old_value);

			print "</td>";
			print "</tr>\n";

			$draw_any_items = true;
			$i++;
		}
	}
	}

	if ($draw_any_items) print "</table></td></tr>";		/* end of html_header */

	return $i;
}
示例#4
0
function draw_nontemplated_fields_custom_data($data_template_data_id, $field_name_format = "|field|", $header_title = "", $alternate_colors = true, $include_hidden_fields = true, $snmp_query_id = 0)
{
    $data = db_fetch_row("SELECT id,data_input_id,data_template_id,name,local_data_id FROM data_template_data WHERE id={$data_template_data_id}");
    $host_id = db_fetch_cell("SELECT host.id FROM (data_local,host) WHERE data_local.host_id=host.id AND data_local.id=" . $data["local_data_id"]);
    $template_data = db_fetch_row("SELECT id,data_input_id FROM data_template_data WHERE data_template_id=" . $data["data_template_id"] . " AND local_data_id=0");
    $draw_any_items = false;
    /* get each INPUT field for this data input source */
    $fields = db_fetch_assoc("SELECT * FROM data_input_fields WHERE data_input_id=" . $data["data_input_id"] . " AND input_output='in' ORDER BY sequence");
    /* loop through each field found */
    $i = 0;
    if (sizeof($fields) > 0) {
        foreach ($fields as $field) {
            $data_input_data = db_fetch_row("SELECT * FROM data_input_data WHERE data_template_data_id=" . $data["id"] . " AND data_input_field_id=" . $field["id"]);
            if (sizeof($data_input_data) > 0) {
                $old_value = $data_input_data["value"];
            } else {
                $old_value = "";
            }
            /* if data template then get t_value from template, else always allow user input */
            if (empty($data["data_template_id"])) {
                $can_template = "on";
            } else {
                $can_template = db_fetch_cell("SELECT t_value FROM data_input_data WHERE data_template_data_id=" . $template_data["id"] . " AND data_input_field_id=" . $field["id"]);
            }
            /* find our field name */
            $form_field_name = str_replace("|id|", $field["id"], $field_name_format);
            if (!empty($host_id) && preg_match('/^' . VALID_HOST_FIELDS . '$/i', $field["type_code"]) && empty($can_template)) {
                /* no host fields */
                if ($include_hidden_fields == true) {
                    form_hidden_box($form_field_name, $old_value, "");
                }
            } elseif (!empty($snmp_query_id) && preg_match('/^(index_type|index_value|output_type)$/i', $field["type_code"])) {
                /* no data query fields */
                if ($include_hidden_fields == true) {
                    form_hidden_box($form_field_name, $old_value, "");
                }
            } elseif (empty($can_template)) {
                /* no templated fields */
                if ($include_hidden_fields == true) {
                    form_hidden_box($form_field_name, $old_value, "");
                }
            } else {
                if ($draw_any_items == false && $header_title != "") {
                    print "<tr class='tableHeader'><td colspan='2' class='tableSubHeaderColumn'>{$header_title}</td></tr>\n";
                }
                if ($alternate_colors == true) {
                    form_alternate_row();
                } else {
                    print "<tr class='odd'>\n";
                }
                print "<td width='50%'><strong>" . $field["name"] . "</strong></td>\n";
                print "<td>";
                draw_custom_data_row($form_field_name, $field["id"], $data["id"], $old_value);
                print "</td>";
                print "</tr>\n";
                $draw_any_items = true;
                $i++;
            }
        }
    }
    return $i;
}
示例#5
0
function data_edit()
{
    /* ================= input validation ================= */
    input_validate_input_number(get_request_var_request('id'));
    /* ==================================================== */
    global $config;
    if (!empty($_REQUEST['id'])) {
        $data = db_fetch_row_prepared('SELECT id, data_input_id, data_template_id, name, local_data_id FROM data_template_data WHERE local_data_id = ?', array($_REQUEST['id']));
        $template_data = db_fetch_row_prepared('SELECT id, data_input_id FROM data_template_data WHERE data_template_id = ? AND local_data_id = 0', array($data['data_template_id']));
        $host = db_fetch_row_prepared('SELECT host.id, host.hostname FROM (data_local, host) WHERE data_local.host_id = host.id and data_local.id = ?', array($_REQUEST['id']));
        $header_label = '[edit: ' . htmlspecialchars($data['name']) . ']';
    } else {
        $header_label = '[new]';
    }
    print "<form method='post' action='data_sources.php'>\n";
    $i = 0;
    if (!empty($data['data_input_id'])) {
        /* get each INPUT field for this data input source */
        $fields = db_fetch_assoc_prepared("SELECT * FROM data_input_fields WHERE data_input_id = ? AND input_output = 'in' ORDER BY name", array($data['data_input_id']));
        html_start_box("<strong>Custom Data</strong> [data input: " . htmlspecialchars(db_fetch_cell_prepared('SELECT name FROM data_input WHERE id = ?', array($data['data_input_id']))) . ']', '100%', '', '3', 'center', '');
        /* loop through each field found */
        if (sizeof($fields) > 0) {
            foreach ($fields as $field) {
                $data_input_data = db_fetch_row_prepared('SELECT * FROM data_input_data WHERE data_template_data_id = ? AND data_input_field_id = ?', array($data['id'], $field['id']));
                if (sizeof($data_input_data) > 0) {
                    $old_value = $data_input_data['value'];
                } else {
                    $old_value = '';
                }
                /* if data template then get t_value FROM template, else always allow user input */
                if (empty($data['data_template_id'])) {
                    $can_template = 'on';
                } else {
                    $can_template = db_fetch_cell_prepared('SELECT t_value FROM data_input_data WHERE data_template_data_id = ? AND data_input_field_id = ?', array($template_data['id'], $field['id']));
                }
                form_alternate_row();
                if (!empty($host['id']) && preg_match('/^' . VALID_HOST_FIELDS . '$/i', $field['type_code'])) {
                    print "<td width='50%'><strong>" . $field['name'] . '</strong> (From Device: ' . $host['hostname'] . ")</td>\n";
                    print "<td><em>{$old_value}</em></td>\n";
                } elseif (empty($can_template)) {
                    print "<td width='50%'><strong>" . $field['name'] . "</strong> (From Data Template)</td>\n";
                    print '<td><em>' . (empty($old_value) ? 'Nothing Entered' : $old_value) . "</em></td>\n";
                } else {
                    print "<td width='50%'><strong>" . $field['name'] . "</strong></td>\n";
                    print '<td>';
                    draw_custom_data_row('value_' . $field['id'], $field['id'], $data['id'], $old_value);
                    print '</td>';
                }
                print "</tr>\n";
                $i++;
            }
        } else {
            print '<tr><td><em>No Input Fields for the Selected Data Input Source</em></td></tr>';
        }
        html_end_box();
    }
    form_hidden_box('local_data_id', isset($data) ? $data['local_data_id'] : '0', '');
    form_hidden_box('data_template_data_id', isset($data) ? $data['id'] : '0', '');
    form_hidden_box('save_component_data', '1', '');
}