unique_query("SELECT id, firstname, lastname, username, company, auth_level FROM users WHERE id=" . intval($id)); if (!empty($res)) { $this->firstname = $res['firstname']; $this->lastname = $res['lastname']; $this->username = $res['username']; $this->company = $res['company']; $this->auth_level = $res['auth_level']; } $db->deconnexion(); } } function update() { $username = $this->username; $auth_level = intval($this->auth_level); $firstname = $this->firstname; $lastname = $this->lastname; $company = $this->company; $db = new BDD(); $db->escape($username); $db->escape($firstname); $db->escape($lastname); $db->escape($company); if (empty($this->id)) { $db->query("INSERT INTO users VALUES (NULL, '".$username."', 0x0, ".$auth_level.", '".$firstname."', '".$lastname."', '".$company."')"); $this->id = $db->insert_id(); $aff = ($this->id > 0); } else { $db->query("UPDATE users SET username = '".$username."', auth_level = '".$auth_level."', firstname = '".$firstname."', lastname = '".$lastname."', company = '".$company."' WHERE id = ".intval($this->id)); $aff = $db->affected(); } $db->deconnexion(); return ($aff == 1); } function get_id() { return $this->id; } function get_firstname() { return $this->firstname; } function get_lastname() { return $this->lastname; } function get_username() { return $this->username; } function get_company() { return $this->company; } function get_auth_level() { return $this->auth_level; } function get_pts() { if(isset($this->points)) { $db = new BDD(); $res = $db->query("SELECT e.id, s.id_user, SUM(e.points) as sum_points FROM exercices e LEFT OUTER JOIN solved s ON e.id = s.id_exercice WHERE s.id_user = " . intval($this->id) . " GROUP BY s.id_user"); if (!empty($res)) { $this->points = $res['sum_points']; } $db->deconnexion(); } } function authenticate($certificate) { //TODO } // Points par theme (theme, user, sum_points) //$res = $db->query("SELECT e.id_theme, s.id_user, SUM(e.points) as sum_points //FROM exercices e //LEFT OUTER JOIN solved s ON e.id = s.id_exercice //WHERE s.id_user = " . intval($this->id) . " //GROUP BY s.id_user, e.id_theme"); //SELECT e.id_theme, // (select e.points from exercices where e.id=???), // (select e.points from exercices where e.id=???), // (select e.points from exercices where e.id=???), // (select e.points from exercices where e.id=???), // (select e.points from exercices where e.id=???) // (select max(e.points) from exercices) //FROM exercices e //LEFT OUTER JOIN solved s ON e.id = s.id_exercice //WHERE s.id_user = " . intval($this->id) . " //GROUP BY s.id_user, e.id_theme"); }