function api_device_field_validate(&$_fields_device, $device_field_name_format = "|field|") { require_once(CACTI_BASE_PATH . "/lib/device/device_info.php"); if (sizeof($_fields_device) == 0) { return array(); } /* array containing errored fields */ $error_fields = array(); /* get a complete field list */ $fields_device = api_device_form_list(); /* base fields */ while (list($_field_name, $_field_array) = each($fields_device)) { if ((isset($_fields_device[$_field_name])) && (isset($_field_array["validate_regexp"])) && (isset($_field_array["validate_empty"]))) { $form_field_name = str_replace("|field|", $_field_name, $device_field_name_format); if (!form_input_validate($_fields_device[$_field_name], $form_field_name, $_field_array["validate_regexp"], $_field_array["validate_empty"])) { $error_fields[] = $form_field_name; } } } return $error_fields; }
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; } }
function api_device_total_get($filter_array = "") { require_once(CACTI_BASE_PATH . "/lib/device/device_form.php"); $sql_where = ""; /* validation and setup for the WHERE clause */ if ((is_array($filter_array)) && (sizeof($filter_array) > 0)) { /* validate each field against the known master field list */ $field_errors = api_device_field_validate(sql_filter_array_to_field_array($filter_array), "|field|"); /* if a field input error has occured, register the error in the session and return */ if (sizeof($field_errors) > 0) { field_register_error($field_errors); return false; /* otherwise, form an SQL WHERE string using the filter fields */ }else{ $sql_where = sql_filter_array_to_where_string($filter_array, api_device_form_list(), true); } } return db_fetch_cell("select count(*) from host $sql_where"); }
function _script_field_field__field_input_value_device($field_name, $field_value = "", $field_id = 0) { require_once(CACTI_BASE_PATH . "/lib/sys/html_form.php"); require_once(CACTI_BASE_PATH . "/lib/device/device_info.php"); ?> <tr class="<?php echo field_get_row_style();?>" id="row_field_device_field_<?php echo $field_id;?>"> <td class="field-row" width="50%"> <span class="textEditTitle"><?php echo _("Device Field");?></span><br> <?php echo _("Select the device field that will be used to populate this input field.");?> </td> <td class="field-row" colspan="2"> <?php form_dropdown($field_name, array_keys(api_device_form_list()), "", "", $field_value, "", "hostname");?> </td> </tr> <?php }