Refback extension in alpha phase finished, users can give refback to all refs in...
[mailer.git] / inc / modules / member / what-refback.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/09/2008 *
4  * ================                             Last change: 09/09/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-refback.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Refback setup                                    *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Refback-Einstellungen                            *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif (!IS_MEMBER()) {
39         // User is not logged in
40         LOAD_URL("modules.php?module=index");
41 } elseif ((!EXT_IS_ACTIVE("refback")) && (!IS_ADMIN())) {
42         // Extension "refback" is not active
43         ADD_FATAL(EXTENSION_PROBLEM_EXT_INACTIVE, "refback");
44         return;
45 }
46
47 // Add description as navigation point
48 ADD_DESCR("member", basename(__FILE__));
49
50 // Was the form submitted?
51 if ((isset($_POST['edit'])) && (isset($_POST['id']))) {
52         // Okay, has the user entered some values?
53         if (isset($_POST['percents'])) {
54                 // Change ref-back for this direct id
55                 $status = REFBACK_CHANGE_MEMBER_PERCENTS($_POST['id'], $_POST['percents']);
56
57                 // Check status
58                 if (isset($status['ok'])) {
59                         // No message found
60                         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_REFBACK_DONE);
61                 } elseif (isset($status['message'])) {
62                         // Something went wrong with error message
63                         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(MEMBER_REFBACK_ERROR_MESSAGE, $status['message']));
64                 } else {
65                         // No message found
66                         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_REFBACK_ERROR_EMPTY_MESSAGE);
67                 }
68
69                 // Insert line
70                 OUTPUT_HTML("<br />");
71         } else {
72                 // Read data from refback table
73                 $content = GET_USER_REF_ENTRY($_POST['id']);
74
75                 // Translate comma
76                 $content['refback'] = TRANSLATE_COMMA($content['refback']);
77
78                 // Load form for editing
79                 LOAD_TEMPLATE("member_refback_edit", false, $content);
80         }
81 } // END - if
82
83 // Load all referal levels
84 $result = SQL_QUERY_ESC("SELECT r.level, r.percents
85 FROM "._MYSQL_PREFIX."_refdepths AS r
86 WHERE r.level > 0
87 ORDER BY r.level ASC",
88         array($GLOBALS['userid']), __FILE__, __LINE__);
89
90 // Are there some entries? (Shall be!)
91 if (SQL_NUMROWS($result) > 0) {
92         // List all levels
93         $OUT = "";
94         while ($content = SQL_FETCHARRAY($result)) {
95                 // Init variables
96                 $rows = "";
97                 $counter = 0;
98                 $SW = 2;
99
100                 // Check for users ref in this level
101                 foreach (GET_USER_REFS($GLOBALS['userid'], $content['level']) as $refRow) {
102                         // Not-deleted account is default
103                         $deleted = false;
104                         if (is_null($refRow['status'])) $deleted = true;
105
106                         // Add/"translate" more content
107                         $refRow['sw']      = $SW;
108                         $refRow['points']  = TRANSLATE_COMMA($refRow['points']);
109                         $refRow['refback'] = TRANSLATE_COMMA($refRow['refback']);
110                         $refRow['status']  = TRANSLATE_STATUS($refRow['status']);
111                         if (empty($refRow['nickname'])) $refRow['nickname'] = "---";
112
113                         // Load row template
114                         if ($deleted) {
115                                 $rows .= LOAD_TEMPLATE("member_refback_list_row_deleted", true, $refRow);
116                         } else {
117                                 $rows .= LOAD_TEMPLATE("member_refback_list_row", true, $refRow);
118                         }
119
120                         // Count this ref and switch color
121                         $counter++;
122                         $SW = 3 - $SW;
123                 } // END - foreach
124
125                 // Remember the content
126                 $content['counter']  = TRANSLATE_COMMA($counter);
127                 $content['percents'] = TRANSLATE_COMMA($content['percents']);
128                 $content['rows']     = $rows;
129
130                 // Load level template
131                 $OUT .= LOAD_TEMPLATE("member_refback_list_level", true, $content);
132         } // END - while
133
134         // Load main template
135         LOAD_TEMPLATE("member_refback_list", false, $OUT);
136 } else {
137         // No entries
138         LOAD_TEMPLATE("admin_settings_saved", false, MEMBER_REFBACK_NO_ENTRIES);
139 }
140
141 // Free result
142 SQL_FREERESULT($result);
143
144 //
145 ?>