Browse Source

Finish user edition

leosw 8 months ago
parent
commit
0f00e4d991
5 changed files with 44 additions and 62 deletions
  1. 4 4
      controllers/d.users.php
  2. 17 35
      models/d.users.php
  3. 4 4
      views/blocks/d.nav.html
  4. 7 7
      views/d.user.profile.edit.html
  5. 12 12
      views/d.user.profile.html

+ 4 - 4
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();

+ 17 - 35
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 '<span class="userrole" style="color: '.$ranks[$this->rank][2].';">'.$ranks[$this->rank][1].'</span>';
-	}
-	public function get_avatar() {
-		if( $this->is_avatar_present == 't')
-			return $this->id;
-		else
-		    return NULL;
+		return '<span class="userrole" style="color: '.$ranks[$this->rank][2].';">'.$ranks[$this->rank][1].'</span>';
 	}
 	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');
 	}

+ 4 - 4
views/blocks/d.nav.html

@@ -10,12 +10,12 @@
 						<li class="on-bar"><a class="on-bar" href="<?=$config['rel_root_folder']?>news">Nouveautés</a></li>
 						<li class="on-bar"><a class="on-bar" href="<?=$config['rel_root_folder']?>community">Contribuer</a></li>
 						<li class="on-bar has-sub">
