1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php
class UIDLocator extends ADEIDB {
var $control; // flag indicating if we are looking for control uids
var $uid_array;
const UIDS_TABLE_SPEC = "`setup` CHAR(64), `control` BOOL, `uid` CHAR(128) NOT NULL, `item` VARCHAR(4096) NOT NULL, UNIQUE INDEX(`setup`, `control`, `uid`)";
function __construct($control = false) {
parent::__construct();
$this->control = $control;
$this->uid_array = false;
}
function FindUIDs() {
$res = array();
$flags = 0;
if ($this->control) $flags |= REQUEST::CONTROL;
$req = new REQUEST($tmp = array());
$groups = $req->GetGroups($flags);
foreach ($groups as $greq) {
$list = $greq->GetItemList($flags);
foreach ($list as $id => &$item) {
if (isset($item["uid"])) {
$uid = $item["uid"];
$res[$uid] = $greq->GetProps();
$res[$uid]['db_mask'] = $id;
}
}
}
return $res;
}
function UIDCreateTable() {
$this->CreateTable('uids', UIDLocator::UIDS_TABLE_SPEC);
}
function UIDAppend($uid, array &$item) {
global $ADEI_SETUP;
$this->AppendRecord('uids', array(
$ADEI_SETUP,
$this->control?1:0,
$uid,
SOURCETree::PropsToItem($item),
),
UIDLocator::UIDS_TABLE_SPEC,
array(3 => "item")
);
}
function UIDDelete($uid) {
global $ADEI_SETUP;
$this->DeleteRecord('uids', array(
'setup' => $ADEI_SETUP,
'control' => $this->control?1:0,
'uid' => $uid
));
}
function GetUIDs() {
global $ADEI_SETUP;
global $READER_DB;
$list = $this->SelectRequest('uids', array('uid', 'item'), array("columns_equal" => array(
'setup' => $ADEI_SETUP,
'control' => $this->control?1:0
)));
$res = array();
foreach ($list as $row) {
$uid = $row[0];
$props = SOURCETree::ItemToProps($row[1]);
if (isset($READER_DB[$props['db_server']]))
$res[$uid] = $props;
}
return $res;
}
function GetItem($uid) {
global $ADEI_SETUP;
$list = $this->SelectRequest('uids', array('item'), array("columns_equal" => array(
'setup' => $ADEI_SETUP,
'control' => $this->control?1:0,
'uid' => $uid
)));
if ($list) return SOURCETree::ItemToProps($list[0][0]);
else {
if (!$this->uid_array) $this->uid_array = $this->FindUIDs();
if (isset($this->uid_array[$uid])) return $this->uid_array[$uid];
return false;
}
}
function UpdateUIDs() {
$uids = $this->FindUIDs();
$db = $this->GetUIDs();
foreach ($uids as $uid => $prop) {
if (isset($db[$uid])) {
if (SOURCETree::PropsCmp($prop, $db[$uid])) {
$this->UIDAppend($uid, $prop);
}
unset($db[$uid]);
} else {
$this->UIDAppend($uid, $prop);
}
}
foreach ($db as $uid => &$value) {
$this->UIDDelete($uid);
}
}
}
?>
|