| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | $Id: m_mem.php,v 1.19 2006/01/12 08:04:43 anarcat Exp $ |
|---|
| 4 | ---------------------------------------------------------------------- |
|---|
| 5 | LICENSE |
|---|
| 6 | |
|---|
| 7 | This program is free software; you can redistribute it and/or |
|---|
| 8 | modify it under the terms of the GNU General Public License (GPL) |
|---|
| 9 | as published by the Free Software Foundation; either version 2 |
|---|
| 10 | of the License, or (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | This program is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | To read the license please visit http://www.gnu.org/copyleft/gpl.html |
|---|
| 18 | ---------------------------------------------------------------------- |
|---|
| 19 | Original Author of file: Benjamin Sonntag |
|---|
| 20 | Purpose of file: Manage Login session on the virtual desktop and |
|---|
| 21 | member parameters |
|---|
| 22 | ---------------------------------------------------------------------- |
|---|
| 23 | */ |
|---|
| 24 | /** |
|---|
| 25 | * This class manage user sessions in the web desktop. |
|---|
| 26 | * |
|---|
| 27 | * This class manage user sessions and administration in AlternC. |
|---|
| 28 | * @copyright AlternC-Team 2002-2005 http://alternc.org/ |
|---|
| 29 | * |
|---|
| 30 | */ |
|---|
| 31 | class m_mem { |
|---|
| 32 | |
|---|
| 33 | /** Original uid for the temporary uid swapping (for administrators) */ |
|---|
| 34 | var $olduid=0; |
|---|
| 35 | |
|---|
| 36 | /** This array contains the Tableau contenant les champs de la table "membres" du membre courant |
|---|
| 37 | * Ce tableau est utilisable globalement par toutes les classes filles. |
|---|
| 38 | */ |
|---|
| 39 | var $user; |
|---|
| 40 | /** Tableau contenant les champs de la table "local" du membre courant |
|---|
| 41 | * Ce tableau est utilisable globalement par toutes les classes filles. |
|---|
| 42 | * Note : les champs de "local" sont spécifiques à l'hébergeur. |
|---|
| 43 | */ |
|---|
| 44 | var $local; |
|---|
| 45 | |
|---|
| 46 | /* ----------------------------------------------------------------- */ |
|---|
| 47 | /** |
|---|
| 48 | * Constructeur |
|---|
| 49 | */ |
|---|
| 50 | function m_mem() { |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | /* ----------------------------------------------------------------- */ |
|---|
| 54 | /** Check that the current user is an admnistrator. |
|---|
| 55 | * @return boolean TRUE if we are super user, or FALSE if we are not. |
|---|
| 56 | */ |
|---|
| 57 | function checkright() { |
|---|
| 58 | return ($this->user["su"]=="1"); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /* ----------------------------------------------------------------- */ |
|---|
| 62 | /** Start a session in the web desktop. Check username and password. |
|---|
| 63 | * <b>Note : </b>If the user entered a bas password, the failure will be logged |
|---|
| 64 | * and told to the corresponding user on next successfull login. |
|---|
| 65 | * @param $username string Username that want to get connected. |
|---|
| 66 | * @param $password string User Password. |
|---|
| 67 | * @return boolean TRUE if the user has been successfully connected, or FALSE if an error occured. |
|---|
| 68 | */ |
|---|
| 69 | function login($username,$password,$restrictip=0) { |
|---|
| 70 | global $db,$session,$err,$cuid; |
|---|
| 71 | $err->log("mem","login",$username); |
|---|
| 72 | // $username=addslashes($username); |
|---|
| 73 | // $password=addslashes($password); |
|---|
| 74 | $password=stripslashes($password); |
|---|
| 75 | $db->query("select * from membres where login='$username';"); |
|---|
| 76 | if ($db->num_rows()==0) { |
|---|
| 77 | $err->raise("mem",1); |
|---|
| 78 | return false; |
|---|
| 79 | } |
|---|
| 80 | $db->next_record(); |
|---|
| 81 | if (_md5cr($password,$db->f("pass"))!=$db->f("pass")) { |
|---|
| 82 | $db->query("UPDATE membres SET lastfail=lastfail+1 WHERE uid='".$db->f("uid")."';"); |
|---|
| 83 | $err->raise("mem",1); |
|---|
| 84 | return false; |
|---|
| 85 | } |
|---|
| 86 | if (!$db->f("enabled")) { |
|---|
| 87 | $err->raise("mem",2); |
|---|
| 88 | return false; |
|---|
| 89 | } |
|---|
| 90 | $this->user=$db->Record; |
|---|
| 91 | $cuid=$db->f("uid"); |
|---|
| 92 | if ($restrictip) { |
|---|
| 93 | $ip="INET_ATON('".getenv("REMOTE_ADDR")."')"; |
|---|
| 94 | } else $ip="0"; |
|---|
| 95 | /* Close sessions that are more than 2 days old. */ |
|---|
| 96 | $db->query("DELETE FROM sessions WHERE DATE_ADD(ts,INTERVAL 2 DAY)<NOW();"); |
|---|
| 97 | /* Open the session : */ |
|---|
| 98 | $session=md5(uniqid(mt_rand())); |
|---|
| 99 | $db->query("insert into sessions (sid,ip,uid) values ('$session',$ip,'$cuid');"); |
|---|
| 100 | setcookie("session",$session,0,"/"); |
|---|
| 101 | $err->error=0; |
|---|
| 102 | /* Fill in $local */ |
|---|
| 103 | $db->query("SELECT * FROM local WHERE uid='$cuid';"); |
|---|
| 104 | if ($db->num_rows()) { |
|---|
| 105 | $db->next_record(); |
|---|
| 106 | $this->local=$db->Record; |
|---|
| 107 | } |
|---|
| 108 | return true; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /* ----------------------------------------------------------------- */ |
|---|
| 112 | /** Start a session as another user from an administrator account. |
|---|
| 113 | * This function is not the same as su. setid connect the current user in the destination |
|---|
| 114 | * account (for good), and su allow any user to become another account for some commands only. |
|---|
| 115 | * (del_user, add_user ...) and allow to bring back admin rights with unsu |
|---|
| 116 | * |
|---|
| 117 | * @param $id integer User id where we will connect to. |
|---|
| 118 | * @return boolean TRUE if the user has been successfully connected, FALSE else. |
|---|
| 119 | */ |
|---|
| 120 | function setid($id) { |
|---|
| 121 | global $db,$session,$err,$cuid; |
|---|
| 122 | $err->log("mem","setid",$username); |
|---|
| 123 | $db->query("select * from membres where uid='$id';"); |
|---|
| 124 | if ($db->num_rows()==0) { |
|---|
| 125 | $err->raise("mem",1); |
|---|
| 126 | return false; |
|---|
| 127 | } |
|---|
| 128 | $db->next_record(); |
|---|
| 129 | $this->user=$db->Record; |
|---|
| 130 | $cuid=$db->f("uid"); |
|---|
| 131 | $ip=getenv("REMOTE_ADDR"); |
|---|
| 132 | $session=md5(uniqid(mt_rand())); |
|---|
| 133 | $db->query("insert into sessions (sid,ip,uid) values ('$session',INET_ATON('$ip'),'$cuid');"); |
|---|
| 134 | setcookie("session",$session,0,"/"); |
|---|
| 135 | $err->error=0; |
|---|
| 136 | /* Fill in $local */ |
|---|
| 137 | $db->query("SELECT * FROM local WHERE uid='$cuid';"); |
|---|
| 138 | if ($db->num_rows()) { |
|---|
| 139 | $db->next_record(); |
|---|
| 140 | $this->local=$db->Record; |
|---|
| 141 | } |
|---|
| 142 | return true; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | /* ----------------------------------------------------------------- */ |
|---|
| 146 | /** Suite à la connexion de l'utilisateur, réinitialise ses paramètres de dernière connexion |
|---|
| 147 | */ |
|---|
| 148 | function resetlast() { |
|---|
| 149 | global $db,$cuid; |
|---|
| 150 | $ip=addslashes(getenv("REMOTE_HOST")); |
|---|
| 151 | if (!$ip) $ip=addslashes(getenv("REMOTE_ADDR")); |
|---|
| 152 | $db->query("UPDATE membres SET lastlogin=NOW(), lastfail=0, lastip='$ip' WHERE uid='$cuid';"); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| 155 | /* ----------------------------------------------------------------- */ |
|---|
| 156 | /** Vérifie que la session courante est correcte (cookie ok et ip valide). |
|---|
| 157 | * Si besoin, et si réception des champs username & password, crée une nouvelle |
|---|
| 158 | * session pour l'utilisateur annoncé. |
|---|
| 159 | * Cette fonction doit être appellée à chaque page devant être authentifiée. |
|---|
| 160 | * et AVANT d'émettre des données. (un cookie peut être envoyé) |
|---|
| 161 | * @global string $session Le cookie de session eventuel |
|---|
| 162 | * @global string $username/password le login/pass de l'utilisateur |
|---|
| 163 | * @return TRUE si la session est correcte, FALSE sinon. |
|---|
| 164 | */ |
|---|
| 165 | function checkid() { |
|---|
| 166 | global $db,$err,$session,$username,$password,$cuid,$restrictip; |
|---|
| 167 | if ($username && $password) { |
|---|
| 168 | return $this->login($username,$password,$restrictip); |
|---|
| 169 | } |
|---|
| 170 | $session=addslashes($session); |
|---|
| 171 | if (strlen($session)!=32) { |
|---|
| 172 | $err->raise("mem",3); |
|---|
| 173 | return false; |
|---|
| 174 | } |
|---|
| 175 | $ip=getenv("REMOTE_ADDR"); |
|---|
| 176 | $db->query("select uid,INET_ATON('$ip') as me,ip from sessions where sid='$session'"); |
|---|
| 177 | if ($db->num_rows()==0) { |
|---|
| 178 | $err->raise("mem",4); |
|---|
| 179 | return false; |
|---|
| 180 | } |
|---|
| 181 | $db->next_record(); |
|---|
| 182 | if ($db->f("ip")) { |
|---|
| 183 | if ($db->f("me")!=$db->f("ip")) { |
|---|
| 184 | $err->raise("mem",5); |
|---|
| 185 | return false; |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | $cuid=$db->f("uid"); |
|---|
| 189 | $db->query("select * from membres where uid='$cuid';"); |
|---|
| 190 | $db->next_record(); |
|---|
| 191 | $this->user=$db->Record; |
|---|
| 192 | $err->error=0; |
|---|
| 193 | /* Remplissage de $local */ |
|---|
| 194 | $db->query("SELECT * FROM local WHERE uid='$cuid';"); |
|---|
| 195 | if ($db->num_rows()) { |
|---|
| 196 | $db->next_record(); |
|---|
| 197 | $this->local=$db->Record; |
|---|
| 198 | } |
|---|
| 199 | return true; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | /* ----------------------------------------------------------------- */ |
|---|
| 203 | /** Change l'identité d'un utilisateur temporairement. |
|---|
| 204 | * @global string $uid Utilisateur dont on prends l'identité |
|---|
| 205 | * @return TRUE si la session est correcte, FALSE sinon. |
|---|
| 206 | */ |
|---|
| 207 | function su($uid) { |
|---|
| 208 | global $cuid,$db,$err; |
|---|
| 209 | if (!$this->olduid) |
|---|
| 210 | $this->olduid=$cuid; |
|---|
| 211 | $db->query("select * from membres where uid='$uid';"); |
|---|
| 212 | if ($db->num_rows()==0) { |
|---|
| 213 | $err->raise("mem",1); |
|---|
| 214 | return false; |
|---|
| 215 | } |
|---|
| 216 | $db->next_record(); |
|---|
| 217 | $this->user=$db->Record; |
|---|
| 218 | $cuid=$db->f("uid"); |
|---|
| 219 | return true; |
|---|
| 220 | } |
|---|
| 221 | |
|---|
| 222 | /* ----------------------------------------------------------------- */ |
|---|
| 223 | /** Retourne a l'identite d'origine de l'utilisateur apres su. |
|---|
| 224 | * @return TRUE si la session est correcte, FALSE sinon. |
|---|
| 225 | */ |
|---|
| 226 | function unsu() { |
|---|
| 227 | global $cuid; |
|---|
| 228 | if (!$this->olduid) |
|---|
| 229 | return false; |
|---|
| 230 | $this->su($this->olduid); |
|---|
| 231 | $this->olduid=0; |
|---|
| 232 | return true; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | /* ----------------------------------------------------------------- */ |
|---|
| 237 | /** Termine une session du bureau virtuel (logout) |
|---|
| 238 | * @return boolean TRUE si la session a bien été détruite, FALSE sinon. |
|---|
| 239 | */ |
|---|
| 240 | function del_session() { |
|---|
| 241 | global $db,$session,$user,$err,$cuid; |
|---|
| 242 | $err->log("mem","del_session"); |
|---|
| 243 | $session=addslashes($session); |
|---|
| 244 | setcookie("session","",0,"/"); |
|---|
| 245 | if ($session=="") { |
|---|
| 246 | $err->error=0; |
|---|
| 247 | return true; |
|---|
| 248 | } |
|---|
| 249 | if (strlen($session)!=32) { |
|---|
| 250 | $err->raise("mem",3); |
|---|
| 251 | return false; |
|---|
| 252 | } |
|---|
| 253 | $ip=getenv("REMOTE_ADDR"); |
|---|
| 254 | $db->query("select uid,INET_ATON('$ip') as me,ip from sessions where sid='$session'"); |
|---|
| 255 | if ($db->num_rows()==0) { |
|---|
| 256 | $err->raise("mem",4); |
|---|
| 257 | return false; |
|---|
| 258 | } |
|---|
| 259 | $db->next_record(); |
|---|
| 260 | if ($db->f("me")!=$db->f("ip")) { |
|---|
| 261 | $err->raise("mem",5); |
|---|
| 262 | return false; |
|---|
| 263 | } |
|---|
| 264 | $cuid=$db->f("uid"); |
|---|
| 265 | $db->query("delete from sessions where sid='$session';"); |
|---|
| 266 | $err->error=0; |
|---|
| 267 | return true; |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | /* ----------------------------------------------------------------- */ |
|---|
| 271 | /** Change le mot de passe de l'utilisateur courant. |
|---|
| 272 | * @param string $oldpass Ancien mot de passe. |
|---|
| 273 | * @param string $newpass Nouveau mot de passe |
|---|
| 274 | * @param string $newpass2 Nouveau mot de passe (à nouveau) |
|---|
| 275 | * @return boolean TRUE si le mot de passe a été changé, FALSE sinon. |
|---|
| 276 | */ |
|---|
| 277 | function passwd($oldpass,$newpass,$newpass2) { |
|---|
| 278 | global $db,$err,$cuid; |
|---|
| 279 | $err->log("mem","passwd"); |
|---|
| 280 | $oldpass=stripslashes($oldpass); |
|---|
| 281 | $newpass=stripslashes($newpass); |
|---|
| 282 | $newpass2=stripslashes($newpass2); |
|---|
| 283 | if (!$this->user["canpass"]) { |
|---|
| 284 | $err->raise("mem",11); |
|---|
| 285 | return false; |
|---|
| 286 | } |
|---|
| 287 | if ($this->user["pass"]!=_md5cr($oldpass,$this->user["pass"])) { |
|---|
| 288 | $err->raise("mem",6); |
|---|
| 289 | return false; |
|---|
| 290 | } |
|---|
| 291 | if ($newpass!=$newpass2) { |
|---|
| 292 | $err->raise("mem",7); |
|---|
| 293 | return false; |
|---|
| 294 | } |
|---|
| 295 | if (strlen($newpass)<3) { |
|---|
| 296 | $err->raise("mem",8); |
|---|
| 297 | return false; |
|---|
| 298 | } |
|---|
| 299 | $newpass=_md5cr($newpass); |
|---|
| 300 | $db->query("UPDATE membres SET pass='$newpass' WHERE uid='$cuid';"); |
|---|
| 301 | $err->error=0; |
|---|
| 302 | return true; |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | /* ----------------------------------------------------------------- */ |
|---|
| 306 | /** Change les préférences administrateur d'un compte |
|---|
| 307 | * @param integer $admlist Mode de visualisation des membres (0=large 1=courte) |
|---|
| 308 | * @return boolean TRUE si les préférences ont été changées, FALSE sinon. |
|---|
| 309 | */ |
|---|
| 310 | function adminpref($admlist) { |
|---|
| 311 | global $db,$err,$cuid; |
|---|
| 312 | $err->log("mem","admlist"); |
|---|
| 313 | if (!$this->user["su"]) { |
|---|
| 314 | $err->raise("mem",12); |
|---|
| 315 | return false; |
|---|
| 316 | } |
|---|
| 317 | $db->query("UPDATE membres SET admlist='$admlist' WHERE uid='$cuid';"); |
|---|
| 318 | $err->error=0; |
|---|
| 319 | return true; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | /* ----------------------------------------------------------------- */ |
|---|
| 323 | /** Envoie en mail le mot de passe d'un compte. |
|---|
| 324 | * <b>Note : </b>On ne peut demander le mot de passe qu'une seule fois par jour. |
|---|
| 325 | * TODO : Translate this mail into the localization program. |
|---|
| 326 | * TODO : Check this function's ! |
|---|
| 327 | * @return boolean TRUE si le mot de passe a été envoyé avec succès, FALSE sinon. |
|---|
| 328 | */ |
|---|
| 329 | function send_pass($login) { |
|---|
| 330 | global $err,$db,$L_HOSTING,$L_FQDN; |
|---|
| 331 | $err->log("mem","send_pass"); |
|---|
| 332 | $db->query("SELECT * FROM membres WHERE login='$login';"); |
|---|
| 333 | if (!$db->num_rows()) { |
|---|
| 334 | $err->raise("mem",2); |
|---|
| 335 | return false; |
|---|
| 336 | } |
|---|
| 337 | $db->next_record(); |
|---|
| 338 | if (time()-$db->f("lastaskpass")<86400) { |
|---|
| 339 | $err->raise("mem",7); |
|---|
| 340 | return false; |
|---|
| 341 | } |
|---|
| 342 | $txt="Bonjour, |
|---|
| 343 | Il semblerait que vous ayez demandé à recevoir le mot de passe du |
|---|
| 344 | compte ".$login." sur $L_HOSTING |
|---|
| 345 | Voici donc le nom d'utilisateur et le mot de passe qui vous |
|---|
| 346 | permettront de rentrer sur le bureau virtuel : |
|---|
| 347 | |
|---|
| 348 | -------------------------------------- |
|---|
| 349 | |
|---|
| 350 | Nom d'utilisateur : ".$db->f("login")." |
|---|
| 351 | |
|---|
| 352 | Mot de passe : ".$db->f("pass")." |
|---|
| 353 | |
|---|
| 354 | -------------------------------------- |
|---|
| 355 | |
|---|
| 356 | Note : si vous n'avez pas fait cette demande, cela signifie que |
|---|
| 357 | quelqu'un l'a faite pour vous. Vous pouvez donc ignorer ce message. |
|---|
| 358 | Si cela se reproduit, n'hésitez pas à contacter l'administrateur |
|---|
| 359 | de votre serveur. |
|---|
| 360 | |
|---|
| 361 | Cordialement. |
|---|
| 362 | "; |
|---|
| 363 | mail($db->f("mail"),"Votre mot de passe sur $L_HOSTING",$txt,"From: root@$L_FQDN\nReply-to: root@$L_FQDN"); |
|---|
| 364 | $db->query("UPDATE membres SET lastaskpass=".time()." WHERE login='$login';"); |
|---|
| 365 | return true; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | /* ----------------------------------------------------------------- */ |
|---|
| 369 | /** Change le mail d'un membre (première etape, envoi du CookiE) |
|---|
| 370 | * TODO : insert this mail string into the localization system |
|---|
| 371 | * @param string $newmail Nouveau mail souhaité pour le membre. |
|---|
| 372 | * @return string le cookie si le mail a bien été envoyé, FALSE sinon |
|---|
| 373 | */ |
|---|
| 374 | function ChangeMail1($newmail) { |
|---|
| 375 | global $err,$db,$L_HOSTING,$L_FQDN,$cuid; |
|---|
| 376 | $err->log("mem","changemail1",$newmail); |
|---|
| 377 | $db->query("SELECT * FROM membres WHERE uid='$cuid';"); |
|---|
| 378 | if (!$db->num_rows()) { |
|---|
| 379 | $err->raise("mem",2); |
|---|
| 380 | return false; |
|---|
| 381 | } |
|---|
| 382 | $db->next_record(); |
|---|
| 383 | |
|---|
| 384 | // un cookie de 20 caractères pour le mail |
|---|
| 385 | $COOKIE=substr(md5(uniqid(rand(),1)),0,20); |
|---|
| 386 | // et de 6 pour la clé à entrer. ca me semble suffisant... |
|---|
| 387 | $KEY=substr(md5(uniqid(rand(),1)),0,6); |
|---|
| 388 | // TODO : Translate this and insert this in alternc.po |
|---|
| 389 | $txt="Bonjour, |
|---|
| 390 | Quelqu'un (peut-etre vous) a demandé le changement de l'email du compte |
|---|
| 391 | ".$db->f("login")." sur $L_HOSTING |
|---|
| 392 | Afin de confirmer que cet email est valide, merci de vous rendre à l'adresse |
|---|
| 393 | ci-dessous : |
|---|
| 394 | |
|---|
| 395 | https://$L_FQDN/admin/mem_cm.php?usr=$cuid&cookie=$COOKIE |
|---|
| 396 | |
|---|
| 397 | (attention : si cette adresse est coupée sur 2 lignes, ne pas oublier de |
|---|
| 398 | reconstituer sur une seule ligne). Le bureau vous demandera la clé qui vous |
|---|
| 399 | a été donnée lors de la demande de changement d'email. |
|---|
| 400 | |
|---|
| 401 | Note : si vous n'avez pas fait cette demande, cela signifie que quelqu'un |
|---|
| 402 | l'a faite pour vous. Vous pouvez donc ignorer ce message. Si cela se |
|---|
| 403 | reproduit, n'hésitez pas à contacter l'administrateur de votre serveur. |
|---|
| 404 | |
|---|
| 405 | Cordialement. |
|---|
| 406 | "; |
|---|
| 407 | mail($newmail,"Changement d'email sur $L_HOSTING",$txt,"From: root@$L_FQDN\nReply-to: root@$L_FQDN"); |
|---|
| 408 | // Supprime les demandes précédentes de ce compte ! |
|---|
| 409 | $db->query("DELETE FROM chgmail WHERE uid='$cuid';"); |
|---|
| 410 | $db->query("INSERT INTO chgmail (cookie,ckey,uid,mail,ts) VALUES ('$COOKIE','$KEY','$cuid','$newmail',".time().");"); |
|---|
| 411 | // Supprime les cookies de la veille :) |
|---|
| 412 | $lts=time()-86400; |
|---|
| 413 | $db->query("DELETE FROM chgmail WHERE ts<'$lts';"); |
|---|
| 414 | return $KEY; |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | /* ----------------------------------------------------------------- */ |
|---|
| 418 | /** Change le mail d'un membre (seconde etape, CookiE+clé = application) |
|---|
| 419 | * @param string $COOKIE Cookie envoyé par mail |
|---|
| 420 | * @param string $KEY clé affichée à l'écran |
|---|
| 421 | * @param integer $uid Utilisateur concerné (on est hors session) |
|---|
| 422 | * @return TRUE si le mail a bien été modifié, FALSE sinon |
|---|
| 423 | */ |
|---|
| 424 | function ChangeMail2($COOKIE,$KEY,$uid) { |
|---|
| 425 | global $err,$db,$L_HOSTING,$L_FQDN; |
|---|
| 426 | $err->log("mem","changemail2",$uid); |
|---|
| 427 | $db->query("SELECT * FROM chgmail WHERE cookie='$COOKIE' and ckey='$KEY' and uid='$uid';"); |
|---|
| 428 | if (!$db->num_rows()) { |
|---|
| 429 | $err->raise("mem",9); |
|---|
| 430 | return false; |
|---|
| 431 | } |
|---|
| 432 | $db->next_record(); |
|---|
| 433 | |
|---|
| 434 | // met à jour le compte : |
|---|
| 435 | $db->query("UPDATE membres SET mail='".$db->f("mail")."' WHERE uid='$uid';"); |
|---|
| 436 | |
|---|
| 437 | $db->query("DELETE FROM chgmail WHERE uid='$uid';"); |
|---|
| 438 | // Supprime les cookies de la veille :) |
|---|
| 439 | $lts=time()-86400; |
|---|
| 440 | $db->query("DELETE FROM chgmail WHERE ts<'$lts';"); |
|---|
| 441 | return true; |
|---|
| 442 | } |
|---|
| 443 | |
|---|
| 444 | /* ----------------------------------------------------------------- */ |
|---|
| 445 | /** Modifie le paramètre d'aide en ligne (1/0) |
|---|
| 446 | * @param integer $show Faut-il (1) ou non (0) afficher l'aide en ligne |
|---|
| 447 | */ |
|---|
| 448 | function set_help_param($show) { |
|---|
| 449 | global $db,$err,$cuid; |
|---|
| 450 | $err->log("mem","set_help_param",$show); |
|---|
| 451 | $db->query("UPDATE membres SET show_help='$show' WHERE uid='$cuid';"); |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | /* ----------------------------------------------------------------- */ |
|---|
| 455 | /** Dit si l'aide en ligne est demandée |
|---|
| 456 | * @return boolean TRUE si l'aide en ligne est demandée, FALSE sinon. |
|---|
| 457 | */ |
|---|
| 458 | function get_help_param() { |
|---|
| 459 | return $this->user["show_help"]; |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | /* ----------------------------------------------------------------- */ |
|---|
| 463 | /** Affiche (echo) l'aide contextuelle |
|---|
| 464 | * @param integer $file Numéro de fichier d'aide à afficher. |
|---|
| 465 | * @return TRUE si l'aide contextuelle a été trouvée, FALSE sinon |
|---|
| 466 | */ |
|---|
| 467 | function show_help($file) { |
|---|
| 468 | global $err; |
|---|
| 469 | $err->log("mem","show_help",$show); |
|---|
| 470 | if ($this->user["show_help"]) { |
|---|
| 471 | $hlp=_("hlp_$file"); |
|---|
| 472 | if ($hlp!="hlp_$file") { |
|---|
| 473 | $hlp=ereg_replace( |
|---|
| 474 | "HELPID_([0-9]*)", |
|---|
| 475 | "<a href=\"javascript:help(\\1);\"><img src=\"/admin/aide/help.png\" width=\"17\" height=\"17\" style=\"vertical-align: middle;\" alt=\""._("Help")."\" /></a>",$hlp); |
|---|
| 476 | echo "<p class=\"hlp\">".$hlp."</p>"; |
|---|
| 477 | return true; |
|---|
| 478 | } |
|---|
| 479 | return false; |
|---|
| 480 | } else { |
|---|
| 481 | return true; |
|---|
| 482 | } |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | /* ----------------------------------------------------------------- */ |
|---|
| 487 | /** |
|---|
| 488 | * Exports all the personnal user related information for an account. |
|---|
| 489 | * @access private |
|---|
| 490 | * EXPERIMENTAL 'sid' function ;) |
|---|
| 491 | */ |
|---|
| 492 | function alternc_export($tmpdir) { |
|---|
| 493 | global $db,$err; |
|---|
| 494 | $err->log("mem","export"); |
|---|
| 495 | $str="<mem>\n"; |
|---|
| 496 | |
|---|
| 497 | foreach ($this->user as $k=>$v) { |
|---|
| 498 | $str.=" <$k>".xml_entities($v)."</$k>\n"; |
|---|
| 499 | } |
|---|
| 500 | $str.="</mem>\n"; |
|---|
| 501 | return $str; |
|---|
| 502 | } |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | } /* Classe Membre */ |
|---|
| 508 | |
|---|
| 509 | ?> |
|---|