3
$DEFAULT_PROPS = array (
10
class REQUESTList implements Iterator {
17
function __construct(&$props, &$list, $cl = NULL) {
18
$this->props = &$props;
23
if ($cl) $this->cl = &$cl;
24
else $this->cl = "REQUEST";
27
function CreateDataRequest() {
28
return new DATARequest($this->props);
33
$this->cur = current($this->list);
37
$props = $this->props;
38
foreach ($this->cur as $key => $value) {
39
$props[$key] = $value;
41
return new $this->cl($props);
45
return key($this->list);
49
$this->cur = next($this->list);
53
return $this->cur?true:false;
60
function __construct(&$props = NULL) {
61
/* $f = fopen("/tmp/xxx.props", "a+");
62
fwrite($f, print_r($_GET, true));
63
fwrite($f, print_r($_POST, true));
66
if ($props) $this->props = $props;
68
if (isset($_GET["db_server"])) $this->props = $_GET;
69
else if (isset($_POST["db_server"])) $this->props = $_POST;
70
else if (isset($_POST["props"])) return $this->props = json_decode(stripslashes($_POST['props']), true);
71
else $this->props = array();
75
foreach ($DEFAULT_PROPS as $prop => $value) {
76
if (!isset($this->props[$prop]))
77
$this->props[$prop] = $value;
84
class REQUEST extends BASICRequest {
86
var $opts_custom = false;
89
const LIST_WILDCARDED = 2;
91
const READER_FORBID_CACHEREADER = 1;
93
function __construct(&$props = NULL) {
94
global $DEFAULT_PROPS;
96
parent::__construct($props);
99
function GetServerConfig() {
102
if (isset($this->props['db_server'])) {
103
$srvid = $this->props['db_server'];
104
if (isset($READER_DB[$srvid]))
105
return $READER_DB[$srvid];
107
throw new ADEIException(translate("Invalid server name is specified: \"%s\"", $srvid));
109
throw new ADEIException(translate("The data source server is not specified"));
112
function GetSourceList($flags = 0) {
115
if ((($flags&REQUEST::LIST_ALL)==0)&&(isset($this->props['db_server']))) {
116
$srvid = $this->props['db_server'];
117
if (isset($READER_DB[$srvid])) {
119
$srvlist[$srvid] = &$READER_DB[$srvid];
120
} else throw new ADEIException(translate("Invalid server name is specified: \"%s\"", $srvid));
122
$srvlist = &$READER_DB;
126
foreach ($srvlist as $srvid => &$srv) {
127
if ((($flags&REQUEST::LIST_ALL)==0)&&(isset($this->props['db_name']))) {
128
$db = $this->props['db_name'];
129
$list[$srvid . "__" . $db] = array(
130
'db_server' => $srvid,
134
if ($flags&REQUEST::LIST_WILDCARDED) {
135
if ($reader) $reader = &$rdr;
136
else $reader = $this->CreateReader();
137
$list = $reader->GetDatabaseList();
138
foreach (array_keys($list) as $db) {
139
$list[$srvid . "__" . $db] = array(
140
'db_server' => $srvid,
146
foreach ($srv['database'] as $db) {
147
$list[$srvid . "__" . $db] = array(
148
'db_server' => $srvid,
156
return new REQUESTList($this->props, $list, "SOURCERequest");
159
function GetOptions() {
160
if ($this->opts) return $this->opts;
162
$this->opts = new OPTIONS($this);
167
function GetGroupOptions(LOGGROUP &$grp = NULL) {
168
if (($grp)&&($grp->gid != $this->props['db_group'])) {
169
return GetCustomOptions($this->props['db_server'], $this->props['db_name'], $grp->gid);
173
$this->opts = new OPTIONS($this);
179
function GetCustomOptions($server = false, $db = false, $group = false) {
180
$id .= $server . "__" . $db . "__" . $group;
182
if (!$this->opts_custom) $this->opts_custom = array();
183
else if (isset($this->opts_custom[$id])) return $this->opts_custom[$id];
187
if ($server !== false) $req["db_server"] = $server;
188
if ($db !== false) $req["db_name"] = $db;
189
if ($group !== false) $req["db_group"] = $group;
191
$this->opts_custom[$id] = new OPTIONS($req);
192
return $this->opts_custom[$id];
195
function GetOption($prop) {
196
$opts = $this->GetOptions();
197
return $opts->Get($prop);
200
function GetGroupOption($prop, LOGGROUP &$grp = NULL) {
201
$opts = $this->GetGroupOptions($grp);
202
return $opts->Get($prop);
205
function GetCustomOption($prop, $server = false, $db = false, $group = false) {
206
$opts = $this->GetCustomOptions($server, $db, $group);
207
return $opts->Get($prop);
210
function GetQueryString(array &$ext = NULL) {
214
foreach (($ext?array_merge($this->props,$ext):$this->props) as $name => $value) {
215
if ($first) $first = 0;
218
$query .= $name . "=" . urlencode($value);
224
function CheckServer() {
225
if (!isset($this->props['db_server'])) return false;
228
function CheckSource() {
229
if (!$this->CheckServer()) return false;
230
if (!isset($this->props['db_name'])) return false;
233
function CheckGroup() {
234
if (!$this->CheckSource()) return false;
235
if (!isset($this->props['db_group'])) return false;
238
function CheckData() {
239
if (!$this->CheckGroup()) return false;
240
// if (!isset($this->props['db_mask'])) return false;
244
function CreateServerRequest() {
245
return new SERVERRequest($this->props);
247
function CreateSourceRequest() {
248
return new SOURCERequest($this->props);
250
function CreateGroupRequest() {
251
return new GROUPRequest($this->props);
253
function CreateDataRequest() {
254
return new DATARequest($this->props);
258
class SERVERRequest extends REQUEST {
261
function __construct(&$props = NULL) {
264
parent::__construct($props);
266
if (isset($this->props["db_server"]))
267
$srvid = $this->props["db_server"];
269
throw new ADEIException(translate("The data source server should be specified"));
271
if (is_array($READER_DB[$srvid]))
272
$this->srv = &$READER_DB[$srvid];
274
throw new ADEIException(translate("Invalid server identificator is supplied: \"%s\"", $srvid));
277
function GetServerInfo() {
278
$server = $this->srv;
279
if (isset($this->props['db_name'])) $server['database'] = $this->props['db_name'];
280
else unset($server['database']);
284
function CreateReader($flags = 0) {
285
if ($this->srv['disconnected']) {
286
if ($flags&REQUEST::READER_FORBID_CACHEREADER)
287
throw new ADEIException(translate("The data reader(%s) is disconnected", $this->srv['reader']));
289
return $this->CreateCacheReader();
290
} else if (($opts = $this->GetOptions())&&($opts->Get('use_cache_reader'))&&(!($flags&REQUEST::READER_FORBID_CACHEREADER))) {
291
return $this->CreateCacheReader();
293
$reader = $this->srv['reader'];
295
if (!include_once("readers/" . strtolower($reader) . '.php')) {
296
if ($this->srv['reader'])
297
throw new ADEIException(translate("Unsupported data reader is configured: \"%s\"", $this->srv['reader']));
299
throw new ADEIException(translate("The data reader is not configured"));
304
$rdr = new $reader($this);
305
} catch (ADEIException $ae) {
306
if ($flags&REQUEST::READER_FORBID_CACHEREADER) throw $ae;
308
if ($opts->Get('overcome_reader_faults')) {
309
$rdr = $this->CreateCacheReader();
316
function CreateCacheReader(CACHEDB &$cache = NULL) {
317
return new CACHEReader($this, $cache);
320
function GetLocationString() {
321
return "Server: \"" . $this->props['db_server'] . "\"";
326
class SOURCERequest extends SERVERRequest {
327
function __construct(&$props = NULL) {
328
parent::__construct($props);
330
if (!isset($this->props["db_name"]))
331
throw new ADEIException(translate("The database should be specified"));
334
function GetGroupList(READER &$rdr = NULL, $flags = 0) {
337
if (isset($this->props['db_group'])) {
338
$gid = $this->props['db_group'];
343
if ($rdr) $reader = &$rdr;
344
else $reader = $this->CreateReader();
345
$list = $reader->GetGroupList();
346
foreach (array_keys($list) as $gid) {
352
return new REQUESTList($this->props, $list, "GROUPRequest");
354
function GetLocationString() {
355
return "Server: \"" . $this->props['db_server'] . "\" Database: \"" . $this->props['db_name'] . "\"";
359
class GROUPRequest extends SOURCERequest {
360
function __construct(&$props = NULL) {
361
parent::__construct($props);
363
if (!isset($this->props["db_group"]))
364
throw new ADEIException(translate("The Logging Group should be specified"));
367
function GetGroupInfo() {
371
function GetMaskInfo() {
375
function CreateGroup(READER &$rdr) {
376
$ginfo = $this->GetGroupInfo();
377
return $rdr->CreateGroup($ginfo);
380
function CreateCache(READER &$rdr = NULL) {
381
return new CACHE($this, $rdr);
384
function CreateCacheUpdater(READER &$rdr = NULL) {
385
return new CACHE($this, $rdr, CACHE::CREATE_UPDATER);
388
function GetLocationString() {
389
return "Server: \"" . $this->props['db_server'] . "\" Database: " . $this->props['db_name'] . "\" Group: \"" . $this->props['db_group'] . "\"";
393
class DATARequest extends GROUPRequest {
394
function __construct(&$props = NULL) {
395
parent::__construct($props);
398
function GetIntervalInfo() {
402
function CreateInterval(READER &$rdr = NULL, LOGGROUP &$grp = NULL, $flags = 0) {
403
$iinfo = $this->GetIntervalInfo();
404
return new INTERVAL($iinfo, $rdr, $grp, $flags);
407
function GetFormatInfo() {
408
global $EXPORT_FORMATS;
409
global $EXPORT_DEFAULT_FORMAT;
411
$format = $this->props['format'];
413
if ($EXPORT_FORMATS[$format])
414
return $EXPORT_FORMATS[$format];
416
throw new ADEIException(translate("Unsupported export fromat (%s) is specified", $format));
417
} else if ($EXPORT_FORMATS[$EXPORT_DEFAULT_FORMAT])
418
return $EXPORT_FORMATS[$EXPORT_DEFAULT_FORMAT];
426
function CreateExporter(STREAMHandler &$h = NULL) {
427
if (!$h) $h = new STREAMHandler();
429
$format = $this->GetFormatInfo();
430
switch($format['type']) {
432
if ($format['handler']) {
433
if (!include_once("handlers/" . strtolower($format['handler']) . '.php')) {
434
throw new ADEIException(translate("Unsupported data handler is configured: \"%s\"", $format['handler']));
436
$handler = $format['handler'] . "Handler";
437
} else $handler = "CSVHandler";
439
$handler = new $handler($h, $format['opts']);
441
return HANDLERExport($this, $handler, $format);
444
return FILTERExport($this, $h, $format);
447
throw new ADEIException(translate("Unknown format type (%s)", $format['type']));
451
return new EXPORT($this, $h, $format);
456
function adeiCreateExporter(STREAMHandler &$h = NULL) {
457
$req = new DATARequest();
458
return $req->CreateExporter($h);
466
function GetGroupList($flags) {
468
function GetGroupInfo() {
471
function GetIntervalInfo() {
474
function CreateCache() {
b'\\ No newline at end of file'