1<?php 2/******************************** 3OSBib: 4A collection of PHP classes to create and manage bibliographic formatting for OS bibliography software 5using the OSBib standard. 6 7Released through http://bibliophile.sourceforge.net under the GPL licence. 8Do whatever you like with this -- some credit to the author(s) would be appreciated. 9 10If you make improvements, please consider contacting the administrators at bibliophile.sourceforge.net 11so that your improvements can be added to the release package. 12 13Adapted from WIKINDX: http://wikindx.sourceforge.net 14 15Mark Grimshaw 2005 16http://bibliophile.sourceforge.net 17********************************/ 18/** 19* Session functions 20* 21* @author Mark Grimshaw 22* 23* $Header: /cvsroot/bibliophile/OSBib/create/SESSION.php,v 1.1 2005/06/20 22:26:51 sirfragalot Exp $ 24*/ 25class SESSION 26{ 27// Constructor 28 function SESSION() 29 { 30 if(isset($_SESSION)) 31 $this->sessionVars = &$_SESSION; 32 } 33// Set a session variable 34 function setVar($key, $value) 35 { 36 if(!isset($key) || !isset($value)) return false; 37 $this->sessionVars[$key] = $value; 38 if(!isset($this->sessionVars[$key])) 39 { 40 return false; 41 } 42 return true; 43 } 44// Get a session variable 45 function getVar($key) 46 { 47 if(isset($this->sessionVars[$key])) 48 return $this->sessionVars[$key]; 49 return false; 50 } 51// Delete a session variable 52 function delVar($key) 53 { 54 if(isset($this->sessionVars[$key])) 55 unset($this->sessionVars[$key]); 56 } 57// Is a session variable set? 58 function issetVar($key) 59 { 60 if(isset($this->sessionVars[$key])) return true; 61 return false; 62 } 63// Destroy the whole session 64 function destroy() 65 { 66 $this->sessionVars = array(); 67 } 68// Return an associative array of all session variables starting with $prefix_. 69// key in returned array is minus the prefix to aid in matching database table fields. 70 function getArray($prefix) 71 { 72 $prefix .= '_'; 73 foreach($this->sessionVars as $key => $value) 74 { 75 if(preg_match("/^$prefix(.*)/", $key, $matches)) 76 $array[$matches[1]] = $value; 77 } 78 if(isset($array)) 79 return $array; 80 return FALSE; 81 } 82// Write to session variables named with $prefix_ the given associative array 83 function writeArray($row, $prefix = FALSE) 84 { 85 foreach($row as $key => $value) 86 { 87 if(!$value) 88 $value = FALSE; 89 if($prefix) 90 { 91 if(!$this->setVar($prefix . '_' . $key, $value)) 92 return FALSE; 93 } 94 else 95 { 96 if(!$this->setVar($key, $value)) 97 return FALSE; 98 } 99 } 100 return TRUE; 101 } 102// Clear session variables named with $prefix 103 function clearArray($prefix) 104 { 105 $prefix .= '_'; 106 foreach($this->sessionVars as $key => $value) 107 { 108 if(preg_match("/^$prefix/", $key)) 109 $this->delVar($key); 110 } 111 } 112} 113?> 114