8075701382b461b125c05dda1f3a2028a207ffbf
[mailer.git] / inc / modules / member / what-refback.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if (!defined('__SECURITY')) {
40         die();
41 } elseif (!isMember()) {
42         // User is not logged in
43         redirectToIndexMemberOnlyModule();
44 } elseif (!isRefbackEnabled()) {
45         // Output message
46         loadTemplate('admin_settings_saved', false, '{--MEMBER_REFBACK_DISABLED--}');
47
48         // Abort here
49         return false;
50 } // END - if
51
52 // Add description as navigation point
53 addYouAreHereLink('member', __FILE__);
54
55 if ((!isExtensionActive('refback')) && (!isAdmin())) {
56         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('refback'));
57         return;
58 } // END - if
59
60 // Was the form submitted?
61 if ((isFormSent('edit')) && (isPostRequestParameterSet('id'))) {
62         // Okay, has the user entered some values?
63         if (isPostRequestParameterSet('percents')) {
64                 // Revert german commta for testing
65                 $percents = convertCommaToDot(postRequestParameter('percents'));
66
67                 // Validate percents
68                 if ((($percents >= getConfig('refback_min_perc')) || (round($percents) == 0)) && ($percents <= getConfig('refback_max_perc'))) {
69                         // Change ref-back for this direct id
70                         $status = updateMemberRefbackPercents(postRequestParameter('id'), postRequestParameter('percents'));
71
72                         // Check status
73                         if (isset($status['ok'])) {
74                                 // No message found
75                                 loadTemplate('admin_settings_saved', false, '{--MEMBER_REFBACK_DONE--}');
76                         } elseif (isset($status['message'])) {
77                                 // Something went wrong with error message
78                                 loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_REFBACK_ERROR_MESSAGE', $status['message']));
79                         } else {
80                                 // No message found
81                                 loadTemplate('admin_settings_saved', false, '{--MEMBER_REFBACK_ERROR_EMPTY_MESSAGE--}');
82                         }
83                 } else {
84                         // Percents out-of-bounds ;-)
85                         loadTemplate('admin_settings_saved', false, getMaskedMessage('MEMBER_REFBACK_ERROR_OUT_OF_BOUNDS'));
86                 }
87
88                 // Insert line
89         } else {
90                 // Read data from refback table
91                 $content = getArrayFromUserRefbackData(postRequestParameter('id'));
92
93                 // Load form for editing
94                 loadTemplate('member_refback_edit', false, $content);
95         }
96 } // END - if
97
98 // Load all referal levels
99 $result = SQL_QUERY('SELECT
100         r.level, r.percents
101 FROM
102         `{?_MYSQL_PREFIX?}_refdepths` AS r
103 WHERE
104         r.level > 0
105 ORDER BY
106         r.level ASC', __FILE__, __LINE__);
107
108 // Are there some entries? (Shall be!)
109 if (!SQL_HASZERONUMS($result)) {
110         // List all levels
111         $OUT = '';
112         while ($content = SQL_FETCHARRAY($result)) {
113                 // Init variables
114                 $rows = '';
115                 $content['counter'] = 0;
116
117                 // Check for users ref in this level
118                 foreach (getArrayFromRefbackUserRefs(getMemberId(), $content['level']) as $refRow) {
119                         // Not-deleted account is default
120                         $deleted = false;
121                         if (is_null($refRow['status'])) $deleted = true;
122
123                         // Add/"translate" more content
124                         // @TODO UNUSED: $refRow['status']      = translateUserStatus($refRow['status']);
125                         $refRow['joined']      = generateDateTime($refRow['joined'], '3');
126
127                         // Load row template
128                         if ($deleted === true) {
129                                 $rows .= loadTemplate('member_refback_list_row_deleted', true, $refRow);
130                         } else {
131                                 $rows .= loadTemplate('member_refback_list_row', true, $refRow);
132                         }
133
134                         // Count this ref and switch color
135                         $content['counter']++;
136                 } // END - foreach
137
138                 // Remember the content
139                 $content['rows'] = $rows;
140
141                 // Load level template
142                 $OUT .= loadTemplate('member_refback_list_level', true, $content);
143         } // END - while
144
145         // Load main template
146         loadTemplate('member_refback_list', false, $OUT);
147 } else {
148         // No entries
149         loadTemplate('admin_settings_saved', false, '{--MEMBER_REFBACK_NO_ENTRIES--}');
150 }
151
152 // Free result
153 SQL_FREERESULT($result);
154
155 // [EOF]
156 ?>