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 ogroup extends plugin
24 {
25 var $typeToClass = array(
26 "Y" => "gosaUserTemplate",
27 "U" => "gosaAccount",
28 "G" => "posixGroup",
29 "A" => "gosaApplication",
30 "D" => "gosaDepartment",
31 "S" => "goServer",
32 "W" => "gotoWorkstation",
33 "O" => "opsiClient",
34 "T" => "gotoTerminal",
35 "F" => "goFonHardware",
36 "P" => "gotoPrinter");
38 var $typeToImage = array(
39 "Y" => "plugins/users/images/select_template.png",
40 "U" => "plugins/users/images/select_user.png",
41 "G" => "plugins/groups/images/select_group.png",
42 "A" => "plugins/ogroups/images/application.png",
43 "D" => "plugins/departments/images/department.png",
44 "S" => "plugins/ogroups/images/server.png",
45 "W" => "plugins/ogroups/images/workstation.png",
46 "O" => "plugins/ogroups/images/winstation.png",
47 "T" => "plugins/ogroups/images/terminal.png",
48 "F" => "plugins/ogroups/images/phone.png",
49 "P" => "plugins/ogroups/images/printer.png",
50 "I" => "images/false.png");
53 /* Variables */
54 var $cn= "";
55 var $description= "";
56 var $base= "";
57 var $gosaGroupObjects= "";
58 var $objects= array();
59 var $objcache= array();
60 var $memberList= array();
61 var $member= array();
62 var $orig_dn= "";
63 var $orig_cn= "";
64 var $orig_base= "";
65 var $objectSelect= FALSE;
66 var $view_logged = FALSE;
68 var $copyMembers = TRUE;
70 var $baseSelector;
72 /* Already assigned Workstations. Will be hidden in selection.
73 */
74 var $used_workstations = array();
76 /* attribute list for save action */
77 var $attributes= array("cn", "description", "gosaGroupObjects","member");
78 var $objectclasses= array("top", "gosaGroupOfNames");
80 function ogroup (&$config, $dn= NULL)
81 {
82 plugin::plugin ($config, $dn);
84 $this->trustModeDialog = new trustModeDialog($this->config, $this->dn,NULL);
85 $this->trustModeDialog->setAcl('ogroups/ogroup');
87 $this->orig_dn= $dn;
89 $this->member = array();
91 /* Load member objects */
92 if (isset($this->attrs['member'])){
93 foreach ($this->attrs['member'] as $key => $value){
94 if ("$key" != "count"){
95 $value= @LDAP::convert($value);
96 $this->member["$value"]= "$value";
97 }
98 }
99 }
100 $this->is_account= TRUE;
102 /* Set base */
103 if ($this->dn == "new"){
104 $ui = get_userinfo();
105 $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn);
106 } else {
107 $this->base= preg_replace("/^[^,]+,".preg_quote(get_ou("group", "ogroupRDN"), '/')."/i","",$this->dn);
108 }
110 /* Detect all workstations, which are already assigned to an object group
111 - Those objects will be hidden in the add object dialog.
112 - Check() will complain if such a system is assigned to this object group.
113 */
114 $base = $this->config->current['BASE'];
115 $res = get_list("(|(objectClass=gotoWorkstation)(objectClass=gotoTerminal))","none" ,
116 $base, array("dn"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
117 $ws_dns = array();
118 foreach($res as $data){
119 $ws_dns[] = $data['dn'];
120 }
121 $res=get_list("(&(member=*)(objectClass=gosaGroupOfNames))","none",
122 $base, array("dn","member", "gosaGroupObjects"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
123 $this->used_workstations = array();
124 foreach($res as $og){
125 if($og['dn'] == $this->dn) continue;
126 $test = array_intersect($ws_dns,LDAP::convert($og['member']));
127 if(($og['gosaGroupObjects'] == "[W]" || $og['gosaGroupObjects'] == "[T]") && count($test)){
128 $this->used_workstations = array_merge($this->used_workstations,$test);
129 }
130 }
132 $this->orig_cn = $this->cn;
133 $this->orig_base = $this->base;
135 /* Get global filter config */
136 if (!session::is_set("sysfilter")){
137 $ui= get_userinfo();
138 $base= get_base_from_people($ui->dn);
139 $sysfilter= array( "depselect" => $base,
140 "regex" => "*");
141 session::set("sysfilter", $sysfilter);
142 }
144 /* Instanciate base selector */
145 $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
146 $this->baseSelector->setSubmitButton(false);
147 $this->baseSelector->setHeight(300);
148 $this->baseSelector->update(true);
150 // Prepare lists
151 $this->memberListing = new sortableListing();
152 $this->memberListing->setDeleteable(true);
153 $this->memberListing->setInstantDelete(true);
154 $this->memberListing->setEditable(false);
155 $this->memberListing->setWidth("100%");
156 $this->memberListing->setHeight("300px");
157 $this->memberListing->setHeader(array("~",_("Name")));
158 $this->memberListing->setColspecs(array('20px','*','20px'));
159 $this->memberListing->setDefaultSortColumn(1);
161 $this->reload();
162 }
164 function AddDelMembership($NewMember = false){
166 if($NewMember){
168 // Ensure that we definitely know the new members attributes.
169 // - Fetch unknown objects here.
170 if(!isset($this->memberList[$NewMember])){
172 $ldap = $this->config->get_ldap_link();
173 $ldap->cd($this->config->current['BASE']);
174 $ldap->cat($NewMember);
175 $attrs = $ldap->fetch();
176 $this->objcache[$NewMember] = $attrs;
177 }
179 /* Add member and force reload */
180 $this->member[$NewMember]= $NewMember;
183 $this->memberList[$NewMember]= $this->objcache[$NewMember];
184 unset ($this->objects[$NewMember]);
185 reset ($this->memberList);
186 $this->reload();
187 }else{
189 // Act on list modifications
190 $this->memberListing->save_object();
191 $action = $this->memberListing->getAction();
192 if($action['action'] == 'delete'){
193 foreach($action['targets'] as $id){
194 $value = $this->memberListing->getKey($id);
195 $this->objects["$value"]= $this->memberList[$value];
196 unset ($this->memberList["$value"]);
197 unset ($this->member["$value"]);
198 }
199 $this->reload();
200 }
203 /* Add objects to group */
204 if (isset($_POST['objectSelect_save']) && $this->objectSelect instanceOf objectSelect){
205 $objects = $this->objectSelect->save();
206 $skipped = FALSE;
207 foreach($objects as $object){
208 $dn = $object['dn'];
210 // Do not add existing members twice!
211 if(isset($this->member["$dn"])){
212 continue;
213 }
215 $tmp = "";
216 foreach($this->memberList as $obj){
217 $tmp .= $obj['type'];
218 }
220 $type = $this->getObjectType($object);
221 $name= $this->getObjectName($object);
223 /* Fill array */
224 if (isset($object["description"][0])){
225 $object= array("text" => "$name [".$object["description"][0]."]", "type" => "$type");
226 } elseif (isset($object["uid"][0])) {
227 $object= array("text" => "$name [".$object["uid"][0]."]", "type" => "$type");
228 } else {
229 $object= array("text" => "$name", "type" => "$type");
230 }
232 if(preg_match("/T/",$tmp) && $type == "W"){
233 $skipped =TRUE;
234 }elseif(preg_match("/W/",$tmp) && $type == "T"){
235 $skipped =TRUE;
236 }else{
238 $this->memberList["$dn"]= $object;
239 $this->member["$dn"]= $dn;
240 reset ($this->memberList);
241 }
242 }
243 if($skipped){
244 msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
245 }
246 $this->objectSelect= FALSE;
247 $this->dialog= FALSE;
248 $this->reload();
249 }
250 }
251 }
253 function execute()
254 {
255 /* Call parent execute */
256 plugin::execute();
258 if(!$this->view_logged){
259 $this->view_logged = TRUE;
260 new log("view","ogroups/".get_class($this),$this->dn);
261 }
264 /* Do we represent a valid group? */
265 if (!$this->is_account){
266 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
267 msgPool::noValidExtension("object group")."</b>";
268 return ($display);
269 }
272 /* Load templating engine */
273 $smarty= get_smarty();
276 $tmp = $this->plInfo();
277 foreach($tmp['plProvidedAcls'] as $name => $translation){
278 $smarty->assign($name."ACL",$this->getacl($name));
279 }
281 /***********
282 * Trusts
283 ***********/
285 // Handle trust mode dialog
286 $this->dialog = FALSE;
287 $trustModeDialog = $this->trustModeDialog->execute();
288 if($this->trustModeDialog->trustSelect){
289 $this->dialog = TRUE;
290 return($trustModeDialog);
291 }
292 $smarty->assign("trustModeDialog",$trustModeDialog);
294 /***********
295 * Ende - Trusts
296 ***********/
299 /* Add objects? */
300 if (isset($_POST["edit_membership"])){
301 $this->objectSelect= new objectSelect($this->config, get_userinfo());
302 }
304 /* Add objects finished? */
305 if (isset($_POST["objectSelect_cancel"])){
306 $this->objectSelect= FALSE;
307 }
309 /* Manage object add dialog */
310 if ($this->objectSelect){
311 session::set('filterBlacklist', array('dn'=> $this->member));
312 $this->dialog= TRUE;
313 return($this->objectSelect->execute());
314 }
316 /* Assemble combine string */
317 if ($this->gosaGroupObjects == "[]"){
318 $smarty->assign("combinedObjects", _("none"));
319 } elseif (strlen($this->gosaGroupObjects) > 4){
320 $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
321 } else {
322 $conv= array( "U" => _("users"),
323 "G" => _("groups"),
324 "A" => _("applications"),
325 "D" => _("departments"),
326 "S" => _("servers"),
327 "W" => _("workstations"),
328 "O" => _("Windows workstations"),
329 "T" => _("terminals"),
330 "F" => _("phones"),
331 "P" => _("printers"));
333 $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
334 $p1= $conv[$type[0]];
335 error_reporting(0);
336 if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
337 $p2= $conv[$type[1]];
338 $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
339 } else {
340 $smarty->assign("combinedObjects", "$p1");
341 }
342 error_reporting(E_ALL | E_STRICT);
343 }
345 /* Assign variables */
346 $smarty->assign("base", $this->baseSelector->render());
350 $this->memberListing->setAcl($this->getacl("member"));
351 $data = $lData = array();
352 foreach($this->member as $key => $dn){
353 $image = 'images/lists/element.png';
354 $name = $dn;
355 if(isset($this->memberList[$dn])){
356 $name = $this->memberList[$dn]['text'];
357 if(isset($this->typeToImage[$this->memberList[$dn]['type']])){
358 $image = $this->typeToImage[$this->memberList[$dn]['type']];
359 }
360 }
361 $data[$key] = $dn;
362 $lData[$key] = array('data'=> array(image($image),$name));
363 }
364 $this->memberListing->setListData($data,$lData);
365 $this->memberListing->update();
366 $smarty->assign("memberList",$this->memberListing->render());
368 /* Fields */
369 foreach ($this->attributes as $val){
370 $smarty->assign("$val", set_post($this->$val));
371 }
373 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
374 }
377 function set_acl_base($base)
378 {
379 plugin::set_acl_base($base);
380 $this->trustModeDialog->set_acl_base($base);
381 }
384 /* Save data to object */
385 function save_object()
386 {
387 /* Save additional values for possible next step */
388 if (isset($_POST['ogroupedit'])){
390 $this->trustModeDialog->save_object();
392 /* Create a base backup and reset the
393 base directly after calling plugin::save_object();
394 Base will be set seperatly a few lines below */
395 $base_tmp = $this->base;
396 plugin::save_object();
397 $this->base = $base_tmp;
399 /* Refresh base */
400 if ($this->acl_is_moveable($this->base)){
401 if (!$this->baseSelector->update()) {
402 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
403 }
404 if ($this->base != $this->baseSelector->getBase()) {
405 $this->base= $this->baseSelector->getBase();
406 $this->is_modified= TRUE;
407 }
408 }
410 }
411 }
414 /* (Re-)Load objects */
415 function reload()
416 {
417 /*###########
418 Variable initialisation
419 ###########*/
421 $this->objects = array();
422 $this->ui = get_userinfo();
423 $filter = "";
424 $objectClasses = array();
426 $ogfilter = session::get("ogfilter");
427 $regex = $ogfilter['regex'];
429 $ldap= $this->config->get_ldap_link();
430 $ldap->cd ($ogfilter['dselect']);
433 /*###########
434 Generate Filter
435 ###########*/
437 $p_f= array("accounts"=> array("OBJ"=>"user", "CLASS"=>"gosaAccount" ,
438 "DN"=> get_people_ou() ,"ACL" => "users"),
439 "groups" => array("OBJ"=>"group", "CLASS"=>"posixGroup" ,
440 "DN"=> get_groups_ou('ogroupRDN') ,"ACL" => "groups"),
441 "departments" => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
442 "DN"=> "" ,"ACL" => "department"),
443 "servers" => array("OBJ"=>"servgeneric", "CLASS"=>"goServer" ,
444 "DN"=> get_ou("servgeneric", "serverRDN") ,"ACL" => "server"),
445 "workstations" => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
446 "DN"=> get_ou("workgeneric", "workstationRDN") ,"ACL" => "workstation"),
447 "winstations" => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",
448 "DN"=> get_ou("wingeneric", 'sambaMachineAccountRDN') ,"ACL" => "winstation"),
449 "terminals" => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal" ,
450 "DN"=> get_ou("termgeneric", "terminalRDN") ,"ACL" => "terminal"),
451 "printers" => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter" ,
452 "DN"=> get_ou("printgeneric", "printerRDN") ,"ACL" => "printer"),
453 "phones" => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware" ,
454 "DN"=> get_ou("phoneGeneric", "phoneRDN") ,"ACL" => "phone"));
457 /* Allow searching for applications, if we are not using release managed applications
458 */
459 if(!$this->IsReleaseManagementActivated()){
460 $p_f[ "applications"] = array("OBJ"=>"application", "CLASS"=>"gosaApplication",
461 "DN"=> get_ou("application", "applicationRDN") ,"ACL" => "application");
462 }
464 /*###########
465 Perform search for selected objectClasses & regex to fill list with objects
466 ###########*/
468 $Get_list_flags = 0;
469 if($ogfilter['subtrees'] == "checked"){
470 $Get_list_flags |= GL_SUBSEARCH;
471 }
473 foreach($p_f as $post_name => $data){
475 if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
477 if($ogfilter['subtrees']){
478 $base = $ogfilter['dselect'];
479 }else{
480 $base = $data['DN'].$ogfilter['dselect'];
481 }
484 $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
485 $res = get_list($filter, $data['ACL'] , $base,
486 array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
488 /* fetch results and append them to the list */
489 foreach($res as $attrs){
491 /* Skip workstations which are already assigned to an object group.
492 */
493 if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]"){
494 if(in_array($attrs['dn'],$this->used_workstations)){
495 continue;
496 }
497 }
499 $type= $this->getObjectType($attrs);
500 $name= $this->getObjectName($attrs);
502 /* Fill array */
503 if (isset($attrs["description"][0])){
504 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
505 } elseif (isset($attrs["uid"][0])) {
506 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
507 } else {
508 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
509 }
510 }
511 }
512 }
513 reset ($this->objects);
516 /*###########
517 Build member list and try to detect obsolete entries
518 ###########*/
520 $this->memberList = array();
522 /* Walk through all single member entry */
523 foreach($this->member as $dn){
525 /* The dn for the current member can't be resolved
526 it seams that this entry was removed
527 */
528 /* Try to resolv the entry again, if it still fails, display error msg */
529 $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
531 /* It has failed, add entry with type flag I (Invalid)*/
532 if (!$ldap->success()){
533 $this->memberList[$dn]= array('text' => _("Non existing DN:")." ".LDAP::fix($dn),"type" => "I");
535 } else {
537 /* Append this entry to our all object list */
539 /* Fetch object */
540 $attrs= $ldap->fetch();
542 $type= $this->getObjectType($attrs);
543 $name= $this->getObjectName($attrs);
545 if (isset($attrs["description"][0])){
546 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
547 } elseif (isset($attrs["uid"][0])) {
548 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
549 } else {
550 $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
551 }
552 $this->objcache[$attrs["dn"]]['objectClass'] = $attrs['objectClass'];
554 if(isset($attrs['macAddress'][0])){
555 $this->objcache[$attrs["dn"]]['macAddress'] = $attrs['macAddress'][0];
556 }else{
557 $this->objcache[$attrs["dn"]]['macAddress'] = "";
558 }
560 if(isset($attrs['uid'])){
561 $this->objcache[$attrs["dn"]]['uid'] = $attrs['uid'];
562 }
564 /* Fill array */
565 if (isset($attrs["description"][0])){
566 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
567 } else {
568 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
569 }
571 $this->memberList[$dn]= $this->objects[$attrs["dn"]];
572 }
573 }
574 reset ($this->memberList);
576 /* Assemble types of currently combined objects */
577 $objectTypes= "";
578 foreach ($this->memberList as $dn => $desc){
580 /* Invalid object? */
581 if ($desc['type'] == 'I'){
582 continue;
583 }
585 /* Fine. Add to list. */
586 if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
587 $objectTypes.= $desc['type'];
588 }
589 }
590 $this->gosaGroupObjects= "[$objectTypes]";
591 }
594 function getObjectType($attrs)
595 {
596 $type= "I";
598 foreach($this->typeToClass as $index => $class){
599 if (in_array($class, $attrs['objectClass'])){
600 $type= $index;
601 break;
602 }
603 }
604 return ($type);
605 }
608 function getObjectName($attrs)
609 {
610 /* Person? */
611 $name ="";
612 if (in_array('gosaAccount', $attrs['objectClass'])){
613 if(isset($attrs['sn']) && isset($attrs['givenName'])){
614 $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
615 } else {
616 $name= $attrs['uid'][0];
617 }
618 } else {
619 if(isset($attrs["cn"][0])) {
620 $name= $attrs['cn'][0];
621 } else {
622 $name= $attrs['ou'][0];
623 }
624 }
626 return ($name);
627 }
630 function check()
631 {
632 /* Call common method to give check the hook */
633 $message= plugin::check();
635 /* Permissions for that base? */
636 if ($this->base != ""){
637 $new_dn= 'cn='.$this->cn.','.get_ou("group", "ogroupRDN").$this->base;
638 } else {
639 $new_dn= $this->dn;
640 }
642 /* Check if we have workstations assigned, that are already assigned to
643 another object group. */
644 if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]" ) {
645 $test =array_intersect($this->used_workstations,$this->member);
646 if(count($test)){
647 $str = "";
648 foreach($test as $dn){
649 $str .= "<li>".$dn."</li>";
650 }
651 $message[] = sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>",$str);
652 }
653 }
655 $ldap = $this->config->get_ldap_link();
656 if(LDAP::fix($this->dn) != LDAP::fix($new_dn)){
657 $ldap->cat ($new_dn, array('dn'));
658 }
660 if($ldap->count() !=0){
661 $message[]= msgPool::duplicated(_("Name"));
662 }
664 // Check if a wrong base was supplied
665 if(!$this->baseSelector->checkLastBaseUpdate()){
666 $message[]= msgPool::check_base();;
667 }
669 /* Set new acl base */
670 if($this->dn == "new") {
671 $this->set_acl_base($this->base);
672 }
674 /* must: cn */
675 if ($this->cn == ""){
676 $message[]= msgPool::required(_("Name"));
677 }
679 if (preg_match('/[=,+<>#;]/', $this->cn)) {
680 $message[] = msgPool::invalid(_("Name"), $this->cn, "/[^=+,<>#;]/");
681 }
683 /* To many different object types? */
684 if (strlen($this->gosaGroupObjects) > 4){
685 $message[]= _("You can combine two different object types at maximum, only!");
686 }
688 /* Check if we are allowed to create or move this object
689 */
690 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
691 $message[] = msgPool::permCreate();
692 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
693 $message[] = msgPool::permMove();
694 }
696 return ($message);
697 }
700 /* Save to LDAP */
701 function save()
702 {
703 // Do not save members if we don't want to.
704 // This may be the case if we've copied an ogroup containing systems!
705 if(!$this->copyMembers){
706 $this->member = array();
707 $this->reload();
708 }
710 plugin::save();
712 /* Move members to target array */
713 $this->attrs['member'] =array();
714 foreach ($this->member as $key => $desc){
715 $this->attrs['member'][]= LDAP::fix($key);
716 }
718 $ldap= $this->config->get_ldap_link();
720 /* New accounts need proper 'dn', propagate it to remaining objects */
721 if ($this->dn == 'new'){
722 $this->dn= 'cn='.$this->cn.','.get_ou("group", "ogroupRDN").$this->base;
723 }
725 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
726 new entries. So do a check first... */
727 $ldap->cat ($this->dn, array('dn'));
728 if ($ldap->fetch()){
729 /* Modify needs array() to remove values :-( */
730 if (!count ($this->member)){
731 $this->attrs['member']= array();
732 }
733 $mode= "modify";
735 } else {
736 $mode= "add";
737 $ldap->cd($this->config->current['BASE']);
738 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
739 }
742 /* Write back to ldap */
743 $ldap->cd($this->dn);
744 $this->cleanup();
745 $ldap->$mode($this->attrs);
747 if($mode == "add"){
748 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
749 }else{
750 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
751 }
753 /* Trigger post signal */
754 $this->handle_post_events($mode);
756 $ret= 0;
757 if (!$ldap->success()){
758 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
759 $ret= 1;
760 }else{
761 $this->trustModeDialog->dn = $this->dn;
762 $this->trustModeDialog->save();
763 }
765 return ($ret);
766 }
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, 0, get_class()));
776 }
778 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
780 /* Trigger remove signal */
781 $this->handle_post_events("remove");
782 }
785 function PrepareForCopyPaste($source)
786 {
787 plugin::PrepareForCopyPaste($source);
789 // Preselect "Copy members" state.
790 // If we've terminals, workstations or servers in our members list,
791 // then disable this option by default, to avoid problems with
792 // inheritance of ogroup values.
793 if (preg_match("/[STW]/", $this->gosaGroupObjects) || !isset($source['member'])) {
794 $this->copyMembers = FALSE;
795 } else {
796 $this->copyMembers = TRUE;
797 }
799 /* Reload tabs */
800 $this->parent->reload($this->gosaGroupObjects );
802 $this->trustModeDialog->PrepareForCopyPaste($source);
804 /* Reload plugins */
805 foreach($this->parent->by_object as $name => $class ){
806 if(get_class($this) != $name) {
807 $this->parent->by_object[$name]->PrepareForCopyPaste($source);
808 }
809 }
811 $source_o = new ogroup ($this->config, $source['dn']);
812 foreach(array("member","gosaGroupObjects") as $attr){
813 $this->$attr = $source_o->$attr;
814 }
815 }
818 function getCopyDialog()
819 {
820 $smarty = get_smarty();
821 $smarty->assign("cn", set_post($this->cn));
822 $smarty->assign("copyMembers", $this->copyMembers);
823 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
824 $ret = array();
825 $ret['string'] = $str;
826 $ret['status'] = "";
827 return($ret);
828 }
830 function saveCopyDialog()
831 {
832 if(isset($_POST['cn'])){
833 $this->cn = get_post('cn');
834 }
835 $this->copyMembers = isset($_POST['copyMembers']);
836 }
839 function IsReleaseManagementActivated()
840 {
841 return($this->config->pluginEnabled("faiManagement"));
842 }
845 static function plInfo()
846 {
847 return (array(
848 "plShortName" => _("Generic"),
849 "plDescription" => _("Object group generic"),
850 "plSelfModify" => FALSE,
851 "plDepends" => array(),
852 "plPriority" => 1,
853 "plSection" => array("administration"),
854 "plRequirements"=> array(
855 'ldapSchema' => array('gosaGroupOfNames' => '>=2.7'),
856 'onFailureDisablePlugin' => array(get_class(), 'ogroupManagement')
857 ),
858 "plCategory" => array("ogroups" => array("description" => _("Object groups"),
859 "objectClass" => "gosaGroupOfNames")),
860 "plProvidedAcls"=> array(
861 "cn" => _("Name"),
862 "base" => _("Base"),
863 "description" => _("Description"),
864 "accessTo" => _("System trust"),
865 "member" => _("Member"))
866 ));
867 }
868 }
870 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
871 ?>