Code

Prepared for multiple asterisk servers
[gosa.git] / plugins / admin / groups / class_groupGeneric.inc
index 5d4e37da129e058980372e21c0d560230e994f86..c0fb36eb343b6ba14af8e60f9713f40713cf4b0a 100644 (file)
@@ -44,6 +44,8 @@ class group extends plugin
   var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
   var $objectclasses= array("top", "posixGroup");
 
+  var $CopyPasteVars  = array("force_gid","fon_group","smbgroup","groupType","sambaSID","sambaDomainName","SID","nagios_group","sambaGroupType");
+
   function group ($config, $dn= NULL)
   {
     plugin::plugin ($config, $dn);
@@ -154,7 +156,9 @@ class group extends plugin
         $this->base= dn2base($ui->dn);
       }
     } else {
-      $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
+
+      /* Get object base */
+      $this->base =preg_replace ("/^[^,]+,".normalizePreg(get_groups_ou())."/","",$this->dn);
     }
 
     /* This is always an account */
@@ -205,33 +209,13 @@ class group extends plugin
       $this->reload();
     }
 
-    /* Only display bases that we are able to read/write */
-    $ui = get_userinfo();
-    $bases = array();
-    if($this->dn == "new") {
-      foreach($this->config->idepartments as $dn => $name){
-        $acl = $ui->get_permissions($dn,"groups/group") ;
-        if(preg_match("/c/",$acl)){
-          $bases[$dn]=$name;
-        }
-      }
-    }else{
-      foreach($this->config->idepartments as $dn => $name){
-        $acl = $ui->get_category_permissions($dn,"groups") ;
-        if(preg_match("/w/",$acl)){
-          $bases[$dn]=$name;
-        }
-      }
-    }
-
-
     /* Base select dialog */
     $once = true;
     foreach($_POST as $name => $value){
       if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
           
         $once = false;
-        $this->dialog = new baseSelectDialog($this->config,$this,$bases);
+        $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
         $this->dialog->setCurrentBase($this->base);
       }
     }
@@ -244,7 +228,10 @@ class group extends plugin
       if($this->dialog->isClosed()){
         $this->dialog = false;
       }elseif($this->dialog->isSelected()){
-        if($this->acl_is_moveable()){
+
+        /* Check if selected base is valid */
+        $tmp = $this->get_allowed_bases();
+        if(isset($tmp[$_POST['base']])){
           $this->base = $this->dialog->isSelected();
         }
         $this->dialog= false;
@@ -273,13 +260,6 @@ class group extends plugin
       $smarty->assign("pickupGroup",false);
     }
 
-    /* Assign base ACL */
-    $baseACL = $this->getacl("base");
-    if(!$this->acl_is_moveable()) {
-      $baseACL = preg_replace("/w/","",$baseACL);
-    }
-    $smarty->assign("baseACL",          $baseACL);
-
     /* Manage object add dialog */
     if ($this->group_dialog){
 
@@ -313,14 +293,7 @@ class group extends plugin
       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
       $smarty->assign("tree_image", get_template_path('images/tree.png'));
 
-      /* Generate list of bases */
-      $check = $ui->get_module_departments("users");
-      $bases_user_select = array();
-      foreach($check as $dn_allowed){
-        $bases_user_select[$dn_allowed] = $this->config->idepartments[$dn_allowed];
-      }
-  
-      $smarty->assign("deplist", $bases_user_select);
+      $smarty->assign("deplist", $this->get_allowed_bases("users/user"));
       $smarty->assign("alphabet", generate_alphabet());
       foreach( array("dselect", "regex","SubSearchGroup") as $type){
         $smarty->assign("$type", $gufilter[$type]);
@@ -332,12 +305,7 @@ class group extends plugin
       return ($display);
     }
 
-    /* Bases / Departments */
-    if (isset($_POST['base'])){
-      $this->base= $_POST['base'];
-    }
-
-    $smarty->assign("bases", $bases);
+    $smarty->assign("bases", $this->get_allowed_bases());
     $smarty->assign("base_select", $this->base);
 
     if ($this->samba3){
@@ -554,19 +522,26 @@ class group extends plugin
     /* Save additional values for possible next step */
     if (isset($_POST['groupedit'])){
 
+      /* Create a base backup and reset the 
+          base directly after calling plugin::save_object();  
+         Base will be set seperatly a few lines below */
+      $base_tmp = $this->base;
       plugin::save_object();
+      $this->base = $base_tmp;
 
       $this->force_gid= 0;
 
-
       /* Only reset sambagroup flag if we are able to write this flag */
       if($this->acl_is_writeable("sambaGroupType")){
         $this->smbgroup = 0;
       }
 
       /* Get base selection */
-      if($this->acl_is_moveable() && isset($_POST['base'])){
-        $this->base = $_POST['base'];
+      if(isset($_POST['base'])){
+        $tmp = $this->get_allowed_bases();
+        if(isset($tmp[$_POST['base']])){
+          $this->base = $_POST['base'];
+        }
       }
 
       foreach (array(
@@ -765,10 +740,6 @@ class group extends plugin
       $new_dn= $this->dn;
     }
 
-    if ($this->orig_dn == "new" && !$this->acl_is_createable()){
-      $message[]= _("You have no permissions to create a group on this 'Base'.");
-    }
-
     /* must: cn */
     if ($this->cn == "" && $this->acl_is_writeable("cn")){
       $message[]= "The required field 'Name' is not set.";
@@ -848,14 +819,14 @@ class group extends plugin
     }
 
     /* Find out next free id near to UID_BASE */
-    for ($id= $this->config->current['UIDBASE']; $id++; $id<65000){
+    for ($id= $this->config->current['UIDBASE']; $id++; $id < pow(2,32)){
       if (!in_array($id, $ids)){
         return ($id);
       }
     }
 
-    /* Should not happen */
-    if ($id == 65000){
+    /* Check if id reached maximum */
+    if ($id >= pow(2,32)){
       print_red(_("Too many users, can't allocate a free ID!"));
       exit;
     }
@@ -914,10 +885,11 @@ class group extends plugin
 
           "plProvidedAcls"    => array(
             "cn"                => _("Name"),
+            "base"              => _("Base"),
             "description"       => _("Description"),
 
-            "fonGroup"         => _("Phone pickup group"),
-            "nagiosGroup"      => _("Nagios group"),
+            "fonGroup"          => _("Phone pickup group"),
+            "nagiosGroup"       => _("Nagios group"),
 
             "gidNumber"         => _("GID"),
             "memberUid"         => _("Group member"),