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 $baseSelector;
70 /* Already assigned Workstations. Will be hidden in selection.
71 */
72 var $used_workstations = array();
74 /* attribute list for save action */
75 var $attributes= array("cn", "description", "gosaGroupObjects","member");
76 var $objectclasses= array("top", "gosaGroupOfNames");
78 function ogroup (&$config, $dn= NULL)
79 {
80 plugin::plugin ($config, $dn);
82 $this->trustModeDialog = new trustModeDialog($this->config, $this->dn,NULL);
83 $this->trustModeDialog->setAcl('ogroups/ogroup');
85 $this->orig_dn= $dn;
87 $this->member = array();
89 /* Load member objects */
90 if (isset($this->attrs['member'])){
91 foreach ($this->attrs['member'] as $key => $value){
92 if ("$key" != "count"){
93 $value= @LDAP::convert($value);
94 $this->member["$value"]= "$value";
95 }
96 }
97 }
98 $this->is_account= TRUE;
100 /* Set base */
101 if ($this->dn == "new"){
102 $ui = get_userinfo();
103 $this->base= dn2base(session::global_is_set("CurrentMainBase")?"cn=dummy,".session::global_get("CurrentMainBase"):$ui->dn);
104 } else {
105 $this->base= preg_replace("/^[^,]+,".preg_quote(get_ou("group", "ogroupRDN"), '/')."/i","",$this->dn);
106 }
108 /* Detect all workstations, which are already assigned to an object group
109 - Those objects will be hidden in the add object dialog.
110 - Check() will complain if such a system is assigned to this object group.
111 */
112 $base = $this->config->current['BASE'];
113 $res = get_list("(|(objectClass=gotoWorkstation)(objectClass=gotoTerminal))","none" ,
114 $base, array("dn"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
115 $ws_dns = array();
116 foreach($res as $data){
117 $ws_dns[] = $data['dn'];
118 }
119 $res=get_list("(&(member=*)(objectClass=gosaGroupOfNames))","none",
120 $base, array("dn","member", "gosaGroupObjects"),GL_NO_ACL_CHECK|GL_SUBSEARCH);
121 $this->used_workstations = array();
122 foreach($res as $og){
123 if($og['dn'] == $this->dn) continue;
124 $test = array_intersect($ws_dns,$og['member']);
125 if(($og['gosaGroupObjects'] == "[W]" || $og['gosaGroupObjects'] == "[T]") && count($test)){
126 $this->used_workstations = array_merge($this->used_workstations,$test);
127 }
128 }
130 $this->orig_cn = $this->cn;
131 $this->orig_base = $this->base;
133 /* Get global filter config */
134 if (!session::is_set("sysfilter")){
135 $ui= get_userinfo();
136 $base= get_base_from_people($ui->dn);
137 $sysfilter= array( "depselect" => $base,
138 "regex" => "*");
139 session::set("sysfilter", $sysfilter);
140 }
142 /* Instanciate base selector */
143 $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
144 $this->baseSelector->setSubmitButton(false);
145 $this->baseSelector->setHeight(300);
146 $this->baseSelector->update(true);
148 // Prepare lists
149 $this->memberListing = new sortableListing();
150 $this->memberListing->setDeleteable(true);
151 $this->memberListing->setInstantDelete(true);
152 $this->memberListing->setEditable(false);
153 $this->memberListing->setWidth("100%");
154 $this->memberListing->setHeight("300px");
155 $this->memberListing->setHeader(array("~",_("Name")));
156 $this->memberListing->setColspecs(array('20px','*','20px'));
157 $this->memberListing->setDefaultSortColumn(1);
159 $this->reload();
160 }
162 function AddDelMembership($NewMember = false){
164 if($NewMember){
166 // Ensure that we definitely know the new members attributes.
167 // - Fetch unknown objects here.
168 if(!isset($this->memberList[$NewMember])){
170 $ldap = $this->config->get_ldap_link();
171 $ldap->cd($this->config->current['BASE']);
172 $ldap->cat($NewMember);
173 $attrs = $ldap->fetch();
174 $this->objcache[$NewMember] = $attrs;
175 }
177 /* Add member and force reload */
178 $this->member[$NewMember]= $NewMember;
181 $this->memberList[$NewMember]= $this->objcache[$NewMember];
182 unset ($this->objects[$NewMember]);
183 reset ($this->memberList);
184 $this->reload();
185 }else{
187 // Act on list modifications
188 $this->memberListing->save_object();
189 $action = $this->memberListing->getAction();
190 if($action['action'] == 'delete'){
191 foreach($action['targets'] as $id){
192 $value = $this->memberListing->getKey($id);
193 $this->objects["$value"]= $this->memberList[$value];
194 unset ($this->memberList["$value"]);
195 unset ($this->member["$value"]);
196 }
197 $this->reload();
198 }
201 /* Add objects to group */
202 if (isset($_POST['objectSelect_save']) && $this->objectSelect instanceOf objectSelect){
203 $objects = $this->objectSelect->save();
204 $skipped = FALSE;
205 foreach($objects as $object){
206 $dn = $object['dn'];
208 // Do not add existing members twice!
209 if(isset($this->member["$dn"])){
210 continue;
211 }
213 $tmp = "";
214 foreach($this->memberList as $obj){
215 $tmp .= $obj['type'];
216 }
218 $type = $this->getObjectType($object);
219 $name= $this->getObjectName($object);
221 /* Fill array */
222 if (isset($object["description"][0])){
223 $object= array("text" => "$name [".$object["description"][0]."]", "type" => "$type");
224 } elseif (isset($object["uid"][0])) {
225 $object= array("text" => "$name [".$object["uid"][0]."]", "type" => "$type");
226 } else {
227 $object= array("text" => "$name", "type" => "$type");
228 }
230 if(preg_match("/T/",$tmp) && $type == "W"){
231 $skipped =TRUE;
232 }elseif(preg_match("/W/",$tmp) && $type == "T"){
233 $skipped =TRUE;
234 }else{
236 $this->memberList["$dn"]= $object;
237 $this->member["$dn"]= $dn;
238 reset ($this->memberList);
239 }
240 }
241 if($skipped){
242 msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
243 }
244 $this->objectSelect= FALSE;
245 $this->dialog= FALSE;
246 $this->reload();
247 }
248 }
249 }
251 function execute()
252 {
253 /* Call parent execute */
254 plugin::execute();
256 if(!$this->view_logged){
257 $this->view_logged = TRUE;
258 new log("view","ogroups/".get_class($this),$this->dn);
259 }
262 /* Do we represent a valid group? */
263 if (!$this->is_account){
264 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
265 msgPool::noValidExtension("object group")."</b>";
266 return ($display);
267 }
270 /* Load templating engine */
271 $smarty= get_smarty();
274 $tmp = $this->plInfo();
275 foreach($tmp['plProvidedAcls'] as $name => $translation){
276 $smarty->assign($name."ACL",$this->getacl($name));
277 }
279 /***********
280 * Trusts
281 ***********/
283 // Handle trust mode dialog
284 $this->dialog = FALSE;
285 $trustModeDialog = $this->trustModeDialog->execute();
286 if($this->trustModeDialog->trustSelect){
287 $this->dialog = TRUE;
288 return($trustModeDialog);
289 }
290 $smarty->assign("trustModeDialog",$trustModeDialog);
292 /***********
293 * Ende - Trusts
294 ***********/
297 /* Add objects? */
298 if (isset($_POST["edit_membership"])){
299 $this->objectSelect= new objectSelect($this->config, get_userinfo());
300 }
302 /* Add objects finished? */
303 if (isset($_POST["objectSelect_cancel"])){
304 $this->objectSelect= FALSE;
305 }
307 /* Manage object add dialog */
308 if ($this->objectSelect){
309 session::set('filterBlacklist', array('dn'=> $this->member));
310 $this->dialog= TRUE;
311 return($this->objectSelect->execute());
312 }
314 /* Assemble combine string */
315 if ($this->gosaGroupObjects == "[]"){
316 $smarty->assign("combinedObjects", _("none"));
317 } elseif (strlen($this->gosaGroupObjects) > 4){
318 $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
319 } else {
320 $conv= array( "U" => _("users"),
321 "G" => _("groups"),
322 "A" => _("applications"),
323 "D" => _("departments"),
324 "S" => _("servers"),
325 "W" => _("workstations"),
326 "O" => _("Windows workstations"),
327 "T" => _("terminals"),
328 "F" => _("phones"),
329 "P" => _("printers"));
331 $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
332 $p1= $conv[$type[0]];
333 error_reporting(0);
334 if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
335 $p2= $conv[$type[1]];
336 $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
337 } else {
338 $smarty->assign("combinedObjects", "$p1");
339 }
340 error_reporting(E_ALL | E_STRICT);
341 }
343 /* Assign variables */
344 $smarty->assign("base", $this->baseSelector->render());
348 $this->memberListing->setAcl($this->getacl("member"));
349 $data = $lData = array();
350 foreach($this->member as $key => $dn){
351 $image = 'images/lists/element.png';
352 $name = $dn;
353 if(isset($this->memberList[$dn])){
354 $name = $this->memberList[$dn]['text'];
355 if(isset($this->typeToImage[$this->memberList[$dn]['type']])){
356 $image = $this->typeToImage[$this->memberList[$dn]['type']];
357 }
358 }
359 $data[$key] = $dn;
360 $lData[$key] = array('data'=> array(image($image),$name));
361 }
362 $this->memberListing->setListData($data,$lData);
363 $this->memberListing->update();
364 $smarty->assign("memberList",$this->memberListing->render());
366 /* Fields */
367 foreach ($this->attributes as $val){
368 $smarty->assign("$val", set_post($this->$val));
369 }
371 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
372 }
375 function set_acl_base($base)
376 {
377 plugin::set_acl_base($base);
378 $this->trustModeDialog->set_acl_base($base);
379 }
382 /* Save data to object */
383 function save_object()
384 {
385 /* Save additional values for possible next step */
386 if (isset($_POST['ogroupedit'])){
388 $this->trustModeDialog->save_object();
390 /* Create a base backup and reset the
391 base directly after calling plugin::save_object();
392 Base will be set seperatly a few lines below */
393 $base_tmp = $this->base;
394 plugin::save_object();
395 $this->base = $base_tmp;
397 /* Refresh base */
398 if ($this->acl_is_moveable($this->base)){
399 if (!$this->baseSelector->update()) {
400 msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
401 }
402 if ($this->base != $this->baseSelector->getBase()) {
403 $this->base= $this->baseSelector->getBase();
404 $this->is_modified= TRUE;
405 }
406 }
408 }
409 }
412 /* (Re-)Load objects */
413 function reload()
414 {
415 /*###########
416 Variable initialisation
417 ###########*/
419 $this->objects = array();
420 $this->ui = get_userinfo();
421 $filter = "";
422 $objectClasses = array();
424 $ogfilter = session::get("ogfilter");
425 $regex = $ogfilter['regex'];
427 $ldap= $this->config->get_ldap_link();
428 $ldap->cd ($ogfilter['dselect']);
431 /*###########
432 Generate Filter
433 ###########*/
435 $p_f= array("accounts"=> array("OBJ"=>"user", "CLASS"=>"gosaAccount" ,
436 "DN"=> get_people_ou() ,"ACL" => "users"),
437 "groups" => array("OBJ"=>"group", "CLASS"=>"posixGroup" ,
438 "DN"=> get_groups_ou('ogroupRDN') ,"ACL" => "groups"),
439 "departments" => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
440 "DN"=> "" ,"ACL" => "department"),
441 "servers" => array("OBJ"=>"servgeneric", "CLASS"=>"goServer" ,
442 "DN"=> get_ou("servgeneric", "serverRDN") ,"ACL" => "server"),
443 "workstations" => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
444 "DN"=> get_ou("workgeneric", "workstationRDN") ,"ACL" => "workstation"),
445 "winstations" => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",
446 "DN"=> get_ou("wingeneric", 'sambaMachineAccountRDN') ,"ACL" => "winstation"),
447 "terminals" => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal" ,
448 "DN"=> get_ou("termgeneric", "terminalRDN") ,"ACL" => "terminal"),
449 "printers" => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter" ,
450 "DN"=> get_ou("printgeneric", "printerRDN") ,"ACL" => "printer"),
451 "phones" => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware" ,
452 "DN"=> get_ou("phoneGeneric", "phoneRDN") ,"ACL" => "phone"));
455 /* Allow searching for applications, if we are not using release managed applications
456 */
457 if(!$this->IsReleaseManagementActivated()){
458 $p_f[ "applications"] = array("OBJ"=>"application", "CLASS"=>"gosaApplication",
459 "DN"=> get_ou("application", "applicationRDN") ,"ACL" => "application");
460 }
462 /*###########
463 Perform search for selected objectClasses & regex to fill list with objects
464 ###########*/
466 $Get_list_flags = 0;
467 if($ogfilter['subtrees'] == "checked"){
468 $Get_list_flags |= GL_SUBSEARCH;
469 }
471 foreach($p_f as $post_name => $data){
473 if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
475 if($ogfilter['subtrees']){
476 $base = $ogfilter['dselect'];
477 }else{
478 $base = $data['DN'].$ogfilter['dselect'];
479 }
482 $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
483 $res = get_list($filter, $data['ACL'] , $base,
484 array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
486 /* fetch results and append them to the list */
487 foreach($res as $attrs){
489 /* Skip workstations which are already assigned to an object group.
490 */
491 if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]"){
492 if(in_array($attrs['dn'],$this->used_workstations)){
493 continue;
494 }
495 }
497 $type= $this->getObjectType($attrs);
498 $name= $this->getObjectName($attrs);
500 /* Fill array */
501 if (isset($attrs["description"][0])){
502 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
503 } elseif (isset($attrs["uid"][0])) {
504 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
505 } else {
506 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
507 }
508 }
509 }
510 }
511 reset ($this->objects);
514 /*###########
515 Build member list and try to detect obsolete entries
516 ###########*/
518 $this->memberList = array();
520 /* Walk through all single member entry */
521 foreach($this->member as $dn){
523 /* The dn for the current member can't be resolved
524 it seams that this entry was removed
525 */
526 /* Try to resolv the entry again, if it still fails, display error msg */
527 $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
529 /* It has failed, add entry with type flag I (Invalid)*/
530 if (!$ldap->success()){
531 $this->memberList[$dn]= array('text' => _("Non existing DN:")." ".LDAP::fix($dn),"type" => "I");
533 } else {
535 /* Append this entry to our all object list */
537 /* Fetch object */
538 $attrs= $ldap->fetch();
540 $type= $this->getObjectType($attrs);
541 $name= $this->getObjectName($attrs);
543 if (isset($attrs["description"][0])){
544 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
545 } elseif (isset($attrs["uid"][0])) {
546 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
547 } else {
548 $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
549 }
550 $this->objcache[$attrs["dn"]]['objectClass'] = $attrs['objectClass'];
552 if(isset($attrs['macAddress'][0])){
553 $this->objcache[$attrs["dn"]]['macAddress'] = $attrs['macAddress'][0];
554 }else{
555 $this->objcache[$attrs["dn"]]['macAddress'] = "";
556 }
558 if(isset($attrs['uid'])){
559 $this->objcache[$attrs["dn"]]['uid'] = $attrs['uid'];
560 }
562 /* Fill array */
563 if (isset($attrs["description"][0])){
564 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
565 } else {
566 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
567 }
569 $this->memberList[$dn]= $this->objects[$attrs["dn"]];
570 }
571 }
572 reset ($this->memberList);
574 /* Assemble types of currently combined objects */
575 $objectTypes= "";
576 foreach ($this->memberList as $dn => $desc){
578 /* Invalid object? */
579 if ($desc['type'] == 'I'){
580 continue;
581 }
583 /* Fine. Add to list. */
584 if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
585 $objectTypes.= $desc['type'];
586 }
587 }
588 $this->gosaGroupObjects= "[$objectTypes]";
589 }
592 function getObjectType($attrs)
593 {
594 $type= "I";
596 foreach($this->typeToClass as $index => $class){
597 if (in_array($class, $attrs['objectClass'])){
598 $type= $index;
599 break;
600 }
601 }
602 return ($type);
603 }
606 function getObjectName($attrs)
607 {
608 /* Person? */
609 $name ="";
610 if (in_array('gosaAccount', $attrs['objectClass'])){
611 if(isset($attrs['sn']) && isset($attrs['givenName'])){
612 $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
613 } else {
614 $name= $attrs['uid'][0];
615 }
616 } else {
617 if(isset($attrs["cn"][0])) {
618 $name= $attrs['cn'][0];
619 } else {
620 $name= $attrs['ou'][0];
621 }
622 }
624 return ($name);
625 }
628 function check()
629 {
630 /* Call common method to give check the hook */
631 $message= plugin::check();
633 /* Permissions for that base? */
634 if ($this->base != ""){
635 $new_dn= 'cn='.$this->cn.','.get_ou("group", "ogroupRDN").$this->base;
636 } else {
637 $new_dn= $this->dn;
638 }
640 /* Check if we have workstations assigned, that are already assigned to
641 another object group. */
642 if ($this->gosaGroupObjects == "[W]" || $this->gosaGroupObjects == "[T]" ) {
643 $test =array_intersect($this->used_workstations,$this->member);
644 if(count($test)){
645 $str = "";
646 foreach($test as $dn){
647 $str .= "<li>".$dn."</li>";
648 }
649 $message[] = sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>",$str);
650 }
651 }
653 $ldap = $this->config->get_ldap_link();
654 if(LDAP::fix($this->dn) != LDAP::fix($new_dn)){
655 $ldap->cat ($new_dn, array('dn'));
656 }
658 if($ldap->count() !=0){
659 $message[]= msgPool::duplicated(_("Name"));
660 }
662 // Check if a wrong base was supplied
663 if(!$this->baseSelector->checkLastBaseUpdate()){
664 $message[]= msgPool::check_base();;
665 }
667 /* Set new acl base */
668 if($this->dn == "new") {
669 $this->set_acl_base($this->base);
670 }
672 /* must: cn */
673 if ($this->cn == ""){
674 $message[]= msgPool::required(_("Name"));
675 }
677 if (preg_match('/[=,+<>#;]/', $this->cn)) {
678 $message[] = msgPool::invalid(_("Name"), $this->cn, "/[^=+,<>#;]/");
679 }
681 /* To many different object types? */
682 if (strlen($this->gosaGroupObjects) > 4){
683 $message[]= _("You can combine two different object types at maximum, only!");
684 }
686 /* Check if we are allowed to create or move this object
687 */
688 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
689 $message[] = msgPool::permCreate();
690 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
691 $message[] = msgPool::permMove();
692 }
694 return ($message);
695 }
698 /* Save to LDAP */
699 function save()
700 {
701 plugin::save();
703 /* Move members to target array */
704 $this->attrs['member'] =array();
705 foreach ($this->member as $key => $desc){
706 $this->attrs['member'][]= LDAP::fix($key);
707 }
709 $ldap= $this->config->get_ldap_link();
711 /* New accounts need proper 'dn', propagate it to remaining objects */
712 if ($this->dn == 'new'){
713 $this->dn= 'cn='.$this->cn.','.get_ou("group", "ogroupRDN").$this->base;
714 }
716 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
717 new entries. So do a check first... */
718 $ldap->cat ($this->dn, array('dn'));
719 if ($ldap->fetch()){
720 /* Modify needs array() to remove values :-( */
721 if (!count ($this->member)){
722 $this->attrs['member']= array();
723 }
724 $mode= "modify";
726 } else {
727 $mode= "add";
728 $ldap->cd($this->config->current['BASE']);
729 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
730 }
733 /* Write back to ldap */
734 $ldap->cd($this->dn);
735 $this->cleanup();
736 $ldap->$mode($this->attrs);
738 if($mode == "add"){
739 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
740 }else{
741 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
742 }
744 /* Trigger post signal */
745 $this->handle_post_events($mode);
747 $ret= 0;
748 if (!$ldap->success()){
749 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
750 $ret= 1;
751 }else{
752 $this->trustModeDialog->dn = $this->dn;
753 $this->trustModeDialog->save();
754 }
756 return ($ret);
757 }
759 function remove_from_parent()
760 {
761 plugin::remove_from_parent();
763 $ldap= $this->config->get_ldap_link();
764 $ldap->rmdir($this->dn);
765 if (!$ldap->success()){
766 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
767 }
769 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
771 /* Trigger remove signal */
772 $this->handle_post_events("remove");
773 }
776 function PrepareForCopyPaste($source)
777 {
778 plugin::PrepareForCopyPaste($source);
780 /* Reload tabs */
781 $this->parent->reload($this->gosaGroupObjects );
783 $this->trustModeDialog->PrepareForCopyPaste($source);
785 /* Reload plugins */
786 foreach($this->parent->by_object as $name => $class ){
787 if(get_class($this) != $name) {
788 $this->parent->by_object[$name]->PrepareForCopyPaste($source);
789 }
790 }
792 $source_o = new ogroup ($this->config, $source['dn']);
793 foreach(array("member","gosaGroupObjects") as $attr){
794 $this->$attr = $source_o->$attr;
795 }
796 }
799 function getCopyDialog()
800 {
801 $smarty = get_smarty();
802 $smarty->assign("cn", set_post($this->cn));
803 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
804 $ret = array();
805 $ret['string'] = $str;
806 $ret['status'] = "";
807 return($ret);
808 }
810 function saveCopyDialog()
811 {
812 if(isset($_POST['cn'])){
813 $this->cn = get_post('cn');
814 }
815 }
818 function IsReleaseManagementActivated()
819 {
820 return($this->config->pluginEnabled("faiManagement"));
821 }
824 static function plInfo()
825 {
826 return (array(
827 "plShortName" => _("Generic"),
828 "plDescription" => _("Object group generic"),
829 "plSelfModify" => FALSE,
830 "plDepends" => array(),
831 "plPriority" => 1,
832 "plSection" => array("administration"),
833 "plRequirements"=> array(
834 'ldapSchema' => array('gosaGroupOfNames' => '>=2.7'),
835 'onFailureDisablePlugin' => array(get_class(), 'ogroupManagement')
836 ),
837 "plCategory" => array("ogroups" => array("description" => _("Object groups"),
838 "objectClass" => "gosaGroupOfNames")),
839 "plProvidedAcls"=> array(
840 "cn" => _("Name"),
841 "base" => _("Base"),
842 "description" => _("Description"),
843 "accessTo" => _("System trust"),
844 "member" => _("Member"))
845 ));
846 }
847 }
849 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
850 ?>