More XHTML-fied and extended header added to templates
[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  * $Revision:: 856                                                    $ *
14  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. March 2009)             $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author:: stelzi                                                   $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
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");
48         return;
49 }
50
51 // Is the refback system enabled?
52 if (getConfig('refback_enabled') != "Y") {
53         // Output message
54         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_REFBACK_DISABLED'));
55         // Abort here
56         return false;
57 } // END - if
58
59 // Add description as navigation point
60 ADD_DESCR("member", __FILE__);
61
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'));
68
69                 // Validate 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'));
73
74                         // Check status
75                         if (isset($status['ok'])) {
76                                 // No message found
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']));
81                         } else {
82                                 // No message found
83                                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_REFBACK_ERROR_EMPTY_MESSAGE'));
84                         }
85                 } else {
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')));
88                 }
89
90                 // Insert line
91         } else {
92                 // Read data from refback table
93                 $content = GET_USER_REF_ENTRY(REQUEST_POST('id'));
94
95                 // Translate comma
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");
99
100                 // Load form for editing
101                 LOAD_TEMPLATE("member_refback_edit", false, $content);
102         }
103 } // END - if
104
105 // Load all referal levels
106 $result = SQL_QUERY_ESC("SELECT r.level, r.percents
107 FROM `{!_MYSQL_PREFIX!}_refdepths` AS r
108 WHERE r.level > 0
109 ORDER BY r.level ASC",
110         array(getUserId()), __FILE__, __LINE__);
111
112 // Are there some entries? (Shall be!)
113 if (SQL_NUMROWS($result) > 0) {
114         // List all levels
115         $OUT = "";
116         while ($content = SQL_FETCHARRAY($result)) {
117                 // Init variables
118                 $rows = "";
119                 $counter = 0;
120                 $SW = 2;
121
122                 // Check for users ref in this level
123                 foreach (GET_USER_REFS(getUserId(), $content['level']) as $refRow) {
124                         // Not-deleted account is default
125                         $deleted = false;
126                         if (is_null($refRow['status'])) $deleted = true;
127
128                         // Add/"translate" more content
129                         $refRow['sw']      = $SW;
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'] = "---";
134
135                         // Load row template
136                         if ($deleted) {
137                                 $rows .= LOAD_TEMPLATE("member_refback_list_row_deleted", true, $refRow);
138                         } else {
139                                 $rows .= LOAD_TEMPLATE("member_refback_list_row", true, $refRow);
140                         }
141
142                         // Count this ref and switch color
143                         $counter++;
144                         $SW = 3 - $SW;
145                 } // END - foreach
146
147                 // Remember the content
148                 $content['counter']  = TRANSLATE_COMMA($counter);
149                 $content['percents'] = TRANSLATE_COMMA($content['percents']);
150                 $content['rows']     = $rows;
151
152                 // Load level template
153                 $OUT .= LOAD_TEMPLATE("member_refback_list_level", true, $content);
154         } // END - while
155
156         // Load main template
157         LOAD_TEMPLATE("member_refback_list", false, $OUT);
158 } else {
159         // No entries
160         LOAD_TEMPLATE("admin_settings_saved", false, getMessage('MEMBER_REFBACK_NO_ENTRIES'));
161 }
162
163 // Free result
164 SQL_FREERESULT($result);
165
166 //
167 ?>