Code

Initial scalix plugin
[gosa.git] / plugins / admin / ogroups / class_ogroup.inc
index 461002c82cd79a89235f773d4072ecc51575f282..7b79378f378894218e6a5fdc23e9752f1204781d 100644 (file)
@@ -25,7 +25,7 @@ class ogroup extends plugin
   var $gosaGroupObjects= "";
   var $department= "";
   var $objects= array();
-  var $allobjects= array();
+  var $objcache= array();
   var $memberList= array();
   var $member= array();
   var $orig_dn= "";
@@ -46,6 +46,7 @@ class ogroup extends plugin
     if (isset($this->attrs['member'])){
       foreach ($this->attrs['member'] as $key => $value){
         if ("$key" != "count"){
+          $value= @LDAP::convert($value);
           $this->member["$value"]= "$value";
         }
       }
@@ -71,6 +72,7 @@ class ogroup extends plugin
           "W" => "workstations",
           "T" => "terminals",
           "F" => "phones",
+          "_" => "subtrees",
           "P" => "printers") as $key => $val){
 
       if (preg_match("/$key/", $this->gosaGroupObjects)){
@@ -80,25 +82,28 @@ class ogroup extends plugin
       }
     }
     register_global("ogfilter", $ogfilter);
-  
-    if(isset($_SESSION['CurrentMainBase'])){
-     $this->base = $_SESSION['CurrentMainBase'];
+    /* Set base */
+    if ($this->dn == "new"){
+      $this->base= $_SESSION['CurrentMainBase'];
+    } else {
+      $this->base= preg_replace("/^[^,]+,".get_groups_ou()."/","",$this->dn);
     }
 
-     /* set permissions */
+    /* set permissions */
     $ui= get_userinfo();
     $acl= get_permissions ($ui->dn, $ui->subtreeACL);
     $this->acl= get_module_permission($acl, "ogroup", $ui->dn);
 
-
     /* Load member data */
     $this->reload();
   }
 
