Code

Add a configuration option allowGroupsWithSameNameInOtherSubtrees,
[gosa.git] / trunk / 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 ($config->get_cfg_value("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->get_cfg_value("sambaversion") == 3);
90     $this->orig_dn= $dn;
91     $this->orig_cn= $this->cn;
93     /* Read configuration option for $this->allowGroupsWithSameNameInOtherSubtrees */
94     if ($config->get_cfg_value("allowGroupsWithSameNameInOtherSubtrees") == "false") {
95         $this->allowGroupsWithSameNameInOtherSubtrees = FALSE;
96     }
98     /* Get member list */
99     if (isset($this->attrs['memberUid'][0])){
100       $tmp= array();
101       for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
102         $tmp[$this->attrs['memberUid'][$i]]= $this->attrs['memberUid'][$i];
103       }
104       $this->memberUid= $tmp;
105       ksort ($this->memberUid);
106     }
108     /* Save gidNumber for later use */
109     if (isset($this->attrs['gidNumber'])){
110       $this->saved_gidNumber= $this->attrs['gidNumber'][0];
111     }
113     /* Is a samba group? */
114     if (isset($this->attrs['objectClass'])){
115       if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == FALSE ){
116         $this->smbgroup= FALSE;
117       } else {
118         $this->smbgroup= TRUE;
119         if (isset($this->attrs['sambaSID'])){
120           $this->sambaSID= $this->attrs['sambaSID'][0];
121         }
122       }
123       if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == FALSE ){
124         $this->fon_group= FALSE;
125       } else {
126         $this->fon_group= TRUE;
127       }
128       if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == FALSE ){
129         $this->nagios_group= FALSE;
130       } else {
131         $this->nagios_group= TRUE;
132       }
133     }
135     /* Set mail flag */
136     if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
137       $this->has_mailAccount= TRUE;
138     }
140     /* Get samba Domain in case of samba 3 */
141     if ($this->samba3 && $this->sambaSID != ""){
142       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
143       $ldap= $this->config->get_ldap_link();
144       $ldap->cd($this->config->current['BASE']);
145       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
146       if ($ldap->count() != 0){
147         $attrs= $ldap->fetch();
148         if(isset($attrs['sambaAlgorithmicRidBase'])){  
149           $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];  
150         } else {  
151           $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
152         } 
154         /* Get domain name for SID */
155         $this->sambaDomainName= "DEFAULT";
156         foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
157           if ($val['SID'] == $this->SID){
158             $this->sambaDomainName= $key;
159             break;
160           }
161         }
162       } else {
163         if ($this->config->get_cfg_value("sambaRidBase") != ""){
164           $this->sambaDomainName= "DEFAULT";
165           $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
166           $this->SID= $this->config->get_cfg_value("sid");
167         } else {
168           msg_dialog::display(_("Configuration error"), _("Cannot find group SID in your configuration!"), ERROR_DIALOG);
169         }
170       }
172       /* Get group type */
173       $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
174       if ($this->groupType < 500 || $this->groupType > 553){
175         $this->groupType= 0;
176       }
177       $this->oldgroupType= $this->groupType;
178     }
180     /* Get global filter config */
181     if (!session::is_set("gufilter")){
182       $ui= get_userinfo();
183       $base= get_base_from_people($ui->dn);
184       $gufilter= array( "dselect"       => $base,
185           "regex"           => "*");
186       session::set("gufilter", $gufilter);
187     }
188     $gufilter= session::get('gufilter');
189     $gufilter['SubSearchGroup'] = false;
190     session::set('gufilter',$gufilter);
191   
192     if ($this->dn == "new"){
193       if(session::is_set('CurrentMainBase')){
194         $this->base = session::get('CurrentMainBase');
195       }else{
196         $ui= get_userinfo();
197         $this->base= dn2base($ui->dn);
198       }
199     } else {
201       /* Get object base */
202       $this->base =preg_replace ("/^[^,]+,".preg_quote(get_groups_ou(), '/')."/","",$this->dn);
203     }
204     $this->orig_base = $this->base;
206     /* Is this account a trustAccount? */
207     if (isset($this->attrs['trustModel'])){
208       $this->trustModel= $this->attrs['trustModel'][0];
209       $this->was_trust_account= TRUE;
210     } else {
211       $this->was_trust_account= FALSE;
212       $this->trustModel= "";
213     }
215     $this->accessTo = array();
216     if (isset($this->attrs['accessTo'])){
217       for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
218         $tmp= $this->attrs['accessTo'][$i];
219         $this->accessTo[$tmp]= $tmp;
220       }
221     }
223     /* Get global filter config */
224     if (!session::is_set("sysfilter")){
225       $ui= get_userinfo();
226       $base= get_base_from_people($ui->dn);
227       $sysfilter= array( "depselect"       => $base,
228           "regex"           => "*");
229       session::set("sysfilter", $sysfilter);
230     }
232     /* This is always an account */
233     $this->is_account= TRUE;
234     $this->reload(TRUE);
235   }
237   function execute()
238   {
239     /* Call parent execute */
240     plugin::execute();
242     /* Log view */
243     if($this->is_account && !$this->view_logged){
244       $this->view_logged = TRUE;
245       new log("view","groups/".get_class($this),$this->dn);
246     }
248     /* Do we represent a valid group? */
249     if (!$this->is_account && $this->parent === NULL){
250       $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".msgPool::noValidExtension()."</b>";
251       return ($display);
252     }
254     /* Delete user from group */
255     if (isset($_POST['del_users']) && isset($_POST['members']) && preg_match("/w/",$this->getacl("memberUid"))){
256       foreach ($_POST['members'] as $value){
257         unset ($this->members["$value"]);
258         $this->removeUser($value);
259       }
260       $this->reload();
261     }
263     /* Add objects? */
264     if (isset($_POST["edit_membership"]) && preg_match("/w/",$this->getacl("memberUid"))){
265       $this->group_dialog= TRUE;
266       $this->dialog= TRUE;
267     }
269     /* Add objects finished? */
270     if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
271       $this->group_dialog= FALSE;
272       $this->dialog= FALSE;
273     }
275     /* Add user to group */
276     if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
277       foreach ($_POST['users'] as $value){
278         $this->members["$value"]= $this->allusers[$value];
279         asort($this->members);
280         $this->addUser($value);
281       }
282       $this->reload();
283     }
285     /* Base select dialog */
286     $once = true;
287     foreach($_POST as $name => $value){
288       if((preg_match("/^chooseBase/",$name) && $once) && $this->acl_is_writeable("base")){
289           
290         $once = false;
291         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
292         $this->dialog->setCurrentBase($this->base);
293       }
294     }
296     /* Dialog handling */
297     if(is_object($this->dialog)){
298       /* Must be called before save_object */
299       $this->dialog->save_object();
301       if($this->dialog->isClosed()){
302         $this->dialog = false;
303       }elseif($this->dialog->isSelected()){
305         /* Check if selected base is valid */
306         $tmp = $this->get_allowed_bases();
307         if(isset($tmp[$this->dialog->isSelected()])){
308           $this->base = $this->dialog->isSelected();
309         }
310         $this->dialog= false;
311       }else{
312         return($this->dialog->execute());
313       }
314     }
317     /* Add user workstation? */
318     if (isset($_POST["add_ws"])){
319       $this->show_ws_dialog= TRUE;
320       $this->dialog= TRUE;
321     }
323     /* Add user workstation? */
324     if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
325       foreach($_POST['wslist'] as $ws){
326         $this->accessTo[$ws]= $ws;
327       }
328       ksort($this->accessTo);
329       $this->is_modified= TRUE;
330     }
332     /* Remove user workstations? */
333     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
334       foreach($_POST['workstation_list'] as $name){
335         unset ($this->accessTo[$name]);
336       }
337       $this->is_modified= TRUE;
338     }
340     /* Add user workstation finished? */
341     if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
342       $this->show_ws_dialog= FALSE;
343       $this->dialog= FALSE;
344     }
346     $smarty= get_smarty();
348     /* Show ws dialog */
349     if ($this->show_ws_dialog){
351       /* Save data */
352       $sysfilter= session::get("sysfilter");
353       foreach( array("depselect", "regex") as $type){
354         if (isset($_POST[$type])){
355           $sysfilter[$type]= $_POST[$type];
356         }
357       }
358       if (isset($_GET['search'])){
359         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
360         if ($s == "**"){
361           $s= "*";
362         }
363         $sysfilter['regex']= $s;
364       }
365       session::set("sysfilter", $sysfilter);
367       /* Get workstation list */
368       $exclude= "";
369       foreach($this->accessTo as $ws){
370         $exclude.= "(cn=$ws)";
371       }
372       if ($exclude != ""){
373         $exclude= "(!(|$exclude))";
374       }
375       $regex= $sysfilter['regex'];
377       /* Search for systems 
378        */
379       $types = array();
380       $types['server']      = array("OU" => get_ou("serverRDN"),     "OC" => "(objectClass=goServer)");
381       $types['workstation'] = array("OU" => get_ou("workstationRDN"),"OC" => "(objectClass=gotoWorkstation)");
382       $types['terminal']    = array("OU" => get_ou("terminalRDN"),   "OC" => "(objectClass=gotoTerminal)");
383       
384       $res = array();
385       foreach($types as $acl => $data){
386         $filter= "(&".$data['OC']."$exclude(cn=$regex))";
387         $res= array_merge($res,get_sub_list($filter,array($acl),$data['OU'],get_ou("systemRDN").$sysfilter['depselect'],
388           array("cn"), GL_SUBSEARCH | GL_SIZELIMIT));
389       }
390       $wslist = array();
391       foreach ($res as $attrs){
392         $wslist[]= preg_replace('/\$/', '', $attrs['cn'][0]);
393       }
395       asort($wslist);
396       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
397       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
398       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
399       $smarty->assign("deplist", $this->config->idepartments);
400       $smarty->assign("alphabet", generate_alphabet());
401       foreach( array("depselect", "regex") as $type){
402         $smarty->assign("$type", $sysfilter[$type]);
403       }
404       $smarty->assign("hint", print_sizelimit_warning());
405       $smarty->assign("wslist", $wslist);
406       $smarty->assign("apply", apply_filter());
407       $display= $smarty->fetch (get_template_path('trust_machines.tpl', TRUE, dirname(__FILE__)));
408       return ($display);
409     }
411     /* Assign templating stuff */
412     if ($this->samba3){
413       $smarty->assign("samba3", "true");
414     } else {
415       $smarty->assign("samba3", "");
416     }
418     if($this->config->search("nagiosaccount", "CLASS",array('menu'))){
419       $smarty->assign("nagios",true);
420     }else{
421       $smarty->assign("nagios",false);
422     }
423     
424     if($this->config->search("phoneAccount", "CLASS",array('menu'))){
425       $smarty->assign("pickupGroup",true);
426     }else{
427       $smarty->assign("pickupGroup",false);
428     }
430     /* Manage object add dialog */
431     if ($this->group_dialog){
433       /* Save data */
434       $gufilter= session::get("gufilter");
435       foreach( array("dselect", "regex") as $type){
436         if (isset($_POST[$type])){
437           $gufilter[$type]= $_POST[$type];
438         }
439       }
440       if(isset($_POST['regex'])){
441         if(isset($_POST['SubSearchGroup'])){
442           $gufilter['SubSearchGroup'] = true;
443         }else{
444           $gufilter['SubSearchGroup'] = false;
445         }
446       }
448       if (isset($_GET['search'])){
449         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
450         if ($s == "**"){
451           $s= "*";
452         }
453         $gufilter['regex']= $s;
454       }
455       session::set("gufilter", $gufilter);
456       $this->reload();
458       /* Show dialog */
459       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
460       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
461       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
462       $ui = get_userinfo();
463       $tmp = $ui->get_module_departments("users");
464       $deps = array();
465       foreach($this->config->idepartments as $dn => $name){
466         if(in_array($dn,$tmp)){
467           $deps[$dn] = $name;
468         }
469       }  
470  
471       $smarty->assign("deplist", $deps);
472       $smarty->assign("alphabet", generate_alphabet());
473       foreach( array("dselect", "regex","SubSearchGroup") as $type){
474         $smarty->assign("$type", $gufilter[$type]);
475       }
476       $smarty->assign("hint", print_sizelimit_warning());
477       $smarty->assign("users", $this->displayUsers);
478       $smarty->assign("apply", apply_filter());
479       $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
480       return ($display);
481     }
483     $smarty->assign("bases", $this->get_allowed_bases());
484     $smarty->assign("base_select", $this->base);
486     if ($this->samba3){
487       $domains= array();
488       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
489         $domains[$name]= $name;
490       }
491       $smarty->assign("sambaDomains", $domains);
492       $smarty->assign("sambaDomainName", $this->sambaDomainName);
493       $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
494           514 => _("Domain guests"));
496       /* Don't loose special groups! If not key'ed above, add it to
497          the combo box... */    
498       if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
499         $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
500       }
502       $smarty->assign("groupTypes", $groupTypes);
503       $smarty->assign("groupType", $this->groupType);
504     }
506     /* Members and users */
507     $smarty->assign("members", $this->members);
509     /* Work on trust modes */
510     $smarty->assign("trusthide", " disabled ");
511     $smarty->assign("trustmodeACL",  $this->getacl("trustModel"));
512     if ($this->trustModel == "fullaccess"){
513       $trustmode= 1;
514       // pervent double disable tag in html code, this will disturb our clean w3c html
515       $smarty->assign("trustmode",  $this->getacl("trustModel"));
517     } elseif ($this->trustModel == "byhost"){
518       $trustmode= 2;
519       $smarty->assign("trusthide", "");
520     } else {
521       // pervent double disable tag in html code, this will disturb our clean w3c html
522       $smarty->assign("trustmode",  $this->getacl("trustModel"));
523       $trustmode= 0;
524     }
525     $smarty->assign("trustmode", $trustmode);
526     $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
527           2 => _("allow access to these hosts")));
529     if((count($this->accessTo))==0){
530       $smarty->assign("emptyArrAccess",true);
531     } else{
532       $smarty->assign("emptyArrAccess",false);
534     }
536     $smarty->assign("workstations", $this->accessTo);
540     /* Checkboxes */
541     foreach (array("force_gid", "smbgroup") as $val){
542       if ($this->$val == "1"){
543         $smarty->assign("$val", "checked");
544       } else {
545         $smarty->assign("$val", "");
546       }
547     }
548     if ($this->force_gid != "1"){
549       $smarty->assign("forceMode", "disabled");
550     }else{
551       $smarty->assign("forceMode", "");
552     }
553     if ($this->fon_group){
554       $smarty->assign("fon_group", "checked");
555     } else {
556       $smarty->assign("fon_group", "");
557     }
559     if ($this->nagios_group){
560       $smarty->assign("nagios_group", "checked");
561     } else {
562       $smarty->assign("nagios_group", "");
563     }
565     /* Fields */
566     foreach (array("cn", "description", "gidNumber") as $val){
567       $smarty->assign("$val", $this->$val);
568     }
570     $tmp = $this->plInfo();
571     foreach($tmp['plProvidedAcls'] as $name => $translation){
572       $smarty->assign($name."ACL",$this->getacl($name));
573     }
574     
575     if($this->acl_is_writeable("base")){
576       $smarty->assign("baseSelect",true);
577     }else{
578       $smarty->assign("baseSelect",false);
579     }
581     /* Show main page */
582     $smarty->assign("alphabet", generate_alphabet(10));
583     $smarty->assign("search_image", get_template_path('images/lists/search.png'));
584     $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
585     $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
586     $smarty->assign("deplist", $this->config->idepartments);
588     /* Multiple edit handling */
589     $smarty->assign("multiple_support",$this->multiple_support_active);
591     $smarty->assign("memberUid_All",$this->memberUid);
592     $smarty->assign("memberUid_Some",$this->memberUid_used_by_some);
594     foreach($this->attributes as $val){
595       if(in_array($val,$this->multi_boxes)){
596         $smarty->assign("use_".$val,TRUE);
597       }else{
598         $smarty->assign("use_".$val,FALSE);
599       }
600     }
601     foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group","trustmode") as $val){
602       if(in_array($val,$this->multi_boxes)){
603         $smarty->assign("use_".$val,TRUE);
604       }else{
605         $smarty->assign("use_".$val,FALSE);
606       }
607     }
609     return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
610   }
612   function addUser($uid)
613   {
614     /* In mutliple edit we have to handle two arrays.
615      *  memberUid               : Containing users used in all groups
616      *  memberUid_used_by_some  : Those which are not used in all groups
617      * So we have to remove the given $uid from the ..used_by_some array first.
618      */
619     if($this->multiple_support_active){
620       if(isset($this->memberUid_used_by_some[$uid])){
621         unset($this->memberUid_used_by_some[$uid]);
622       }
623     }  
625     $this->memberUid[$uid]= $uid;
626   }
629   function removeUser($uid)
630   {
631     $temp= array();
632     if(isset($this->memberUid[$uid])){
633       unset($this->memberUid[$uid]);
634     }
636     /* We have two array contianing group members in multiple edit.
637      *  this->memberUid             : Groups used by all currently edited groups 
638      *  this->memberUid_used_by_some: Used by some 
639      * So we have to remove the specified uid from both arrays.
640      */
641     if($this->multiple_support_active){
642       if(isset($this->memberUid_used_by_some[$uid])){
643         unset($this->memberUid_used_by_some[$uid]);
644       }
645     }
646   }
648   /* Reload data */
649   function reload($silent = FALSE)
650   {
651     /* Fix regex string */
652     $gufilter = session::get("gufilter");
653     $regex    = normalizeLdap($gufilter['regex']);
654     $MaxUser  = $this->OnlyShowFirstEntries;
656     /* Prepare ldap link */
657     $ldap= $this->config->get_ldap_link();
658     $ldap->cd($gufilter['dselect']);
661     /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes 
662         (Store gathered sn/givenName informations in $this->allusers too, 
663          to be prepared when adding/deleting users)
664      */    
665     $filter = "";
666     if ($this->config->get_cfg_value("ldapFilterNestingLimit") == "" ||
667         count($this->memberUid) < $this->config->get_cfg_value("ldapFilterNestingLimit")){
668       foreach ($this->memberUid as $value){
669         if(!isset($this->members[$value])){
670           $filter .= "(uid=".normalizeLdap($value).")";
671         }
672       }
673     }
675     if(!empty($filter)){    
676       $ldap->cd($this->config->current['BASE']);
677       $ldap->search("(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(|".$filter."))",array("dn", "uid","sn","givenName"));
678       while($attrs = $ldap->fetch()){
679         $this->dnMapping[$attrs['uid'][0]] = $attrs['dn'];
680         $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
681         $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
682       } 
683     }
684   
685     /* check if all uids are resolved */
686     if ($this->config->get_cfg_value("ldapFilterNestingLimit") == "" ||
687         count($this->memberUid) < $this->config->get_cfg_value("ldapFilterNestingLimit")){
688       foreach ($this->memberUid as $value){
689         if(!isset($this->members[$value])){
690           $this->members[$value] =  _("! unknown id")." [".$value."]"; 
691         }
692       }  
693     }else{
694       foreach ($this->memberUid as $value){
695         $this->members[$value] = $value; 
696       }  
697     }
699     /* Create display list of users matching regex & filter 
700      */
701     $this->displayUsers = array();
702     $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
704     /* Search in current tree or within subtrees depending on the checkbox from filter section */
705     if($gufilter['SubSearchGroup']){
706       $flag = GL_SIZELIMIT | GL_SUBSEARCH;
707       $base = $gufilter['dselect'];
708     }else{
709       $flag = GL_SIZELIMIT ;
710       $base = get_people_ou().$gufilter['dselect'];
711     }
712     $i = 0;
713   
715     $res = get_list($filter,"users",$base,array("dn", "uid", "sn", "givenName"),$flag);
717     /* Fetch all users and skip already used users */
718     foreach($res as $attrs){
719       if(in_array($attrs['uid'][0], $this->memberUid)) {
720         continue;
721       }
722       $i ++;
723       if($i > $MaxUser) {
724         break;
725       }
726       $this->dnMapping[$attrs['uid'][0]]= $attrs["dn"];
727       $this->allusers[$attrs['uid'][0]]     = $this->createResultName($attrs);
728       $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
729     }
730   
731     /* If more than max users are found, display a message to warn the user */
732     if($i == $MaxUser && !$silent){
733       msg_dialog::display(_("Configuration error"), sprintf(_("Search returned too many results. Not displaying more than %s entries!"), $MaxUser), ERROR_DIALOG);
734     }
735     
736     /* Sort lists */
737     natcasesort($this->members);
738     reset($this->members);
739     natcasesort ($this->displayUsers);
740     reset ($this->displayUsers);
741   }
744   /* Create display name, this was used so often that it is excluded into a seperate function */
745   function createResultName($attrs)
746   {
747     if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
748       $ret =  $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
749     } else {
750       $ret= $attrs['uid'][0];
751     }
752     return($ret);
753   }
756   function remove_from_parent()
757   {
758     plugin::remove_from_parent();
760     $ldap= $this->config->get_ldap_link();
761     $ldap->rmdir($this->dn);
762     if (!$ldap->success()){
763       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
764     }
766     new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
768     /* Delete references to object groups */
769     $ldap->cd ($this->config->current['BASE']);
770     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
771     while ($ldap->fetch()){
772       $og= new ogroup($this->config, $ldap->getDN());
773       unset($og->member[$this->dn]);
774       $og->save ();
775     }
777     /* Remove ACL dependencies too,
778      */
779     $ldap = $this->config->get_ldap_link();
780     $ldap->cd($this->config->current['BASE']);
781     $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($this->dn)."*))",array("gosaAclEntry","dn"));
782     while($attrs = $ldap->fetch()){
783       $acl = new acl($this->config,$this->parent,$attrs['dn']);
784       foreach($acl->gosaAclEntry as $id => $entry){
785         foreach($entry['members'] as $m_id => $member){
786           if($m_id == "G:".$this->dn || $m_id == "U:".$this->dn){
787             unset($acl->gosaAclEntry[$id]['members'][$m_id]);
788             gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$this->dn,$attrs['dn']));
789           }
790         }
791       }
792       $acl->save();
793     }
795     /* Remove ACL dependencies too,
796      */
797     $tmp = new acl($this->config,$this->parent,$this->dn);
798     $tmp->remove_acl();
800     /* Send signal to the world that we've done */
801     $this->handle_post_events("remove");
802   }
805   /* Save data to object */
806   function save_object()
807   {
808     /* Save additional values for possible next step */
809     if (isset($_POST['groupedit'])){
811       /* Create a base backup and reset the 
812           base directly after calling plugin::save_object();  
813          Base will be set seperatly a few lines below */
814       $base_tmp = $this->base;
815       plugin::save_object();
816       $this->base = $base_tmp;
818       $this->force_gid= 0;
820       /* Only reset sambagroup flag if we are able to write this flag */
821       if($this->acl_is_writeable("sambaGroupType")){
822         $this->smbgroup = 0;
823       }
825       /* Get base selection */
826       if(isset($_POST['base'])){
827         $tmp = $this->get_allowed_bases();
828         if(isset($tmp[$_POST['base']])){
829           $this->base = $_POST['base'];
830         }
831       }
833       foreach (array(
834             "force_gid"  => "gidNumber", 
835             "smbgroup"   => "sambaGroupType") as $val => $aclname) {
836         if ($this->acl_is_writeable($aclname)  && isset($_POST["$val"])){
837           $this->$val= $_POST["$val"];
838         }
839       }
841       /* Save sambaDomain attribute */
842       if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
843         $this->sambaDomainName= $_POST['sambaDomainName'];
844         $this->groupType= $_POST['groupType'];
845       }
847       /* Save fon attribute */
848       if ($this->acl_is_writeable("fonGroup")){
849         if (isset ($_POST['fon_group'])){
850           $this->fon_group= TRUE;
851         } else {
852           $this->fon_group= FALSE;
853         }
854       }
855       if ($this->acl_is_writeable("nagiosGroup")){
856         if (isset ($_POST['nagios_group'])){
857           $this->nagios_group= TRUE;
858         } else {
859           $this->nagios_group= FALSE;
860         }
861       }
862     }
864     /* Trust mode - special handling */
865     if($this->acl_is_writeable("trustModel")){
866       if (isset($_POST['trustmode'])){
867         $saved= $this->trustModel;
868         if ($_POST['trustmode'] == "1"){
869           $this->trustModel= "fullaccess";
870         } elseif ($_POST['trustmode'] == "2"){
871           $this->trustModel= "byhost";
872         } else {
873           $this->trustModel= "";
874         }
875         if ($this->trustModel != $saved){
876           $this->is_modified= TRUE;
877         }
878       }
879     }
881   }
884   /* Save to LDAP */
885   function save()
886   {
888     /* ID handling */
889     if ($this->force_gid == 0){
890       if ($this->saved_gidNumber != ""){
891         $this->gidNumber= $this->saved_gidNumber;
892       } else {
893         /* Calculate new, lock uids */
894         $wait= 10;
895         while (get_lock("uidnumber") != ""){
896           sleep (1);
898           /* timed out? */
899           if ($wait-- == 0){
900             break;
901           }
902         }
903         add_lock ("uidnumber", "gosa");
904         $this->gidNumber= $this->get_next_id("gidNumber", $this->dn);
905       }
906     }
907   
908     plugin::save(); 
910  /* Trust accounts */
911     $objectclasses= array();
912     foreach ($this->attrs['objectClass'] as $key => $class){
913       if (preg_match('/trustAccount/i', $class)){
914         continue;
915       }
916       $objectclasses[]= $this->attrs['objectClass'][$key];
917     }
918     $this->attrs['objectClass']= $objectclasses;
919     if ($this->trustModel != ""){
920       $this->attrs['objectClass'][]= "trustAccount";
921       $this->attrs['trustModel']= $this->trustModel;
922       $this->attrs['accessTo']= array();
923       if ($this->trustModel == "byhost"){
924         foreach ($this->accessTo as $host){
925           $this->attrs['accessTo'][]= $host;
926         }
927       }
928     } else {
929       if ($this->was_trust_account){
930         $this->attrs['accessTo']= array();
931         $this->attrs['trustModel']= array();
932       }
933     }
937     /* Remove objectClass for samba/phone support */
938     $tmp= array();
939     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
940       if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
941           $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
942           $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
943          $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
944         $tmp[]= $this->attrs['objectClass'][$i];
945       }
946     }
947     $this->attrs['objectClass']= $tmp;
948     $ldap= $this->config->get_ldap_link();
950     /* Add samba group functionality */
951     if ($this->samba3 && $this->smbgroup){
952   
953       /* Fixed undefined index ... 
954        */ 
955       $this->SID = $this->ridBase = "";
956       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
957         $this->SID    = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
958       }else{
959         msg_dialog::display(_("Error"), sprintf(_("Cannot find any SID for '%s'!"), $this->sambaDomainName), ERROR_DIALOG);
960       }
961       if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
962         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE']; 
963       }else{
964         msg_dialog::display(_("Error"), sprintf(_("Cannot find any RIDBASE for '%s'!"), $this->sambaDomainName), ERROR_DIALOG);
965       }
967       $this->attrs['objectClass'][]= 'sambaGroupMapping';
968       $this->attrs['sambaGroupType']= "2";
970       /* Check if we need to create a special entry */
971       if ($this->groupType == 0){
973         if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
974           $gidNumber= $this->gidNumber;
975           while(TRUE){
976             $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
977             $ldap->cd($this->config->current['BASE']);
978             $ldap->search("(sambaSID=$sid)",array("sambaSID"));
979             if ($ldap->count() == 0){
980               break;
981             }
982             $gidNumber++;
983           }
984           $this->attrs['sambaSID']= $sid;
985           $this->sambaSID= $sid;
986         }
988       } else {
989         $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
990       }
992       /* User wants me to fake the idMappings? This is useful for
993          making winbind resolve the group names in a reasonable amount
994          of time in combination with larger databases. */
995       if ($this->config->get_cfg_value("sambaidmapping") == "true"){
996         $this->attrs['objectClass'][]= "sambaIdmapEntry";
997       }
999     }
1001     /* Add phone functionality */
1002     if ($this->fon_group){
1003       $this->attrs['objectClass'][]= "goFonPickupGroup";
1004     }
1006     /* Add nagios functionality */
1007     if ($this->nagios_group){
1008       $this->attrs['objectClass'][]= "nagiosContactGroup";
1009     }
1011     /* Take members array */
1012     if (count ($this->memberUid)){
1013       $this->attrs['memberUid']= array_values(array_unique($this->memberUid));
1014     }
1016     /* New accounts need proper 'dn', propagate it to remaining objects */
1017     if ($this->dn == 'new'){
1018       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1019     }
1021     /* Add member dn's for RFC2307bis Support */
1022     if ($this->rfc2307bis){
1023       $this->attrs['member'] = array();
1024       if (count($this->memberUid)){
1025         foreach($this->attrs['memberUid'] as $uid) {
1026           $this->attrs['member'][]= $this->dnMapping[$uid];
1027         }
1028       } else {
1029         $this->attrs['member'][]= $this->dn;
1030       }
1031     }
1033     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1034        new entries. So do a check first... */
1035     $ldap->cat ($this->dn, array('dn'));
1036     if ($ldap->fetch()){
1037       /* Modify needs array() to remove values :-( */
1038       if (!count ($this->memberUid)){
1039         $this->attrs['memberUid']= array();
1040       }
1041       if ($this->samba3){
1042         if (!$this->smbgroup){
1043           $this->attrs['sambaGroupType']= array();
1044           $this->attrs['sambaSID']= array();
1045         }
1046       }
1047       $mode= "modify";
1048     } else {
1049       $mode= "add";
1050       $ldap->cd($this->config->current['BASE']);
1051       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1052     }
1054     /* Write back to ldap */
1055     $ldap->cd($this->dn);
1056     $this->cleanup();
1057     $ldap->$mode($this->attrs);
1059     /* Remove ACL dependencies too,
1060      */
1061     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1062       $tmp = new acl($this->config,$this->parent,$this->dn);
1063       $tmp->update_acl_membership($this->orig_dn,$this->dn);
1064     }
1066     if($this->initially_was_account){
1067       new log("modify","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1068     }else{
1069       new log("create","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1070     }
1072     $ret= 0;
1073     if (!$ldap->success()){
1074       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1075       $ret= 1;
1076     }
1078     /* Remove uid lock */
1079     del_lock ("uidnumber");
1081     /* Post that we've done*/
1082     $this->handle_post_events($mode);
1084     return ($ret);
1085   }
1087   function check()
1088   {
1089     /* Call common method to give check the hook */
1090     $message= plugin::check();
1092     /* Permissions for that base? */
1093     if ($this->base != ""){
1094       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1095     } else {
1096       $new_dn= $this->dn;
1097     }
1099     /* must: cn */
1100     if ($this->cn == "" && $this->acl_is_writeable("cn")){
1101       $message[]= msgPool::required(_("Name"));
1102     }
1104     /* Check for valid input */
1105     if (!tests::is_uid($this->cn)){
1106       if (strict_uid_mode()){
1107         $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/");
1108       } else {
1109         $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/i");
1110       }
1111     }
1113     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
1115       /* Check for used 'cn' */
1116       $ldap= $this->config->get_ldap_link();
1117       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new") || ($new_dn != $this->orig_dn)){
1118         $ldap->cd(get_groups_ou().$this->base);
1119         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
1120         if ($ldap->count() != 0){
1121           $message[]= msgPool::duplicated(_("Name"));
1122         }
1123       }
1125     }else{
1127       /* Check for used 'cn' */
1128       $ldap= $this->config->get_ldap_link();
1129       $ldap->cd($this->config->current['BASE']);
1130       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
1131       if ($ldap->count() != 0){
1133         /* New entry? */
1134         if ($this->dn == 'new'){
1135           $message[]= msgPool::duplicated(_("Name"));
1136         }
1138         /* Moved? */
1139         elseif ($new_dn != $this->orig_dn){
1140           $ldap->fetch();
1141           if ($ldap->getDN() != $this->orig_dn){
1142             $message[]= msgPool::duplicated(_("Name"));
1143           }
1144         }
1145       }
1146     }
1147      
1148     /* Check ID */
1149     if ($this->force_gid == "1"){
1150       if (!tests::is_id($this->gidNumber)){
1151         $message[]= msgPool::invalid(_("GID"), $this->gidNumber, "/[0-9]/");
1152       } else {
1153         if ($this->gidNumber < $this->config->get_cfg_value("minId")){
1154           $message[]= msgPool::toosmall(_("GID"), $this->config->get_cfg_value("minId"));
1155         }
1157       }
1158     }
1159     
1160     /* Check if we are allowed to create or move this object 
1161      */
1162     if(!$this->orig_dn == "new" || 
1163         $this->orig_base != $this->base || 
1164         $this->cn != $this->orig_cn){
1166       if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1167         $message[] = msgPool::permCreate();
1168       }elseif($this->orig_dn != "new" && !$this->acl_is_moveable($this->base)){
1169         $message[] = msgPool::permMove();
1170       }
1171     }
1173     return ($message);
1174   }
1176   function get_next_id($attrib, $dn)
1177   {
1178     $ids= array();
1179     $ldap= $this->config->get_ldap_link();
1181     $ldap->cd ($this->config->current['BASE']);
1182     if (preg_match('/gidNumber/i', $attrib)){
1183       $oc= "posixGroup";
1184     } else {
1185       $oc= "posixAccount";
1186     }
1187     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
1189     /* Get list of ids */
1190     while ($attrs= $ldap->fetch()){
1191       $ids[]= (int)$attrs["$attrib"][0];
1192     }
1194     /* Find out next free id near to UID_BASE */
1195     if ($this->config->get_cfg_value("baseIdHook") == ""){
1196       $base= $this->config->get_cfg_value("uidNumberBase");
1197     } else {
1198       /* Call base hook */
1199       $base= get_base_from_hook($dn, $attrib);
1200     }
1201     for ($id= $base; $id++; $id < pow(2,32)){
1202       if (!in_array($id, $ids)){
1203         return ($id);
1204       }
1205     }
1207     /* Check if id reached maximum */
1208     if ($id >= pow(2,32)){
1209       msg_dialog::display(_("Error"), _("Cannot allocate a free ID!"), ERROR_DIALOG);
1210       exit;
1211     }
1212   }
1214   function getCopyDialog()
1215   {
1216     $vars = array("cn");
1217   
1218     if($this ->force_gid){
1219       $used = " checked ";
1220       $dis  = "";
1221     }else{
1222       $used = "";
1223       $dis  = " disabled ";
1224     }
1226     $smarty = get_smarty();
1227     $smarty->assign("used",$used);
1228     $smarty->assign("dis" ,$dis);
1229     $smarty->assign("cn" ,$this->cn);
1230     $smarty->assign("gidNumber",$this->gidNumber);
1231     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
1232     $ret = array();
1233     $ret['string'] = $str;
1234     $ret['status'] = "";
1235     return($ret);
1236   }
1238   function saveCopyDialog()
1239   {
1240     if(isset($_POST['cn'])){
1241       $this->cn = $_POST['cn'];
1242     }
1243     if(isset($_POST['force_gid'])){
1244       $this->force_gid  = 1;
1245       $this->gidNumber= $_POST['gidNumber'];
1246     }else{
1247       $this->force_gid  = 0;
1248       $this->gidNumber  = false;
1249     }
1250   }
1252   
1253   /* Return plugin informations for acl handling  */ 
1254   static function plInfo()
1255   {
1256     return (array(  
1257           "plShortName" => _("Generic"),
1258           "plDescription" => _("Generic group settings"),
1259           "plSelfModify"  => FALSE,
1260           "plDepends"     => array(),
1261           "plPriority"    => 0,
1262           "plSection"     => array("administration"),
1263           "plCategory"    => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
1265           "plProvidedAcls"    => array(
1266             "cn"                => _("Name"),
1267             "description"       => _("Description"),
1268             "base"              => _("Base"),
1270             "gidNumber"         => _("GID"),
1272             "sambaGroupType"    => _("Samba group type"),
1273             "sambaDomainName"   => _("Samba domain name"),
1274             "trustModel"        => _("System trust"),
1275             "fonGroup"          => _("Phone pickup group"),
1276             "nagiosGroup"       => _("Nagios group"),
1278             "memberUid"         => _("Group member"))
1279         ));
1280   }
1283   function multiple_save_object()
1284   {
1285     if(isset($_POST['group_mulitple_edit'])){
1287       /* Create a base backup and reset the
1288          base directly after calling plugin::save_object();
1289          Base will be set seperatly a few lines below */
1290       $base_tmp = $this->base;
1291       plugin::multiple_save_object();
1292       plugin::save_object();
1293       $this->base = $base_tmp;
1295       foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group","trustmode") as $attr){
1296         if(isset($_POST['use_'.$attr])){
1297           $this->multi_boxes[] = $attr;
1298         }
1299       }
1301       /* Get base selection */
1302       if(isset($_POST['base'])){
1303         $tmp = $this->get_allowed_bases();
1304         if(isset($tmp[$_POST['base']])){
1305           $this->base = $_POST['base'];
1306         }
1307       }
1309       foreach (array( "smbgroup"   => "sambaGroupType" ,"nagios_group" => "nagios_group") as $val => $aclname) {
1310         if ($this->acl_is_writeable($aclname)){
1311           if(isset($_POST["$val"])){
1312             $this->$val=  TRUE;
1313           }else{
1314             $this->$val=  FALSE;
1315           }
1316         }
1317       }
1319       /* Save sambaDomain attribute */
1320       if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
1321         $this->sambaDomainName= $_POST['sambaDomainName'];
1322         $this->groupType= $_POST['groupType'];
1323       }
1325       /* Trust mode - special handling */
1326       if($this->acl_is_writeable("trustModel")){
1327         if (isset($_POST['trustmode'])){
1328           $saved= $this->trustModel;
1329           if ($_POST['trustmode'] == "1"){
1330             $this->trustModel= "fullaccess";
1331           } elseif ($_POST['trustmode'] == "2"){
1332             $this->trustModel= "byhost";
1333           } else {
1334             $this->trustModel= "";
1335           }
1336           if ($this->trustModel != $saved){
1337             $this->is_modified= TRUE;
1338           }
1339         }
1340       }
1342       /* Save fon attribute */
1343       if ($this->acl_is_writeable("fonGroup")){
1344         if (isset ($_POST['fon_group'])){
1345           $this->fon_group= TRUE;
1346         } else {
1347           $this->fon_group= FALSE;
1348         }
1349       }
1350     }
1351   }
1354   function get_multi_edit_values()
1355   {
1356     $ret = plugin::get_multi_edit_values();
1358     foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group") as $attr){    
1359       if(in_array($attr,$this->multi_boxes)){
1360         $ret[$attr] = $this->$attr;
1361       }
1362     }
1364     if(in_array("trustmode",$this->multi_boxes)){
1365       $ret['trustModel'] = $this->trustModel;
1366       $ret['accessTo'] = $this->accessTo;
1367     }
1369     $ret['memberUid'] = $this->memberUid;
1370     $ret['memberUid_used_by_some'] = $this->memberUid_used_by_some;
1371     return($ret);
1372   }
1374   function multiple_execute()
1375   {
1376     return($this->execute());
1377   }
1380   /* Initialize plugin with given atribute arrays
1381    */
1382   function init_multiple_support($attrs,$all)
1383   {
1384     plugin::init_multiple_support($attrs,$all);
1386     $this->memberUid = array();
1387     $this->memberUid_used_by_some = array();
1388     if (isset($attrs['memberUid'])){
1389       for ($i= 0; $i<$attrs['memberUid']['count']; $i++){
1390         $this->memberUid[$attrs['memberUid'][$i]]= $attrs['memberUid'][$i];
1391       }
1392       ksort($this->memberUid);
1393     }
1395     if (isset($all['memberUid'])){
1396       for ($i= 0; $i<$all['memberUid']['count']; $i++){
1397         if(!in_array($all['memberUid'][$i],$this->memberUid)){
1398           $this->memberUid_used_by_some[$all['memberUid'][$i]]= $all['memberUid'][$i];
1399         }
1400       }
1401       ksort($this->memberUid_used_by_some);
1402     }
1403   }
1406   function PrepareForCopyPaste($source)
1407   {
1408     plugin::PrepareForCopyPaste($source);
1410     $this->memberUid = array();
1411     if(isset($source['memberUid'])){
1412       for($i = 0 ; $i < $source['memberUid']['count']; $i ++){
1413         $this->memberUid[] = $source['memberUid'][$i];
1414       }
1415     }
1416   }
1419   function set_multi_edit_values($attrs)
1420   {
1421     $users = array();
1423     /* Update groupMembership, keep optinal group */
1424     foreach($attrs['memberUid_used_by_some'] as $uid){
1425       if(in_array($uid,$this->memberUid)){
1426         $users[$uid] = $uid;
1427       }
1428     }
1430     /* Update groupMembership, add forced groups */
1431     foreach($attrs['memberUid'] as $uid){
1432       $users[$uid] = $uid;
1433     }
1434     plugin::set_multi_edit_values($attrs);
1435     $this->memberUid = $users;
1436   }
1438 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1439 ?>