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 /* Sort multidimensional arrays for key 'text' */
24 function sort_list($val1, $val2)
25 {
26 $v1= strtolower($val1['text']);
27 $v2= strtolower($val2['text']);
28 if ($v1 > $v2){
29 return 1;
30 }
31 if ($v1 < $v2){
32 return -1;
33 }
34 return 0;
35 }
38 class ogroup extends plugin
39 {
40 /* Variables */
41 var $cn= "";
42 var $description= "";
43 var $base= "";
44 var $gosaGroupObjects= "";
45 var $department= "";
46 var $objects= array();
47 var $objcache= array();
48 var $memberList= array();
49 var $member= array();
50 var $orig_dn= "";
51 var $group_dialog= FALSE;
52 var $view_logged = FALSE;
54 /* attribute list for save action */
55 var $attributes= array("cn", "description", "gosaGroupObjects","member");
56 var $objectclasses= array("top", "gosaGroupOfNames");
58 function ogroup (&$config, $dn= NULL)
59 {
60 plugin::plugin ($config, $dn);
61 $this->orig_dn= $dn;
63 $this->member = array();
65 /* Load member objects */
66 if (isset($this->attrs['member'])){
67 foreach ($this->attrs['member'] as $key => $value){
68 if ("$key" != "count"){
69 $value= @LDAP::convert($value);
70 $this->member["$value"]= "$value";
71 }
72 }
73 }
74 $this->is_account= TRUE;
76 /* Get global filter config */
77 if (!session::is_set("ogfilter")){
78 $ui= get_userinfo();
79 $base= get_base_from_people($ui->dn);
80 $ogfilter= array( "dselect" => $base,
81 "regex" => "*");
82 session::set("ogfilter", $ogfilter);
83 }
84 $ogfilter= session::get('ogfilter');
86 /* Adjust flags */
87 foreach( array( "U" => "accounts",
88 "G" => "groups",
89 "A" => "applications",
90 "D" => "departments",
91 "S" => "servers",
92 "W" => "workstations",
93 "O" => "winstations",
94 "T" => "terminals",
95 "F" => "phones",
96 "_" => "subtrees",
97 "P" => "printers") as $key => $val){
99 if (preg_match("/$key/", $this->gosaGroupObjects)){
100 $ogfilter[$val]= "checked";
101 } else {
102 $ogfilter[$val]= "";
103 }
104 }
105 session::set("ogfilter", $ogfilter);
107 if(session::is_set('CurrentMainBase')){
108 $this->base = session::get('CurrentMainBase');
109 }
111 /* Set base */
112 if ($this->dn == "new"){
113 $this->base = session::get('CurrentMainBase');
114 } else {
115 $this->base= preg_replace("/^[^,]+,".normalizePreg(get_ou("ogroupou"))."/","",$this->dn);
116 }
118 /* Load member data */
119 $this->reload();
120 }
122 function AddDelMembership($NewMember = false){
124 if($NewMember){
126 /* Add member and force reload */
127 $this->member[$NewMember]= $NewMember;
128 $this->reload();
130 $this->memberList[$NewMember]= $this->objcache[$NewMember];
131 unset ($this->objects[$NewMember]);
132 uasort ($this->memberList, 'sort_list');
133 reset ($this->memberList);
134 }else{
135 /* Delete objects from group */
136 if (isset($_POST['delete_membership']) && isset($_POST['members'])){
137 foreach ($_POST['members'] as $value){
138 $this->objects["$value"]= $this->memberList[$value];
139 unset ($this->memberList["$value"]);
140 unset ($this->member["$value"]);
141 uasort ($this->objects, 'sort_list');
142 reset ($this->objects);
143 }
144 $this->reload();
145 }
147 /* Add objects to group */
148 if (isset($_POST['add_object_finish']) && isset($_POST['objects'])){
150 $tmp = "";
151 foreach($this->memberList as $obj){
152 $tmp .= $obj['type'];
153 }
154 $skipped = FALSE;
155 foreach ($_POST['objects'] as $value){
156 if(preg_match("/T/",$tmp) && $this->objects[$value]['type'] == "W"){
157 $skipped =TRUE;
158 }elseif(preg_match("/W/",$tmp) && $this->objects[$value]['type'] == "T"){
159 $skipped =TRUE;
160 }else{
161 $this->memberList["$value"]= $this->objects[$value];
162 $this->member["$value"]= $value;
163 unset ($this->objects[$value]);
164 uasort ($this->memberList, 'sort_list');
165 reset ($this->memberList);
166 }
167 }
168 if($skipped){
169 msg_dialog::display(_("Information"), _("You cannot combine terminals and workstations in one object group!"), INFO_DIALOG);
170 }
171 $this->reload();
172 }
173 }
174 }
176 function execute()
177 {
178 /* Call parent execute */
179 plugin::execute();
181 if(!$this->view_logged){
182 $this->view_logged = TRUE;
183 new log("view","ogroups/".get_class($this),$this->dn);
184 }
187 /* Do we represent a valid group? */
188 if (!$this->is_account){
189 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
190 msgPool::noValidExtension("object group")."</b>";
191 return ($display);
192 }
195 /* Load templating engine */
196 $smarty= get_smarty();
198 $tmp = $this->plInfo();
199 foreach($tmp['plProvidedAcls'] as $name => $translation){
200 $smarty->assign($name."ACL",$this->getacl($name));
201 }
203 /* Base select dialog */
204 $once = true;
205 foreach($_POST as $name => $value){
206 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_moveable()){
207 $once = false;
208 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
209 $this->dialog->setCurrentBase($this->base);
210 }
211 }
213 /* Dialog handling */
214 if(is_object($this->dialog) && $this->acl_is_moveable()){
215 /* Must be called before save_object */
216 $this->dialog->save_object();
218 if($this->dialog->isClosed()){
219 $this->dialog = false;
220 }elseif($this->dialog->isSelected()){
222 /* A new base was selected, check if it is a valid one */
223 $tmp = $this->get_allowed_bases();
224 if(isset($tmp[$this->dialog->isSelected()])){
225 $this->base = $this->dialog->isSelected();
226 }
227 $this->dialog= false;
228 }else{
229 return($this->dialog->execute());
230 }
231 }
233 /* Add objects? */
234 if (isset($_POST["edit_membership"])){
235 $this->group_dialog= TRUE;
236 $this->dialog= TRUE;
237 }
239 /* Add objects finished? */
240 if (isset($_POST["add_object_finish"]) || isset($_POST["add_object_cancel"])){
241 $this->group_dialog= FALSE;
242 $this->dialog= FALSE;
243 }
245 /* Manage object add dialog */
246 if ($this->group_dialog){
248 /* Save data */
249 $ogfilter= session::get("ogfilter");
250 foreach( array("dselect", "regex") as $type){
251 if (isset($_POST[$type])){
252 $ogfilter[$type]= $_POST[$type];
253 }
254 }
255 if (isset($_POST['dselect'])){
256 foreach( array("accounts", "groups", "applications", "departments",
257 "servers", "workstations", "winstations", "terminals", "printers","subtrees",
258 "phones") as $type){
260 if (isset($_POST[$type])) {
261 $ogfilter[$type]= "checked";
262 } else {
263 $ogfilter[$type]= "";
264 }
265 }
266 }
267 if (isset($_GET['search'])){
268 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
269 if ($s == "**"){
270 $s= "*";
271 }
272 $ogfilter['regex']= $s;
273 }
274 session::set("ogfilter", $ogfilter);
275 $this->reload();
277 /* Calculate actual groups */
278 $smarty->assign("objects", $this->convert_list($this->objects));
280 /* Show dialog */
281 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
282 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
283 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
284 $smarty->assign("deplist", $this->config->idepartments);
285 $smarty->assign("alphabet", generate_alphabet());
286 foreach( array("dselect", "regex", "subtrees") as $type){
287 $smarty->assign("$type", $ogfilter[$type]);
288 }
289 $smarty->assign("hint", print_sizelimit_warning());
290 $smarty->assign("apply", apply_filter());
292 /* Build up checkboxes
293 */
294 $ar = array(
295 "departments" => array(
296 "T" => msgPool::selectToView(_("departments")),
297 "C" => (isset($ogfilter['departments']) && ($ogfilter['departments'])),
298 "L" => sprintf(_("Show %s"),_("departments"))),
299 "accounts" => array(
300 "T" => msgPool::selectToView(_("people")),
301 "C" => (isset($ogfilter['accounts']) && ($ogfilter['accounts'])),
302 "L" => sprintf(_("Show %s"),_("people"))),
303 "groups"=> array(
304 "T" => msgPool::selectToView(_("groups")),
305 "C" => (isset($ogfilter['groups']) && ($ogfilter['groups'])),
306 "L" => sprintf(_("Show %s"),_("groups"))),
307 "applications"=> array(
308 "T" => msgPool::selectToView(_("applications")),
309 "C" => (isset($ogfilter['applications']) && ($ogfilter['applications'])),
310 "L" => sprintf(_("Show %s"),_("applications"))),
311 "servers"=> array(
312 "T" => msgPool::selectToView(_("servers")),
313 "C" => (isset($ogfilter['servers']) && ($ogfilter['servers'])),
314 "L" => sprintf(_("Show %s"),_("servers"))),
315 "workstations"=> array(
316 "T" => msgPool::selectToView(_("workstations")),
317 "C" => (isset($ogfilter['workstations']) && ($ogfilter['workstations'])),
318 "L" => sprintf(_("Show %s"),_("workstations"))),
319 "terminals"=> array(
320 "T" => msgPool::selectToView(_("terminals")),
321 "C" => (isset($ogfilter['terminals']) && ($ogfilter['terminals'])),
322 "L" => sprintf(_("Show %s"),_("terminals"))),
323 "printers"=> array(
324 "T" => msgPool::selectToView(_("printer")),
325 "C" => (isset($ogfilter['printers']) && ($ogfilter['printers'])),
326 "L" => sprintf(_("Show %s"),_("printers"))),
327 "phones"=> array(
328 "T" => msgPool::selectToView(_("phones")),
329 "C" => (isset($ogfilter['phones']) && ($ogfilter['phones'])),
330 "L" => sprintf(_("Show %s"),_("phones"))));
331 $smarty->assign("checkboxes",$ar);
332 $display= $smarty->fetch (get_template_path('ogroup_objects.tpl', TRUE, dirname(__FILE__)));
333 return ($display);
334 }
336 /* Bases / Departments */
337 if ((isset($_POST['base'])) && ($this->acl_is_moveable())){
338 $this->base= $_POST['base'];
339 }
341 /* Assemble combine string */
342 if ($this->gosaGroupObjects == "[]"){
343 $smarty->assign("combinedObjects", _("none"));
344 } elseif (strlen($this->gosaGroupObjects) > 4){
345 $smarty->assign("combinedObjects", "<font color=red>"._("too many different objects!")."</font>");
346 } else {
347 $conv= array( "U" => _("users"),
348 "G" => _("groups"),
349 "A" => _("applications"),
350 "D" => _("departments"),
351 "S" => _("servers"),
352 "W" => _("workstations"),
353 "O" => _("winstations"),
354 "T" => _("terminals"),
355 "F" => _("phones"),
356 "P" => _("printers"));
358 $type= preg_replace('/[\[\]]/', '', $this->gosaGroupObjects);
359 $p1= $conv[$type[0]];
360 error_reporting(0);
361 if (isset($type[1]) && preg_match('/[UGADSFOWTP]/', $type[1])){
362 $p2= $conv[$type[1]];
363 $smarty->assign("combinedObjects", sprintf("'%s' and '%s'", $p1, $p2));
364 } else {
365 $smarty->assign("combinedObjects", "$p1");
366 }
367 error_reporting(E_ALL | E_STRICT);
368 }
370 /* Assign variables */
371 $smarty->assign("bases", $this->get_allowed_bases());
372 $smarty->assign("base_select", $this->base);
373 $smarty->assign("department", $this->department);
374 $smarty->assign("members", $this->convert_list($this->memberList));
376 /* Objects have to be tuned... */
377 $smarty->assign("objects", $this->convert_list($this->objects));
379 /* Fields */
380 foreach ($this->attributes as $val){
381 $smarty->assign("$val", $this->$val);
382 }
384 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
385 }
388 /* Save data to object */
389 function save_object()
390 {
391 /* Save additional values for possible next step */
392 if (isset($_POST['ogroupedit'])){
394 /* Create a base backup and reset the
395 base directly after calling plugin::save_object();
396 Base will be set seperatly a few lines below */
397 $base_tmp = $this->base;
398 plugin::save_object();
399 $this->base = $base_tmp;
401 /* Save base, since this is no LDAP attribute */
402 $tmp = $this->get_allowed_bases();
403 if(isset($_POST['base'])){
404 if(isset($tmp[$_POST['base']])){
405 $this->base= $_POST['base'];
406 }
407 }
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('ogroupou') ,"ACL" => "groups"),
439 "applications" => array("OBJ"=>"application", "CLASS"=>"gosaApplication",
440 "DN"=> get_ou('applicationou') ,"ACL" => "application"),
441 "departments" => array("OBJ"=>"department", "CLASS"=>"gosaDepartment" ,
442 "DN"=> "" ,"ACL" => "department"),
443 "servers" => array("OBJ"=>"servgeneric", "CLASS"=>"goServer" ,
444 "DN"=> get_ou('serverou') ,"ACL" => "server"),
445 "workstations" => array("OBJ"=>"workgeneric", "CLASS"=>"gotoWorkstation",
446 "DN"=> get_ou('workstationou') ,"ACL" => "workstation"),
447 "winstations" => array("OBJ"=>"wingeneric", "CLASS"=>"opsiClient",
448 "DN"=> get_ou('WINSTATIONS') ,"ACL" => "winstation"),
449 "terminals" => array("OBJ"=>"termgeneric", "CLASS"=>"gotoTerminal" ,
450 "DN"=> get_ou('terminalou') ,"ACL" => "terminal"),
451 "printers" => array("OBJ"=>"printgeneric", "CLASS"=>"gotoPrinter" ,
452 "DN"=> get_ou('printerou') ,"ACL" => "printer"),
453 "phones" => array("OBJ"=>"phoneGeneric", "CLASS"=>"goFonHardware" ,
454 "DN"=> get_ou('phoneou') ,"ACL" => "phone"));
457 /*###########
458 Perform search for selected objectClasses & regex to fill list with objects
459 ###########*/
461 $Get_list_flags = 0;
462 if($ogfilter['subtrees'] == "checked"){
463 $Get_list_flags |= GL_SUBSEARCH;
464 }
466 foreach($p_f as $post_name => $data){
468 if($ogfilter[$post_name] == "checked" && class_available($data['OBJ'])){
470 if($ogfilter['subtrees']){
471 $base = $ogfilter['dselect'];
472 }else{
473 $base = $data['DN'].$ogfilter['dselect'];
474 }
477 $filter = "(&(objectClass=".$data['CLASS'].")(|(uid=$regex)(cn=$regex)(ou=$regex)))";
478 $res = get_list($filter, $data['ACL'] , $base,
479 array("description", "objectClass", "sn", "givenName", "uid","ou","cn"),$Get_list_flags);
481 /* fetch results and append them to the list */
482 foreach($res as $attrs){
484 $type= $this->getObjectType($attrs);
485 $name= $this->getObjectName($attrs);
487 /* Fill array */
488 if (isset($attrs["description"][0])){
489 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
490 } elseif (isset($attrs["uid"][0])) {
491 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
492 } else {
493 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
494 }
495 }
496 }
497 }
498 uasort ($this->objects, 'sort_list');
499 reset ($this->objects);
502 /*###########
503 Build member list and try to detect obsolete entries
504 ###########*/
506 $this->memberList = array();
508 /* Walk through all single member entry */
509 foreach($this->member as $dn){
511 /* The dn for the current member can't be resolved
512 it seams that this entry was removed
513 */
514 /* Try to resolv the entry again, if it still fails, display error msg */
515 $ldap->cat($dn, array("cn", "sn", "givenName", "ou", "description", "objectClass", "macAddress"));
517 /* It has failed, add entry with type flag I (Invalid)*/
518 if (!$ldap->success()){
519 $this->memberList[$dn]= array('text' => _("Non existing dn:")." ".@LDAP::fix($dn),"type" => "I");
521 } else {
523 /* Append this entry to our all object list */
525 /* Fetch object */
526 $attrs= $ldap->fetch();
528 $type= $this->getObjectType($attrs);
529 $name= $this->getObjectName($attrs);
531 if (isset($attrs["description"][0])){
532 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
533 } elseif (isset($attrs["uid"][0])) {
534 $this->objcache[$attrs["dn"]]= array("text" => "$name [".$attrs["uid"][0]."]", "type" => "$type");
535 } else {
536 $this->objcache[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
537 }
538 $this->objcache[$attrs["dn"]]['objectClass'] = $attrs['objectClass'];
540 if(isset($attrs['macAddress'][0])){
541 $this->objcache[$attrs["dn"]]['macAddress'] = $attrs['macAddress'][0];
542 }else{
543 $this->objcache[$attrs["dn"]]['macAddress'] = "";
544 }
546 if(isset($attrs['uid'])){
547 $this->objcache[$attrs["dn"]]['uid'] = $attrs['uid'];
548 }
550 /* Fill array */
551 if (isset($attrs["description"][0])){
552 $this->objects[$attrs["dn"]]= array("text" => "$name [".$attrs["description"][0]."]", "type" => "$type");
553 } else {
554 $this->objects[$attrs["dn"]]= array("text" => "$name", "type" => "$type");
555 }
557 $this->memberList[$dn]= $this->objects[$attrs["dn"]];
558 }
559 }
560 uasort ($this->memberList, 'sort_list');
561 reset ($this->memberList);
563 /* Assemble types of currently combined objects */
564 $objectTypes= "";
565 foreach ($this->memberList as $dn => $desc){
567 /* Invalid object? */
568 if ($desc['type'] == 'I'){
569 continue;
570 }
572 /* Fine. Add to list. */
573 if (!preg_match('/'.$desc['type'].'/', $objectTypes)){
574 $objectTypes.= $desc['type'];
575 }
576 }
577 $this->gosaGroupObjects= "[$objectTypes]";
578 }
581 function convert_list($input)
582 {
583 $temp= "";
584 $conv= array( "U" => "select_user.png",
585 "G" => "plugins/groups/images/groups.png",
586 "A" => "plugins/ogroups/images/application.png",
587 "D" => "plugins/departments/images/department.png",
588 "S" => "plugins/ogroups/images/server.png",
589 "W" => "plugins/ogroups/images/workstation.png",
590 "O" => "plugins/ogroups/images/winstation.png",
591 "T" => "plugins/ogroups/images/terminal.png",
592 "F" => "plugins/ogroups/images/phone.png",
593 "I" => "images/lists/flag.png",
594 "P" => "plugins/ogroups/images/printer.png");
596 foreach ($input as $key => $value){
597 /* Generate output */
598 $temp.= "<option title='".addslashes( $key)."' value=\"$key\" class=\"select\" style=\"background-image:url('".get_template_path($conv[$value['type']])."');\">".$value['text']."</option>\n";
599 }
601 return ($temp);
602 }
605 function getObjectType($attrs)
606 {
607 $type= "I";
609 foreach(array( "U" => "gosaAccount",
610 "G" => "posixGroup",
611 "A" => "gosaApplication",
612 "D" => "gosaDepartment",
613 "S" => "goServer",
614 "W" => "gotoWorkstation",
615 "O" => "opsiClient",
616 "T" => "gotoTerminal",
617 "F" => "goFonHardware",
618 "P" => "gotoPrinter") as $index => $class){
619 if (in_array($class, $attrs['objectClass'])){
620 $type= $index;
621 break;
622 }
623 }
625 return ($type);
626 }
629 function getObjectName($attrs)
630 {
631 /* Person? */
632 $name ="";
633 if (in_array('gosaAccount', $attrs['objectClass'])){
634 if(isset($attrs['sn']) && isset($attrs['givenName'])){
635 $name= $attrs['sn'][0].", ".$attrs['givenName'][0];
636 } else {
637 $name= $attrs['uid'][0];
638 }
639 } else {
640 if(isset($attrs["cn"][0])) {
641 $name= $attrs['cn'][0];
642 } else {
643 $name= $attrs['ou'][0];
644 }
645 }
647 return ($name);
648 }
651 function check()
652 {
653 /* Call common method to give check the hook */
654 $message= plugin::check();
656 /* Permissions for that base? */
657 if ($this->base != ""){
658 $new_dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
659 } else {
660 $new_dn= $this->dn;
661 }
664 $ldap = $this->config->get_ldap_link();
665 if($this->dn != $new_dn){
666 $ldap->cat ($new_dn, array('dn'));
667 }
669 if($ldap->count() !=0){
670 $message[]= msgPool::duplicated(_("Name"));
671 }
673 /* Set new acl base */
674 if($this->dn == "new") {
675 $this->set_acl_base($this->base);
676 }
678 /* must: cn */
679 if ($this->cn == ""){
680 $message[]= msgPool::required(_("Name"));
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 return ($message);
689 }
692 /* Save to LDAP */
693 function save()
694 {
695 plugin::save();
697 /* Move members to target array */
698 $this->attrs['member'] =array();
699 foreach ($this->member as $key => $desc){
700 $this->attrs['member'][]= @LDAP::fix($key);
701 }
703 $ldap= $this->config->get_ldap_link();
705 /* New accounts need proper 'dn', propagate it to remaining objects */
706 if ($this->dn == 'new'){
707 $this->dn= 'cn='.$this->cn.','.get_ou('ogroupou').$this->base;
708 }
710 /* Save data. Using 'modify' implies that the entry is already present, use 'add' for
711 new entries. So do a check first... */
712 $ldap->cat ($this->dn, array('dn'));
713 if ($ldap->fetch()){
714 /* Modify needs array() to remove values :-( */
715 if (!count ($this->member)){
716 $this->attrs['member']= array();
717 }
718 $mode= "modify";
720 } else {
721 $mode= "add";
722 $ldap->cd($this->config->current['BASE']);
723 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
724 }
726 /* Write back to ldap */
727 $ldap->cd($this->dn);
728 $this->cleanup();
729 $ldap->$mode($this->attrs);
731 if($mode == "add"){
732 new log("create","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
733 }else{
734 new log("modify","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
735 }
737 /* Trigger post signal */
738 $this->handle_post_events($mode);
740 $ret= 0;
741 if (!$ldap->success()){
742 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
743 $ret= 1;
744 }
746 return ($ret);
747 }
749 function remove_from_parent()
750 {
751 plugin::remove_from_parent();
753 $ldap= $this->config->get_ldap_link();
754 $ldap->rmdir($this->dn);
755 if (!$ldap->success()){
756 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
757 }
759 new log("remove","ogroups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
761 /* Trigger remove signal */
762 $this->handle_post_events("remove");
763 }
766 function PrepareForCopyPaste($source)
767 {
768 /* Update available object types */
769 if(isset($source['gosaGroupObjects'][0])){
770 $this->gosaGroupObjects = $source['gosaGroupObjects'][0];
771 }
773 /* Reload tabs */
774 $this->parent->reload($this->gosaGroupObjects );
776 /* Reload plugins */
777 foreach($this->parent->by_object as $name => $class ){
778 if(get_class($this) != $name) {
779 $this->parent->by_object[$name]->PrepareForCopyPaste($source);
780 }
781 }
783 /* Load member objects */
784 if (isset($source['member'])){
785 foreach ($source['member'] as $key => $value){
786 if ("$key" != "count"){
787 $value= @LDAP::convert($value);
788 $this->member["$value"]= "$value";
789 }
790 }
791 }
793 }
796 function getCopyDialog()
797 {
798 $smarty = get_smarty();
799 $smarty->assign("cn", $this->cn);
800 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
801 $ret = array();
802 $ret['string'] = $str;
803 $ret['status'] = "";
804 return($ret);
805 }
807 function saveCopyDialog()
808 {
809 if(isset($_POST['cn'])){
810 $this->cn = $_POST['cn'];
811 }
812 }
815 static function plInfo()
816 {
817 return (array(
818 "plShortName" => _("Generic"),
819 "plDescription" => _("Object group generic"),
820 "plSelfModify" => FALSE,
821 "plDepends" => array(),
822 "plPriority" => 1,
823 "plSection" => array("administration"),
824 "plCategory" => array("ogroups" => array("description" => _("Object groups"),
825 "objectClass" => "gosaGroupOfNames")),
826 "plProvidedAcls"=> array(
827 "cn" => _("Name"),
828 "base" => _("Base"),
829 "description" => _("Description"),
830 "member" => _("Member"))
831 ));
832 }
833 }
835 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
836 ?>