id = $id; } $this->load($this->id); } function load($id = NULL) { if (!is_numeric($id)) { return false; } $this->id = $id; $q = "SELECT * FROM " . DB_PREFIX . "users WHERE id=".$this->id; $ret = query_row($q); if ( $ret) { $this->id = $ret->id; $this->first_name = $ret->first_name; $this->last_name = $ret->last_name; $this->email = $ret->email; $this->language = $ret->language; $this->level = $ret->role; return true; } return false; } function getFirstName() { return $this->first_name; } function getLastName() { return $this->last_name; } function getFullName() { return $this->first_name." ".$this->last_name; } function getEmail() { return $this->email; } function getRole() { return $this->level; } function getURL() { return WWW_ROOT."user/view/".$this->id; } function hasRole($role) { if ( $this->roles[$role] == 1) { return True; } return False; } function getId() { return $this->id; } /*function getUserById($usid) { global $db; $q = "SELECT * FROM " . DB_PREFIX . "users LEFT JOIN userinfo ON " . DB_PREFIX . "users.id=" . DB_PREFIX . "userinfo.userid WHERE " . DB_PREFIX . "users.id=".$usid; $ret = $db->query($q); $res = mysql_fetch_array($ret); return $res; }*/ function getUsers() { global $db; return $db->query("SELECT *, concat(firstname, ' ', lastname) AS fullname FROM " . DB_PREFIX . "users LEFT JOIN " . DB_PREFIX . "userinfo ON " . DB_PREFIX . "users.id=" . DB_PREFIX . "userinfo.userid WHERE approved"); } function getUserById($id=false) { if (isset($id) && is_numeric($id)) { $user = new User(); $load = $user->load($id); if ($load) return $user; return false; } return false; } function getAllUsers() { $res = query_rows("SELECT *, concat(first_name, ' ', last_name) AS fullname FROM " . DB_PREFIX . "users"); return $res; } public function make_admin($uid) { $roles = "111111"; $approved = 1; $res = $this->db->query("UPDATE " . DB_PREFIX . "users SET roles='{$roles}', approved={$approved} WHERE id={$uid}"); if ($res) return 1; return 0; } function updateLastLoginTime() { $q = "UPDATE " . DB_PREFIX . "users SET last_login=NOW() WHERE id={$this->getId()}"; return query($q); } function check_email_exists($email) { $res = query("SELECT count(email) FROM " . DB_PREFIX . "users WHERE email='{$email}'"); $check = mysql_fetch_row($res); return $check[0]; } function is_valid_email($email) { return filter_var($email, FILTER_VALIDATE_EMAIL); } function get_user_by_username_or_email($identificator) { $res = query_row("SELECT * FROM " . DB_PREFIX . "users WHERE username='{$identificator}' OR email='{$identificator}'"); if (!$res) { return false; } $this->load($res->id); return $this; } public function create($backoffice_user) { $role = 5; if ($backoffice_user->getLevel() >= 95) { $role = 9; } $q = "INSERT INTO " . DB_PREFIX . "users (id, first_name, last_name, email, role, registered, last_login) values (".$backoffice_user->getId().", '".$backoffice_user->getFirstName()."', '".$backoffice_user->getLastName()."', '".$backoffice_user->getEmail()."', {$role}, NOW(), NOW())"; $uid = query_insert($q); if ($uid) { $user = new User(); $load = $user->load($uid); if ($load) return $user; } return false; } public function update($backoffice_user) { $role = 5; if ($backoffice_user->getLevel() >= 95) { $role = 9; } $query = "UPDATE " . DB_PREFIX ."users SET"; $query .= " first_name='{$backoffice_user->getFirstName()}',"; $query .= " last_name='{$backoffice_user->getLastName()}',"; $query .= " email='{$backoffice_user->getEmail()}',"; $query .= " role='{$role}',"; $query .= " last_login=NOW()"; $query .= " WHERE id='{$backoffice_user->getId()}'"; return query($query); } public function update_settings($user, $language) { $q = "UPDATE " . DB_PREFIX . "users SET language='{$language}' WHERE id = '{$user->id}'"; return query($q); } function delete() { global $TeKe; if (is_numeric($this->getId()) && $this->getId() > 0) { if ($TeKe->is_admin()) { return query("DELETE FROM " . DB_PREFIX . "users WHERE id=".$this->getId()); } } return false; } } ?>