Code

Removed faifilter
[gosa.git] / plugins / admin / fai / class_faiSummaryTab.inc
1 <?php
3 class faiSummaryTab extends plugin{
5   var $Classes = array();
6   var $Release = "";
7   var $Releases= array();
8   var $Result  = array();
9   var $objs      = array();
10   var $ObjectList = "";
12   var $FAIclass;
13   var $attributes = array("FAIclass");
15   function faiSummaryTab($config,$dn)
16   {
17     plugin::plugin($config,$dn);
19     $this->objs = array(        "FAIscript"             => array(       "Image" =>"images/fai_script.png",
20           "Tree"        =>"ou=scripts,") ,
21         "FAIhook"                       => array(       "Image" =>"images/fai_hook.png" ,
22           "Tree"        =>"ou=hooks,"),
23         "FAIvariable"           => array(       "Image" =>"images/fai_variable.png",
24           "Tree"        =>"ou=variables,") ,
25         "FAItemplate"           => array(       "Image" =>"images/fai_template.png",
26           "Tree"        =>"ou=templates,") ,
27         "FAIpartitionTable" => array(   "Image" =>"images/fai_partitionTable.png",
28           "Tree"        =>"ou=disk,") ,
29         "FAIpackageList"        => array(       "Image" =>"images/fai_packages.png",
30           "Tree"        =>"ou=packages,") ,
31         "FAIprofile"            => array(       "Image" =>"images/fai_profile.png",
32           "Tree"        =>"ou=profiles,"));
34     if(count($this->FAIclass)){
37       /* Set Release */
38       if(preg_match("/:/",$this->FAIclass)){
39         if(preg_match("/:/",$this->FAIclass)){
40           $this->Release =trim( preg_replace("/^.*:/","",$this->FAIclass));
41         }
42       }
44       /* Get classes */
45       $tmp = split("\ ", preg_replace("/:.*$/","",$this->FAIclass));
46       foreach($tmp as $class){
47         if(!empty($class)){
48           $this->Classes[]= trim($class);
49         }
50       }
51     }
53     $_SESSION['faiSummaryTab']['UniqueID'] = 0; 
55     $this->Releases = array_flip($this->getBranches());
57     if(count($this->Classes) && (!empty($this->Release))){
58       foreach($this->Classes as $class){
59         $this->Result[$class] = $this->resolveObject($class);
60       }
61     }
62   }
64   /* returns an array with all possibly release types */
65   function getBranches($base = false,$prefix = "")
66   {
67     $ret = array("main"=>"/");
68     $ldap = $this->config->get_ldap_link();
69     $ldap->cd($this->config->current['BASE']);
70     if(!$base){
71       $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
72     }
73     $ldap->cd($base);
74     $ldap->ls("(objectClass=FAIbranch)",$base);
75     while($attrs = $ldap->fetch()){
76       if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
77         $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
78         $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
79       }
80     }
81     return($ret);
82   }
85   function execute() 
86   {
87     $display = "";      
88     $smarty = get_smarty();
89     $this->ObjectList = $this->createSummary($this->Result);
90     $smarty->assign("objectList",$this->ObjectList);
91     $display.= $smarty->fetch (get_template_path('faiSummary.tpl', TRUE, dirname(__FILE__)));
92     return($display);
93   }
95   /* Create output of our resolved objects */
96   function createSummary($data)
97   {
98  
99     /* Don't generate any output, if there is no result */ 
100     $str ="<table style='width:100%;background:#F5F5F5;'> ";
101     if(!count($this->Result)){
102       $str.="<tr><td>"; 
103       $str.= (_("This object has no FAI classes assigned."));
104       $str.= "</tr></td></table>";
105       return($str);
106     }
108     /* walk through all classes */      
109     foreach($data as $key => $entry){
111       /* Check every kind of object type */
112       foreach($this->objs as $ok => $obj){
114         /* check of objectType is used */
115         if(isset($entry[$ok])){
116           $str.="<tr><td style='padding-left:10px;'>";
118           /* Show open or close icon */ 
119           if( ! $entry[$ok]['Open'] ){
120             $str .= "<input type='image' class='center' src='images/expand.png' name='open_".$entry[$ok]['id']."'>&nbsp;";
121             $str .="<img src='".$obj['Image']."'>&nbsp;";
122             $str .= "<b>".$entry[$ok]['Name']."</b>";
123             $str .= "&nbsp;".$entry[$ok]['String1'];
124           }else{
125             $str .= "<input type='image' class='center' src='images/sort_down.png' name='close_".$entry[$ok]['id']."'>&nbsp;";
126             $str .="<img src='".$obj['Image']."'>&nbsp;";
127             $str .= "<b>".$entry[$ok]['Name']."</b>";
128             $str .= "&nbsp;".$entry[$ok]['String1'];
129             if(!empty($entry[$ok]['String2'])){
130               $str .= "</td></tr><tr><td style='padding-left:50px;'>".$entry[$ok]['String2'];
131             }
133             if(isset($data[$key][$ok]['data'])){
134               $str.=$this->createSummary($data[$key][$ok]['data']);
135             }
136           }
137           $str .="</td></tr>";
138         }
139       }
140     }
141     $str .="</table>";  
142     return($str);
143   }
145   /* resolve specified object to append it to our object tree
146      calls prepare_"FAIclass"
147    */
148   function resolveObject($class)
149   {
150     $ldap       = $this->config->get_ldap_link();
151     $dn         = $this->Releases [$this->Release];
153     $res = array();
155     foreach($this->objs as $key =>  $obj){
156       $ldap->ls("(&(objectClass=".$key.")(cn=".$class."))",$obj['Tree'].$dn,array("*"));
157       while($attrs = $ldap->fetch()){
158         switch($key){
159           case "FAIprofile":            $tmp = $this->prepare_FAIprofile($attrs);break;
160           case "FAIscript":             $tmp = $this->prepare_FAIscript($attrs);break;
161           case "FAIhook":               $tmp = $this->prepare_FAIhook($attrs);break;
162           case "FAIvariable":           $tmp = $this->prepare_FAIvariable($attrs);break;
163           case "FAItemplate":           $tmp = $this->prepare_FAItemplate($attrs);break;
164           case "FAIpackageList":        $tmp = $this->prepare_FAIpackageList($attrs);break;
165           case "FAIpartitionTable":     $tmp = $this->prepare_FAIpartitionTable($attrs);break;
166           default : $tmp = array(); print_red(sprintf(_("Undefined FAI object '%s'."),$key));
167         }
168         if(isset($tmp['Name'])){
169           $res[$key] = $tmp     ;
170         }
171       }
172     }
173     return($res);
174   }
176   /* Prepare fai script */
177   function prepare_FAIscript($data)
178   {
179     /* Set basic attributes */
180     $res['Name']        = $data['cn'][0];
181     if(isset($data['description'][0])){
182       $res['String1'] = $data['description'][0];
183     }else{
184       $res['String1'] = "";
185     }
186     $res['Open']        = false;
187     $res['id']          = ($_SESSION['faiSummaryTab']['UniqueID'] ++);
188     $res['Resolved']= true;
189     $res['String2'] = "";
191     /* get subentries */        
192     $ldap = $this->config->get_ldap_link();
193     $ldap->cd($data['dn']);
194     $ldap->search("(&(objectClass=FAIscriptEntry)(FAIpriority=*))",array("cn","description","FAIpriority"));
195     $scripts  = array();
197     /* Create an array which is sortable by priority */
198     while($attrs = $ldap->fetch()){
199       $scripts[$attrs['FAIpriority'][0]][] = $attrs;    
200     }
202     /* Sort by priority */
203     ksort($scripts);
205     /* append them to our list */       
206     $image = "<image class='center' border=0 src='".$this->objs['FAIscript']['Image']."'>&nbsp;";
208     foreach($scripts as $prio => $script){
209       foreach($script as $attrs){
210         $res['String2'] .="<a href='?plug=".$_GET['plug']."&display=FAIscript&id=".base64_encode($attrs['dn'])."'>";
211         if(isset($attrs['description'][0])){
212           $res['String2'] .= $image.$attrs['FAIpriority'][0]."&nbsp;-&nbsp;".$attrs['cn'][0]." [".$attrs['description'][0]."]<br>";                     
213         }else{
214           $res['String2'] .= $image.$attrs['FAIpriority'][0]."&nbsp;-&nbsp;".$attrs['cn'][0]."<br>";                    
215         }
216         $res['String2'] .="</a>";
217       }
218     }
219     return($res);
220   }
222   /* Prepare fai script */
223   function prepare_FAIpartitionTable($data)
224   {
225     /* Set basic attributes */
226     $res['Name']        = $data['cn'][0];
227     if(isset($data['description'][0])){
228       $res['String1'] = $data['description'][0];
229     }else{
230       $res['String1'] = "";
231     }
232     $res['Open']        = false;
233     $res['id']          = ($_SESSION['faiSummaryTab']['UniqueID'] ++);
234     $res['Resolved']= true;
235     $res['String2'] = "";
237     /* get subentries */        
238     $ldap = $this->config->get_ldap_link();
239     $ldap->cd($data['dn']);
240     $ldap->search("(objectClass=FAIpartitionDisk)",array("cn","description"));
241     $disks = array();
243     /* Create an array which is sortable by priority */
244     while($attrs = $ldap->fetch()){
245       $disks[$attrs['cn'][0]] = $attrs; 
246       $disks[$attrs['cn'][0]]['partitions'] = array();  
247     }
249     /* Sort by priority */
250     foreach($disks as $key => $disk){
251       $ldap->cd($disk['dn']);
252       $ldap->search("(objectClass=FAIpartitionEntry)",array("*"));
253       while($attrs = $ldap->fetch()){
254         if(!isset($attrs['FAIfsOptions'][0])){
255           $attrs['FAIfsOptions'][0] = "";
256         }
257         $disks[$key]['partitions'][$attrs['cn'][0]] = $attrs;
258       }
259     }
261     
262     $image = "<image class='center' border=0 src='".$this->objs['FAIpartitionTable']['Image']."'>&nbsp;";
263     foreach($disks as $disk){
264       $res['String2'] .= "<div 'width:100%;padding-left:10px'>";
265       $res['String2'] .= $image."<b>".$disk['cn'][0] ."</b>";
266       
267       if(isset($disk['description'][0])){
268         $res['String2'] .= "&nbsp;[".$disk['description'][0]."]" ;
269       }
270       $res['String2'] .= "</div>";
271   
272       $res['String2'] .= "<table cellspacing=1 style='background:#FFFFFF;'>";
273       $res['String2'] .= "<tr style='background-color:#BBBBBB;'>";
274       $res['String2'] .= "<td>"._("No.")."</td><td>"._("Name")."</td><td>"._("FS options")."</td>";
275       $res['String2'] .= "<td>"._("Mount options")."</td><td>"._("Size in MB")."</td>";
276       $res['String2'] .= "<td>"._("Mount point")."</td><td>"._("Type")."</td>";
277       $res['String2'] .= "</tr>";
278       $i = 0;
279       foreach($disk['partitions'] as $partition){
280         $i = !$i;
281         if($i){
282           $c = " class='rowxp1'";
283           $d = " class='list1' style='border:0px;'";
284         }else{
285           $c = " class='rowxp0'";
286           $d = " class='list0' style='border:0px;'";
287         }
289         $res['String2'] .= "<tr $c style='height:10px;'>";
290         $res['String2'] .= "<td $d>".$partition['FAIpartitionNr'][0]."</td><td $d>".$partition['cn'][0]."</td><td $d>".$partition['FAIfsType'][0]."</td>";
291         $res['String2'] .= "<td $d>".$partition['FAIfsOptions'][0]."</td><td $d>".$partition['FAIpartitionSize'][0]."</td>";
292         $res['String2'] .= "<td $d>".$partition['FAImountPoint'][0]."</td><td $d>".$partition['FAIpartitionType'][0]."</td>";
293         $res['String2'] .= "</tr>";
294       }
295       $res['String2'] .= "</table>";
296     }
298     return($res);
299   }
302   /* Create template entry */   
303   function prepare_FAItemplate($data)
304   {
305     /* Set basic attributes */
306     $res['Name']        = $data['cn'][0];
307     if(isset($data['description'][0])){
308       $res['String1'] = $data['description'][0];
309     }else{
310       $res['String1'] = "";
311     }
312     $res['Open']        = false;
313     $res['id']          = ($_SESSION['faiSummaryTab']['UniqueID'] ++);
314     $res['Resolved']= true;
315     $res['String2'] = "";
317     /* get subentries */        
318     $ldap = $this->config->get_ldap_link();
319     $ldap->cd($data['dn']);
320     $ldap->search("(objectClass=FAItemplateEntry)",array("cn","description"));
321     $scripts  = array();
323     /* append them to our list */       
324     $image = "<image class='center' border=0 src='".$this->objs['FAItemplate']['Image']."'>&nbsp;";
326     /* Create an array which is sortable by priority */
327     while($attrs = $ldap->fetch()){
328       $res['String2'] .="<a href='?plug=".$_GET['plug']."&display=FAItemplate&id=".base64_encode($attrs['dn'])."'>";
329       if(isset($attrs['description'][0])){
330         $res['String2'] .= $image.$attrs['cn'][0]." [".$attrs['description'][0]."]";                    
331       }else{
332         $res['String2'] .= $image.$attrs['cn'][0];                      
333       }
334       $res['String2'] .="</a><br>";
335     }
336     return($res);
337   }
340   /* Create a package list  */  
341   function prepare_FAIpackageList($data)
342   {
343     /* Set basic attributes */
344     $res['Name']        = $data['cn'][0];
345     if(isset($data['description'][0])){
346       $res['String1'] = $data['description'][0];
347     }else{
348       $res['String1'] = "";
349     }
350     $res['Open']        = false;
351     $res['id']          = ($_SESSION['faiSummaryTab']['UniqueID'] ++);
352     $res['Resolved']= true;
353     $res['String2'] = "";
355     /* append them to our list */       
356     $image = "<image class='center' border=0 src='".$this->objs['FAIpackageList']['Image']."'>&nbsp;";
358     /* add selected packages to our list */             
359     if(isset($data['FAIpackage']['count'])) {   
360       unset($data['FAIpackage']['count']);
361       foreach($data['FAIpackage'] as $entry){
362         $res['String2'].= $image.$entry." <br>";
363       } 
364     }
365     return($res);
366   }
369   /* Create a variable entry */ 
370   function prepare_FAIvariable($data)
371   {
372     /* Set basic attributes */
373     $res['Name']        = $data['cn'][0];
374     if(isset($data['description'][0])){
375       $res['String1'] = $data['description'][0];
376     }else{
377       $res['String1'] = "";
378     }
379     $res['Open']        = false;
380     $res['id']          = ($_SESSION['faiSummaryTab']['UniqueID'] ++);
381     $res['Resolved']= true;
382     $res['String2'] = "";
384     /* get subentries */        
385     $ldap = $this->config->get_ldap_link();
386     $ldap->cd($data['dn']);
387     $ldap->search("(objectClass=FAIvariableEntry)",array("cn","description","FAIvariableContent"));
388     $scripts  = array();
390     /* append them to our list */       
391     $image = "<image class='center' border=0 src='".$this->objs['FAIvariable']['Image']."'>&nbsp;";
393     /* Create an array which is sortable by priority */
394     while($attrs = $ldap->fetch()){
395       if(isset($attrs['description'][0])){
396         $res['String2'] .= $image.$attrs['cn'][0]." [".$attrs['description'][0]."]";                    
397       }else{
398         $res['String2'] .= $image.$attrs['cn'][0];                      
399       }
400       if(isset($attrs['FAIvariableContent'][0])){
401         $res['String2'] .= " \"".$attrs['FAIvariableContent'][0]."\" ";
402       }
403       $res['String2'] .= "<br>";
405     }
406     return($res);
407   }
409   /* Create a hook entry */     
410   function prepare_FAIhook($data)
411   {
412     /* Set basic attributes */
413     $res['Name']        = $data['cn'][0];
414     if(isset($data['description'][0])){
415       $res['String1'] = $data['description'][0];
416     }else{
417       $res['String1'] = "";
418     }
419     $res['Open']        = false;
420     $res['id']          = ($_SESSION['faiSummaryTab']['UniqueID'] ++);
421     $res['Resolved']= true;
422     $res['String2'] = "";
424     /* get subentries */        
425     $ldap = $this->config->get_ldap_link();
426     $ldap->cd($data['dn']);
427     $ldap->search("(objectClass=FAIhookEntry)",array("cn","description"));
428     $scripts  = array();
430     /* append them to our list */       
431     $image = "<image class='center' border=0 src='".$this->objs['FAIhook']['Image']."'>&nbsp;";
433     /* Create an array which is sortable by priority */
434     while($attrs = $ldap->fetch()){
435       $res['String2'] .="<a href='?plug=".$_GET['plug']."&display=FAIhook&id=".base64_encode($attrs['dn'])."'>";
436       if(isset($attrs['description'][0])){
437         $res['String2'] .= $image.$attrs['cn'][0]." [".$attrs['description'][0]."]<br>";                        
438       }else{
439         $res['String2'] .= $image.$attrs['cn'][0]."<br>";                       
440       }
441       $res['String2'] .="</a>";
442     }
443     return($res);
444   }
446   /* Create a new Profile entry */
447   function prepare_FAIprofile($data)
448   {
449     /* initialise basics */
450     $res = array();
451     $res['Name']        = $data['cn'][0];
452     if(isset($data['description'][0])){
453       $res['String1'] = $data['description'][0];
454     }else{
455       $res['String1'] = "";
456     }
457     $res['Open']        = false;
458     $res['id']          = ($_SESSION['faiSummaryTab']['UniqueID'] ++);
459     $res['Resolved']= true;
460     $res['String2'] = "";
462     /* Append empty data objects named by member classes */
463     $res['data'] = array();
464     if(isset($data['FAIclass'][0])){
465       $tmp = split("\ ",$data['FAIclass'][0]);
466       foreach($tmp as $class){
467         $res['data'][trim($class)] = array();
468       }
469     }
470     return($res);
471   }
475   /* Open the tag with the given id .. 
476      so the entries of this tag will be shown */
477   function openTag($data, $id)
478   {
479     /* Walk through objects */
480     if(!count($data)) return(array());
481     foreach($data as $key => $dat){
483       /* Check all types of objects (FAIhook, FAIscript ..)*/
484       foreach($this->objs as $ok => $obj){
486         /* If this type of object is assigned */
487         if(isset($dat[$ok])){
489           /* check given id */
490           if($dat[$ok]['id'] == $id ){
492             /* Id was $id so set this leaf to open */
493             $data[$key][$ok]['Open'] = true;
495             /* Check if the sub leafs are already readed 
496                if not, resolve the classes and append them to our tree */
497             if(isset($dat[$ok]['data'])){
499               foreach($data[$key][$ok]['data'] as $key1 => $dat1){
500                 if(!count($dat1)){
501                   $tmp = $this->resolveObject($key1);
502                   foreach($tmp as $r => $e)
503                     $data[$key][$ok]['data'][$key1][$r] = $e;
504                 }
505               }
506             }
507           }
508           /* Search sub tags for given id $id */
509           if(isset($data[$key][$ok]['data'])){
510             $data[$key][$ok]['data'] = $this->openTag($data[$key][$ok]['data'],$id);    
511           }
512         }
513       }
514     }
515     return($data);
516   }
518   /* Walk through all tags and close tag with id = $id*/
519   function closeTag($data, $id)
520   {
521     $found = false;
523     /* The parameter data is given as specified */
524     // ClassName ['FAIprofile']['data']  
526     /* Walk through all given classes */
527     foreach($data as $key => $dat){
529       /* Walk through all possible objectClasses */
530       foreach($this->objs as $ok => $obj){
532         /* If class is set, check if id matches */
533         if(isset($dat[$ok])){
534           if($dat[$ok]['id'] == $id ){
535             $data[$key][$ok]['Open'] = false;
536           }
538           /* Check subobjects for $id */
539           if(isset($dat[$ok]['data'])){
540             $data[$key][$ok]['data'] = $this->closeTag( $data[$key][$ok]['data'], $id);
541           }
542         }
543       }
544     }
545     return($data);
546   }
548   /* Capture posts, and call opnen close tag */
549   function save_object()
550   {
551     $once = true;
552     foreach($_POST as $name => $value ){
554       /* check for open tag request */
555       if(preg_match("/^open_/",$name) && $once){
556         $once  = false;
557         $value = preg_replace("/^open_/","",$name);
558         $value = preg_replace("/_.*$/","",$value); 
559         $this->Result = $this->openTag($this->Result,$value);
560       }
561       /* Check for close tag request */
562       if(preg_match("/^close_/",$name) && $once){
563         $once  = false;
564         $value = preg_replace("/^close_/","",$name);
565         $value = preg_replace("/_.*$/","",$value); 
566         $this->Result = $this->closeTag($this->Result,$value);
567       }
568     }
569   }
571 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
572 ?>