Code

Prepared for multiple asterisk servers
[gosa.git] / plugins / admin / fai / class_faiSummaryTab.inc
index 0fd878cd38322f2257f013919bd6fa7267fb1e06..034f8cefe107b388f1f5a2a2cb6ee0acc628486e 100644 (file)
@@ -30,11 +30,14 @@ class faiSummaryTab extends plugin{
   var $InitCalled     = false;
   var $usedClasses    = array();
   var $base           = ""; 
-  var $parent         = ""; 
+  var $parent         = NULL; 
+  var $ui             = NULL;
 
-  function faiSummaryTab($config,$dni,$parent)
+  function faiSummaryTab($config,$dn)//,$parent)
   {
-    plugin::plugin($config,$dn,$parent);
+    plugin::plugin($config,$dn);//,$parent);
+
+    $this->ui = get_userinfo();
 
     /* Base object configuration */
     $this->objs = array(       
@@ -56,8 +59,7 @@ class faiSummaryTab extends plugin{
     $this->InitCalled = true;
     $this->Result = array();
     $_SESSION['faiSummaryTab']['UniqueID'] = 0; 
-    $tmp = array_flip($this->getBranches());
-   
+  
     /* Get classes & release name 
        There are 2 different tabs which use the summary tab
        faiProfile / Workstations */
@@ -74,16 +76,32 @@ class faiSummaryTab extends plugin{
     }elseif(isset($this->parent->by_name['workstartup'])){
       $this->Classes = $this->parent->by_object['workstartup']->FAIclass;
       $this->Release = $this->parent->by_object['workstartup']->FAIrelease;
-      $this->base    = $this->parent->by_object['workgeneric']->base;
 
+      /* 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 = $tmp;
     $this->usedClasses = array();
@@ -150,6 +168,14 @@ class faiSummaryTab extends plugin{
   /* 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();
@@ -172,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__))));
@@ -195,14 +224,15 @@ 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>
-                    <a href='?plug=".$_GET['plug']."&expand&id=".$key."'>
-                  <img border=0 class='center' src='images/expand.png' alt='"._("Open")."'>&nbsp;";
-        $str .= $image."&nbsp;";
-        $str .= "<b>".$this->objs[$key]['Name']."</b></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>
-                    <a href='?plug=".$_GET['plug']."&compress&id=".$key."'>
+                    <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></a></td></tr>";
@@ -211,17 +241,19 @@ class faiSummaryTab extends plugin{
         if(in_array($key,array("FAItemplate","FAIhook","FAIscript"))){
 
           $nums = array();          
-
+          $tmp  = array();
           if($key == "FAIscript"){
-            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;
+            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);;
@@ -248,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].")";
@@ -527,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:
 ?>