1 <?php
3 class filterOpsiLicense {
5 static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "")
6 {
8 if(!class_available('opsi')) return(array());
10 $config= session::global_get('config');
11 $ldap= $config->get_ldap_link(TRUE);
12 $flag= ($scope == "sub")?GL_SUBSEARCH:0;
13 $result= filterOpsiLicense::get_list($base, $filter, $attributes, $category, $objectStorage, $flag);
15 // Simple filtering
16 if(!empty($filter)){
17 foreach($result as $key => $entry){
18 if(!preg_match($filter, $entry['cn'][0])){
19 unset($result[$key]);
20 }
21 }
22 }
24 return(filterACL::unifyResult($result));
25 }
27 static function get_list($base, $filter, $attributes, $category, $objectStorage, $flags= GL_SUBSEARCH)
28 {
29 $config= session::global_get('config');
30 $si = new opsiLicenceHandler($config);
32 if(!$si->enabled()) return(array());
34 $res = $si->listPools();
35 $result = array();
36 if($si->is_error() || !is_array($res)){
37 $this->init_successfull = FALSE;
38 msg_dialog::display(_("Error"),msgPool::siError($si->get_error()),ERROR_DIALOG);
39 return;
40 }else{
42 // Reset the list of licenses
43 foreach($res as $item){
45 $item['objectClass'] = array('fake_opsiLicense');
47 // Fake an ldap entry, this enables ACL checks.
48 $entry = array();
49 $entry['dn'] = "opsi:cn=".$item['cn'][0].",".$config->current['BASE'];
50 foreach($item as $name => $value){
51 $entry[] = $name;
52 $entry[$name] = $value;
53 }
54 $entry['count'] = count($item);
55 $result[] = $entry;
56 }
57 }
58 return($result);
59 }
61 static function unifyResult($result)
62 {
63 $res=array();
64 foreach($result as $entry){
65 if(!isset($res[$entry['dn']])){
66 $res[$entry['dn']]=$entry;
67 }
68 }
69 return(array_values($res));
70 }
71 }
73 ?>