Renamed ifSqlHasZeroNums() to ifSqlHasZeroNumRows() and improved some queries.
[mailer.git] / inc / modules / admin / what-config_payouts.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 04/11/2004 *
4  * ===================                          Last change: 08/12/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-config_payouts.php                          *
8  * -------------------------------------------------------------------- *
9  * Short description : Configure payout types                           *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Auszahlungensarten editieren                     *
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')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 // Do we add an entry?
47 if ((isFormSent('add')) && (isPostRequestElementSet('title')) && (postRequestElement('rate') > 0)) {
48         // Add new payout type
49         $result = sqlQueryEscaped("SELECT `id` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE type='%s' LIMIT 1",
50                 array(postRequestElement('title')), __FILE__, __LINE__);
51         if (ifSqlHasZeroNumRows($result)) {
52                 // Add now
53                 sqlQueryEscaped("INSERT INTO
54         `{?_MYSQL_PREFIX?}_payout_types`
55 (
56         `type`, `rate`, `min_points`, `from_account`, `from_pass`, `engine_url`, `engine_ret_ok`, `engine_ret_failed`, `pass_enc`, `allow_url`
57 ) VALUES (
58         '%s', %s, %s,'%s','%s','%s','%s','%s','%s','%s'
59 )",
60                 array(
61                         postRequestElement('title'),
62                         bigintval(postRequestElement('rate')),
63                         bigintval(postRequestElement('min_points')),
64                         postRequestElement('yacc'),
65                         postRequestElement('ypass'),
66                         postRequestElement('yurl'),
67                         postRequestElement('yrdone'),
68                         postRequestElement('yrfailed'),
69                         postRequestElement('ytrans'),
70                         postRequestElement('allow_url'),
71                 ), __FILE__, __LINE__);
72
73                 // Get message
74                 $message = '{--ADMIN_PAYOUT_TYPE_ADDED--}';
75         } else {
76                 // Free memory
77                 sqlFreeResult($result);
78
79                 // Does already exist
80                 $message = '<div class="bad">{--ADMIN_PAYOUT_TYPE_ALREADY--}</div>';
81         }
82 }
83
84 // Payout requests by your members
85 $result_mem = sqlQuery("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `status`='NEW' ORDER BY payout_timestamp DESC", __FILE__, __LINE__);
86
87 $display = TRUE;
88 if ((isFormSent('edit')) && (ifPostContainsSelections())) {
89         // Make payouts configurable
90         $display = FALSE; //Suppress any other outputs
91         $OUT = '';
92         foreach (postRequestElement('sel') as $id => $sel) {
93                 // Load data
94                 $result = sqlQueryEscaped("SELECT `id`, `type`, `rate`, `min_points`, `allow_url` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
95                         array(bigintval($id)), __FILE__, __LINE__);
96                 $content = sqlFetchArray($result);
97                 sqlFreeResult($result);
98
99                 // Prepare data for the row template
100                 $content['allow_url'] = addSelectionBox('yn', $content['allow_url'], 'allow_url[' . $content['id'] . ']');
101
102                 // Load row template and switch color
103                 $OUT .= loadTemplate('admin_edit_payouts_row', TRUE, $content);
104         } // END - foreach
105
106         // Load main template
107         loadTemplate('admin_edit_payouts', FALSE, $OUT);
108 } elseif ((isFormSent('do_edit')) && (ifPostContainsSelections())) {
109         // Change them now
110         // Init SQLs
111         initSqls();
112
113         // Edit entries
114         foreach (postRequestElement('sel') as $id => $sel) {
115                 // Secure id
116                 $id = bigintval($id);
117
118                 // Edit only if something is entered
119                 if ((isPostRequestElementSet('type', $id)) && (postRequestElement('rate', $id) > 0)) {
120                         // Update entry
121                         addSql(sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_payout_types` SET
122         `type`='%s',
123         `rate`=%s,
124         `min_points`=%s,
125         `allow_url`='%s'
126 WHERE
127         `id`=%s
128 LIMIT 1",
129                         array(
130                                 postRequestElement('type', $id),
131                                 convertCommaToDot(postRequestElement('rate', $id)),
132                                 convertCommaToDot(postRequestElement('min_points' , $id)),
133                                 postRequestElement('allow_url', $id),
134                                 $id
135                         ),__FILE__, __LINE__, FALSE));
136                 }
137         }
138
139         // Run all SQLs
140         runFilterChain('run_sqls');
141
142         // Get message
143         $message = '{--ADMIN_PAYOUT_ENTRIES_CHANGED--}';
144 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
145         $display = FALSE; //Suppress any other outputs
146         $OUT = '';
147         foreach (postRequestElement('sel') as $id => $sel) {
148                 // Secure id number
149                 $id = bigintval($id);
150
151                 // Load data
152                 $result = sqlQueryEscaped("SELECT `id`, `type`, `rate`, `min_points` FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
153                         array($id), __FILE__, __LINE__);
154                 $content = sqlFetchArray($result);
155                 sqlFreeResult($result);
156
157                 // Load row template and switch color
158                 $OUT .= loadTemplate('admin_delete_payouts_row', TRUE, $content);
159         } // END - foreach
160
161         // Load main template
162         loadTemplate('admin_delete_payouts', FALSE, $OUT);
163 } elseif ((isFormSent('do_delete')) && (ifPostContainsSelections())) {
164         // Init SQLs
165         initSqls();
166
167         // Delete entries
168         foreach (postRequestElement('sel') as $id => $sel) {
169                 addSql(sqlQueryEscaped("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_payout_types` WHERE `id`=%s LIMIT 1",
170                         array(bigintval($id)), __FILE__, __LINE__, FALSE));
171         } // END - foreach
172
173         // Run all SQLs
174         runFilterChain('run_sqls');
175
176         // Get message
177         $message = '{--ADMIN_PAYOUT_ENTRIES_DELETED--}';
178 }
179
180 if (!empty($message)) {
181         // Output message
182         displayMessage($message);
183 } // END - if
184
185 // Payout types
186 $result_type = sqlQuery('SELECT
187         `id`,
188         `type`,
189         `rate`,
190         `min_points`,
191         `from_account`
192 FROM
193         `{?_MYSQL_PREFIX?}_payout_types`
194 ORDER BY
195         `type` ASC', __FILE__, __LINE__);
196
197 if ((!ifSqlHasZeroNumRows($result_type)) && ($display)) {
198         // List all payout types
199         $OUT = '';
200         while ($content = sqlFetchArray($result_type)) {
201                 // Load row template and switch color
202                 $OUT .= loadTemplate('admin_config_payouts_row', TRUE, $content);
203         } // END - while
204
205         // Free memory
206         sqlFreeResult($result_type);
207
208         // Load main template
209         loadTemplate('admin_config_payouts', FALSE, $OUT);
210 } // END - if
211
212 // Does your members request payouts?
213 if ((!ifSqlHasZeroNumRows($result_mem)) && ($display === TRUE)) {
214         // Members has requested payouts
215         displayMessage('<a href="{%url=modules.php?module=admin&amp;what=list_payouts%}">{--ADMIN_PAYOUT_LIST_REQUESTS--}</a>');
216 } elseif ($display === TRUE) {
217         // No member requests so far
218         displayMessage('{--ADMIN_PAYOUT_NO_MEMBER_REQUESTS--}');
219 }
220
221 // Free result
222 sqlFreeResult($result_mem);
223
224 // Add new payout type
225 if ($display === TRUE) {
226         loadTemplate('admin_add_payout');
227 } // END - if
228
229 // [EOF]
230 ?>