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 $sambaSID= "";
39 var $sambaDomainName= "DEFAULT";
40 var $SID= "";
41 var $ridBase= 0;
42 var $members= array();
43 var $users= array();
44 var $member= array();
45 var $allusers= array();
46 var $saved_gidNumber= "";
47 var $oldgroupType= "";
48 var $orig_dn= "";
49 var $orig_cn= "";
50 var $orig_base= "";
51 var $has_mailAccount= FALSE;
52 var $group_dialog= FALSE;
53 var $nagios_group =FALSE;
54 var $sambaGroupType;
55 var $dialog;
56 var $rfc2307bis= FALSE;
57 var $OnlyShowFirstEntries =200;
58 var $dnMapping= array();
59 var $view_logged = FALSE;
60 var $allowGroupsWithSameNameInOtherSubtrees = true;
62 /* Trustmodel/AccessTo
63 */
64 var $accessTo= array();
65 var $trustModel= "";
66 var $show_ws_dialog = FALSE;
68 /* attribute list for save action */
69 var $attributes= array("cn", "description", "gidNumber","memberUid","sambaGroupType","sambaSID","accessTo","trustModel");
70 var $objectclasses= array("top", "posixGroup");
72 var $CopyPasteVars = array("force_gid","fon_group","smbgroup","groupType","sambaSID","sambaDomainName","SID","nagios_group","sambaGroupType");
74 var $multiple_support = TRUE;
76 function group (&$config, $dn= NULL)
77 {
78 /* Set rfc2307bis flag */
79 if ($config->get_cfg_value("rfc2307bis") == "true"){
80 $this->rfc2307bis= TRUE;
81 $this->attributes[]= "member";
82 $this->objectclasses[]= "groupOfNames";
83 }
85 plugin::plugin ($config, $dn);
87 /* Load attributes depending on the samba version */
88 $this->orig_dn= $dn;
89 $this->orig_cn= $this->cn;
91 /* Get member list */
92 if (isset($this->attrs['memberUid'][0])){
93 $tmp= array();
94 for ($i= 0; $i<$this->attrs['memberUid']['count']; $i++){
95 $tmp[$this->attrs['memberUid'][$i]]= $this->attrs['memberUid'][$i];
96 }
97 $this->memberUid= $tmp;
98 ksort ($this->memberUid);
99 }
101 /* Save gidNumber for later use */
102 if (isset($this->attrs['gidNumber'])){
103 $this->saved_gidNumber= $this->attrs['gidNumber'][0];
104 }
106 /* Is a samba group? */
107 if (isset($this->attrs['objectClass'])){
108 if (array_search ('sambaGroupMapping', $this->attrs['objectClass']) == FALSE ){
109 $this->smbgroup= FALSE;
110 } else {
111 $this->smbgroup= TRUE;
112 if (isset($this->attrs['sambaSID'])){
113 $this->sambaSID= $this->attrs['sambaSID'][0];
114 }
115 }
116 if (array_search ('goFonPickupGroup', $this->attrs['objectClass']) == FALSE ){
117 $this->fon_group= FALSE;
118 } else {
119 $this->fon_group= TRUE;
120 }
121 if (array_search ('nagiosContactGroup', $this->attrs['objectClass']) == FALSE ){
122 $this->nagios_group= FALSE;
123 } else {
124 $this->nagios_group= TRUE;
125 }
126 }
128 /* Set mail flag */
129 if (isset($this->attrs['objectClass']) && in_array('gosaMailAccount', $this->attrs['objectClass'])){
130 $this->has_mailAccount= TRUE;
131 }
133 /* Get samba Domain in case of samba 3 */
134 if ($this->sambaSID != ""){
135 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
136 $ldap= $this->config->get_ldap_link();
137 $ldap->cd($this->config->current['BASE']);
138 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase"));
139 if ($ldap->count() != 0){
140 $attrs= $ldap->fetch();
141 if(isset($attrs['sambaAlgorithmicRidBase'])){
142 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
143 } else {
144 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
145 }
147 /* Get domain name for SID */
148 $this->sambaDomainName= "DEFAULT";
149 foreach ($this->config->data['SERVERS']['SAMBA'] as $key => $val){
150 if ($val['SID'] == $this->SID){
151 $this->sambaDomainName= $key;
152 break;
153 }
154 }
155 } else {
156 if ($this->config->get_cfg_value("sambaRidBase") != ""){
157 $this->sambaDomainName= "DEFAULT";
158 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
159 $this->SID= $this->config->get_cfg_value("sid");
160 } else {
161 msg_dialog::display(_("Configuration error"), _("Cannot find group SID in your configuration!"), ERROR_DIALOG);
162 }
163 }
165 /* Get group type */
166 $this->groupType= (int)substr(strrchr($this->sambaSID, "-"), 1);
167 if ($this->groupType < 500 || $this->groupType > 553){
168 $this->groupType= 0;
169 }
170 $this->oldgroupType= $this->groupType;
171 }
173 /* Get global filter config */
174 if (!session::is_set("gufilter")){
175 $ui= get_userinfo();
176 $base= get_base_from_people($ui->dn);
177 $gufilter= array( "dselect" => $base,
178 "regex" => "*");
179 session::set("gufilter", $gufilter);
180 }
181 $gufilter= session::get('gufilter');
182 $gufilter['SubSearchGroup'] = false;
183 session::set('gufilter',$gufilter);
185 if ($this->dn == "new"){
186 if(session::is_set('CurrentMainBase')){
187 $this->base = session::get('CurrentMainBase');
188 }else{
189 $ui= get_userinfo();
190 $this->base= dn2base($ui->dn);
191 }
192 } else {
194 /* Get object base */
195 $this->base =preg_replace ("/^[^,]+,".preg_quote(get_groups_ou(), '/')."/","",$this->dn);
196 }
197 $this->orig_base = $this->base;
199 /* Is this account a trustAccount? */
200 if (isset($this->attrs['trustModel'])){
201 $this->trustModel= $this->attrs['trustModel'][0];
202 $this->was_trust_account= TRUE;
203 } else {
204 $this->was_trust_account= FALSE;
205 $this->trustModel= "";
206 }
208 $this->accessTo = array();
209 if (isset($this->attrs['accessTo'])){
210 for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
211 $tmp= $this->attrs['accessTo'][$i];
212 $this->accessTo[$tmp]= $tmp;
213 }
214 }
216 /* Get global filter config */
217 if (!session::is_set("sysfilter")){
218 $ui= get_userinfo();
219 $base= get_base_from_people($ui->dn);
220 $sysfilter= array( "depselect" => $base,
221 "regex" => "*");
222 session::set("sysfilter", $sysfilter);
223 }
225 /* This is always an account */
226 $this->is_account= TRUE;
227 $this->reload(TRUE);
228 }
230 function execute()
231 {
232 /* Call parent execute */
233 plugin::execute();
235 /* Log view */
236 if($this->is_account && !$this->view_logged){
237 $this->view_logged = TRUE;
238 new log("view","groups/".get_class($this),$this->dn);
239 }
241 /* Do we represent a valid group? */
242 if (!$this->is_account && $this->parent === NULL){
243 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".msgPool::noValidExtension()."</b>";
244 return ($display);
245 }
247 /* Delete user from group */
248 if (isset($_POST['del_users']) && isset($_POST['members']) && preg_match("/w/",$this->getacl("memberUid"))){
249 foreach ($_POST['members'] as $value){
250 unset ($this->members["$value"]);
251 $this->removeUser($value);
252 }
253 $this->reload();
254 }
256 /* Add objects? */
257 if (isset($_POST["edit_membership"]) && preg_match("/w/",$this->getacl("memberUid"))){
258 $this->group_dialog= TRUE;
259 $this->dialog= TRUE;
260 }
262 /* Add objects finished? */
263 if (isset($_POST["add_users_finish"]) || isset($_POST["add_users_cancel"])){
264 $this->group_dialog= FALSE;
265 $this->dialog= FALSE;
266 }
268 /* Add user to group */
269 if (isset($_POST['add_users_finish']) && isset($_POST['users'])){
270 foreach ($_POST['users'] as $value){
271 $this->members["$value"]= $this->allusers[$value];
272 asort($this->members);
273 $this->addUser($value);
274 }
275 $this->reload();
276 }
278 /* Base select dialog */
279 $once = true;
280 foreach($_POST as $name => $value){
281 if((preg_match("/^chooseBase/",$name) && $once) && $this->acl_is_writeable("base")){
283 $once = false;
284 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
285 $this->dialog->setCurrentBase($this->base);
286 }
287 }
289 /* Dialog handling */
290 if(is_object($this->dialog)){
291 /* Must be called before save_object */
292 $this->dialog->save_object();
294 if($this->dialog->isClosed()){
295 $this->dialog = false;
296 }elseif($this->dialog->isSelected()){
298 /* Check if selected base is valid */
299 $tmp = $this->get_allowed_bases();
300 if(isset($tmp[$this->dialog->isSelected()])){
301 $this->base = $this->dialog->isSelected();
302 }
303 $this->dialog= false;
304 }else{
305 return($this->dialog->execute());
306 }
307 }
310 /* Add user workstation? */
311 if (isset($_POST["add_ws"])){
312 $this->show_ws_dialog= TRUE;
313 $this->dialog= TRUE;
314 }
316 /* Add user workstation? */
317 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
318 foreach($_POST['wslist'] as $ws){
319 $this->accessTo[$ws]= $ws;
320 }
321 ksort($this->accessTo);
322 $this->is_modified= TRUE;
323 }
325 /* Remove user workstations? */
326 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
327 foreach($_POST['workstation_list'] as $name){
328 unset ($this->accessTo[$name]);
329 }
330 $this->is_modified= TRUE;
331 }
333 /* Add user workstation finished? */
334 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
335 $this->show_ws_dialog= FALSE;
336 $this->dialog= FALSE;
337 }
339 $smarty= get_smarty();
341 /* Show ws dialog */
342 if ($this->show_ws_dialog){
344 /* Save data */
345 $sysfilter= session::get("sysfilter");
346 foreach( array("depselect", "regex") as $type){
347 if (isset($_POST[$type])){
348 $sysfilter[$type]= $_POST[$type];
349 }
350 }
351 if (isset($_GET['search'])){
352 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
353 if ($s == "**"){
354 $s= "*";
355 }
356 $sysfilter['regex']= $s;
357 }
358 session::set("sysfilter", $sysfilter);
360 /* Get workstation list */
361 $exclude= "";
362 foreach($this->accessTo as $ws){
363 $exclude.= "(cn=$ws)";
364 }
365 if ($exclude != ""){
366 $exclude= "(!(|$exclude))";
367 }
368 $regex= $sysfilter['regex'];
370 /* Search for systems
371 */
372 $types = array();
373 $types['server'] = array("OU" => get_ou("serverRDN"), "OC" => "(objectClass=goServer)");
374 $types['workstation'] = array("OU" => get_ou("workstationRDN"),"OC" => "(objectClass=gotoWorkstation)");
375 $types['terminal'] = array("OU" => get_ou("terminalRDN"), "OC" => "(objectClass=gotoTerminal)");
377 $res = array();
378 foreach($types as $acl => $data){
379 $filter= "(&".$data['OC']."$exclude(cn=$regex))";
380 $res= array_merge($res,get_sub_list($filter,array($acl),$data['OU'],get_ou("systemRDN").$sysfilter['depselect'],
381 array("cn"), GL_SUBSEARCH | GL_SIZELIMIT));
382 }
383 $wslist = array();
384 foreach ($res as $attrs){
385 $wslist[]= preg_replace('/\$/', '', $attrs['cn'][0]);
386 }
388 asort($wslist);
389 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
390 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
391 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
392 $smarty->assign("deplist", $this->config->idepartments);
393 $smarty->assign("alphabet", generate_alphabet());
394 foreach( array("depselect", "regex") as $type){
395 $smarty->assign("$type", $sysfilter[$type]);
396 }
397 $smarty->assign("hint", print_sizelimit_warning());
398 $smarty->assign("wslist", $wslist);
399 $smarty->assign("apply", apply_filter());
400 $display= $smarty->fetch (get_template_path('trust_machines.tpl', TRUE, dirname(__FILE__)));
401 return ($display);
402 }
404 if($this->config->search("nagiosaccount", "CLASS",array('menu'))){
405 $smarty->assign("nagios",true);
406 }else{
407 $smarty->assign("nagios",false);
408 }
410 if($this->config->search("phoneAccount", "CLASS",array('menu'))){
411 $smarty->assign("pickupGroup",true);
412 }else{
413 $smarty->assign("pickupGroup",false);
414 }
416 /* Manage object add dialog */
417 if ($this->group_dialog){
419 /* Save data */
420 $gufilter= session::get("gufilter");
421 foreach( array("dselect", "regex") as $type){
422 if (isset($_POST[$type])){
423 $gufilter[$type]= $_POST[$type];
424 }
425 }
426 if(isset($_POST['regex'])){
427 if(isset($_POST['SubSearchGroup'])){
428 $gufilter['SubSearchGroup'] = true;
429 }else{
430 $gufilter['SubSearchGroup'] = false;
431 }
432 }
434 if (isset($_GET['search'])){
435 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
436 if ($s == "**"){
437 $s= "*";
438 }
439 $gufilter['regex']= $s;
440 }
441 session::set("gufilter", $gufilter);
442 $this->reload();
444 /* Show dialog */
445 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
446 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
447 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
448 $ui = get_userinfo();
449 $tmp = $ui->get_module_departments("users");
450 $deps = array();
451 foreach($this->config->idepartments as $dn => $name){
452 if(in_array($dn,$tmp)){
453 $deps[$dn] = $name;
454 }
455 }
457 $smarty->assign("deplist", $deps);
458 $smarty->assign("alphabet", generate_alphabet());
459 foreach( array("dselect", "regex","SubSearchGroup") as $type){
460 $smarty->assign("$type", $gufilter[$type]);
461 }
462 $smarty->assign("hint", print_sizelimit_warning());
463 $smarty->assign("users", $this->displayUsers);
464 $smarty->assign("apply", apply_filter());
465 $display= $smarty->fetch (get_template_path('group_objects.tpl', TRUE, dirname(__FILE__)));
466 return ($display);
467 }
469 $smarty->assign("bases", $this->get_allowed_bases());
470 $smarty->assign("base_select", $this->base);
472 $domains= array();
473 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
474 $domains[$name]= $name;
475 }
476 $smarty->assign("sambaDomains", $domains);
477 $smarty->assign("sambaDomainName", $this->sambaDomainName);
478 $groupTypes= array(0 => _("Samba group"), 512 => _("Domain admins"), 513 => _("Domain users"),
479 514 => _("Domain guests"));
481 /* Don't loose special groups! If not key'ed above, add it to
482 the combo box... */
483 if ($this->groupType >= 500 && $this->groupType <= 553 && !isset($groupTypes[$this->groupType])){
484 $groupTypes[$this->groupType]= sprintf(_("Special group (%d)"), $this->groupType);
485 }
487 $smarty->assign("groupTypes", $groupTypes);
488 $smarty->assign("groupType", $this->groupType);
491 /* Members and users */
492 $smarty->assign("members", $this->members);
494 /* Work on trust modes */
495 $smarty->assign("trusthide", " disabled ");
496 $smarty->assign("trustmodeACL", $this->getacl("trustModel"));
497 if ($this->trustModel == "fullaccess"){
498 $trustmode= 1;
499 // pervent double disable tag in html code, this will disturb our clean w3c html
500 $smarty->assign("trustmode", $this->getacl("trustModel"));
502 } elseif ($this->trustModel == "byhost"){
503 $trustmode= 2;
504 $smarty->assign("trusthide", "");
505 } else {
506 // pervent double disable tag in html code, this will disturb our clean w3c html
507 $smarty->assign("trustmode", $this->getacl("trustModel"));
508 $trustmode= 0;
509 }
510 $smarty->assign("trustmode", $trustmode);
511 $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
512 2 => _("allow access to these hosts")));
514 if((count($this->accessTo))==0){
515 $smarty->assign("emptyArrAccess",true);
516 } else{
517 $smarty->assign("emptyArrAccess",false);
519 }
521 $smarty->assign("workstations", $this->accessTo);
525 /* Checkboxes */
526 foreach (array("force_gid", "smbgroup") as $val){
527 if ($this->$val == "1"){
528 $smarty->assign("$val", "checked");
529 } else {
530 $smarty->assign("$val", "");
531 }
532 }
533 if ($this->force_gid != "1"){
534 $smarty->assign("forceMode", "disabled");
535 }else{
536 $smarty->assign("forceMode", "");
537 }
538 if ($this->fon_group){
539 $smarty->assign("fon_group", "checked");
540 } else {
541 $smarty->assign("fon_group", "");
542 }
544 if ($this->nagios_group){
545 $smarty->assign("nagios_group", "checked");
546 } else {
547 $smarty->assign("nagios_group", "");
548 }
550 /* Fields */
551 foreach (array("cn", "description", "gidNumber") as $val){
552 $smarty->assign("$val", $this->$val);
553 }
555 $tmp = $this->plInfo();
556 foreach($tmp['plProvidedAcls'] as $name => $translation){
557 $smarty->assign($name."ACL",$this->getacl($name));
558 }
560 if($this->acl_is_writeable("base")){
561 $smarty->assign("baseSelect",true);
562 }else{
563 $smarty->assign("baseSelect",false);
564 }
566 /* Show main page */
567 $smarty->assign("alphabet", generate_alphabet(10));
568 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
569 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
570 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
571 $smarty->assign("deplist", $this->config->idepartments);
573 /* Multiple edit handling */
574 $smarty->assign("multiple_support",$this->multiple_support_active);
576 $smarty->assign("memberUid_All",$this->memberUid);
577 $smarty->assign("memberUid_Some",$this->memberUid_used_by_some);
579 foreach($this->attributes as $val){
580 if(in_array($val,$this->multi_boxes)){
581 $smarty->assign("use_".$val,TRUE);
582 }else{
583 $smarty->assign("use_".$val,FALSE);
584 }
585 }
586 foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group","trustmode") as $val){
587 if(in_array($val,$this->multi_boxes)){
588 $smarty->assign("use_".$val,TRUE);
589 }else{
590 $smarty->assign("use_".$val,FALSE);
591 }
592 }
594 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
595 }
597 function addUser($uid)
598 {
599 /* In mutliple edit we have to handle two arrays.
600 * memberUid : Containing users used in all groups
601 * memberUid_used_by_some : Those which are not used in all groups
602 * So we have to remove the given $uid from the ..used_by_some array first.
603 */
604 if($this->multiple_support_active){
605 if(isset($this->memberUid_used_by_some[$uid])){
606 unset($this->memberUid_used_by_some[$uid]);
607 }
608 }
610 /* Ensure that the requested object is known to the group class
611 */
612 if(!isset($this->dnMapping[$uid])){
613 $ldap = $this->config->get_ldap_link();
614 $ldap->cd($this->config->current['BASE']);
615 $ldap->search("(&(objectClass=gosaAccount)(uid=".$uid."))",array("dn", "uid","sn","givenName"));
616 if($ldap->count() == 0 ){
617 msg_dialog::display(_("Error"),
618 sprintf(_("Adding UID '%s' to group '%s' failed: cannot find user object!"),
619 $uid,$this->cn),
620 ERROR_DIALOG);
621 return;
622 }elseif($ldap->count() >= 2){
623 msg_dialog::display(_("Error"),
624 sprintf(_("Add UID '%s' to group '%s' failed: UID is used more than once!"),
625 $uid,$this->cn),
626 ERROR_DIALOG);
627 return;
628 }else{
629 while($attrs = $ldap->fetch()){
630 $this->dnMapping[$attrs['uid'][0]] = $attrs['dn'];
631 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
632 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
633 }
634 }
635 }
637 $this->memberUid[$uid]= $uid;
638 }
641 function removeUser($uid)
642 {
643 $temp= array();
644 if(isset($this->memberUid[$uid])){
645 unset($this->memberUid[$uid]);
646 }
648 /* We have two array contianing group members in multiple edit.
649 * this->memberUid : Groups used by all currently edited groups
650 * this->memberUid_used_by_some: Used by some
651 * So we have to remove the specified uid from both arrays.
652 */
653 if($this->multiple_support_active){
654 if(isset($this->memberUid_used_by_some[$uid])){
655 unset($this->memberUid_used_by_some[$uid]);
656 }
657 }
658 }
660 /* Reload data */
661 function reload($silent = FALSE)
662 {
663 /* Fix regex string */
664 $gufilter = session::get("gufilter");
665 $regex = normalizeLdap($gufilter['regex']);
666 $MaxUser = $this->OnlyShowFirstEntries;
668 /* Prepare ldap link */
669 $ldap= $this->config->get_ldap_link();
670 $ldap->cd($gufilter['dselect']);
673 /* Resolve still unresolved memberuids to fill the list with sn/giveName attributes
674 (Store gathered sn/givenName informations in $this->allusers too,
675 to be prepared when adding/deleting users)
676 */
677 $filter = "";
678 if ($this->config->get_cfg_value("ldapFilterNestingLimit") == "" ||
679 count($this->memberUid) < $this->config->get_cfg_value("ldapFilterNestingLimit")){
680 foreach ($this->memberUid as $value){
681 if(!isset($this->members[$value])){
682 $filter .= "(uid=".normalizeLdap($value).")";
683 }
684 }
685 }
687 if(!empty($filter)){
688 $ldap->cd($this->config->current['BASE']);
689 $ldap->search("(&(objectClass=gosaAccount)(|".$filter."))",array("dn", "uid","sn","givenName"));
690 while($attrs = $ldap->fetch()){
691 $this->dnMapping[$attrs['uid'][0]] = $attrs['dn'];
692 $this->members[$attrs['uid'][0]] = $this->createResultName($attrs);
693 $this->allusers[$attrs['uid'][0]]= $this->createResultName($attrs);
694 }
695 }
697 /* check if all uids are resolved */
698 if ($this->config->get_cfg_value("ldapFilterNestingLimit") == "" ||
699 count($this->memberUid) < $this->config->get_cfg_value("ldapFilterNestingLimit")){
700 foreach ($this->memberUid as $value){
701 if(!isset($this->members[$value])){
702 $this->members[$value] = _("! unknown UID")." [".$value."]";
703 }
704 }
705 }else{
706 foreach ($this->memberUid as $value){
707 $this->members[$value] = $value;
708 }
709 }
711 /* Create display list of users matching regex & filter
712 */
713 $this->displayUsers = array();
714 $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))(!(uid=*$))(|(uid=".$regex.")(sn=".$regex.")(givenName=".$regex.")))";
716 /* Search in current tree or within subtrees depending on the checkbox from filter section */
717 if($gufilter['SubSearchGroup']){
718 $flag = GL_SIZELIMIT | GL_SUBSEARCH;
719 $base = $gufilter['dselect'];
720 }else{
721 $flag = GL_SIZELIMIT ;
722 $base = get_people_ou().$gufilter['dselect'];
723 }
724 $i = 0;
727 $res = get_list($filter,"users",$base,array("dn", "uid", "sn", "givenName"),$flag);
729 /* Fetch all users and skip already used users */
730 foreach($res as $attrs){
731 if(in_array($attrs['uid'][0], $this->memberUid)) {
732 continue;
733 }
734 $i ++;
735 if($i > $MaxUser) {
736 break;
737 }
738 $this->dnMapping[$attrs['uid'][0]]= $attrs["dn"];
739 $this->allusers[$attrs['uid'][0]] = $this->createResultName($attrs);
740 $this->displayUsers[$attrs['uid'][0]] = $this->createResultName($attrs);
741 }
743 /* If more than max users are found, display a message to warn the user */
744 if($i == $MaxUser && !$silent){
745 msg_dialog::display(_("Configuration error"), sprintf(_("Search returned too many results. Not displaying more than %s entries!"), $MaxUser), ERROR_DIALOG);
746 }
748 /* Sort lists */
749 natcasesort($this->members);
750 reset($this->members);
751 natcasesort ($this->displayUsers);
752 reset ($this->displayUsers);
753 }
756 /* Create display name, this was used so often that it is excluded into a seperate function */
757 function createResultName($attrs)
758 {
759 if (isset($attrs["givenName"][0]) && isset($attrs["sn"][0])){
760 $ret = $attrs["sn"][0].", ".$attrs["givenName"][0]." [".$attrs["uid"][0]."]";
761 } else {
762 $ret= $attrs['uid'][0];
763 }
764 return($ret);
765 }
768 function remove_from_parent()
769 {
770 plugin::remove_from_parent();
772 $ldap= $this->config->get_ldap_link();
773 $ldap->rmdir($this->dn);
774 if (!$ldap->success()){
775 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
776 }
778 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
780 /* Delete references to object groups */
781 $ldap->cd ($this->config->current['BASE']);
782 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
783 while ($ldap->fetch()){
784 $og= new ogroup($this->config, $ldap->getDN());
785 unset($og->member[$this->dn]);
786 $og->save ();
787 }
789 /* Remove ACL dependencies too,
790 */
791 $ldap = $this->config->get_ldap_link();
792 $ldap->cd($this->config->current['BASE']);
793 $ldap->search("(&(objectClass=gosaAcl)(gosaAclEntry=*".base64_encode($this->dn)."*))",array("gosaAclEntry","dn"));
794 while($attrs = $ldap->fetch()){
795 $acl = new acl($this->config,$this->parent,$attrs['dn']);
796 foreach($acl->gosaAclEntry as $id => $entry){
797 foreach($entry['members'] as $m_id => $member){
798 if($m_id == "G:".$this->dn || $m_id == "U:".$this->dn){
799 unset($acl->gosaAclEntry[$id]['members'][$m_id]);
800 gosa_log("modify","groups/acl",$attrs['dn'],array(),sprintf("Removed acl for %s on object %s.",$this->dn,$attrs['dn']));
801 }
802 }
803 }
804 $acl->save();
805 }
807 /* Remove ACL dependencies too,
808 */
809 $tmp = new acl($this->config,$this->parent,$this->dn);
810 $tmp->remove_acl();
812 /* Send signal to the world that we've done */
813 $this->handle_post_events("remove");
814 }
817 /* Save data to object */
818 function save_object()
819 {
820 /* Save additional values for possible next step */
821 if (isset($_POST['groupedit'])){
823 /* Create a base backup and reset the
824 base directly after calling plugin::save_object();
825 Base will be set seperatly a few lines below */
826 $base_tmp = $this->base;
827 plugin::save_object();
828 $this->base = $base_tmp;
830 $this->force_gid= 0;
832 /* Only reset sambagroup flag if we are able to write this flag */
833 if($this->acl_is_writeable("sambaGroupType")){
834 $this->smbgroup = 0;
835 }
837 /* Get base selection */
838 if(isset($_POST['base'])){
839 $tmp = $this->get_allowed_bases();
840 if(isset($tmp[$_POST['base']])){
841 $this->base = $_POST['base'];
842 }
843 }
845 foreach (array(
846 "force_gid" => "gidNumber",
847 "smbgroup" => "sambaGroupType") as $val => $aclname) {
848 if ($this->acl_is_writeable($aclname) && isset($_POST["$val"])){
849 $this->$val= $_POST["$val"];
850 }
851 }
853 /* Save sambaDomain attribute */
854 if ($this->acl_is_writeable("sambaDomainName") && isset ($_POST['sambaDomainName'])){
855 $this->sambaDomainName= $_POST['sambaDomainName'];
856 $this->groupType= $_POST['groupType'];
857 }
859 /* Save fon attribute */
860 if ($this->acl_is_writeable("fonGroup")){
861 if (isset ($_POST['fon_group'])){
862 $this->fon_group= TRUE;
863 } else {
864 $this->fon_group= FALSE;
865 }
866 }
867 if ($this->acl_is_writeable("nagiosGroup")){
868 if (isset ($_POST['nagios_group'])){
869 $this->nagios_group= TRUE;
870 } else {
871 $this->nagios_group= FALSE;
872 }
873 }
874 }
876 /* Trust mode - special handling */
877 if($this->acl_is_writeable("trustModel")){
878 if (isset($_POST['trustmode'])){
879 $saved= $this->trustModel;
880 if ($_POST['trustmode'] == "1"){
881 $this->trustModel= "fullaccess";
882 } elseif ($_POST['trustmode'] == "2"){
883 $this->trustModel= "byhost";
884 } else {
885 $this->trustModel= "";
886 }
887 if ($this->trustModel != $saved){
888 $this->is_modified= TRUE;
889 }
890 }
891 }
893 }
896 /* Save to LDAP */
897 function save()
898 {
900 /* ID handling */
901 if ($this->force_gid == 0){
902 if ($this->saved_gidNumber != ""){
903 $this->gidNumber= $this->saved_gidNumber;
904 } else {
905 /* Calculate new, lock uids */
906 $wait= 10;
907 while (get_lock("gidnumber") != ""){
908 sleep (1);
910 /* timed out? */
911 if ($wait-- == 0){
912 break;
913 }
914 }
915 add_lock ("gidnumber", "gosa");
916 $this->gidNumber= get_next_id("gidNumber", $this->dn);
917 }
918 }
920 plugin::save();
922 /* Trust accounts */
923 $objectclasses= array();
924 foreach ($this->attrs['objectClass'] as $key => $class){
925 if (preg_match('/trustAccount/i', $class)){
926 continue;
927 }
928 $objectclasses[]= $this->attrs['objectClass'][$key];
929 }
930 $this->attrs['objectClass']= $objectclasses;
931 if ($this->trustModel != ""){
932 $this->attrs['objectClass'][]= "trustAccount";
933 $this->attrs['trustModel']= $this->trustModel;
934 $this->attrs['accessTo']= array();
935 if ($this->trustModel == "byhost"){
936 foreach ($this->accessTo as $host){
937 $this->attrs['accessTo'][]= $host;
938 }
939 }
940 } else {
941 if ($this->was_trust_account){
942 $this->attrs['accessTo']= array();
943 $this->attrs['trustModel']= array();
944 }
945 }
949 /* Remove objectClass for samba/phone support */
950 $tmp= array();
951 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
952 if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
953 $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
954 $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
955 $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
956 $tmp[]= $this->attrs['objectClass'][$i];
957 }
958 }
959 $this->attrs['objectClass']= $tmp;
960 $ldap= $this->config->get_ldap_link();
962 /* Add samba group functionality */
963 if ($this->smbgroup){
965 /* Fixed undefined index ...
966 */
967 $this->SID = $this->ridBase = "";
968 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
969 $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
970 }else{
971 msg_dialog::display(_("Error"), sprintf(_("Cannot find any SID for '%s'!"), $this->sambaDomainName), ERROR_DIALOG);
972 }
973 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
974 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
975 }else{
976 msg_dialog::display(_("Error"), sprintf(_("Cannot find any RIDBASE for '%s'!"), $this->sambaDomainName), ERROR_DIALOG);
977 }
979 $this->attrs['objectClass'][]= 'sambaGroupMapping';
980 $this->attrs['sambaGroupType']= "2";
982 /* Check if we need to create a special entry */
983 if ($this->groupType == 0){
985 if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
986 $gidNumber= $this->gidNumber;
987 while(TRUE){
988 $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
989 $ldap->cd($this->config->current['BASE']);
990 $ldap->search("(sambaSID=$sid)",array("sambaSID"));
991 if ($ldap->count() == 0){
992 break;
993 }
994 $gidNumber++;
995 }
996 $this->attrs['sambaSID']= $sid;
997 $this->sambaSID= $sid;
998 }
1000 } else {
1001 $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
1002 }
1004 /* User wants me to fake the idMappings? This is useful for
1005 making winbind resolve the group names in a reasonable amount
1006 of time in combination with larger databases. */
1007 if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1008 $this->attrs['objectClass'][]= "sambaIdmapEntry";
1009 }
1011 }
1013 /* Add phone functionality */
1014 if ($this->fon_group){
1015 $this->attrs['objectClass'][]= "goFonPickupGroup";
1016 }
1018 /* Add nagios functionality */
1019 if ($this->nagios_group){
1020 $this->attrs['objectClass'][]= "nagiosContactGroup";
1021 }
1023 /* Take members array */
1024 if (count ($this->memberUid)){
1025 $this->attrs['memberUid']= array_values(array_unique($this->memberUid));
1026 }
1028 /* New accounts need proper 'dn', propagate it to remaining objects */
1029 if ($this->dn == 'new'){
1030 $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1031 }
1033 /* Add member dn's for RFC2307bis Support */
1034 if ($this->rfc2307bis){
1035 $this->attrs['member'] = array();
1036 if (count($this->memberUid)){
1037 foreach($this->attrs['memberUid'] as $uid) {
1039 if(isset($this->dnMapping[$uid])){
1040 $this->attrs['member'][]= $this->dnMapping[$uid];
1041 }
1042 }
1043 } else {
1044 $this->attrs['member'][]= $this->dn;
1045 }
1046 }
1048 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1049 new entries. So do a check first... */
1050 $ldap->cat ($this->dn, array('dn'));
1051 if ($ldap->fetch()){
1052 /* Modify needs array() to remove values :-( */
1053 if (!count ($this->memberUid)){
1054 $this->attrs['memberUid']= array();
1055 }
1056 if (!$this->smbgroup){
1057 $this->attrs['sambaGroupType']= array();
1058 $this->attrs['sambaSID']= array();
1059 }
1061 $mode= "modify";
1062 } else {
1063 $mode= "add";
1064 $ldap->cd($this->config->current['BASE']);
1065 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1066 }
1069 /* Check generated gidNumber, it may be used by another group.
1070 */
1071 if($this->gidNumber != ""){
1072 $ldap->cd($this->config->current['BASE']);
1073 $ldap->search("(&(!(cn=".$this->orig_cn."))(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))",array("cn"));
1074 if($ldap->count()){
1075 $cns = "";
1076 while($attrs = $ldap->fetch()){
1077 $cns .= $attrs['cn'][0].", ";
1078 }
1079 $cns = rtrim($cns,", ");
1080 msg_dialog::display(_("Warning"),sprintf(_("The gidNumber '%s' is already in use by %s!"),$this->gidNumber,$cns) , WARNING_DIALOG );
1081 }
1082 }
1084 /* Write back to ldap */
1085 $ldap->cd($this->dn);
1086 $this->cleanup();
1087 $ldap->$mode($this->attrs);
1089 /* Remove ACL dependencies too,
1090 */
1091 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1092 $tmp = new acl($this->config,$this->parent,$this->dn);
1093 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1094 }
1096 if($this->initially_was_account){
1097 new log("modify","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1098 }else{
1099 new log("create","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1100 }
1102 $ret= 0;
1103 if (!$ldap->success()){
1104 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1105 $ret= 1;
1106 }
1108 /* Remove uid lock */
1109 del_lock ("gidnumber");
1111 /* Post that we've done*/
1112 $this->handle_post_events($mode);
1114 return ($ret);
1115 }
1117 function check()
1118 {
1119 /* Call common method to give check the hook */
1120 $message= plugin::check();
1122 /* Permissions for that base? */
1123 if ($this->base != ""){
1124 $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1125 } else {
1126 $new_dn= $this->dn;
1127 }
1129 /* must: cn */
1130 if ($this->cn == "" && $this->acl_is_writeable("cn")){
1131 $message[]= msgPool::required(_("Name"));
1132 }
1134 /* Check for valid input */
1135 if (!tests::is_uid($this->cn)){
1136 if (strict_uid_mode()){
1137 $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/");
1138 } else {
1139 $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/i");
1140 }
1141 }
1143 if($this->allowGroupsWithSameNameInOtherSubtrees == true){
1145 /* Check for used 'cn' */
1146 $ldap= $this->config->get_ldap_link();
1147 if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
1148 $ldap->cd(get_groups_ou().$this->base);
1149 $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
1150 if ($ldap->count() != 0){
1151 $message[]= msgPool::duplicated(_("Name"));
1152 }
1153 }
1155 }else{
1157 /* Check for used 'cn' */
1158 $ldap= $this->config->get_ldap_link();
1159 $ldap->cd($this->config->current['BASE']);
1160 $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
1161 if ($ldap->count() != 0){
1163 /* New entry? */
1164 if ($this->dn == 'new'){
1165 $message[]= msgPool::duplicated(_("Name"));
1166 }
1168 /* Moved? */
1169 elseif ($new_dn != $this->orig_dn){
1170 $ldap->fetch();
1171 if ($ldap->getDN() != $this->orig_dn){
1172 $message[]= msgPool::duplicated(_("Name"));
1173 }
1174 }
1175 }
1176 }
1178 /* Check ID */
1179 if ($this->force_gid == "1"){
1180 if (!tests::is_id($this->gidNumber)){
1181 $message[]= msgPool::invalid(_("GID"), $this->gidNumber, "/[0-9]/");
1182 } else {
1183 if ($this->gidNumber < $this->config->get_cfg_value("minId")){
1184 $message[]= msgPool::toosmall(_("GID"), $this->config->get_cfg_value("minId"));
1185 }
1187 }
1188 }
1190 /* Check if we are allowed to create or move this object
1191 */
1192 if(!$this->orig_dn == "new" ||
1193 $this->orig_base != $this->base ||
1194 $this->cn != $this->orig_cn){
1196 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1197 $message[] = msgPool::permCreate();
1198 }elseif($this->orig_dn != "new" && !$this->acl_is_moveable($this->base)){
1199 $message[] = msgPool::permMove();
1200 }
1201 }
1203 return ($message);
1204 }
1207 function getCopyDialog()
1208 {
1209 $vars = array("cn");
1211 if($this ->force_gid){
1212 $used = " checked ";
1213 $dis = "";
1214 }else{
1215 $used = "";
1216 $dis = " disabled ";
1217 }
1219 $smarty = get_smarty();
1220 $smarty->assign("used",$used);
1221 $smarty->assign("dis" ,$dis);
1222 $smarty->assign("cn" ,$this->cn);
1223 $smarty->assign("gidNumber",$this->gidNumber);
1224 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
1225 $ret = array();
1226 $ret['string'] = $str;
1227 $ret['status'] = "";
1228 return($ret);
1229 }
1231 function saveCopyDialog()
1232 {
1233 if(isset($_POST['cn'])){
1234 $this->cn = $_POST['cn'];
1235 }
1236 if(isset($_POST['force_gid'])){
1237 $this->force_gid = 1;
1238 $this->gidNumber= $_POST['gidNumber'];
1239 }else{
1240 $this->force_gid = 0;
1241 $this->gidNumber = false;
1242 }
1243 }
1246 /* Return plugin informations for acl handling */
1247 static function plInfo()
1248 {
1249 return (array(
1250 "plShortName" => _("Generic"),
1251 "plDescription" => _("Generic group settings"),
1252 "plSelfModify" => FALSE,
1253 "plDepends" => array(),
1254 "plPriority" => 0,
1255 "plSection" => array("administration"),
1256 "plCategory" => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
1258 "plProvidedAcls" => array(
1259 "cn" => _("Name"),
1260 "description" => _("Description"),
1261 "base" => _("Base"),
1263 "gidNumber" => _("GID"),
1265 "sambaGroupType" => _("Samba group type"),
1266 "sambaDomainName" => _("Samba domain name"),
1267 "trustModel" => _("System trust"),
1268 "fonGroup" => _("Phone pickup group"),
1269 "nagiosGroup" => _("Nagios group"),
1271 "memberUid" => _("Group member"))
1272 ));
1273 }
1276 function multiple_save_object()
1277 {
1278 if(isset($_POST['group_mulitple_edit'])){
1280 /* Create a base backup and reset the
1281 base directly after calling plugin::save_object();
1282 Base will be set seperatly a few lines below */
1283 $base_tmp = $this->base;
1284 plugin::multiple_save_object();
1285 plugin::save_object();
1286 $this->base = $base_tmp;
1288 foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group","trustmode") as $attr){
1289 if(isset($_POST['use_'.$attr])){
1290 $this->multi_boxes[] = $attr;
1291 }
1292 }
1294 /* Get base selection */
1295 if(isset($_POST['base'])){
1296 $tmp = $this->get_allowed_bases();
1297 if(isset($tmp[$_POST['base']])){
1298 $this->base = $_POST['base'];
1299 }
1300 }
1302 foreach (array( "smbgroup" => "sambaGroupType" ,"nagios_group" => "nagios_group") as $val => $aclname) {
1303 if ($this->acl_is_writeable($aclname)){
1304 if(isset($_POST["$val"])){
1305 $this->$val= TRUE;
1306 }else{
1307 $this->$val= FALSE;
1308 }
1309 }
1310 }
1312 /* Save sambaDomain attribute */
1313 if ($this->acl_is_writeable("sambaDomainName") && isset ($_POST['sambaDomainName'])){
1314 $this->sambaDomainName= $_POST['sambaDomainName'];
1315 $this->groupType= $_POST['groupType'];
1316 }
1318 /* Trust mode - special handling */
1319 if($this->acl_is_writeable("trustModel")){
1320 if (isset($_POST['trustmode'])){
1321 $saved= $this->trustModel;
1322 if ($_POST['trustmode'] == "1"){
1323 $this->trustModel= "fullaccess";
1324 } elseif ($_POST['trustmode'] == "2"){
1325 $this->trustModel= "byhost";
1326 } else {
1327 $this->trustModel= "";
1328 }
1329 if ($this->trustModel != $saved){
1330 $this->is_modified= TRUE;
1331 }
1332 }
1333 }
1335 /* Save fon attribute */
1336 if ($this->acl_is_writeable("fonGroup")){
1337 if (isset ($_POST['fon_group'])){
1338 $this->fon_group= TRUE;
1339 } else {
1340 $this->fon_group= FALSE;
1341 }
1342 }
1343 }
1344 }
1347 function get_multi_edit_values()
1348 {
1349 $ret = plugin::get_multi_edit_values();
1351 foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group") as $attr){
1352 if(in_array($attr,$this->multi_boxes)){
1353 $ret[$attr] = $this->$attr;
1354 }
1355 }
1357 if(in_array("trustmode",$this->multi_boxes)){
1358 $ret['trustModel'] = $this->trustModel;
1359 $ret['accessTo'] = $this->accessTo;
1360 }
1362 $ret['memberUid'] = $this->memberUid;
1363 $ret['memberUid_used_by_some'] = $this->memberUid_used_by_some;
1364 return($ret);
1365 }
1367 function multiple_execute()
1368 {
1369 return($this->execute());
1370 }
1373 /* Initialize plugin with given atribute arrays
1374 */
1375 function init_multiple_support($attrs,$all)
1376 {
1377 plugin::init_multiple_support($attrs,$all);
1379 $this->memberUid = array();
1380 $this->memberUid_used_by_some = array();
1381 if (isset($attrs['memberUid'])){
1382 for ($i= 0; $i<$attrs['memberUid']['count']; $i++){
1383 $this->memberUid[$attrs['memberUid'][$i]]= $attrs['memberUid'][$i];
1384 }
1385 ksort($this->memberUid);
1386 }
1388 if (isset($all['memberUid'])){
1389 for ($i= 0; $i<$all['memberUid']['count']; $i++){
1390 if(!in_array($all['memberUid'][$i],$this->memberUid)){
1391 $this->memberUid_used_by_some[$all['memberUid'][$i]]= $all['memberUid'][$i];
1392 }
1393 }
1394 ksort($this->memberUid_used_by_some);
1395 }
1396 }
1399 function PrepareForCopyPaste($source)
1400 {
1401 plugin::PrepareForCopyPaste($source);
1403 $this->memberUid = array();
1404 if(isset($source['memberUid'])){
1405 for($i = 0 ; $i < $source['memberUid']['count']; $i ++){
1406 $this->memberUid[] = $source['memberUid'][$i];
1407 }
1408 }
1409 $this->accessTo = array();
1410 if (isset($source['accessTo'])){
1411 for ($i= 0; $i<$source['accessTo']['count']; $i++){
1412 $tmp= $source['accessTo'][$i];
1413 $this->accessTo[$tmp]= $tmp;
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 }
1437 }
1438 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1439 ?>