Code

Updated divlists.
[gosa.git] / plugins / admin / fai / class_faiHook.inc
index f86302e93e26f8ddf762ce32b811b4f1b5d33fc7..9fdb2b15de0f1c98dc14f1ceab8470efb0b317e9 100644 (file)
@@ -37,6 +37,7 @@ class faiHook extends plugin
   var $SubObjects       = array();  // All leafobjects of this object
 
   var $FAIstate         = "";  
+  var $ui;
 
   function faiHook ($config, $dn= NULL)
   {
@@ -61,9 +62,17 @@ class faiHook extends plugin
       $ldap->cd ($this->dn);
       $attrs_to_search = $this->subAttributes;
       $attrs_to_search[] = "FAIstate";
-      $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))", array("dn"));
+      $ldap->search("(&(objectClass=FAIclass)(objectClass=".$this->subClass."))", $attrs_to_search);
 
       while($object = $ldap->fetch()){
+
+       /* Skip objects, that are tagged as removed */
+        if(isset($object['FAIstate'][0])){
+          if(preg_match("/removed$/",$object['FAIstate'][0])){
+            continue;
+          }
+        }
+
         /* Set status for save management */
         $objects = array();
         $objects['status']      = "FreshLoaded";
@@ -72,6 +81,7 @@ class faiHook extends plugin
         $this->SubObjects[$objects['cn']] = $objects;
       }
     }
+    $this->ui = get_userinfo();
   }
 
 
@@ -106,6 +116,19 @@ class faiHook extends plugin
   }
 
 
+  function acl_base_for_current_object($dn)
+  {
+    if($dn == "new"){
+      if($this->dn == "new"){
+        $dn= $_SESSION['CurrentMainBase'];
+      }else{
+        $dn = $this->dn;
+      }
+    }
+    return($dn);
+  }
+
+
   function getUsedFAItask($cn)
   {
     $ret = array();
@@ -142,8 +165,9 @@ class faiHook extends plugin
         if($obj['status'] == "FreshLoaded"){
           $obj  = $this->get_object_attributes($obj,$this->sub_Load_Later);
         }
+
         $this->dialog= new $this->subClassName($this->config,$this->dn,$obj);
-        $this->dialog->set_acl_base($this->dn);
+        $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn']));
         $this->dialog->set_acl_category("fai");
 
         $_SESSION['objectinfo'] = $obj['dn'];
@@ -151,19 +175,17 @@ class faiHook extends plugin
         $this->is_dialog=true;
       }
       if(preg_match("/^deletescript_/",$name)&&($once)){
+        $entry = preg_replace("/^deletescript_/","",$name);
+        $entry = base64_decode(preg_replace("/_.*/","",$entry));
 
-        $dn= $name['dn'];
-        if($dn == "new"){
-          $dn = $_SESSION['CurrentMainBase'];
-        }
+        $dn = $this->acl_base_for_current_object($this->SubObjects[$entry]['dn']);
         $acl = $this->ui -> get_permissions($dn,"fai/faiScriptEntry")  ;
 
         if(preg_match("/d/",$acl)){
           $once = false;
-          $entry = preg_replace("/^deletescript_/","",$name);
-          $entry = base64_decode(preg_replace("/_.*/","",$entry));
 
-          if(($this->SubObjects[$entry]['status'] == "edited")||($this->SubObjects[$entry]['status'] == "FreshLoaded")){
+          $status = $this->SubObjects[$entry]['status'];
+          if($status == "edited" || $status == "FreshLoaded"){
             $this->SubObjects[$entry]['status']= "delete";
           }else{
             unset($this->SubObjects[$entry]);
@@ -176,11 +198,7 @@ class faiHook extends plugin
     /* Add new sub object */
     if(isset($_POST['AddSubObject'])){
 
-      $c_dn = $this->dn;
-      if($c_dn == "new"){
-        $c_dn = $_SESSION['CurrentMainBase'];
-      }
-
+      $c_dn = $this->acl_base_for_current_object($this->dn);
       $this->dialog= new $this->subClassName($this->config,"new");
       $this->dialog->set_acl_base($c_dn);
       $this->dialog->set_acl_category("fai");
@@ -268,14 +286,11 @@ class faiHook extends plugin
 
     foreach($this->getList(true) as $key => $name){
 
-      $dn= $name['dn'];
-      if($dn == "new"){
-        $dn = $_SESSION['CurrentMainBase'];
-      }
-      $ui  = get_userinfo();
-      $acl = $ui->get_permissions($dn,"fai/faiScriptEntry")  ;
+      $dn= $this->acl_base_for_current_object($name['dn']);
+      $acl = $this->ui->get_permissions($dn,"fai/faiHookEntry")  ;
       $act = "";
 
+      /* Check if this object is freezed, in this case hide the delete icon */
       if($this->FAIstate == "freeze"){
         $act .= "<input type='image' src='images/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
       }else{
@@ -285,8 +300,8 @@ class faiHook extends plugin
         }
       }
 
-
-      $s_acl = $ui->get_permissions($dn,"fai/faiScriptEntry","FAIscript")  ;
+      /* Check if we are allowed to use the export button for this object */
+      $s_acl = $this->ui->get_permissions($dn,"fai/faiHookEntry","FAIscript")  ;
       if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new") || !preg_match("/r/",$s_acl)){
         $down = "";
       }else{
@@ -295,10 +310,14 @@ class faiHook extends plugin
           </a>";
       }
 
-      $divlist->AddEntry(array( array("string"=>$name['name']),
-            array("string"=>$down , "attach" => "style='width:20px;'"),
-            array("string"=>str_replace("%s",base64_encode($key),$act),
-              "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
+      /* Check if we are allowed to view the object */
+      $s_acl = $this->ui->get_permissions($dn,"fai/faiHookEntry","cn")  ;
+      if(preg_match("/r/",$s_acl)){
+        $divlist->AddEntry(array( array("string"=>$name['name']),
+              array("string"=>$down , "attach" => "style='width:20px;'"),
+              array("string"=>str_replace("%s",base64_encode($key),$act),
+                "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
+      }
     }
     $smarty->assign("Entry_divlist",$divlist->DrawList());
     /* Divlist creation complete
@@ -318,14 +337,9 @@ class faiHook extends plugin
     }
 
     $tmp = $this->plInfo();
-    $this->ui = get_userinfo();
       
-    $c_dn = $this->dn;
-    if($c_dn == "new"){
-      $c_dn = $_SESSION['CurrentMainBase'];
-    }
-
-    $smarty->assign("sub_object_is_addable", preg_match("/c/",$this->ui->get_permissions($c_dn,"fai/faiScriptEntry")) && $this->FAIstate!="freeze");
+    $c_dn = $this->acl_base_for_current_object($this->dn);
+    $smarty->assign("sub_object_is_addable", preg_match("/c/",$this->ui->get_permissions($c_dn,"fai/faiHookEntry")) && $this->FAIstate!="freeze");
     foreach($tmp['plProvidedAcls'] as $name => $translation){
       $smarty->assign($name."ACL",$this->getacl($name));
     }