Code

Added "gosaAdministrativeUnitTag" fix for partition tables
[gosa.git] / plugins / admin / fai / class_faiPartitionTable.inc
index d5feaa4df0e61ba95efc425c845f416320d6a0c0..336d93180bb3f397b173c7e54e7a7463df8c1caa 100644 (file)
@@ -19,11 +19,15 @@ class faiPartitionTable extends plugin
   var $is_dialog        = false;    // specifies which buttons will be shown to save or abort
   var $dialog           = NULL;     // a dialog, e.g. new disk dialog
 
+  var $FAIstate         = "";
+
   function faiPartitionTable ($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.
      * First read disks from ldap ... and then the partition definitions for the disks.
@@ -31,6 +35,19 @@ 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])){
+        $this->FAIstate = $this->attrs['FAIstate'][0];
+      }
+
       /* Read all disks from ldap taht are defined fot this partition table 
        */
       $ldap = $this->config->get_ldap_link();
@@ -72,10 +89,14 @@ class faiPartitionTable extends plugin
         }  
       }
     }
+    ksort($this->disks);
   }
 
   function execute()
   {
+       /* Call parent execute */
+       plugin::execute();
+
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
@@ -90,20 +111,40 @@ class faiPartitionTable extends plugin
         $usedDiskNames[]= $key;
       }
       $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames); 
+      $this->dialog->acl = $this->acl;
+      $this->dialog->FAIstate = $this->FAIstate;
       $this->is_dialog = true;
     }
 
     /* Edit disk.
      * Open dialog which allows us to edit the selected entry 
      */    
+
+    if($this->dn != "new"){
+      $_SESSION['objectinfo']= $this->dn;
+    }
+
     if((isset($_POST['EditDisk']))&&(isset($_POST['disks']))){
       $usedDiskNames =array();
+
+      $Udisk = $_POST['disks'][0];
+      
       foreach($this->disks  as $key=>$disk){
-        if($key != $_POST['disks']){
+        if($key != $Udisk){
           $usedDiskNames[]= $key;
         }
       }
-      $this->dialog = new faiPartitionTableEntry($this->config,$this->dn,$usedDiskNames,$this->disks[$_POST['disks']]); 
+      $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'];
+      }else{
+        $_SESSION['objectinfo'] = "";
+      }
+    
       $this->is_dialog = true;
     }
 
@@ -114,37 +155,44 @@ class faiPartitionTable extends plugin
       $this->dialog = NULL;
       $this->is_dialog=false;
     }
-  
+
     /* Dialog saved
      * Save given data from Dialog, if no error is occured
      */
     if(isset($_POST['SaveDisk'])){
-      $this->dialog->save_object();
-      if(count($this->dialog->check())){
-        foreach($this->dialog->check() as $msg){
-          print_red($msg);
-        }
-      }else{
-        $disk = $this->dialog->save();
-        if(isset($disk['rename'])){
-          if($this->disks[$disk['rename']['from']]['status']=="edited"){
-            $this->disks[$disk['rename']['from']]['status']="delete";
-          }else{
-            unset($this->disks[$disk['rename']['from']]);
+
+      if($this->FAIstate != "freeze"){
+        $this->dialog->save_object();
+        if(count($this->dialog->check())){
+          foreach($this->dialog->check() as $msg){
+            print_red($msg);
           }
-  
-          foreach($disk['partitions'] as $key => $val){
-            if($disk['partitions'][$key]['status']!="delete"){
-              $disk['partitions'][$key]['status']= "new";
+        }else{
+          $disk = $this->dialog->save();
+          if(isset($disk['rename'])){
+            if($this->disks[$disk['rename']['from']]['status']=="edited"){
+              $this->disks[$disk['rename']['from']]['status']="delete";
+            }else{
+              unset($this->disks[$disk['rename']['from']]);
             }
+
+            foreach($disk['partitions'] as $key => $val){
+              if($disk['partitions'][$key]['status']!="delete"){
+                $disk['partitions'][$key]['status']= "new";
+              }
+            }
+
+            $disk['status']="new";
+            $disk['cn']= $disk['rename']['to'];
           }
 
-          $disk['status']="new";
-          $disk['cn']= $disk['rename']['to'];
+          $this->disks[$disk['cn']]=$disk; 
+          unset($this->dialog);
+          $this->dialog = NULL;
+          $this->is_dialog=false;
+          ksort($this->disks);
         }
-      
-        $this->disks[$disk['cn']]=$disk; 
-        unset($this->dialog);
+      }else{
         $this->dialog = NULL;
         $this->is_dialog=false;
       }
@@ -154,21 +202,24 @@ class faiPartitionTable extends plugin
      * Assign delete status for all its partitions      
      */
     if((isset($_POST['DelDisk']))&&(!empty($_POST['disks']))){
-      $disk = $_POST['disks'];
-      if($this->disks[$disk]['status']=="edited"){
-        $this->disks[$disk."-delete"]=$this->disks[$disk];
-        unset($this->disks[$disk]);
-        $disk = $disk."-delete";        
-        $this->disks[$disk]['status']="delete";
-        foreach($this->disks[$disk]['partitions'] as $name => $value ){
-          if($value['status']=="edited"){
-            $this->disks[$disk]['partitions'][$name]['status']="delete"; 
+      if($this->FAIstate != "freeze"){
+        foreach($_POST['disks'] as $disk) {
+          if($this->disks[$disk]['status']=="edited"){
+            $this->disks[$disk."-delete"]=$this->disks[$disk];
+            unset($this->disks[$disk]);
+            $disk = $disk."-delete";        
+            $this->disks[$disk]['status']="delete";
+            foreach($this->disks[$disk]['partitions'] as $name => $value ){
+              if($value['status']=="edited"){
+                $this->disks[$disk]['partitions'][$name]['status']="delete"; 
+              }else{
+                unset($this->disks[$disk]['partitions'][$name]);
+              }
+            }
           }else{
-            unset($this->disks[$disk]['partitions'][$name]);
+            unset($this->disks[$disk]);
           }
         }
-      }else{
-        unset($this->disks[$disk]);
       }
     }
 
@@ -189,10 +240,13 @@ class faiPartitionTable extends plugin
         $smarty->assign($attrs."CHK"," disabled ");
       }
     }
-    
+   
+    foreach($this->attributes as $attr){
+      $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
+    }
+
     $disks = $this->getDisks();
     $smarty->assign("disks"   ,$disks);
-    $smarty->assign("diskKeys",array_flip($disks));
     $display.= $smarty->fetch(get_template_path('faiPartitionTable.tpl', TRUE));
     return($display);
   }
@@ -211,9 +265,17 @@ class faiPartitionTable extends plugin
           }
         }
         if(!empty($disk['description'])){
-          $a_return[$key]=  $disk['cn']." [".$disk['description']."], ".sprintf(_("%s partition(s)"), $cnt);
+          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);
+          }
         }
       }
     }
