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 // Prepare filter and split it into attribute and value to search for
16 $filter=preg_replace("/\*/","",$filter);
17 $attr = $value = "";
18 if(!empty($filter) && preg_match("/=/", $filter)){
19 list($attr,$value) = preg_split("/=/", $filter);
20 }
22 // Simple filtering
23 if(!empty($attr)){
24 foreach($result as $key => $entry){
25 if(!preg_match("/".$value."/i", $entry[$attr][0])){
26 unset($result[$key]);
27 }
28 }
29 }
31 return(filterACL::unifyResult($result));
32 }
34 static function get_list($base, $filter, $attributes, $category, $objectStorage, $flags= GL_SUBSEARCH)
35 {
36 $config= session::global_get('config');
37 $si = new opsiLicenceHandler($config);
39 if(!$si->enabled()) return(array());
41 $res = $si->listPools();
42 $result = array();
43 if($si->is_error() || !is_array($res)){
44 $this->init_successfull = FALSE;
45 msg_dialog::display(_("Error"),msgPool::siError($si->get_error()),ERROR_DIALOG);
46 return;
47 }else{
49 // Reset the list of licenses
50 foreach($res as $item){
52 $item['objectClass'] = array('fake_opsiLicense');
54 // Fake an ldap entry, this enables ACL checks.
55 $entry = array();
56 $entry['dn'] = "opsi:cn=".$item['cn'][0].",".$config->current['BASE'];
57 foreach($item as $name => $value){
58 $entry[] = $name;
59 $entry[$name] = $value;
60 }
61 $entry['count'] = count($item);
62 $result[] = $entry;
63 }
64 }
65 return($result);
66 }
68 static function unifyResult($result)
69 {
70 $res=array();
71 foreach($result as $entry){
72 if(!isset($res[$entry['dn']])){
73 $res[$entry['dn']]=$entry;
74 }
75 }
76 return(array_values($res));
77 }
78 }
80 ?>