OSDN Git Service

a76b15a91f273f34d9e54d1ad799ce8f05190973
[nucleus-jp/nucleus-jp-ancient.git] / nucleus / libs / MEMBER.php
1 <?php
2
3 /*
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5  * Copyright (C) 2002-2012 The Nucleus Group
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
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * (see nucleus/documentation/index.html#license for more info)
12  */
13 /**
14  * A class representing site members
15  *
16  * @license http://nucleuscms.org/license.txt GNU General Public License
17  * @copyright Copyright (C) 2002-2012 The Nucleus Group
18  * @version $Id$
19  * $NucleusJP: MEMBER.php,v 1.6 2006/07/17 20:03:44 kimitake Exp $
20  */
21 class MEMBER {
22
23         // 1 when authenticated, 0 when not
24         var $loggedin = 0;
25         var $password;          // not the actual password, but rather a MD5 hash
26
27         var $cookiekey;         // value that should also be in the client cookie to allow authentication
28
29         // member info
30         var $id = -1;
31         var $realname;
32         var $displayname;
33         var $email;
34         var $url;
35         var $language = '';             // name of the language file to use (e.g. 'english' -> english.php)
36         var $admin = 0;                 // (either 0 or 1)
37         var $canlogin = 0;              // (either 0 or 1)
38         var $notes;
39         var $autosave = 1;              // if the member use the autosave draft function
40
41         /**
42          * Constructor for a member object
43          */
44         function MEMBER() {
45                 // do nothing
46         }
47
48         /**
49          * Create a member object for a given displayname
50          *
51          * @static
52          */
53         function &createFromName($displayname) {
54                 $mem = new MEMBER();
55                 $mem->readFromName($displayname);
56                 return $mem;
57         }
58
59         /**
60          * Create a member object for a given ID
61          *
62          * @static
63          */
64         function &createFromID($id) {
65                 $mem = new MEMBER();
66                 $mem->readFromID($id);
67                 return $mem;
68         }
69
70         function readFromName($displayname) {
71                 return $this->read("mname='".sql_real_escape_string($displayname)."'");
72         }
73
74         function readFromID($id) {
75                 return $this->read("mnumber=" . intval($id));
76         }
77
78         /**
79           * Tries to login as a given user.
80           * Returns true when succeeded, returns false when failed
81           * 3.40 adds CustomLogin event
82           */
83         function login($login, $password) {
84                 global $manager;
85                 $this->loggedin = 0;
86                 $success = 0;
87                 $allowlocal = 1;
88                 $param = array(
89                         'login'                 => &$login,
90                         'password'              =>&$password,
91                         'success'               =>&$success,
92                         'allowlocal'    =>&$allowlocal
93                 );
94                 $manager->notify('CustomLogin', $param);
95                 if ($success && $this->readFromName($login)) {
96                         $this->loggedin = 1;
97                         return $this->isLoggedIn();
98                 } elseif (!$success && $allowlocal) {
99                         if (!$this->readFromName($login))
100                                 return 0;
101                         if (!$this->checkPassword($password))
102                                 return 0;
103                         $this->loggedin = 1;
104                         return $this->isLoggedIn();
105                 } else {
106                         return 0;
107                 }
108         }
109
110         /**
111          * Login using cookie key
112          */
113         function cookielogin($login, $cookiekey) {
114                 $this->loggedin = 0;
115                 if (!$this->readFromName($login))
116                         return 0;
117                 if (!$this->checkCookieKey($cookiekey))
118                         return 0;
119                 $this->loggedin = 1;
120                 return $this->isLoggedIn();
121         }
122
123         function logout() {
124                 $this->loggedin=0;
125         }
126
127         function isLoggedIn() {
128                 return $this->loggedin;
129         }
130
131         /**
132          * Read member information from the database
133          */
134         function read($where) {
135                 // read info
136                 $query =  'SELECT * FROM '.sql_table('member') . ' WHERE ' . $where;
137
138                 $res = sql_query($query);
139                 $obj = sql_fetch_object($res);
140
141                 $this->setRealName($obj->mrealname);
142                 $this->setEmail($obj->memail);
143                 $this->password = $obj->mpassword;
144                 $this->setCookieKey($obj->mcookiekey);
145                 $this->setURL($obj->murl);
146                 $this->setDisplayName($obj->mname);
147                 $this->setAdmin($obj->madmin);
148                 $this->id = $obj->mnumber;
149                 $this->setCanLogin($obj->mcanlogin);
150                 $this->setNotes($obj->mnotes);
151                 $this->setLanguage($obj->deflang);
152                 $this->setAutosave($obj->mautosave);
153
154                 return sql_num_rows($res);
155         }
156
157
158         /**
159           * Returns true if member is an admin for the given blog
160           * (returns false if not a team member)
161           */
162         function isBlogAdmin($blogid) {
163                 $query = 'SELECT tadmin FROM '.sql_table('team').' WHERE'
164                            . ' tblog=' . intval($blogid)
165                            . ' and tmember='. $this->getID();
166                 $res = sql_query($query);
167                 if (sql_num_rows($res) == 0)
168                         return 0;
169                 else
170                         return (sql_result($res,0,0) == 1) ;
171         }
172
173         function blogAdminRights($blogid) {
174                 return ($this->isAdmin() || $this->isBlogAdmin($blogid));
175         }
176
177
178         function teamRights($blogid) {
179                 return ($this->isAdmin() || $this->isTeamMember($blogid));
180         }
181
182         /**
183           * Returns true if this member is a team member of the given blog
184           */
185         function isTeamMember($blogid) {
186                 $query = 'SELECT * FROM '.sql_table('team').' WHERE'
187                            . ' tblog=' . intval($blogid)
188                            . ' and tmember='. $this->getID();
189                 $res = sql_query($query);
190                 return (sql_num_rows($res) != 0);
191         }
192
193         function canAddItem($catid) {
194                 global $manager;
195
196                 // if this is a 'newcat' style newcat
197                 // no blog admin of destination blog -> NOK
198                 // blog admin of destination blog -> OK
199                 if (strstr($catid,'newcat')) {
200                         // get blogid
201                         list($blogid) = sscanf($catid,"newcat-%d");
202                         return $this->blogAdminRights($blogid);
203                 }
204
205                 // category does not exist -> NOK
206                 if (!$manager->existsCategory($catid)) return 0;
207
208                 $blogid = getBlogIDFromCatID($catid);
209
210                 // no team rights for blog -> NOK
211                 if (!$this->teamRights($blogid)) return 0;
212
213                 // all other cases: OK
214                 return 1;
215         }
216
217         /**
218           * Returns true if this member can edit/delete a commentitem. This can be in the
219           * following cases:
220           *       - member is a super-admin
221           *   - member is the author of the comment
222           *   - member is admin of the blog associated with the comment
223           *   - member is author of the item associated with the comment
224           */
225         function canAlterComment($commentid) {
226                 if ($this->isAdmin()) return 1;
227
228                 $query =  'SELECT citem as itemid, iblog as blogid, cmember as cauthor, iauthor'
229                            . ' FROM '.sql_table('comment') .', '.sql_table('item').', '.sql_table('blog')
230                            . ' WHERE citem=inumber and iblog=bnumber and cnumber=' . intval($commentid);
231                 $res = sql_query($query);
232                 $obj = sql_fetch_object($res);
233
234                 return ($obj->cauthor == $this->getID()) or $this->isBlogAdmin($obj->blogid) or ($obj->iauthor == $this->getID());
235         }
236
237         /**
238           * Returns true if this member can edit/delete an item. This is true in the following
239           * cases: - member is a super-admin
240           *            - member is the author of the item
241           *        - member is admin of the the associated blog
242           */
243         function canAlterItem($itemid) {
244                 if ($this->isAdmin()) return 1;
245
246                 $query =  'SELECT iblog, iauthor FROM '.sql_table('item').' WHERE inumber=' . intval($itemid);
247                 $res = sql_query($query);
248                 $obj = sql_fetch_object($res);
249                 return ($obj->iauthor == $this->getID()) or $this->isBlogAdmin($obj->iblog);
250         }
251
252         /**
253           * Return true if member can be deleted. This means that there are no items
254           * posted by the member left
255           */
256         function canBeDeleted() {
257                 $res = sql_query('SELECT * FROM '.sql_table('item').' WHERE iauthor=' . $this->getID());
258                 return (sql_num_rows($res) == 0);
259         }
260
261         /**
262           * returns true if this member can move/update an item to a given category,
263           * false if not (see comments fot the tests that are executed)
264           *
265           * @param itemid
266           * @param newcat (can also be of form 'newcat-x' with x=blogid)
267           */
268         function canUpdateItem($itemid, $newcat) {
269                 global $manager;
270
271                 // item does not exists -> NOK
272                 if (!$manager->existsItem($itemid,1,1)) return 0;
273
274                 // cannot alter item -> NOK
275                 if (!$this->canAlterItem($itemid)) return 0;
276
277                 // if this is a 'newcat' style newcat
278                 // no blog admin of destination blog -> NOK
279                 // blog admin of destination blog -> OK
280                 if (strstr($newcat,'newcat')) {
281                         // get blogid
282                         list($blogid) = sscanf($newcat,'newcat-%d');
283                         return $this->blogAdminRights($blogid);
284                 }
285
286                 // category does not exist -> NOK
287                 if (!$manager->existsCategory($newcat)) return 0;
288
289
290                 // get item
291                 $item =& $manager->getItem($itemid,1,1);
292
293                 // old catid = new catid -> OK
294                 if ($item['catid'] == $newcat) return 1;
295
296                 // not a valid category -> NOK
297                 $validCat = quickQuery('SELECT COUNT(*) AS result FROM '.sql_table('category').' WHERE catid='.intval($newcat));
298                 if (!$validCat) return 0;
299
300                 // get destination blog
301                 $source_blogid = getBlogIDFromItemID($itemid);
302                 $dest_blogid = getBlogIDFromCatID($newcat);
303
304                 // not a team member of destination blog -> NOK
305                 if (!$this->teamRights($dest_blogid)) return 0;
306
307                 // if member is author of item -> OK
308                 if ($item['authorid'] == $this->getID()) return 1;
309
310                 // if member has admin rights on both blogs: OK
311                 if (($this->blogAdminRights($dest_blogid)) && ($this->blogAdminRights($source_blogid))) return 1;
312
313                 // all other cases: NOK
314                 return 0;
315
316         }
317
318         /**
319           * Sets the cookies for the member
320           *
321           * @param shared
322           *             set this to 1 when using a shared computer. Cookies will expire
323           *             at the end of the session in this case.
324           */
325         function setCookies($shared = 0) {
326                 global $CONF;
327
328                 if ($CONF['SessionCookie'] || $shared)
329                         $lifetime = 0;
330                 else
331                         $lifetime = (time()+2592000);
332
333                 setcookie($CONF['CookiePrefix'] .'user',$this->getDisplayName(),$lifetime,$CONF['CookiePath'],$CONF['CookieDomain'],$CONF['CookieSecure']);
334                 setcookie($CONF['CookiePrefix'] .'loginkey', $this->getCookieKey(),$lifetime,$CONF['CookiePath'],$CONF['CookieDomain'],$CONF['CookieSecure']);
335
336                 // make sure cookies on shared pcs don't get renewed
337                 if ($shared)
338                         setcookie($CONF['CookiePrefix'] .'sharedpc', '1',$lifetime,$CONF['CookiePath'],$CONF['CookieDomain'],$CONF['CookieSecure']);
339         }
340
341         function sendActivationLink($type, $extra='')
342         {
343                 global $CONF;
344                 
345                 if (!isset($CONF['ActivationDays'])) $CONF['ActivationDays'] = 2;
346                 
347                 // generate key and URL
348                 $key = $this->generateActivationEntry($type, $extra);
349                 $url = $CONF['AdminURL'] . 'index.php?action=activate&key=' . $key;
350
351                 // choose text to use in mail
352                 switch ($type)
353                 {
354                         case 'register':
355                                 $message = _ACTIVATE_REGISTER_MAIL;
356                                 $title = _ACTIVATE_REGISTER_MAILTITLE;
357                                 break;
358                         case 'forgot':
359                                 $message = _ACTIVATE_FORGOT_MAIL;
360                                 $title = _ACTIVATE_FORGOT_MAILTITLE;
361                                 break;
362                         case 'addresschange':
363                                 $message = _ACTIVATE_CHANGE_MAIL;
364                                 $title = _ACTIVATE_CHANGE_MAILTITLE;
365                                 break;
366                         default;
367                 }
368
369                 // fill out variables in text
370
371                 $aVars = array(
372                         'siteName' => $CONF['SiteName'],
373                         'siteUrl' => $CONF['IndexURL'],
374                         'memberName' => $this->getDisplayName(),
375                         'activationUrl' => $url,
376                         'activationDays' => $CONF['ActivationDays']
377                 );
378
379                 $message = TEMPLATE::fill($message, $aVars);
380                 $title = TEMPLATE::fill($title, $aVars);
381
382                 // send mail
383
384                 mb_language('ja');
385                 mb_internal_encoding(_CHARSET);
386                 @mb_send_mail($this->getEmail(), $title ,$message,'From: ' . $CONF['AdminEmail']);
387
388                 ACTIONLOG::add(INFO, _ACTIONLOG_ACTIVATIONLINK . ' (' . $this->getDisplayName() . ' / type: ' . $type . ')');
389
390
391         }
392
393         /**
394           * Returns an array of all blogids for which member has admin rights
395           */
396         function getAdminBlogs() {
397                 $blogs = array();
398
399                 if ($this->isAdmin())
400                         $query = 'SELECT bnumber as blogid from '.sql_table('blog');
401                 else
402                         $query = 'SELECT tblog as blogid from '.sql_table('team').' where tadmin=1 and tmember=' . $this->getID();
403
404                 $res = sql_query($query);
405                 if (sql_num_rows($res) > 0) {
406                         while ($obj = sql_fetch_object($res)) {
407                                 array_push($blogs, $obj->blogid);
408                         }
409                 }
410
411                 return $blogs;
412         }
413
414         /**
415           * Returns an array of all blogids for which member has team rights
416           */
417         function getTeamBlogs($incAdmin = 1) {
418                 $incAdmin = intval($incAdmin);
419                 $blogs = array();
420
421                 if ($this->isAdmin() && $incAdmin)
422                         $query = 'SELECT bnumber as blogid from '.sql_table('blog');
423                 else
424                         $query = 'SELECT tblog as blogid from '.sql_table('team').' where tmember=' . $this->getID();
425
426                 $res = sql_query($query);
427                 if (sql_num_rows($res) > 0) {
428                         while ($obj = sql_fetch_object($res)) {
429                                 array_push($blogs, $obj->blogid);
430                         }
431                 }
432
433                 return $blogs;
434         }
435
436         /**
437           * Returns an email address from which notification of commenting/karma voting can
438           * be sent. A suggestion can be given for when the member is not logged in
439           */
440         function getNotifyFromMailAddress($suggest = "") {
441                 global $CONF;
442                 if ($this->isLoggedIn()) {
443                         return $this->getDisplayName() . " <" . $this->getEmail() . ">";
444                 } else if (isValidMailAddress($suggest)) {
445                         return $suggest;
446                 } else {
447                         return $CONF['AdminEmail'];
448                 }
449         }
450
451         /**
452           * Write data to database
453           */
454         function write() {
455
456                 $query =  'UPDATE '.sql_table('member')
457                            . " SET mname='" . sql_real_escape_string($this->getDisplayName()) . "',"
458                            . "     mrealname='". sql_real_escape_string($this->getRealName()) . "',"
459                            . "     mpassword='". sql_real_escape_string($this->getPassword()) . "',"
460                            . "     mcookiekey='". sql_real_escape_string($this->getCookieKey()) . "',"
461                            . "     murl='" . sql_real_escape_string($this->getURL()) . "',"
462                            . "     memail='" . sql_real_escape_string($this->getEmail()) . "',"
463                            . "     madmin=" . $this->isAdmin() . ","
464                            . "     mnotes='" . sql_real_escape_string($this->getNotes()) . "',"
465                            . "     mcanlogin=" . $this->canLogin() . ","
466                            . "     deflang='" . sql_real_escape_string($this->getLanguage()) . "',"
467                            . "     mautosave=" . intval($this->getAutosave()) . ""
468                            . " WHERE mnumber=" . $this->getID();
469                 sql_query($query);
470         }
471
472         function checkCookieKey($key) {
473                 return (($key != '') && ($key == $this->getCookieKey()));
474         }
475
476         function checkPassword($pw) {
477                 return (md5($pw) == $this->getPassword());
478         }
479
480         function getRealName() {
481                 return $this->realname;
482         }
483
484         function setRealName($name) {
485                 $this->realname = $name;
486         }
487
488         function getEmail() {
489                 return $this->email;
490         }
491
492         function setEmail($email) {
493                 $this->email = $email;
494         }
495
496         function getPassword() {
497                 return $this->password;
498         }
499
500         function setPassword($pwd) {
501                 $this->password = md5($pwd);
502         }
503
504         function getCookieKey() {
505                 return $this->cookiekey;
506         }
507
508         /**
509           * Generate new cookiekey, save it, and return it
510           */
511         function newCookieKey() {
512                 mt_srand( (double) microtime() * 1000000);
513                 $this->cookiekey = md5(uniqid(mt_rand()));
514                 $this->write();
515                 return $this->cookiekey;
516         }
517
518         function setCookieKey($val) {
519                 $this->cookiekey = $val;
520         }
521
522         function getURL() {
523                 return $this->url;
524         }
525
526         function setURL($site) {
527                 $this->url = $site;
528         }
529
530         function getLanguage() {
531                 return $this->language;
532         }
533
534         function setLanguage($lang) {
535                 $this->language = $lang;
536         }
537
538         function setDisplayName($nick) {
539                 $this->displayname = $nick;
540         }
541
542         function getDisplayName() {
543                 return $this->displayname;
544         }
545
546         function isAdmin() {
547                 return $this->admin;
548         }
549
550         function setAdmin($val) {
551                 $this->admin = $val;
552         }
553
554         function canLogin() {
555                 return $this->canlogin;
556         }
557
558         function setCanLogin($val) {
559                 $this->canlogin = $val;
560         }
561
562         function getNotes() {
563                 return $this->notes;
564         }
565
566         function setNotes($val) {
567                 $this->notes = $val;
568         }
569
570         function getAutosave() {
571                 return $this->autosave;
572         }
573
574         function setAutosave($val) {
575                 $this->autosave = $val;
576         }
577
578         function getID() {
579                 return $this->id;
580         }
581
582         /**
583          * Returns true if there is a member with the given login name
584          *
585          * @static
586          */
587         function exists($name) {
588                 $r = sql_query('select * FROM '.sql_table('member')." WHERE mname='".sql_real_escape_string($name)."'");
589                 return (sql_num_rows($r) != 0);
590         }
591
592         /**
593          * Returns true if there is a member with the given ID
594          *
595          * @static
596          */
597         function existsID($id) {
598                 $r = sql_query('select * FROM '.sql_table('member')." WHERE mnumber='".intval($id)."'");
599                 return (sql_num_rows($r) != 0);
600         }
601
602         /**
603          *  Checks if a username is protected.
604          *  If so, it can not be used on anonymous comments
605          */
606         function isNameProtected($name) {
607
608                 // extract name
609                 $name = strip_tags($name);
610                 $name = trim($name);
611
612                 return MEMBER::exists($name);
613         }
614
615         /**
616          * Adds a new member
617          *
618          * @static
619          */
620         function create($name, $realname, $password, $email, $url, $admin, $canlogin, $notes) {
621                 if (!isValidMailAddress($email))
622                 {
623                         return _ERROR_BADMAILADDRESS;
624                 }
625                 if (!isValidDisplayName($name))
626                 {
627                         return _ERROR_BADNAME;
628                 }
629                 if (MEMBER::exists($name))
630                 {
631                         return _ERROR_NICKNAMEINUSE;
632                 }
633                 if (!$realname)
634                 {
635                         return _ERROR_REALNAMEMISSING;
636                 }
637                 if (!$password)
638                 {
639                         return _ERROR_PASSWORDMISSING;
640                 }
641                 
642                 # replaced eregi() below with preg_match(). ereg* functions are deprecated in PHP 5.3.0
643                 # original eregi: !eregi("^https?://", $url)
644                 // begin if: sometimes user didn't prefix the URL with http:// or https://, this cause a malformed URL. Let's fix it.
645                 if (!preg_match('#^https?://#', $url) )
646                 {
647                         $url = 'http://' . $url;
648                 } // end if
649                 
650                 $name = sql_real_escape_string($name);
651                 $realname = sql_real_escape_string($realname);
652                 $password = sql_real_escape_string(md5($password));
653                 $email = sql_real_escape_string($email);
654                 $url = sql_real_escape_string($url);
655                 $admin = intval($admin);
656                 $canlogin = intval($canlogin);
657                 $notes = sql_real_escape_string($notes);
658                 
659                 if (($admin) && !($canlogin)) {
660                         return _ERROR;
661                 }
662                 
663                 $query = 'INSERT INTO '.sql_table('member')." (MNAME,MREALNAME,MPASSWORD,MEMAIL,MURL, MADMIN, MCANLOGIN, MNOTES) "
664                            . "VALUES ('$name','$realname','$password','$email','$url',$admin, $canlogin, '$notes')";
665                 sql_query($query);
666
667                 ACTIONLOG::add(INFO, _ACTIONLOG_NEWMEMBER . ' ' . $name);
668
669                 return 1;
670         }
671
672         /**
673          * Returns activation info for a certain key (an object with properties vkey, vmember, ...)
674          * (static)
675          *
676          * @author karma
677          */
678         function getActivationInfo($key)
679         {
680                 $query = 'SELECT * FROM ' . sql_table('activation') . ' WHERE vkey=\'' . sql_real_escape_string($key). '\'';
681                 $res = sql_query($query);
682
683                 if (!$res || (sql_num_rows($res) == 0))
684                         return 0;
685                 else
686                         return sql_fetch_object($res);
687         }
688
689         /**
690          * Creates an account activation key
691          *
692          * @param $type one of the following values (determines what to do when activation expires)
693          *                'register' (new member registration)
694          *                'forgot' (forgotton password)
695          *                'addresschange' (member address has changed)
696          * @param $extra extra info (needed when validation link expires)
697          *                                addresschange -> old email address
698          * @author dekarma
699          */
700         function generateActivationEntry($type, $extra = '')
701         {
702                 // clean up old entries
703                 $this->cleanupActivationTable();
704
705                 // kill any existing entries for the current member (delete is ok)
706                 // (only one outstanding activation key can be present for a member)
707                 sql_query('DELETE FROM ' . sql_table('activation') . ' WHERE vmember=' . intval($this->getID()));
708
709                 $canLoginWhileActive = false; // indicates if the member can log in while the link is active
710                 switch ($type)
711                 {
712                         case 'forgot':
713                                 $canLoginWhileActive = true;
714                                 break;
715                         case 'register':
716                                 break;
717                         case 'addresschange':
718                                 $extra = $extra . '/' . ($this->canLogin() ? '1' : '0');
719                                 break;
720                 }
721
722                 $ok = false;
723                 while (!$ok)
724                 {
725                         // generate a random key
726                         srand((double)microtime()*1000000);
727                         $key = md5(uniqid(rand(), true));
728
729                         // attempt to add entry in database
730                         // add in database as non-active
731                         $query = 'INSERT INTO ' . sql_table('activation'). ' (vkey, vtime, vmember, vtype, vextra) ';
732                         $query .= 'VALUES (\'' . sql_real_escape_string($key). '\', \'' . date('Y-m-d H:i:s',time()) . '\', \'' . intval($this->getID()). '\', \'' . sql_real_escape_string($type). '\', \'' . sql_real_escape_string($extra). '\')';
733                         if (sql_query($query))
734                                 $ok = true;
735                 }
736
737                 // mark member as not allowed to log in
738                 if (!$canLoginWhileActive)
739                 {
740                         $this->setCanLogin(0);
741                         $this->write();
742                 }
743
744                 // return the key
745                 return $key;
746         }
747
748         /**
749          * Inidicates that an activation link has been clicked and any forms displayed
750          * there have been successfully filled out.
751          * @author dekarma
752          */
753         function activate($key)
754         {
755                 // get activate info
756                 $info = MEMBER::getActivationInfo($key);
757
758                 // no active key
759                 if (!$info)
760                         return false;
761
762                 switch ($info->vtype)
763                 {
764                         case 'forgot':
765                                 // nothing to do
766                                 break;
767                         case 'register':
768                                 // set canlogin value
769                                 global $CONF;
770                                 sql_query('UPDATE ' . sql_table('member') . ' SET mcanlogin=' . intval($CONF['NewMemberCanLogon']). ' WHERE mnumber=' . intval($info->vmember));
771                                 break;
772                         case 'addresschange':
773                                 // reset old 'canlogin' value
774                                 list($oldEmail, $oldCanLogin) = explode('/', $info->vextra);
775                                 sql_query('UPDATE ' . sql_table('member') . ' SET mcanlogin=' . intval($oldCanLogin). ' WHERE mnumber=' . intval($info->vmember));
776                                 break;
777                 }
778
779                 // delete from activation table
780                 sql_query('DELETE FROM ' . sql_table('activation') . ' WHERE vkey=\'' . sql_real_escape_string($key) . '\'');
781
782                 // success!
783                 return true;
784         }
785
786         /**
787          * Cleans up entries in the activation table. All entries older than 2 days are removed.
788          * (static)
789          *
790          * @author dekarma
791          */
792         function cleanupActivationTable()
793         {
794                 $actdays = 2;
795                 if (isset($CONF['ActivationDays']) && intval($CONF['ActivationDays']) > 0) {
796                     $actdays = intval($CONF['ActivationDays']);
797                 }
798                 else {
799                         $CONF['ActivationDays'] = 2;
800                 }
801                 $boundary = time() - (60 * 60 * 24 * $actdays);
802
803                 // 1. walk over all entries, and see if special actions need to be performed
804                 $res = sql_query('SELECT * FROM ' . sql_table('activation') . ' WHERE vtime < \'' . date('Y-m-d H:i:s',$boundary) . '\'');
805
806                 while ($o = sql_fetch_object($res))
807                 {
808                         switch ($o->vtype)
809                         {
810                                 case 'register':
811                                         // delete all information about this site member. registration is undone because there was
812                                         // no timely activation
813                                         include_once($DIR_LIBS . 'ADMIN.php');
814                                         ADMIN::deleteOneMember(intval($o->vmember));
815                                         break;
816                                 case 'addresschange':
817                                         // revert the e-mail address of the member back to old address
818                                         list($oldEmail, $oldCanLogin) = explode('/', $o->vextra);
819                                         sql_query('UPDATE ' . sql_table('member') . ' SET mcanlogin=' . intval($oldCanLogin). ', memail=\'' . sql_real_escape_string($oldEmail). '\' WHERE mnumber=' . intval($o->vmember));
820                                         break;
821                                 case 'forgot':
822                                         // delete the activation link and ignore. member can request a new password using the
823                                         // forgot password link
824                                         break;
825                         }
826                 }
827
828                 // 2. delete activation entries for real
829                 sql_query('DELETE FROM ' . sql_table('activation') . ' WHERE vtime < \'' . date('Y-m-d H:i:s',$boundary) . '\'');
830         }
831
832 }
833
834 ?>