From 0f00e4d991ccda9361978a02b77e197d452f1e6d Mon Sep 17 00:00:00 2001 From: leosw Date: Thu, 18 Oct 2018 23:04:13 +0200 Subject: [PATCH] Finish user edition --- controllers/d.users.php | 8 +++--- models/d.users.php | 52 +++++++++++----------------------- views/blocks/d.nav.html | 8 +++--- views/d.user.profile.edit.html | 14 ++++----- views/d.user.profile.html | 24 ++++++++-------- 5 files changed, 44 insertions(+), 62 deletions(-) diff --git a/controllers/d.users.php b/controllers/d.users.php index be0add3..acf9818 100755 --- a/controllers/d.users.php +++ b/controllers/d.users.php @@ -15,7 +15,7 @@ if(isset($controller->splitted_url[1])) { if($user->login($_POST['login'], $_POST['password'])) { // SUCESSFULL LOGIN - $_SESSION['userid'] = $user->get_id(); + $_SESSION['userid'] = $user->id; header('Location: '.$_SERVER['HTTP_REFERER']); } else { @@ -102,7 +102,7 @@ if(isset($controller->splitted_url[1])) { $userProfile->checkID(intval($controller->splitted_url[2])); } $head['title'] = "Profil inexistant"; - if($userProfile->get_id() != 0) { + if($userProfile->id != 0) { $head['title'] = "Profil de ".$userProfile->name; } @@ -144,13 +144,13 @@ if(isset($controller->splitted_url[1])) { if(file_exists($pathToFile."_s.jpg")) unlink($pathToFile."_s.jpg"); generate_image_thumbnail($pathToFile, $pathToFile."_s.jpg", 28, 28); - $userProfile->avatar = 't'; + $userProfile->is_avatar_present = 't'; } elseif (!isset($_POST['avatar'])) { if(file_exists($pathToFile)) unlink($pathToFile); if(file_exists($pathToFile."_p.jpg")) unlink($pathToFile."_p.jpg"); if(file_exists($pathToFile."_s.jpg")) unlink($pathToFile."_s.jpg"); - $userProfile->avatar = 'f'; + $userProfile->is_avatar_present = 'f'; } $userProfile->update(); diff --git a/models/d.users.php b/models/d.users.php index 00d4ddd..54ba283 100755 --- a/models/d.users.php +++ b/models/d.users.php @@ -21,19 +21,19 @@ $ranks = array( class User { - private $id = 0; + public $id = 0; public $name = NULL; - private $version = NULL; + public $version = NULL; public $email = NULL; - private $password = NULL; + public $password = NULL; public $website = NULL; - private $is_avatar_present = NULL; - private $is_archive = NULL; + public $is_avatar_present = NULL; + public $is_archive = NULL; public $rank = NULL; - private $locale = NULL; - private $timezone = NULL; - private $visit_date = NULL; - private $register_date = NULL; + public $locale = NULL; + public $timezone = NULL; + public $visit_date = NULL; + public $register_date = NULL; /***** ** Connect to correct account using ID and stores its ID @@ -91,7 +91,7 @@ class User /***** ** Populate the object using raw data from SQL *****/ - private function populate($row) { + public function populate($row) { $this->id = $row['id']; $this->name = $row['name']; $this->version = $row['version']; @@ -110,22 +110,10 @@ class User /***** ** Simple return only functions *****/ - public function get_id() { - return $this->id; - } - public function get_rank( $no_html = false ) { + public function get_rank() { global $ranks; - if( $no_html ) - return $this->rank; - else - return ''.$ranks[$this->rank][1].''; - } - public function get_avatar() { - if( $this->is_avatar_present == 't') - return $this->id; - else - return NULL; + return ''.$ranks[$this->rank][1].''; } public function get_locale() { if( isset($this->locale_loaded) ) { @@ -140,12 +128,6 @@ class User return false; } } - public function get_visit_date() { - return $this->visit_date; - } - public function get_register_date() { - return $this->register_date; - } /***** ** Returns true if user permissions are higher than $rank @@ -259,17 +241,17 @@ class User or die ("Could not connect to server\n"); if($this->password=='') { - $query = "UPDATE users SET name = $1, avatar = $2, locale = $3, role = $4, mail = $5, website = $6 WHERE id = $7"; + $query = "UPDATE users SET name = $1, is_avatar_present = $2, locale = $3, rank = $4, email = $5, website = $6 WHERE id = $7"; pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); - pg_execute($con, "prepare1", array($this->name, $this->avatar, $this->locale, $this->role, $this->mail, $this->website, $this->id)) + pg_execute($con, "prepare1", array($this->name, $this->is_avatar_present, $this->locale, $this->rank, $this->email, $this->website, $this->id)) or die ("Cannot execute statement\n"); } else { - $query = "UPDATE users SET name = $1, avatar = $2, locale = $3, role = $4, mail = $5, website = $6, password = $7 WHERE id = $8"; + $query = "UPDATE users SET name = $1, is_avatar_present = $2, locale = $3, rank = $4, email = $5, website = $6, password = $7 WHERE id = $8"; pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); - pg_execute($con, "prepare1", array($this->name, $this->avatar, $this->locale, $this->role, $this->mail, $this->website, $this->password, $this->id)) + pg_execute($con, "prepare1", array($this->name, $this->is_avatar_present, $this->locale, $this->rank, $this->email, $this->website, $this->password, $this->id)) or die ("Cannot execute statement\n"); } @@ -374,7 +356,7 @@ class User mail($this->email, 'Kabano - Nouveau message privé', $message, $headers); error_log( - date('r')." \t".$user->name." (".$user->get_id().") \tMAIL \tMail sent to ".$this->name." (".$this->id.")\r\n", + date('r')." \t".$user->name." (".$user->id.") \tMAIL \tMail sent to ".$this->name." (".$this->id.")\r\n", 3, $config['logs_folder'].'users.log'); } diff --git a/views/blocks/d.nav.html b/views/blocks/d.nav.html index 54c88a6..b727172 100755 --- a/views/blocks/d.nav.html +++ b/views/blocks/d.nav.html @@ -10,12 +10,12 @@
  • Nouveautés
  • Contribuer
  • - get_id() == 0) { ?> + id == 0) { ?> - get_avatar() == NULL) { ?> - + is_avatar_present == 't') { ?> + Avatar - Avatar +