More globals rewritten, see ticket #100
[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_array']['request_get'][$element])) {
52                 // Then use the cache
53                 $value = $GLOBALS['cache_array']['request_get'][$element];
54         } elseif (REQUEST_ISSET_GET($element)) {
55                 // Then get it directly
56                 $value = SQL_ESCAPE($_GET[$element]);
57
58                 // Store it in cache
59                 $GLOBALS['cache_array']['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($_GET[$element]));
70         } else {
71                 return (isset($_GET[$element][$subElement]));
72         }
73 }
74
75 // Removes an element from $_GET
76 function REQUEST_UNSET_GET ($element) {
77         unset($_GET[$element]);
78 }
79
80 // Getter for whole $_GET array
81 function REQUEST_GET_ARRAY () {
82         return $_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         $_GET[SQL_ESCAPE($element)] = SQL_ESCAPE($value);
105 }
106
107 // Wrapper for elements in $_POST
108 function REQUEST_POST ($element, $subElement=null) {
109         // By default no element is there
110         $value = null;
111
112         // Is the element there?
113         if (REQUEST_ISSET_POST($element)) {
114                 // Then use it
115                 $value = $_POST[$element];
116
117                 // Is $subElement set?
118                 if ((!is_null($subElement)) && (REQUEST_ISSET_POST($element, $subElement))) {
119                         // Then use this
120                         $value = $value[$subElement];
121                 } // END - if
122         } // END - if
123
124         // Return value
125         return $value;
126 }
127
128 // Checks if an element in $_POST exists
129 function REQUEST_ISSET_POST ($element, $subElement=null) {
130         if (is_null($subElement)) {
131                 return (isset($_POST[$element]));
132         } else {
133                 return (isset($_POST[$element][$subElement]));
134         }
135 }
136
137 // Removes an element from $_POST
138 function REQUEST_UNSET_POST ($element) {
139         unset($_POST[$element]);
140 }
141
142 // Getter for whole $_POST array
143 function REQUEST_POST_ARRAY () {
144         return $_POST;
145 }
146
147 // Counts entries in $_POST or returns false if not an array
148 function REQUEST_POST_COUNT () {
149         // By default this is not an array
150         $count = false;
151
152         // Get the array
153         $POST = REQUEST_POST_ARRAY();
154
155         // Is it an array?
156         if (is_array($POST)) {
157                 // Then count it
158                 $count = count($POST);
159         } // END - if
160
161         // Return value
162 }
163
164 // Setter for element in $_POST
165 function REQUEST_SET_POST ($element, $value) {
166         if (is_array($element)) {
167                 // Set array
168                 $eval = "\$_POST['";
169
170                 // Add all entries
171                 $eval .= implode("', '", $element);
172
173                 // Finish eval() command
174                 $eval .= sprintf("'] = \"%s\";", SQL_ESCAPE($value));
175
176                 // And run it
177                 eval($eval);
178         } elseif (is_array($value)) {
179                 // Value is an array so set it directly
180                 $_POST[SQL_ESCAPE($element)] = $value;
181         } else {
182                 // Set regular entry
183                 $_POST[SQL_ESCAPE($element)] = SQL_ESCAPE($value);
184         }
185 }
186
187 // Checks wether a form was sent. If so, the $_POST['ok'] element must be set
188 function IS_FORM_SENT () {
189         // Simply wrap it!
190         return REQUEST_ISSET_POST('ok');
191 }
192
193 //
194 ?>