本文整理汇总了PHP中db_fetch_insert_id函数的典型用法代码示例。如果您正苦于以下问题:PHP db_fetch_insert_id函数的具体用法?PHP db_fetch_insert_id怎么用?PHP db_fetch_insert_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_fetch_insert_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: api_data_preset_gprint_save
function api_data_preset_gprint_save($data_preset_gprint_id, $_fields_data_preset_gprint) {
require_once(CACTI_BASE_PATH . "/lib/data_preset/data_preset_gprint_info.php");
/* sanity checks */
validate_id_die($data_preset_gprint_id, "data_preset_gprint_id", true);
/* make sure that there is at least one field to save */
if (sizeof($_fields_data_preset_gprint) == 0) {
return false;
}
/* field: id */
$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $data_preset_gprint_id);
/* convert the input array into something that is compatible with db_replace() */
$_fields += sql_get_database_field_array($_fields_data_preset_gprint, api_data_preset_gprint_form_list());
if (db_replace("preset_gprint", $_fields, array("id"))) {
if (empty($data_preset_gprint_id)) {
$data_preset_gprint_id = db_fetch_insert_id();
}
return $data_preset_gprint_id;
}else{
return false;
}
}
示例2: api_device_save
function api_device_save($device_id, &$_fields_device) {
require_once(CACTI_BASE_PATH . "/lib/device/device_info.php");
/* sanity checks */
validate_id_die($device_id, "device_id", true);
/* field: id */
$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $device_id);
/* convert the input array into something that is compatible with db_replace() */
$_fields += sql_get_database_field_array($_fields_device, api_device_form_list());
/* check for an empty field list */
if (sizeof($_fields) == 1) {
return true;
}
if (db_replace("host", $_fields, array("id"))) {
if (empty($device_id)) {
return db_fetch_insert_id();
}else{
return $device_id;
}
}else{
return false;
}
}
示例3: api_graph_save
function api_graph_save($graph_id, &$_fields_graph, $skip_cache_update = false) {
require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");
/* sanity check for $graph_id */
if (!is_numeric($graph_id)) {
return false;
}
/* field: id */
$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $graph_id);
/* field: graph_template_id */
if (isset($_fields_graph["graph_template_id"])) {
$_fields["graph_template_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph["graph_template_id"]);
}
/* field: host_id */
if (isset($_fields_graph["host_id"])) {
$_fields["host_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph["host_id"]);
}
/* convert the input array into something that is compatible with db_replace() */
$_fields += sql_get_database_field_array($_fields_graph, api_graph_form_list());
/* check for an empty field list */
if (sizeof($_fields) == 1) {
return true;
}
if (db_replace("graph", $_fields, array("id"))) {
$graph_id = db_fetch_insert_id();
if ($skip_cache_update == false) {
api_graph_title_cache_update($graph_id);
}
return true;
}else{
return false;
}
}
示例4: api_user_save
function api_user_save($array) {
if (db_replace("user_auth", $array)) {
/* logging */
if (empty($array["id"])) {
/* New user */
$user_id = db_fetch_insert_id();
log_save(sprintf(_("USER_ADMIN: User id '%s' added"), $user_id), SEV_NOTICE, FACIL_AUTH);
}else{
/* existing user */
$user_id = $array["id"]["value"];
log_save(sprintf(_("USER_ADMIN: User id '%s' updated"), $user_id), SEV_NOTICE, FACIL_AUTH);
}
return $user_id;
} else {
log_save(sprintf(_("USER_ADMIN: Error saving user id '%s' "), $user_id), SEV_ERROR, FACIL_AUTH);
return 0;
}
}
示例5: api_package_metadata_save
function api_package_metadata_save($package_metadata_id, &$_fields_package_metadata) {
require_once(CACTI_BASE_PATH . "/lib/package/package_info.php");
/* sanity checks */
validate_id_die($package_metadata_id, "package_metadata_id", true);
/* sanity check for $package_id */
if ((empty($package_metadata_id)) && (empty($_fields_package_metadata["package_id"]))) {
log_save("Required package_id when package_metadata_id = 0", SEV_ERROR);
return false;
} else if ((isset($_fields_package_metadata["package_id"])) && (!is_numeric($_fields_package_metadata["package_id"]))) {
return false;
}
/* field: id */
$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $package_metadata_id);
/* field: package_id */
if (!empty($_fields_package_metadata["package_id"])) {
$_fields["package_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_package_metadata["package_id"]);
}
/* convert the input array into something that is compatible with db_replace() */
$_fields += sql_get_database_field_array($_fields_package_metadata, api_package_metadata_form_list());
/* check for an empty field list */
if (sizeof($_fields) == 1) {
return true;
}
if (db_replace("package_metadata", $_fields, array("id"))) {
if (empty($package_metadata_id)) {
return db_fetch_insert_id();
}else{
return $package_metadata_id;
}
}else{
return false;
}
}
示例6: api_data_preset_rra_item_save
function api_data_preset_rra_item_save($data_preset_rra_item_id, $_fields_data_preset_rra_item) {
require_once(CACTI_BASE_PATH . "/lib/data_preset/data_preset_rra_info.php");
/* sanity checks */
validate_id_die($data_preset_rra_item_id, "data_preset_rra_item_id", true);
/* make sure that there is at least one field to save */
if (sizeof($_fields_data_preset_rra_item) == 0) {
return false;
}
/* sanity check for $preset_rra_id */
if ((empty($data_preset_rra_item_id)) && (empty($_fields_data_preset_rra_item["preset_rra_id"]))) {
log_save("Required preset_rra_id when data_preset_rra_item_id = 0", SEV_ERROR);
return false;
} else if ((isset($_fields_data_preset_rra_item["preset_rra_id"])) && (!db_integer_validate($_fields_data_preset_rra_item["preset_rra_id"]))) {
return false;
}
/* field: id */
$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $data_preset_rra_item_id);
/* field: preset_rra_id */
if (!empty($_fields_data_preset_rra_item["preset_rra_id"])) {
$_fields["preset_rra_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_data_preset_rra_item["preset_rra_id"]);
}
/* convert the input array into something that is compatible with db_replace() */
$_fields += sql_get_database_field_array($_fields_data_preset_rra_item, api_data_preset_rra_item_form_list());
if (db_replace("preset_rra_item", $_fields, array("id"))) {
if (empty($data_preset_rra_item_id)) {
$data_preset_rra_item_id = db_fetch_insert_id();
}
return $data_preset_rra_item_id;
}else{
return false;
}
}
示例7: copy_graph_template_to_graph
function copy_graph_template_to_graph($graph_template_id, $host_id = 0, $data_query_id = 0, $data_query_index = "") {
require_once(CACTI_BASE_PATH . "/lib/sys/variable.php");
require_once(CACTI_BASE_PATH . "/lib/graph/graph_update.php");
require_once(CACTI_BASE_PATH . "/lib/graph/graph_info.php");
require_once(CACTI_BASE_PATH . "/lib/graph_template/graph_template_info.php");
/* sanity check for $graph_template_id */
if ((!is_numeric($graph_template_id)) || (empty($graph_template_id))) {
return false;
}
/* sanity check for $host_id */
if (!is_numeric($host_id)) {
return false;
}
/* fetch field lists */
$fields_graph = api_graph_form_list();
$fields_graph_item = api_graph_item_form_list();
$graph_template = api_graph_template_get($graph_template_id);
if (sizeof($graph_template) > 0) {
/* copy down per-graph only fields */
$_fields = array();
$_fields["id"] = "0";
$_fields["graph_template_id"] = $graph_template_id;
$_fields["host_id"] = $host_id;
/* evaluate suggested values: data query-based graphs */
if ((!empty($data_query_id)) && ($data_query_index != "")) {
$_fields["title"] = evaluate_data_query_suggested_values($host_id, $data_query_id, $data_query_index, "graph_template_suggested_value", "graph_template_id = " . sql_sanitize($graph_template_id) . " and field_name = 'title'", 0);
/* evaluate suggested values: non-data query-based graphs */
}else{
$_fields["title"] = db_fetch_cell("select value from graph_template_suggested_value where graph_template_id = " . sql_sanitize($graph_template_id) . " and field_name = 'title' order by sequence limit 1");
}
/* copy down all visible fields */
foreach (array_keys($fields_graph) as $field_name) {
if (isset($graph_template[$field_name])) {
$_fields[$field_name] = $graph_template[$field_name];
}
}
if (api_graph_save(0, $_fields, true)) {
$graph_id = db_fetch_insert_id();
log_save("Cloning graph [ID#$graph_id] from template [ID#$graph_template_id]", SEV_DEBUG);
/* move onto the graph items */
$graph_template_items = api_graph_template_item_list($graph_template_id);
if (sizeof($graph_template_items) > 0) {
foreach ($graph_template_items as $graph_template_item) {
/* copy down per-graph only fields */
$_fields = array();
$_fields["id"] = "0";
$_fields["graph_id"] = $graph_id;
$_fields["graph_template_item_id"] = $graph_template_item["id"]; /* this allows us to connect the dots later */
foreach (array_keys($fields_graph_item) as $field_name) {
if (isset($graph_template_item[$field_name])) {
$_fields[$field_name] = $graph_template_item[$field_name];
}
}
if (!api_graph_item_save(0, $_fields)) {
log_save("Save error in api_graph_item_save()", SEV_ERROR);
}
}
}
return $graph_id;
}else{
log_save("Save error in api_graph_save()", SEV_ERROR);
return false;
}
}
return false;
}
示例8: form_save
//.........这里部分代码省略.........
$save["text_format"] = form_input_validate(((isset($item["text_format"]) ? $item["text_format"] : (isset($_POST["text_format"]) ? $_POST["text_format"] : ""))), "text_format", "", true, 3);
$save["value"] = form_input_validate((isset($_POST["value"]) ? $_POST["value"] : ""), "value", "", true, 3);
$save["hard_return"] = form_input_validate(((isset($item["hard_return"]) ? $item["hard_return"] : (isset($_POST["hard_return"]) ? $_POST["hard_return"] : ""))), "hard_return", "", true, 3);
$save["gprint_id"] = form_input_validate(((isset($item["gprint_id"]) ? $item["gprint_id"] : (isset($_POST["gprint_id"]) ? $_POST["gprint_id"] : 0))), "gprint_id", "^[0-9]+$", true, 3);
/* generate a new sequence if needed */
if (empty($_POST["sequence"])) {
$_POST["sequence"] = get_sequence($_POST["sequence"], "sequence", "graph_templates_item", "graph_template_id=" . $_POST["graph_template_id"] . " and local_graph_id=0");
}
$save["sequence"] = form_input_validate($_POST["sequence"], "sequence", "^[0-9]+$", false, 3);
if (!is_error_message()) {
/* Before we save the item, let's get a look at task_item_id <-> input associations */
$orig_data_source_graph_inputs = db_fetch_assoc("select
graph_template_input.id,
graph_template_input.name,
graph_templates_item.task_item_id
from (graph_template_input,graph_template_input_defs,graph_templates_item)
where graph_template_input.id=graph_template_input_defs.graph_template_input_id
and graph_template_input_defs.graph_template_item_id=graph_templates_item.id
and graph_template_input.graph_template_id=" . $save["graph_template_id"] . "
and graph_template_input.column_name='task_item_id'
group by graph_templates_item.task_item_id");
$orig_data_source_to_input = array_rekey($orig_data_source_graph_inputs, "task_item_id", "id");
$graph_template_item_id = sql_save($save, "graph_templates_item");
if ($graph_template_item_id) {
raise_message(1);
if (!empty($save["task_item_id"])) {
/* old item clean-up. Don't delete anything if the item <-> task_item_id association remains the same. */
if ($_POST["hidden_task_item_id"] != $_POST["task_item_id"]) {
/* It changed. Delete any old associations */
db_execute("delete from graph_template_input_defs where graph_template_item_id=$graph_template_item_id");
/* Input for current data source exists and has changed. Update the association */
if (isset($orig_data_source_to_input{$save["task_item_id"]})) {
db_execute("REPLACE INTO graph_template_input_defs " .
"(graph_template_input_id, graph_template_item_id) " .
"VALUES (" .
$orig_data_source_to_input{$save["task_item_id"]} . "," .
$graph_template_item_id .
")");
}
}
/* an input for the current data source does NOT currently exist, let's create one */
if (!isset($orig_data_source_to_input{$save["task_item_id"]})) {
$ds_name = db_fetch_cell("select data_source_name from data_template_rrd where id=" . $_POST["task_item_id"]);
db_execute("REPLACE INTO graph_template_input " .
"(hash,graph_template_id,name,column_name) " .
"VALUES ('" .
get_hash_graph_template(0, "graph_template_input") . "'," .
$save["graph_template_id"] . "," .
"'Data Source [" . $ds_name . "]'," .
'task_item_id' .
")");
$graph_template_input_id = db_fetch_insert_id();
$graph_items = db_fetch_assoc("select id from graph_templates_item where graph_template_id=" . $save["graph_template_id"] . " and task_item_id=" . $_POST["task_item_id"]);
if (sizeof($graph_items) > 0) {
foreach ($graph_items as $graph_item) {
db_execute("REPLACE INTO graph_template_input_defs " .
"(graph_template_input_id,graph_template_item_id) " .
"VALUES (" .
$graph_template_input_id . "," .
$graph_item["id"] .
")");
}
}
}
}
push_out_graph_item($graph_template_item_id);
if (isset($_POST["task_item_id"]) && isset($orig_data_source_to_input{$_POST["task_item_id"]})) {
/* make sure all current graphs using this graph input are aware of this change */
push_out_graph_input($orig_data_source_to_input{$_POST["task_item_id"]}, $graph_template_item_id, array($graph_template_item_id => $graph_template_item_id));
}
}else{
raise_message(2);
}
}
$_POST["sequence"] = 0;
}
if (is_error_message()) {
header("Location: graph_templates_items.php?action=item_edit&graph_template_item_id=" . (empty($graph_template_item_id) ? $_POST["graph_template_item_id"] : $graph_template_item_id) . "&id=" . $_POST["graph_template_id"]);
}else{
header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"] . "&template_id=" . $_POST["graph_template_id"] . "&tab=items");
}
exit;
}
}
示例9: template_rrd_add
function template_rrd_add()
{
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
input_validate_input_number(get_request_var("local_data_id"));
/* ==================================================== */
$hash = get_hash_data_template(0, "data_template_item");
db_execute("insert into data_template_rrd (hash,data_template_id,rrd_maximum,rrd_minimum,rrd_heartbeat,data_source_type_id,\n\t\tdata_source_name) values ('{$hash}'," . $_GET["id"] . ",100,0,600,1,'ds')");
$data_template_rrd_id = db_fetch_insert_id();
/* add this data template item to each data source using this data template */
$children = db_fetch_assoc("select local_data_id from data_template_data where data_template_id=" . $_GET["id"] . " and local_data_id>0");
if (sizeof($children) > 0) {
foreach ($children as $item) {
db_execute("insert into data_template_rrd (local_data_template_rrd_id,local_data_id,data_template_id,rrd_maximum,rrd_minimum,rrd_heartbeat,data_source_type_id,\n\t\t\tdata_source_name) values ({$data_template_rrd_id}," . $item["local_data_id"] . "," . $_GET["id"] . ",100,0,600,1,'ds')");
}
}
header("Location: data_templates.php?action=template_edit&id=" . $_GET["id"] . "&view_rrd={$data_template_rrd_id}");
}
示例10: form_save
//.........这里部分代码省略.........
/* generate a new sequence if needed */
if (empty($_POST["sequence"])) {
$_POST["sequence"] = get_sequence($_POST["sequence"], "sequence", "graph_templates_item", "graph_template_id=" . $_POST["graph_template_id"] . " and local_graph_id=0");
}
$save["id"] = $_POST["graph_template_item_id"];
$save["hash"] = get_hash_graph_template($_POST["graph_template_item_id"], "graph_template_item");
$save["graph_template_id"] = $_POST["graph_template_id"];
$save["local_graph_id"] = 0;
$save["task_item_id"] = form_input_validate($_POST["task_item_id"], "task_item_id", "", true, 3);
$save["color_id"] = form_input_validate((isset($item["color_id"]) ? $item["color_id"] : $_POST["color_id"]), "color_id", "", true, 3);
/* if alpha is disabled, use invisible_alpha instead */
if (!isset($_POST["alpha"])) {$_POST["alpha"] = $_POST["invisible_alpha"];}
$save["alpha"] = form_input_validate((isset($item["alpha"]) ? $item["alpha"] : $_POST["alpha"]), "alpha", "", true, 3);
$save["graph_type_id"] = form_input_validate((isset($item["graph_type_id"]) ? $item["graph_type_id"] : $_POST["graph_type_id"]), "graph_type_id", "", true, 3);
$save["cdef_id"] = form_input_validate($_POST["cdef_id"], "cdef_id", "", true, 3);
$save["consolidation_function_id"] = form_input_validate((isset($item["consolidation_function_id"]) ? $item["consolidation_function_id"] : $_POST["consolidation_function_id"]), "consolidation_function_id", "", true, 3);
$save["text_format"] = form_input_validate((isset($item["text_format"]) ? $item["text_format"] : $_POST["text_format"]), "text_format", "", true, 3);
$save["value"] = form_input_validate($_POST["value"], "value", "", true, 3);
$save["hard_return"] = form_input_validate(((isset($item["hard_return"]) ? $item["hard_return"] : (isset($_POST["hard_return"]) ? $_POST["hard_return"] : ""))), "hard_return", "", true, 3);
$save["gprint_id"] = form_input_validate($_POST["gprint_id"], "gprint_id", "", true, 3);
$save["sequence"] = $_POST["sequence"];
if (!is_error_message()) {
/* Before we save the item, let's get a look at task_item_id <-> input associations */
$orig_data_source_graph_inputs = db_fetch_assoc("select
graph_template_input.id,
graph_template_input.name,
graph_templates_item.task_item_id
from (graph_template_input,graph_template_input_defs,graph_templates_item)
where graph_template_input.id=graph_template_input_defs.graph_template_input_id
and graph_template_input_defs.graph_template_item_id=graph_templates_item.id
and graph_template_input.graph_template_id=" . $save["graph_template_id"] . "
and graph_template_input.column_name='task_item_id'
group by graph_templates_item.task_item_id");
$orig_data_source_to_input = array_rekey($orig_data_source_graph_inputs, "task_item_id", "id");
$graph_template_item_id = sql_save($save, "graph_templates_item");
if ($graph_template_item_id) {
raise_message(1);
if (!empty($save["task_item_id"])) {
/* old item clean-up. Don't delete anything if the item <-> task_item_id association remains the same. */
if ($_POST["_task_item_id"] != $_POST["task_item_id"]) {
/* It changed. Delete any old associations */
db_execute("delete from graph_template_input_defs where graph_template_item_id=$graph_template_item_id");
/* Input for current data source exists and has changed. Update the association */
if (isset($orig_data_source_to_input{$save["task_item_id"]})) {
db_execute("replace into graph_template_input_defs (graph_template_input_id,
graph_template_item_id) values (" . $orig_data_source_to_input{$save["task_item_id"]}
. ",$graph_template_item_id)");
}
}
/* an input for the current data source does NOT currently exist, let's create one */
if (!isset($orig_data_source_to_input{$save["task_item_id"]})) {
$ds_name = db_fetch_cell("select data_source_name from data_template_rrd where id=" . $_POST["task_item_id"]);
db_execute("replace into graph_template_input (hash,graph_template_id,name,column_name) values (
'" . get_hash_graph_template(0, "graph_template_input") . "'," . $save["graph_template_id"] . ",
'Data Source [$ds_name]','task_item_id')");
$graph_template_input_id = db_fetch_insert_id();
$graph_items = db_fetch_assoc("select id from graph_templates_item where graph_template_id=" . $save["graph_template_id"] . " and task_item_id=" . $_POST["task_item_id"]);
if (sizeof($graph_items) > 0) {
foreach ($graph_items as $graph_item) {
db_execute("replace into graph_template_input_defs (graph_template_input_id,graph_template_item_id) values ($graph_template_input_id," . $graph_item["id"] . ")");
}
}
}
}
push_out_graph_item($graph_template_item_id);
if (isset($orig_data_source_to_input{$_POST["task_item_id"]})) {
/* make sure all current graphs using this graph input are aware of this change */
push_out_graph_input($orig_data_source_to_input{$_POST["task_item_id"]}, $graph_template_item_id, array($graph_template_item_id => $graph_template_item_id));
}
}else{
raise_message(2);
}
}
$_POST["sequence"] = 0;
}
if (is_error_message()) {
header("Location: graph_templates_items.php?action=item_edit&graph_template_item_id=" . (empty($graph_template_item_id) ? $_POST["graph_template_item_id"] : $graph_template_item_id) . "&id=" . $_POST["graph_template_id"]);
exit;
}else{
header("Location: graph_templates.php?action=template_edit&id=" . $_POST["graph_template_id"]);
exit;
}
}
}
示例11: ds_rrd_add
function ds_rrd_add()
{
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
/* ==================================================== */
db_execute("insert into data_template_rrd (local_data_id,rrd_maximum,rrd_minimum,rrd_heartbeat,data_source_type_id,\n\t\tdata_source_name) values (" . $_GET["id"] . ",100,0,600,1,'ds')");
$data_template_rrd_id = db_fetch_insert_id();
header("Location: data_sources.php?action=ds_edit&id=" . $_GET["id"] . "&view_rrd={$data_template_rrd_id}");
}
示例12: item_group
function item_group()
{
if (ereg("&group_item_id=([0-9]+)\$", $_SESSION["sess_field_values"]["cacti_js_dropdown_redirect"], $matches)) {
$graph_template_item_id = $matches[1];
$selected_items = array();
/* list each selected item */
while (list($name, $value) = each($_SESSION["sess_field_values"])) {
if (substr($name, 0, 9) == "gi_value_" && $value == "1") {
$selected_items[substr($name, 9)] = 1;
}
}
/* get an official list of items to compare against */
$graph_template_items = db_fetch_assoc("select id from graph_template_item where graph_template_id = " . $_SESSION["sess_field_values"]["id"] . " order by sequence");
/* find out which items were selected for grouping by the user */
$_group = array();
$keep_this_group = false;
if (sizeof($graph_template_items) > 0) {
foreach ($graph_template_items as $item) {
if (isset($selected_items[$item["id"]])) {
$_group[] = $item["id"];
if ($graph_template_item_id == $item["id"]) {
$keep_this_group = true;
}
} else {
if ($keep_this_group == true) {
break;
}
$_group = array();
}
}
}
if (sizeof($_group) > 1) {
db_execute("insert into graph_template_item_group (id,hash,graph_template_id) values (0,''," . $_SESSION["sess_field_values"]["id"] . ")");
$graph_template_item_group_id = db_fetch_insert_id();
if ($graph_template_item_group_id) {
for ($i = 0; $i < sizeof($_group); $i++) {
db_execute("insert into graph_template_item_group_item (graph_template_item_group_id,graph_template_item_id) values ({$graph_template_item_group_id}," . $_group[$i] . ")");
}
}
}
}
}
示例13: ds_rrd_add
function ds_rrd_add() {
db_execute("insert into data_template_rrd (local_data_id,rrd_maximum,rrd_minimum,rrd_heartbeat,data_source_type_id,
data_source_name) values (" . $_GET["id"] . ",100,0,600,1,'ds')");
$data_template_rrd_id = db_fetch_insert_id();
header("Location: data_sources.php?action=ds_edit&id=" . $_GET["id"] . "&view_rrd=$data_template_rrd_id");
}
示例14: template_rrd_add
function template_rrd_add()
{
/* ================= input validation ================= */
input_validate_input_number(get_request_var_request('id'));
input_validate_input_number(get_request_var_request('local_data_id'));
/* ==================================================== */
$hash = get_hash_data_template(0, 'data_template_item');
db_execute_prepared("INSERT INTO data_template_rrd (hash, data_template_id, rrd_maximum, rrd_minimum, rrd_heartbeat, data_source_type_id, data_source_name) \n\t\t VALUES (?, ?, 0, 0, 600, 1, 'ds')", array($hash, $_REQUEST['id']));
$data_template_rrd_id = db_fetch_insert_id();
/* add this data template item to each data source using this data template */
$children = db_fetch_assoc_prepared('SELECT local_data_id FROM data_template_data WHERE data_template_id = ? AND local_data_id > 0', array($_REQUEST['id']));
if (sizeof($children) > 0) {
foreach ($children as $item) {
db_execute_prepared("INSERT INTO data_template_rrd (local_data_template_rrd_id, local_data_id, data_template_id, rrd_maximum, rrd_minimum, rrd_heartbeat, data_source_type_id, data_source_name) \n\t\t\t\t VALUES (?, ?, ?, 0, 0, 600, 1, 'ds')", array($data_template_rrd_id, $item['local_data_id'], $_REQUEST['id']));
}
}
header('Location: data_templates.php?action=template_edit&id=' . $_REQUEST['id'] . "&view_rrd={$data_template_rrd_id}");
}
示例15: api_graph_tree_item_save
function api_graph_tree_item_save($graph_tree_item_id, &$_fields_graph_tree_item) {
require_once(CACTI_BASE_PATH . "/include/graph_tree/graph_tree_constants.php");
require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_utility.php");
require_once(CACTI_BASE_PATH . "/lib/graph_tree/graph_tree_info.php");
/* sanity checks */
validate_id_die($graph_tree_item_id, "graph_tree_item_id", true);
/* sanity check for $graph_tree_id */
if ((empty($graph_tree_item_id)) && (empty($_fields_graph_tree_item["graph_tree_id"]))) {
log_save("Required graph_tree_id when graph_tree_item_id = 0", SEV_ERROR);
return false;
}else if ((isset($_fields_graph_tree_item["graph_tree_id"])) && (!db_integer_validate($_fields_graph_tree_item["graph_tree_id"]))) {
return false;
}
/* sanity check for $item_type */
if ((!isset($_fields_graph_tree_item["item_type"])) || (!db_integer_validate($_fields_graph_tree_item["item_type"]))) {
log_save("Missing required item_type", SEV_ERROR);
return false;
}
/* sanity check for $item_value */
if ((empty($graph_tree_item_id)) && (empty($_fields_graph_tree_item["item_value"]))) {
log_save("Required item_value when graph_tree_item_id = 0", SEV_ERROR);
return false;
}else if ((isset($_fields_graph_tree_item["item_value"])) && ( (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) || ($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HOST)) && (!db_integer_validate($_fields_graph_tree_item["item_value"])) )) {
return false;
}
/* sanity check for $parent_item_id */
if ((!isset($_fields_graph_tree_item["parent_item_id"])) || (!db_integer_validate($_fields_graph_tree_item["parent_item_id"], true))) {
log_save("Missing required parent_item_id", SEV_ERROR);
return false;
}
/* field: id */
$_fields["id"] = array("type" => DB_TYPE_INTEGER, "value" => $graph_tree_item_id);
/* field: graph_tree_id */
if (isset($_fields_graph_tree_item["graph_tree_id"])) {
$_fields["graph_tree_id"] = array("type" => DB_TYPE_INTEGER, "value" => $_fields_graph_tree_item["graph_tree_id"]);
}
/* get a copy of the parent tree item id */
if ($_fields_graph_tree_item["parent_item_id"] == "0") {
$parent_order_key = "";
$parent_sort_type = TREE_ORDERING_NONE;
}else{
$parent_graph_tree_item = api_graph_tree_item_get($_fields_graph_tree_item["parent_item_id"]);
$parent_order_key = $parent_graph_tree_item["order_key"];
$parent_sort_type = $parent_graph_tree_item["sort_children_type"];
}
/* generate a new order key if this is a new graph tree item */
if (empty($graph_tree_item_id)) {
$_fields["order_key"] = array("type" => DB_TYPE_STRING, "value" => api_graph_tree_item_available_order_key_get($_fields_graph_tree_item["graph_tree_id"], $parent_order_key));
}else{
$graph_tree_item = api_graph_tree_item_get($graph_tree_item_id);
$_fields["order_key"] = array("type" => DB_TYPE_STRING, "value" => $graph_tree_item["order_key"]);
}
/* if this item is a graph, make sure it is not being added to the same branch twice */
$search_key = substr($parent_order_key, 0, (api_graph_tree_item_depth_get($parent_order_key) * CHARS_PER_TIER));
if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_GRAPH) && (sizeof(db_fetch_assoc("select id from graph_tree_items where item_value = " . $_fields_graph_tree_item["item_value"] . " and item_type = " . TREE_ITEM_TYPE_GRAPH . " and graph_tree_id = " . $_fields_graph_tree_item["graph_tree_id"] . " and order_key like '$search_key" . str_repeat('_', CHARS_PER_TIER) . str_repeat('0', (MAX_TREE_DEPTH * CHARS_PER_TIER) - (strlen($search_key) + CHARS_PER_TIER)) . "'")) > 0)) {
return true;
}
/* convert the input array into something that is compatible with db_replace() */
$_fields += sql_get_database_field_array($_fields_graph_tree_item, api_graph_tree_item_form_list());
/* check for an empty field list */
if (sizeof($_fields) == 1) {
return true;
}
if (db_replace("graph_tree_items", $_fields, array("id"))) {
if (empty($graph_tree_item_id)) {
$graph_tree_item_id = db_fetch_insert_id();
}
/* re-parent the branch if the parent item has changed */
if ($_fields_graph_tree_item["parent_item_id"] != api_graph_tree_item_parent_get_bykey($_fields["order_key"]["value"], $_fields_graph_tree_item["graph_tree_id"])) {
api_graph_tree_item_reparent($graph_tree_item_id, $_fields_graph_tree_item["parent_item_id"]);
}
$parent_tree = api_graph_tree_get($_fields_graph_tree_item["graph_tree_id"]);
/* tree item ordering */
if ($parent_tree["sort_type"] == TREE_ORDERING_NONE) {
/* resort our parent */
if ($parent_sort_type != TREE_ORDERING_NONE) {
echo $parent_sort_type;
api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $_fields_graph_tree_item["parent_item_id"], $parent_sort_type);
}
/* if this is a header, sort direct children */
if (($_fields_graph_tree_item["item_type"] == TREE_ITEM_TYPE_HEADER) && ($parent_sort_type != TREE_ORDERING_NONE)) {
api_graph_tree_item_sort(SORT_TYPE_TREE_ITEM, $graph_tree_item_id, $parent_sort_type);
}
//.........这里部分代码省略.........