Double->single converted and fixed a display bug when theme is already installed
[mailer.git] / inc / request-functions.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    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  * 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 - 2008 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         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } // END - if
44
45 // Wrapper for elements in $_GET
46 function REQUEST_GET ($element) {
47         // By default no element is there
48         $value = null;
49
50         // Is the element cached or there?
51         if (isset($GLOBALS['cache_request']['request_get'][$element])) {
52                 // Then use the cache
53                 $value = $GLOBALS['cache_request']['request_get'][$element];
54         } elseif (REQUEST_ISSET_GET($element)) {
55                 // Then get it directly
56                 $value = SQL_ESCAPE($GLOBALS['raw_request']['get'][$element]);
57
58                 // Store it in cache
59                 $GLOBALS['cache_request']['request_get'][$element] = $value;
60         } // END - if
61
62         // Return value
63         return $value;
64 }
65
66 // Checks if an element in $_GET exists
67 function REQUEST_ISSET_GET ($element, $subElement = '') {
68         if (empty($subElement)) {
69                 return ((isset($GLOBALS['raw_request']['get'][$element])) && (!empty($GLOBALS['raw_request']['get'][$element])));
70         } else {
71                 return ((isset($GLOBALS['raw_request']['get'][$element][$subElement])) && (!empty($GLOBALS['raw_request']['get'][$element][$subElement])));
72         }
73 }
74
75 // Removes an element from $_GET
76 function REQUEST_UNSET_GET ($element) {
77         unset($GLOBALS['raw_request']['get'][$element]);
78 }
79
80 // Getter for whole $_GET array
81 function REQUEST_GET_ARRAY () {
82         return $GLOBALS['raw_request']['get'];
83 }
84
85 // Counts entries in $_GET or returns false if not an array
86 function REQUEST_GET_COUNT () {
87         // By default this is not an array
88         $count = false;
89
90         // Get the array
91         $GET = REQUEST_GET_ARRAY();
92
93         // Is it an array?
94         if (is_array($GET)) {
95                 // Then count it
96                 $count = count($GET);
97         } // END - if
98
99         // Return value
100 }
101
102 // Setter for element in $_GET
103 function REQUEST_SET_GET ($element, $value) {
104         // Escape both
105         $element = SQL_ESCAPE($element);
106         $value   = SQL_ESCAPE($value);
107
108         // Set in $_GET
109         $GLOBALS['raw_request']['get'][$element] = $value;
110
111         // Update cache
112         $GLOBALS['cache_request']['request_get'][$element] = $value;
113 }
114
115 // Wrapper for elements in $_POST
116 function REQUEST_POST ($element, $subElement=null) {
117         // By default no element is there
118         $value = null;
119
120         // Is the element in cache?
121         if (isset($GLOBALS['cache_request']['request_post'][$element][$subElement])) {
122                 // Then use it
123                 $value = $GLOBALS['cache_request']['request_post'][$element][$subElement];
124         } elseif (REQUEST_ISSET_POST($element)) {
125                 // Then use it
126                 $value = $GLOBALS['raw_request']['post'][$element];
127
128                 // Is $subElement set?
129                 if ((!is_null($subElement)) && (REQUEST_ISSET_POST($element, $subElement))) {
130                         // Then use this
131                         $value = SQL_ESCAPE($value[$subElement]);
132                 } elseif (!is_array($value)) {
133                         // Escape it here
134                         $value = SQL_ESCAPE($value);
135                 }
136
137                 // Set it in cache
138                 $GLOBALS['cache_request']['request_post'][$element][$subElement] = $value;
139         } // END - if
140
141         // Return value
142         return $value;
143 }
144
145 // Checks if an element in $_POST exists
146 function REQUEST_ISSET_POST ($element, $subElement=null) {
147         if (is_null($subElement)) {
148                 return ((isset($GLOBALS['raw_request']['post'][$element])) && (!empty($GLOBALS['raw_request']['post'][$element])));
149         } else {
150                 return ((isset($GLOBALS['raw_request']['post'][$element][$subElement])) && (!empty($GLOBALS['raw_request']['post'][$element][$subElement])));
151         }
152 }
153
154 // Removes an element from $_POST
155 function REQUEST_UNSET_POST ($element) {
156         unset($GLOBALS['raw_request']['post'][$element]);
157 }
158
159 // Getter for whole $_POST array
160 function REQUEST_POST_ARRAY () {
161         return $GLOBALS['raw_request']['post'];
162 }
163
164 // Setter for whole $_POST array
165 function REQUEST_SET_POST_ARRAY (array $POST) {
166         $GLOBALS['raw_request']['post'] = $POST;
167 }
168
169 // Counts entries in $_POST or returns false if not an array
170 function REQUEST_POST_COUNT () {
171         // By default this is not an array
172         $count = false;
173
174         // Get the array
175         $POST = REQUEST_POST_ARRAY();
176
177         // Is it an array?
178         if (is_array($POST)) {
179                 // Then count it
180                 $count = count($POST);
181         } // END - if
182
183         // Return value
184 }
185
186 // Setter for element in $_POST
187 function REQUEST_SET_POST ($element, $value) {
188         // Is $element or $value an array?
189         if (is_array($element)) {
190                 // Set array
191                 $eval = "\$GLOBALS['raw_request']['post']['";
192
193                 // Add all entries
194                 $eval .= implode("']['", $element);
195
196                 // Finish eval() command
197                 $eval .= sprintf("'] = \"%s\";", SQL_ESCAPE($value));
198
199                 // And run it
200                 eval($eval);
201         } elseif (is_array($value)) {
202                 // Escape element
203                 $element = SQL_ESCAPE($element);
204
205                 // Value is an array so set it directly
206                 $GLOBALS['raw_request']['post'][$element] = $value;
207         } else {
208                 // Escape both
209                 $element = SQL_ESCAPE($element);
210                 $value   = SQL_ESCAPE($value);
211
212                 // Set regular entry
213                 $GLOBALS['raw_request']['post'][$element] = $value;
214         }
215
216         // Update cache
217         $GLOBALS['cache_request']['request_post'][$element] = $value;
218 }
219
220 // Checks wether a form was sent. If so, the $_POST['ok'] element must be set
221 function isFormSent () {
222         // Simply wrap it!
223         return REQUEST_ISSET_POST('ok');
224 }
225
226 // Initialize the request elements
227 function initRequest () {
228         $GLOBALS['raw_request']['get']  = $_GET;
229         $GLOBALS['raw_request']['post'] = $_POST;
230 }
231
232 //
233 ?>