config = $config; if ($id > 0) { $this->id = $id; $rows = $this->config->select("select id, name, cmd from languages where id = ?", $id); if (isset($rows[0]) && $rows[0]->id > 0) { $this->name = $rows[0]->name; $this->cmd = $rows[0]->cmd; } else { error_log("Language not found"); return false; } } return true; } /** * Create a new language if there's no language with that name yet. * Construct object first. * $language->create("my lang", "/bin/mylang"); * * param $name The language name * param $cmd Its binary, if not provided try to check it * return $id Newly created language's ID */ function create ($name, $cmd="") { if ($this->config->select("select id from languages where name = ?", $name)) return false; else { $values = array($name, $cmd); $this->config->query("insert into languages values (NULL, ?, ?)", $values); $rows = $this->config->select("select last_insert_id() as id"); $this->id = $rows[0]->id; $this->name = $name; $this->cmd = $cmd; return $this->id; } } /** * Update the current language on the database using the current parameters. * $language->name = "my language's new name"; * $language->update() */ function update () { $values = array( $this->name, $this->cmd, $this->id ); return $this->config->query("update languages set name = ?, cmd = ? where id = ?", $values); } /** * Delete the current language IF and only IF there's no service using it. * $language->delete(); */ function delete () { $values = array( $this->id ); if ($this->config->select("select id from services where language = ?", $values)) return null; return $this->config->query("delete from languages where id = ?", $values); } /** * Dumper. * $language->dump(); */ function dump () { print "\t\t\t* Language: $this->name\n"; if ($this->cmd) print "\t\t\t Language Cmd: $this->cmd\n"; } } ?>