Code

Updated divlists.
[gosa.git] / plugins / admin / fai / class_faiHook.inc
index cc94b04f4071943a9524d9954d65d1aaca50b5d9..9fdb2b15de0f1c98dc14f1ceab8470efb0b317e9 100644 (file)
@@ -37,27 +37,19 @@ class faiHook extends plugin
   var $SubObjects       = array();  // All leafobjects of this object
 
   var $FAIstate         = "";  
+  var $ui;
 
   function faiHook ($config, $dn= NULL)
   {
     /* Load Attributes */
     plugin::plugin ($config, $dn);
 
-    $this->acl ="#all#";
-
     /* If "dn==new" we try to create a new entry
      * Else we must read all objects from ldap which belong to this entry.
      */
     if($dn != "new"){
       $this->dn =$dn;
     
-      /* Set acls 
-       */
-      $ui   = get_userinfo();
-      $acl  = get_permissions ($this->dn, $ui->subtreeACL);
-      $acli = get_module_permission($acl, "FAIclass", $this->dn);
-      $this->acl=$acli;
-
       /* Get FAIstate
        */
       if(isset($this->attrs['FAIstate'][0])){
@@ -70,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";
@@ -81,6 +81,7 @@ class faiHook extends plugin
         $this->SubObjects[$objects['cn']] = $objects;
       }
     }
+    $this->ui = get_userinfo();
   }
 
 
@@ -115,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();
@@ -151,22 +165,31 @@ 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= new $this->subClassName($this->config,$this->dn,$obj);
+        $this->dialog->set_acl_base($this->acl_base_for_current_object($obj['dn']));
+        $this->dialog->set_acl_category("fai");
 
         $_SESSION['objectinfo'] = $obj['dn'];
         $this->dialog->parent = &$this;
         $this->is_dialog=true;
       }
       if(preg_match("/^deletescript_/",$name)&&($once)){
-        $once = false;
         $entry = preg_replace("/^deletescript_/","",$name);
         $entry = base64_decode(preg_replace("/_.*/","",$entry));
 
-        if(($this->SubObjects[$entry]['status'] == "edited")||($this->SubObjects[$entry]['status'] == "FreshLoaded")){
-          $this->SubObjects[$entry]['status']= "delete";
-        }else{
-          unset($this->SubObjects[$entry]);
+        $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;
+
+          $status = $this->SubObjects[$entry]['status'];
+          if($status == "edited" || $status == "FreshLoaded"){
+            $this->SubObjects[$entry]['status']= "delete";
+          }else{
+            unset($this->SubObjects[$entry]);
+          }
         }
       }
     }
@@ -174,8 +197,11 @@ class faiHook extends plugin
 
     /* Add new sub object */
     if(isset($_POST['AddSubObject'])){
+
+      $c_dn = $this->acl_base_for_current_object($this->dn);
       $this->dialog= new $this->subClassName($this->config,"new");
-      $this->dialog->acl = $this->acl;
+      $this->dialog->set_acl_base($c_dn);
+      $this->dialog->set_acl_category("fai");
       $this->dialog->parent = &$this;
       $this->is_dialog=true;
     }
@@ -257,17 +283,26 @@ class faiHook extends plugin
 
     $divlist = new divSelectBox("FAIhooks");
     $divlist->setHeight(400);
-    if((chkacl($this->acl,"cn")!="") || ($this->FAIstate == "freeze")){
-      $img_edit = "<input type='image' src='images/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
-      $img_remo = ""; 
-    }else{
-      $img_edit = "<input type='image' src='images/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
-      $img_remo = "<input type='image' src='images/edittrash.png' name='deletescript_%s'  title='"._("delete")."' alt='"._("delete")."'>";
-    }
 
     foreach($this->getList(true) as $key => $name){
 
-      if(($this->SubObjects[$key]['status'] == "new") || ($this->SubObjects[$key]['dn'] == "new")){
+      $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{
+        $act .= "<input type='image' src='images/edit.png'      name='editscript_%s'    title='"._("edit")."' alt='"._("edit")."'>";
+        if(preg_match("/d/",$acl)){
+          $act .="<input type='image' src='images/edittrash.png' name='deletescript_%s'  title='"._("delete")."' alt='"._("delete")."'>";
+        }
+      }
+
+      /* 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{
         $down = "<a href='getFAIscript.php?id=".base64_encode($name['dn'])."'>
@@ -275,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),$img_edit.$img_remo),
-              "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
@@ -297,8 +336,12 @@ class faiHook extends plugin
       }
     }
 
-    foreach($this->attributes as $attr){
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
+    $tmp = $this->plInfo();
+      
+    $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));
     }
 
     $display.= $smarty->fetch(get_template_path('faiHook.tpl', TRUE));
@@ -486,14 +529,12 @@ class faiHook extends plugin
           "plDescription" => _("FAI hook"),
           "plSelfModify"  => FALSE,
           "plDepends"     => array(),
-          "plPriority"    => 0,
+          "plPriority"    => 20,
           "plSection"     => array("administration"),
           "plCategory"    => array("fai"),
           "plProvidedAcls" => array(
-            "cn"                => _("Name"),
-            "description"       => _("Description"),
-            "FAItast"           => _("Task"),
-            "FAIscript"         => _("FAI script"))
+            "cn"                => _("Name")." ("._("Read only").")",
+            "description"       => _("Description"))
           ));
   }
 }