Code

Added gray out to navigation icons in divlist
[gosa.git] / plugins / admin / fai / class_faiPartitionTable.inc
index 336d93180bb3f397b173c7e54e7a7463df8c1caa..550e719991cc036a9955d983edb24279c90b7179 100644 (file)
@@ -20,6 +20,7 @@ class faiPartitionTable extends plugin
   var $dialog           = NULL;     // a dialog, e.g. new disk dialog
 
   var $FAIstate         = "";
+  var $ui;
 
   function faiPartitionTable ($config, $dn= NULL)
   {
@@ -28,6 +29,8 @@ class faiPartitionTable extends plugin
 
     $this->acl ="#all#";
 
+    $this->ui = get_userinfo();    
+
     /* If "dn==new" we try to create a new entry
      * Else we must read all objects from ldap which belong to this entry.
      * First read disks from ldap ... and then the partition definitions for the disks.
@@ -35,13 +38,6 @@ class faiPartitionTable extends plugin
     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])){
@@ -54,6 +50,14 @@ class faiPartitionTable extends plugin
       $ldap->cd ($this->dn);
       $ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))",array("*"));
       while($object = $ldap->fetch()){
+
+        /* Skip objects, that are tagged as removed */
+        if(isset($object['FAIstate'][0])){
+          if(preg_match("/removed$/",$object['FAIstate'][0])){
+            continue;
+          }
+        }
+
         $this->disks[$object['cn'][0]]['status']      = "edited";
         $this->disks[$object['cn'][0]]['dn']          = $object['dn'];
         $this->disks[$object['cn'][0]]['cn']          = $object['cn'][0];
@@ -72,6 +76,13 @@ class faiPartitionTable extends plugin
         $ldap->search("(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))",array("*"));
         while($partition = $ldap->fetch()){
 
+          /* Skip objects, that are tagged as removed */
+          if(isset($partition['FAIstate'][0])){
+            if(preg_match("/removed$/",$partition['FAIstate'][0])){
+              continue;
+            }
+          }
+
           /* remove count ... from ldap result 
            */
           foreach($partition as $key=>$val){
@@ -92,6 +103,20 @@ class faiPartitionTable extends plugin
     ksort($this->disks);
   }
 
+
+  function acl_base_for_current_object($dn)
+  {
+    if($dn == "new"){
+      if($this->dn == "new"){
+        $dn= $_SESSION['CurrentMainBase'];
+      }else{
+        $dn = $this->dn;
+      }
+    }
+    return($dn);
+  }
+
+
   function execute()
   {
        /* Call parent execute */
@@ -111,7 +136,8 @@ class faiPartitionTable extends plugin
         $usedDiskNames[]= $key;
       }
       $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames); 
-      $this->dialog->acl = $this->acl;
+      $this->dialog->set_acl_base($this->acl_base_for_current_object($this->dn));
+      $this->dialog->set_acl_category("fai");
       $this->dialog->FAIstate = $this->FAIstate;
       $this->is_dialog = true;
     }
@@ -134,17 +160,21 @@ class faiPartitionTable extends plugin
           $usedDiskNames[]= $key;
         }
       }
-      $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); 
-      $this->dialog->acl = $this->acl;
-      $this->dialog->FAIstate = $this->FAIstate;
-     
+    
       /* Set object info string, which will be displayed in plugin info line */ 
       if(isset($this->disks[$Udisk]['dn'])){
         $_SESSION['objectinfo'] = $this->disks[$Udisk]['dn'];
+        $dn = $this->disks[$Udisk]['dn'];
       }else{
         $_SESSION['objectinfo'] = "";
+        $dn = "new";
       }
-    
+
+      $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$Udisk]); 
+      $this->dialog->set_acl_base($this->acl_base_for_current_object($dn));
+      $this->dialog->set_acl_category("fai");
+      $this->dialog->FAIstate = $this->FAIstate;
+     
       $this->is_dialog = true;
     }
 
@@ -241,10 +271,15 @@ class faiPartitionTable extends plugin
       }
     }
    
