<?php
class SessionMgr { 
var $kSess = null; 
var $funcRead = ""; 
var $funcWrite = ""; 
var $funcDestroy = ""; 
var $funcGc = ""; 
var $funcTimeout = ""; 
function &getEngineObject(){ 
return $this->kSess; 
} 
function init($kerioId, $functions) { 
$this->kSess = kerio($kerioId); 
session_set_save_handler( 
Array(&$this, "open"), 
Array(&$this, "close"), 
Array(&$this, "read"), 
Array(&$this, "write"), 
Array(&$this, "destroy"), 
Array(&$this, "gc") 
); 
$funcNames = Array('read' => 'funcRead', 
'write' => 'funcWrite', 
'destroy' => 'funcDestroy', 
'gc' => 'funcGc', 
'timeout' => 'funcTimeout'); 
foreach ($funcNames as $index => $func) { 
if (array_key_exists($index, $functions)) { 
$this->$func = $functions[$index]; 
} 
} 
} 
function setTimeout($timeout){ 
if (!empty($this->funcTimeout)) { 
$func = $this->funcTimeout; 
$this->kSess->$func($timeout); 
} 
} 
function open($save_path, $session_name) { 
return true; 
} 
function close() { 
return true; 
} 
function read($id) { 
if (!empty($this->funcRead)) { 
$func = $this->funcRead; 
return $this->kSess->$func($id); 
} 
else { 
return ""; 
} 
} 
function write($id, $data) { 
if (!empty($this->funcWrite)) { 
$func = $this->funcWrite; 
return $this->kSess->$func($id, &$data); 
} 
else { 
return false; 
} 
} 
function destroy($id) { 
if (!empty($this->funcDestroy)) { 
$func = $this->funcDestroy; 
return $this->kSess->$func($id); 
} 
else { 
return false; 
} 
} 
function gc($maxlifetime) 
{ 
if (!empty($this->funcGc)) { 
$func = $this->funcGc; 
return $this->kSess->$func($maxlifetime); 
} 
else { 
return true; 
} 
} 
} 
?>