Fix for non-working what-config_payouts
[mailer.git] / inc / request-functions.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 02/28/2009 *
4  * ===================                          Last change: 02/28/2009 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : request-functions.php                            *
8  * -------------------------------------------------------------------- *
9  * Short description : Special functions for request handling           *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Spezialle Funktionen fuer die Anfragebehandlung  *
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://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 } // END - if
42
43 // Initialize the request elements
44 function initRequest () {
45         $GLOBALS['raw_request']['get']  = (array) $_GET;
46         $GLOBALS['raw_request']['post'] = (array) $_POST;
47 }
48
49 // Wrapper for elements in $_GET
50 function getRequestElement ($element) {
51         // By default no element is there
52         $value = NULL;
53
54         // Is the element cached or there?
55         if (isset($GLOBALS['cache_request']['get'][$element])) {
56                 // Then use the cache
57                 $value = $GLOBALS['cache_request']['get'][$element];
58         } elseif (isGetRequestElementSet($element)) {
59                 // Then get it directly
60                 $value = SQL_ESCAPE($GLOBALS['raw_request']['get'][$element]);
61
62                 // Store it in cache
63                 $GLOBALS['cache_request']['get'][$element] = $value;
64         } // END - if
65
66         // Return value
67         return $value;
68 }
69
70 // Checks if an element in $_GET exists
71 function isGetRequestElementSet ($element, $subElement = '') {
72         if (empty($subElement)) {
73                 return ((isset($GLOBALS['raw_request']['get'][$element])) && ('' . ($GLOBALS['raw_request']['get'][$element] . '') != ''));
74         } else {
75                 return ((isset($GLOBALS['raw_request']['get'][$element][$subElement])) && ('' . ($GLOBALS['raw_request']['get'][$element][$subElement] . '') != ''));
76         }
77 }
78
79 // Removes an element from $_GET
80 function unsetGetRequestElement ($element) {
81         unset($GLOBALS['raw_request']['get'][$element]);
82 }
83
84 // Getter for whole $_GET array
85 function getRequestArray () {
86         return $GLOBALS['raw_request']['get'];
87 }
88
89 // Counts entries in $_GET or returns false if not an array
90 function countRequestGet () {
91         // By default this is not an array
92         $count = false;
93
94         // Get the array
95         $GET = getRequestArray();
96
97         // Is it an array?
98         if (is_array($GET)) {
99                 // Then count it
100                 $count = count($GET);
101         } // END - if
102
103         // Return value
104 }
105
106 // Setter for element in $_GET
107 function setGetRequestElement ($element, $value) {
108         // Escape both
109         $element = SQL_ESCAPE($element);
110         $value   = SQL_ESCAPE($value);
111
112         // Set in $_GET
113         $GLOBALS['raw_request']['get'][$element] = $value;
114
115         // Update cache
116         $GLOBALS['cache_request']['get'][$element] = $value;
117 }
118
119 // Wrapper for elements in $_POST
120 function postRequestElement ($element, $subElement = NULL) {
121         // By default no element is there
122         $value = NULL;
123
124         // Is the element in cache?
125         if (isset($GLOBALS['cache_request']['post'][$element][$subElement])) {
126                 // Then use it
127                 $value = $GLOBALS['cache_request']['post'][$element][$subElement];
128                 //* DEBUG: */ print $element.'/'.$subElement.'='.$value.'<br />';
129         } elseif (isPostRequestElementSet($element)) {
130                 // Then use it
131                 $value = $GLOBALS['raw_request']['post'][$element];
132
133                 // Is $subElement set?
134                 if ((!is_null($subElement)) && (isPostRequestElementSet($element, $subElement))) {
135                         // Then use this
136                         $value = SQL_ESCAPE($value[$subElement]);
137                         //* DEBUG: */ print 'sub!<br />';
138                 } elseif (!is_array($value)) {
139                         // Escape it here
140                         $value = SQL_ESCAPE($value);
141                         //* DEBUG: */ print 'no-array!<br />';
142                 }
143
144                 // Set it in cache
145                 //* DEBUG: */ print $element.'/'.$subElement.'='.$value.'<br />';
146                 //* DEBUG: */ print('<pre>'.print_r($_POST,true).'</pre>');
147                 $GLOBALS['cache_request']['post'][$element][$subElement] = $value;
148         } // END - if
149
150         // Return value
151         return $value;
152 }
153
154 // Checks if an element in $_POST exists
155 function isPostRequestElementSet ($element, $subElement = NULL) {
156         if (is_null($subElement)) {
157                 return ((isset($GLOBALS['raw_request']['post'][$element])) && (('' . $GLOBALS['raw_request']['post'][$element] . '') != ''));
158         } else {
159                 return ((isset($GLOBALS['raw_request']['post'][$element][$subElement])) && (('' . $GLOBALS['raw_request']['post'][$element][$subElement] . '') != ''));
160         }
161 }
162
163 // Removes an element from $_POST
164 function unsetPostRequestElement ($element) {
165         unset($GLOBALS['raw_request']['post'][$element]);
166 }
167
168 // Getter for whole $_POST array
169 function postRequestArray () {
170         return $GLOBALS['raw_request']['post'];
171 }
172
173 // Setter for whole $_POST array
174 function setPostRequestArray ($postData) {
175         $GLOBALS['raw_request']['post'] = $postData;
176 }
177
178 // Counts entries in $_POST or returns false if not an array
179 function countRequestPost () {
180         // By default this is not an array
181         $count = false;
182
183         // Get the array
184         $postData = postRequestArray();
185
186         // Is it an array?
187         if (is_array($postData)) {
188                 // Then count it
189                 $count = count($postData);
190         } // END - if
191
192         // Return value
193 }
194
195 // Setter for element in $_POST
196 function setPostRequestElement ($element, $value) {
197         // Is $element or $value an array?
198         if (is_array($element)) {
199                 // Set array
200                 $eval = "\$GLOBALS['raw_request']['post']['";
201
202                 // Add all entries
203                 $eval .= implode("']['", $element);
204
205                 // Finish eval() command
206                 $eval .= sprintf("'] = \"%s\";", SQL_ESCAPE($value));
207
208                 // And run it
209                 eval($eval);
210         } elseif (is_array($value)) {
211                 // Escape element
212                 $element = SQL_ESCAPE($element);
213
214                 // Value is an array so set it directly
215                 $GLOBALS['raw_request']['post'][$element] = $value;
216         } else {
217                 // Escape both
218                 $element = SQL_ESCAPE($element);
219                 $value   = SQL_ESCAPE($value);
220
221                 // Set regular entry
222                 $GLOBALS['raw_request']['post'][$element] = $value;
223         }
224
225         // Update cache
226         $GLOBALS['cache_request']['post'][$element][null] = $value;
227 }
228
229 // Checks wether a form was sent. If so, the $_POST['ok'] element must be set
230 function isFormSent ($requestParameter = 'ok') {
231         // Simply wrap it!
232         return isPostRequestElementSet($requestParameter);
233 }
234
235 // Checks if 'content_type' is set
236 function isContentTypeSet () {
237         return isset($GLOBALS['content_type']);
238 }
239
240 // Setter for content type
241 function setContentType ($contentType) {
242         $GLOBALS['content_type'] = (string) $contentType;
243 }
244
245 // Getter for content type
246 function getContentType () {
247         return $GLOBALS['content_type'];
248 }
249
250 // Getter for request URI
251 function getRequestUri () {
252         return $_SERVER['REQUEST_URI'];
253 }
254
255 // [EOF]
256 ?>