-  function AddDelMembership($NewMember = false){
-
+  function AddDelMembership($NewMember = false)
+  {
     if($NewMember){
-      $this->memberList[$NewMember]= $this->allobjects[$NewMember];
+      $this->importMember($NewMember);
+      $this->memberList[$NewMember]= $this->objcache[$NewMember];
       $this->member[$NewMember]= $NewMember;
       unset ($this->objects[$NewMember]);
       uasort ($this->memberList, 'sort_list');
@@ -106,7 +111,7 @@ class ogroup extends plugin
       $this->reload();
     }else{
       /* Delete objects from group */
-      if (isset($_POST['delete_membership']) && isset($_POST['members'])){
+      if (isset($_POST['delete_membership']) && isset($_POST['members'])  && chkacl($this->acl,"gosaGroupObjects") == ""){
         foreach ($_POST['members'] as $value){
           $this->objects["$value"]= $this->memberList[$value];
           unset ($this->memberList["$value"]);
@@ -118,7 +123,7 @@ class ogroup extends plugin
       }
 
       /* Add objects to group */
-      if (isset($_POST['add_object_finish']) && isset($_POST['objects'])){
+      if (isset($_POST['add_object_finish']) && isset($_POST['objects'])  && chkacl($this->acl,"gosaGroupObjects") == ""){
         foreach ($_POST['objects'] as $value){
           $this->memberList["$value"]= $this->objects[$value];
           $this->member["$value"]= $value;
@@ -146,7 +151,7 @@ class ogroup extends plugin
     }
 
     /* Delete objects from group */
-    if (isset($_POST['delete_membership']) && isset($_POST['members'])){
+    if (isset($_POST['delete_membership']) && isset($_POST['members']) && chkacl($this->acl,"gosaGroupObjects") == ""){
       foreach ($_POST['members'] as $value){
         if(isset($this->memberList[$value])){
           $this->objects["$value"]= $this->memberList[$value];
@@ -179,7 +184,7 @@ class ogroup extends plugin
     /* Base select dialog */
     $once = true;
     foreach($_POST as $name => $value){
-      if(preg_match("/^chooseBase/",$name) && $once){
+      if(preg_match("/^chooseBase/",$name) && $once && chkacl($this->acl,"base") == ""){
         $once = false;
         $this->dialog = new baseSelectDialog($this->config);
         $this->dialog->setCurrentBase($this->base);
@@ -202,7 +207,7 @@ class ogroup extends plugin
     }
 
     /* Add objects? */
-    if (isset($_POST["edit_membership"])){
+    if (isset($_POST["edit_membership"])  && chkacl($this->acl,"gosaGroupObjects") == ""){
       $this->group_dialog= TRUE;
       $this->dialog= TRUE;
     }
@@ -225,7 +230,7 @@ class ogroup extends plugin
       }
       if (isset($_POST['dselect'])){
         foreach( array("accounts", "groups", "applications", "departments",
-              "servers", "workstations", "terminals", "printers",
+              "servers", "workstations", "terminals", "printers","subtrees",
               "phones") as $type){
 
           if (isset($_POST[$type])) {
@@ -255,7 +260,7 @@ class ogroup extends plugin
       $smarty->assign("deplist", $this->config->idepartments);
       $smarty->assign("alphabet", generate_alphabet());
       foreach( array("dselect", "regex", "accounts", "groups", "applications",
-            "departments", "servers", "workstations", "terminals",
+            "departments", "servers", "workstations", "terminals","subtrees",
             "printers", "phones") as $type){
         $smarty->assign("$type", $ogfilter[$type]);
       }
@@ -267,10 +272,9 @@ class ogroup extends plugin
     }
 
     /* Bases / Departments */
-   
-      if (isset($_POST['base'])){
-        $this->base= $_POST['base'];
-      }
+    if (isset($_POST['base']) && chkacl($this->acl,"base") == ""){
+      $this->base= $_POST['base'];
+    }
 
     /* Assemble combine string */
     if ($this->gosaGroupObjects == "[]"){
@@ -334,7 +338,6 @@ class ogroup extends plugin
       if (chkacl ($this->acl, "base") == "" && isset($_POST["base"])){
         $this->base= $_POST["base"];
       }
-
     }
   }
 
@@ -409,8 +412,15 @@ class ogroup extends plugin
 
     /* Perform search for selected objectClasses */
     foreach($objectClasses as $class=> $basedn){
-      $ldap->ls("(&(objectClass=".$class.")(|(uid=$regex)(cn=$regex)(ou=$regex)))",$basedn.$ogfilter['dselect'] ,
-          array("dn", "cn", "description", "objectClass", "sn", "givenName", "uid","ou"));
+
+      if($ogfilter['subtrees'] == "checked"){
+        $ldap->cd($ogfilter['dselect']);
+        $ldap->search("(&(objectClass=".$class.")(|(uid=$regex)(cn=$regex)(ou=$regex)))",
+            array("dn", "cn", "description", "objectClass", "sn", "givenName", "uid","ou"));
+      }else{
+        $ldap->ls("(&(objectClass=".$class.")(|(uid=$regex)(cn=$regex)(ou=$regex)))",$basedn.$ogfilter['dselect'] ,
+            array("dn", "cn", "description", "objectClass", "sn", "givenName", "uid","ou"));
+      }
       
       /* fetch results and append them to the list */
       while($attrs = $ldap->fetch()){
@@ -431,46 +441,6 @@ class ogroup extends plugin
     uasort ($this->objects, 'sort_list');
     reset ($this->objects);
 
-    /*###########
-      Get a list with all possible objects, to detect objects which doesn't exists anymore ... 
-      ###########*/
-
-    /* Only do this, if this wasn't already done */
-    if(count($this->allobjects) == 0){
-      $ldap->cd ($this->config->current['BASE']);
-      $filter="(objectClass=gosaAccount)".        
-              "(objectClass=posixGroup)".
-              "(objectClass=gosaApplication)".
-              "(objectClass=gosaDepartment)".
-              "(objectClass=goServer)".
-              "(objectClass=gotoWorkstation)".
-              "(objectClass=gotoTerminal)".
-              "(objectClass=gotoPrinter)".
-              "(objectClass=goFonHardware)";
-      $regex= "*";
-
-      $ldap->search ("(&(|$filter)(|(uid=$regex)(cn=$regex)(ou=$regex)))", array("dn", "cn", "ou", "description", "objectClass", "sn", "givenName", "uid"));
-      while ($attrs= $ldap->fetch()){
-
-        $type= $this->getObjectType($attrs);
-        $name= $this->getObjectName($attrs);
-
-        if (isset($attrs["description"][0])){
-          $this->allobjects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
-        } elseif (isset($attrs["uid"][0])) {
-          $this->allobjects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
-        } else {
-          $this->allobjects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
-        }
-        $this->allobjects[$attrs["dn"]]['objectClass']  = $attrs['objectClass'];
-        if(isset($attrs['uid'])){
-          $this->allobjects[$attrs["dn"]]['uid']          = $attrs['uid'];
-        }
-      }
-      uasort ($this->allobjects, 'sort_list');
-      reset ($this->allobjects);
-    }      
-
     
     /*###########
       Build member list and try to detect obsolete entries 
@@ -480,63 +450,7 @@ class ogroup extends plugin
   
     /* Walk through all single member entry */
     foreach($this->member as $dn){
-
-      /* Object in object list? */
-      if (isset($this->allobjects[$dn])){
-        
-        /* Add this entry to member list, its dn is in allobjects
-            this means it still exists 
-         */
-        $this->memberList[$dn]= $this->allobjects[$dn];
-
-        /* Remove this from selectable entries */
-        if (isset ($this->objects[$dn])){
-          unset ($this->objects[$dn]);
-        }
-
-      
-      } else {
-
-        /* The dn for the current member can't be resolved 
-            it seams that this entry was removed 
-         */ 
-        /* Try to resolv the entry again, if it still fails, display error msg */
-        $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass"));
-
-        /* It has failed, add entry with type flag I (Invalid)*/
-        if ($ldap->error != "success"){
-          $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".@LDAP::fix($dn),"type" => "I");
-
-        } else {
-          
-          /* Append this entry to our all object list */
-    
-          /* Fetch object */
-          $attrs= $ldap->fetch();
-
-          $type= $this->getObjectType($attrs);
-          $name= $this->getObjectName($attrs);
-
-          if (isset($attrs["description"][0])){
-            $this->allobjects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
-          } elseif (isset($attrs["uid"][0])) {
-            $this->allobjects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
-          } else {
-            $this->allobjects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
-          }
-          $this->allobjects[$attrs["dn"]]['objectClass']  = $attrs['objectClass'];
-          if(isset($attrs['uid'])){
-            $this->allobjects[$attrs["dn"]]['uid']          = $attrs['uid'];
-          }
-
-          /* Fill array */
-          if (isset($attrs["description"][0])){
-            $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
-          } else {
-            $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
-          }
-        }
-      }
+      $this->importMember($dn);
     }
     uasort ($this->memberList, 'sort_list');
     reset ($this->memberList);
@@ -559,6 +473,48 @@ class ogroup extends plugin
   }
 
 
+  function importMember($dn)
+  {
+    $ldap= $this->config->get_ldap_link();
+
+    /* Try to resolv the entry again, if it still fails, display error msg */
+    $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "uid", "description", "objectClass"));
+
+    /* It has failed, add entry with type flag I (Invalid)*/
+    if ($ldap->error != "Success"){
+      $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".@LDAP::fix($dn),"type" => "I");
+    } else {
+      /* Append this entry to our all object list */
+
+      /* Fetch object */
+      $attrs= $ldap->fetch();
+
+      $type= $this->getObjectType($attrs);
+      $name= $this->getObjectName($attrs);
+
+      if (isset($attrs["description"][0])){
+        $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
+      } elseif (isset($attrs["uid"][0])) {
+        $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
+      } else {
+        $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
+      }
+      $this->objcache[$attrs["dn"]]['objectClass']  = $attrs['objectClass'];
+      if(isset($attrs['uid'])){
+        $this->objcache[$attrs["dn"]]['uid']          = $attrs['uid'];
+      }
+
+      /* Fill array */
+      if (isset($attrs["description"][0])){
+        $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
+      } else {
+        $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
+      }
+
+      $this->memberList[$dn]= $this->objects[$attrs["dn"]];
+    }
+  }
+
   function convert_list($input)
   {
     $temp= "";
@@ -575,7 +531,7 @@ class ogroup extends plugin
 
     foreach ($input as $key => $value){
       /* Generate output */
-      $temp.= "<option value=\"$key\" class=\"select\" style=\"background-image:url('".get_template_path("images/".$conv[$value['type']])."');\">".$value['text']."</option>\n";
+      $temp.= "<option title='".addslashes($key)."' value=\"$key\" class=\"select\" style=\"background-image:url('".get_template_path("images/".$conv[$value['type']])."');\">".$value['text']."</option>\n";
     }
 
     return ($temp);
@@ -652,7 +608,7 @@ class ogroup extends plugin
     $ui= get_userinfo();
     $acl= get_permissions ($new_dn, $ui->subtreeACL);
     $acl= get_module_permission($acl, "group", $new_dn);
-    if (chkacl($acl, "create") != ""){
+    if (chkacl($acl, "create") != "" && $this->dn=="new"){
       $message[]= _("You have no permissions to create a group on this 'Base'.");
     }
 
@@ -678,7 +634,7 @@ class ogroup extends plugin
     /* Move members to target array */
     $this->attrs['member'] =array();
     foreach ($this->member as $key => $desc){
-      $this->attrs['member'][]= $key;
+      $this->attrs['member'][]= @LDAP::fix($key);
     }
 
     $ldap= $this->config->get_ldap_link();
@@ -733,10 +689,15 @@ class ogroup extends plugin
 
   function getCopyDialog()
   {
-    $str  = "";
-    $str .= _("Group name");
-    $str .= "&nbsp;<input type='text' name='cn' value='".$this->cn."'>";
-    return($str);
+    $str = "";
+
+    $smarty = get_smarty();
+    $smarty->assign("cn",     $this->cn);
+    $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
+    $ret = array();
+    $ret['string'] = $str;
+    $ret['status'] = "";
+    return($ret);
   }
 
   function saveCopyDialog()