**/ class twIf_Interface { const LISTING_ITEMS_PER_PAGE = 20; const MSG_SAVED = 'All changes were saved successfully'; const MSG_SAVE_FAILED = 'The changes could not be saved'; const MSG_NO_CHANGES = 'No changed were made'; const MSG_EXCEPTION_FIELDS = 'Please check your input for the following fields:'; // How to append Parameters to URLs const MODE_PARAMETER = 0; const MODE_URL = 1; protected $urlMode = twIf_Interface::MODE_URL; private $Caption_Level = 0; private $Cache = null; private $Editors = array (); private $Exceptions = array (); protected $Base = ""; // {{{ setBase /** * Set current Base-URL * * @param string $Base * * @access public * @return void */ public function setBase ($Base) { $this->Base = $Base; if (($this->Base [strlen ($this->Base) - 1] != '/') && (strpos ($this->Base, '?') === false) && (substr ($this->Base, -5) != '.html') && ($this->urlMode != self::MODE_PARAMETER)) $this->Base .= '/'; } // }}} // {{{ getBase /** * Retrive assigned Base-URL * * @access public * @return string */ public function getBase ($Minimal = false) { return $this->Base; } // }}} // {{{ mergeDefinition /** * Safely merge two page-definitions into one single * * @param array $Def1 * @param array $Def2 * * @access public * @return array */ protected function mergeDefinition ($Def1, $Def2) { foreach ($Def2 as $Item) $Def1 [] = $Item; return $Def1; } // }}} // {{{ prepare /** * Prepare this interface for output * * @access public * @return bool **/ public function prepare () { $Definition = $this->cachedDefinition (); $Prepared = null; foreach ($Definition as $ID=>$Item) { switch ($Item ['Type']) { case 'Editor': $rc = self::prepareEditor ($Definition [$ID]); break; case 'Interface': $rc = self::prepareInterface ($Definition [$ID]); break; default: $rc = null; } if ($rc === false) return false; elseif ($rc === true) $Prepared = true; } if ($Prepared) $this->destroyDefinition (); return $Prepared; } // }}} // {{{ generate /** * Generate the Page-Output from definiton * * @access public * @return mixed */ public function generate ($Print = true) { if ($this->prepare () === false) return false; // Reload the definition if neccessary $Definition = $this->cachedDefinition (); $buf = '
\n"; // Generate foreach ($Definition as $Item) switch ($Item ['Type']) { case 'Caption': $buf .= self::generateCaption ($Item); break; case 'Box': $buf .= self::generateBox ($Item); break; case 'Block': $buf .= self::generateBlock ($Item); break; case 'Chooser': $buf .= self::generateChooser ($Item); break; case 'Navigation': $buf .= self::generateNavigation ($Item); break; case 'Listbox': $buf .= self::generateListbox ($Item); break; case 'Listing': $buf .= self::generateListing ($Item); break; case 'Editor': $buf .= self::generateEditor ($Item); break; case 'Image': $buf .= self::generateImage ($Item); break; case 'Feedback': $buf .= self::generateFeedback ($Item); break; case 'Interface': $buf .= self::embedInterface ($Item); break; default: $buf .= self::giveFeedback (false, 'Unknown Item-Type', null); break; } $buf .= "
\n"; if ($Print) print $buf; return $buf; } // }}} // {{{ cachedDefinition /** * Retrive a (cached) Page-Definition * * @access private * @return array **/ private function cachedDefinition () { if (!is_array ($this->Cache)) if (!is_array ($this->Cache = $this->getDefinition ())) $this->Cache = array (); return $this->Cache; } // }}} // {{{ destroyDefinition /** * Remove a cached page-definition * * @access private * @return void **/ private function destroyDefinition () { $this->Cache = null; } // }}} // {{{ generateCaption /** * Generate a caption * * @param array $Definition * * @access private * @return string */ private function generateCaption ($Item) { if ($Item ['Text'] == '') return; if (isset ($Item ['Subcaption']) && $Item ['Subcaption']) $this->Caption_Level++; elseif (!isset ($Item ['SameLevel']) || !$Item ['SameLevel']) $this->Caption_Level = max (0, $this->Caption_Level - 1); if (isset ($Item ['Main']) && $Item ['Main']) $Level = 1; else $Level = (2 + $this->Caption_Level); $buf = ''; if (isset ($Item ['LinkPrev']) && ($Item ['LinkPrev'] != '')) $buf .= '« '; $buf .= twIf_i18n::getText ($Item ['Text']); if (isset ($Item ['LinkNext']) && ($Item ['LinkNext'] != '')) $buf .= ' »'; $buf .= '\n"; return $buf; } // }}} // {{{ generateBox /** * Generate a plain HTML-Box * * @param array $Definition * * @access private * @return string */ private function generateBox ($Item) { return '' . twIf_i18n::getText ($Item ['Content']) . "\n"; } // }}} // {{{ generateBlock /** * Generate a text-block * * @param array $Definition * * @access private * @return string */ private function generateBlock ($Item) { if (is_array ($Item ['Text'])) $Items = $Item ['Text']; else $Items = array ($Item ['Text']); $buf = ""; foreach ($Items as $Label) if ($Label != '') $buf .= '

