2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 07/13/2011 *
4 * =================== Last change: 07/13/2011 *
6 * -------------------------------------------------------------------- *
7 * File : fix_refsystem.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Generate refback table including all refs *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Refback-Tabelle mit allen Refs generieren *
12 * -------------------------------------------------------------------- *
13 * Copyright (c) 2003 - 2009 by Roland Haeder *
14 * Copyright (c) 2009 - 2015 by Mailer Developer Team *
15 * For more information visit: http://mxchange.org *
17 * This program is free software; you can redistribute it and/or modify *
18 * it under the terms of the GNU General Public License as published by *
19 * the Free Software Foundation; either version 2 of the License, or *
20 * (at your option) any later version. *
22 * This program is distributed in the hope that it will be useful, *
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25 * GNU General Public License for more details. *
27 * You should have received a copy of the GNU General Public License *
28 * along with this program; if not, write to the Free Software *
29 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
31 ************************************************************************/
33 // Some security stuff...
34 if (!defined('__SECURITY')) {
38 // Sanity-check: Is there ref level 0? If so, this must be fixed to NULL and `level` must be increased by one
39 $result = sqlQuery('SELECT `id` FROM `{?_MYSQL_PREFIX?}_refsystem` WHERE `level`=0', __FILE__, __LINE__);
40 if (!ifSqlHasZeroNums($result)) {
41 // Remove index temporaly
42 sqlQueryAlterTable('ALTER TABLE `{?_MYSQL_PREFIX?}_refsystem` DROP INDEX `userid_level`', __FILE__, __LINE__);
45 sqlQuery('UPDATE `{?_MYSQL_PREFIX?}_refsystem` SET `level`=`level`+1', __FILE__, __LINE__);
48 sqlQueryAlterTable('ALTER TABLE `{?_MYSQL_PREFIX?}_refsystem` ADD UNIQUE INDEX `userid_level` (`userid`, `level`)', __FILE__, __LINE__);
51 rebuildCache('refsystem', 'refsystem');
55 sqlFreeResult($result);
58 sqlQuery('TRUNCATE TABLE `{?_MYSQL_PREFIX?}_user_refs`', __FILE__, __LINE__);
60 // Begin with all users in level one
61 $result_direct = sqlQuery('SELECT
64 `{?_MYSQL_PREFIX?}_user_data`
69 `userid` ASC', __FILE__, __LINE__);
72 if (!ifSqlHasZeroNums($result_direct)) {
73 // When 'walk' through all users
74 while ($content = sqlFetchArray($result_direct)) {
75 // Update refback table
76 /* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'userid=' . $content['userid'] . ' - BEFORE!');
77 updateReferralTable($content['userid']);
78 /* DEBUG: */ logDebugMessage(__FILE__, __LINE__, 'userid=' . $content['userid'] . ' - AFTER!');
83 sqlFreeResult($result_direct);