Code

Fixed groupmail acl stuff
[gosa.git] / plugins / admin / groups / class_groupGeneric.inc
index 52df6e02369d44cc8bd4e8795c04e192b975ed0f..e1286d7e1b1344263e9783e717d637d24904a748 100644 (file)
@@ -32,9 +32,12 @@ class group extends plugin
   var $orig_dn= "";
   var $has_mailAccount= FALSE;
   var $group_dialog= FALSE;
+  var $nagios_group =FALSE;
+  var $sambaGroupType;
+  var $dialog;
 
   /* attribute list for save action */
-  var $attributes= array("cn", "description", "gidNumber");
+  var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID");
   var $objectclasses= array("top", "posixGroup");
 
   function group ($config, $dn= NULL)
@@ -75,6 +78,11 @@ class group extends plugin
       } else {
         $this->fon_group= TRUE;
       }
+      if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == NULL ){
+        $this->nagios_group= FALSE;
+      } else {
+        $this->nagios_group= TRUE;
+      }
     }
 
     /* Set mail flag */
@@ -87,7 +95,7 @@ class group extends plugin
       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
       $ldap= $this->config->get_ldap_link();
       $ldap->cd($this->config->current['BASE']);
-      $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))");
+      $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
       if ($ldap->count() != 0){
         $attrs= $ldap->fetch();
         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
@@ -149,7 +157,13 @@ class group extends plugin
 
   function execute()
   {
-    /* Do we represent a valid group? */
+       /* Call parent execute */
+       plugin::execute();
+
+  $ui= get_userinfo();
+  $acla= get_permissions ($ui->dn, $ui->subtreeACL);
+  $this->acl= get_module_permission($acla, "group", $ui->dn);
+  /* Do we represent a valid group? */
     if (!$this->is_account && $this->parent == NULL){
       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
         _("This 'dn' is no group.")."</b>";
@@ -187,7 +201,32 @@ class group extends plugin
       $this->reload();
     }
 
-    /* Assign templating stuff */
+    /* Base select dialog */
+    $once = true;
+    foreach($_POST as $name => $value){
+      if(preg_match("/^chooseBase/",$name) && $once){
+        $once = false;
+        $this->dialog = new baseSelectDialog($this->config);
+        $this->dialog->setCurrentBase($this->base);
+      }
+    }
+
+    /* Dialog handling */
+    if(is_object($this->dialog)){
+      /* Must be called before save_object */
+      $this->dialog->save_object();
+
+      if($this->dialog->isClosed()){
+        $this->dialog = false;
+      }elseif($this->dialog->isSelected()){
+        $this->base = $this->dialog->isSelected();
+        $this->dialog= false;
+      }else{
+        return($this->dialog->execute());
+      }
+    }
+
+   /* Assign templating stuff */
     $smarty= get_smarty();
     if ($this->samba3){
       $smarty->assign("samba3", "true");
@@ -195,6 +234,18 @@ class group extends plugin
       $smarty->assign("samba3", "");
     }
 
+    if(search_config($this->config->data['MENU'], "nagiosaccount", "CLASS")){
+      $smarty->assign("nagios",true);
+    }else{
+      $smarty->assign("nagios",false);
+    }
+    
+    if(search_config($this->config->data['MENU'], "phoneAccount", "CLASS")){
+      $smarty->assign("pickupGroup",true);
+    }else{
+      $smarty->assign("pickupGroup",false);
+    }
+
     /* Manage object add dialog */
     if ($this->group_dialog){
 
@@ -283,6 +334,8 @@ class group extends plugin
     }
     if ($this->force_gid != "1"){
       $smarty->assign("forceMode", "disabled");
+    }else{
+      $smarty->assign("forceMode", "");
     }
     $smarty->assign("force_gidACL", chkacl($this->acl, "gidNumber"));
     $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
@@ -293,6 +346,13 @@ class group extends plugin
     }
     $smarty->assign("fon_groupACL", chkacl($this->acl, "fon_group"));
 
+    if ($this->nagios_group){
+      $smarty->assign("nagios_group", "checked");
+    } else {
+      $smarty->assign("nagios_group", "");
+    }
+    $smarty->assign("nagios_groupACL", chkacl($this->acl, "nagios_group"));
+
     /* Fields */
     foreach (array("cn", "description", "gidNumber") as $val){
       $smarty->assign("$val", $this->$val);
@@ -339,13 +399,9 @@ class group extends plugin
     $this->users= array();
     $ldap= $this->config->get_ldap_link();
     $gufilter= get_global("gufilter");
-    $ldap->cd ($gufilter['dselect']);
-    $ldap->search ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))");
-    natcasesort ($this->users);
-    reset ($this->users);
 
     $ldap->cd ($gufilter['dselect']);
