740f7bd52eea4aeedb9fbe6e1b3f2521930b276f
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } // END - if
39
40 // Wrapper for elements in $_GET
41 function REQUEST_GET ($element) {
42         // By default no element is there
43         $value = null;
44
45         // Is the element cached or there?
46         if (isset($GLOBALS['cache_array']['request_get'][$element])) {
47                 // Then use the cache
48                 $value = $GLOBALS['cache_array']['request_get'][$element];
49         } elseif (REQUEST_ISSET_GET($element)) {
50                 // Then get it directly
51                 $value = SQL_ESCAPE($_GET[$element]);
52
53                 // Store it in cache
54                 $GLOBALS['cache_array']['request_get'][$element] = $value;
55         } // END - if
56
57         // Return value
58         return $value;
59 }
60
61 // Checks if an element in $_GET exists
62 function REQUEST_ISSET_GET ($element, $extra="") {
63         if (empty($extra)) {
64                 return (isset($_GET[$element]));
65         } else {
66                 return (isset($_GET[$element][$extra]));
67         }
68 }
69
70 // Removes an element from $_GET
71 function REQUEST_UNSET_GET ($element) {
72         unset($_GET[$element]);
73 }
74
75 // Getter for whole $_GET array
76 function REQUEST_GET_ARRAY () {
77         return $_GET;
78 }
79
80 // Counts entries in $_GET or returns false if not an array
81 function REQUEST_GET_COUNT () {
82         // By default this is not an array
83         $count = false;
84
85         // Get the array
86         $GET = REQUEST_GET_ARRAY();
87
88         // Is it an array?
89         if (is_array($GET)) {
90                 // Then count it
91                 $count = count($GET);
92         } // END - if
93
94         // Return value
95 }
96
97 // Setter for element in $_GET
98 function REQUEST_SET_GET ($element, $value) {
99         $_GET[SQL_ESCAPE($element)] = SQL_ESCAPE($value);
100 }
101
102 // Wrapper for elements in $_POST
103 function REQUEST_POST ($element) {
104         // By default no element is there
105         $value = null;
106
107         // Is the element there?
108         if (REQUEST_ISSET_POST($element)) {
109                 // Then use it
110                 $value = $_POST[$element];
111         } // END - if
112
113         // Return value
114         return $value;
115 }
116
117 // Checks if an element in $_POST exists
118 function REQUEST_ISSET_POST ($element, $extra="") {
119         if (empty($extra)) {
120                 return (isset($_POST[$element]));
121         } else {
122                 return (isset($_POST[$element][$extra]));
123         }
124 }
125
126 // Removes an element from $_POST
127 function REQUEST_UNSET_POST ($element) {
128         unset($_POST[$element]);
129 }
130
131 // Getter for whole $_POST array
132 function REQUEST_POST_ARRAY () {
133         return $_POST;
134 }
135
136 // Counts entries in $_POST or returns false if not an array
137 function REQUEST_POST_COUNT () {
138         // By default this is not an array
139         $count = false;
140
141         // Get the array
142         $POST = REQUEST_POST_ARRAY();
143
144         // Is it an array?
145         if (is_array($POST)) {
146                 // Then count it
147                 $count = count($POST);
148         } // END - if
149
150         // Return value
151 }
152
153 // Setter for element in $_POST
154 function REQUEST_SET_POST ($element, $value) {
155         if (is_array($element)) {
156                 // Set array
157                 $eval = "\$_POST['";
158
159                 // Add all entries
160                 $eval .= implode("', '", $element);
161
162                 // Finish eval() command
163                 $eval .= sprintf("'] = \"%s\";", SQL_ESCAPE($value));
164
165                 // And run it
166                 eval($eval);
167         } else {
168                 // Set regular entry
169                 $_POST[SQL_ESCAPE($element)] = SQL_ESCAPE($value);
170         }
171 }
172
173 // Checks wether a form was sent. If so, the $_POST['ok'] element must be set
174 function IS_FORM_SENT () {
175         // Simply wrap it!
176         return REQUEST_ISSET_POST('ok');
177 }
178
179 //
180 ?>