Compilation time added, some compileCode() calles removed, ADMIN_WHAT_404 added
[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::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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 - 2009 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         die();
42 } elseif (!isMember()) {
43         // User is not logged in
44         redirectToIndexMemberOnlyModule();
45 }
46
47 // Is the refback system enabled?
48 if (getConfig('refback_enabled') != 'Y') {
49         // Output message
50         loadTemplate('admin_settings_saved', false, getMessage('MEMBER_REFBACK_DISABLED'));
51         // Abort here
52         return false;
53 } // END - if
54
55 // Add description as navigation point
56 addMenuDescription('member', __FILE__);
57
58 if ((!isExtensionActive('refback')) && (!isAdmin())) {
59         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('refback'));
60         return;
61 } // END - if
62
63 // Was the form submitted?
64 if ((isPostRequestElementSet('edit')) && (isPostRequestElementSet('id'))) {
65         // Okay, has the user entered some values?
66         if (isPostRequestElementSet('percents')) {
67                 // Revert german commta for testing
68                 $percents = convertCommaToDot(postRequestElement('percents'));
69
70                 // Validate percents
71                 if ((($percents >= getConfig('refback_min_perc')) || (round($percents) == 0)) && ($percents <= getConfig('refback_max_perc'))) {
72                         // Change ref-back for this direct id
73                         $status = updateMemberRefbackPercents(postRequestElement('id'), postRequestElement('percents'));
74
75                         // Check status
76                         if (isset($status['ok'])) {
77                                 // No message found
78                                 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_REFBACK_DONE'));
79                         } elseif (isset($status['message'])) {
80                                 // Something went wrong with error message
81                                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('MEMBER_REFBACK_ERROR_MESSAGE'), $status['message']));
82                         } else {
83                                 // No message found
84                                 loadTemplate('admin_settings_saved', false, getMessage('MEMBER_REFBACK_ERROR_EMPTY_MESSAGE'));
85                         }
86                 } else {
87                         // Percents out-of-bounds ;-)
88                         loadTemplate('admin_settings_saved', false, sprintf(getMessage('MEMBER_REFBACK_ERROR_OUT_OF_BOUNDS'), getConfig('refback_min_perc'), getConfig('refback_max_perc')));
89                 }
90
91                 // Insert line
92         } else {
93                 // Read data from refback table
94                 $content = getArrayFromUserRefbackData(postRequestElement('id'));
95
96                 // Translate comma
97                 $content['refback'] = translateComma($content['refback']);
98                 $content['min']     = translateComma(getConfig('refback_min_perc').".0");
99                 $content['max']     = translateComma(getConfig('refback_max_perc').".0");
100
101                 // Load form for editing
102                 loadTemplate('member_refback_edit', false, $content);
103         }
104 } // END - if
105
106 // Load all referal levels
107 $result = SQL_QUERY_ESC("SELECT r.level, r.percents
108 FROM `{?_MYSQL_PREFIX?}_refdepths` AS r
109 WHERE r.level > 0
110 ORDER BY r.level ASC",
111 array(getUserId()), __FILE__, __LINE__);
112
113 // Are there some entries? (Shall be!)
114 if (SQL_NUMROWS($result) > 0) {
115         // List all levels
116         $OUT = '';
117         while ($content = SQL_FETCHARRAY($result)) {
118                 // Init variables
119                 $rows = '';
120                 $counter = 0;
121                 $SW = 2;
122
123                 // Check for users ref in this level
124                 foreach (getArrayFromRefbackUserRefs(getUserId(), $content['level']) as $refRow) {
125                         // Not-deleted account is default
126                         $deleted = false;
127                         if (is_null($refRow['status'])) $deleted = true;
128
129                         // Add/"translate" more content
130                         $refRow['sw']      = $SW;
131                         $refRow['points']  = translateComma($refRow['points']);
132                         $refRow['refback'] = translateComma($refRow['refback']);
133                         $refRow['status']  = translateUserStatus($refRow['status']);
134                         if (empty($refRow['nickname'])) $refRow['nickname'] = '---';
135
136                         // Load row template
137                         if ($deleted) {
138                                 $rows .= loadTemplate('member_refback_list_row_deleted', true, $refRow);
139                         } else {
140                                 $rows .= loadTemplate('member_refback_list_row', true, $refRow);
141                         }
142
143                         // Count this ref and switch color
144                         $counter++;
145                         $SW = 3 - $SW;
146                 } // END - foreach
147
148                 // Remember the content
149                 $content['counter']  = translateComma($counter);
150                 $content['percents'] = translateComma($content['percents']);
151                 $content['rows']     = $rows;
152
153                 // Load level template
154                 $OUT .= loadTemplate('member_refback_list_level', true, $content);
155         } // END - while
156
157         // Load main template
158         loadTemplate('member_refback_list', false, $OUT);
159 } else {
160         // No entries
161         loadTemplate('admin_settings_saved', false, getMessage('MEMBER_REFBACK_NO_ENTRIES'));
162 }
163
164 // Free result
165 SQL_FREERESULT($result);
166
167 //
168 ?>