' . nl2br (twIf_i18n::getText ($Label)) . "

\n"; return $buf; } // }}} // {{{ generateChooser /** * Generate a simple link-list * * @param array $Definition * * @access private * @return string */ private function generateChooser ($Item) { if (count ($Item ['Items']) == 0) return ''; $buf = '
'; foreach ($Item ['Items'] as $Caption=>$Link) $buf .= '

' . twIf_i18n::getText ($Caption) . '

' . "\n"; return $buf . '
'; } // }}} // {{{ generateNavigation /** * Generate a small navi * * @param array $Definition * * @access private * @return string */ private function generateNavigation ($Item) { $Items = self::getArray ($Item ['Items']); if (count ($Items) < 1) return; $buf = '
'; foreach ($Items as $Item) { $Selected = (isset ($Item ['Selected']) && $Item ['Selected']); $Submenu = (isset ($Item ['Submenu']) && $Item ['Submenu']); if ($Item ['Caption'] == '-') $buf .= ' '; else $buf .= '' . twIf_i18n::getText ($Item ['Caption']) . ''; } return $buf . "
\n"; } // }}} // {{{ generateListbox /** * Generate a listbox from a set of objects * * @param array $Definition * * @access private * @return string **/ private function generateListbox ($Item) { require_once ('twIf/widget/listbox.php'); // Check if we do paging $Paging = isset ($Item ['Paging']) && $Item ['Paging']; $buf = ''; if (isset ($Item ['Class']) && ($Item ['Class'] != '')) $buf .= '
\n"; if ($Paging && isset ($Item ['Counter'])) { $Count = self::getFunction ($Item ['Counter']); $buf .= $Counter = self::printPageCounter ($Count, $this->getBase ()); $Filter = self::getPageCounter ($Count, $this->getBase ()); } else { $Count = null; $Filter = null; } // Load all required data for the listbox $Items = self::getArray ($Item ['Source'], $Filter); $Fields = self::getArray ($Item ['Fields']); $Link = (isset ($Item ['Link']) ? $Item ['Link'] : null); $buf .= twIf_Widget_Listbox::generateListbox ($Items, $Fields, $Link); // Output tailing counter if ($Count > 0) $buf .= $Counter; if (isset ($Item ['Class']) && ($Item ['Class'] != '')) $buf .= "
\n"; return $buf; } // }}} // {{{ generateListing /** * Generate an object-listing * * @param array $Definition * * @access private * @return void */ private function generateListing ($Item) { require_once ('twIf/widget/table.php'); $Paging = isset ($Item ['Paging']) && $Item ['Paging']; $buf = ""; if ($Paging && isset ($Item ['Counter'])) { $Count = self::getFunction ($Item ['Counter']); $buf .= $Counter = self::printPageCounter ($Count, $this->getBase ()); $Filter = self::getPageCounter ($Count, $this->getBase ()); } else { $Count = null; $Filter = null; } $Items = self::getArray ($Item ['Source'], $Filter); $Fields = self::getArray ($Item ['Fields']); if (isset ($Item ['Options'])) $Options = self::getArray ($Item ['Options']); else $Options = array (); if (isset ($Item ['Highlight'])) $Highlight = self::getArray ($Item ['Highlight']); else $Highlight = array (); if (isset ($Item ['SortParams'])) $SortParams = self::getArray ($Item ['SortParams']); else $SortParams = null; if (isset ($Item ['Group'])) $Group = $Item ['Group']; else $Group = null; $Enable = isset ($Item ['EnableToggle']) && $Item ['EnableToggle']; $Header = !isset ($Item ['ShowHeader']) || $Item ['ShowHeader']; $Select = isset ($Item ['EnableSelect']) && $Item ['EnableSelect']; $selectFunc = (isset ($Item ['Select']) ? $Item ['Select'] : null); if ($Select) $buf .= '
\n" . '\n"; $buf .= twIf_Widget_Table::generateTable ($Items, $Fields, $Options, $Highlight, $Enable, $Select, $this->getBase (), $SortParams, $Group, $Header, $selectFunc); if ($Select) $buf .= '
\n" . "
\n"; if ($Count > 0) $buf .= $Counter; return $buf; } // }}} // {{{ getPageCounter /** * Generate all neccessary information to draw the page-counter * * @param int $Count Count of the items * * @access protected * @return array **/ protected function getPageCounter ($Count) { // Check if there is at least one item if ($Count < 1) return array (0, 0); // Build Cookie UUID $cookieURL = self::getPageUUID (); // Retrive defaults $C = intval (isset ($_GET ['C']) ? $_GET ['C'] : (isset ($_SESSION [$cookieURL . '_C']) ? $_SESSION [$cookieURL . '_C'] : self::LISTING_ITEMS_PER_PAGE)); $P = max (1, intval (isset ($_GET ['P']) ? $_GET ['P'] : (isset ($_SESSION [$cookieURL . '_P']) ? $_SESSION [$cookieURL . '_P'] : 0))); $c = max (self::LISTING_ITEMS_PER_PAGE, $C); $p = ceil ($Count / $c); $s = max (0, ($P - 1) * $c); if ($s > $Count) $s = max (0, $Count - $c); if (($p < 2) || ($C == 0)) return array (0, 0); return array ($s, $c); } // }}} // {{{ printPageCounter /** * Output a simple page-counter and return values for listing-retrival * * @param int $Count * @param string $URL * * @access private * @return string **/ private function printPageCounter ($Count, $URL) { // Check if there is at least one item if ($Count < 1) return ''; // Ensure that there is a session if (count ($_SESSION) == 0) session_start (); // Handle some URL-Stuff if (strpos ($URL, '?') === false) $URL .= '?'; else $URL .= '&'; // Build Cookie UUID $cookieURL = self::getPageUUID (); // Retrive defaults $C = intval (isset ($_GET ['C']) ? $_GET ['C'] : (isset ($_SESSION [$cookieURL . '_C']) ? $_SESSION [$cookieURL . '_C'] : self::LISTING_ITEMS_PER_PAGE)); $P = max (1, intval (isset ($_GET ['P']) ? $_GET ['P'] : (isset ($_SESSION [$cookieURL . '_P']) ? $_SESSION [$cookieURL . '_P'] : 0))); $c = max (self::LISTING_ITEMS_PER_PAGE, $C); $p = ceil ($Count / $c); // Output the counter if (($p < 2) || ($C == 0)) return ''; // Output the counter $Counter = ($c != self::LISTING_ITEMS_PER_PAGE ? '&C=' . $c : ''); $_SESSION [$cookieURL . '_C'] = $C; $_SESSION [$cookieURL . '_P'] = $P; $buf = '
' . twIf_i18n::getText ('Page:') . ' ' . ($P > 1 ? '' : '') . '«' . ($P > 1 ? '' : '') . ' '; $l = 0; for ($i = 1; $i < $p + 1; $i++) if (($i < 4) || ($i > $p - 3) || (abs ($P - $i) < 6)) { if ($i - $l > 1) $buf .= ' ... '; $buf .= ($P != $i ? '' : '') . $i . ($i != $P ? '' : '') . ' '; $l = $i; } $buf .= ($P < $p ? '' : '') . '»' . ($P < $p ? '' : ''); for ($i = 1; $i < 4; $i++) { $V = $i * self::LISTING_ITEMS_PER_PAGE; $buf .= ' [' . ($V != $c ? '' : '') . $V . ($V != $c ? '' : '') . ']'; if ($V > $Count) break; } return $buf . '
'; } // }}} // {{{ getPageUUID /** * Generate a unique identifier for this page * * @access public * @return string **/ public function getPageUUID () { $Base = $this->getBase (true); if ($Base [0] != '/') $Base = dirname ($_SERVER ['PHP_SELF']) . '/' . $Base; $Base = md5 ($Base); return $Base; } // }}} // {{{ generateEditor /** * Generate an object-editor * * @param array $Definition * * @access private * @return string */ private function generateEditor ($Item) { require_once ('twIf/widget/object.php'); // Determine our mode if (!isset ($Item ['Mode'])) { if ($New = !is_object ($Object = self::getObject ($Item ['Source']))) $Object = $Item ['Source']; } elseif ($New = ($Item ['Mode'] == 'new')) { $Object = $Item ['Source']; } else $Object = self::getObject ($Item ['Source']); // Get all required information $Fields = self::getArray ($Item ['Fields']); // Determine which class we are handling if ($New) $Class = $Object; else $Class = get_class ($Object); $buf = ''; // Handle possible results if (isset ($this->Exceptions [$Class])) $Ex = $this->Exceptions [$Class]; else $Ex = null; if (!isset ($Item ['Feedback']) || $Item ['Feedback']) { if (($this->Editors [$Class] === true) || is_object ($this->Editors [$Class])) $buf .= self::giveFeedback (true, (isset ($Item ['msgSaved']) ? $Item ['msgSaved'] : self::MSG_SAVED), $Item ['SuccessURL']); elseif (isset ($this->Editors [$Class]) && ($this->Editors [$Class] === 2)) { $Text = twIf_i18n::getText (isset ($Item ['msgSaveFailed']) ? $Item ['msgSaveFailed'] : self::MSG_SAVE_FAILED); if (is_object ($Ex) && is_array ($F = $Ex->getFields ())) { $Text .= '

