db = $db; } public function load($nasname) { //var_dump($this->db); $nasname = $this->db->escape($nasname); $res = $this->db->select("nas", "*", "nasname='$nasname'"); if(!$this->db->num_rows($res)) { $this->type = "other"; $this->secret = Helper::getNewPassword(24); return true; } $nas = $this->db->fetch_object($res); $this->id = $nas->id; $this->nasname = $nas->nasname; $this->intaddress = $nas->intaddress; $this->shortname = $nas->shortname; $this->type = $nas->type; $this->secret = $nas->secret; $this->description = $nas->description; return true; } public function save() { if(!$this->nasname) { return false; } if(!$this->secret) { return false; } if($this->id) { $id = $this->id; } $values['nasname'] = $this->nasname; $values['intaddress'] = $this->nasname; // is supposed to be the same as nasname $values['shortname'] = $this->shortname; $values['type'] = $this->type; $values['secret'] = $this->secret; $values['description'] = $this->description; if($id) { if(!$this->db->update("nas", $values, "id=$id")) { return false; } } else { if(!$id = $this->db->insert("nas", $values)) { return false; } } return $id; } }