OSDN Git Service

本家版の言語エントリーに合わせてエントリーの順序を変更
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / MEMBER.php
1 <?php
2
3 /*
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5  * Copyright (C) 2002-2009 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-2009 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='".addslashes($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 = mysql_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 mysql_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 (mysql_num_rows($res) == 0)
162                         return 0;
163                 else
164                         return (mysql_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 (mysql_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 = mysql_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 = mysql_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 (mysql_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                 // generate key and URL
340                 $key = $this->generateActivationEntry($type, $extra);
341                 $url = $CONF['AdminURL'] . 'index.php?action=activate&key=' . $key;
342
343                 // choose text to use in mail
344                 switch ($type)
345                 {
346                         case 'register':
347                                 $message = _ACTIVATE_REGISTER_MAIL;
348                                 $title = _ACTIVATE_REGISTER_MAILTITLE;
349                                 break;
350                         case 'forgot':
351                                 $message = _ACTIVATE_FORGOT_MAIL;
352                                 $title = _ACTIVATE_FORGOT_MAILTITLE;
353                                 break;
354                         case 'addresschange':
355                                 $message = _ACTIVATE_CHANGE_MAIL;
356                                 $title = _ACTIVATE_CHANGE_MAILTITLE;
357                                 break;
358                         default;
359                 }
360
361                 // fill out variables in text
362
363                 $aVars = array(
364                         'siteName' => $CONF['SiteName'],
365                         'siteUrl' => $CONF['IndexURL'],
366                         'memberName' => $this->getDisplayName(),
367                         'activationUrl' => $url
368                 );
369
370                 $message = TEMPLATE::fill($message, $aVars);
371                 $title = TEMPLATE::fill($title, $aVars);
372
373                 // send mail
374
375                 mb_language('ja');
376                 mb_internal_encoding(_CHARSET);
377                 @mb_send_mail($this->getEmail(), $title ,$message,'From: ' . $CONF['AdminEmail']);
378
379                 ACTIONLOG::add(INFO, _ACTIONLOG_ACTIVATIONLINK . ' (' . $this->getDisplayName() . ' / type: ' . $type . ')');
380
381
382         }
383
384         /**
385           * Returns an array of all blogids for which member has admin rights
386           */
387         function getAdminBlogs() {
388                 $blogs = array();
389
390                 if ($this->isAdmin())
391                         $query = 'SELECT bnumber as blogid from '.sql_table('blog');
392                 else
393                         $query = 'SELECT tblog as blogid from '.sql_table('team').' where tadmin=1 and tmember=' . $this->getID();
394
395                 $res = sql_query($query);
396                 if (mysql_num_rows($res) > 0) {
397                         while ($obj = mysql_fetch_object($res)) {
398                                 array_push($blogs, $obj->blogid);
399                         }
400                 }
401
402                 return $blogs;
403         }
404
405         /**
406           * Returns an array of all blogids for which member has team rights
407           */
408         function getTeamBlogs($incAdmin = 1) {
409                 $incAdmin = intval($incAdmin);
410                 $blogs = array();
411
412                 if ($this->isAdmin() && $incAdmin)
413                         $query = 'SELECT bnumber as blogid from '.sql_table('blog');
414                 else
415                         $query = 'SELECT tblog as blogid from '.sql_table('team').' where tmember=' . $this->getID();
416
417                 $res = sql_query($query);
418                 if (mysql_num_rows($res) > 0) {
419                         while ($obj = mysql_fetch_object($res)) {
420                                 array_push($blogs, $obj->blogid);
421                         }
422                 }
423
424                 return $blogs;
425         }
426
427         /**
428           * Returns an email address from which notification of commenting/karma voting can
429           * be sent. A suggestion can be given for when the member is not logged in
430           */
431         function getNotifyFromMailAddress($suggest = "") {
432                 global $CONF;
433                 if ($this->isLoggedIn()) {
434                         return $this->getDisplayName() . " <" . $this->getEmail() . ">";
435                 } else if (isValidMailAddress($suggest)) {
436                         return $suggest;
437                 } else {
438                         return $CONF['AdminEmail'];
439                 }
440         }
441
442         /**
443           * Write data to database
444           */
445         function write() {
446
447                 $query =  'UPDATE '.sql_table('member')
448                            . " SET mname='" . addslashes($this->getDisplayName()) . "',"
449                            . "     mrealname='". addslashes($this->getRealName()) . "',"
450                            . "     mpassword='". addslashes($this->getPassword()) . "',"
451                            . "     mcookiekey='". addslashes($this->getCookieKey()) . "',"
452                            . "     murl='" . addslashes($this->getURL()) . "',"
453                            . "     memail='" . addslashes($this->getEmail()) . "',"
454                            . "     madmin=" . $this->isAdmin() . ","
455                            . "     mnotes='" . addslashes($this->getNotes()) . "',"
456                            . "     mcanlogin=" . $this->canLogin() . ","
457                            . "     deflang='" . addslashes($this->getLanguage()) . "',"
458                            . "     mautosave=" . intval($this->getAutosave()) . ""
459                            . " WHERE mnumber=" . $this->getID();
460                 sql_query($query);
461         }
462
463         function checkCookieKey($key) {
464                 return (($key != '') && ($key == $this->getCookieKey()));
465         }
466
467         function checkPassword($pw) {
468                 return (md5($pw) == $this->getPassword());
469         }
470
471         function getRealName() {
472                 return $this->realname;
473         }
474
475         function setRealName($name) {
476                 $this->realname = $name;
477         }
478
479         function getEmail() {
480                 return $this->email;
481         }
482
483         function setEmail($email) {
484                 $this->email = $email;
485         }
486
487         function getPassword() {
488                 return $this->password;
489         }
490
491         function setPassword($pwd) {
492                 $this->password = md5($pwd);
493         }
494
495         function getCookieKey() {
496                 return $this->cookiekey;
497         }
498
499         /**
500           * Generate new cookiekey, save it, and return it
501           */
502         function newCookieKey() {
503                 mt_srand( (double) microtime() * 1000000);
504                 $this->cookiekey = md5(uniqid(mt_rand()));
505                 $this->write();
506                 return $this->cookiekey;
507         }
508
509         function setCookieKey($val) {
510                 $this->cookiekey = $val;
511         }
512
513         function getURL() {
514                 return $this->url;
515         }
516
517         function setURL($site) {
518                 $this->url = $site;
519         }
520
521         function getLanguage() {
522                 return $this->language;
523         }
524
525         function setLanguage($lang) {
526                 $this->language = $lang;
527         }
528
529         function setDisplayName($nick) {
530                 $this->displayname = $nick;
531         }
532
533         function getDisplayName() {
534                 return $this->displayname;
535         }
536
537         function isAdmin() {
538                 return $this->admin;
539         }
540
541         function setAdmin($val) {
542                 $this->admin = $val;
543         }
544
545         function canLogin() {
546                 return $this->canlogin;
547         }
548
549         function setCanLogin($val) {
550                 $this->canlogin = $val;
551         }
552
553         function getNotes() {
554                 return $this->notes;
555         }
556
557         function setNotes($val) {
558                 $this->notes = $val;
559         }
560
561         function getAutosave() {
562                 return $this->autosave;
563         }
564
565         function setAutosave($val) {
566                 $this->autosave = $val;
567         }
568
569         function getID() {
570                 return $this->id;
571         }
572
573         /**
574          * Returns true if there is a member with the given login name
575          *
576          * @static
577          */
578         function exists($name) {
579                 $r = sql_query('select * FROM '.sql_table('member')." WHERE mname='".addslashes($name)."'");
580                 return (mysql_num_rows($r) != 0);
581         }
582
583         /**
584          * Returns true if there is a member with the given ID
585          *
586          * @static
587          */
588         function existsID($id) {
589                 $r = sql_query('select * FROM '.sql_table('member')." WHERE mnumber='".intval($id)."'");
590                 return (mysql_num_rows($r) != 0);
591         }
592
593         /**
594          *  Checks if a username is protected.
595          *  If so, it can not be used on anonymous comments
596          */
597         function isNameProtected($name) {
598
599                 // extract name
600                 $name = strip_tags($name);
601                 $name = trim($name);
602
603                 return MEMBER::exists($name);
604         }
605
606         /**
607          * Adds a new member
608          *
609          * @static
610          */
611         function create($name, $realname, $password, $email, $url, $admin, $canlogin, $notes) {
612                 if (!isValidMailAddress($email))
613                         return _ERROR_BADMAILADDRESS;
614
615                 if (!isValidDisplayName($name))
616                         return _ERROR_BADNAME;
617
618                 if (MEMBER::exists($name))
619                         return _ERROR_NICKNAMEINUSE;
620
621                 if (!$realname)
622                         return _ERROR_REALNAMEMISSING;
623
624                 if (!$password)
625                         return _ERROR_PASSWORDMISSING;
626
627                 // Sometimes user didn't prefix the URL with http://, this cause a malformed URL. Let's fix it.
628                 if (!eregi("^https?://", $url))
629                         $url = "http://".$url;
630
631                 $name = addslashes($name);
632                 $realname = addslashes($realname);
633                 $password = addslashes(md5($password));
634                 $email = addslashes($email);
635                 $url = addslashes($url);
636                 $admin = intval($admin);
637                 $canlogin = intval($canlogin);
638                 $notes = addslashes($notes);
639
640                 $query = 'INSERT INTO '.sql_table('member')." (MNAME,MREALNAME,MPASSWORD,MEMAIL,MURL, MADMIN, MCANLOGIN, MNOTES) "
641                            . "VALUES ('$name','$realname','$password','$email','$url',$admin, $canlogin, '$notes')";
642                 sql_query($query);
643
644                 ACTIONLOG::add(INFO, _ACTIONLOG_NEWMEMBER . ' ' . $name);
645
646                 return 1;
647         }
648
649         /**
650          * Returns activation info for a certain key (an object with properties vkey, vmember, ...)
651          * (static)
652          *
653          * @author karma
654          */
655         function getActivationInfo($key)
656         {
657                 $query = 'SELECT * FROM ' . sql_table('activation') . ' WHERE vkey=\'' . addslashes($key). '\'';
658                 $res = sql_query($query);
659
660                 if (!$res || (mysql_num_rows($res) == 0))
661                         return 0;
662                 else
663                         return mysql_fetch_object($res);
664         }
665
666         /**
667          * Creates an account activation key
668          *
669          * @param $type one of the following values (determines what to do when activation expires)
670          *                'register' (new member registration)
671          *                'forgot' (forgotton password)
672          *                'addresschange' (member address has changed)
673          * @param $extra extra info (needed when validation link expires)
674          *                                addresschange -> old email address
675          * @author dekarma
676          */
677         function generateActivationEntry($type, $extra = '')
678         {
679                 // clean up old entries
680                 $this->cleanupActivationTable();
681
682                 // kill any existing entries for the current member (delete is ok)
683                 // (only one outstanding activation key can be present for a member)
684                 sql_query('DELETE FROM ' . sql_table('activation') . ' WHERE vmember=' . intval($this->getID()));
685
686                 $canLoginWhileActive = false; // indicates if the member can log in while the link is active
687                 switch ($type)
688                 {
689                         case 'forgot':
690                                 $canLoginWhileActive = true;
691                                 break;
692                         case 'register':
693                                 break;
694                         case 'addresschange':
695                                 $extra = $extra . '/' . ($this->canLogin() ? '1' : '0');
696                                 break;
697                 }
698
699                 $ok = false;
700                 while (!$ok)
701                 {
702                         // generate a random key
703                         srand((double)microtime()*1000000);
704                         $key = md5(uniqid(rand(), true));
705
706                         // attempt to add entry in database
707                         // add in database as non-active
708                         $query = 'INSERT INTO ' . sql_table('activation'). ' (vkey, vtime, vmember, vtype, vextra) ';
709                         $query .= 'VALUES (\'' . addslashes($key). '\', \'' . date('Y-m-d H:i:s',time()) . '\', \'' . intval($this->getID()). '\', \'' . addslashes($type). '\', \'' . addslashes($extra). '\')';
710                         if (sql_query($query))
711                                 $ok = true;
712                 }
713
714                 // mark member as not allowed to log in
715                 if (!$canLoginWhileActive)
716                 {
717                         $this->setCanLogin(0);
718                         $this->write();
719                 }
720
721                 // return the key
722                 return $key;
723         }
724
725         /**
726          * Inidicates that an activation link has been clicked and any forms displayed
727          * there have been successfully filled out.
728          * @author dekarma
729          */
730         function activate($key)
731         {
732                 // get activate info
733                 $info = MEMBER::getActivationInfo($key);
734
735                 // no active key
736                 if (!$info)
737                         return false;
738
739                 switch ($info->vtype)
740                 {
741                         case 'forgot':
742                                 // nothing to do
743                                 break;
744                         case 'register':
745                                 // set canlogin value
746                                 global $CONF;
747                                 sql_query('UPDATE ' . sql_table('member') . ' SET mcanlogin=' . intval($CONF['NewMemberCanLogon']). ' WHERE mnumber=' . intval($info->vmember));
748                                 break;
749                         case 'addresschange':
750                                 // reset old 'canlogin' value
751                                 list($oldEmail, $oldCanLogin) = explode('/', $info->vextra);
752                                 sql_query('UPDATE ' . sql_table('member') . ' SET mcanlogin=' . intval($oldCanLogin). ' WHERE mnumber=' . intval($info->vmember));
753                                 break;
754                 }
755
756                 // delete from activation table
757                 sql_query('DELETE FROM ' . sql_table('activation') . ' WHERE vkey=\'' . addslashes($key) . '\'');
758
759                 // success!
760                 return true;
761         }
762
763         /**
764          * Cleans up entries in the activation table. All entries older than 2 days are removed.
765          * (static)
766          *
767          * @author dekarma
768          */
769         function cleanupActivationTable()
770         {
771                 $boundary = time() - (60 * 60 * 24 * 2);
772
773                 // 1. walk over all entries, and see if special actions need to be performed
774                 $res = sql_query('SELECT * FROM ' . sql_table('activation') . ' WHERE vtime < \'' . date('Y-m-d H:i:s',$boundary) . '\'');
775
776                 while ($o = mysql_fetch_object($res))
777                 {
778                         switch ($o->vtype)
779                         {
780                                 case 'register':
781                                         // delete all information about this site member. registration is undone because there was
782                                         // no timely activation
783                                         include_once($DIR_LIBS . 'ADMIN.php');
784                                         ADMIN::deleteOneMember(intval($o->vmember));
785                                         break;
786                                 case 'addresschange':
787                                         // revert the e-mail address of the member back to old address
788                                         list($oldEmail, $oldCanLogin) = explode('/', $o->vextra);
789                                         sql_query('UPDATE ' . sql_table('member') . ' SET mcanlogin=' . intval($oldCanLogin). ', memail=\'' . addslashes($oldEmail). '\' WHERE mnumber=' . intval($o->vmember));
790                                         break;
791                                 case 'forgot':
792                                         // delete the activation link and ignore. member can request a new password using the
793                                         // forgot password link
794                                         break;
795                         }
796                 }
797
798                 // 2. delete activation entries for real
799                 sql_query('DELETE FROM ' . sql_table('activation') . ' WHERE vtime < \'' . date('Y-m-d H:i:s',$boundary) . '\'');
800         }
801
802 }
803
804 ?>