' . twIf_i18n::getText (self::MSG_EXCEPTION_FIELDS) . '

'; } $buf .= self::giveFeedback (false, $Text, null); } elseif (isset ($this->Editors [$Class]) && ($this->Editors [$Class] === null) && !$New) $buf .= self::giveFeedback (true, (isset ($Item ['msgNoChanges']) ? $Item ['msgNoChanges'] : self::MSG_NO_CHANGES), null); } if (isset ($Item ['msgSubmit'])) $Caption = $Item ['msgSubmit']; elseif ($New) $Caption = twIf_Widget_Object::CREATE_CAPTION; else $Caption = twIf_Widget_Object::EDIT_CAPTION; // Output the formular if ($New) $buf .= twIf_Widget_Object::newObject ($Object, $Fields, $this->getBase (), $Ex, $Caption); else $buf .= twIf_Widget_Object::editObject ($Object, $Fields, $this->getBase (), $Ex, $Caption); return $buf; } // }}} // {{{ prepareEditor /** * Run some tasks before generating the editor * * @param array $Item * * @access private * @return bool * @todo Remove dependencies **/ private function prepareEditor (&$Item) { require_once ('twIf/widget/object.php'); // Determine our mode if (!isset ($Item ['Mode'])) { if ($New = !is_object ($Object = self::getObject ($Item ['Source']))) $Object = $Item ['Source']; } elseif ($New = ($Item ['Mode'] == twIf_Widget_Object::MODE_CREATE)) { $Object = $Item ['Source']; } else $Object = self::getObject ($Item ['Source']); // Determine which class we are handling if ($New) $Class = $Object; else $Class = get_class ($Object); // Check if we are already prepared if (isset ($this->Editors [$Class])) return null; // Set initial state $this->Editors [$Class] = false; // Get all required information $Fields = self::getArray ($Item ['Fields']); // Try to save try { if ($New) $this->Editors [$Class] = twIf_Widget_Object::createObject ($Object, $Fields, self::getArray ($Item ['Constructor']), (!isset ($Item ['Strict']) || $Item ['Strict'])); else $this->Editors [$Class] = twIf_Widget_Object::saveObject ($Object, $Fields); } catch (twIf_Validator_Error $Error) { $this->Exceptions [$Class] = $Error; $this->Editors [$Class] = 2; } if (($this->Editors [$Class] === false) && twIf_Widget_Object::haveData ($Object)) $this->Editors [$Class] = 2; if (isset ($Item ['onSuccess']) && (is_object ($this->Editors [$Class]) || ($this->Editors [$Class] === true))) return self::getFunction ($Item ['onSuccess'], ($New ? $this->Editors [$Class] : $Object)); return null; } // }}} // {{{ prepareInterface /** * Forward prepare-request to any subclass * * @param array $Item * * @access private * @return bool **/ private function prepareInterface (&$Item) { if (!is_object ($Item ['Class'])) return null; return $Item ['Class']->prepare (); } // }}} // {{{ generateImage /** * Embed an image in page * * @param array $Item * * @access private * @return string */ private function generateImage ($Item) { // Retrive Image-Information $Source = self::getArray ($Item ['Source']); // Check for a valid Image-Handle if (!is_resource ($Source ['Handle'])) return; // Check dimensions of image if (!isset ($Source ['Width'])) $Source ['Width'] = imagesx ($Source ['Handle']); if (!isset ($Source ['Height'])) $Source ['Height'] = imagesy ($Source ['Handle']); // Generate the image $buf = ob_get_clean (); ob_start (); switch ($Source ['MIME']) { case 'image/jpeg': // Write the image to disk imagePNG ($Source ['Handle']); break; case 'image/gif': // Try to write GIF-Image if (function_exists ('imageGIF')) { imageGIF ($Source ['Handle']); break; } case 'image/png': default: // Just to be sure $Source ['MIME'] = 'image/png'; // Write the image to disk imagePNG ($Source ['Handle']); } // Read the image from buffer $Data = ob_get_clean (); $Size = strlen ($Data); // Restart output-buffering ob_start (); print $buf; // Embed the image if (!isset ($Source ['Caption'])) $Source ['Caption'] = 'Embeded image (' . $Size . ' bytes)'; return '

