9f5ef86794bed476eb5e74dd17c57a538af8ddfe
[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 - 2015 by Mailer Developer Team                   *
20  * For more information visit: http://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         exit();
41 } elseif (!isMember()) {
42         // User is not logged in
43         redirectToIndexMemberOnlyModule();
44 } elseif (!isRefbackEnabled()) {
45         // Output message
46         displayMessage('{--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         displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=refback%}');
57         return;
58 } // END - if
59
60 // Was the form submitted?
61 if ((isFormSent('edit')) && (isPostRequestElementSet('id'))) {
62         // Okay, has the user entered some values?
63         if (isPostRequestElementSet('refback_percents')) {
64                 // Revert german commta for testing
65                 $percents = convertCommaToDot(postRequestElement('refback_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(postRequestElement('id'), postRequestElement('refback_percents'), postRequestElement('refback_notice'));
71
72                         // Check status
73                         if (isset($status['ok'])) {
74                                 // No message found
75                                 displayMessage('{--MEMBER_REFBACK_DONE--}');
76                         } elseif (isset($status['message'])) {
77                                 // Something went wrong with error message
78                                 displayMessage('{%message,MEMBER_REFBACK_ERROR_MESSAGE=' . getMessage($status['message']) . '%}');
79                         } else {
80                                 // No message found
81                                 displayMessage('{--MEMBER_REFBACK_ERROR_EMPTY_MESSAGE--}');
82                         }
83                 } else {
84                         // Percents out-of-bounds ;-)
85                         displayMessage('{--MEMBER_REFBACK_ERROR_OUT_OF_BOUNDS--}');
86                 }
87
88                 // Insert line
89         } else {
90                 // Read data from refback table
91                 $content = getArrayFromUserRefbackData(postRequestElement('id'));
92
93                 // Load form for editing
94                 loadTemplate('member_edit_refback', FALSE, $content);
95         }
96 } // END - if
97
98 // Load all referral levels
99 $result = sqlQuery('SELECT
100         `r`.`level`,
101         `r`.`percents`
102 FROM
103         `{?_MYSQL_PREFIX?}_refdepths` AS `r`
104 WHERE
105         `r`.`level` > 0
106 ORDER BY
107         `r`.`level` ASC', __FILE__, __LINE__);
108
109 // Are there some entries? (Shall be!)
110 if (!ifSqlHasZeroNums($result)) {
111         // List all levels
112         $OUT = '';
113         while ($content = sqlFetchArray($result)) {
114                 // Init variables
115                 $rows = '';
116                 $content['counter'] = 0;
117
118                 // Check for users ref in this level
119                 foreach (getArrayFromRefbackUserRefs(getMemberId(), $content['level']) as $refRow) {
120                         // Not-deleted account is default
121                         $deleted = FALSE;
122                         if (is_null($refRow['status'])) {
123                                 $deleted = TRUE;
124                         } // END - if
125
126                         // Add/"translate" more content
127                         $refRow['joined'] = generateDateTime($refRow['joined'], '3');
128
129                         // Load row template
130                         if ($deleted === TRUE) {
131                                 $rows .= loadTemplate('member_list_refback_deleted_row', TRUE, $refRow);
132                         } else {
133                                 $rows .= loadTemplate('member_list_refback_row', TRUE, $refRow);
134                         }
135
136                         // Count this ref and switch color
137                         $content['counter']++;
138                 } // END - foreach
139
140                 // Remember the content
141                 $content['rows'] = $rows;
142
143                 // Load level template
144                 $OUT .= loadTemplate('member_list_refback_level', TRUE, $content);
145         } // END - while
146
147         // Load main template
148         loadTemplate('member_list_refback', FALSE, $OUT);
149 } else {
150         // No entries
151         displayMessage('{--MEMBER_REFBACK_NO_ENTRIES--}');
152 }
153
154 // Free result
155 sqlFreeResult($result);
156
157 // [EOF]
158 ?>