2 /************************************************************************
3 * MXChange v0.2.1 Start: 09/09/2008 *
4 * ================ Last change: 09/09/2008 *
6 * -------------------------------------------------------------------- *
7 * File : what-refback.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Refback setup *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Refback-Einstellungen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
43 } elseif (!IS_MEMBER()) {
44 // User is not logged in
45 LOAD_URL("modules.php?module=index");
46 } elseif ((!EXT_IS_ACTIVE("refback")) && (!IS_ADMIN())) {
47 addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "refback");
51 // Is the refback system enabled?
52 if (getConfig('refback_enabled') != "Y") {
54 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_REFBACK_DISABLED'));
59 // Add description as navigation point
60 ADD_DESCR("member", __FILE__);
62 // Was the form submitted?
63 if ((REQUEST_ISSET_POST('edit')) && (REQUEST_ISSET_POST(('id')))) {
64 // Okay, has the user entered some values?
65 if (REQUEST_ISSET_POST(('percents'))) {
66 // Revert german commta for testing
67 $percents = REVERT_COMMA(REQUEST_POST('percents'));
70 if ((($percents >= getConfig('refback_min_perc')) || (round($percents) == 0)) && ($percents <= getConfig('refback_max_perc'))) {
71 // Change ref-back for this direct id
72 $status = REFBACK_CHANGE_MEMBER_PERCENTS(REQUEST_POST('id'), REQUEST_POST('percents'));
75 if (isset($status['ok'])) {
77 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_REFBACK_DONE'));
78 } elseif (isset($status['message'])) {
79 // Something went wrong with error message
80 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('MEMBER_REFBACK_ERROR_MESSAGE'), $status['message']));
83 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_REFBACK_ERROR_EMPTY_MESSAGE'));
86 // Percents out-of-bounds ;-)
87 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('MEMBER_REFBACK_ERROR_OUT_OF_BOUNDS'), getConfig('refback_min_perc'), getConfig('refback_max_perc')));
92 // Read data from refback table
93 $content = GET_USER_REF_ENTRY(REQUEST_POST('id'));
96 $content['refback'] = TRANSLATE_COMMA($content['refback']);
97 $content['min'] = TRANSLATE_COMMA(getConfig('refback_min_perc').".0");
98 $content['max'] = TRANSLATE_COMMA(getConfig('refback_max_perc').".0");
100 // Load form for editing
101 LOAD_TEMPLATE("member_refback_edit", false, $content);
105 // Load all referal levels
106 $result = SQL_QUERY_ESC("SELECT r.level, r.percents
107 FROM `{!_MYSQL_PREFIX!}_refdepths` AS r
109 ORDER BY r.level ASC",
110 array(getUserId()), __FILE__, __LINE__);
112 // Are there some entries? (Shall be!)
113 if (SQL_NUMROWS($result) > 0) {
116 while ($content = SQL_FETCHARRAY($result)) {
122 // Check for users ref in this level
123 foreach (GET_USER_REFS(getUserId(), $content['level']) as $refRow) {
124 // Not-deleted account is default
126 if (is_null($refRow['status'])) $deleted = true;
128 // Add/"translate" more content
130 $refRow['points'] = TRANSLATE_COMMA($refRow['points']);
131 $refRow['refback'] = TRANSLATE_COMMA($refRow['refback']);
132 $refRow['status'] = TRANSLATE_STATUS($refRow['status']);
133 if (empty($refRow['nickname'])) $refRow['nickname'] = "---";
137 $rows .= LOAD_TEMPLATE("member_refback_list_row_deleted", true, $refRow);
139 $rows .= LOAD_TEMPLATE("member_refback_list_row", true, $refRow);
142 // Count this ref and switch color
147 // Remember the content
148 $content['counter'] = TRANSLATE_COMMA($counter);
149 $content['percents'] = TRANSLATE_COMMA($content['percents']);
150 $content['rows'] = $rows;
152 // Load level template
153 $OUT .= LOAD_TEMPLATE("member_refback_list_level", true, $content);
156 // Load main template
157 LOAD_TEMPLATE("member_refback_list", false, $OUT);
160 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_REFBACK_NO_ENTRIES'));
164 SQL_FREERESULT($result);