function hosting_ip_save in Hosting 6.2
IP Utility function for hook_update/hook_insert.
2 calls to hosting_ip_save()
- hosting_server_insert in server/
hosting_server.module - Implementation of hook_insert().
- hosting_server_update in server/
hosting_server.module - Implementation of hook_update().
File
- server/
hosting.ip.inc, line 25 - General IP address CRUD routines.
Code
function hosting_ip_save($node, $update = FALSE) {
$ips = is_array($node->ip_addresses) ? (array) $node->ip_addresses : array();
foreach ($ips as $id => $ip) {
$ip = trim($ip);
if (empty($ip)) {
// empty fields are considered removed
db_query("DELETE FROM {hosting_ip_addresses} WHERE id=%d", $id);
}
else {
db_query("UPDATE {hosting_ip_addresses} SET ip_address = '%s' WHERE id=%d", $ip, $id);
}
}
$ips = isset($node->new_ip_addresses) ? (array) $node->new_ip_addresses : array();
foreach ($ips as $id => $ip) {
if (!empty($ip)) {
// new entries are prefixed with the string 'new', insert those
db_query("INSERT INTO {hosting_ip_addresses} (nid, ip_address) VALUES (%d, '%s')", $node->nid, $ip);
}
}
}