1 <?php
3 class filterDeviceItems {
5 static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "")
6 {
7 // Walk through the data array till we reach the correct level, then
8 // create the list of entries.
9 $data = session::get('DEVICE_ITEMS');
10 foreach($data as $id => $item){
11 if($item['base'] == $base){
12 $data = $item['children'];
13 break;;
14 }
15 }
17 // Prepare filter, strip out regex regex related chars, except for *
18 $filter = preg_replace('/\*/','____STAR____', $filter);
19 $filter = preg_quote($filter,'/');
20 $filter = preg_replace('/____STAR____/','.*', $filter);
22 // Add entries
23 $ret = array();
24 foreach($data as $item){
25 filterDeviceItems::addEntry($ret, $item, $scope == 'sub', $filter);
26 }
27 return($ret);
28 }
30 static function addEntry(&$ret, $item, $recursive = FALSE, $filter)
31 {
32 if(preg_match("/".$filter."/",$item['name'])){
33 $entry = array();
34 $entry['dn'] = $item['id'];
35 $entry[] = 'dn';
36 $entry['cn'] = array($item['name'], 'count' => 1);
37 $entry[] = 'cn';
38 $entry['id'] = array($item['id'], 'count' => 1);
39 $entry[] = 'id';
40 $entry['description'] = array($item['type'], 'count' => 1);
41 $entry[] = 'description';
42 $entry['objectClass'] = array($item['type'],'count' => 1);
43 $entry[] = 'objectClass';
44 $entry['count'] = 5;
45 $ret[] = $entry;
46 }
48 if($recursive && isset($item['children']) && count($item['children'])){
49 foreach($item['children'] as $item){
50 filterDeviceItems::addEntry($ret, $item, $recursive,$filter);
51 }
52 }
54 }
55 }
57 ?>