-							<? if ($user->get_id() == 0) { ?>
+							<? if ($user->id == 0) { ?>
 							<a class="on-bar" href="#"><i class="icon fas fa-user"></i></a>
-							<? } elseif ($user->get_avatar() == NULL) { ?>
-							<a class="on-bar" href="#"><i class="icon fas fa-user-secret"></i></a>
+							<? } elseif ($user->is_avatar_present == 't') { ?>
+							<a class="on-bar" href="#"><img alt="Avatar" class="icon avatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$user->id?>_s.jpg"></a>
 							<? } else { ?>
-							<a class="on-bar" href="#"><img alt="Avatar" class="icon avatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$user->get_avatar()?>_s.jpg"></a>
+							<a class="on-bar" href="#"><i class="icon fas fa-user-secret"></i></a>
 							<? } ?>
 							<ul>
 								<? if($user->rank == 'visitor') { ?>

+ 7 - 7
views/d.user.profile.edit.html

@@ -8,7 +8,7 @@
 		<? include('blocks/d.nav.html'); ?>
 
 		<section id="profile">
-			<? if ($userProfile->get_id() != 0) { ?>
+			<? if ($userProfile->id != 0) { ?>
 				<h1><?=$userProfile->name?></h1>
 				<article>
 					<? if(isset($nameError) AND $nameError==1) { ?>
@@ -20,19 +20,19 @@
 					<? if(isset($updated) AND $updated==1) { ?>
 						<p style="color: #006600;">Le profil a été mis à jour.</p>
 					<? } ?>
-					<form action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->get_id()?>/edit" method="post" class="edituser" enctype="multipart/form-data">
-						<aside class="<?=$userProfile->get_avatar()!=NULL?'':'no'?>avatar">
+					<form action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->id?>/edit" method="post" class="edituser" enctype="multipart/form-data">
+						<aside class="<?=$userProfile->is_avatar_present=='t'?'':'no'?>avatar">
 							<div id="picturebuttonscontainer">
 								<div id="picturebuttons">
-									<a href="#" id="uploadavatar"><i class="fas fa-camera"></i></a><a <?=$userProfile->get_avatar()!=NULL?'':'style="display: none;"'?> href="#" id="deleteavatar" style="font-size: 1.1em;"><i class="fas fa-trash"></i></a>
+									<a href="#" id="uploadavatar"><i class="fas fa-camera"></i></a><a <?=$userProfile->is_avatar_present=='t'?'':'style="display: none;"'?> href="#" id="deleteavatar" style="font-size: 1.1em;"><i class="fas fa-trash"></i></a>
 								</div>
 							</div>
 
-							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->get_id()?>_p.jpg" alt="Profile picture">
+							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->id?>_p.jpg" alt="Profile picture">
 							<i id="profilenoavatar" class="fas fa-user-secret"></i>
 						</aside>
 
-						<input id="avatarcheckbox" style="display: none;" type="checkbox" name="avatar" <?=$userProfile->get_avatar()!=NULL?'checked':''?>>
+						<input id="avatarcheckbox" style="display: none;" type="checkbox" name="avatar" <?=$userProfile->is_avatar_present=='t'?'checked':''?>>
 						<input type="hidden" name="MAX_FILE_SIZE" value="4194304" />
 						<input id="avatarfile" name="avatarfile" style="display: none;" type="file" accept="image/*" />
 
@@ -51,7 +51,7 @@
 								<li><label for="rank">Rang : </label>
 									<select name="rank" id="rank">
 										<? foreach($ranks as $rank) { ?>
-											<option <?=$userProfile->get_rank(true)==$rank[3]?'selected':''?> value="<?=$rank[0]?>"><?=$rank[1]?></option>
+											<option <?=$userProfile->rank==$rank[3]?'selected':''?> value="<?=$rank[3]?>"><?=$rank[1]?></option>
 										<? } ?>
 									</select></li>
 								<? } ?>

+ 12 - 12
views/d.user.profile.html

@@ -8,36 +8,36 @@
 		<? include('blocks/d.nav.html'); ?>
 
 		<section id="profile">
-			<? if ($userProfile->get_id() != 0) { ?>
+			<? if ($userProfile->id != 0) { ?>
 				<h1><?=$userProfile->name?></h1>
-				<? if($user->rankIsHigher("moderator") || $user->get_id() == $userProfile->get_id()) { ?>
-				<a class="subtitle" id="editprofile" href="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->get_id()?>/edit"><i class="fas fa-pencil-alt"></i> Éditer les paramètres du compte</a>
+				<? if($user->rankIsHigher("moderator") || $user->id == $userProfile->id) { ?>
+				<a class="subtitle" id="editprofile" href="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->id?>/edit"><i class="fas fa-pencil-alt"></i> Éditer les paramètres du compte</a>
 				<? } ?>
 				<article>
 					<div id="profilepart">
 						<? if(isset($mailsent) AND $mailsent==1) { ?>
 							<p style="color: #006600;">Le message a bien été envoyé.</p>
 						<? } ?>
-						<aside class="<?=$userProfile->get_avatar()!=NULL?'':'no'?>avatar">
-							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->get_id()?>_p.jpg" alt="Profile picture">
+						<aside class="<?=$userProfile->is_avatar_present=='t'?'':'no'?>avatar">
+							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->id?>_p.jpg" alt="Profile picture">
 							<i id="profilenoavatar" class="fas fa-user-secret"></i>
 						</aside>
 							<div id="description">
 								<p>Langue : <?=$userProfile->get_locale()?></p>
-								<p>Inscrit le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($userProfile->get_register_date())) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
-								<p>Dernière connexion le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($userProfile->get_visit_date())) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
+								<p>Inscrit le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($userProfile->register_date)) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
+								<p>Dernière connexion le <? echo strftime('%e %B %G, %kh%Mm%Ss',strtotime($userProfile->visit_date)) ?> <small><abbr title="Temps Universel Coordonné">UTC</abbr></small></p>
 								<p><?=$userProfile->get_rank()?></p>
 								<p>
 									<? if ($userProfile->website != "") { ?>
 										<a target="_blank" href="<?=$userProfile->website?>">Site internet <span class="external-link"><i class="fas fa-external-link-alt"></i></span></a>
 									<? }
-									if ($userProfile->website != "" AND $userProfile->get_id() != $user->get_id()) { ?>
+									if ($userProfile->website != "" AND $userProfile->id != $user->id) { ?>
 										 &mdash; 
 									<? }
-									if ($userProfile->get_id() != $user->get_id()) { ?>
+									if ($userProfile->id != $user->id) { ?>
 										<a href="#" onclick="$('#profilepart').hide(0, function(){$('#contact').show('fast');});">Contacter par mail</a>
 									<? }
-									if ($user->rankIsHigher("premium") AND ($userProfile->website != "" OR $userProfile->get_id() != $user->get_id())) { ?>
+									if ($user->rankIsHigher("premium") AND ($userProfile->website != "" OR $userProfile->id != $user->id)) { ?>
 										 &mdash; 
 									<? }
 									if ($user->rankIsHigher("premium")) { ?>
@@ -47,8 +47,8 @@
 							</div>
 							<div style="clear:both;"></div>
 					</div>
-						<? if ($userProfile->get_id() != $user->get_id()) { ?>
-							<form style="display:none;" class="form" id="contact" action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->get_id()?>" method="post" >
+						<? if ($userProfile->id != $user->id) { ?>
+							<form style="display:none;" class="form" id="contact" action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->id?>" method="post" >
 								<textarea rows="12" name="message" id="message" placeholder="Votre message"></textarea>
 								<p><i>Votre adresse email sera transmise à votre destinataire.</i></p>
 								<input type="submit" name="submit" value="Envoyer">