public function table_add_2($ip_addrs, $location_id) { $raw_ips = preg_split("/(\r\n|\n|\r)/", $ip_addrs); $out = array(); $insert = array(); $cleaned = array(); $err = true; foreach ($raw_ips as $ip_addr) { if (!$this->check_syntax($ip_addr)) { $out[] = _("Bad format") . ": '{$ip_addr}'"; $err = true; } else { if (ip_exists_in_table($ip_addr)) { $out[] = "IP '{$ip_addr}' is already in database"; $err = true; } else { $insert[] = $ip_addr; $err = false; } } } if ($err) { $this->xtpl->perex(_("Operation not successful"), implode("<br/>", $out)); return; } if (!count($insert)) { return; } foreach ($insert as $ip) { if ($this->register_ip($location_id, $ip)) { $out[] = _("Added IP") . " {$ip}"; $cleaned[] = array("ver" => $this->type, "addr" => $ip); $err = false; } else { $out[] = _("Failed to register IP") . " {$ip}"; $err = true; } } if (count($cleaned) > 0) { $params = array("ip_addrs" => $cleaned); add_transaction_locationwide($_SESSION["member"]["m_id"], 0, T_CLUSTER_IP_REGISTER, $params, $location_id); } if ($err) { $this->xtpl->perex(_("Operation not completely successful"), implode("<br/>", $out)); } else { $this->xtpl->perex(_("Operation successful"), implode("<br/>", $out)); } }
public function table_add_2($ip_addr, $location_id) { if ($this->check_syntax($ip_addr) == false) { } else { if (!ip_exists_in_table($ip_addr)) { $sql = "INSERT INTO `vps_ip` SET `ip_v`=" . $this->type . ",`ip_location`=" . $location_id . ", `vps_id`=0, `ip_addr`='" . $ip_addr . "';"; if ($this->db->query($sql)) { $t_param["ip_v"] = $this->type; $t_param["ip_addr"] = $ip_addr; $t_param["ip_id"] = $this->db->insert_id(); add_transaction_locationwide($_SESSION["member"]["m_id"], 0, T_CLUSTER_IP_REGISTER, $t_param, $location_id); $this->xtpl->perex(_("Operation successful"), sprintf(_("IP address '%s' has been successfully added"), $ip_addr)); } else { $this->xtpl->perex(_("Operation not successful"), _("An error has occured, while you were trying to add a new IP")); } } else { $this->xtpl->perex(_("Operation not successful"), _("IP already exists in DB")); } } }