Code

test
[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];
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['TYPES'][]       = $type;
59           $obj['GROUPS'][$type]      = $object;
60         
61           if(!isset($result[$obj['cn']])){
62             $result[$obj['cn']] = $obj;
63           }else{
64             $result[$obj['cn']]['TYPES'][]=$type;
65             $result[$obj['cn']]['GROUPS'][$type]=$object;
66           }
67         }
68       }
69     }
71     // Make results useable for the listing class.
72     $entries = array();
73     foreach($result as $entry){
74       $item=array('count' => count($entry) -1);
75       foreach($entry as $name => $value){
76         if($name != "GROUPS"){
77           $item[] = $name;
79           $item[$name] = $value ;       
80         }
81       }
82       $item['GROUPS'] = $entry['GROUPS'];
83       $entries[] = $item;
84     }
86     return($entries);
87   }
88 }
89 ?>