-    foreach($this->attributes as $attr){
-      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
+    $dn = $this->acl_base_for_current_object($this->dn);
+    $smarty->assign("sub_object_is_addable",
+        preg_match("/c/",$this->ui->get_permissions($dn,"fai/faiPartitionTableEntry")) &&
+        !preg_match("/freeze/",$this->FAIstate));
+
+    $tmp = $this->plInfo();
+    foreach($tmp['plProvidedAcls'] as $name => $translated){
+      $smarty->assign($name."ACL",$this->getacl($name));
     }
-
     $disks = $this->getDisks();
     $smarty->assign("disks"   ,$disks);
     $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
@@ -257,24 +292,34 @@ class faiPartitionTable extends plugin
      */
     $a_return = array();
     foreach($this->disks as $key => $disk){
-      if($disk['status'] != "delete"){
-        $cnt=0;
-        foreach($disk['partitions'] as $val){
-          if($val['status']!="delete"){
-            $cnt ++;
-          }
-        }
-        if(!empty($disk['description'])){
-          if($cnt == 1){
-            $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition"), $cnt);
-          }else{
-            $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition(s)"), $cnt);
+
+      $dn = "new";
+      if(isset($obj['dn'])){
+        $dn = $obj['dn'];
+      }
+      $dn = $this->acl_base_for_current_object($dn);
+      $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
+      if(preg_match("/(r|w)/",$acl)) {
+
+        if($disk['status'] != "delete"){
+          $cnt=0;
+          foreach($disk['partitions'] as $val){
+            if($val['status']!="delete"){
+              $cnt ++;
+            }
           }
-        }else{
-          if($cnt == 1){
-            $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partition"), $cnt);
+          if(!empty($disk['description'])){
+            if($cnt == 1){
+              $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition"), $cnt);
+            }else{
+              $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition(s)"), $cnt);
+            }
           }else{
-            $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partition(s)"), $cnt);
+            if($cnt == 1){
+              $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partition"), $cnt);
+            }else{
+              $a_return[$key]=  $disk['cn'].", ".sprintf(_("%s partition(s)"), $cnt);
+            }
           }
         }
       }
@@ -289,10 +334,36 @@ class faiPartitionTable extends plugin
   {
     $ldap = $this->config->get_ldap_link();
     $ldap->cd ($this->dn);
-    $ldap->rmdir_recursive($this->dn);
-    $this->handle_post_events("remove");    
-  
-    /* This cannot be removed... */
+
+#    $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $this->dn);
+    $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $this->dn);
+    if($_SESSION['faifilter']['branch'] == "main"){
+      $use_dn = $this->dn;
+    }
+
+    prepare_to_save_FAI_object($use_dn,array(),true);
+    
+    foreach($this->disks as $disk){
+
+      $disk_dn = "cn=".$disk['cn'].",".$this->dn;
+#      $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $disk_dn);
+      $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $disk_dn);
+      if($_SESSION['faifilter']['branch'] == "main"){
+        $use_dn = $disk_dn;
+      }
+      prepare_to_save_FAI_object($use_dn,array(),true);
+
+      foreach($disk['partitions'] as $key => $partition){    
+     
+        $partition_dn= "FAIpartitionNr=".$partition['FAIpartitionNr'].",".$disk_dn;      
+#        $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $partition_dn);
+        $use_dn = preg_replace("/".normalizePreg(get_release_dn($this->dn))."/i", $_SESSION['faifilter']['branch'], $partition_dn);
+        if($_SESSION['faifilter']['branch'] == "main"){
+          $use_dn = $disk_dn;
+        }
+        prepare_to_save_FAI_object($use_dn,array(),true);
+      }
+    }
   }
 
 
@@ -333,24 +404,11 @@ class faiPartitionTable extends plugin
 
     $ldap = $this->config->get_ldap_link();
 
-    if($this->new){
-      $ldap->cd($this->config->current['BASE']);
-      $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
-      $ldap->cd($this->dn);
-      $ldap->add($this->attrs);
-      show_ldap_error($ldap->get_error());
-    }else{
-      /* Add partition table to ldap
-       */
-      $ldap->cd($this->dn);
-      $this->cleanup();
-      $ldap->modify ($this->attrs); 
-      show_ldap_error($ldap->get_error());
-    }
+    prepare_to_save_FAI_object($this->dn,$this->attrs);
+    show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/partition table with dn '%s' failed."),$this->dn));
   
     /* Do object tagging */
     $this->handle_object_tagging();
-    show_ldap_error($ldap->get_error());
   
     /* Sort entries, because we must delete entries with status="delete" first */
     $order = array();
@@ -385,32 +443,19 @@ class faiPartitionTable extends plugin
       if(isset($attrs['objectClass']) && in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){
         $disk_attrs['objectClass'][] = "gosaAdministrativeUnitTag";
       }
+
       if($disk['status'] == "delete"){
-        $ldap->cd($disk_dn);
-        $ldap->rmdir_recursive($disk_dn);
-      }elseif($disk['status']== "edited"){
-        if(empty($disk_attrs['description'])){
-          $disk_attrs['description']=array();
-        }
-        $ldap->cd($disk_dn);
-        $this->cleanup();
-        $ldap->modify ($disk_attrs); 
-      }elseif($disk['status']== "new"){
-        if(empty($disk_attrs['description'])){
-          unset($disk_attrs['description']);
-        }
-        $ldap->cd($this->config->current['BASE']);
-        $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $disk_dn));
-        $ldap->cd($disk_dn);
-        $ldap->add($disk_attrs);
-      }else{
-        print_red("unknown status while saving disks");
+        prepare_to_save_FAI_object($disk_dn,array(),true);
+        $this->handle_post_events("remove");
+      }elseif($disk['status'] == "edited"){
+        prepare_to_save_FAI_object($disk_dn,$disk_attrs);
+        $this->handle_post_events("modify");
+      }elseif($disk['status']=="new"){
+        prepare_to_save_FAI_object($disk_dn,$disk_attrs);
+        $this->handle_post_events("add");
       }
 
-      show_ldap_error($ldap->get_error());
       $this->handle_object_tagging($disk_dn, $this->gosaUnitTag);
-      show_ldap_error($ldap->get_error());
 
       if($disk['status']!="delete")
       /* Add all partitions */
@@ -450,34 +495,40 @@ class faiPartitionTable extends plugin
           $partition_attrs['objectClass'][] = "gosaAdministrativeUnitTag";
         }
 
-        if(($partition['status'] == "delete")&&($disk['status']!="new")){
-          $ldap->cd($partition_dn);
-          $ldap->rmdir_recursive($partition_dn);
-        }elseif($partition['status'] == "new"){
-          if(empty($partition_attrs['description'])){
-            unset($partition_attrs['description']);
-          }
-          $ldap->cd($this->config->current['BASE']);
-          $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $partition_dn));
-          $ldap->cd($partition_dn);
-          $ldap->add($partition_attrs);
+        if($partition['status'] == "delete"){
+          prepare_to_save_FAI_object($partition_dn,array(),true);
+          $this->handle_post_events("remove");
         }elseif($partition['status'] == "edited"){
-          if(empty($partition_attrs['description'])){
-            $partition_attrs['description']=array();
-          }
-          $ldap->cd($partition_dn);
-          $this->cleanup();
-$ldap->modify ($partition_attrs); 
-
-        } 
-        show_ldap_error($ldap->get_error());
+          prepare_to_save_FAI_object($partition_dn,$partition_attrs);
+          $this->handle_post_events("modify");
+        }elseif($partition['status']=="new"){
+          prepare_to_save_FAI_object($partition_dn,$partition_attrs);
+          $this->handle_post_events("add");
+        }
 
         $this->handle_object_tagging($partition_dn, $this->gosaUnitTag);
-        show_ldap_error($ldap->get_error());
       }
     }
     $this->handle_post_events("add");
   }
+
+
+  /* Return plugin informations for acl handling */ 
+  function plInfo()
+  {
+    return (array( 
+          "plShortName" => _("Partition table"),
+          "plDescription" => _("FAI partition table"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 26,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("fai"),
+          "plProvidedAcls" => array(
+            "cn"                => _("Name")." ("._("Read only").")",
+            "description"       => _("Description"))
+          ));
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: