Code

Fixed group move permission check.
[gosa.git] / gosa-core / plugins / admin / groups / class_groupGeneric.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 class group extends plugin
24 {
25   /* Group attributes */
26   var $cn= "";
27   var $description= "";
28   var $gidNumber= "";
29   var $memberUid= array();
30   var $memberUid_used_by_some= array();
32   /* Helpers */
33   var $base= "";
34   var $force_gid= FALSE;
35   var $fon_group= FALSE;
36   var $smbgroup= FALSE;
37   var $groupType= FALSE;
38   var $samba3= FALSE;
39   var $sambaSID= "";
40   var $sambaDomainName= "DEFAULT";
41   var $SID= "";
42   var $ridBase= 0;
43   var $members= array();
44   var $users= array();
45   var $member= array();
46   var $allusers= array();
47   var $saved_gidNumber= "";
48   var $oldgroupType= "";
49   var $orig_dn= "";
50   var $orig_cn= "";
51   var $orig_base= "";
52   var $has_mailAccount= FALSE;
53   var $group_dialog= FALSE;
54   var $nagios_group =FALSE;
55   var $sambaGroupType;
56   var $dialog;
57   var $rfc2307bis= FALSE;
58   var $OnlyShowFirstEntries =200;
59   var $dnMapping= array();
60   var $view_logged = FALSE;
61   var $allowGroupsWithSameNameInOtherSubtrees = true;
63   /* Trustmodel/AccessTo 
64    */
65   var $accessTo= array();
66   var $trustModel= "";
67   var $show_ws_dialog = FALSE;
69   /* attribute list for save action */
70   var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID","accessTo","trustModel");
71   var $objectclasses= array("top", "posixGroup");
73   var $CopyPasteVars  = array("force_gid","fon_group","smbgroup","groupType","sambaSID","sambaDomainName","SID","nagios_group","sambaGroupType");
75   var $multiple_support = TRUE;
77   function group (&$config, $dn= NULL)
78   {
79      /* Set rfc2307bis flag */
80      if (isset($config->current['RFC2307BIS']) && ($config->current['RFC2307BIS']== "true")){
81        $this->rfc2307bis= TRUE;
82        $this->attributes[]= "member";
83        $this->objectclasses[]= "groupOfNames";
84      }
86     plugin::plugin ($config, $dn);
88     /* Load attributes depending on the samba version */
89     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
90     $this->orig_dn= $dn;
91     $this->orig_cn= $this->cn;
93     /* Get member list */
94     if (isset($this->attrs['memberUid'][0])){
95       $tmp= array();
96       for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
97         $tmp[$this->attrs['memberUid'][$i]]= $this->attrs['memberUid'][$i];
98       }
99       $this->memberUid= $tmp;
100       ksort ($this->memberUid);
101     }
103     /* Save gidNumber for later use */
104     if (isset($this->attrs['gidNumber'])){
105       $this->saved_gidNumber= $this->attrs['gidNumber'][0];
106     }
108     /* Is a samba group? */
109     if (isset($this->attrs['objectClass'])){
110       if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == FALSE ){
111         $this->smbgroup= FALSE;
112       } else {
113         $this->smbgroup= TRUE;
114         if (isset($this->attrs['sambaSID'])){
115           $this->sambaSID= $this->attrs['sambaSID'][0];
116         }
117       }
118       if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == FALSE ){
119         $this->fon_group= FALSE;
120       } else {
121         $this->fon_group= TRUE;
122       }
123       if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == FALSE ){
124         $this->nagios_group= FALSE;
125       } else {
126         $this->nagios_group= TRUE;
127       }
128     }
130     /* Set mail flag */
131     if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
132       $this->has_mailAccount= TRUE;
133     }
135     /* Get samba Domain in case of samba 3 */
136     if ($this->samba3 && $this->sambaSID != ""){
137       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
138       $ldap= $this->config->get_ldap_link();
139       $ldap->cd($this->config->current['BASE']);
140       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
141       if ($ldap->count() != 0){
142         $attrs= $ldap->fetch();
143         if(isset($attrs['sambaAlgorithmicRidBase'])){  
144           $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];  
145         } else {  
146           $this->ridBase= $this->config->current['RIDBASE'];  
147         } 
149         /* Get domain name for SID */
150         $this->sambaDomainName= "DEFAULT";
151         foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
152           if ($val['SID'] == $this->SID){
153             $this->sambaDomainName= $key;
154             break;
155           }
156         }
157       } else {
158         if (isset($this->config->current['RIDBASE'])){
159           $this->sambaDomainName= "DEFAULT";
160           $this->ridBase= $this->config->current['RIDBASE'];
161           $this->SID= $this->config->current['SID'];
162         } else {
163           msg_dialog::display(_("Configuration error"), _("Cannot find group SID in your configuration!"), ERROR_DIALOG);
164         }
165       }
167       /* Get group type */
168       $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
169       if ($this->groupType < 500 || $this->groupType > 553){
170         $this->groupType= 0;
171       }
172       $this->oldgroupType= $this->groupType;
173     }
175     /* Get global filter config */
176     if (!session::is_set("gufilter")){
177       $ui= get_userinfo();
178       $base= get_base_from_people($ui->dn);
179       $gufilter= array( "dselect"       => $base,
180           "regex"           => "*");
181       session::set("gufilter", $gufilter);
182     }
183     $gufilter= session::get('gufilter');
184     $gufilter['SubSearchGroup'] = false;
185     session::set('gufilter',$gufilter);
186   
187     if ($this->dn == "new"){
188       if(session::is_set('CurrentMainBase')){
189         $this->base = session::get('CurrentMainBase');
190       }else{
191         $ui= get_userinfo();
192         $this->base= dn2base($ui->dn);
193       }
194     } else {
196       /* Get object base */
197       $this->base =preg_replace ("/^[^,]+,".normalizePreg(get_groups_ou())."/","",$this->dn);
198     }
199     $this->orig_base = $this->base;
201     /* Is this account a trustAccount? */
202     if (isset($this->attrs['trustModel'])){
203       $this->trustModel= $this->attrs['trustModel'][0];
204       $this->was_trust_account= TRUE;
205     } else {
206       $this->was_trust_account= FALSE;
207       $this->trustModel= "";
208     }
210     $this->accessTo = array();
211     if (isset($this->attrs['accessTo'])){
212       for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
213         $tmp= $this->attrs['accessTo'][$i];
214         $this->accessTo[$tmp]= $tmp;
215       }
216     }
218     /* Get global filter config */
219     if (!session::is_set("sysfilter")){
220       $ui= get_userinfo();
221       $base= get_base_from_people($ui->dn);
222       $sysfilter= array( "depselect"       => $base,
223           "regex"           => "*");
224       session::set("sysfilter", $sysfilter);
225     }
227     /* This is always an account */
228     $this->is_account= TRUE;
229     $this->reload();
230   }
232   function execute()
233   {
234     /* Call parent execute */
235     plugin::execute();
237     /* Log view */
238     if($this->is_account && !$this->view_logged){
239       $this->view_logged = TRUE;
240       new log("view","groups/".get_class($this),$this->dn);
241     }
243     /* Do we represent a valid group? */
244     if (!$this->is_account && $this->parent === NULL){
245       $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".msgPool::noValidExtension()."</b>";
246       return ($display);
247     }
249     /* Delete user from group */
250     if (isset($_POST['del_users']) && isset($_POST['members']) && preg_match("/w/",$this->getacl("memberUid"))){
251       foreach ($_POST['members'] as $value){
252         unset ($this->members["$value"]);
253         $this->removeUser($value);
254       }
255       $this->reload();
256     }
258     /* Add objects? */
259     if (isset($_POST["edit_membership"]) && preg_match("/w/",$this->getacl("memberUid"))){
260       $this->group_dialog= TRUE;
261       $this->dialog= TRUE;
262     }
264     /* Add objects finished? */
265     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
266       $this->group_dialog= FALSE;
267       $this->dialog= FALSE;
268     }
270     /* Add user to group */
271     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
272       foreach ($_POST['users'] as $value){
273         $this->members["$value"]= $this->allusers[$value];
274         asort($this->members);
275         $this->addUser($value);
276       }
277       $this->reload();
278     }
280     /* Base select dialog */
281     $once = true;
282     foreach($_POST as $name => $value){
283       if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
284           
285         $once = false;
286         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
287         $this->dialog->setCurrentBase($this->base);
288       }
289     }
291     /* Dialog handling */
292     if(is_object($this->dialog)){
293       /* Must be called before save_object */
294       $this->dialog->save_object();
296       if($this->dialog->isClosed()){
297         $this->dialog = false;
298       }elseif($this->dialog->isSelected()){
300         /* Check if selected base is valid */
301         $tmp = $this->get_allowed_bases();
302         if(isset($tmp[$this->dialog->isSelected()])){
303           $this->base = $this->dialog->isSelected();
304         }
305         $this->dialog= false;
306       }else{
307         return($this->dialog->execute());
308       }
309     }
312     /* Add user workstation? */
313     if (isset($_POST["add_ws"])){
314       $this->show_ws_dialog= TRUE;
315       $this->dialog= TRUE;
316     }
318     /* Add user workstation? */
319     if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
320       foreach($_POST['wslist'] as $ws){
321         $this->accessTo[$ws]= $ws;
322       }
323       ksort($this->accessTo);
324       $this->is_modified= TRUE;
325     }
327     /* Remove user workstations? */
328     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
329       foreach($_POST['workstation_list'] as $name){
330         unset ($this->accessTo[$name]);
331       }
332       $this->is_modified= TRUE;
333     }
335     /* Add user workstation finished? */
336     if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
337       $this->show_ws_dialog= FALSE;
338       $this->dialog= FALSE;
339     }
341     $smarty= get_smarty();
343     /* Show ws dialog */
344     if ($this->show_ws_dialog){
346       /* Save data */
347       $sysfilter= session::get("sysfilter");
348       foreach( array("depselect", "regex") as $type){
349         if (isset($_POST[$type])){
350           $sysfilter[$type]= $_POST[$type];
351         }
352       }
353       if (isset($_GET['search'])){
354         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
355         if ($s == "**"){
356           $s= "*";
357         }
358         $sysfilter['regex']= $s;
359       }
360       session::set("sysfilter", $sysfilter);
362       /* Get workstation list */
363       $exclude= "";
364       foreach($this->accessTo as $ws){
365         $exclude.= "(cn=$ws)";
366       }
367       if ($exclude != ""){
368         $exclude= "(!(|$exclude))";
369       }
370       $regex= $sysfilter['regex'];
372       /* Search for systems 
373        */
374       $types = array();
375       $types['server']      = array("OU" => get_ou("serverou"),     "OC" => "(objectClass=goServer)");
376       $types['workstation'] = array("OU" => get_ou("workstationou"),"OC" => "(objectClass=gotoWorkstation)");
377       $types['terminal']    = array("OU" => get_ou("terminalou"),   "OC" => "(objectClass=gotoTerminal)");
378       
379       $res = array();
380       foreach($types as $acl => $data){
381         $filter= "(&".$data['OC']."$exclude(cn=$regex))";
382         $res= array_merge($res,get_sub_list($filter,array($acl),$data['OU'],get_ou("systemsou").$sysfilter['depselect'],
383           array("cn"), GL_SUBSEARCH | GL_SIZELIMIT));
384       }
385       $wslist = array();
386       foreach ($res as $attrs){
387         $wslist[]= preg_replace('/\$/', '', $attrs['cn'][0]);
388       }
390       asort($wslist);
391       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
392       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
393       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
394       $smarty->assign("deplist", $this->config->idepartments);
395       $smarty->assign("alphabet", generate_alphabet());
396       foreach( array("depselect", "regex") as $type){
397         $smarty->assign("$type", $sysfilter[$type]);
398       }
399       $smarty->assign("hint", print_sizelimit_warning());
400       $smarty->assign("wslist", $wslist);
401       $smarty->assign("apply", apply_filter());
402       $display= $smarty->fetch (get_template_path('trust_machines.tpl', TRUE, dirname(__FILE__)));
403       return ($display);
404     }
406     /* Assign templating stuff */
407     if ($this->samba3){
408       $smarty->assign("samba3", "true");
409     } else {
410       $smarty->assign("samba3", "");
411     }
413     if($this->config->search("nagiosaccount", "CLASS",array('menu'))){
414       $smarty->assign("nagios",true);
415     }else{
416       $smarty->assign("nagios",false);
417     }
418     
419     if($this->config->search("phoneAccount", "CLASS",array('menu'))){
420       $smarty->assign("pickupGroup",true);
421     }else{
422       $smarty->assign("pickupGroup",false);
423     }
425     /* Manage object add dialog */
426     if ($this->group_dialog){
428       /* Save data */
429       $gufilter= session::get("gufilter");
430       foreach( array("dselect", "regex") as $type){
431         if (isset($_POST[$type])){
432           $gufilter[$type]= $_POST[$type];
433         }
434       }
435       if(isset($_POST['regex'])){
436         if(isset($_POST['SubSearchGroup'])){
437           $gufilter['SubSearchGroup'] = true;
438         }else{
439           $gufilter['SubSearchGroup'] = false;
440         }
441       }
443       if (isset($_GET['search'])){
444         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
445         if ($s == "**"){
446           $s= "*";
447         }
448         $gufilter['regex']= $s;
449       }
450       session::set("gufilter", $gufilter);
451       $this->reload();
453       /* Show dialog */
454       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
455       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
456       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
457       $ui = get_userinfo();
458       $tmp = $ui->get_module_departments("users");
459       $deps = array();
460       foreach($this->config->idepartments as $dn => $name){
461         if(in_array($dn,$tmp)){
462           $deps[$dn] = $name;
463         }
464       }  
465  
466       $smarty->assign("deplist", $deps);
467       $smarty->assign("alphabet", generate_alphabet());
468       foreach( array("dselect", "regex","SubSearchGroup") as $type){
469         $smarty->assign("$type", $gufilter[$type]);
470       }
471       $smarty->assign("hint", print_sizelimit_warning());
472       $smarty->assign("users", $this->displayUsers);
473       $smarty->assign("apply", apply_filter());
474       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
475       return ($display);
476     }
478     $smarty->assign("bases", $this->get_allowed_bases());
479     $smarty->assign("base_select", $this->base);
481     if ($this->samba3){
482       $domains= array();
483       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
484         $domains[$name]= $name;
485       }
486       $smarty->assign("sambaDomains", $domains);
487       $smarty->assign("sambaDomainName", $this->sambaDomainName);
488       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
489           514 => _("Domain guests"));
491       /* Don't loose special groups! If not key'ed above, add it to
492          the combo box... */    
493       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
494         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
495       }
497       $smarty->assign("groupTypes", $groupTypes);
498       $smarty->assign("groupType", $this->groupType);
499     }
501     /* Members and users */
502     $smarty->assign("members", $this->members);
504     /* Work on trust modes */
505     $smarty->assign("trusthide", " disabled ");
506     $smarty->assign("trustmodeACL",  $this->getacl("trustModel"));
507     if ($this->trustModel == "fullaccess"){
508       $trustmode= 1;
509       // pervent double disable tag in html code, this will disturb our clean w3c html
510       $smarty->assign("trustmode",  $this->getacl("trustModel"));
512     } elseif ($this->trustModel == "byhost"){
513       $trustmode= 2;
514       $smarty->assign("trusthide", "");
515     } else {
516       // pervent double disable tag in html code, this will disturb our clean w3c html
517       $smarty->assign("trustmode",  $this->getacl("trustModel"));
518       $trustmode= 0;
519     }
520     $smarty->assign("trustmode", $trustmode);
521     $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
522           2 => _("allow access to these hosts")));
524     if((count($this->accessTo))==0){
525       $smarty->assign("emptyArrAccess",true);
526     } else{
527       $smarty->assign("emptyArrAccess",false);
529     }
531     $smarty->assign("workstations", $this->accessTo);
535     /* Checkboxes */
536     foreach (array("force_gid", "smbgroup") as $val){
537       if ($this->$val == "1"){
538         $smarty->assign("$val", "checked");
539       } else {
540         $smarty->assign("$val", "");
541       }
542     }
543     if ($this->force_gid != "1"){
544       $smarty->assign("forceMode", "disabled");
545     }else{
546       $smarty->assign("forceMode", "");
547     }
548     if ($this->fon_group){
549       $smarty->assign("fon_group", "checked");
550     } else {
551       $smarty->assign("fon_group", "");
552     }
554     if ($this->nagios_group){
555       $smarty->assign("nagios_group", "checked");
556     } else {
557       $smarty->assign("nagios_group", "");
558     }
560     /* Fields */
561     foreach (array("cn", "description", "gidNumber") as $val){
562       $smarty->assign("$val", $this->$val);
563     }
565     $tmp = $this->plInfo();
566     foreach($tmp['plProvidedAcls'] as $name => $translation){
567       $smarty->assign($name."ACL",$this->getacl($name));
568     }
569     
570     if($this->acl_is_writeable("base")){
571       $smarty->assign("baseSelect",true);
572     }else{
573       $smarty->assign("baseSelect",false);
574     }
576     /* Show main page */
577     $smarty->assign("alphabet", generate_alphabet(10));
578     $smarty->assign("search_image", get_template_path('images/lists/search.png'));
579     $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
580     $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
581     $smarty->assign("deplist", $this->config->idepartments);
583     /* Multiple edit handling */
584     $smarty->assign("multiple_support",$this->multiple_support_active);
586     $smarty->assign("memberUid_All",$this->memberUid);
587     $smarty->assign("memberUid_Some",$this->memberUid_used_by_some);
589     foreach($this->attributes as $val){
590       if(in_array($val,$this->multi_boxes)){
591         $smarty->assign("use_".$val,TRUE);
592       }else{
593         $smarty->assign("use_".$val,FALSE);
594       }
595     }
596     foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group") as $val){
597       if(in_array($val,$this->multi_boxes)){
598         $smarty->assign("use_".$val,TRUE);
599       }else{
600         $smarty->assign("use_".$val,FALSE);
601       }
602     }
604     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
605   }
607   function addUser($uid)
608   {
609     /* In mutliple edit we have to handle two arrays.
610      *  memberUid               : Containing users used in all groups
611      *  memberUid_used_by_some  : Those which are not used in all groups
612      * So we have to remove the given $uid from the ..used_by_some array first.
613      */
614     if($this->multiple_support_active){
615       if(isset($this->memberUid_used_by_some[$uid])){
616         unset($this->memberUid_used_by_some[$uid]);
617       }
618     }  
620     $this->memberUid[$uid]= $uid;
621   }
624   function removeUser($uid)
625   {
626     $temp= array();
627     if(isset($this->memberUid[$uid])){
628       unset($this->memberUid[$uid]);
629     }
631     /* We have two array contianing group members in multiple edit.
632      *  this->memberUid             : Groups used by all currently edited groups 
633      *  this->memberUid_used_by_some: Used by some 
634      * So we have to remove the specified uid from both arrays.
635      */
636     if($this->multiple_support_active){
637       if(isset($this->memberUid_used_by_some[$uid])){
638         unset($this->memberUid_used_by_some[$uid]);
639       }
640     }
641   }
643   /* Reload data */
644   function reload()
645   {
646     /* Fix regex string */
647     $gufilter = session::get("gufilter");
648     $regex    = normalizeLdap($gufilter['regex']);
649     $MaxUser  = $this->OnlyShowFirstEntries;
651     /* Prepare ldap link */
652     $ldap= $this->config->get_ldap_link();
653     $ldap->cd($gufilter['dselect']);
656     /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes 
657         (Store gathered sn/givenName informations in $this->allusers too, 
658          to be prepared when adding/deleting users)
659      */    
660     $filter = "";
661     if(!isset($this->config->current['LDAP_FILTER_NESTING_LIMIT']) || 
662         count($this->memberUid) < $this->config->current['LDAP_FILTER_NESTING_LIMIT']){
663       foreach ($this->memberUid as $value){
664         if(!isset($this->members[$value])){
665           $filter .= "(uid=".normalizeLdap($value).")";
666         }
667       }
668     }
670     if(!empty($filter)){    
671       $ldap->cd($this->config->current['BASE']);
672       $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("dn", "uid","sn","givenName"));
673       while($attrs = $ldap->fetch()){
674         $this->dnMapping[$attrs['uid'][0]] = $attrs['dn'];
675         $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
676         $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
677       } 
678     }
679   
680     /* check if all uids are resolved */
681     if(!isset($this->config->current['LDAP_FILTER_NESTING_LIMIT']) || 
682         count($this->memberUid) < $this->config->current['LDAP_FILTER_NESTING_LIMIT']){
683       foreach ($this->memberUid as $value){
684         if(!isset($this->members[$value])){
685           $this->members[$value] =  _("! unknown id")." [".$value."]"; 
686         }
687       }  
688     }else{
689       foreach ($this->memberUid as $value){
690         $this->members[$value] = $value; 
691       }  
692     }
694     /* Create display list of users matching regex & filter 
695      */
696     $this->displayUsers = array();
697     $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
699     /* Search in current tree or within subtrees depending on the checkbox from filter section */
700     if($gufilter['SubSearchGroup']){
701       $flag = GL_SIZELIMIT | GL_SUBSEARCH;
702       $base = $gufilter['dselect'];
703     }else{
704       $flag = GL_SIZELIMIT ;
705       $base = get_people_ou().$gufilter['dselect'];
706     }
707     $i = 0;
708   
710     $res = get_list($filter,"users",$base,array("dn", "uid", "sn", "givenName"),$flag);
712     /* Fetch all users and skip already used users */
713     foreach($res as $attrs){
714       if(in_array($attrs['uid'][0], $this->memberUid)) {
715         continue;
716       }
717       $i ++;
718       if($i > $MaxUser) {
719         break;
720       }
721       $this->dnMapping[$attrs['uid'][0]]= $attrs["dn"];
722       $this->allusers[$attrs['uid'][0]]     = $this->createResultName($attrs);
723       $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
724     }
725   
726     /* If more than max users are found, display a message to warn the user */
727     if($i == $MaxUser){
728       msg_dialog::display(_("Configuration error"), sprintf(_("Search returned too many results. Not displaying more than %s entries!"), $MaxUser), ERROR_DIALOG);
729     }
730     
731     /* Sort lists */
732     natcasesort($this->members);
733     reset($this->members);
734     natcasesort ($this->displayUsers);
735     reset ($this->displayUsers);
736   }
739   /* Create display name, this was used so often that it is excluded into a seperate function */
740   function createResultName($attrs)
741   {
742     if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
743       $ret =  $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
744     } else {
745       $ret= $attrs['uid'][0];
746     }
747     return($ret);
748   }
751   function remove_from_parent()
752   {
753     plugin::remove_from_parent();
755     $ldap= $this->config->get_ldap_link();
756     $ldap->rmdir($this->dn);
757     if (!$ldap->success()){
758       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
759     }
761     new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
763     /* Delete references to object groups */
764     $ldap->cd ($this->config->current['BASE']);
765     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
766     while ($ldap->fetch()){
767       $og= new ogroup($this->config, $ldap->getDN());
768       unset($og->member[$this->dn]);
769       $og->save ();
770     }
772     /* Remove ACL dependencies too,
773      */
774     $ldap = $this->config->get_ldap_link();
775     $ldap->cd($this->config->current['BASE']);
776     $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($this->dn)."*))",array("gosaAclEntry","dn"));
777     while($attrs = $ldap->fetch()){
778       $acl = new acl($this->config,$this->parent,$attrs['dn']);
779       foreach($acl->gosaAclEntry as $id => $entry){
780         foreach($entry['members'] as $m_id => $member){
781           if($m_id == "G:".$this->dn || $m_id == "U:".$this->dn){
782             unset($acl->gosaAclEntry[$id]['members'][$m_id]);
783             gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$this->dn,$attrs['dn']));
784           }
785         }
786       }
787       $acl->save();
788     }
790     /* Remove ACL dependencies too,
791      */
792     $tmp = new acl($this->config,$this->parent,$this->dn);
793     $tmp->remove_acl();
795     /* Send signal to the world that we've done */
796     $this->handle_post_events("remove");
797   }
800   /* Save data to object */
801   function save_object()
802   {
803     /* Save additional values for possible next step */
804     if (isset($_POST['groupedit'])){
806       /* Create a base backup and reset the 
807           base directly after calling plugin::save_object();  
808          Base will be set seperatly a few lines below */
809       $base_tmp = $this->base;
810       plugin::save_object();
811       $this->base = $base_tmp;
813       $this->force_gid= 0;
815       /* Only reset sambagroup flag if we are able to write this flag */
816       if($this->acl_is_writeable("sambaGroupType")){
817         $this->smbgroup = 0;
818       }
820       /* Get base selection */
821       if(isset($_POST['base'])){
822         $tmp = $this->get_allowed_bases();
823         if(isset($tmp[$_POST['base']])){
824           $this->base = $_POST['base'];
825         }
826       }
828       foreach (array(
829             "force_gid"  => "gidNumber", 
830             "smbgroup"   => "sambaGroupType") as $val => $aclname) {
831         if ($this->acl_is_writeable($aclname)  && isset($_POST["$val"])){
832           $this->$val= $_POST["$val"];
833         }
834       }
836       /* Save sambaDomain attribute */
837       if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
838         $this->sambaDomainName= $_POST['sambaDomainName'];
839         $this->groupType= $_POST['groupType'];
840       }
842       /* Save fon attribute */
843       if ($this->acl_is_writeable("fonGroup")){
844         if (isset ($_POST['fon_group'])){
845           $this->fon_group= TRUE;
846         } else {
847           $this->fon_group= FALSE;
848         }
849       }
850       if ($this->acl_is_writeable("nagiosGroup")){
851         if (isset ($_POST['nagios_group'])){
852           $this->nagios_group= TRUE;
853         } else {
854           $this->nagios_group= FALSE;
855         }
856       }
857     }
859     /* Trust mode - special handling */
860     if($this->acl_is_writeable("trustModel")){
861       if (isset($_POST['trustmode'])){
862         $saved= $this->trustModel;
863         if ($_POST['trustmode'] == "1"){
864           $this->trustModel= "fullaccess";
865         } elseif ($_POST['trustmode'] == "2"){
866           $this->trustModel= "byhost";
867         } else {
868           $this->trustModel= "";
869         }
870         if ($this->trustModel != $saved){
871           $this->is_modified= TRUE;
872         }
873       }
874     }
876   }
879   /* Save to LDAP */
880   function save()
881   {
883     /* ID handling */
884     if ($this->force_gid == 0){
885       if ($this->saved_gidNumber != ""){
886         $this->gidNumber= $this->saved_gidNumber;
887       } else {
888         /* Calculate new, lock uids */
889         $wait= 10;
890         while (get_lock("uidnumber") != ""){
891           sleep (1);
893           /* timed out? */
894           if ($wait-- == 0){
895             break;
896           }
897         }
898         add_lock ("uidnumber", "gosa");
899         $this->gidNumber= $this->get_next_id("gidNumber", $this->dn);
900       }
901     }
902   
903     plugin::save(); 
905  /* Trust accounts */
906     $objectclasses= array();
907     foreach ($this->attrs['objectClass'] as $key => $class){
908       if (preg_match('/trustAccount/i', $class)){
909         continue;
910       }
911       $objectclasses[]= $this->attrs['objectClass'][$key];
912     }
913     $this->attrs['objectClass']= $objectclasses;
914     if ($this->trustModel != ""){
915       $this->attrs['objectClass'][]= "trustAccount";
916       $this->attrs['trustModel']= $this->trustModel;
917       $this->attrs['accessTo']= array();
918       if ($this->trustModel == "byhost"){
919         foreach ($this->accessTo as $host){
920           $this->attrs['accessTo'][]= $host;
921         }
922       }
923     } else {
924       if ($this->was_trust_account){
925         $this->attrs['accessTo']= array();
926         $this->attrs['trustModel']= array();
927       }
928     }
932     /* Remove objectClass for samba/phone support */
933     $tmp= array();
934     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
935       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
936           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
937           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
938          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
939         $tmp[]= $this->attrs['objectClass'][$i];
940       }
941     }
942     $this->attrs['objectClass']= $tmp;
943     $ldap= $this->config->get_ldap_link();
945     /* Add samba group functionality */
946     if ($this->samba3 && $this->smbgroup){
947   
948       /* Fixed undefined index ... 
949        */ 
950       $this->SID = $this->ridBase = "";
951       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
952         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
953       }else{
954         msg_dialog::display(_("Error"), sprintf(_("Cannot find any SID for '%s'!"), $this->sambaDomainName), ERROR_DIALOG);
955       }
956       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
957         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
958       }else{
959         msg_dialog::display(_("Error"), sprintf(_("Cannot find any RIDBASE for '%s'!"), $this->sambaDomainName), ERROR_DIALOG);
960       }
962       $this->attrs['objectClass'][]= 'sambaGroupMapping';
963       $this->attrs['sambaGroupType']= "2";
965       /* Check if we need to create a special entry */
966       if ($this->groupType == 0){
968         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
969           $gidNumber= $this->gidNumber;
970           while(TRUE){
971             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
972             $ldap->cd($this->config->current['BASE']);
973             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
974             if ($ldap->count() == 0){
975               break;
976             }
977             $gidNumber++;
978           }
979           $this->attrs['sambaSID']= $sid;
980           $this->sambaSID= $sid;
981         }
983       } else {
984         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
985       }
987       /* User wants me to fake the idMappings? This is useful for
988          making winbind resolve the group names in a reasonable amount
989          of time in combination with larger databases. */
990       if (isset($this->config->current['SAMBAIDMAPPING']) &&
991           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
992         $this->attrs['objectClass'][]= "sambaIdmapEntry";
993       }
995     }
997     /* Add phone functionality */
998     if ($this->fon_group){
999       $this->attrs['objectClass'][]= "goFonPickupGroup";
1000     }
1002     /* Add nagios functionality */
1003     if ($this->nagios_group){
1004       $this->attrs['objectClass'][]= "nagiosContactGroup";
1005     }
1007     /* Take members array */
1008     if (count ($this->memberUid)){
1009       $this->attrs['memberUid']= array_values(array_unique($this->memberUid));
1010     }
1012     /* New accounts need proper 'dn', propagate it to remaining objects */
1013     if ($this->dn == 'new'){
1014       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1015     }
1017     /* Add member dn's for RFC2307bis Support */
1018     if ($this->rfc2307bis){
1019       $this->attrs['member'] = array();
1020       if (count($this->memberUid)){
1021         foreach($this->attrs['memberUid'] as $uid) {
1022           $this->attrs['member'][]= $this->dnMapping[$uid];
1023         }
1024       } else {
1025         $this->attrs['member'][]= $this->dn;
1026       }
1027     }
1029     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1030        new entries. So do a check first... */
1031     $ldap->cat ($this->dn, array('dn'));
1032     if ($ldap->fetch()){
1033       /* Modify needs array() to remove values :-( */
1034       if (!count ($this->memberUid)){
1035         $this->attrs['memberUid']= array();
1036       }
1037       if ($this->samba3){
1038         if (!$this->smbgroup){
1039           $this->attrs['sambaGroupType']= array();
1040           $this->attrs['sambaSID']= array();
1041         }
1042       }
1043       $mode= "modify";
1044     } else {
1045       $mode= "add";
1046       $ldap->cd($this->config->current['BASE']);
1047       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1048     }
1050     /* Write back to ldap */
1051     $ldap->cd($this->dn);
1052     $this->cleanup();
1053     $ldap->$mode($this->attrs);
1055     /* Remove ACL dependencies too,
1056      */
1057     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1058       $tmp = new acl($this->config,$this->parent,$this->dn);
1059       $tmp->update_acl_membership($this->orig_dn,$this->dn);
1060     }
1062     if($this->initially_was_account){
1063       new log("modify","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1064     }else{
1065       new log("create","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1066     }
1068     $ret= 0;
1069     if (!$ldap->success()){
1070       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1071       $ret= 1;
1072     }
1074     /* Remove uid lock */
1075     del_lock ("uidnumber");
1077     /* Post that we've done*/
1078     $this->handle_post_events($mode);
1080     return ($ret);
1081   }
1083   function check()
1084   {
1085     /* Call common method to give check the hook */
1086     $message= plugin::check();
1088     /* Permissions for that base? */
1089     if ($this->base != ""){
1090       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1091     } else {
1092       $new_dn= $this->dn;
1093     }
1095     /* must: cn */
1096     if ($this->cn == "" && $this->acl_is_writeable("cn")){
1097       $message[]= msgPool::required(_("Name"));
1098     }
1100     /* Check for valid input */
1101     if (!tests::is_uid($this->cn)){
1102       if (strict_uid_mode()){
1103         $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/");
1104       } else {
1105         $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/i");
1106       }
1107     }
1109     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
1111       /* Check for used 'cn' */
1112       $ldap= $this->config->get_ldap_link();
1113       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new")){
1114         $ldap->cd(get_groups_ou().$this->base);
1115         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
1116         if ($ldap->count() != 0){
1117           $message[]= msgPool::duplicated(_("Name"));
1118         }
1119       }
1121     }else{
1123       /* Check for used 'cn' */
1124       $ldap= $this->config->get_ldap_link();
1125       $ldap->cd($this->config->current['BASE']);
1126       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
1127       if ($ldap->count() != 0){
1129         /* New entry? */
1130         if ($this->dn == 'new'){
1131           $message[]= msgPool::duplicated(_("Name"));
1132         }
1134         /* Moved? */
1135         elseif ($new_dn != $this->orig_dn){
1136           $ldap->fetch();
1137           if ($ldap->getDN() != $this->orig_dn){
1138             $message[]= msgPool::duplicated(_("Name"));
1139           }
1140         }
1141       }
1142     }
1143      
1144     /* Check ID */
1145     if ($this->force_gid == "1"){
1146       if (!tests::is_id($this->gidNumber)){
1147         $message[]= msgPool::invalid(_("GID"), $this->gidNumber, "/[0-9]/");
1148       } else {
1149         if ($this->gidNumber < $this->config->current['MINID']){
1150           $message[]= msgPool::toosmall(_("GID"), $this->config->current['MINID']);
1151         }
1153       }
1154     }
1155     
1156     /* Check if we are allowed to create or move this object 
1157      */
1158     if(!$this->orig_dn == "new" || 
1159         $this->orig_base != $this->base || 
1160         $this->cn != $this->orig_cn){
1162       if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1163         $message[] = msgPool::permCreate();
1164       }elseif($this->orig_dn != "new" && !$this->acl_is_moveable($this->base)){
1165         $message[] = msgPool::permMove();
1166       }
1167     }
1169     return ($message);
1170   }
1172   function get_next_id($attrib, $dn)
1173   {
1174     $ids= array();
1175     $ldap= $this->config->get_ldap_link();
1177     $ldap->cd ($this->config->current['BASE']);
1178     if (preg_match('/gidNumber/i', $attrib)){
1179       $oc= "posixGroup";
1180     } else {
1181       $oc= "posixAccount";
1182     }
1183     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
1185     /* Get list of ids */
1186     while ($attrs= $ldap->fetch()){
1187       $ids[]= (int)$attrs["$attrib"][0];
1188     }
1190     /* Find out next free id near to UID_BASE */
1191     if (!isset($this->config->current['BASE_HOOK'])){
1192       $base= $this->config->current['UIDBASE'];
1193     } else {
1194       /* Call base hook */
1195       $base= get_base_from_hook($dn, $attrib);
1196     }
1197     for ($id= $base; $id++; $id < pow(2,32)){
1198       if (!in_array($id, $ids)){
1199         return ($id);
1200       }
1201     }
1203     /* Check if id reached maximum */
1204     if ($id >= pow(2,32)){
1205       msg_dialog::display(_("Error"), _("Cannot allocate a free ID!"), ERROR_DIALOG);
1206       exit;
1207     }
1208   }
1210   function getCopyDialog()
1211   {
1212     $vars = array("cn");
1213   
1214     if($this ->force_gid){
1215       $used = " checked ";
1216       $dis  = "";
1217     }else{
1218       $used = "";
1219       $dis  = " disabled ";
1220     }
1222     $smarty = get_smarty();
1223     $smarty->assign("used",$used);
1224     $smarty->assign("dis" ,$dis);
1225     $smarty->assign("cn" ,$this->cn);
1226     $smarty->assign("gidNumber",$this->gidNumber);
1227     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
1228     $ret = array();
1229     $ret['string'] = $str;
1230     $ret['status'] = "";
1231     return($ret);
1232   }
1234   function saveCopyDialog()
1235   {
1236     if(isset($_POST['cn'])){
1237       $this->cn = $_POST['cn'];
1238     }
1239     if(isset($_POST['force_gid'])){
1240       $this->force_gid  = 1;
1241       $this->gidNumber= $_POST['gidNumber'];
1242     }else{
1243       $this->force_gid  = 0;
1244       $this->gidNumber  = false;
1245     }
1246   }
1248   
1249   /* Return plugin informations for acl handling  */ 
1250   static function plInfo()
1251   {
1252     return (array(  
1253           "plShortName" => _("Generic"),
1254           "plDescription" => _("Generic group settings"),
1255           "plSelfModify"  => FALSE,
1256           "plDepends"     => array(),
1257           "plPriority"    => 0,
1258           "plSection"     => array("admin"),
1259           "plCategory"    => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
1261           "plProvidedAcls"    => array(
1262             "cn"                => _("Name"),
1263             "description"       => _("Description"),
1264             "base"              => _("Base"),
1266             "gidNumber"         => _("GID"),
1268             "sambaGroupType"    => _("Samba group type"),
1269             "sambaDomainName"   => _("Samba domain name"),
1270             "trustModel"        => _("System trust"),
1271             "fonGroup"          => _("Phone pickup group"),
1272             "nagiosGroup"       => _("Nagios group"),
1274             "memberUid"         => _("Group member"))
1275         ));
1276   }
1279   function multiple_save_object()
1280   {
1281     if(isset($_POST['group_mulitple_edit'])){
1283       /* Create a base backup and reset the
1284          base directly after calling plugin::save_object();
1285          Base will be set seperatly a few lines below */
1286       $base_tmp = $this->base;
1287       plugin::multiple_save_object();
1288       plugin::save_object();
1289       $this->base = $base_tmp;
1291       foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group") as $attr){
1292         if(isset($_POST['use_'.$attr])){
1293           $this->multi_boxes[] = $attr;
1294         }
1295       }
1297       /* Get base selection */
1298       if(isset($_POST['base'])){
1299         $tmp = $this->get_allowed_bases();
1300         if(isset($tmp[$_POST['base']])){
1301           $this->base = $_POST['base'];
1302         }
1303       }
1305       foreach (array( "smbgroup"   => "sambaGroupType") as $val => $aclname) {
1306         if ($this->acl_is_writeable($aclname)){
1307           if(isset($_POST["$val"])){
1308             $this->$val=  TRUE;
1309           }else{
1310             $this->$val=  FALSE;
1311           }
1312         }
1313       }
1315       /* Save sambaDomain attribute */
1316       if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
1317         $this->sambaDomainName= $_POST['sambaDomainName'];
1318         $this->groupType= $_POST['groupType'];
1319       }
1321       /* Save fon attribute */
1322       if ($this->acl_is_writeable("fonGroup")){
1323         if (isset ($_POST['fon_group'])){
1324           $this->fon_group= TRUE;
1325         } else {
1326           $this->fon_group= FALSE;
1327         }
1328       }
1329     }
1330   }
1333   function get_multi_edit_values()
1334   {
1335     $ret = plugin::get_multi_edit_values();
1337     foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group") as $attr){    
1338       if(in_array($attr,$this->multi_boxes)){
1339         $ret[$attr] = $this->$attr;
1340       }
1341     }
1342     $ret['memberUid'] = $this->memberUid;
1343     $ret['memberUid_used_by_some'] = $this->memberUid_used_by_some;
1344     return($ret);
1345   }
1347   function multiple_execute()
1348   {
1349     return($this->execute());
1350   }
1353   /* Initialize plugin with given atribute arrays
1354    */
1355   function init_multiple_support($attrs,$all)
1356   {
1357     plugin::init_multiple_support($attrs,$all);
1359     $this->memberUid = array();
1360     $this->memberUid_used_by_some = array();
1361     if (isset($attrs['memberUid'])){
1362       for ($i= 0; $i<$attrs['memberUid']['count']; $i++){
1363         $this->memberUid[$attrs['memberUid'][$i]]= $attrs['memberUid'][$i];
1364       }
1365       ksort($this->memberUid);
1366     }
1368     if (isset($all['memberUid'])){
1369       for ($i= 0; $i<$all['memberUid']['count']; $i++){
1370         if(!in_array($all['memberUid'][$i],$this->memberUid)){
1371           $this->memberUid_used_by_some[$all['memberUid'][$i]]= $all['memberUid'][$i];
1372         }
1373       }
1374       ksort($this->memberUid_used_by_some);
1375     }
1376   }
1379   function PrepareForCopyPaste($source)
1380   {
1381     plugin::PrepareForCopyPaste($source);
1383     $this->memberUid = array();
1384     if(isset($source['memberUid'])){
1385       for($i = 0 ; $i < $source['memberUid']['count']; $i ++){
1386         $this->memberUid[] = $source['memberUid'][$i];
1387       }
1388     }
1389   }
1392   function set_multi_edit_values($attrs)
1393   {
1394     $users = array();
1396     /* Update groupMembership, keep optinal group */
1397     foreach($attrs['memberUid_used_by_some'] as $uid){
1398       if(in_array($uid,$this->memberUid)){
1399         $users[$uid] = $uid;
1400       }
1401     }
1403     /* Update groupMembership, add forced groups */
1404     foreach($attrs['memberUid'] as $uid){
1405       $users[$uid] = $uid;
1406     }
1407     plugin::set_multi_edit_values($attrs);
1408     $this->memberUid = $users;
1409   }
1411 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1412 ?>