id = $id; } else { $this->setting = $id; //$this->load(); } } public function create() { $user_id = "NULL"; if (is_logged_in()) { $user_id = get_logged_in_user()->getId(); } $insert = query_insert("INSERT INTO " . DB_PREFIX . $this->getTable() . " (setting, value, user) values ('".$this->getSetting()."', '".mysql_real_escape_string($this->getValue())."', ".$user_id.")"); if ($insert) { $this->id = $insert; return $this->id; } return false; } public function save() { $user_id = "NULL"; if (is_logged_in()) { $user_id = get_logged_in_user()->getId(); } $update_query = "UPDATE " . DB_PREFIX . $this->getTable() . " SET"; $update_query .= " value='" . mysql_real_escape_string($this->getValue()) . "',"; $update_query .= " user=" . $user_id; $update_query .= " WHERE id=" . $this->getId(); $update = query_update($update_query); return $update; } public function updateValue($value) { $exists = $this->load(); if (!$exists) { $this->setValue($value); return $this->create(); } else { if ($this->getValue() != $value) { $this->setValue($value); return $this->save(); } } return false; } public function load() { $data = false; $setting = $this->getSetting(); if ($this->getSetting()) { $this->setting = $setting; $data = query_row("SELECT * FROM " . DB_PREFIX . $this->getTable() . " WHERE setting='{$setting}'"); } if ($data) { $this->id = $data->id; $this->setValue($data->value); $this->setUser($data->user); $this->setModified($data->modified); return $data; } return false; } public function canEdit() { if (is_admin()) { return 1; } return 0; } public function getId() { return $this->id; } public function getTable() { return $this->table; } function setTable($table) { $this->table = $table; } public function getSetting() { return $this->setting; } function setSetting($setting) { $this->setting = $setting; } public function getValue() { return $this->value; } function setValue($value) { $this->value = $value; } public function getUser() { return $this->user; } function setUser($user) { $this->user = $user; } public function getModified() { return $this->modified; } function setModified($modified) { $this->modified = $modified; } } ?>