Code

Backport from trunk
[gosa.git] / gosa-plugins / fai / admin / fai / class_filterOPSIPackages.inc
1 <?php
3 class filterOPSIPackages extends filterLDAP{
5   static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "")
6   {
7     global $config;
8     $ui = get_userinfo();
9     $ldap = $config->get_ldap_link();
10     $ldap->cd($config->current['BASE']);
11     $entries = array();
13     // Append opsi stuff ...
14     if(class_available('opsi') && $base == get_ou("faiManagement", "faiBaseRDN").$config->current['BASE']){
15       $opsi = new opsi($config);
16       $objects = array();
17       if($opsi instanceof opsi && $opsi->enabled()){
18         $opsi_acl = $ui->get_permissions($base,"opsi/opsiProperties");
19         if(preg_match("/r/",$opsi_acl)){
20           $err = FALSE;
22           $n_pro = $opsi->get_netboot_products();
23           $err |= $opsi->is_error();
24           foreach($n_pro as $name => $data){
25             $entry = array(
26                 "cn" => $name,
27                 "description" => $data['DESC'],
28                 "type" => "opsi_netboot");
29             $objects[$name]['opsi_netboot'] = $entry;
30           }
31           $l_pro = $opsi->get_local_products();
32           $err |= $opsi->is_error();
33           foreach($l_pro as $name => $data){
34             $entry = array("cn" => $name,
35                 "description" => $data['DESC'],
36                 "type" => "opsi_local");
37             $objects[$name]["opsi_local"] = $entry;
38           }
39           if($err){
40             msg_dialog::display(_("Error"),msgPool::siError($opsi->get_error()),ERROR_DIALOG);
41           }
42         }
43       }
45       // Parse filter string 
46       list($type,$filter) = preg_split("/;/",$filter);
47       $types = preg_split("/,/", $type);
49       // Remove automatically added '*' from filter 
50       $filter= trim(preg_replace("/\*/",'', $filter));
51       if(empty($filter)){
52         $filter = ".*";
53       }else{
54         $filter = preg_quote($filter,'/');
55       }
58       // Build up ldap like object list.
59       foreach($objects as $name => $data)
60       {
61         $data = array_pop($data);
63         // Display only requested object types
64         if(!in_array_strict($data['type'], $types)) continue;
66         // Filter out those entries that doesn't match the filter.
67         if(!preg_match("/".$filter."/i",  $data['cn'])){
68           continue;
69         }
71         $item =array();
72         $item['objectClass']  = array('count' => 2, $data['type'],"FAKE_OC_OPSI");
73         $item[] = 'objectClass';
74         $item['cn']  = $data['cn'];
75         $item[] = 'cn';
76         $item['description']  = $data['description'];
77         $item[] = 'description';
78         $item['dn']  = $data['cn'];
79         $item[] = 'dn';
80         $item['TYPES']  = array($data['type']);
81         $item[] = 'TYPES';
82         $item['count'] = '5';
83         $entries[] = $item;
84       }
85     }
86     return($entries);
87   }
88 }
89 ?>