Browse Source

Finish user edition

Léo Serre 11 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 View File

@@ -15,7 +15,7 @@ if(isset($controller->splitted_url[1])) {
15 15
 
16 16
 					if($user->login($_POST['login'], $_POST['password'])) {
17 17
 						// SUCESSFULL LOGIN
18
-						$_SESSION['userid'] = $user->get_id();
18
+						$_SESSION['userid'] = $user->id;
19 19
 						header('Location: '.$_SERVER['HTTP_REFERER']);
20 20
 					}
21 21
 					else {
@@ -102,7 +102,7 @@ if(isset($controller->splitted_url[1])) {
102 102
 					$userProfile->checkID(intval($controller->splitted_url[2]));
103 103
 				}
104 104
 				$head['title'] = "Profil inexistant";
105
-				if($userProfile->get_id() != 0) {
105
+				if($userProfile->id != 0) {
106 106
 					$head['title'] = "Profil de ".$userProfile->name;
107 107
 				}
108 108
 
@@ -144,13 +144,13 @@ if(isset($controller->splitted_url[1])) {
144 144
 							if(file_exists($pathToFile."_s.jpg")) unlink($pathToFile."_s.jpg");
145 145
 							generate_image_thumbnail($pathToFile, $pathToFile."_s.jpg", 28, 28);
146 146
 
147
-							$userProfile->avatar = 't';
147
+							$userProfile->is_avatar_present = 't';
148 148
 						}
149 149
 						elseif (!isset($_POST['avatar'])) {
150 150
 							if(file_exists($pathToFile)) unlink($pathToFile);
151 151
 							if(file_exists($pathToFile."_p.jpg")) unlink($pathToFile."_p.jpg");
152 152
 							if(file_exists($pathToFile."_s.jpg")) unlink($pathToFile."_s.jpg");
153
-							$userProfile->avatar = 'f';
153
+							$userProfile->is_avatar_present = 'f';
154 154
 						}
155 155
 
156 156
 						$userProfile->update();

+ 17
- 35
models/d.users.php View File

@@ -21,19 +21,19 @@ $ranks = array(
21 21
 
22 22
 class User
23 23
 {
24
-    private $id = 0;
24
+    public $id = 0;
25 25
     public $name = NULL;
26
-    private $version = NULL;
26
+    public $version = NULL;
27 27
     public $email = NULL;
28
-    private $password = NULL;
28
+    public $password = NULL;
29 29
     public $website = NULL;
30
-    private $is_avatar_present = NULL;
31
-    private $is_archive = NULL;
30
+    public $is_avatar_present = NULL;
31
+    public $is_archive = NULL;
32 32
     public $rank = NULL;
33
-    private $locale = NULL;
34
-    private $timezone = NULL;
35
-    private $visit_date = NULL;
36
-    private $register_date = NULL;
33
+    public $locale = NULL;
34
+    public $timezone = NULL;
35
+    public $visit_date = NULL;
36
+    public $register_date = NULL;
37 37
 
38 38
 	/*****
39 39
 	** Connect to correct account using ID and stores its ID
@@ -91,7 +91,7 @@ class User
91 91
 	/*****
92 92
 	** Populate the object using raw data from SQL
93 93
 	*****/
94
-	private function populate($row) {
94
+	public function populate($row) {
95 95
 	    $this->id = $row['id'];
96 96
 	    $this->name = $row['name'];
97 97
 	    $this->version = $row['version'];
@@ -110,22 +110,10 @@ class User
110 110
 	/*****
111 111
 	** Simple return only functions
112 112
 	*****/
113
-	public function get_id() {
114
-	    return $this->id;
115
-	}
116
-	public function get_rank( $no_html = false ) {
113
+	public function get_rank() {
117 114
 		global $ranks;
118 115
 
119
-		if( $no_html )
120
-			return $this->rank;
121
-		else
122
-			return '<span class="userrole" style="color: '.$ranks[$this->rank][2].';">'.$ranks[$this->rank][1].'</span>';
123
-	}
124
-	public function get_avatar() {
125
-		if( $this->is_avatar_present == 't')
126
-			return $this->id;
127
-		else
128
-		    return NULL;
116
+		return '<span class="userrole" style="color: '.$ranks[$this->rank][2].';">'.$ranks[$this->rank][1].'</span>';
129 117
 	}
130 118
 	public function get_locale() {
131 119
 		if( isset($this->locale_loaded) ) {
@@ -140,12 +128,6 @@ class User
140 128
 				return false;
141 129
 		}
142 130
 	}
143
-	public function get_visit_date() {
144
-	    return $this->visit_date;
145
-	}
146
-	public function get_register_date() {
147
-	    return $this->register_date;
148
-	}
149 131
 
150 132
 	/*****
151 133
 	** Returns true if user permissions are higher than $rank
@@ -259,17 +241,17 @@ class User
259 241
 			or die ("Could not connect to server\n");
260 242
 
261 243
 		if($this->password=='') {
262
-			$query = "UPDATE users SET name = $1, avatar = $2, locale = $3, role = $4, mail = $5, website = $6 WHERE id = $7";
244
+			$query = "UPDATE users SET name = $1, is_avatar_present = $2, locale = $3, rank = $4, email = $5, website = $6 WHERE id = $7";
263 245
 			pg_prepare($con, "prepare1", $query) 
264 246
 				or die ("Cannot prepare statement\n");
265
-			pg_execute($con, "prepare1", array($this->name, $this->avatar, $this->locale, $this->role, $this->mail, $this->website, $this->id))
247
+			pg_execute($con, "prepare1", array($this->name, $this->is_avatar_present, $this->locale, $this->rank, $this->email, $this->website, $this->id))
266 248
 				or die ("Cannot execute statement\n");
267 249
 		}
268 250
 		else {
269
-			$query = "UPDATE users SET name = $1, avatar = $2, locale = $3, role = $4, mail = $5, website = $6, password = $7 WHERE id = $8";
251
+			$query = "UPDATE users SET name = $1, is_avatar_present = $2, locale = $3, rank = $4, email = $5, website = $6, password = $7 WHERE id = $8";
270 252
 			pg_prepare($con, "prepare1", $query) 
271 253
 				or die ("Cannot prepare statement\n");
272
-			pg_execute($con, "prepare1", array($this->name, $this->avatar, $this->locale, $this->role, $this->mail, $this->website, $this->password, $this->id))
254
+			pg_execute($con, "prepare1", array($this->name, $this->is_avatar_present, $this->locale, $this->rank, $this->email, $this->website, $this->password, $this->id))
273 255
 				or die ("Cannot execute statement\n");
274 256
 		}
275 257
 
@@ -374,7 +356,7 @@ class User
374 356
 		mail($this->email, 'Kabano - Nouveau message privé', $message, $headers);
375 357
 
376 358
 		error_log(
377
-			date('r')." \t".$user->name." (".$user->get_id().") \tMAIL \tMail sent to ".$this->name." (".$this->id.")\r\n",
359
+			date('r')." \t".$user->name." (".$user->id.") \tMAIL \tMail sent to ".$this->name." (".$this->id.")\r\n",
378 360
 			3,
379 361
 			$config['logs_folder'].'users.log');
380 362
 	}

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

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

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

@@ -8,7 +8,7 @@
8 8
 		<? include('blocks/d.nav.html'); ?>
9 9
 
10 10
 		<section id="profile">
11
-			<? if ($userProfile->get_id() != 0) { ?>
11
+			<? if ($userProfile->id != 0) { ?>
12 12
 				<h1><?=$userProfile->name?></h1>
13 13
 				<article>
14 14
 					<? if(isset($nameError) AND $nameError==1) { ?>
@@ -20,19 +20,19 @@
20 20
 					<? if(isset($updated) AND $updated==1) { ?>
21 21
 						<p style="color: #006600;">Le profil a été mis à jour.</p>
22 22
 					<? } ?>
23
-					<form action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->get_id()?>/edit" method="post" class="edituser" enctype="multipart/form-data">
24
-						<aside class="<?=$userProfile->get_avatar()!=NULL?'':'no'?>avatar">
23
+					<form action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->id?>/edit" method="post" class="edituser" enctype="multipart/form-data">
24
+						<aside class="<?=$userProfile->is_avatar_present=='t'?'':'no'?>avatar">
25 25
 							<div id="picturebuttonscontainer">
26 26
 								<div id="picturebuttons">
27
-									<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>
27
+									<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>
28 28
 								</div>
29 29
 							</div>
30 30
 
31
-							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->get_id()?>_p.jpg" alt="Profile picture">
31
+							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->id?>_p.jpg" alt="Profile picture">
32 32
 							<i id="profilenoavatar" class="fas fa-user-secret"></i>
33 33
 						</aside>
34 34
 
35
-						<input id="avatarcheckbox" style="display: none;" type="checkbox" name="avatar" <?=$userProfile->get_avatar()!=NULL?'checked':''?>>
35
+						<input id="avatarcheckbox" style="display: none;" type="checkbox" name="avatar" <?=$userProfile->is_avatar_present=='t'?'checked':''?>>
36 36
 						<input type="hidden" name="MAX_FILE_SIZE" value="4194304" />
37 37
 						<input id="avatarfile" name="avatarfile" style="display: none;" type="file" accept="image/*" />
38 38
 
@@ -51,7 +51,7 @@
51 51
 								<li><label for="rank">Rang : </label>
52 52
 									<select name="rank" id="rank">
53 53
 										<? foreach($ranks as $rank) { ?>
54
-											<option <?=$userProfile->get_rank(true)==$rank[3]?'selected':''?> value="<?=$rank[0]?>"><?=$rank[1]?></option>
54
+											<option <?=$userProfile->rank==$rank[3]?'selected':''?> value="<?=$rank[3]?>"><?=$rank[1]?></option>
55 55
 										<? } ?>
56 56
 									</select></li>
57 57
 								<? } ?>

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

@@ -8,36 +8,36 @@
8 8
 		<? include('blocks/d.nav.html'); ?>
9 9
 
10 10
 		<section id="profile">
11
-			<? if ($userProfile->get_id() != 0) { ?>
11
+			<? if ($userProfile->id != 0) { ?>
12 12
 				<h1><?=$userProfile->name?></h1>
13
-				<? if($user->rankIsHigher("moderator") || $user->get_id() == $userProfile->get_id()) { ?>
14
-				<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>
13
+				<? if($user->rankIsHigher("moderator") || $user->id == $userProfile->id) { ?>
14
+				<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>
15 15
 				<? } ?>
16 16
 				<article>
17 17
 					<div id="profilepart">
18 18
 						<? if(isset($mailsent) AND $mailsent==1) { ?>
19 19
 							<p style="color: #006600;">Le message a bien été envoyé.</p>
20 20
 						<? } ?>
21
-						<aside class="<?=$userProfile->get_avatar()!=NULL?'':'no'?>avatar">
22
-							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->get_id()?>_p.jpg" alt="Profile picture">
21
+						<aside class="<?=$userProfile->is_avatar_present=='t'?'':'no'?>avatar">
22
+							<img alt="Avatar" id="profileavatar" src="<?=$config['rel_root_folder']?>medias/avatars/<?=$userProfile->id?>_p.jpg" alt="Profile picture">
23 23
 							<i id="profilenoavatar" class="fas fa-user-secret"></i>
24 24
 						</aside>
25 25
 							<div id="description">
26 26
 								<p>Langue : <?=$userProfile->get_locale()?></p>
27
-								<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>
28
-								<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>
27
+								<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>
28
+								<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>
29 29
 								<p><?=$userProfile->get_rank()?></p>
30 30
 								<p>
31 31
 									<? if ($userProfile->website != "") { ?>
32 32
 										<a target="_blank" href="<?=$userProfile->website?>">Site internet <span class="external-link"><i class="fas fa-external-link-alt"></i></span></a>
33 33
 									<? }
34
-									if ($userProfile->website != "" AND $userProfile->get_id() != $user->get_id()) { ?>
34
+									if ($userProfile->website != "" AND $userProfile->id != $user->id) { ?>
35 35
 										 &mdash; 
36 36
 									<? }
37
-									if ($userProfile->get_id() != $user->get_id()) { ?>
37
+									if ($userProfile->id != $user->id) { ?>
38 38
 										<a href="#" onclick="$('#profilepart').hide(0, function(){$('#contact').show('fast');});">Contacter par mail</a>
39 39
 									<? }
40
-									if ($user->rankIsHigher("premium") AND ($userProfile->website != "" OR $userProfile->get_id() != $user->get_id())) { ?>
40
+									if ($user->rankIsHigher("premium") AND ($userProfile->website != "" OR $userProfile->id != $user->id)) { ?>
41 41
 										 &mdash; 
42 42
 									<? }
43 43
 									if ($user->rankIsHigher("premium")) { ?>
@@ -47,8 +47,8 @@
47 47
 							</div>
48 48
 							<div style="clear:both;"></div>
49 49
 					</div>
50
-						<? if ($userProfile->get_id() != $user->get_id()) { ?>
51
-							<form style="display:none;" class="form" id="contact" action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->get_id()?>" method="post" >
50
+						<? if ($userProfile->id != $user->id) { ?>
51
+							<form style="display:none;" class="form" id="contact" action="<?=$config['rel_root_folder']?>user/p/<?=$userProfile->id?>" method="post" >
52 52
 								<textarea rows="12" name="message" id="message" placeholder="Votre message"></textarea>
53 53
 								<p><i>Votre adresse email sera transmise à votre destinataire.</i></p>
54 54
 								<input type="submit" name="submit" value="Envoyer">

Loading…
Cancel
Save