Extension ext-user for sub id tracking continued:
[mailer.git] / inc / request-functions.php
index 86db766d4273a63ad71a3637c01d3c053db839c6..e0051a169edc6da09958b57ae5ac2276f48452b9 100644 (file)
@@ -16,8 +16,8 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
@@ -47,15 +47,15 @@ function initRequest () {
 }
 
 // Wrapper for elements in $_GET
-function getRequestParameter ($element) {
+function getRequestElement ($element) {
        // By default no element is there
-       $value = null;
+       $value = NULL;
 
        // Is the element cached or there?
        if (isset($GLOBALS['cache_request']['get'][$element])) {
                // Then use the cache
                $value = $GLOBALS['cache_request']['get'][$element];
-       } elseif (isGetRequestParameterSet($element)) {
+       } elseif (isGetRequestElementSet($element)) {
                // Then get it directly
                $value = SQL_ESCAPE($GLOBALS['raw_request']['get'][$element]);
 
@@ -68,7 +68,7 @@ function getRequestParameter ($element) {
 }
 
 // Checks if an element in $_GET exists
-function isGetRequestParameterSet ($element, $subElement = '') {
+function isGetRequestElementSet ($element, $subElement = '') {
        if (empty($subElement)) {
                return ((isset($GLOBALS['raw_request']['get'][$element])) && ('' . ($GLOBALS['raw_request']['get'][$element] . '') != ''));
        } else {
@@ -77,7 +77,8 @@ function isGetRequestParameterSet ($element, $subElement = '') {
 }
 
 // Removes an element from $_GET
-function unsetGetRequestParameter ($element) {
+function unsetGetRequestElement ($element) {
+       unset($GLOBALS['cache_request']['get'][$element]);
        unset($GLOBALS['raw_request']['get'][$element]);
 }
 
@@ -104,7 +105,7 @@ function countRequestGet () {
 }
 
 // Setter for element in $_GET
-function setGetRequestParameter ($element, $value) {
+function setGetRequestElement ($element, $value) {
        // Escape both
        $element = SQL_ESCAPE($element);
        $value   = SQL_ESCAPE($value);
@@ -117,47 +118,64 @@ function setGetRequestParameter ($element, $value) {
 }
 
 // Wrapper for elements in $_POST
-function postRequestParameter ($element, $subElement=null) {
+function postRequestElement ($element, $subElement = NULL) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . gettype($element) . ']=' . $element . ',subElement[' . gettype($subElement) . ']=' . $subElement . ' - ENTERED!');
        // By default no element is there
-       $value = null;
+       $value = NULL;
 
        // Is the element in cache?
        if (isset($GLOBALS['cache_request']['post'][$element][$subElement])) {
                // Then use it
                $value = $GLOBALS['cache_request']['post'][$element][$subElement];
-       } elseif (isPostRequestParameterSet($element)) {
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . gettype($element) . ']=' . $element . ',subElement[' . gettype($subElement) . ']=' . $subElement . ',value[' . gettype($value) . ']=' . $value . ' - CACHE!');
+       } elseif (isPostRequestElementSet($element)) {
                // Then use it
                $value = $GLOBALS['raw_request']['post'][$element];
 
                // Is $subElement set?
-               if ((!is_null($subElement)) && (isPostRequestParameterSet($element, $subElement))) {
+               if ((!is_null($subElement)) && (isPostRequestElementSet($element, $subElement))) {
                        // Then use this
                        $value = SQL_ESCAPE($value[$subElement]);
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',subElement=' . $subElement . ' - SUB!');
                } elseif (!is_array($value)) {
                        // Escape it here
                        $value = SQL_ESCAPE($value);
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ' - REGULAR!');
                }
 
                // Set it in cache
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ',subElement=' . $subElement . ',value=' . $value.' - ADDED!');
                $GLOBALS['cache_request']['post'][$element][$subElement] = $value;
        } // END - if
 
        // Return value
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . gettype($element) . ']=' . $element . ',subElement[' . gettype($subElement) . ']=' . $subElement . ',value[' . gettype($value) . ']=' . $value . ' - EXIT!');
        return $value;
 }
 
 // Checks if an element in $_POST exists
-function isPostRequestParameterSet ($element, $subElement=null) {
+function isPostRequestElementSet ($element, $subElement = NULL) {
+       /*
+        * Always check that $element is a string and that $subElement is NULL or
+        * a string as numerical indexes are not wanted in POST data (in this
+        * project).
+        */
+       assert(is_string($element) && ((is_null($subElement)) || (is_string($subElement)) || (is_int($subElement))));
+
+       // Is a sub element set?
        if (is_null($subElement)) {
-               return ((isset($GLOBALS['raw_request']['post'][$element])) && (('' . $GLOBALS['raw_request']['post'][$element] . '') != ''));
+               // No, then only check $element
+               return ((isset($GLOBALS['raw_request']['post'][$element])) && ((is_array($GLOBALS['raw_request']['post'][$element])) || (('' . $GLOBALS['raw_request']['post'][$element] . '') != '')));
        } else {
+               // Yes, then check both together
                return ((isset($GLOBALS['raw_request']['post'][$element][$subElement])) && (('' . $GLOBALS['raw_request']['post'][$element][$subElement] . '') != ''));
        }
 }
 
 // Removes an element from $_POST
-function unsetPostRequestParameter ($element) {
+function unsetPostRequestElement ($element) {
        unset($GLOBALS['raw_request']['post'][$element]);
+       unset($GLOBALS['cache_request']['post'][$element]);
 }
 
 // Getter for whole $_POST array
@@ -185,10 +203,11 @@ function countRequestPost () {
        } // END - if
 
        // Return value
+       return $count;
 }
 
 // Setter for element in $_POST
-function setPostRequestParameter ($element, $value) {
+function setPostRequestElement ($element, $value) {
        // Is $element or $value an array?
        if (is_array($element)) {
                // Set array
@@ -221,30 +240,40 @@ function setPostRequestParameter ($element, $value) {
        $GLOBALS['cache_request']['post'][$element][null] = $value;
 }
 
-// Checks wether a form was sent. If so, the $_POST['ok'] element must be set
+// Checks whether a form was sent. If so, the $_POST['ok'] element must be set
 function isFormSent ($requestParameter = 'ok') {
        // Simply wrap it!
-       return isPostRequestParameterSet($requestParameter);
+       return isPostRequestElementSet($requestParameter);
 }
 
-// Checks if 'content_type' is set
-function isContentTypeSet () {
-       return isset($GLOBALS['content_type']);
-}
+// Getter for request URI
+function getRequestUri () {
+       // Is it not set?
+       if (!isset($_SERVER['REQUEST_URI'])) {
+               // Return empty string
+               return '';
+       } // END - if
 
-// Setter for content type
-function setContentType ($contentType) {
-       $GLOBALS['content_type'] = (string) $contentType;
+       // Return it
+       return $_SERVER['REQUEST_URI'];
 }
 
-// Getter for content type
-function getContentType () {
-       return $GLOBALS['content_type'];
-}
+// Add all GET parameters to a string (without leading sign)
+function addAllGetRequestParameters () {
+       // Init variable
+       $return = '';
 
-// Getter for request URI
-function getRequestUri () {
-       return $_SERVER['REQUEST_URI'];
+       // Now add all parameters
+       foreach (getRequestArray() as $key => $value) {
+               // Add it secured
+               $return .= SQL_ESCAPE($key) . '=' . SQL_ESCAPE($value) . '&';
+       } // END - foreach
+
+       // Remove trailing &
+       $return = substr($return, 0, -5);
+
+       // Return it
+       return $return;
 }
 
 // [EOF]