-    $ldap->search ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))");
+    $ldap->ls ("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$)))",get_people_ou().$gufilter['dselect'],array("uid", "sn", "givenName"));
     $this->allusers= array();
     while ($attrs= $ldap->fetch()){
       if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
@@ -427,7 +483,13 @@ class group extends plugin
           $this->fon_group= FALSE;
         }
       }
-
+        if (chkacl ($this->acl, "nagios_group") == ""){
+        if (isset ($_POST['nagios_group'])){
+          $this->nagios_group= TRUE;
+        } else {
+          $this->nagios_group= FALSE;
+        }
+      }
     }
   }
 
@@ -462,7 +524,8 @@ class group extends plugin
     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
-          $this->attrs['objectClass'][$i] != 'goFonPickupGroup'){
+          $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
+        $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
         $tmp[]= $this->attrs['objectClass'][$i];
       }
     }
@@ -485,7 +548,7 @@ class group extends plugin
           while(TRUE){
             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
             $ldap->cd($this->config->current['BASE']);
-            $ldap->search("(sambaSID=$sid)");
+            $ldap->search("(sambaSID=$sid)",array("sambaSID"));
             if ($ldap->count() == 0){
               break;
             }
@@ -514,6 +577,11 @@ class group extends plugin
       $this->attrs['objectClass'][]= "goFonPickupGroup";
     }
 
+    /* Add nagios functionality */
+    if ($this->nagios_group){
+       $this->attrs['objectClass'][]= "nagiosContactGroup";
+    }
+
     /* Take members array */
     if (count ($this->memberUid)){
       $this->attrs['memberUid']= array_unique($this->memberUid);
@@ -547,6 +615,7 @@ class group extends plugin
 
     /* Write back to ldap */
     $ldap->cd($this->dn);
+    $this->cleanup();
     $ldap->$mode($this->attrs);
 
     $ret= 0;
@@ -575,9 +644,9 @@ class group extends plugin
     }
 
     $ui= get_userinfo();
-    $acl= get_permissions ($new_dn, $ui->subtreeACL);
-    $acl= get_module_permission($acl, "group", $new_dn);
-    if (chkacl($acl, "create") != ""){
+    $acl= get_permissions ($ui->dn, $ui->subtreeACL);
+    $acl= get_module_permission($acl, "group", $ui->dn);
+    if (chkacl($this->acl, "create") != ""){
       $message[]= _("You have no permissions to create a group on this 'Base'.");
     }
 
@@ -594,7 +663,7 @@ class group extends plugin
     /* Check for used 'cn' */
     $ldap= $this->config->get_ldap_link();
     $ldap->cd($this->config->current['BASE']);
-    $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))");
+    $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
     if ($ldap->count() != 0){
 
       /* New entry? */
@@ -632,7 +701,12 @@ class group extends plugin
     $ldap= $this->config->get_ldap_link();
 
     $ldap->cd ($this->config->current['BASE']);
-    $ldap->search ("($attrib=*)");
+    if (preg_match('/gidNumber/i', $attrib)){
+      $oc= "posixGroup";
+    } else {
+      $oc= "posixAccount";
+    }
+    $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
 
     /* Get list of ids */
     while ($attrs= $ldap->fetch()){