Code

Prepared for multiple asterisk servers
[gosa.git] / plugins / admin / fai / class_faiSummaryTab.inc
index 45402b6b2c7e9d378e5fb4d0e653878d59892789..034f8cefe107b388f1f5a2a2cb6ee0acc628486e 100644 (file)
@@ -29,10 +29,15 @@ class faiSummaryTab extends plugin{
   var $is_dialog      = false;
   var $InitCalled     = false;
   var $usedClasses    = array();
-  
-  function faiSummaryTab($config,$dn)
+  var $base           = ""; 
+  var $parent         = NULL; 
+  var $ui             = NULL;
+
+  function faiSummaryTab($config,$dn)//,$parent)
   {
-    plugin::plugin($config,$dn);
+    plugin::plugin($config,$dn);//,$parent);
+
+    $this->ui = get_userinfo();
 
     /* Base object configuration */
     $this->objs = array(       
@@ -54,8 +59,7 @@ class faiSummaryTab extends plugin{
     $this->InitCalled = true;
     $this->Result = array();
     $_SESSION['faiSummaryTab']['UniqueID'] = 0; 
-    $tmp = $this->getBranches();
-    
+  
     /* Get classes & release name 
        There are 2 different tabs which use the summary tab
        faiProfile / Workstations */
@@ -65,23 +69,41 @@ class faiSummaryTab extends plugin{
       
       /* Get Classes and release */
       $this->Classes = $this->parent->by_object['faiProfile']->FAIclasses;
+      $this->base    = $this->parent->by_object['faiProfile']->base;
       $str = preg_replace("/^.*ou=profiles,/","",$this->dn);
-      if(isset($tmp[$str])){
-        $this->Release = $tmp[$str];
-      }
   
     /* Check if parent tab is work tab */
     }elseif(isset($this->parent->by_name['workstartup'])){
       $this->Classes = $this->parent->by_object['workstartup']->FAIclass;
       $this->Release = $this->parent->by_object['workstartup']->FAIrelease;
-      $tmp = array_flip($tmp);
-      if(!isset($tmp[$this->Release])) {
-        $this->Release = "";
+
+      /* Check if this is a workstation or an object group */
+      if(isset($this->parent->by_object['workgeneric'])){
+        $this->base    = $this->parent->by_object['workgeneric']->base;
+      }elseif(isset($this->parent->by_object['ogroup'])){
+        $this->base    = $this->parent->by_object['ogroup']->base;
+      }else{
+        print_red(_("Unknown type of FAI source information. This is not a profile, workstation nor a ogroup."));
+      }
+      
+      /* Append workstation class && LAST */
+      if(isset($this->parent->by_object['workgeneric']->cn)){
+        $this->Classes[] = $this->parent->by_object['workgeneric']->cn;
       }
     }
 
+    $tmp = array_flip($this->getBranches());
+
+    $this->Classes[] = "LAST";
+
+    /* You need full access to complete collection of fai acls to view this summary */
+    $acl = $this->ui->has_complete_category_acls($this->base,"fai");
+    if(!preg_match("/r/",$acl)){
+      $this->Classes = array();
+    }
+
     /* Set all available releases */
-    $this->Releases = array_flip($this->getBranches());
+    $this->Releases = $tmp;
     $this->usedClasses = array();
 
     /* Check the configuration */
@@ -97,6 +119,19 @@ class faiSummaryTab extends plugin{
   function save_object()
   {
     $once = true;
+
+    if(isset($_GET['expand']) && isset($_GET['id'])){
+      if(isset($this->Result[$_GET['id']])){
+        $this->Result[$_GET['id']]['Open'] =true  ;
+      }
+    }
+
+    if(isset($_GET['compress']) && isset($_GET['id'])){
+      if(isset($this->Result[$_GET['id']])){
+        unset($this->Result[$_GET['id']]['Open']);
+      }
+    }
+
     foreach($_POST as $name => $value ){
 
       /* check for open tag request */
@@ -123,27 +158,24 @@ class faiSummaryTab extends plugin{
   /* returns an array with all possibly release types */
   function getBranches($base = false,$prefix = "")
   {
-    $ret = array("main"=>"/");
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd($this->config->current['BASE']);
     if(!$base){
-      $base= "ou=fai,ou=configs,ou=systems,".$_SESSION['CurrentMainBase'];
-    }
-    $ldap->cd($base);
-    $ldap->ls("(objectClass=FAIbranch)",$base);
-    while($attrs = $ldap->fetch()){
-      if((isset($attrs['ou']))&&($attrs['dn']!=$base)){
-        $ret[$attrs['dn']]= $prefix.$attrs['ou'][0];
-        $ret = array_merge($ret,$this->getBranches($attrs['dn'],"".$prefix.$attrs['ou'][0]."/"));
-      }
+      $base = $this->base;
     }
-    return($ret);
+    return(get_all_releases_from_base($base,true));
   }
 
 
   /* This function calls all nescessary functions to generate the fai class summary tree */
   function execute() 
   {
+
+    /* Skip this if fai is deactivated */
+    $tmp = search_config($this->config->data,"faiManagement","CLASS");
+    if(empty($tmp)){
+      $str = "<h2>"._("You can't use this plugin until FAI is activated.")."</h2>";
+      return $str;
+    }    
+
     /* Check if we must (re)init the this tab */
     if(!$this->InitCalled){
       $this->init();
@@ -151,7 +183,7 @@ class faiSummaryTab extends plugin{
 
     if(isset($_GET['show'])){
       $ldap = $this->config->get_ldap_link();
-      $ldap->cat(base64_decode($_GET['id']));
+      $ldap->cat(base64_decode($_GET['id']), array('FAIscript', 'FAIhook', 'FAItemplate'));
       $attrs = $ldap->fetch();
       if($_GET['type'] == "FAIscript"){
         $str = $attrs['FAIscript'][0];
@@ -166,6 +198,9 @@ class faiSummaryTab extends plugin{
 
     /* Get smarty class & assign created summary results */
     $smarty = get_smarty();
+    $acl = $this->ui->has_complete_category_acls($this->base,"fai");
+    $smarty->assign("readable", preg_match("/r/",$acl));
+
     $this->ObjectList = $this->createSummary($this->Result);
     $smarty->assign("objectList",$this->ObjectList);
     return($smarty->fetch (get_template_path('faiSummary.tpl', TRUE, dirname(__FILE__))));
@@ -176,7 +211,7 @@ class faiSummaryTab extends plugin{
   function createSummary($data)
   {
     /* Don't generate any output, if there is no result */ 
-    $str ="<table style='width:100%;background:#F5F5F5;'> ";
+    $str ="<table cellspacing=0 cellpadding=2 style='width:100%;background:#F5F5F5;'> ";
     if(!count($this->Result)){
       $str.="<tr><td>"; 
       $str.= (_("This object has no FAI classes assigned."));
@@ -189,43 +224,52 @@ class faiSummaryTab extends plugin{
       
       $image = "<img src='".$this->objs[$key]['Image']."' class='center' alt='".$this->objs[$key]['Name']."' border=0>";
       if(!isset($entry['Open'])){
-        $str .= "<tr><td colspan=2><input type='image' class='center' src='images/expand.png' name='open_".$key."'>&nbsp;";
-        $str .= $image."&nbsp;";
-        $str .= "<b>".$this->objs[$key]['Name']."</b></td></tr>";
+        $str .= "<tr>
+                  <td colspan=2>
+                   <a href='?plug=".$_GET['plug']."&amp;expand&amp;id=".$key."'>
+                    <img border=0 class='center' src='images/expand.png' alt='"._("Open")."'>&nbsp;";
+        $str .=     $image."&nbsp;";
+        $str .= "   <b>".$this->objs[$key]['Name']."</b></a></td></tr>";
       }else{
-        $str .= "<tr><td colspan=2><input type='image' class='center' src='images/sort_down.png' name='close_".$key."'>&nbsp;";
+        $str .= "<tr><td colspan=2>
+                    <a href='?plug=".$_GET['plug']."&amp;compress&amp;id=".$key."'>
+                   <img border=0 class='center' src='images/sort_down.png' alt='"._("Close")."'>&nbsp;";
         $str .= $image."&nbsp;";
-        $str .= "<b>".$this->objs[$key]['Name']."</b></td></tr>";
+        $str .= "<b>".$this->objs[$key]['Name']."</b></a></td></tr>";
    
         /* Display FAItemplate FAIhook FAIscript entries */ 
         if(in_array($key,array("FAItemplate","FAIhook","FAIscript"))){
 
           $nums = array();          
-
+          $tmp  = array();
           if($key == "FAIscript"){
-      
-            krsort($entry['Entries']);
-            foreach($entry['Entries'] as $scripts){
-              ksort($scripts);
-              foreach($scripts as $script){
-                
-//                $script['cn'][0] = "(".$script['FAIpriority'][0].") ".$script['cn'][0];
-                if(!isset($nums[$script['cn'][0]])){
-                  $nums[$script['cn'][0]]= 0;
-                } 
-                $nums[$script['cn'][0]] ++;
-            
-                $tmp[] = $script;
+            if(is_array($entry['Entries'])){
+              foreach($entry['Entries'] as $scripts){
+                foreach($scripts as $script){
+
+                  if(!isset($nums[$script['cn'][0]])){
+                    $nums[$script['cn'][0]]= 0;
+                  } 
+                  $nums[$script['cn'][0]] ++;
+
+                  $tmp[$script['FAIpriority'][0].$script['cn'][0].$script['CLASS']] = $script;
+                }
               }
             }
+            krsort($tmp);;
+            
             $entry['Entries'] = $tmp;
           }else{
+            $tmp = array();
             foreach($entry['Entries'] as $script){
+              $tmp[$script['cn'][0].$script['CLASS']] = $script;
               if(!isset($nums[$script['cn'][0]])){
                 $nums[$script['cn'][0]]= 0;
               } 
               $nums[$script['cn'][0]] ++;
             }
+             ksort($tmp);
+            $entry['Entries'] = $tmp;
           }
 
           foreach($entry['Entries'] as $cn => $data){
@@ -236,7 +280,7 @@ class faiSummaryTab extends plugin{
               $str .="<tr><td style='padding-left:20px;'>";
             }
 
-            $str .= "<a target='_blank'href='?plug=".$_GET['plug']."&show&type=".$key."&id=".base64_encode($data['dn'])."'>";
+            $str .= "<a target='_blank' href='?plug=".$_GET['plug']."&amp;show&amp;type=".$key."&amp;id=".base64_encode($data['dn'])."'>";
             $str .= $image."&nbsp;";
             if(isset($data['FAIpriority'][0])){
               $str .= "(".$data['FAIpriority'][0].")";
@@ -260,18 +304,18 @@ class faiSummaryTab extends plugin{
             if(isset($data['description'][0])){
               $str .= " [".$data['description'][0]."] ";
             }
-            $str .=" = '".$data['FAIvariableContent'][0]."'";
-
+            /* Only display FAIvariableContent if description dosn't contain [*] */ 
+            if(isset($data['description'][0]) && !preg_match("#\[\*\]#",$data['description'][0])){
+              $str .=" = '".$data['FAIvariableContent'][0]."'";
+            }
             $str .= "</td><td><i>".$data['CLASS']."</i>";
-            
-
             $str .="</td></tr>";
           }
         }
 
         /* Create packagelist entries */ 
         if(in_array($key,array("FAIpackageList"))) {
-//          ksort($entry['Entries']);
+          ksort($entry['Entries']);
           foreach($entry['Entries'] as $data){
             $str .="<tr><td style='padding-left:20px;'>";
             $str .= $image."&nbsp;".$data['cn'][0];
@@ -290,15 +334,15 @@ class faiSummaryTab extends plugin{
             ksort($data['partitions']);
 
             $str .= "<tr><td colspan=2  style='padding-left:20px;'>";
-            $str .= "<table cellspacing=1 style='background:#FFFFFF;'>
-                      <tr style='background-color:#BBBBBB;'>
-                       <td>"._("No.")."</td>
-                       <td>"._("Name")."</td>
-                       <td>"._("FS options")."</td>
-                       <td>"._("Mount options")."</td>
-                       <td>"._("Size in MB")."</td>
-                       <td>"._("Mount point")."</td>
-                       <td>"._("Type")."</td>
+            $str .= "<table cellspacing=0 cellpadding=2 style='background:#FFFFFF;border:1px solid #B0B0B0'>
+                      <tr style='background-color:#DBDBDB;'>
+                       <td class='tbhead'>"._("No.")."</td>
+                       <td class='tbhead'>"._("Name")."</td>
+                       <td class='tbhead'>"._("FS options")."</td>
+                       <td class='tbhead'>"._("Mount options")."</td>
+                       <td class='tbhead'>"._("Size in MB")."</td>
+                       <td class='tbhead'>"._("Mount point")."</td>
+                       <td class='tbrhead'>"._("Type")."</td>
                       </tr>";
 
             $i = 0;
@@ -307,10 +351,10 @@ class faiSummaryTab extends plugin{
 
               if($i%2 == 1){
                 $c = " class='rowxp1'";
-                $d = " class='list1' style='border:0px;'";
+                $d = " class='list1'";
               }else{
                 $c = " class='rowxp0'";
-                $d = " class='list0' style='border:0px;'";
+                $d = " class='list0'";
               }
 
               $str.="<tr $c style='height:10px;'>
@@ -320,7 +364,7 @@ class faiSummaryTab extends plugin{
                       <td $d>".$part['FAIfsOptions'][0]."</td> 
                       <td $d>".$part['FAIpartitionSize'][0]."</td> 
                       <td $d>".$part['FAImountPoint'][0]."</td> 
-                      <td $d>".$part['FAIpartitionType'][0]."</td> 
+                      <td $d style='border:none'>".$part['FAIpartitionType'][0]."</td> 
                     </tr>";
             }
             $str .="</table>";
@@ -336,36 +380,40 @@ class faiSummaryTab extends plugin{
   /* resolve specified object to append it to our object tree */
   function resolveObject($class)
   {
-    $ldap      = $this->config->get_ldap_link();
-    $dn          = $this->Releases [$this->Release];
-    $res    = array();
+    $ldap                = $this->config->get_ldap_link();
+    $dn                    = $this->Releases [$this->Release];
+    $resolvedClasses  = get_all_objects_for_given_base($dn,"(&(objectClass=FAIclass)(cn=".$class."))");
+
     /* Try to fetch all types of fai objects with the given cn  */
-    foreach($this->objs as $key =>  $obj){
-      
-      /* Check for objects with cn=$class 
-          and add them to our list */
-      $ldap->ls("(&(objectClass=".$key.")(cn=".$class."))",$obj['Tree'].$dn,array("*"));
+    foreach($resolvedClasses as $obj){
+
+      $dn = $obj['dn'];
+      $ldap->cat($dn);
+
       while($attrs = $ldap->fetch()){
 
-        if(!isset($this->usedClasses[$key][$class])){
-          $this->usedClasses[$key][$class] = true;
-          switch($key){
-            case "FAIprofile":                         $this->prepare_FAIprofile($attrs);break;
-            case "FAIscript":                  $this->prepare_FAIscript($attrs);break;
-            case "FAIhook":                      $this->prepare_FAIhook($attrs);break;
-            case "FAIvariable":                        $this->prepare_FAIvariable($attrs);break;
-            case "FAItemplate":                        $this->prepare_FAItemplate($attrs);break;
-            case "FAIpackageList":           $this->prepare_FAIpackageList($attrs);break;
-            case "FAIpartitionTable":      $this->prepare_FAIpartitionTable($attrs);break;
+        foreach($this-> objs as $key => $rest){
+          if(in_array($key,$attrs['objectClass'])){
+
+            if(!isset($this->usedClasses[$key][$class])){
+              $this->usedClasses[$key][$class] = true;
+              switch($key){
+                case "FAIprofile":                     $this->prepare_FAIprofile($attrs);break;
+                case "FAIscript":                      $this->prepare_FAIscript($attrs);break;
+                case "FAIhook":                          $this->prepare_FAIhook($attrs);break;
+                case "FAIvariable":                    $this->prepare_FAIvariable($attrs);break;
+                case "FAItemplate":                    $this->prepare_FAItemplate($attrs);break;
+                case "FAIpackageList":       $this->prepare_FAIpackageList($attrs);break;
+                case "FAIpartitionTable":          $this->prepare_FAIpartitionTable($attrs);break;
+              }
+            }
+
           }
         }
       }
     }
-    return($res);
   }
 
-
   /* Prepare fai script */
   function prepare_FAIscript($data)
   {
@@ -511,6 +559,23 @@ class faiSummaryTab extends plugin{
       $this->resolveObject($class);
     }
   }
+
+  /* Return plugin informations for acl handling * /
+  function plInfo()
+  {
+    return (array(
+          "plShortName"   => _("Summary"),
+          "plDescription" => _("FAI summary"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 15,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("workstation","server","fai","ogroups") ,
+          "plProvidedAcls"=> array(
+            "readable" => _("Viewable")),
+          ));
+  }
+  */
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>