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(), '/')."/i","",$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 acl::remove_acl_for($this->dn);
810 /* Send signal to the world that we've done */
811 $this->handle_post_events("remove");
812 }
815 /* Save data to object */
816 function save_object()
817 {
818 /* Save additional values for possible next step */
819 if (isset($_POST['groupedit'])){
821 /* Create a base backup and reset the
822 base directly after calling plugin::save_object();
823 Base will be set seperatly a few lines below */
824 $base_tmp = $this->base;
825 plugin::save_object();
826 $this->base = $base_tmp;
828 $this->force_gid= 0;
830 /* Only reset sambagroup flag if we are able to write this flag */
831 if($this->acl_is_writeable("sambaGroupType")){
832 $this->smbgroup = 0;
833 }
835 /* Get base selection */
836 if(isset($_POST['base'])){
837 $tmp = $this->get_allowed_bases();
838 if(isset($tmp[$_POST['base']])){
839 $this->base = $_POST['base'];
840 }
841 }
843 foreach (array(
844 "force_gid" => "gidNumber",
845 "smbgroup" => "sambaGroupType") as $val => $aclname) {
846 if ($this->acl_is_writeable($aclname) && isset($_POST["$val"])){
847 $this->$val= $_POST["$val"];
848 }
849 }
851 /* Save sambaDomain attribute */
852 if ($this->acl_is_writeable("sambaDomainName") && isset ($_POST['sambaDomainName'])){
853 $this->sambaDomainName= $_POST['sambaDomainName'];
854 $this->groupType= $_POST['groupType'];
855 }
857 /* Save fon attribute */
858 if ($this->acl_is_writeable("fonGroup")){
859 if (isset ($_POST['fon_group'])){
860 $this->fon_group= TRUE;
861 } else {
862 $this->fon_group= FALSE;
863 }
864 }
865 if ($this->acl_is_writeable("nagiosGroup")){
866 if (isset ($_POST['nagios_group'])){
867 $this->nagios_group= TRUE;
868 } else {
869 $this->nagios_group= FALSE;
870 }
871 }
872 }
874 /* Trust mode - special handling */
875 if($this->acl_is_writeable("trustModel")){
876 if (isset($_POST['trustmode'])){
877 $saved= $this->trustModel;
878 if ($_POST['trustmode'] == "1"){
879 $this->trustModel= "fullaccess";
880 } elseif ($_POST['trustmode'] == "2"){
881 $this->trustModel= "byhost";
882 } else {
883 $this->trustModel= "";
884 }
885 if ($this->trustModel != $saved){
886 $this->is_modified= TRUE;
887 }
888 }
889 }
891 }
894 /* Save to LDAP */
895 function save()
896 {
898 /* ID handling */
899 if ($this->force_gid == 0){
900 if ($this->saved_gidNumber != ""){
901 $this->gidNumber= $this->saved_gidNumber;
902 } else {
903 /* Calculate new, lock uids */
904 $wait= 10;
905 while (get_lock("gidnumber") != ""){
906 sleep (1);
908 /* timed out? */
909 if ($wait-- == 0){
910 break;
911 }
912 }
913 add_lock ("gidnumber", "gosa");
914 $this->gidNumber= get_next_id("gidNumber", $this->dn);
915 }
916 }
918 plugin::save();
920 /* Trust accounts */
921 $objectclasses= array();
922 foreach ($this->attrs['objectClass'] as $key => $class){
923 if (preg_match('/trustAccount/i', $class)){
924 continue;
925 }
926 $objectclasses[]= $this->attrs['objectClass'][$key];
927 }
928 $this->attrs['objectClass']= $objectclasses;
929 if ($this->trustModel != ""){
930 $this->attrs['objectClass'][]= "trustAccount";
931 $this->attrs['trustModel']= $this->trustModel;
932 $this->attrs['accessTo']= array();
933 if ($this->trustModel == "byhost"){
934 foreach ($this->accessTo as $host){
935 $this->attrs['accessTo'][]= $host;
936 }
937 }
938 } else {
939 if ($this->was_trust_account){
940 $this->attrs['accessTo']= array();
941 $this->attrs['trustModel']= array();
942 }
943 }
947 /* Remove objectClass for samba/phone support */
948 $tmp= array();
949 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
950 if ($this->attrs['objectClass'][$i] != 'sambaGroupMapping' &&
951 $this->attrs['objectClass'][$i] != 'sambaIdmapEntry' &&
952 $this->attrs['objectClass'][$i] != 'goFonPickupGroup' &&
953 $this->attrs['objectClass'][$i] != 'nagiosContactGroup'){
954 $tmp[]= $this->attrs['objectClass'][$i];
955 }
956 }
957 $this->attrs['objectClass']= $tmp;
958 $ldap= $this->config->get_ldap_link();
960 /* Add samba group functionality */
961 if ($this->smbgroup){
963 /* Fixed undefined index ...
964 */
965 $this->SID = $this->ridBase = "";
966 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
967 $this->SID = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
968 }else{
969 msg_dialog::display(_("Error"), sprintf(_("Cannot find any SID for '%s'!"), $this->sambaDomainName), ERROR_DIALOG);
970 }
971 if(isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'])){
972 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
973 }else{
974 msg_dialog::display(_("Error"), sprintf(_("Cannot find any RIDBASE for '%s'!"), $this->sambaDomainName), ERROR_DIALOG);
975 }
977 $this->attrs['objectClass'][]= 'sambaGroupMapping';
978 $this->attrs['sambaGroupType']= "2";
980 /* Check if we need to create a special entry */
981 if ($this->groupType == 0){
983 if ($this->sambaSID == "" || $this->oldgroupType != $this->groupType){
984 $gidNumber= $this->gidNumber;
985 while(TRUE){
986 $sid= $this->SID."-".($gidNumber*2 + $this->ridBase+1);
987 $ldap->cd($this->config->current['BASE']);
988 $ldap->search("(sambaSID=$sid)",array("sambaSID"));
989 if ($ldap->count() == 0){
990 break;
991 }
992 $gidNumber++;
993 }
994 $this->attrs['sambaSID']= $sid;
995 $this->sambaSID= $sid;
996 }
998 } else {
999 $this->attrs['sambaSID']=$this->SID."-".$this->groupType;
1000 }
1002 /* User wants me to fake the idMappings? This is useful for
1003 making winbind resolve the group names in a reasonable amount
1004 of time in combination with larger databases. */
1005 if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1006 $this->attrs['objectClass'][]= "sambaIdmapEntry";
1007 }
1009 }
1011 /* Add phone functionality */
1012 if ($this->fon_group){
1013 $this->attrs['objectClass'][]= "goFonPickupGroup";
1014 }
1016 /* Add nagios functionality */
1017 if ($this->nagios_group){
1018 $this->attrs['objectClass'][]= "nagiosContactGroup";
1019 }
1021 /* Take members array */
1022 if (count ($this->memberUid)){
1023 $this->attrs['memberUid']= array_values(array_unique($this->memberUid));
1024 }
1026 /* New accounts need proper 'dn', propagate it to remaining objects */
1027 if ($this->dn == 'new'){
1028 $this->dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1029 }
1031 /* Add member dn's for RFC2307bis Support */
1032 if ($this->rfc2307bis){
1033 $this->attrs['member'] = array();
1034 if (count($this->memberUid)){
1035 foreach($this->attrs['memberUid'] as $uid) {
1037 if(isset($this->dnMapping[$uid])){
1038 $this->attrs['member'][]= $this->dnMapping[$uid];
1039 }
1040 }
1041 } else {
1042 $this->attrs['member'][]= $this->dn;
1043 }
1044 }
1046 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
1047 new entries. So do a check first... */
1048 $ldap->cat ($this->dn, array('dn'));
1049 if ($ldap->fetch()){
1050 /* Modify needs array() to remove values :-( */
1051 if (!count ($this->memberUid)){
1052 $this->attrs['memberUid']= array();
1053 }
1054 if (!$this->smbgroup){
1055 $this->attrs['sambaGroupType']= array();
1056 $this->attrs['sambaSID']= array();
1057 }
1059 $mode= "modify";
1060 } else {
1061 $mode= "add";
1062 $ldap->cd($this->config->current['BASE']);
1063 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1064 }
1067 /* Check generated gidNumber, it may be used by another group.
1068 */
1069 if($this->gidNumber != ""){
1070 $ldap->cd($this->config->current['BASE']);
1071 $ldap->search("(&(!(cn=".$this->orig_cn."))(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))",array("cn"));
1072 if($ldap->count()){
1073 $cns = "";
1074 while($attrs = $ldap->fetch()){
1075 $cns .= $attrs['cn'][0].", ";
1076 }
1077 $cns = rtrim($cns,", ");
1078 msg_dialog::display(_("Warning"),sprintf(_("The gidNumber '%s' is already in use by %s!"),$this->gidNumber,$cns) , WARNING_DIALOG );
1079 }
1080 }
1082 /* Write back to ldap */
1083 $ldap->cd($this->dn);
1084 $this->cleanup();
1085 $ldap->$mode($this->attrs);
1087 /* Remove ACL dependencies too,
1088 */
1089 if($this->dn != $this->orig_dn && $this->orig_dn != "new"){
1090 $tmp = new acl($this->config,$this->parent,$this->dn);
1091 $tmp->update_acl_membership($this->orig_dn,$this->dn);
1092 }
1094 if($this->initially_was_account){
1095 new log("modify","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1096 }else{
1097 new log("create","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1098 }
1100 $ret= 0;
1101 if (!$ldap->success()){
1102 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1103 $ret= 1;
1104 }
1106 /* Remove uid lock */
1107 del_lock ("gidnumber");
1109 /* Post that we've done*/
1110 $this->handle_post_events($mode);
1112 return ($ret);
1113 }
1115 function check()
1116 {
1117 /* Call common method to give check the hook */
1118 $message= plugin::check();
1120 /* Permissions for that base? */
1121 if ($this->base != ""){
1122 $new_dn= 'cn='.$this->cn.','.get_groups_ou().$this->base;
1123 } else {
1124 $new_dn= $this->dn;
1125 }
1127 /* must: cn */
1128 if ($this->cn == "" && $this->acl_is_writeable("cn")){
1129 $message[]= msgPool::required(_("Name"));
1130 }
1132 /* Check for valid input */
1133 if (!tests::is_uid($this->cn)){
1134 if (strict_uid_mode()){
1135 $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/");
1136 } else {
1137 $message[]= msgPool::invalid(_("Name"), $this->cn, "/[a-z0-9_-]/i");
1138 }
1139 }
1141 if($this->allowGroupsWithSameNameInOtherSubtrees == true){
1143 /* Check for used 'cn' */
1144 $ldap= $this->config->get_ldap_link();
1145 if(($this->cn != $this->orig_cn) || ($this->orig_dn == "new")){
1146 $ldap->cd(get_groups_ou().$this->base);
1147 $ldap->ls("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",get_groups_ou().$this->base,array("cn"));
1148 if ($ldap->count() != 0){
1149 $message[]= msgPool::duplicated(_("Name"));
1150 }
1151 }
1153 }else{
1155 /* Check for used 'cn' */
1156 $ldap= $this->config->get_ldap_link();
1157 $ldap->cd($this->config->current['BASE']);
1158 $ldap->search("(&(|(objectClass=gosaGroupOfNames)(objectClass=posixGroup))(cn=$this->cn))",array("cn"));
1159 if ($ldap->count() != 0){
1161 /* New entry? */
1162 if ($this->dn == 'new'){
1163 $message[]= msgPool::duplicated(_("Name"));
1164 }
1166 /* Moved? */
1167 elseif ($new_dn != $this->orig_dn){
1168 $ldap->fetch();
1169 if ($ldap->getDN() != $this->orig_dn){
1170 $message[]= msgPool::duplicated(_("Name"));
1171 }
1172 }
1173 }
1174 }
1176 /* Check ID */
1177 if ($this->force_gid == "1"){
1178 if (!tests::is_id($this->gidNumber)){
1179 $message[]= msgPool::invalid(_("GID"), $this->gidNumber, "/[0-9]/");
1180 } else {
1181 if ($this->gidNumber < $this->config->get_cfg_value("minId")){
1182 $message[]= msgPool::toosmall(_("GID"), $this->config->get_cfg_value("minId"));
1183 }
1185 }
1186 }
1188 /* Check if we are allowed to create or move this object
1189 */
1190 if(!$this->orig_dn == "new" ||
1191 $this->orig_base != $this->base ||
1192 $this->cn != $this->orig_cn){
1194 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
1195 $message[] = msgPool::permCreate();
1196 }elseif($this->orig_dn != "new" && !$this->acl_is_moveable($this->base)){
1197 $message[] = msgPool::permMove();
1198 }
1199 }
1201 return ($message);
1202 }
1205 function getCopyDialog()
1206 {
1207 $vars = array("cn");
1209 if($this ->force_gid){
1210 $used = " checked ";
1211 $dis = "";
1212 }else{
1213 $used = "";
1214 $dis = " disabled ";
1215 }
1217 $smarty = get_smarty();
1218 $smarty->assign("used",$used);
1219 $smarty->assign("dis" ,$dis);
1220 $smarty->assign("cn" ,$this->cn);
1221 $smarty->assign("gidNumber",$this->gidNumber);
1222 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
1223 $ret = array();
1224 $ret['string'] = $str;
1225 $ret['status'] = "";
1226 return($ret);
1227 }
1229 function saveCopyDialog()
1230 {
1231 if(isset($_POST['cn'])){
1232 $this->cn = $_POST['cn'];
1233 }
1234 if(isset($_POST['force_gid'])){
1235 $this->force_gid = 1;
1236 $this->gidNumber= $_POST['gidNumber'];
1237 }else{
1238 $this->force_gid = 0;
1239 $this->gidNumber = false;
1240 }
1241 }
1244 /* Return plugin informations for acl handling */
1245 static function plInfo()
1246 {
1247 return (array(
1248 "plShortName" => _("Generic"),
1249 "plDescription" => _("Generic group settings"),
1250 "plSelfModify" => FALSE,
1251 "plDepends" => array(),
1252 "plPriority" => 0,
1253 "plSection" => array("administration"),
1254 "plCategory" => array("groups" => array("objectClass" => "posixGroup", "description" => _("Groups"))),
1256 "plProvidedAcls" => array(
1257 "cn" => _("Name"),
1258 "description" => _("Description"),
1259 "base" => _("Base"),
1261 "gidNumber" => _("GID"),
1263 "sambaGroupType" => _("Samba group type"),
1264 "sambaDomainName" => _("Samba domain name"),
1265 "trustModel" => _("System trust"),
1266 "fonGroup" => _("Phone pickup group"),
1267 "nagiosGroup" => _("Nagios group"),
1269 "memberUid" => _("Group member"))
1270 ));
1271 }
1274 function multiple_save_object()
1275 {
1276 if(isset($_POST['group_mulitple_edit'])){
1278 /* Create a base backup and reset the
1279 base directly after calling plugin::save_object();
1280 Base will be set seperatly a few lines below */
1281 $base_tmp = $this->base;
1282 plugin::multiple_save_object();
1283 plugin::save_object();
1284 $this->base = $base_tmp;
1286 foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group","trustmode") as $attr){
1287 if(isset($_POST['use_'.$attr])){
1288 $this->multi_boxes[] = $attr;
1289 }
1290 }
1292 /* Get base selection */
1293 if(isset($_POST['base'])){
1294 $tmp = $this->get_allowed_bases();
1295 if(isset($tmp[$_POST['base']])){
1296 $this->base = $_POST['base'];
1297 }
1298 }
1300 foreach (array( "smbgroup" => "sambaGroupType" ,"nagios_group" => "nagios_group") as $val => $aclname) {
1301 if ($this->acl_is_writeable($aclname)){
1302 if(isset($_POST["$val"])){
1303 $this->$val= TRUE;
1304 }else{
1305 $this->$val= FALSE;
1306 }
1307 }
1308 }
1310 /* Save sambaDomain attribute */
1311 if ($this->acl_is_writeable("sambaDomainName") && isset ($_POST['sambaDomainName'])){
1312 $this->sambaDomainName= $_POST['sambaDomainName'];
1313 $this->groupType= $_POST['groupType'];
1314 }
1316 /* Trust mode - special handling */
1317 if($this->acl_is_writeable("trustModel")){
1318 if (isset($_POST['trustmode'])){
1319 $saved= $this->trustModel;
1320 if ($_POST['trustmode'] == "1"){
1321 $this->trustModel= "fullaccess";
1322 } elseif ($_POST['trustmode'] == "2"){
1323 $this->trustModel= "byhost";
1324 } else {
1325 $this->trustModel= "";
1326 }
1327 if ($this->trustModel != $saved){
1328 $this->is_modified= TRUE;
1329 }
1330 }
1331 }
1333 /* Save fon attribute */
1334 if ($this->acl_is_writeable("fonGroup")){
1335 if (isset ($_POST['fon_group'])){
1336 $this->fon_group= TRUE;
1337 } else {
1338 $this->fon_group= FALSE;
1339 }
1340 }
1341 }
1342 }
1345 function get_multi_edit_values()
1346 {
1347 $ret = plugin::get_multi_edit_values();
1349 foreach(array("base","smbgroup","groupType","sambaDomainName","fon_group","nagios_group") as $attr){
1350 if(in_array($attr,$this->multi_boxes)){
1351 $ret[$attr] = $this->$attr;
1352 }
1353 }
1355 if(in_array("trustmode",$this->multi_boxes)){
1356 $ret['trustModel'] = $this->trustModel;
1357 $ret['accessTo'] = $this->accessTo;
1358 }
1360 $ret['memberUid'] = $this->memberUid;
1361 $ret['memberUid_used_by_some'] = $this->memberUid_used_by_some;
1362 return($ret);
1363 }
1365 function multiple_execute()
1366 {
1367 return($this->execute());
1368 }
1371 /* Initialize plugin with given atribute arrays
1372 */
1373 function init_multiple_support($attrs,$all)
1374 {
1375 plugin::init_multiple_support($attrs,$all);
1377 $this->memberUid = array();
1378 $this->memberUid_used_by_some = array();
1379 if (isset($attrs['memberUid'])){
1380 for ($i= 0; $i<$attrs['memberUid']['count']; $i++){
1381 $this->memberUid[$attrs['memberUid'][$i]]= $attrs['memberUid'][$i];
1382 }
1383 ksort($this->memberUid);
1384 }
1386 if (isset($all['memberUid'])){
1387 for ($i= 0; $i<$all['memberUid']['count']; $i++){
1388 if(!in_array($all['memberUid'][$i],$this->memberUid)){
1389 $this->memberUid_used_by_some[$all['memberUid'][$i]]= $all['memberUid'][$i];
1390 }
1391 }
1392 ksort($this->memberUid_used_by_some);
1393 }
1394 }
1397 function PrepareForCopyPaste($source)
1398 {
1399 plugin::PrepareForCopyPaste($source);
1401 $this->memberUid = array();
1402 if(isset($source['memberUid'])){
1403 for($i = 0 ; $i < $source['memberUid']['count']; $i ++){
1404 $this->memberUid[] = $source['memberUid'][$i];
1405 }
1406 }
1407 $this->accessTo = array();
1408 if (isset($source['accessTo'])){
1409 for ($i= 0; $i<$source['accessTo']['count']; $i++){
1410 $tmp= $source['accessTo'][$i];
1411 $this->accessTo[$tmp]= $tmp;
1412 }
1413 }
1414 }
1417 function set_multi_edit_values($attrs)
1418 {
1419 $users = array();
1421 /* Update groupMembership, keep optinal group */
1422 foreach($attrs['memberUid_used_by_some'] as $uid){
1423 if(in_array($uid,$this->memberUid)){
1424 $users[$uid] = $uid;
1425 }
1426 }
1428 /* Update groupMembership, add forced groups */
1429 foreach($attrs['memberUid'] as $uid){
1430 $users[$uid] = $uid;
1431 }
1432 plugin::set_multi_edit_values($attrs);
1433 $this->memberUid = $users;
1434 }
1435 }
1436 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1437 ?>