' . $Source ['Caption'] . '

\n"; } // }}} // {{{ generateFeedback /** * Use ISP_Web-Feedback-Functions * * @param array $Item * * @access private * @return string */ private function generateFeedback ($Item) { $Message = $Item ['Message']; $URL = (!isset ($Item ['URL']) || ($Item ['URL'] == '') ? null : $Item ['URL']); return self::giveFeedback ($Item ['Success'], $Message, $URL); } // }}} // {{{ embedInterface /** * Generate items of a subclass * * @access private * @return string */ private function embedInterface ($Item) { if (!is_object ($Item ['Class'])) return self::giveFeedback (false, 'Failed to generate Interface', null); return $Item ['Class']->generate (false); } // }}} // {{{ giveFeedback /** * Give a visual feedback * * @param bool $isSuccess * @param string $Message * @param string $URL * * @access private * @return string **/ private function giveFeedback ($isSuccess, $Message, $URL = null) { if ($Message == '') return ''; $buf = '
\n" . "

\n"; $M = explode ("\n", $Message); foreach ($M as $L) $buf .= ' ' . twIf_i18n::getText (trim ($L)) . "
\n"; $buf .= '

'; if ($URL !== null) { $buf .= "

\n" . ' Zurück\n" . "

\n"; } else $buf .= "\n"; return $buf . "
\n"; } // }}} // {{{ getDefinition /** * Just a dummy * * @access public * @return void */ public function getDefinition () { return array ( array ('Type' => 'Block', 'Text' => 'You need to fix this class. It does not work.'), ); } // }}} // {{{ getFunction /** * Try to access a given function on this object * * @param string $Function * @param array $Params (optional) * * @access private * @return mixed */ private function getFunction ($Name, $Params = array ()) { // Check for an empty function if ($Name == '') { trigger_error (twIf_i18n::getText ('Function-label must not be empty')); return; } // Create the callback if (is_array ($Name)) $Callback = $Name; else $Callback = array ($this, $Name); if (!is_callable ($Callback)) { if (is_object ($Callback [0])) $CB = get_class ($Callback [0]) . '::' . $Callback [1]; else $CB = $Callback [0] . '::' . $Callback [1]; trigger_error (twIf_i18n::getText ('Function %s is not callable', $CB)); return; } // Run the callback return call_user_func ($Callback, $Params); } // }}} // {{{ getArray /** * Try to get an array from a configuration value (pre-filled or by function-call) * * @param mixed $Pointer Value from configuration (callback or array) * @param array $Filter (optional) Parameters for callback * * @access private * @return array */ private function getArray ($Pointer, $Filter = array ()) { // Return an empty array if pointer is empty (this sometimes happen ;)) if ($Pointer === null) return array (); // Check wheter this is not a function-call but an pre-filled array if (is_array ($Pointer) && ((count ($Pointer) != 2) || !is_object ($Pointer [0]) || !is_string ($Pointer [1]))) return $Pointer; // Run the function $rc = self::getFunction ($Pointer, $Filter); // Convert the result to an array if (!is_array ($rc) && !($rc instanceof Traversable)) { if ($rc === null) return array (); return array ($rc); } return $rc; } // }}} // {{{ getObject /** * Try to get an object from a configuration value * * @param mixed $Pointer * * @see ISP_Interface::getArray * * @access private * @return object */ private function getObject ($Pointer) { if (is_object ($Pointer)) return $Pointer; return self::getFunction ($Pointer); } // }}} // {{{ regenerateURL /** * Generate a full URL * * @param string $URL (optional) * @param array $Params (optional) * * @access public * @return string **/ public static function regenerateURL ($URL = null, $Params = null) { // Generate our base-URL if ($URL === null) { if (($p = strpos ($_SERVER ['REQUEST_URI'], '?')) !== false) $URL = substr ($_SERVER ['REQUEST_URI'], 0, $p); else $URL = $_SERVER ['REQUEST_URI']; } // Generate the QueryString if (!is_array ($Params)) $Params = $_GET; $QS = ''; if (count ($Params) > 0) { $QS = '?'; foreach ($Params as $Key=>$Value) $QS .= urlencode ($Key) . '=' . urlencode (stripslashes ($Value)) . '&'; $QS = substr ($QS, 0, -1); } // Concatenate the URL return $URL . $QS; } // {{{ insertURLParameter /** * Safely insert a given parameter into a given URL * * @param string $Parameter * @param string $Value (optional) * @param string $URL (optional) * @param bool $ignoreEncoding (optional) * * @access public * @return string **/ public static function insertURLParameter ($Parameter, $Value = null, $URL = null, $ignoreEncoding = false) { // Make sure we have an URL given if ($URL === null) $URL = self::regenerateURL (); // Try to auto-detect value if neccessary if ($Value === null) { if (!isset ($_GET [$Parameter])) return $URL; $Value = $_GET [$Parameter]; } # TODO: Check if parameter was already set // Append the parameter to URL if (($p = strpos ($URL, '?')) !== false) { $Query = explode ('&', substr ($URL, $p + 1)); $URL = substr ($URL, 0, $p + 1); $Params = array (); foreach ($Query as $String) { if (($p = strpos ($String, '=')) !== false) { $Property = substr ($String, 0, $p); $Val = substr ($String, $p + 1); } else { $Property = $String; $Val = null; } if ($Property != $Parameter) $URL .= $Property . ($Val !== null ? '=' . $Val : '') . '&'; } } else $URL .= '?'; $URL .= $Parameter . '=' . ($ignoreEncoding ? $Value : urlencode ($Value)); return $URL; } // }}} // {{{ sendFile /** * Genreate a download instead of a webpage * * @param string $Content * @param string $Mime (optional) * @param string $Filename (optional) * * @access protected * @return void **/ protected function sendFile ($Content, $Mime = 'application/octet-stream', $Filename = null) { // Try to auto-generate filename if ($Filename === null) switch ($Mime) { case 'application/pdf': $Filename = 'document.pdf'; break; case 'application/msword': $Filename = 'document.doc'; break; } // Empty current output-buffer @ob_end_clean (); // Append the header header ('Content-Length: ' . strlen ($Content)); header ('Content-Type: ' . $Mime . (($n = strlen ($Filename)) > 0 ? '; name="' . $Filename . '"' : '')); header ('Content-Disposition: attachment' . ($n > 0 ? '; filename="' . $Filename . '"' : '')); // Output the file echo $Content; exit (0); } // }}} // {{{ storeValue /** * Store a given value into our session * * @param string $Name * @param mixed $Value * @param bool $Overwrite (optional) Allow to overwrite * @param bool $Global (optional) Store in global scope * * @access protected * @return bool **/ protected function storeValue ($Name, $Value, $Overwrite = true, $Global = false) { // Prefix the name with our UUID when not in global scope if (!$Global) $Name = self::getPageUUID () . '_' . $Name; // Check if session was started if (count ($_SESSION) == 0) session_start (); // Check if a value by that name is already stored if (isset ($_SESSION [$Name]) && !$Overwrite) return ($_SESSION [$Name] == $Value); // Store the value on session $_SESSION [$Name] = $Value; return true; } // }}} // {{{ retriveValue /** * Retrive a stored value from our session * * @param string $Name * @param mixed $Default (optional) Return this as default value * @param bool $Global (optional) Fallback to global scope * * @access protected * @return mixed **/ protected function retriveValue ($Name, $Default = null, $Global = false) { // Retrive our UUID $UUID = self::getPageUUID (); // Check if session was started if (count ($_SESSION) == 0) session_start (); // Check if there is a value stored for our UUID $Key = $UUID . '_' . $Name; if (isset ($_SESSION [$Key])) return $_SESSION [$Key]; // Look in global scope or return default if (!$Global || !isset ($_SESSION [$Name])) return $Default; return $_SESSION [$Name]; } // }}} // {{{ unsetValue /** * Remove a stored value from our session * * @param string $Name * @param bool $Global (optional) * * @access protected * @return bool **/ protected function unsetValue ($Name, $Global = false) { // Check if session was started if (count ($_SESSION) == 0) session_start (); // Prefix the name with our UUID when not in global scope if (!$Global) $Name = self::getPageUUID () . '_' . $Name; // Check if a value by that name is stored if (!isset ($_SESSION [$Name])) return false; // Remove the value and return success unset ($_SESSION [$Name]); return true; } // }}} } // Some hacks for pre-5.3 PHP if (!defined ('E_USER_DEPRECATED')) define ('E_USER_DEPRECATED', E_USER_NOTICE); ?>