Code

Added label in class name selector for more comfort.
[gosa.git] / gosa-plugins / fai / admin / fai / class_filterFAI.inc
1 <?php
3 class filterFAI extends filterLDAP{
5   static function query($base, $scope, $filter, $attributes, $category, $objectStorage= "")
6   {
7   /* Create a new list of FAI object
8      * Generate List of Partitions,Hooks,Scripts,Templates,Profiles ...
9      */
10     $ObjectTypes = array(
11         "FAIpartitionTable"  => array("OU"=> get_ou('faiPartitionRDN') , "CHKBOX"=>"ShowPartitions"  ,"ACL" => "faiPartitionTable"),
12         "FAIpackageList"     => array("OU"=> get_ou('faiPackageRDN')   , "CHKBOX"=>"ShowPackages"    ,"ACL" => "faiPackage"),
13         "FAIscript"          => array("OU"=> get_ou('faiScriptRDN')    , "CHKBOX"=>"ShowScripts"     ,"ACL" => "faiScript"),
14         "FAIvariable"        => array("OU"=> get_ou('faiVariableRDN')  , "CHKBOX"=>"ShowVariables"   ,"ACL" => "faiVariable"),
15         "FAIhook"            => array("OU"=> get_ou('faiHookRDN')      , "CHKBOX"=>"ShowHooks"       ,"ACL" => "faiHook"),
16         "FAIprofile"         => array("OU"=> get_ou('faiProfileRDN')   , "CHKBOX"=>"ShowProfiles"    ,"ACL" => "faiProfile"),
17         "FAItemplate"        => array("OU"=> get_ou('faiTemplateRDN')  , "CHKBOX"=>"ShowTemplates"   ,"ACL" => "faiTemplate"));
21     global $config;
22     $tmp = FAI::get_all_objects_for_given_base($base,$filter);
23     $ui = get_userinfo();
24     $ldap = $config->get_ldap_link();
25     $ldap->cd($config->current['BASE']);
27     $result = array();
28     foreach($tmp as $entry){
30       /* Get some more informations about the object */
31       $ldap->cat($entry['dn'], array("cn","description","objectClass","FAIclass","FAIstate","objectClass"));
32       $object  = $ldap->fetch();
34       /* Walk through possible types */
35       foreach($ObjectTypes as $type => $rest){
37         $acl = $ui->get_permissions($object['dn'],"fai/".$rest ['ACL']);
39         if(in_array($type,$object['objectClass']) && preg_match("/r/",$acl)){
41           /* Prepare object */
42           unset($object['objectClass']['count']);
43           if(!isset($object['description'][0])){
44             $object['description'][0]="";
45           }
47           $dn = preg_replace("/^[^,]*+,/","",$object['dn']);
49           /* Clean up object informations */
50           $obj                  = array();
51           $obj['cn']            = $object['cn'][0];
52           $obj['dn']            = $object['cn'][0].",".get_ou("faiBaseRDN").$config->current['BASE'];
53           $obj['acl']           = $acl;
54           $obj['class']         = $rest ['ACL'];
55           $obj['FAIstate']      = $entry['FAIstate'];
56           $obj['description']   = $object['description'][0];
57           $obj['objectClass']   = $object['objectClass'];
58           $obj['objectClass'][] = 'FAKE_OC_FAI';
60           if(!preg_match("/freeze/i", $entry['FAIstate'])){
61             $obj['objectClass'][] = "FAKE_OC_IsBranch";
62           }
63           $object['FAIstate'] = $entry['FAIstate'];
65           $obj['TYPES'][]       = $type;
66           $obj['GROUPS'][$type]      = $object;
68           if(!isset($result[$obj['cn']])){
69             $result[$obj['cn']] = $obj;
70           }else{
71             $result[$obj['cn']]['TYPES'][]=$type;
72             $result[$obj['cn']]['GROUPS'][$type]=$object;
73           }
74         }
75       }
76     }
78     // Make results useable for the listing class.
79     $entries = array();
80     foreach($result as $entry){
81       $item=array('count' => count($entry) -1);
82       foreach($entry as $name => $value){
83         if($name != "GROUPS"){
84           $item[] = $name;
86           $item[$name] = $value ;       
87         }
88       }
89       $item['GROUPS'] = $entry['GROUPS'];
90       $entries[] = $item;
91     }
94     // Append opsi stuff ... 
95     if(class_available('opsi') && $base == get_ou("faiBaseRDN").$config->current['BASE']){
96       $opsi = new opsi($config);
97       $objects = array();
98       if($opsi instanceof opsi && $opsi->enabled()){
99         $opsi_acl = $ui->get_permissions($base,"opsi/opsiProperties");
100         if(preg_match("/r/",$opsi_acl)){
101           $err = FALSE;
103           if(preg_match("/FAIstate=__NETBOOT__/", $filter)){
104             $n_pro = $opsi->get_netboot_products();
105             $err |= $opsi->is_error();
106             foreach($n_pro as $name => $data){
107               $entry = array(
108                   "cn" => $name,
109                   "description" => $data['DESC'],
110                   "type" => "opsi_netboot");
111               $objects[$name]['opsi_netboot'] = $entry;
112             }
113           }
114           if(preg_match("/FAIstate=__LOCALBOOT__/", $filter)){
115             $l_pro = $opsi->get_local_products();
116             $err |= $opsi->is_error();
117             foreach($l_pro as $name => $data){
118               $entry = array("cn" => $name,
119                   "description" => $data['DESC'],
120                   "type" => "opsi_local");
121               $objects[$name]["opsi_local"] = $entry;
122             }
123           }
124           if($err){
125             msg_dialog::display(_("Error"),msgPool::siError($opsi->get_error()),ERROR_DIALOG);
126           }
127         }
128       }
130       $cn_filter = "";
131       if(preg_match("/^.*cn=([^)]*).*/",$filter)){
132         $cn_filter = trim(preg_replace("/^.*cn=([^)]*).*/","\\1",$filter),"*");
133       }
135       foreach($objects as $name => $data)
136       {
137         $data = array_pop($data);
138         if(!empty($cn_filter) && !preg_match("/".preg_quote($cn_filter,'/')."/",  $data['cn'])){
139           continue;
140         }
141         $item =array();
143         $item['objectClass']  = array('count' => 2, $data['type'],"FAKE_OC_OPSI");
144         $item[] = 'objectClass';
145         $item['cn']  = $data['cn'];
146         $item[] = 'cn';
147         $item['description']  = $data['description'];
148         $item[] = 'description';
149         $item['dn']  = $data['cn'];
150         $item[] = 'dn';
151         $item['TYPES']  = array($data['type']);
152         $item[] = 'TYPES';
153         $item['count'] = '5';
154         $entries[] = $item;  
156       }
157     }
159     return($entries);
160   }
162 ?>