Code

Created trunk inside of 2.6-lhm
[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     /* 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->get_cfg_value("sambaRidBase");
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 ($this->config->get_cfg_value("sambaRidBase") != ""){
159           $this->sambaDomainName= "DEFAULT";
160           $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
161           $this->SID= $this->config->get_cfg_value("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 ("/^[^,]+,".preg_quote(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(TRUE);
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_writeable("base")){
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("serverRDN"),     "OC" => "(objectClass=goServer)");
376       $types['workstation'] = array("OU" => get_ou("workstationRDN"),"OC" => "(objectClass=gotoWorkstation)");
377       $types['terminal']    = array("OU" => get_ou("terminalRDN"),   "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("systemRDN").$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","nagios_group","trustmode") 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($silent = FALSE)
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 ($this->config->get_cfg_value("ldapFilterNestingLimit") == "" ||
662         count($this->memberUid) < $this->config->get_cfg_value("ldapFilterNestingLimit")){
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 ($this->config->get_cfg_value("ldapFilterNestingLimit") == "" ||
682         count($this->memberUid) < $this->config->get_cfg_value("ldapFilterNestingLimit")){
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 && !$silent){
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 ($this->config->get_cfg_value("sambaidmapping") == "true"){
991         $this->attrs['objectClass'][]= "sambaIdmapEntry";
992       }
994     }
996     /* Add phone functionality */
997     if ($this->fon_group){
998       $this->attrs['objectClass'][]= "goFonPickupGroup";
999     }
1001     /* Add nagios functionality */
1002     if ($this->nagios_group){
1003       $this->attrs['objectClass'][]= "nagiosContactGroup";
1004     }
1006     /* Take members array */
1007     if (count ($this->memberUid)){
1008       $this->attrs['memberUid']= array_values(array_unique($this->memberUid));
1009     }
1011     /* New accounts need proper 'dn', propagate it to remaining objects */
1012     if ($this->dn == 'new'){
1013       $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1014     }
1016     /* Add member dn's for RFC2307bis Support */
1017     if ($this->rfc2307bis){
1018       $this->attrs['member'] = array();
1019       if (count($this->memberUid)){
1020         foreach($this->attrs['memberUid'] as $uid) {
1021           $this->attrs['member'][]= $this->dnMapping[$uid];
1022         }
1023       } else {
1024         $this->attrs['member'][]= $this->dn;
1025       }
1026     }
1028     /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1029        new entries. So do a check first... */
1030     $ldap->cat ($this->dn, array('dn'));
1031     if ($ldap->fetch()){
1032       /* Modify needs array() to remove values :-( */
1033       if (!count ($this->memberUid)){
1034         $this->attrs['memberUid']= array();
1035       }
1036       if ($this->samba3){
1037         if (!$this->smbgroup){
1038           $this->attrs['sambaGroupType']= array();
1039           $this->attrs['sambaSID']= array();
1040         }
1041       }
1042       $mode= "modify";
1043     } else {
1044       $mode= "add";
1045       $ldap->cd($this->config->current['BASE']);
1046       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1047     }
1049     /* Write back to ldap */
1050     $ldap->cd($this->dn);
1051     $this->cleanup();
1052     $ldap->$mode($this->attrs);
1054     /* Remove ACL dependencies too,
1055      */
1056     if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1057       $tmp = new acl($this->config,$this->parent,$this->dn);
1058       $tmp->update_acl_membership($this->orig_dn,$this->dn);
1059     }
1061     if($this->initially_was_account){
1062       new log("modify","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1063     }else{
1064       new log("create","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1065     }
1067     $ret= 0;
1068     if (!$ldap->success()){
1069       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1070       $ret= 1;
1071     }
1073     /* Remove uid lock */
1074     del_lock ("uidnumber");
1076     /* Post that we've done*/
1077     $this->handle_post_events($mode);
1079     return ($ret);
1080   }
1082   function check()
1083   {
1084     /* Call common method to give check the hook */
1085     $message= plugin::check();
1087     /* Permissions for that base? */
1088     if ($this->base != ""){
1089       $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1090     } else {
1091       $new_dn= $this->dn;
1092     }
1094     /* must: cn */
1095     if ($this->cn == "" && $this->acl_is_writeable("cn")){
1096       $message[]= msgPool::required(_("Name"));
1097     }
1099     /* Check for valid input */
1100     if (!tests::is_uid($this->cn)){
1101       if (strict_uid_mode()){
1102         $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/");
1103       } else {
1104         $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/i");
1105       }
1106     }
1108     if($this->allowGroupsWithSameNameInOtherSubtrees == true){
1110       /* Check for used 'cn' */
1111       $ldap= $this->config->get_ldap_link();
1112       if(($this->cn  != $this->orig_cn) || ($this->orig_dn == "new")){
1113         $ldap->cd(get_groups_ou().$this->base);
1114         $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
1115         if ($ldap->count() != 0){
1116           $message[]= msgPool::duplicated(_("Name"));
1117         }
1118       }
1120     }else{
1122       /* Check for used 'cn' */
1123       $ldap= $this->config->get_ldap_link();
1124       $ldap->cd($this->config->current['BASE']);
1125       $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
1126       if ($ldap->count() != 0){
1128         /* New entry? */
1129         if ($this->dn == 'new'){
1130           $message[]= msgPool::duplicated(_("Name"));
1131         }
1133         /* Moved? */
1134         elseif ($new_dn != $this->orig_dn){
1135           $ldap->fetch();
1136           if ($ldap->getDN() != $this->orig_dn){
1137             $message[]= msgPool::duplicated(_("Name"));
1138           }
1139         }
1140       }
1141     }
1142      
1143     /* Check ID */
1144     if ($this->force_gid == "1"){
1145       if (!tests::is_id($this->gidNumber)){
1146         $message[]= msgPool::invalid(_("GID"), $this->gidNumber, "/[0-9]/");
1147       } else {
1148         if ($this->gidNumber < $this->config->get_cfg_value("minId")){
1149           $message[]= msgPool::toosmall(_("GID"), $this->config->get_cfg_value("minId"));
1150         }
1152       }
1153     }
1154     
1155     /* Check if we are allowed to create or move this object 
1156      */
1157     if(!$this->orig_dn == "new" || 
1158         $this->orig_base != $this->base || 
1159         $this->cn != $this->orig_cn){
1161       if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1162         $message[] = msgPool::permCreate();
1163       }elseif($this->orig_dn != "new" && !$this->acl_is_moveable($this->base)){
1164         $message[] = msgPool::permMove();
1165       }
1166     }
1168     return ($message);
1169   }
1171   function get_next_id($attrib, $dn)
1172   {
1173     $ids= array();
1174     $ldap= $this->config->get_ldap_link();
1176     $ldap->cd ($this->config->current['BASE']);
1177     if (preg_match('/gidNumber/i', $attrib)){
1178       $oc= "posixGroup";
1179     } else {
1180       $oc= "posixAccount";
1181     }
1182     $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
1184     /* Get list of ids */
1185     while ($attrs= $ldap->fetch()){
1186       $ids[]= (int)$attrs["$attrib"][0];
1187     }
1189     /* Find out next free id near to UID_BASE */
1190     if ($this->config->get_cfg_value("baseIdHook") == ""){
1191       $base= $this->config->get_cfg_value("uidNumberBase");
1192     } else {
1193       /* Call base hook */
1194       $base= get_base_from_hook($dn, $attrib);
1195     }
1196     for ($id= $base; $id++; $id < pow(2,32)){
1197       if (!in_array($id, $ids)){
1198         return ($id);
1199       }
1200     }
1202     /* Check if id reached maximum */
1203     if ($id >= pow(2,32)){
1204       msg_dialog::display(_("Error"), _("Cannot allocate a free ID!"), ERROR_DIALOG);
1205       exit;
1206     }
1207   }
1209   function getCopyDialog()
1210   {
1211     $vars = array("cn");
1212   
1213     if($this ->force_gid){
1214       $used = " checked ";
1215       $dis  = "";
1216     }else{
1217       $used = "";
1218       $dis  = " disabled ";
1219     }
1221     $smarty = get_smarty();
1222     $smarty->assign("used",$used);
1223     $smarty->assign("dis" ,$dis);
1224     $smarty->assign("cn" ,$this->cn);
1225     $smarty->assign("gidNumber",$this->gidNumber);
1226     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
1227     $ret = array();
1228     $ret['string'] = $str;
1229     $ret['status'] = "";
1230     return($ret);
1231   }
1233   function saveCopyDialog()
1234   {
1235     if(isset($_POST['cn'])){
1236       $this->cn = $_POST['cn'];
1237     }
1238     if(isset($_POST['force_gid'])){
1239       $this->force_gid  = 1;
1240       $this->gidNumber= $_POST['gidNumber'];
1241     }else{
1242       $this->force_gid  = 0;
1243       $this->gidNumber  = false;
1244     }
1245   }
1247   
1248   /* Return plugin informations for acl handling  */ 
1249   static function plInfo()
1250   {
1251     return (array(  
1252           "plShortName" => _("Generic"),
1253           "plDescription" => _("Generic group settings"),
1254           "plSelfModify"  => FALSE,
1255           "plDepends"     => array(),
1256           "plPriority"    => 0,
1257           "plSection"     => array("administration"),
1258           "plCategory"    => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
1260           "plProvidedAcls"    => array(
1261             "cn"                => _("Name"),
1262             "description"       => _("Description"),
1263             "base"              => _("Base"),
1265             "gidNumber"         => _("GID"),
1267             "sambaGroupType"    => _("Samba group type"),
1268             "sambaDomainName"   => _("Samba domain name"),
1269             "trustModel"        => _("System trust"),
1270             "fonGroup"          => _("Phone pickup group"),
1271             "nagiosGroup"       => _("Nagios group"),
1273             "memberUid"         => _("Group member"))
1274         ));
1275   }
1278   function multiple_save_object()
1279   {
1280     if(isset($_POST['group_mulitple_edit'])){
1282       /* Create a base backup and reset the
1283          base directly after calling plugin::save_object();
1284          Base will be set seperatly a few lines below */
1285       $base_tmp = $this->base;
1286       plugin::multiple_save_object();
1287       plugin::save_object();
1288       $this->base = $base_tmp;
1290       foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group","trustmode") as $attr){
1291         if(isset($_POST['use_'.$attr])){
1292           $this->multi_boxes[] = $attr;
1293         }
1294       }
1296       /* Get base selection */
1297       if(isset($_POST['base'])){
1298         $tmp = $this->get_allowed_bases();
1299         if(isset($tmp[$_POST['base']])){
1300           $this->base = $_POST['base'];
1301         }
1302       }
1304       foreach (array( "smbgroup"   => "sambaGroupType" ,"nagios_group" => "nagios_group") as $val => $aclname) {
1305         if ($this->acl_is_writeable($aclname)){
1306           if(isset($_POST["$val"])){
1307             $this->$val=  TRUE;
1308           }else{
1309             $this->$val=  FALSE;
1310           }
1311         }
1312       }
1314       /* Save sambaDomain attribute */
1315       if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
1316         $this->sambaDomainName= $_POST['sambaDomainName'];
1317         $this->groupType= $_POST['groupType'];
1318       }
1320       /* Trust mode - special handling */
1321       if($this->acl_is_writeable("trustModel")){
1322         if (isset($_POST['trustmode'])){
1323           $saved= $this->trustModel;
1324           if ($_POST['trustmode'] == "1"){
1325             $this->trustModel= "fullaccess";
1326           } elseif ($_POST['trustmode'] == "2"){
1327             $this->trustModel= "byhost";
1328           } else {
1329             $this->trustModel= "";
1330           }
1331           if ($this->trustModel != $saved){
1332             $this->is_modified= TRUE;
1333           }
1334         }
1335       }
1337       /* Save fon attribute */
1338       if ($this->acl_is_writeable("fonGroup")){
1339         if (isset ($_POST['fon_group'])){
1340           $this->fon_group= TRUE;
1341         } else {
1342           $this->fon_group= FALSE;
1343         }
1344       }
1345     }
1346   }
1349   function get_multi_edit_values()
1350   {
1351     $ret = plugin::get_multi_edit_values();
1353     foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group") as $attr){    
1354       if(in_array($attr,$this->multi_boxes)){
1355         $ret[$attr] = $this->$attr;
1356       }
1357     }
1359     if(in_array("trustmode",$this->multi_boxes)){
1360       $ret['trustModel'] = $this->trustModel;
1361       $ret['accessTo'] = $this->accessTo;
1362     }
1364     $ret['memberUid'] = $this->memberUid;
1365     $ret['memberUid_used_by_some'] = $this->memberUid_used_by_some;
1366     return($ret);
1367   }
1369   function multiple_execute()
1370   {
1371     return($this->execute());
1372   }
1375   /* Initialize plugin with given atribute arrays
1376    */
1377   function init_multiple_support($attrs,$all)
1378   {
1379     plugin::init_multiple_support($attrs,$all);
1381     $this->memberUid = array();
1382     $this->memberUid_used_by_some = array();
1383     if (isset($attrs['memberUid'])){
1384       for ($i= 0; $i<$attrs['memberUid']['count']; $i++){
1385         $this->memberUid[$attrs['memberUid'][$i]]= $attrs['memberUid'][$i];
1386       }
1387       ksort($this->memberUid);
1388     }
1390     if (isset($all['memberUid'])){
1391       for ($i= 0; $i<$all['memberUid']['count']; $i++){
1392         if(!in_array($all['memberUid'][$i],$this->memberUid)){
1393           $this->memberUid_used_by_some[$all['memberUid'][$i]]= $all['memberUid'][$i];
1394         }
1395       }
1396       ksort($this->memberUid_used_by_some);
1397     }
1398   }
1401   function PrepareForCopyPaste($source)
1402   {
1403     plugin::PrepareForCopyPaste($source);
1405     $this->memberUid = array();
1406     if(isset($source['memberUid'])){
1407       for($i = 0 ; $i < $source['memberUid']['count']; $i ++){
1408         $this->memberUid[] = $source['memberUid'][$i];
1409       }
1410     }
1411   }
1414   function set_multi_edit_values($attrs)
1415   {
1416     $users = array();
1418     /* Update groupMembership, keep optinal group */
1419     foreach($attrs['memberUid_used_by_some'] as $uid){
1420       if(in_array($uid,$this->memberUid)){
1421         $users[$uid] = $uid;
1422       }
1423     }
1425     /* Update groupMembership, add forced groups */
1426     foreach($attrs['memberUid'] as $uid){
1427       $users[$uid] = $uid;
1428     }
1429     plugin::set_multi_edit_values($attrs);
1430     $this->memberUid = $users;
1431   }
1433 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1434 ?>