@@ -238,6 +300,7 @@ class faiPartitionTable extends plugin
    */
   function save_object()
   {
+    if($this->FAIstate == "freeze") return;
     plugin::save_object();
     foreach($this->attributes as $attrs){
       if(isset($_POST[$attrs])){
@@ -250,17 +313,8 @@ class faiPartitionTable extends plugin
   /* Check supplied data */
   function check()
   {
-
-    $message= array();
-
-    $str = utf8_encode("üöä");
-    if((empty($this->description))||(preg_match("/[^a-z0-9".$str."\.,;:\-_\? ]/i",$this->description))){
-      $message[]=_("Please enter a valid description.");
-    }
-
-    if((empty($this->cn))||(preg_match("/[^a-z0-9]/i",$this->cn))){
-      $message[]=_("Please enter a valid name.");
-    }
+    /* Call common method to give check the hook */
+    $message= plugin::check();
 
     return ($message);
   }
@@ -289,10 +343,14 @@ class faiPartitionTable extends plugin
       /* Add partition table to ldap
        */
       $ldap->cd($this->dn);
-      $ldap->modify($this->attrs);
+      $this->cleanup();
+      $ldap->modify ($this->attrs); 
       show_ldap_error($ldap->get_error());
     }
   
+    /* 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();
@@ -313,14 +371,35 @@ class faiPartitionTable extends plugin
       $disk_attrs['cn']           =  $disk['cn'];
       $disk_attrs['description']  =  $disk['description']; 
       $disk_attrs['objectClass']  =  array("top","FAIclass","FAIpartitionDisk");
-  
+
+      if($disk['status']=="new"){
+        $ldap->cat($disk_dn,array("objectClass"));
+        if($ldap->count()){
+          $disk['status']="edited";
+        }
+      }
+
+      /* Fix problem with missing objectClass "gosaAdministrativeUnitTag" for disks */
+      $ldap->cat($disk_dn,array("objectClass"));
+      $attrs = $ldap->fetch();
+      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);
-        $ldap->modify($disk_attrs);
+        $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);
@@ -330,6 +409,9 @@ class faiPartitionTable extends plugin
       }
 
       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 */
       foreach($disk['partitions'] as $key => $partition){
@@ -349,20 +431,49 @@ class faiPartitionTable extends plugin
         
         unset($partition_attrs['status']);
         unset($partition_attrs['old_cn']);
-      
+
+        if($partition['status']=="new"){
+          $ldap->cat($partition_dn,array("objectClass"));
+          if($ldap->count()){
+            $partition['status']="edited";
+          }
+        }
+
+        if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){
+          $partition_attrs['FAImountPoint']="swap";
+        }
+
+        /* Fix problem with missing objectClass "gosaAdministrativeUnitTag" for partitions */
+        $ldap->cat($partition_dn,array("objectClass"));
+        $attrs = $ldap->fetch();
+        if(isset($attrs['objectClass']) && in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){
+          $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);
         }elseif($partition['status'] == "edited"){
+          if(empty($partition_attrs['description'])){
+            $partition_attrs['description']=array();
+          }
           $ldap->cd($partition_dn);
-          $ldap->modify($partition_attrs);
+          $this->cleanup();
+$ldap->modify ($partition_attrs); 
+
         } 
-      show_ldap_error($ldap->get_error());
+        show_ldap_error($ldap->get_error());
+
+        $this->handle_object_tagging($partition_dn, $this->gosaUnitTag);
+        show_ldap_error($ldap->get_error());
       }
     }
     $this->handle_post_events("add");