Code

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