OSDN Git Service

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